]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
the compile portion of the binary version seems to work
authorAlexandre Oliva <aoliva@redhat.com>
Sun, 3 Mar 2002 01:22:40 +0000 (01:22 +0000)
committerBruce Korb <bkorb@gnu.org>
Sun, 3 Mar 2002 01:22:40 +0000 (01:22 +0000)
exe/Makefile
exe/compile-txt.tpl
exe/ltcompile.c
exe/ltconfig.x
exe/ltexe.c
exe/ltmain.c
exe/ltmain.mk
exe/ltmain.tpl
exe/ltstr.def
exe/ltstr.tpl

index d98dbee70c8c90382e67ddd035a210fbd8831b64..fb74eac36ac9c45555bff5f061f8774241e4abbd 100644 (file)
@@ -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
index 2ae5d22dd7d781042fb58a98fff6449f8af48814..907eca818587c2e6fa4e7fbef333ce765d13bb84 100644 (file)
@@ -1,4 +1,5 @@
 [++ AutoGen5 Template ++]
+[++ IF (getenv "SCRIPT") ++]
     # Get the compilation command and the source file.
     base_compile=
     prev=
           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]'
index b1a82856313d2d1ee420b3eac42a30ff91623fa4..9434d9ec0d5d5d9ed2f4dc1f57afc7c9f4bfb17f 100644 (file)
  * the same distribution terms that you use for the rest of that program.
  */
 
+#include <sys/types.h>
 #include <stdio.h>              /* printf */
 #include <stdlib.h>             /* exit */
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
+#include <sys/stat.h>
 #include <sys/wait.h>
 #include <signal.h>
 
 #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<argc; i++) {
+        if (strncmp( argv[i], "-o", 2 ) == 0) {
+            if (pzTarget != NULL) {
+                fprintf( stderr, zTooManyTargets, libtoolOptions.pzProgPath );
+                exit( EXIT_FAILURE );
+            }
+            if (argv[i][2] != '\0')
+                pzTarget = (argv[i]) + 2;
+            else {
+                pzTarget = argv[ ++i ];
+                if (pzTarget == NULL) {
+                    fprintf( stderr, zNoTarget, libtoolOptions.pzProgPath );
+                    exit( EXIT_FAILURE );
+                }
+            }
+
+        } else if (strcmp( argv[i], "-static"         ) == 0) {
+            oldLibs = 1;
+
+        } else if (strcmp( argv[i], "-prefer-pic"     ) == 0) {
+            pzPicMode = "yes";
+
+        } else if (strcmp( argv[i], "-prefer-non-pic" ) == 0) {
+            pzPicMode = "no";
+
+        } else if (strcmp( argv[i], "-Xcompiler"      ) == 0) {
+            if (argv[++i] == NULL) {
+                fprintf( stderr, zNoXcompile, libtoolOptions.pzProgPath );
+                exit( EXIT_FAILURE );
+            }
+            pzCmd = newArgv[ newCt++ ] = makeShellSafe( argv[i] );
+
+        } else if (argv[i][0] == '-') {
+            if (pzCmd == NULL) {
+                fprintf( stderr, zEarlyOpts, libtoolOptions.pzProgPath );
+                exit( EXIT_FAILURE );
+            }
+            newArgv[ newCt++ ] = makeShellSafe( argv[i] );
+
+        } else if (pzCmd == NULL) {
+            pzCmd = newArgv[ newCt++ ] = makeShellSafe( argv[i] );
+
+        } else {
+            if (pzSource != NULL)
+                newArgv[ newCt++ ] = makeShellSafe( pzSource );
+            pzSource = argv[i];
+        }
+    }
+
+    if (pzSource == NULL) {
+        fprintf( stderr, "%s compile: error: no source file to compile\n",
+                 libtoolOptions.pzProgName );
+        exit( EXIT_FAILURE );
+    }
+
+    newArgv[ newCt ] = NULL;
+    *pArgc = newCt;
+    *pArgv = (char**)newArgv;
+}
+
 
     void
 emitCompile( argc, argv )
@@ -72,6 +226,8 @@ else  echo='%s --echo --' ; fi\n";
 
 #    define CLOSEOK if (signalReceived != 0) { closeScript( fp ); return; }
 
+    parseCompileOpts( &argc, &argv );
+
     /*
      *  Emit the default configuration set up at program configuration time
      */
