From 340cf1cfb699a8b49b8a93967a3ac5c23dd00453 Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Fri, 14 Aug 2009 04:24:30 +0000 Subject: [PATCH] * configure.in: Check for sys/select.h, termios.h, sys/socket.h, netinet/in.h, and netinet/tcp.h. * configure: Regenerate. * config.in: Add those headers. * main.c: Check for them. (setup_tcp_console): Disable if no networking. (main): Note missing networking or termios. * mem.c: Check for those headers. (stdin_ready): Disable if no termios. (m32c_sim_restore_console): Disable if no termios. (mem_get_byte): Disable console input if no termios. --- sim/m32c/ChangeLog | 14 ++++ sim/m32c/config.in | 15 ++++ sim/m32c/configure | 155 ++++++++++++++++++++++++++++++++++++++++++ sim/m32c/configure.in | 2 + sim/m32c/main.c | 29 +++++++- sim/m32c/mem.c | 16 +++++ 6 files changed, 230 insertions(+), 1 deletion(-) diff --git a/sim/m32c/ChangeLog b/sim/m32c/ChangeLog index 24684fb5eb1..9d71093cadb 100644 --- a/sim/m32c/ChangeLog +++ b/sim/m32c/ChangeLog @@ -1,3 +1,17 @@ +2009-08-14 DJ Delorie + + * configure.in: Check for sys/select.h, termios.h, sys/socket.h, + netinet/in.h, and netinet/tcp.h. + * configure: Regenerate. + * config.in: Add those headers. + * main.c: Check for them. + (setup_tcp_console): Disable if no networking. + (main): Note missing networking or termios. + * mem.c: Check for those headers. + (stdin_ready): Disable if no termios. + (m32c_sim_restore_console): Disable if no termios. + (mem_get_byte): Disable console input if no termios. + 2009-01-06 Joel Sherrill * r8c.opc, m32c.opc: Add parentheses to remove warnings. diff --git a/sim/m32c/config.in b/sim/m32c/config.in index 5e29f9569bf..0cde41f6c3b 100644 --- a/sim/m32c/config.in +++ b/sim/m32c/config.in @@ -22,6 +22,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET_IN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_NETINET_TCP_H + /* Define to 1 if you have the `nsl' library (-lnsl). */ #undef HAVE_LIBNSL @@ -49,15 +55,24 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_RESOURCE_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SELECT_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SOCKET_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TIME_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H +/* Define to 1 if you have the header file. */ +#undef HAVE_TERMIOS_H + /* Define to 1 if you have the `time' function. */ #undef HAVE_TIME diff --git a/sim/m32c/configure b/sim/m32c/configure index 95fef5c67c9..77e811104f3 100755 --- a/sim/m32c/configure +++ b/sim/m32c/configure @@ -4790,6 +4790,161 @@ sim_link_links="${sim_link_links} targ-vals.def" + + + + +for ac_header in sys/select.h termios.h sys/socket.h netinet/in.h netinet/tcp.h +do +as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 +else + # Is the header compilable? +echo "$as_me:$LINENO: checking $ac_header usability" >&5 +echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +#include <$ac_header> +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_header_compiler=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_header_compiler=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +echo "${ECHO_T}$ac_header_compiler" >&6 + +# Is the header present? +echo "$as_me:$LINENO: checking $ac_header presence" >&5 +echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <$ac_header> +_ACEOF +if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 + (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + ac_cpp_err=$ac_cpp_err$ac_c_werror_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + ac_header_preproc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_preproc=no +fi +rm -f conftest.err conftest.$ac_ext +echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +echo "${ECHO_T}$ac_header_preproc" >&6 + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in + yes:no: ) + { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 +echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} + ac_header_preproc=yes + ;; + no:yes:* ) + { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 +echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 +echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 +echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 +echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 +echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} + ( + cat <<\_ASBOX +## ------------------------------------------ ## +## Report this to the AC_PACKAGE_NAME lists. ## +## ------------------------------------------ ## +_ASBOX + ) | + sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac +echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 +if eval "test \"\${$as_ac_Header+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + eval "$as_ac_Header=\$ac_header_preproc" +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 + +fi +if test `eval echo '${'$as_ac_Header'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + + ac_sources="$sim_link_files" ac_dests="$sim_link_links" while test -n "$ac_sources"; do diff --git a/sim/m32c/configure.in b/sim/m32c/configure.in index 80c1f8a6f82..bca97ba49e8 100644 --- a/sim/m32c/configure.in +++ b/sim/m32c/configure.in @@ -28,4 +28,6 @@ sinclude(../common/aclocal.m4) # it by inlining the macro's contents. sinclude(../common/common.m4) +AC_CHECK_HEADERS(sys/select.h termios.h sys/socket.h netinet/in.h netinet/tcp.h) + SIM_AC_OUTPUT diff --git a/sim/m32c/main.c b/sim/m32c/main.c index 721f728890e..c33824364f2 100644 --- a/sim/m32c/main.c +++ b/sim/m32c/main.c @@ -19,6 +19,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include "config.h" #include #include #include @@ -26,11 +27,21 @@ along with this program. If not, see . */ #include #include #include - #include + +#ifdef HAVE_SYS_SOCKET_H +#ifdef HAVE_NETINET_IN_H +#ifdef HAVE_NETINET_TCP_H +#define HAVE_networking +#endif +#endif +#endif + +#ifdef HAVE_networking #include #include #include +#endif #include "bfd.h" @@ -45,8 +56,10 @@ along with this program. If not, see . */ #include "timer_a.h" #endif +#ifdef HAVE_networking extern int m32c_console_ofd; extern int m32c_console_ifd; +#endif int m32c_disassemble = 0; static unsigned int cycles = 0; @@ -63,6 +76,7 @@ done (int exit_code) exit (exit_code); } +#ifdef HAVE_networking static void setup_tcp_console (char *portname) { @@ -109,6 +123,7 @@ setup_tcp_console (char *portname) printf ("connection from %d.%d.%d.%d\n", a[0], a[1], a[2], a[3]); m32c_console_ofd = m32c_console_ifd; } +#endif int main (int argc, char **argv) @@ -116,7 +131,9 @@ main (int argc, char **argv) int o; int save_trace; bfd *prog; +#ifdef HAVE_networking char *console_port_s = 0; +#endif setbuf (stdout, 0); @@ -129,10 +146,18 @@ main (int argc, char **argv) trace++; break; case 'c': +#ifdef HAVE_networking console_port_s = optarg; +#else + fprintf (stderr, "Nework console not available in this build.\n"); +#endif break; case 'C': +#ifdef HAVE_TERMIOS_H m32c_use_raw_console = 1; +#else + fprintf (stderr, "Raw console not available in this build.\n"); +#endif break; case 'v': verbose++; @@ -177,8 +202,10 @@ main (int argc, char **argv) m32c_load (prog); trace = save_trace; +#ifdef HAVE_networking if (console_port_s) setup_tcp_console (console_port_s); +#endif sim_disasm_init (prog); diff --git a/sim/m32c/mem.c b/sim/m32c/mem.c index 51bb0ab3d9e..a8630b13ea8 100644 --- a/sim/m32c/mem.c +++ b/sim/m32c/mem.c @@ -19,6 +19,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include "config.h" #include #include #include @@ -26,8 +27,12 @@ along with this program. If not, see . */ #include #include #include +#ifdef HAVE_SYS_SELECT_H #include +#endif +#ifdef HAVE_TERMIOS_H #include +#endif #include "mem.h" #include "cpu.h" @@ -48,9 +53,13 @@ along with this program. If not, see . */ static unsigned char **pt[L1_LEN]; +#ifdef HAVE_TERMIOS_H int m32c_console_ifd = 0; +#endif int m32c_console_ofd = 1; +#ifdef HAVE_TERMIOS_H int m32c_use_raw_console = 0; +#endif #ifdef TIMER_A Timer_A timer_a; @@ -374,6 +383,7 @@ mem_get_pc () return *m; } +#ifdef HAVE_TERMIOS_H static int console_raw = 0; static struct termios oattr; @@ -399,6 +409,7 @@ m32c_sim_restore_console () tcsetattr (m32c_console_ifd, TCSANOW, &oattr); console_raw = 0; } +#endif static unsigned char mem_get_byte (int address) @@ -408,6 +419,7 @@ mem_get_byte (int address) m = mem_ptr (address); switch (address) { +#ifdef HAVE_TERMIOS_H case 0x2ed: /* m32c uart1c1 */ case 0x3ad: /* m16c uart1c1 */ @@ -447,6 +459,7 @@ mem_get_byte (int address) } return c; } +#endif #ifdef TIMER_A case 0x346: /* TA0low */ @@ -457,6 +470,9 @@ mem_get_byte (int address) return timer_a.count; #endif + default: + /* In case both cases above are not included. */ + ; } S ("=>"); -- 2.30.2