]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
This gives a slightly better idea of the approach
authorAndreas Jaeger <aj@suse.de>
Sun, 13 May 2001 01:51:15 +0000 (01:51 +0000)
committerBruce Korb <bkorb@gnu.org>
Sun, 13 May 2001 01:51:15 +0000 (01:51 +0000)
exe/lt_exe.tpl
exe/lt_execute.def
exe/ltexe.c [new file with mode: 0644]
exe/ltmain.mk

index 8fe746c5d803c870c749a11e2f813be7f29b52a7..bfa894b334a96b06285517e6abe114867752de42 100644 (file)
     cmd="$nonopt"
     [= test-or-exit test = 'test -z "$cmd"'
        msg  = "you must specify a COMMAND" =]
-
-    # Handle -dlopen flags immediately.
-    for file in $execute_dlfiles; do
-      if test ! -f "$file"; then
-       $echo "$modename: \`$file' is not a file" 1>&2
-       $echo "$help" 1>&2
-       exit 1
-      fi
-
-      dir=
-      case $file in
-      *.la)
-       # Check to see that this really is a libtool archive.
-    [= test-or-exit  invert = yes
-          test = "sed -e '2q' $file | egrep \"^# Generated by .*$PACKAGE\""
-          msg  = "\\`$lib' is not a valid libtool archive"  =]
-
-       # Read the libtool library.
-       dlname=
-       library_names=
-
-       # If there is no directory component, then add one.
-       case $file in
-       */* | *\\*) . $file ;;
-       *) . ./$file ;;
-       esac
-
-       # Skip this library if it cannot be dlopened.
-       if test -z "$dlname"; then
-         # Warn if it was a shared library.
-         test -n "$library_names" && $echo "$modename: warning: \`$file' was not linked with \`-export-dynamic'"
-         continue
-       fi
-
-       dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`
-       test "X$dir" = "X$file" && dir=.
-
-    [= test-or-exit test = 'test -f "$dir/$objdir/$dlname"'  invert = yes
-           msg = "cannot find \\`$dlname' in \\`$dir' or \\`$dir/$objdir'" =]
-       dir="$dir/$objdir"
-       ;;
-
-      *.lo)
-       # Just add the directory containing the .lo file.
-       dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`
-       test "X$dir" = "X$file" && dir=.
-       ;;
-
-      *)
-       $echo "$modename: warning \`-dlopen' is ignored for non-libtool libraries and objects" 1>&2
-       continue
-       ;;
-      esac
-
-      # Get the absolute pathname.
-      absdir=`cd "$dir" && pwd`
-      test -n "$absdir" && dir="$absdir"
-
-      # Now add the directory to shlibpath_var.
-      if eval "test -z \"\$$shlibpath_var\""; then
-       eval "$shlibpath_var=\"\$dir\""
-      else
-       eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
-      fi
-    done
-
-    # This variable tells wrapper scripts just to set shlibpath_var
-    # rather than running their programs.
-    libtool_execute_magic="$magic"
-
-    # Check if any of the arguments is a wrapper script.
-    args=
-    for file
-    do
-      case $file in
-      -*) ;;
-      *)
-       # Do a test to see if this is really a libtool program.
-       if (sed -e '4q' $file | egrep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
-         # If there is no directory component, then add one.
-         case $file in
-         */* | *\\*) . $file ;;
-         *) . ./$file ;;
-         esac
-
-         # Transform arg to wrapped name.
-         file="$progdir/$program"
-       fi
-       ;;
-      esac
-      # Quote arguments (to preserve shell metacharacters).
-      file=`$echo "X$file" | $Xsed -e "$sed_quote_subst"`
-      args="$args \"$file\""
-    done
-
-    if test -z "$run"; then
-      if test -n "$shlibpath_var"; then
-       # Export the shlibpath_var.
-       eval "export $shlibpath_var"
-      fi
-
-      # Restore saved enviroment variables
-      if test "${save_LC_ALL+set}" = set; then
-       LC_ALL="$save_LC_ALL"; export LC_ALL
-      fi
-      if test "${save_LANG+set}" = set; then
-       LANG="$save_LANG"; export LANG
-      fi
-
-      # Now actually exec the command.
-      eval "exec \$cmd$args"
-
-      $echo "$modename: cannot exec \$cmd$args"
-      exit 1
-    else
-      # Display what would be done.
-      if test -n "$shlibpath_var"; then
-       eval "\$echo \"\$shlibpath_var=\$$shlibpath_var\""
-       $echo "export $shlibpath_var"
-      fi
-      $echo "$cmd$args"
-      exit 0
-    fi
+[=(shellf "cat > .lttmp.exe <<'END_LTEXE_TEMP'
+[+ AutoGen5 Template +]
+%s\nEND_LTEXE_TEMP"
+          (get "string[EXECUTE_STRING].text")) =][=
+    INCLUDE ".lttmp.exe" =][=
+    `rm -f .lttmp.exe`   =]
     ;;
