From 7b81badd89d828ac4d2ffa235367fa10c40652df Mon Sep 17 00:00:00 2001 From: David McCullough Date: Sun, 12 Jul 2009 23:28:58 +0000 Subject: [PATCH] Due to shell portability issues (which is to say shell scripts are not portable -- think Windows), convert elf2flt to C code. I've updated this code base to the latest elf2flt tree and actually done some basic tests -- building the three Blackfin tuples (ELF, FLAT, FDPIC) and running programs on my Blackfin boards. This process found errors in the original implementation as well as some of the cleanups I did. Signed-off-by: Nathan Sidwell Signed-off-by: Mike Frysinger --- Makefile.in | 35 +- configure | 1755 +++++++++++++++++++++++++++++++------------------ configure.in | 33 +- ld-elf2flt.c | 573 ++++++++++++++++ ld-elf2flt.in | 8 +- stubs.c | 83 +++ stubs.h | 37 ++ 7 files changed, 1853 insertions(+), 671 deletions(-) create mode 100644 ld-elf2flt.c diff --git a/Makefile.in b/Makefile.in index fc00851..66ce5a6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -10,13 +10,22 @@ includedir = @includedir@ CC = @CC@ CPU = @target_cpu@ TARGET = @target_alias@ +SYMBOL_PREFIX = @SYMBOL_PREFIX@ CFLAGS = @CFLAGS@ INCLUDES = -I$(srcdir) @bfd_include_dir@ @binutils_include_dir@ @zlib_include_dir@ CPPFLAGS = @CPPFLAGS@ $(DEFS) $(INCLUDES) LDFLAGS = @LDFLAGS@ LDLIBS = @LIBS@ INSTALL = @INSTALL@ -DEFS = @DEFS@ -DTARGET_$(CPU) +DEFS = @DEFS@ \ + -DTARGET_$(CPU) \ + -DTARGET_CPU=\"$(CPU)\" \ + -DSYMBOL_PREFIX=\"$(SYMBOL_PREFIX)\" \ + -DBINUTILS_LDSCRIPTDIR=\"@binutils_ldscript_dir@\" \ + -DTARGET_ALIAS=\"$(TARGET)\" \ + -DNO_GOT_CHECK=@got_check@ \ + -DUSE_EMIT_RELOCS=@emit_relocs@ \ + -DEMIT_CTOR_DTOR=@emit_ctor_dtor@ EXEEXT = @EXEEXT@ OBJEXT = @OBJEXT@ @@ -42,9 +51,18 @@ target_bindir = $(prefix)/$(TARGET)/bin target_libdir = $(prefix)/$(TARGET)/lib -PROG_ELF2FLT = elf2flt$(EXEEXT) -PROG_FLTHDR = flthdr$(EXEEXT) -PROGS = $(PROG_ELF2FLT) $(PROG_FLTHDR) +PROG_ELF2FLT = elf2flt$(EXEEXT) +PROG_FLTHDR = flthdr$(EXEEXT) +PROG_LD_ELF2FLT_C = ld-elf2flt$(EXEEXT) +PROG_LD_ELF2FLT_SH = ld-elf2flt.sh + +ifeq (@use_ld_elf2flt_binary@,yes) +PROG_LD_ELF2FLT = $(PROG_LD_ELF2FLT_C) +else +PROG_LD_ELF2FLT = $(PROG_LD_ELF2FLT_SH) +endif + +PROGS = $(PROG_ELF2FLT) $(PROG_FLTHDR) $(PROG_LD_ELF2FLT_C) $(PROG_LD_ELF2FLT_SH) all: $(PROGS) ld-elf2flt @@ -58,7 +76,10 @@ $(PROG_ELF2FLT): elf2flt.o compress.o stubs.o $(PROG_FLTHDR): flthdr.o compress.o stubs.o $(link) -ld-elf2flt: $(srcdir)/ld-elf2flt.in +ld-elf2flt$(EXEEXT): ld-elf2flt.o stubs.o + $(link) + +ld-elf2flt.sh: $(srcdir)/ld-elf2flt.sh.in ./config.status $@ Makefile: $(srcdir)/Makefile.in @@ -82,8 +103,8 @@ install: mv $(bindir)/$(TARGET)-ld$(EXEEXT) $(bindir)/$(TARGET)-ld.real$(EXEEXT) [ -f $(target_bindir)/ld.real$(EXEEXT) ] || \ mv $(target_bindir)/ld$(EXEEXT) $(target_bindir)/ld.real$(EXEEXT) - $(INSTALL) -m 755 ld-elf2flt $(bindir)/$(TARGET)-ld - $(INSTALL) -m 755 ld-elf2flt $(target_bindir)/ld + $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(bindir)/$(TARGET)-ld$(EXEEXT) + $(INSTALL) -m 755 $(PROG_LD_ELF2FLT) $(target_bindir)/ld$(EXEEXT) $(INSTALL) -m 644 $(SRC_LDFILE) $(target_libdir)/$(LDFILE) sinclude .deps diff --git a/configure b/configure index bcd26ae..8177dff 100755 --- a/configure +++ b/configure @@ -641,16 +641,17 @@ SYMBOL_PREFIX emit_ctor_dtor emit_relocs got_check +use_ld_elf2flt_binary binutils_ldscript_dir zlib_include_dir binutils_include_dir bfd_include_dir -EGREP -GREP -CPP INSTALL_DATA INSTALL_SCRIPT INSTALL_PROGRAM +EGREP +GREP +CPP OBJEXT EXEEXT ac_ct_CC @@ -717,6 +718,7 @@ with_bfd_include_dir with_binutils_include_dir with_binutils_ldscript_dir with_binutils_build_dir +enable_ld_elf2flt_binary enable_got_check enable_emit_relocs enable_emit_ctor_dtor @@ -1354,6 +1356,8 @@ Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --disable-ld-elf2flt-binary + use ld-elf2flt shell script --disable-got-check - disable check for GOT (needed on H8) --disable-emit-relocs - don't use the --emit-relocs (-q) linker option --enable-emit-ctor-dtor manually create ctor/dtor list @@ -1889,6 +1893,23 @@ else fi +# Check whether --enable-ld-elf2flt-binary was given. +if test "${enable_ld_elf2flt_binary+set}" = set; then + enableval=$enable_ld_elf2flt_binary; use_ld_elf2flt_binary=$enableval +else + use_ld_elf2flt_binary=yes + +fi + + +var_yn_to_10() { + if eval test \"\$$1\" = yes ; then + eval $1=1 + else + eval $1=0 + fi +} + # Check whether --enable-got-check was given. if test "${enable_got_check+set}" = set; then enableval=$enable_got_check; got_check=$enableval @@ -1897,6 +1918,7 @@ else fi +var_yn_to_10 got_check # Check whether --enable-emit-relocs was given. if test "${enable_emit_relocs+set}" = set; then @@ -1906,6 +1928,7 @@ else fi +var_yn_to_10 emit_relocs # Check whether --enable-emit-ctor-dtor was given. if test "${enable_emit_ctor_dtor+set}" = set; then @@ -1915,6 +1938,7 @@ else fi +var_yn_to_10 emit_ctor_dtor ac_aux_dir= for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do @@ -3007,252 +3031,1103 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu -# Find a good install program. We prefer a C program (faster), -# so one script is as good as another. But avoid the broken or -# incompatible versions: -# SysV /etc/install, /usr/sbin/install -# SunOS /usr/etc/install -# IRIX /sbin/install -# AIX /bin/install -# AmigaOS /C/install, which installs bootblocks on floppy discs -# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag -# AFS /usr/afsws/bin/install, which mishandles nonexistent args -# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" -# OS/2's system install, which has a completely different semantic -# ./install, which can be erroneously created by make from ./install.sh. -# Reject install programs that cannot install multiple files. -{ $as_echo "$as_me:$LINENO: checking for a BSD-compatible install" >&5 -$as_echo_n "checking for a BSD-compatible install... " >&6; } -if test -z "$INSTALL"; then -if test "${ac_cv_path_install+set}" = set; then - $as_echo_n "(cached) " >&6 -else - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - # Account for people who put trailing slashes in PATH elements. -case $as_dir/ in - ./ | .// | /cC/* | \ - /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ - ?:\\/os2\\/install\\/* | ?:\\/OS2\\/INSTALL\\/* | \ - /usr/ucb/* ) ;; - *) - # OSF1 and SCO ODT 3.0 have their own names for install. - # Don't use installbsd from OSF since it installs stuff as root - # by default. - for ac_prog in ginstall scoinst install; do - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then - if test $ac_prog = install && - grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then - # AIX install. It has an incompatible calling convention. - : - elif test $ac_prog = install && - grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then - # program-specific install script used by HP pwplus--don't use. - : - else - rm -rf conftest.one conftest.two conftest.dir - echo one > conftest.one - echo two > conftest.two - mkdir conftest.dir - if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && - test -s conftest.one && test -s conftest.two && - test -s conftest.dir/conftest.one && - test -s conftest.dir/conftest.two - then - ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" - break 3 - fi - fi - fi - done - done - ;; -esac - -done -IFS=$as_save_IFS - -rm -rf conftest.one conftest.two conftest.dir - -fi - if test "${ac_cv_path_install+set}" = set; then - INSTALL=$ac_cv_path_install - else - # As a last resort, use the slow shell script. Don't cache a - # value for INSTALL within a source directory, because that will - # break other packages using the cache if that directory is - # removed, or if the value is a relative name. - INSTALL=$ac_install_sh - fi -fi -{ $as_echo "$as_me:$LINENO: result: $INSTALL" >&5 -$as_echo "$INSTALL" >&6; } - -# Use test -z because SunOS4 sh mishandles braces in ${var-val}. -# It thinks the first close brace ends the variable substitution. -test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' - -test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' - -test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' - -if test "$ac_binutils_build_dir" != "NONE"; then - test "$ac_libbfd" = "NONE" && ac_libbfd="$ac_binutils_build_dir/bfd/libbfd.a" - test "$ac_libiberty" = "NONE" && ac_libiberty="$ac_binutils_build_dir/libiberty/libiberty.a" - test "$ac_bfd_include_dir" = "NONE" && ac_bfd_include_dir="$ac_binutils_build_dir/bfd" - test "$ac_binutils_include_dir" = "NONE" && ac_binutils_include_dir="$ac_binutils_build_dir/include" +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5 +$as_echo_n "checking how to run the C preprocessor... " >&6; } +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= fi - -if test "$ac_libiberty" = "NONE"; then - - -{ $as_echo "$as_me:$LINENO: checking for objalloc_create in -liberty" >&5 -$as_echo_n "checking for objalloc_create in -liberty... " >&6; } -if test "${ac_cv_lib_iberty_objalloc_create+set}" = set; then +if test -z "$CPP"; then + if test "${ac_cv_prog_CPP+set}" = set; then $as_echo_n "(cached) " >&6 else - ac_check_lib_save_LIBS=$LIBS -LIBS="-liberty $LIBS" -cat >conftest.$ac_ext <<_ACEOF + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" +#ifdef __STDC__ +# include +#else +# include #endif -char objalloc_create (); -int -main () -{ -return objalloc_create (); - ; - return 0; -} + Syntax error _ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" +if { (ac_try="$ac_cpp conftest.$ac_ext" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" $as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 + (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 $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext }; then - ac_cv_lib_iberty_objalloc_create=yes + : else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 - ac_cv_lib_iberty_objalloc_create=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_iberty_objalloc_create" >&5 -$as_echo "$ac_cv_lib_iberty_objalloc_create" >&6; } -if test "x$ac_cv_lib_iberty_objalloc_create" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBIBERTY 1 -_ACEOF - - LIBS="-liberty $LIBS" - + # Broken: fails on valid input. +continue fi - ac_libiberty=auto -else - LIBS="$ac_libiberty $LIBS" -fi -if test "$ac_libbfd" = "NONE"; then +rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: checking for bfd_openr in -lbfd" >&5 -$as_echo_n "checking for bfd_openr in -lbfd... " >&6; } -if test "${ac_cv_lib_bfd_bfd_openr+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lbfd $LIBS" -cat >conftest.$ac_ext <<_ACEOF + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char bfd_openr (); -int -main () -{ -return bfd_openr (); - ; - return 0; -} +#include _ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" +if { (ac_try="$ac_cpp conftest.$ac_ext" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" $as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 + (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 $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext }; then - ac_cv_lib_bfd_bfd_openr=yes + # Broken: success on invalid input. +continue else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 - ac_cv_lib_bfd_bfd_openr=no + # Passes both tests. +ac_preproc_ok=: +break fi -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + break +fi + + done + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ $as_echo "$as_me:$LINENO: result: $CPP" >&5 +$as_echo "$CPP" >&6; } +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&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 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + : +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Broken: fails on valid input. +continue +fi + +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&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 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + # Broken: success on invalid input. +continue +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Passes both tests. +ac_preproc_ok=: +break +fi + +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + : +else + { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +{ { $as_echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details." >&5 +$as_echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; }; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +{ $as_echo "$as_me:$LINENO: checking for grep that handles long lines and -e" >&5 +$as_echo_n "checking for grep that handles long lines and -e... " >&6; } +if test "${ac_cv_path_GREP+set}" = set; then + $as_echo_n "(cached) " >&6 +else + if test -z "$GREP"; then + ac_path_GREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in grep ggrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue +# Check for GNU ac_path_GREP and select it if it is found. + # Check for GNU $ac_path_GREP +case `"$ac_path_GREP" --version 2>&1` in +*GNU*) + ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'GREP' >> "conftest.nl" + "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + ac_count=`expr $ac_count + 1` + if test $ac_count -gt ${ac_path_GREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_GREP="$ac_path_GREP" + ac_path_GREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_GREP_found && break 3 + done + done +done +IFS=$as_save_IFS + if test -z "$ac_cv_path_GREP"; then + { { $as_echo "$as_me:$LINENO: error: no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5 +$as_echo "$as_me: error: no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;} + { (exit 1); exit 1; }; } + fi +else + ac_cv_path_GREP=$GREP +fi + +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_path_GREP" >&5 +$as_echo "$ac_cv_path_GREP" >&6; } + GREP="$ac_cv_path_GREP" + + +{ $as_echo "$as_me:$LINENO: checking for egrep" >&5 +$as_echo_n "checking for egrep... " >&6; } +if test "${ac_cv_path_EGREP+set}" = set; then + $as_echo_n "(cached) " >&6 +else + if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 + then ac_cv_path_EGREP="$GREP -E" + else + if test -z "$EGREP"; then + ac_path_EGREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in egrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue +# Check for GNU ac_path_EGREP and select it if it is found. + # Check for GNU $ac_path_EGREP +case `"$ac_path_EGREP" --version 2>&1` in +*GNU*) + ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'EGREP' >> "conftest.nl" + "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + ac_count=`expr $ac_count + 1` + if test $ac_count -gt ${ac_path_EGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_EGREP="$ac_path_EGREP" + ac_path_EGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_EGREP_found && break 3 + done + done +done +IFS=$as_save_IFS + if test -z "$ac_cv_path_EGREP"; then + { { $as_echo "$as_me:$LINENO: error: no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5 +$as_echo "$as_me: error: no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;} + { (exit 1); exit 1; }; } + fi +else + ac_cv_path_EGREP=$EGREP +fi + + fi +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_path_EGREP" >&5 +$as_echo "$ac_cv_path_EGREP" >&6; } + EGREP="$ac_cv_path_EGREP" + + +{ $as_echo "$as_me:$LINENO: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if test "${ac_cv_header_stdc+set}" = set; then + $as_echo_n "(cached) " >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_header_stdc=yes +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_header_stdc=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then + : +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then + : +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then + : +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +rm -f conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + : +else + $as_echo "$as_me: program exited with status $ac_status" >&5 +$as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +ac_cv_header_stdc=no +fi +rm -rf conftest.dSYM +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi + + +fi +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +cat >>confdefs.h <<\_ACEOF +#define STDC_HEADERS 1 +_ACEOF + +fi + +# On IRIX 5.3, sys/types and inttypes.h are conflicting. + + + + + + + + + +for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ + inttypes.h stdint.h unistd.h +do +as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 +$as_echo_n "checking for $ac_header... " >&6; } +if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then + $as_echo_n "(cached) " >&6 +else + 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 { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + eval "$as_ac_Header=yes" +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + eval "$as_ac_Header=no" +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +ac_res=`eval 'as_val=${'$as_ac_Header'} + $as_echo "$as_val"'` + { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +as_val=`eval 'as_val=${'$as_ac_Header'} + $as_echo "$as_val"'` + if test "x$as_val" = x""yes; then + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + + + if test "${ac_cv_header_minix_config_h+set}" = set; then + { $as_echo "$as_me:$LINENO: checking for minix/config.h" >&5 +$as_echo_n "checking for minix/config.h... " >&6; } +if test "${ac_cv_header_minix_config_h+set}" = set; then + $as_echo_n "(cached) " >&6 +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_minix_config_h" >&5 +$as_echo "$ac_cv_header_minix_config_h" >&6; } +else + # Is the header compilable? +{ $as_echo "$as_me:$LINENO: checking minix/config.h usability" >&5 +$as_echo_n "checking minix/config.h usability... " >&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 +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_header_compiler=yes +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_compiler=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +$as_echo "$ac_header_compiler" >&6; } + +# Is the header present? +{ $as_echo "$as_me:$LINENO: checking minix/config.h presence" >&5 +$as_echo_n "checking minix/config.h presence... " >&6; } +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&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 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + ac_header_preproc=yes +else + $as_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 +{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +$as_echo "$ac_header_preproc" >&6; } + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in + yes:no: ) + { $as_echo "$as_me:$LINENO: WARNING: minix/config.h: accepted by the compiler, rejected by the preprocessor!" >&5 +$as_echo "$as_me: WARNING: minix/config.h: accepted by the compiler, rejected by the preprocessor!" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: minix/config.h: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: minix/config.h: proceeding with the compiler's result" >&2;} + ac_header_preproc=yes + ;; + no:yes:* ) + { $as_echo "$as_me:$LINENO: WARNING: minix/config.h: present but cannot be compiled" >&5 +$as_echo "$as_me: WARNING: minix/config.h: present but cannot be compiled" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: minix/config.h: check for missing prerequisite headers?" >&5 +$as_echo "$as_me: WARNING: minix/config.h: check for missing prerequisite headers?" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: minix/config.h: see the Autoconf documentation" >&5 +$as_echo "$as_me: WARNING: minix/config.h: see the Autoconf documentation" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: minix/config.h: section \"Present But Cannot Be Compiled\"" >&5 +$as_echo "$as_me: WARNING: minix/config.h: section \"Present But Cannot Be Compiled\"" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: minix/config.h: proceeding with the preprocessor's result" >&5 +$as_echo "$as_me: WARNING: minix/config.h: proceeding with the preprocessor's result" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: minix/config.h: in the future, the compiler will take precedence" >&5 +$as_echo "$as_me: WARNING: minix/config.h: in the future, the compiler will take precedence" >&2;} + + ;; +esac +{ $as_echo "$as_me:$LINENO: checking for minix/config.h" >&5 +$as_echo_n "checking for minix/config.h... " >&6; } +if test "${ac_cv_header_minix_config_h+set}" = set; then + $as_echo_n "(cached) " >&6 +else + ac_cv_header_minix_config_h=$ac_header_preproc +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_minix_config_h" >&5 +$as_echo "$ac_cv_header_minix_config_h" >&6; } + +fi +if test "x$ac_cv_header_minix_config_h" = x""yes; then + MINIX=yes +else + MINIX= +fi + + + if test "$MINIX" = yes; then + +cat >>confdefs.h <<\_ACEOF +#define _POSIX_SOURCE 1 +_ACEOF + + +cat >>confdefs.h <<\_ACEOF +#define _POSIX_1_SOURCE 2 +_ACEOF + + +cat >>confdefs.h <<\_ACEOF +#define _MINIX 1 +_ACEOF + + fi + + + + { $as_echo "$as_me:$LINENO: checking whether it is safe to define __EXTENSIONS__" >&5 +$as_echo_n "checking whether it is safe to define __EXTENSIONS__... " >&6; } +if test "${ac_cv_safe_to_define___extensions__+set}" = set; then + $as_echo_n "(cached) " >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +# define __EXTENSIONS__ 1 + $ac_includes_default +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_safe_to_define___extensions__=yes +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_safe_to_define___extensions__=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_safe_to_define___extensions__" >&5 +$as_echo "$ac_cv_safe_to_define___extensions__" >&6; } + test $ac_cv_safe_to_define___extensions__ = yes && + cat >>confdefs.h <<\_ACEOF +#define __EXTENSIONS__ 1 +_ACEOF + + cat >>confdefs.h <<\_ACEOF +#define _ALL_SOURCE 1 +_ACEOF + + cat >>confdefs.h <<\_ACEOF +#define _GNU_SOURCE 1 +_ACEOF + + cat >>confdefs.h <<\_ACEOF +#define _POSIX_PTHREAD_SEMANTICS 1 +_ACEOF + + cat >>confdefs.h <<\_ACEOF +#define _TANDEM_SOURCE 1 +_ACEOF + + +# Find a good install program. We prefer a C program (faster), +# so one script is as good as another. But avoid the broken or +# incompatible versions: +# SysV /etc/install, /usr/sbin/install +# SunOS /usr/etc/install +# IRIX /sbin/install +# AIX /bin/install +# AmigaOS /C/install, which installs bootblocks on floppy discs +# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag +# AFS /usr/afsws/bin/install, which mishandles nonexistent args +# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" +# OS/2's system install, which has a completely different semantic +# ./install, which can be erroneously created by make from ./install.sh. +# Reject install programs that cannot install multiple files. +{ $as_echo "$as_me:$LINENO: checking for a BSD-compatible install" >&5 +$as_echo_n "checking for a BSD-compatible install... " >&6; } +if test -z "$INSTALL"; then +if test "${ac_cv_path_install+set}" = set; then + $as_echo_n "(cached) " >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + # Account for people who put trailing slashes in PATH elements. +case $as_dir/ in + ./ | .// | /cC/* | \ + /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ + ?:\\/os2\\/install\\/* | ?:\\/OS2\\/INSTALL\\/* | \ + /usr/ucb/* ) ;; + *) + # OSF1 and SCO ODT 3.0 have their own names for install. + # Don't use installbsd from OSF since it installs stuff as root + # by default. + for ac_prog in ginstall scoinst install; do + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then + if test $ac_prog = install && + grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # AIX install. It has an incompatible calling convention. + : + elif test $ac_prog = install && + grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # program-specific install script used by HP pwplus--don't use. + : + else + rm -rf conftest.one conftest.two conftest.dir + echo one > conftest.one + echo two > conftest.two + mkdir conftest.dir + if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && + test -s conftest.one && test -s conftest.two && + test -s conftest.dir/conftest.one && + test -s conftest.dir/conftest.two + then + ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" + break 3 + fi + fi + fi + done + done + ;; +esac + +done +IFS=$as_save_IFS + +rm -rf conftest.one conftest.two conftest.dir + +fi + if test "${ac_cv_path_install+set}" = set; then + INSTALL=$ac_cv_path_install + else + # As a last resort, use the slow shell script. Don't cache a + # value for INSTALL within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + INSTALL=$ac_install_sh + fi +fi +{ $as_echo "$as_me:$LINENO: result: $INSTALL" >&5 +$as_echo "$INSTALL" >&6; } + +# Use test -z because SunOS4 sh mishandles braces in ${var-val}. +# It thinks the first close brace ends the variable substitution. +test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' + +test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' + +test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' + + +if test "$ac_binutils_build_dir" != "NONE"; then + test "$ac_libbfd" = "NONE" && ac_libbfd="$ac_binutils_build_dir/bfd/libbfd.a" + test "$ac_libiberty" = "NONE" && ac_libiberty="$ac_binutils_build_dir/libiberty/libiberty.a" + test "$ac_bfd_include_dir" = "NONE" && ac_bfd_include_dir="$ac_binutils_build_dir/bfd" + test "$ac_binutils_include_dir" = "NONE" && ac_binutils_include_dir="$ac_binutils_build_dir/include" +fi + +if test "$ac_libiberty" = "NONE"; then + +{ $as_echo "$as_me:$LINENO: checking for objalloc_create in -liberty" >&5 +$as_echo_n "checking for objalloc_create in -liberty... " >&6; } +if test "${ac_cv_lib_iberty_objalloc_create+set}" = set; then + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-liberty $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char objalloc_create (); +int +main () +{ +return objalloc_create (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + $as_test_x conftest$ac_exeext + }; then + ac_cv_lib_iberty_objalloc_create=yes +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_lib_iberty_objalloc_create=no +fi + +rm -rf conftest.dSYM +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_iberty_objalloc_create" >&5 +$as_echo "$ac_cv_lib_iberty_objalloc_create" >&6; } +if test "x$ac_cv_lib_iberty_objalloc_create" = x""yes; then + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBIBERTY 1 +_ACEOF + + LIBS="-liberty $LIBS" + +fi + + ac_libiberty=auto +else + LIBS="$ac_libiberty $LIBS" +fi +if test "$ac_libbfd" = "NONE"; then + +{ $as_echo "$as_me:$LINENO: checking for bfd_openr in -lbfd" >&5 +$as_echo_n "checking for bfd_openr in -lbfd... " >&6; } +if test "${ac_cv_lib_bfd_bfd_openr+set}" = set; then + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lbfd $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char bfd_openr (); +int +main () +{ +return bfd_openr (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + $as_test_x conftest$ac_exeext + }; then + ac_cv_lib_bfd_bfd_openr=yes +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_lib_bfd_bfd_openr=no +fi + +rm -rf conftest.dSYM +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:$LINENO: result: $ac_cv_lib_bfd_bfd_openr" >&5 $as_echo "$ac_cv_lib_bfd_bfd_openr" >&6; } @@ -3420,7 +4295,7 @@ fi SYMBOL_PREFIX= case $target in - bfin*) + h8300|bfin*) SYMBOL_PREFIX=_ ;; esac @@ -3462,408 +4337,37 @@ case "(($ac_try" in esac eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" $as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_lib_c_malloc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_lib_c_malloc=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_c_malloc" >&5 -$as_echo "$ac_cv_lib_c_malloc" >&6; } -if test "x$ac_cv_lib_c_malloc" = x""yes; then - LIBS="-lc $LIBS" -fi - - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -{ $as_echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5 -$as_echo_n "checking how to run the C preprocessor... " >&6; } -# On Suns, sometimes $CPP names a directory. -if test -n "$CPP" && test -d "$CPP"; then - CPP= -fi -if test -z "$CPP"; then - if test "${ac_cv_prog_CPP+set}" = set; then - $as_echo_n "(cached) " >&6 -else - # Double quotes because CPP needs to be expanded - for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" - do - ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer to if __STDC__ is defined, since - # exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#ifdef __STDC__ -# include -#else -# include -#endif - Syntax error -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&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 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Broken: fails on valid input. -continue -fi - -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether nonexistent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&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 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - # Broken: success on invalid input. -continue -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Passes both tests. -ac_preproc_ok=: -break -fi - -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - break -fi - - done - ac_cv_prog_CPP=$CPP - -fi - CPP=$ac_cv_prog_CPP -else - ac_cv_prog_CPP=$CPP -fi -{ $as_echo "$as_me:$LINENO: result: $CPP" >&5 -$as_echo "$CPP" >&6; } -ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer to if __STDC__ is defined, since - # exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#ifdef __STDC__ -# include -#else -# include -#endif - Syntax error -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&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 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Broken: fails on valid input. -continue -fi - -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether nonexistent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + (eval "$ac_link") 2>conftest.er1 ac_status=$? grep -v '^ *+' conftest.er1 >conftest.err rm -f conftest.er1 cat conftest.err >&5 $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + $as_test_x conftest$ac_exeext }; then - # Broken: success on invalid input. -continue + ac_cv_lib_c_malloc=yes else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 - # Passes both tests. -ac_preproc_ok=: -break -fi - -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - : -else - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; }; } -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - - -{ $as_echo "$as_me:$LINENO: checking for grep that handles long lines and -e" >&5 -$as_echo_n "checking for grep that handles long lines and -e... " >&6; } -if test "${ac_cv_path_GREP+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test -z "$GREP"; then - ac_path_GREP_found=false - # Loop through the user's path and test for each of PROGNAME-LIST - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in grep ggrep; do - for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" - { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue -# Check for GNU ac_path_GREP and select it if it is found. - # Check for GNU $ac_path_GREP -case `"$ac_path_GREP" --version 2>&1` in -*GNU*) - ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; -*) - ac_count=0 - $as_echo_n 0123456789 >"conftest.in" - while : - do - cat "conftest.in" "conftest.in" >"conftest.tmp" - mv "conftest.tmp" "conftest.in" - cp "conftest.in" "conftest.nl" - $as_echo 'GREP' >> "conftest.nl" - "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break - diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break - ac_count=`expr $ac_count + 1` - if test $ac_count -gt ${ac_path_GREP_max-0}; then - # Best one so far, save it but keep looking for a better one - ac_cv_path_GREP="$ac_path_GREP" - ac_path_GREP_max=$ac_count - fi - # 10*(2^10) chars as input seems more than enough - test $ac_count -gt 10 && break - done - rm -f conftest.in conftest.tmp conftest.nl conftest.out;; -esac - - $ac_path_GREP_found && break 3 - done - done -done -IFS=$as_save_IFS - if test -z "$ac_cv_path_GREP"; then - { { $as_echo "$as_me:$LINENO: error: no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5 -$as_echo "$as_me: error: no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;} - { (exit 1); exit 1; }; } - fi -else - ac_cv_path_GREP=$GREP -fi - + ac_cv_lib_c_malloc=no fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_path_GREP" >&5 -$as_echo "$ac_cv_path_GREP" >&6; } - GREP="$ac_cv_path_GREP" - - -{ $as_echo "$as_me:$LINENO: checking for egrep" >&5 -$as_echo_n "checking for egrep... " >&6; } -if test "${ac_cv_path_EGREP+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 - then ac_cv_path_EGREP="$GREP -E" - else - if test -z "$EGREP"; then - ac_path_EGREP_found=false - # Loop through the user's path and test for each of PROGNAME-LIST - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in egrep; do - for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" - { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue -# Check for GNU ac_path_EGREP and select it if it is found. - # Check for GNU $ac_path_EGREP -case `"$ac_path_EGREP" --version 2>&1` in -*GNU*) - ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; -*) - ac_count=0 - $as_echo_n 0123456789 >"conftest.in" - while : - do - cat "conftest.in" "conftest.in" >"conftest.tmp" - mv "conftest.tmp" "conftest.in" - cp "conftest.in" "conftest.nl" - $as_echo 'EGREP' >> "conftest.nl" - "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break - diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break - ac_count=`expr $ac_count + 1` - if test $ac_count -gt ${ac_path_EGREP_max-0}; then - # Best one so far, save it but keep looking for a better one - ac_cv_path_EGREP="$ac_path_EGREP" - ac_path_EGREP_max=$ac_count - fi - # 10*(2^10) chars as input seems more than enough - test $ac_count -gt 10 && break - done - rm -f conftest.in conftest.tmp conftest.nl conftest.out;; -esac - $ac_path_EGREP_found && break 3 - done - done -done -IFS=$as_save_IFS - if test -z "$ac_cv_path_EGREP"; then - { { $as_echo "$as_me:$LINENO: error: no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5 -$as_echo "$as_me: error: no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;} - { (exit 1); exit 1; }; } - fi -else - ac_cv_path_EGREP=$EGREP +rm -rf conftest.dSYM +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS fi - - fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_c_malloc" >&5 +$as_echo "$ac_cv_lib_c_malloc" >&6; } +if test "x$ac_cv_lib_c_malloc" = x""yes; then + LIBS="-lc $LIBS" fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_path_EGREP" >&5 -$as_echo "$ac_cv_path_EGREP" >&6; } - EGREP="$ac_cv_path_EGREP" { $as_echo "$as_me:$LINENO: checking for ANSI C header files" >&5 @@ -4044,79 +4548,6 @@ _ACEOF fi -# On IRIX 5.3, sys/types and inttypes.h are conflicting. - - - - - - - - - -for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ - inttypes.h stdint.h unistd.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - 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 { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - eval "$as_ac_Header=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_Header=no" -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - @@ -4572,7 +5003,14 @@ done -for ac_func in dcgettext libintl_dgettext + + +for ac_func in \ + dcgettext \ + getline \ + libintl_dgettext \ + strsignal \ + do as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` { $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 @@ -4673,6 +5111,9 @@ fi done +test "$GCC" = yes && CFLAGS="-Wall $CFLAGS" + + @@ -4687,7 +5128,7 @@ done -ac_config_files="$ac_config_files Makefile ld-elf2flt elf2flt.ld" +ac_config_files="$ac_config_files ld-elf2flt.sh:ld-elf2flt.in Makefile elf2flt.ld" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -5298,8 +5739,8 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 for ac_config_target in $ac_config_targets do case $ac_config_target in + "ld-elf2flt.sh") CONFIG_FILES="$CONFIG_FILES ld-elf2flt.sh:ld-elf2flt.in" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; - "ld-elf2flt") CONFIG_FILES="$CONFIG_FILES ld-elf2flt" ;; "elf2flt.ld") CONFIG_FILES="$CONFIG_FILES elf2flt.ld" ;; *) { { $as_echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 diff --git a/configure.in b/configure.in index eb9733f..8c4ebdb 100644 --- a/configure.in +++ b/configure.in @@ -43,29 +43,48 @@ AC_ARG_WITH(binutils-build-dir, [ ac_binutils_build_dir=NONE ] ) +AC_ARG_ENABLE(ld-elf2flt-binary, + AS_HELP_STRING([--disable-ld-elf2flt-binary], [use ld-elf2flt shell script]), + [ use_ld_elf2flt_binary=$enableval ], + [ use_ld_elf2flt_binary=yes ] +) + +dnl convert a yes/no variable to 1/0 for C code +var_yn_to_10() { + if eval test \"\$$1\" = yes ; then + eval $1=1 + else + eval $1=0 + fi +} + AC_ARG_ENABLE(got-check, [ --disable-got-check - disable check for GOT (needed on H8) ], [ got_check=$enableval ], [ got_check=yes ] ) +var_yn_to_10 got_check AC_ARG_ENABLE(emit-relocs, [ --disable-emit-relocs - don't use the --emit-relocs (-q) linker option ], [ emit_relocs=$enableval ], [ emit_relocs=yes ] ) +var_yn_to_10 emit_relocs AC_ARG_ENABLE(emit-ctor-dtor, AS_HELP_STRING([--enable-emit-ctor-dtor], [manually create ctor/dtor list]), [ emit_ctor_dtor=$enableval ], [ emit_ctor_dtor=no ] ) +var_yn_to_10 emit_ctor_dtor AC_CANONICAL_HOST AC_CANONICAL_TARGET dnl Checks for programs. AC_PROG_CC +AC_USE_SYSTEM_EXTENSIONS AC_PROG_INSTALL if test "$ac_binutils_build_dir" != "NONE"; then @@ -143,7 +162,7 @@ fi SYMBOL_PREFIX= case $target in - bfin*) + h8300|bfin*) SYMBOL_PREFIX=_ ;; esac @@ -165,7 +184,14 @@ AC_C_CONST dnl Checks for library functions. AC_FUNC_VPRINTF -AC_CHECK_FUNCS(dcgettext libintl_dgettext) +AC_CHECK_FUNCS([ \ + dcgettext \ + getline \ + libintl_dgettext \ + strsignal \ +]) + +test "$GCC" = yes && CFLAGS="-Wall $CFLAGS" dnl Subsitute values AC_SUBST(target) @@ -177,10 +203,11 @@ AC_SUBST(bfd_include_dir) AC_SUBST(binutils_include_dir) AC_SUBST(zlib_include_dir) AC_SUBST(binutils_ldscript_dir) +AC_SUBST(use_ld_elf2flt_binary) AC_SUBST(got_check) AC_SUBST(emit_relocs) AC_SUBST(emit_ctor_dtor) AC_SUBST(SYMBOL_PREFIX) -AC_OUTPUT(Makefile ld-elf2flt elf2flt.ld) +AC_OUTPUT(ld-elf2flt.sh:ld-elf2flt.in Makefile elf2flt.ld) diff --git a/ld-elf2flt.c b/ld-elf2flt.c new file mode 100644 index 0000000..f9b0f1a --- /dev/null +++ b/ld-elf2flt.c @@ -0,0 +1,573 @@ +/* + * Wrapper for the real linker and the elf2flt converter. This was + * originally a simple shell script, but that doesn't work on a + * Windows host without cygwin. + * The proper long term solution is to add FLT as a BFD output format. + * + * Converted from ld-elf2flt.in by Nathan Sidwell, nathan@codesourcery.com. + * Updated to latest elf2flt code by Mike Frysinger, vapier@gentoo.org. + * + * This is Free Software, under the GNU General Public License V2 or greater. + * + * Copyright (C) 2006, CodeSourcery Inc. + * Copyright (C) 2009, Analog Devices, Inc. + * Copyright (C) 2002-2003 David McCullough + * Copyright (C) 2000, Lineo. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stubs.h" +const char *elf2flt_progname; + +static int flag_verbose = 0, flag_final = 1, have_elf2flt_options = 0, + flag_move_data = 0, want_shared = 0; +static const char *shared_lib_id = NULL; +static const char *output_file = "a.out"; +static const char *linker_script = NULL; +static const char *emulation = NULL; +static const char *tmp_file = NULL; +static const char *output_gdb = NULL; +static const char *output_elf = NULL; +static const char *output_flt = NULL; +static options_t search_dirs, all_options, other_options, flt_options; + +static const char *linker = NULL; +static const char *elf2flt = NULL; +static const char *nm = NULL; +static const char *objdump = NULL; +static const char *objcopy = NULL; +static const char *tooldir = "."; +static const char *ldscriptpath = BINUTILS_LDSCRIPTDIR; + +/* A list of sed commands */ +typedef struct { + options_t *pattern; /* '^' for start of line match, everything else verbatim */ + options_t *replacement; /* Delete line, if NULL */ +} sed_commands_t; + +/* Initialize a sed structure */ +#define init_sed(DST) ( \ + (DST)->pattern = xmalloc(sizeof(*(DST)->pattern)), \ + (DST)->replacement = xmalloc(sizeof(*(DST)->replacement)), \ + init_options((DST)->pattern), \ + init_options((DST)->replacement) \ +) +#define free_sed(DST) (free((DST)->pattern), free((DST)->replacement)) + +/* Append a slot for a new sed command. */ +static void append_sed(sed_commands_t *dst, const char *pattern, + const char *replacement) +{ + debug1("adding pattern '%s' with replacement '%s'\n", + pattern, replacement); + append_option(dst->pattern, pattern); + append_option(dst->replacement, replacement); +} + +/* Execute an external program COMMAND. Write its stdout to OUTPUT, + unless that is NULL. Pass the trailing NULL terminated list of + options, followed by all those in OPTIONS, if that is non-NULL. */ +static int +execute(const char *command, const char *output, const options_t *options, ...) +{ + struct pex_obj *pex; + const char *errmsg; + int err; + int status; + va_list args; + const char *opt; + options_t opts; + + debug("command=%s\n", command); + + init_options(&opts); + append_option(&opts, command); + va_start(args, options); + while ((opt = va_arg(args, const char *))) + append_option(&opts, opt); + va_end(args); + if (options) + append_options(&opts, options); + append_option(&opts, NULL); + + fflush(stdout); + fflush(stderr); + + pex = pex_init(0, elf2flt_progname, NULL); + if (pex == NULL) + fatal_perror("pex_init failed"); + + if (flag_verbose) { + unsigned ix; + + fprintf(stderr, "Invoking:"); + for (ix = 0; ix != opts.num - 1; ix++) + fprintf(stderr, " '%s'", opts.options[ix]); + fprintf(stderr, "\n"); + } + + errmsg = pex_run(pex, PEX_LAST | PEX_SEARCH, command, + (char *const *)opts.options, output, NULL, &err); + if (errmsg != NULL) { + if (err != 0) { + errno = err; + fatal_perror(errmsg); + } else + fatal(errmsg); + } + + if (!pex_get_status(pex, 1, &status)) + fatal_perror("can't get program status"); + pex_free(pex); + + if (status) { + if (WIFSIGNALED(status)) { + int sig = WTERMSIG(status); + + fatal("%s terminated with signal %d [%s]%s", + command, sig, strsignal(sig), + WCOREDUMP(status) ? ", core dumped" : ""); + } + + if (WIFEXITED(status)) + return WEXITSTATUS(status); + } + return 0; +} +/* Auto NULL terminate */ +#define execute(...) execute(__VA_ARGS__, NULL) + +/* Apply the sed commands in SED to file NAME_IN producing file NAME_OUT */ +static void +do_sed(const sed_commands_t *sed, const char *name_in, const char *name_out) +{ + FILE *in, *out; + size_t alloc = 0; + char *line = NULL; + ssize_t len; + const char *pattern, *replacement; + int ix; + + if (flag_verbose) { + fprintf(stderr, "emulating: sed \\\n"); + for (ix = 0; ix != sed->pattern->num; ix++) { + pattern = sed->pattern->options[ix]; + replacement = sed->replacement->options[ix]; + if (replacement) + fprintf(stderr, "\t-e 's/%s/%s/' \\\n", pattern, replacement); + else + fprintf(stderr, "\t-e 'd/%s/' \\\n", pattern); + } + fprintf(stderr, "\t%s > %s\n", name_in, name_out); + } + + in = xfopen(name_in, "r"); + out = xfopen(name_out, "w"); + + while ((len = getline(&line, &alloc, in)) > 0) { + debug2("len=%2zi line=%s", len, line); + + for (ix = 0; ix != sed->pattern->num; ix++) { + const char *ptr; + int bol; + size_t pat_len; + + pattern = sed->pattern->options[ix]; + replacement = sed->replacement->options[ix]; + ptr = line; + bol = pattern[0] == '^'; + + pattern += bol; + pat_len = strlen(pattern); + + if (!bol) { + do { + ptr = strchr(ptr, pattern[0]); + if (!ptr) ; + else if (!strncmp(ptr, pattern, pat_len)) + goto found; + else + ptr++; + } + while (ptr); + } else if (!strncmp(ptr, pattern, pat_len)) { + found: + if (replacement) { + debug2(" [modified]\n"); + fwrite(line, 1, ptr - line, out); + fwrite(replacement, 1, strlen(replacement), out); + fwrite(ptr + pat_len, 1, + len - pat_len - (ptr - line), + out); + } else + debug2(" {dropped}\n"); + goto next_line; + } + } + + debug2("(untouched)\n"); + fwrite(line, 1, len, out); + next_line: + ; + } + fclose(in); + if (fclose(out)) + fatal_perror("error writing temporary script '%s'", name_out); + free(line); +} + +/* Generate the flt binary along with any other necessary pieces. */ +#define exec_or_ret(...) \ + do { \ + int status = execute(__VA_ARGS__); \ + if (status) return status; \ + } while (0) +static int do_final_link(void) +{ + sed_commands_t sed; + struct stat buf; + const char *script; + const char *rel_output; + int have_got = 0; + FILE *in; + char *line = NULL; + size_t alloc = 0; + ssize_t len; + + init_sed(&sed); + + if (flag_move_data) { + FILE *in; + + /* See if the .rodata section contains any relocations. */ + if (!output_flt) + output_flt = make_temp_file(NULL); + exec_or_ret(linker, NULL, &other_options, "-r", "-d", "-o", output_flt); + exec_or_ret(objdump, tmp_file, NULL, "-h", output_flt); + + in = xfopen(tmp_file, "r"); + while ((len = getline(&line, &alloc, in)) > 0) { + const char *ptr = line; + + while (1) { + ptr = strchr(ptr, '.'); + if (!ptr) + break; + if (streqn(ptr, ".rodata")) { + getline(&line, &alloc, in); + ptr = line; + while (1) { + ptr = strchr(ptr, 'R'); + if (!ptr) + break; + if (streqn(ptr, "RELOC")) { + flag_move_data = 0; + fprintf(stderr, "warning: .rodata section contains relocations"); + break; + } else + ptr++; + } + break; + } else + ptr++; + } + } + fclose(in); + } + append_sed(&sed, "^R_RODAT", flag_move_data ? NULL : ""); + append_sed(&sed, "^W_RODAT", flag_move_data ? "" : NULL); + append_sed(&sed, "^SINGLE_LINK:", USE_EMIT_RELOCS ? "" : NULL); + append_sed(&sed, "^TOR:", EMIT_CTOR_DTOR ? "" : NULL); + + if (shared_lib_id) { + const char *got_offset; + int adj, id = strtol(shared_lib_id, NULL, 0); + char buf[30]; + + /* Replace addresses using the shared object id. */ + sprintf(buf, "%.2X", id); + append_sed(&sed, "ORIGIN = 0x0,", concat("ORIGIN = 0x", buf, "000000,", NULL)); + append_sed(&sed, ".text 0x0 :", concat(".text 0x0", buf, "000000 :", NULL)); + if (id) + append_sed(&sed, "ENTRY (" SYMBOL_PREFIX "_start)", "ENTRY (lib_main)"); + + /* Provide the symbol specifying the library's data segment + pointer offset. */ + adj = 4; + if (streq(TARGET_CPU, "h8300")) + got_offset = "__current_shared_library_er5_offset_"; + else if (streq(TARGET_CPU, "bfin")) + got_offset = "_current_shared_library_p5_offset_", adj = 1; + else + got_offset = "_current_shared_library_a5_offset_"; + append_option(&other_options, "-defsym"); + sprintf(buf, "%d", id * -adj - adj); + append_option(&other_options, concat(got_offset, "=", buf, NULL)); + } + + /* Locate the default linker script, if we don't have one provided. */ + if (!linker_script) + linker_script = concat(ldscriptpath, "/elf2flt.ld", NULL); + + /* Try and locate the linker script. */ + script = linker_script; + if (stat(script, &buf) || !S_ISREG(buf.st_mode)) { + script = concat(ldscriptpath, "/", linker_script, NULL); + if (stat(script, &buf) || !S_ISREG(buf.st_mode)) { + script = concat(ldscriptpath, "/ldscripts/", linker_script, NULL); + if (stat(script, &buf) || !S_ISREG(buf.st_mode)) + script = NULL; + } + } + /* And process it if we can -- if we can't find it, the user must + know what they are doing. */ + if (script) { + do_sed(&sed, linker_script, tmp_file); + linker_script = tmp_file; + } + free_sed(&sed); + + if (USE_EMIT_RELOCS) { + + exec_or_ret(linker, NULL, &other_options, + "-T", linker_script, "-q", "-o", output_gdb, emulation); + + append_option(&flt_options, "-a"); + rel_output = output_gdb; + + } else if (NO_GOT_CHECK) { + + output_elf = make_temp_file(NULL); + + exec_or_ret(linker, NULL, &other_options, + "-T", linker_script, "-Ur", "-d", "-o", output_elf, emulation); + exec_or_ret(linker, NULL, &other_options, + "-T", linker_script, "-o", output_gdb, emulation); + + rel_output = output_elf; + + } else { + + output_flt = make_temp_file(NULL); + exec_or_ret(linker, NULL, &other_options, + "-r", "-d", "-o", output_flt, emulation); + + output_elf = make_temp_file(NULL); + exec_or_ret(linker, NULL, &search_dirs, + "-T", linker_script, "-Ur", "-o", output_elf, output_flt, emulation); + + exec_or_ret(linker, NULL, &search_dirs, + "-T", linker_script, "-o", output_gdb, output_flt, emulation); + + rel_output = output_elf; + + } + + if (shared_lib_id && strtol(shared_lib_id, NULL, 0) != 0) + exec_or_ret(objcopy, NULL, NULL, "--localize-hidden", "--weaken", output_gdb); + + exec_or_ret(nm, tmp_file, NULL, "-p", output_gdb); + in = xfopen(tmp_file, "r"); + while ((len = getline(&line, &alloc, in)) > 0) { + const char *ptr = strchr(line, '_'); + if (ptr && streqn(ptr, "_GLOBAL_OFFSET_TABLE")) { + have_got = 1; + break; + } + } + fclose(in); + if (have_got) + exec_or_ret(elf2flt, NULL, &flt_options, + "-o", output_file, "-p", output_gdb, rel_output); + else + exec_or_ret(elf2flt, NULL, &flt_options, + "-o", output_file, "-r", rel_output); + + return 0; +} + +/* parse all the arguments provided to us */ +static void parse_args(int argc, char **argv) +{ + char *fltflags; + int argno; + + for (argno = 1; argno < argc; argno++) { + char const *arg = argv[argno]; + int to_all = argno; + + if (streq(arg, "-elf2flt")) { + have_elf2flt_options = 1; + to_all++; + } else if (streqn(arg, "-elf2flt=")) { + have_elf2flt_options = 1; + append_option_str(&flt_options, &arg[9], "\t "); + to_all++; + } else if (streq(arg, "-move-rodata")) { + flag_move_data = 1; + } else if (streq(arg, "-shared-lib-id")) { + shared_lib_id = argv[++argno]; + } else if (streq(arg, "-shared") || streq(arg, "-G")) { + want_shared = 1; + } else if (streqn(arg, "-o")) { + output_file = arg[2] ? &arg[2] : argv[++argno]; + } else if (streqn(arg, "-T")) { + linker_script = arg[2] ? &arg[2] : argv[++argno]; + } else if (streq(arg, "-c")) { + linker_script = argv[++argno]; + } else if (streqn(arg, "-L")) { + const char *merged = + (arg[2] ? arg : concat("-L", argv[++argno], NULL)); + append_option(&other_options, merged); + append_option(&search_dirs, merged); + } else if (streq(arg, "-EB")) { + append_option(&other_options, arg); + append_option(&search_dirs, arg); + } else if (streq(arg, "-relax")) { + ; + } else if (streq(arg, "-s") || streq(arg, "--strip-all") || + streq(arg, "-S") || streq(arg, "--strip-debug")) { + /* Ignore these strip options for links involving elf2flt. + The final flat output will be stripped by definition, and we + don't want to strip the .gdb helper file. The strip options + are also incompatible with -r and --emit-relocs. */ + ; + } else if (streq(arg, "-r") || streq(arg, "-Ur")) { + flag_final = 0; + append_option(&other_options, arg); + } else if (streq(arg, "-v") || streq(arg, "--verbose")) { + flag_verbose = 1; + append_option(&other_options, arg); + } else if (streqn(arg, "-m")) { + emulation = arg[2] ? arg : concat("-m", argv[++argno], NULL); + } else + append_option(&other_options, arg); + + while (to_all <= argno) + append_option(&all_options, argv[to_all++]); + } + + fltflags = getenv("FLTFLAGS"); + if (fltflags) + append_option_str(&flt_options, fltflags, "\t "); +} + +int main(int argc, char *argv[]) +{ + const char *ptr; + char *tmp; + const char *argv0 = argv[0]; + size_t len; + struct stat buf; + const char *have_exe = NULL; + int status; + + len = strlen(argv0); +#ifdef __WIN32 + /* Remove the .exe extension, if it's there. */ + if (len > 4 && streq(&argv0[len - 4], ".exe")) { + have_exe = ".exe"; + len -= 4; + argv0 = tmp = xstrdup(argv0); + tmp[len] = 0; + } +#endif + elf2flt_progname = argv0; + for (ptr = elf2flt_progname + len; ptr != elf2flt_progname; ptr--) + if (IS_DIR_SEPARATOR(ptr[-1])) { + tooldir = tmp = xmalloc(len); + memcpy(tmp, argv0, len); + tmp[ptr - elf2flt_progname - 1] = 0; + elf2flt_progname = ptr; + /* The standard binutils tool layout has: + + bin/-foo + lib/ + /bin/foo + /lib + + It's / that we want here: files in lib/ are for + the host while those in /lib are for the target. */ + if (streqn(elf2flt_progname, TARGET_ALIAS)) { + tmp = concat(tooldir, "/../" TARGET_ALIAS "/bin", NULL); + if (stat(tmp, &buf) == 0 && S_ISDIR(buf.st_mode)) + tooldir = tmp; + } + break; + } + /* Typically ld-elf2flt is invoked as `ld` which means error + * messages from it will look like "ld: " which is completely + * confusing. So append an identifier to keep things clear. + */ + elf2flt_progname = concat(elf2flt_progname, " (ld-elf2flt)", NULL); + + xmalloc_set_program_name(elf2flt_progname); + + tmp = xmalloc(len + 16); + memcpy(tmp, argv0, len); + while (len && tmp[len - 1] != '-' && !IS_DIR_SEPARATOR(tmp[len - 1])) + len--; + tmp[len] = 0; + + linker = concat(tmp, "ld.real", have_exe, NULL); + elf2flt = concat(tmp, "elf2flt", have_exe, NULL); + nm = concat(tmp, "nm", have_exe, NULL); + objdump = concat(tooldir, "/../../bin/", TARGET_ALIAS, "-objdump", have_exe, NULL); + objcopy = concat(tooldir, "/../../bin/", TARGET_ALIAS, "-objcopy", have_exe, NULL); + + if (stat(ldscriptpath, &buf) || !S_ISDIR(buf.st_mode)) + ldscriptpath = concat(tooldir, "/../lib", NULL); + + parse_args(argc, argv); + + if (flag_verbose) { + fprintf(stderr, "argv[0] = '%s'\n", argv[0]); + fprintf(stderr, "tooldir = '%s'\n", tooldir); + fprintf(stderr, "linker = '%s'\n", linker); + fprintf(stderr, "elf2flt = '%s'\n", elf2flt); + fprintf(stderr, "nm = '%s'\n", nm); + fprintf(stderr, "objdump = '%s'\n", objdump); + fprintf(stderr, "objcopy = '%s'\n", objcopy); + fprintf(stderr, "ldscriptpath = '%s'\n", ldscriptpath); + } + + /* Pass off to regular linker, if there's nothing elf2flt-like */ + if (!have_elf2flt_options) + return execute(linker, NULL, &all_options); + + /* Pass off to regular linker, minus the elf2flt options, if it's + not the final link. */ + if (!flag_final) + return execute(linker, NULL, &other_options, "-o", output_file); + + if (want_shared && !shared_lib_id) + fatal("-shared used without passing a shared library ID"); + + /* Otherwise link & convert to flt. */ + output_gdb = concat(output_file, ".gdb", NULL); + tmp_file = make_temp_file(NULL); + status = do_final_link(); + if (!flag_verbose) { + unlink(tmp_file); + unlink(output_flt); + unlink(output_elf); + } else { + fprintf(stderr, + "leaving elf2flt temp files behind:\n" + "tmp_file = %s\n" + "output_flt = %s\n" + "output_elf = %s\n", + tmp_file, output_flt, output_elf); + } + return status; +} diff --git a/ld-elf2flt.in b/ld-elf2flt.in index 5671da0..fd1faed 100644 --- a/ld-elf2flt.in +++ b/ld-elf2flt.in @@ -149,13 +149,13 @@ then esac ARG1="$ARG1 -defsym $GOT_OFFSET=`expr ${SHARED_ID} '*' -${GOT_ADJ} - ${GOT_ADJ}`" fi - if [ "@emit_relocs@" = "yes" ] + if [ "@emit_relocs@" = "1" ] then SEDOP="$SEDOP -e s/^SINGLE_LINK://" else SEDOP="$SEDOP -e /^SINGLE_LINK:/d" fi - if [ "@emit_ctor_dtor@" = "yes" ] + if [ "@emit_ctor_dtor@" = "1" ] then SEDOP="$SEDOP -e s/^TOR://" else @@ -178,13 +178,13 @@ then LDSCRIPT="$NEWLDSCRIPT" fi - if [ "@emit_relocs@" = "yes" ] + if [ "@emit_relocs@" = "1" ] then $LINKER $EMUL $SDIRS -T $LDSCRIPT -q -o "$OFILE.gdb" $ARG1 ||exit $? RFILE="$OFILE.gdb" FLTFLAGS="$FLTFLAGS -a" else - if [ "@got_check@" = "no" ] + if [ "@got_check@" = "0" ] then $LINKER $EMUL $SDIRS -T $LDSCRIPT -Ur -d -o "$OFILE.elf" $ARG1 ||exit $? $LINKER $EMUL $SDIRS -T $LDSCRIPT -o "$OFILE.gdb" $ARG1 ||exit $? diff --git a/stubs.c b/stubs.c index 53a93aa..696ed3b 100644 --- a/stubs.c +++ b/stubs.c @@ -22,6 +22,33 @@ const char *libintl_dgettext(const char *domain, const char *msg) } #endif /* !HAVE_LIBINTL_DGETTEXT */ +#ifndef HAVE_GETLINE +/* Read a line from IN. LINE points to a malloc'd buffer that is extended as + necessary. ALLOC points to the allocated length of LINE. Returns + the length of the string read (including any trailing \n) */ + +ssize_t getline(char **line, size_t *alloc, FILE *in) +{ + size_t len = 0; + + if (!*alloc) { + *alloc = 200; + *line = xmalloc(*alloc); + } + + while (1) { + if (!fgets(*line + len, *alloc - len, in)) + return 0; + len += strlen(*line + len); + if (len && (*line)[len - 1] == '\n') + return len; + + *alloc *= 2; + *line = xrealloc(*line, *alloc); + } +} +#endif + /* fatal error & exit */ void fatal(const char *format, ...) { @@ -48,3 +75,59 @@ void fatal_perror(const char *format, ...) va_end(args); exit(1); } + +/* open a file or fail */ +FILE *xfopen(const char *path, const char *mode) +{ + FILE *ret = fopen(path, mode); + if (!ret) + fatal_perror("Unable to open '%s'", path); + return ret; +} + +/* Append a string SRC to an options array DST */ +void append_option(options_t *dst, const char *src) +{ + if (dst->alloc == dst->num) { + size_t a = (dst->num + 2) * 2; + void *o = xmalloc(sizeof(*dst->options) * a); + + memcpy(o, dst->options, sizeof(*dst->options) * dst->num); + free(dst->options); + dst->options = o; + dst->alloc = a; + } + + dst->options[dst->num] = src; + dst->num++; +} + +/* Split and append a string SRC to an options array DST */ +void append_option_str(options_t *dst, const char *src, const char *delim) +{ + char *tok_src = xstrdup(src); + char *tok = strtok(tok_src, delim); + while (tok) { + append_option(dst, tok); + tok = strtok(NULL, delim); + } + /* don't free tok_src since options_t now points to it */ +} + +/* Append an options array SRC to another options array DST */ +void append_options(options_t *dst, const options_t *src) +{ + if (dst->alloc < dst->num + src->num) { + size_t a = (dst->num + src->num + 2) * 2; + void *o = xmalloc(sizeof(*dst->options) * a); + + memcpy(o, dst->options, sizeof(*dst->options) * dst->num); + free(dst->options); + dst->options = o; + dst->alloc = a; + } + + memcpy(&dst->options[dst->num], &src->options[0], + sizeof(*dst->options) * src->num); + dst->num += src->num; +} diff --git a/stubs.h b/stubs.h index 493ff73..7e5308d 100644 --- a/stubs.h +++ b/stubs.h @@ -32,7 +32,44 @@ # define strsignal(sig) "SIG???" #endif +#define streq(str1, str2) (strcmp(str1, str2) == 0) +#define streqn(str1, str2) (strncmp(str1, str2, strlen(str2)) == 0) + +#ifndef DEBUG +# define DEBUG -1 +#endif +#define _debug(lvl, fmt, args...) \ + do { \ + if (lvl <= DEBUG) { \ + fprintf(stderr, "%s:%i: " fmt, __func__, __LINE__, ## args); \ + fflush(stderr); \ + } \ + } while (0) +#define debug2(...) _debug(2, __VA_ARGS__) +#define debug1(...) _debug(1, __VA_ARGS__) +#define debug0(...) _debug(0, __VA_ARGS__) +#define debug(...) debug0(__VA_ARGS__) + +#ifndef HAVE_GETLINE +ssize_t getline(char **line, size_t *alloc, FILE *in); +#endif + extern const char *elf2flt_progname; void fatal(const char *, ...); void fatal_perror(const char *, ...); + +FILE *xfopen(const char *path, const char *mode); + +/* Structure to hold a list of options */ +typedef struct +{ + const char **options; + size_t num; + size_t alloc; +} options_t; +/* Initialize an options structure */ +#define init_options(DST) ((DST)->options = NULL, (DST)->num = (DST)->alloc = 0) +void append_options(options_t *dst, const options_t *src); +void append_option(options_t *dst, const char *src); +void append_option_str(options_t *dst, const char *src, const char *delim); -- 2.39.5