From: Alexandre Oliva Date: Sun, 3 Mar 2002 01:22:40 +0000 (+0000) Subject: the compile portion of the binary version seems to work X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=152c936ef59d30d8c0f2731ab5d5daadb8705d06;p=thirdparty%2Flibtool.git the compile portion of the binary version seems to work --- diff --git a/exe/Makefile b/exe/Makefile index d98dbee70..fb74eac36 100644 --- a/exe/Makefile +++ b/exe/Makefile @@ -5,4 +5,4 @@ TPL = base-txt.tpl clean-txt.tpl compile-txt.tpl execute-txt.tpl \ DEF = ltstr.def newltmain.in : $(TPL) $(DEF) $(MTPL) - autogen -T ltmain.tpl -l ltmacros.tpl ltstr.def + autogen -T ltmain.tpl -l ltmacros.tpl -DSCRIPT=1 ltstr.def diff --git a/exe/compile-txt.tpl b/exe/compile-txt.tpl index 2ae5d22dd..907eca818 100644 --- a/exe/compile-txt.tpl +++ b/exe/compile-txt.tpl @@ -1,4 +1,5 @@ [++ AutoGen5 Template ++] +[++ IF (getenv "SCRIPT") ++] # Get the compilation command and the source file. base_compile= prev= @@ -147,7 +148,7 @@ no_help = true ++] ;; esac - +[++ ENDIF (getenv "SCRIPT") ++] # Recognize several different file suffixes. # If the user specifies -o file.o, it is replaced with file.lo xform='[cCFSifmso]' diff --git a/exe/ltcompile.c b/exe/ltcompile.c index b1a828563..9434d9ec0 100644 --- a/exe/ltcompile.c +++ b/exe/ltcompile.c @@ -23,17 +23,171 @@ * the same distribution terms that you use for the rest of that program. */ +#include #include /* printf */ #include /* exit */ #include #include #include +#include #include #include #include "ltopts.h" #include "ltstr.h" +static char* pzTarget = NULL; +static char* pzSource = NULL; +static int oldLibs = 0; +static char* pzPicMode = "default"; +static int xCompile = 0; + +static void* +xmalloc( size_t s ) +{ + void* p = malloc( s ); + if (p == NULL) { + fprintf( stderr, "%s error: cannot allocate %d bytes\n", + libtoolOptions.pzProgPath ); + exit( EXIT_FAILURE ); + } + return p; +} + +tCC* +makeShellSafe( pzArg ) + tCC* pzArg; +{ + tSCC zSpecial[] = "\\\"$`[~#^&*(){}|;<>?' \t|]"; + tSCC* pzProt = zSpecial + 4; + + size_t len = strlen( pzArg ); + char* pz; + + if (strcspn( pzArg, zSpecial ) == len) + return pzArg; + + pz = strchr( pzArg, '\'' ); + if (pz == NULL) + return pzArg; + + do { + len += 3; + pz = strchr( pz+1, '\'' ); + } while (pz != NULL); + + { + char* pzRes = malloc( len + 1 ); + pz = pzRes; + for (;;) { + char ch = *(pzArg++); + *(pz++) = ch; + + switch (ch) { + case '\0': + goto scan_done; + + case '\'': + do { + strcpy( pz, "\\'" ); + pz += 2; + } while (*pzArg == '\''); + *(pz++) = '\''; + break; + + default: + break; + } + } scan_done:; + + return pzRes; + } +} + + +static void +parseCompileOpts( pArgc, pArgv ) + int* pArgc; + char*** pArgv; +{ + tSCC zTooManyTargets[] = + "%s compile: you cannot specify `-o' more than once\n"; + tSCC zNoTarget[] = + "%s compile: `-o' must specify an output file name\n"; + tSCC zNoXcompile[] = + "%s compile: `-Xcompiler' must specify a cross compiler\n"; + tSCC zEarlyOpts[] = + "%s compile: error: you cannot supply options before the command\n"; + + int argc = *pArgc; + char** argv = *pArgv; + + tCC** newArgv = xmalloc( sizeof( char* ) * (argc + 1) ); + int newCt = 0; + + tCC* pzCmd = NULL; + int i; + + for (i=0; i 0) { - fputc( ' ', fp ); - emitShellArg( *(++argv), fp ); + fprintf( fp, "build_old_libs=%s\n", oldLibs ? "yes" : "no" ); + CKSERV; + + fprintf( fp, "pic_mode=%s\n", pzPicMode ); + CKSERV; + + fputs( "base_compile='", fp ); + for (;;) { + fputs( *(argv++), fp ); CKSERV; + if (--argc <= 0) + break; + fputc( ' ', fp ); } - fputc( '\n', fp ); - fflush( fp ); - CKSERV; + { + struct stat stbf; - /* - * Up to now, we are just initializing variables. Here, we write - * a large chunk of text to the pipe and the shell may exit before - * we are done. If that happens, we get a SIGPIPE. The `CLOSEOK' - * macro will detect that, call closeScript() and return so as to - * avoid segfaults and more SIGPIPEs. - */ - fputs( apz_mode_cmd[ OPT_VALUE_MODE ], fp ); - CLOSEOK; + if (stat( pzSource, &stbf ) != 0) do { + char* pz = getenv( "source" ); + if ( (pz != NULL) + && (stat( pz, &stbf ) == 0)) { + pzSource = pz; + break; + } + + pz = getenv( "srcdir" ); + if (pz == NULL) + pz = getenv( "VPATH" ); - fputc( '\n', fp ); - CLOSEOK; + if (pz != NULL) { + char* p = xmalloc( strlen( pz ) + strlen( pzSource ) + 2 ); + sprintf( p, "%s/%s", pz, pzSource ); + if (stat( p, &stbf ) == 0) + pzSource = p; + else + free( p ); + } + } while (0); - fflush( fp ); + fprintf( fp, "'\nsrcfile='%s'\n", pzSource ); + } - if (fp != stdout) - closeScript( fp ); + emitCommands( fp, apz_mode_cmd[ OPT_VALUE_MODE ]); } +/* + * Local Variables: + * c-file-style: "stroustrup" + * indent-tabs-mode: nil + * End: + * end of ltcompile.c */ diff --git a/exe/ltconfig.x b/exe/ltconfig.x index d04c550d3..6587e7b71 100644 --- a/exe/ltconfig.x +++ b/exe/ltconfig.x @@ -16,18 +16,17 @@ #define LIBTOOL_CONFIG_TEXT 1 static const char z_ltconfig[] = "\n\ -LTCONFIG_VERSION=\"1.4a\"\n\ +SED=sed\n\ SHELL=\"/bin/sh\"\n\ build_libtool_libs=yes\n\ -build_libtool_need_lc=yes\n\ build_old_libs=yes\n\ +build_libtool_need_lc=no\n\ fast_install=yes\n\ -host_alias=i586-pc-linux-gnu\n\ -host=i586-pc-linux-gnu\n\ +host_alias=\n\ +host=i686-pc-linux-gnu\n\ echo=\"echo\"\n\ AR=\"ar\"\n\ AR_FLAGS=\"cru\"\n\ -LTCC=\"gcc\"\n\ CC=\"gcc\"\n\ with_gcc=yes\n\ LD=\"/usr/i486-suse-linux/bin/ld\"\n\ @@ -45,16 +44,16 @@ wl=\"-Wl,\"\n\ objext=\"o\"\n\ libext=\"a\"\n\ exeext=\"\"\n\ -pic_flag=\" -fPIC -DPIC\"\n\ +pic_flag=\" -fPIC\"\n\ pic_mode=default\n\ -max_cmd_len=73729\n\ compiler_c_o=\"yes\"\n\ +compiler_o_lo=\"yes\"\n\ need_locks=\"no\"\n\ need_lib_prefix=no\n\ need_version=no\n\ -dlopen_support=yes\n\ -dlopen_self=yes\n\ -dlopen_self_static=no\n\ +dlopen_support=unknown\n\ +dlopen_self=unknown\n\ +dlopen_self_static=unknown\n\ link_static_flag=\"-static\"\n\ no_builtin_flag=\" -fno-builtin -fno-rtti -fno-exceptions\"\n\ export_dynamic_flag_spec=\"\\${wl}--export-dynamic\"\n\ @@ -76,19 +75,15 @@ postinstall_cmds=\"\"\n\ postuninstall_cmds=\"\"\n\ old_striplib=\"strip --strip-debug\"\n\ striplib=\"strip --strip-unneeded\"\n\ -predep_objects=\"\"\n\ -postdep_objects=\"\"\n\ -predeps=\"\"\n\ -postdeps=\"\"\n\ -compiler_lib_search_path=\"\"\n\ deplibs_check_method=\"pass_all\"\n\ -file_magic_cmd=\"\"\n\ +file_magic_cmd=\"\\$MAGIC_CMD\"\n\ allow_undefined_flag=\"\"\n\ no_undefined_flag=\"\"\n\ finish_cmds=\"PATH=\\\\\\\"\\\\\\$PATH:/sbin\\\\\\\" ldconfig -n \\$libdir\"\n\ finish_eval=\"\"\n\ -global_symbol_pipe=\"sed -n -e 's/^.*[ ]\\\\([ABCDGISTW][ABCDGISTW]*\\\\)[ ][ ]*\\\\(\\\\)\\\\([_A-Za-z][_A-Za-z0-9]*\\\\)\\$/\\\\1 \\\\2\\\\3 \\\\3/p'\"\n\ +global_symbol_pipe=\"sed -n -e 's/^.*[ \t]\\\\([ABCDGISTW][ABCDGISTW]*\\\\)[ \t][ \t]*\\\\(\\\\)\\\\([_A-Za-z][_A-Za-z0-9]*\\\\)\\$/\\\\1 \\\\2\\\\3 \\\\3/p'\"\n\ global_symbol_to_cdecl=\"sed -n -e 's/^. .* \\\\(.*\\\\)\\$/extern char \\\\1;/p'\"\n\ +global_symbol_to_c_name_address=\"sed -n -e 's/^: \\\\([^ ]*\\\\) \\$/ {\\\\\\\"\\\\1\\\\\\\", (lt_ptr) 0},/p' -e 's/^[BCDEGRST] \\\\([^ ]*\\\\) \\\\([^ ]*\\\\)\\$/ {\\\"\\\\2\\\", (lt_ptr) \\\\&\\\\2},/p'\"\n\ runpath_var=LD_RUN_PATH\n\ shlibpath_var=LD_LIBRARY_PATH\n\ shlibpath_overrides_runpath=no\n\ @@ -108,7 +103,23 @@ always_export_symbols=no\n\ export_symbols_cmds=\"\\$NM \\$libobjs \\$convenience | \\$global_symbol_pipe | sed 's/.* //' | sort | uniq > \\$export_symbols\"\n\ extract_expsyms_cmds=\"\"\n\ exclude_expsyms=\"_GLOBAL_OFFSET_TABLE_\"\n\ -include_expsyms=\"\"\n"; +include_expsyms=\"\"\n\ +exec_cmd=\n\ +Xsed='sed -e 1s/^X//'\n\ +sed_quote_subst='$sed_quote_subst'\n\ +relink_command=\\\"$relink_command\\\"\n\ +dlname='$tdlname'\n\ +library_names='$library_names'\n\ +old_library='$old_library'\n\ +dependency_libs='$dependency_libs'\n\ +current=$current\n\ +age=$age\n\ +revision=$revision\n\ +installed=$installed\n\ +dlopen='$dlfiles'\n\ +dlpreopen='$dlprefiles'\n\ +libdir='$install_libdir'\"\n\ +relink_command=\\\"$relink_command\\\"\"\n"; const char* pz_ltconfig = z_ltconfig; const char* pz_shell = "/bin/sh"; diff --git a/exe/ltexe.c b/exe/ltexe.c index 7e5de5445..49dd3b1f4 100644 --- a/exe/ltexe.c +++ b/exe/ltexe.c @@ -149,25 +149,11 @@ else echo='%s --echo --' ; fi\n"; CKSERV; } - fputc( '\n', fp ); - fflush( fp ); - CKSERV; - - /* - * Up to now, we are just initializing variables. Here, we write - * a large chunk of text to the pipe and the shell may exit before - * we are done. If that happens, we get a SIGPIPE. The `CLOSEOK' - * macro will detect that, call closeScript() and return so as to - * avoid segfaults and more SIGPIPEs. - */ - fputs( apz_mode_cmd[ OPT_VALUE_MODE ], fp ); - CLOSEOK; - - fputc( '\n', fp ); - CLOSEOK; - - fflush( fp ); - - if (fp != stdout) - closeScript( fp ); + emitCommands( fp, apz_mode_cmd[ OPT_VALUE_MODE ]); } +/* + * Local Variables: + * c-file-style: "stroustrup" + * indent-tabs-mode: nil + * End: + * end of ltcompile.c */ diff --git a/exe/ltmain.c b/exe/ltmain.c index 278e497a4..aca0da122 100644 --- a/exe/ltmain.c +++ b/exe/ltmain.c @@ -350,6 +350,13 @@ else echo='%s --echo --' ; fi\n"; CKSERV; } + emitCommands( fp, apz_mode_cmd[ OPT_VALUE_MODE ]); +} + + +void +emitCommands( FILE* fp, tCC* pzCmds ) +{ fputc( '\n', fp ); fflush( fp ); CKSERV; @@ -361,27 +368,9 @@ else echo='%s --echo --' ; fi\n"; * macro will detect that, call closeScript() and return so as to * avoid segfaults and more SIGPIPEs. */ - fputs( apz_mode_cmd[ OPT_VALUE_MODE ], fp ); + fputs( pzCmds, fp ); CLOSEOK; - /* - * Now all the commands have run. Sometimes, however, the operation - * is deferred by putting the command to run into an environment variable - * and eval-ing it at the end. So, emit some code that verifies that - * if the shell is still interpreting text, then "exec_cmd" is not empty. - */ - { - tSCC z[] = - "if test -z \"${exec_cmd}\"\nthen\n" - " $echo $modename: 'invalid operation mode: `$mode'\\' 1>&2\n" - " $echo 'Try `%s --help'\\' for more information 1>&2\nfi\n" - "eval exec $exec_cmd\nexit 1\n"; - fprintf( fp, z, libtoolOptions.pzProgName ); - CLOSEOK; - - fflush( fp ); - } - if (fp != stdout) closeScript( fp ); } @@ -488,3 +477,9 @@ main( argc, argv ) return scriptStatus; } +/* + * Local Variables: + * c-file-style: "stroustrup" + * indent-tabs-mode: nil + * End: + * end of ltmain.c */ diff --git a/exe/ltmain.mk b/exe/ltmain.mk index beb73c8a1..cd56ecce9 100644 --- a/exe/ltmain.mk +++ b/exe/ltmain.mk @@ -18,7 +18,7 @@ clean : rm -rf .libs lt*.o ltmain libtool $(GENED) *~ ltmain.in : $(TXTTPL) ltstr.def - autogen -T ltmain.tpl -l ltmacros.tpl ltstr.def + autogen -T ltmain.tpl -l ltmacros.tpl -DSCRIPT=1 ltstr.def ltstr.c : ltstr.def ltstr.tpl ltmacros.tpl autogen -T ltstr.tpl -l ltmacros.tpl ltstr.def diff --git a/exe/ltmain.tpl b/exe/ltmain.tpl index 85f905cd6..20c9149aa 100644 --- a/exe/ltmain.tpl +++ b/exe/ltmain.tpl @@ -291,6 +291,7 @@ if test -z "$show_help"; then # libtool compile mode compile) modename="$modename: compile" + [= INCLUDE "compile-txt.tpl" =] exit 0 diff --git a/exe/ltstr.def b/exe/ltstr.def index 25caa6b6a..7131ce7c2 100644 --- a/exe/ltstr.def +++ b/exe/ltstr.def @@ -3,10 +3,13 @@ AutoGen Definitions ltmain.tpl; string = { str-name = base; + continues; }; string = { str-name = clean; + end-exits = '$exit_status'; + explain = " is the name of the program to use to delete files associated with each FILE (typically `/bin/rm'). `-s' are options (such as `-f') @@ -20,6 +23,7 @@ the file itself is deleted using .\n"; string = { str-name = compile; call-proc = emitCompile; + end-exits = "0"; explain = " Compile a source file into a libtool library object.\n @@ -53,6 +57,8 @@ Then, is executed, with `...' as arguments.\n"; string = { str-name = finish; + end-exits = "0"; + explain = " Complete the installation of libtool libraries.\n The -s must actually be directories that contain @@ -73,6 +79,8 @@ It should be either the `install' or `cp' program.\n string = { str-name = link; + end-exits = "0"; + explain = " Link object files or libraries together to form another library, or to create an executable program.\n @@ -117,6 +125,7 @@ is created, otherwise an executable program is created.\n"; string = { str-name = uninstall; + end-exits = '$exit_status'; use_explain = clean; use_cmd = clean; }; diff --git a/exe/ltstr.tpl b/exe/ltstr.tpl index 022fec831..87e0609ed 100644 --- a/exe/ltstr.tpl +++ b/exe/ltstr.tpl @@ -85,6 +85,19 @@ tSCC [= (. cmd-str) =][] =[= (set! cmd-list (string-append cmd-list cmd-str "\n")) (out-push-new) (. tpl-name) =][= + + IF (exist? "end-exits") =] + exit [= end-exits =][= + ELIF (not (exist? "continues")) =] +if test -z "${exec_cmd}" +then + $echo $modename: 'invalid operation mode: `'$mode\' 1>&2 + $echo 'Try `ltmain --help'\' for more information 1>&2 +fi +eval exec $exec_cmd +exit 1[= + ENDIF =] +[= (kr-string (out-pop #t)) =]; @@ -143,6 +156,7 @@ extern void closeScript LT_PARAMS(( FILE* fp )); extern void modalUsage LT_PARAMS(( tOptions* pOpts, int exitCode )); extern void emitShellQuoted LT_PARAMS(( tCC* pzArg, FILE* outFp )); extern void emitShellArg LT_PARAMS(( tCC* pzArg, FILE* outFp )); +extern void emitCommands LT_PARAMS(( FILE* fp, tCC* pzCmds )); #endif /* [=(. header-guard)=] */[=