index 614ec35b774f7c9f456117c38b9f5033c1eaf944..1b3c8a314ac29123aa3ffcd18dc391d21fafec59 100644 (file)
@@ -4,7 +4,9 @@ AutoGen Definitions ltmain.tpl;
 #define EXECUTE_STRING 3
 
 string[EXECUTE_STRING] = {
-  str-name = execute;
+  str-name  = execute;
+  call-proc = emitExecute;
+
   explain = "
 Automatically set library path, then run a program.\n
 This mode accepts the following additional options:\n
@@ -17,32 +19,18 @@ required library directories are added to the library path.\n
 Then, <command> is executed, with  `<cmd-arg>...' as arguments.\n";
 
   text = << _END_EXECUTE_STRING_
-    # The first argument is the command name.
-    cmd="$nonopt"
-    if test -z "$cmd"; then
-      $echo "$modename: you must specify a COMMAND" 1>&2
-      $echo "$help"
-      exit 1
-    fi
-
     # Handle -dlopen flags immediately.
     for file in $execute_dlfiles; do
-      if test ! -f "$file"; then
-       $echo "$modename: \`$file' is not a file" 1>&2
-       $echo "$help" 1>&2
-       exit 1
-      fi
+      [+ test-or-exit test = 'test ! -f "$file"'
+         msg = "\\`$file' is not a file" +]
 
       dir=
       case $file in
       *.la)
        # Check to see that this really is a libtool archive.
-       if (sed -e '2q' $file | egrep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then :
-       else
-         $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2
-         $echo "$help" 1>&2
-         exit 1
-       fi
+       [+ test-or-exit  invert = yes
+          test = "sed -e '2q' $file | egrep \"^# Generated by .*$PACKAGE\""
+          msg  = "\\`$lib' is not a valid libtool archive"  +]
 
        # Read the libtool library.
        dlname=
@@ -64,12 +52,9 @@ Then, <command> is executed, with  `<cmd-arg>...' as arguments.\n";
        dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`
        test "X$dir" = "X$file" && dir=.
 
-       if test -f "$dir/$objdir/$dlname"; then
-         dir="$dir/$objdir"
-       else
-         $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2
-         exit 1
-       fi
+       [+ test-or-exit test = 'test -f "$dir/$objdir/$dlname"'  invert = yes
+           msg = "cannot find \\`$dlname' in \\`$dir' or \\`$dir/$objdir'" +]
+       dir="$dir/$objdir"
        ;;
 
       *.lo)