@@ -89,10 +245,11 @@ else  echo='%s --echo --' ; fi\n";
      *  IF we have DYNAMIC or STATIC, then we override the configured
      *  values.  We emitted the configured values with `z_ltconfig'.
      */
-    if (HAVE_OPT( DYNAMIC ))
+    if (HAVE_OPT( DYNAMIC ) && (oldLibs == 0))
         fprintf( fp, zDynFmt, ENABLED_OPT( DYNAMIC ) ? "yes" : "no" );
-    if (HAVE_OPT( STATIC ))
-        fprintf( fp, zStatic, ENABLED_OPT( STATIC )  ? "yes" : "no" );
+    if (HAVE_OPT( STATIC ) || oldLibs)
+        fprintf( fp, zStatic, ENABLED_OPT( STATIC )
+                 ? "yes" : (oldLibs ? "yes" : "no") );
 
     if (HAVE_OPT( DEBUG )) {
         fprintf( stderr, "%s: enabling shell trace mode\n",
@@ -120,45 +277,70 @@ else  echo='%s --echo --' ; fi\n";
      *  that one of the command scripts depends upon.
      */
     fprintf( fp, zModeName, libtoolOptions.pzProgName,
-            libtoolOptions.pOptDesc[ OPT_VALUE_MODE ].pz_Name );
+             libtoolOptions.pOptDesc[ OPT_VALUE_MODE ].pz_Name );
     CKSERV;
     fprintf( fp, zMode, libtoolOptions.pzProgName );
     CKSERV;
 
-    /*
-     *  Emit the real command.  The original shell script shifts off the
-     *  command name before it realizes what it has done.  We emulate
-     *  that behavior by setting `nonopt' to the command name and inserting
-     *  the remaining arguments as arguments via `set -- $@'.
-     */
-    fprintf( fp, zCmdName, argv[0] );
+    if (pzTarget == NULL) {
+        pzTarget = strrchr( pzSource, '/' );
+        if (pzTarget == NULL)
+            pzTarget = pzSource;
+        else
+            pzTarget++; 
+    }
+
+    fprintf( fp, "libobj='%s'\n", makeShellSafe( pzTarget ));
     CKSERV;
 
-    while (--argc > 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 */
index d04c550d31a1455350243eb5a1b04efb01943af6..6587e7b71b5bd712bfa3c5780a76adedae5a61b1 100644 (file)
 #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";
index 7e5de54458852d2ac6a8ffac18f66614a8f219c4..49dd3b1f47098dc2d7a264c6d57fbdab742ed214 100644 (file)
@@ -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 */
index 278e497a4b8e7c6a8e341029ce37369ce800d470..aca0da1220c90377dc66d9eac30f5e9108467590 100644 (file)
@@ -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 */
index beb73c8a193342d9f9103e03a758ecc017dc9e50..cd56ecce9bd1ae2355617248b0675eccd2deff4c 100644 (file)
@@ -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
index 85f905cd61af4210dee7d9f6985de321eabd52e3..20c9149aa56854deba47707613821271151a1dd7 100644 (file)
@@ -291,6 +291,7 @@ if test -z "$show_help"; then
   # libtool compile mode
   compile)
     modename="$modename: compile"
+
 [= INCLUDE "compile-txt.tpl" =]
 
     exit 0
index 25caa6b6ac027ff9e0ecb84e3c04608d51c90e0e..7131ce7c263f050a0b24afd27f78c3c9aaf9240c 100644 (file)
@@ -3,10 +3,13 @@ AutoGen Definitions ltmain.tpl;
 
 string = {
   str-name = base;
+  continues;
 };
 
 string = {
   str-name = clean;
+  end-exits = '$exit_status';
+
   explain = "
 <command> is the name of the program to use to delete files associated with
 each FILE (typically `/bin/rm').  `<cmd-arg>-s' are options (such as `-f')
@@ -20,6 +23,7 @@ the file itself is deleted using <command>.\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, <command> is executed, with  `<cmd-arg>...' as arguments.\n";
 
 string = {
   str-name = finish;
+  end-exits = "0";
+
   explain = "
 Complete the installation of libtool libraries.\n
 The <cmd-arg>-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;
 };
index 022fec8311a003b120f9c79576c6a707a89b6c70..87e0609edfc93d1d5a64d2bd81af2ecbd4a9accc 100644 (file)
@@ -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)=] */[=