diff --git a/exe/ltexe.c b/exe/ltexe.c
new file mode 100644 (file)
index 0000000..7e5de54
--- /dev/null
@@ -0,0 +1,173 @@
+/* ltexe.c - C implementation of GNU Libtool
+ *
+ * Copyright (C) 1998-2000 Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307 USA
+ *
+ * As a special exception to the GNU General Public License, if you
+ * distribute this file as part of a program that contains a
+ * configuration script generated by Autoconf, you may include it under
+ * the same distribution terms that you use for the rest of that program.
+ */
+
+#include <stdio.h>              /* printf */
+#include <stdlib.h>             /* exit */
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/wait.h>
+#include <signal.h>
+
+#include "ltopts.h"
+#include "ltstr.h"
+
+
+    void
+emitExecute( argc, argv )
+    int argc;
+    char** argv;
+{
+    tSCC zDbgFmt[]   = "set -x\n";
+    tSCC zQuiet[]    = "run=\nshow=%s\n";
+    tSCC zDynFmt[]   = "build_libtool_libs=%s\n";
+    tSCC zStatic[]   = "build_old_libs=%s\n";
+    tSCC zModeName[] = "modename='%s: %s'\n";
+    tSCC zMode[]     = "mode='%s'\n";
+    tSCC zCmdName[]  = "nonopt='%s'\nset --";
+    tSCC zDlOpt[]    = "execute_dlfiles='";
+
+    /*
+     *  When we emit our script, we want the interpreter to invoke *US*
+     *  if echo does not work right.
+     */
+    tSCC zChkEcho[]  = 
+"\n\nif test \"X`($echo '\\t') 2>/dev/null`\" = 'X\\t'\n\
+then  :\n\
+else  echo='%s --echo --' ; fi\n";
+
+    FILE* fp;
+
+       if (argc <= 0) {
+               fprintf( stderr,
+                                "libtool error:  in %s mode, you must specify a command\n",
+                                apz_mode_cmd[ OPT_VALUE_MODE ]);
+               USAGE( EXIT_FAILURE );
+       }
+
+       fp = HAVE_OPT( DRY_RUN ) ? stdout : popen( pz_shell, "w" );
+    if (fp == (FILE*)NULL) {
+        tSCC zErr[] = "%s error:  fs error %d (%s) on popen( \"%s\",\"w\")\n";
+        fprintf( stderr, zErr, libtoolOptions.pzProgPath, errno,
+                 strerror( errno ), pz_shell );
+        exit( EXIT_FAILURE );
+    }
+
+#    define CKSERV if (signalReceived != 0) { \
+     closeScript( fp ); if (scriptStatus == 0) scriptStatus = EXIT_FAILURE; \
+     return; }
+
+#    define CLOSEOK if (signalReceived != 0) { closeScript( fp ); return; }
+
+    /*
+     *  Emit the default configuration set up at program configuration time
+     */
+    fputs( pz_ltconfig, fp );
+    CKSERV;
+    fputs( apz_mode_cmd[ 0 ], fp );
+    CKSERV;
+    fprintf( fp, zChkEcho, libtoolOptions.pzProgPath );
+    CKSERV;
+
+    fprintf( fp, zQuiet,  HAVE_OPT( QUIET )      ? ":"   : "\"$echo\"" );
+    CKSERV;
+
+    /*
+     *  IF we have DYNAMIC or STATIC, then we override the configured
+     *  values.  We emitted the configured values with `z_ltconfig'.
+     */
+    if (HAVE_OPT( DYNAMIC ))
+        fprintf( fp, zDynFmt, ENABLED_OPT( DYNAMIC ) ? "yes" : "no" );
+    if (HAVE_OPT( STATIC ))
+        fprintf( fp, zStatic, ENABLED_OPT( STATIC )  ? "yes" : "no" );
+
+    if (HAVE_OPT( DEBUG )) {
+        fprintf( stderr, "%s: enabling shell trace mode\n",
+                 libtoolOptions.pzProgName );
+        fputs( zDbgFmt, fp );
+    }
+    CKSERV;
+
+    if (HAVE_OPT( DLOPEN )) {
+        int    ct = STACKCT_OPT(  DLOPEN );
+        char** al = STACKLST_OPT( DLOPEN );
+        fputs( zDlOpt, fp );
+        for (;;) {
+            emitShellQuoted( *(al++), fp );
+            if (--ct <= 0)
+                break;
+            fputc( ' ', fp ); /* between each value only */
+        }
+        fputs( "'\n", fp );
+    }
+    CKSERV;
+
+    /*
+     *  Insert our modal stuff and one shell option processing dinkleberry
+     *  that one of the command scripts depends upon.
+     */
+    fprintf( fp, zModeName, libtoolOptions.pzProgName,
+            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] );
+    CKSERV;
+
+    while (--argc > 0) {
+        fputc( ' ', fp );
+        emitShellArg( *(++argv), fp );
+        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 );
+}
index dd64696a8b0f7dafc220a4ca2d410f36d1990159..815a432965f975507340b7d9267c59204f234e43 100644 (file)
@@ -1,5 +1,5 @@
 
-SRC = ltmain.c ltopts.c ltstr.c ltcompile.c ltversion.c
+SRC = ltmain.c ltopts.c ltstr.c ltcompile.c ltexe.c ltversion.c
 OBJ = $(SRC:.c=.o)
 GENED = ltmain.in ltstr.[ch] ltopts.[ch]
 CC    = cc -I/usr/local/include -g