libtool-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [patch] win32: eliminate wrapper script in main build dir


From: Charles Wilson
Subject: Re: [patch] win32: eliminate wrapper script in main build dir
Date: Sun, 17 Jun 2007 16:51:41 -0400
User-agent: Thunderbird 1.5.0.12 (Windows/20070509)

Ralf Wildenhues wrote:
* Charles Wilson wrote on Sun, Jun 17, 2007 at 02:43:02AM CEST:
OK by me. Do you wat me to add your patch to mine and check it all in at once (e.g. keep the new-testsuite .exe fixes to destdir.at together), or will you check your changes in separately?

However you like.

It is included below.

Attached.  Unless you beat me to it, I can try to go about a patch
sometime though.

In any case, I'd like to postpone the cross-compile old-testsuite .exe fixes to a followup patch.

Sure.

OK.

Updated patch attached, incorporating (I hope) all extant comments from Noah and Ralf, along with an updated ChangeLog.

This passes all expected tests on linux (native).

On cygwin (native) it fails 14,16,32, and 54, which is the expected behavior.

I'll test

[with
    export INSTALL=/usr/bin/install.exe
to ensure that I don't get spurious failures for 35 39 43 46]

on mingw (native) before committing, and then commit tomorrow only if the failures are limited to the same as on cygwin, and there are no other objections.

--
Chuck

2007-06-17  Charles Wilson  <address@hidden>

        * libltdl/config/ltmain.m4sh: Add new magic variable
        for use with cwrapper.
        (func_ltwrapper_script_p): New function.
        (func_ltwrapper_executable_p): New function.
        (func_ltwrapper_scriptname): New function.
        (func_ltwrapper_p): Accomodate both wrapper scripts and
        wrapper executables.
        (func_mode_execute): Handle $file that is a wrapper
        script and $file that is a wrapper executable differently.
        (func_mode_install) [cygwin|mingw]: If $file is a wrapper
        executable, use func_ltwrapper_scriptname to determine
        wrapper script name. Afterwards, always use
        func_ltwrapper_script_p instead of func_ltwrapper_p.
        (func_emit_libtool_wrapper_script): Rename to...
        (func_emit_wrapper): ...this. All callers changed.
        (func_emit_libtool_cwrapperexe_source): Rename to...
        (func_emit_cwrapperexe_src): ...this. All callers changed.
        Embed new magic_exe variable into source. Private transient
        wrapper script now called foo_ltshwrapperTMP, not
        foo_ltshwrapper.
        (func_emit_cwrapperexe_src) [main, mingw]: Use _spawnv
        and return child's exit code manually rather than rely on
        broken execv.
        (func_mode_link) [cygwin|mingw]: Don't call dirname and
        basename directly; use func_dirname and func_basename
        when computing cwrapper names.  Use cwrapper to generate
        wrapper script, and use pathname returned by
        func_ltwrapper_scriptname instead of $output.
        (func_mode_link) [NOT cygwin|mingw]: move wrapper script
        generation for non-win32 inside case statement, as default
        case.
        (func_mode_uninstall) [$name's extension != .lo|.la]:
        'clean' mode must handle $file differently if it is a libtool
        wrapper script, or if it is a libtool wrapper executable.
        * tests/destdir.at [Simple DESTDIR install]: $EXEEXT fixups.
        * tests/destdir.at [DESTDIR with in-package deplibs]: Ditto.


Index: libltdl/config/ltmain.m4sh
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/config/ltmain.m4sh,v
retrieving revision 1.79
diff -u -r1.79 ltmain.m4sh
--- libltdl/config/ltmain.m4sh  9 Jun 2007 17:46:40 -0000       1.79
+++ libltdl/config/ltmain.m4sh  17 Jun 2007 18:02:16 -0000
@@ -135,7 +135,7 @@
 fi
 
 magic="%%%MAGIC variable%%%"
-
+magic_exe="%%%MAGIC EXE variable%%%"
 
 # Global variables.
 # $mode is unset
@@ -661,13 +661,55 @@
     test "$lalib_p" = yes
 }
 
+# func_ltwrapper_script_p file
+# True iff FILE is a libtool wrapper script
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_script_p ()
+{
+    func_lalib_p "$1"
+}
+
+# func_ltwrapper_executable_p file
+# True iff FILE is a libtool wrapper executable
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_executable_p ()
+{
+    func_ltwrapper_exec_suffix=
+    case $1 in
+    *.exe) ;;
+    *) func_ltwrapper_exec_suffix=.exe ;;
+    esac
+    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
+}
+
+# func_ltwrapper_scriptname file
+# Assumes file is an ltwrapper_executable
+# uses $file to determine the appropriate filename for a
+# temporary ltwrapper_script.
+func_ltwrapper_scriptname ()
+{
+    func_ltwrapper_scriptname_result=""
+    if func_ltwrapper_executable_p "$1"; then
+       func_dirname "$1"
+       func_basename "$1"
+       func_stripname '' '.exe' "$func_basename_result"
+       if test -z "$func_dirname_result"; then
+           
func_ltwrapper_scriptname_result="./$objdir/${func_stripname_result}_ltshwrapper"
+       else
+           
func_ltwrapper_scriptname_result="$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper"
+       fi
+    fi
+}
+
 # func_ltwrapper_p file
-# True iff FILE is a libtool wrapper script.
+# True iff FILE is a libtool wrapper script or wrapper executable
 # This function is only a basic sanity check; it will hardly flush out
 # determined imposters.
 func_ltwrapper_p ()
 {
-    func_lalib_p "$1"
+    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
 }
 
 
@@ -1649,12 +1691,14 @@
       -*) ;;
       *)
        # Do a test to see if this is really a libtool program.
-       if func_ltwrapper_p "$file"; then
-         func_source "$file"
-
-         # Transform arg to wrapped name.
-         file="$progdir/$program"
+       if func_ltwrapper_script_p "$file"; then
+         func_source "$file"
+       elif func_ltwrapper_executable_p "$file"; then
+         func_ltwrapper_scriptname "$file"
+         func_source "$func_ltwrapper_scriptname_result"
        fi
+       # Transform arg to wrapped name.
+       file="$progdir/$program"
        ;;
       esac
       # Quote arguments (to preserve shell metacharacters).
@@ -2085,14 +2129,19 @@
        # Do a test to see if this is really a libtool program.
        case $host in
        *cygwin*|*mingw*)
-           func_stripname '' '.exe' "$file"
-           wrapper=$func_stripname_result
+           if func_ltwrapper_executable_p "$file"; then
+             func_ltwrapper_scriptname "$file"
+             wrapper=$func_ltwrapper_scriptname_result
+           else
+             func_stripname '' '.exe' "$file"
+             wrapper=$func_stripname_result
+           fi
            ;;
        *)
            wrapper=$file
            ;;
        esac
-       if func_ltwrapper_p "$wrapper"; then
+       if func_ltwrapper_script_p "$wrapper"; then
          notinst_deplibs=
          relink_command=
 
@@ -2209,7 +2258,7 @@
 test "$mode" = install && func_mode_install ${1+"$@"}
 
 
-# func_emit_libtool_wrapper_script arg
+# func_emit_wrapper arg
 #
 # emit a libtool wrapper script on stdout
 # don't directly open a file because we may want to
@@ -2223,11 +2272,11 @@
 # will assume that the directory in which it is stored is
 # the '.lib' directory.  This is a cygwin/mingw-specific
 # behavior.
-func_emit_libtool_wrapper_script ()
+func_emit_wrapper ()
 {
-       func_emit_libtool_wrapper_script_arg1=no
+       func_emit_wrapper_arg1=no
        if test -n "$1" ; then
-         func_emit_libtool_wrapper_script_arg1=$1
+         func_emit_wrapper_arg1=$1
        fi
          
        $ECHO "\
@@ -2315,7 +2364,7 @@
 
   # Usually 'no', except on cygwin/mingw when embedded into 
   # the cwrapper.
-  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_libtool_wrapper_script_arg1
+  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
   if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
     # special case for '.'
     if test \"\$thisdir\" = \".\"; then
@@ -2432,13 +2481,13 @@
 fi\
 "
 }
-# end: func_emit_libtool_wrapper_script
+# end: func_emit_wrapper
 
-# func_emit_libtool_cwrapperexe_source
+# func_emit_cwrapperexe_src
 # emit the source code for a wrapper executable on stdout
 # Must ONLY be called from within func_mode_link because
 # it depends on a number of variable set therein.
-func_emit_libtool_cwrapperexe_source ()
+func_emit_cwrapperexe_src ()
 {
        cat <<EOF
 
@@ -2547,12 +2596,13 @@
 static const char *script_text = 
 EOF
 
-           func_emit_libtool_wrapper_script yes |
+           func_emit_wrapper yes |
                $SED -e 's/\([\\"]\)/\\\1/g' \
                     -e 's/^/  "/' -e 's/$/\\n"/' 
            echo ";"
 
            cat <<EOF
+const char * MAGIC_EXE = "$magic_exe";
 
 int
 main (int argc, char *argv[])
@@ -2561,11 +2611,12 @@
   char *tmp_pathspec;
   char *actual_cwrapper_path;
   char *shwrapper_name;
+  intptr_t rval = 127;
   FILE *shwrapper;
 
   const char *dumpscript_opt = "--lt-dump-script";
   int i;
-
+ 
   program_name = (char *) xstrdup (base_name (argv[0]));
   LTWRAPPER_DEBUGPRINTF (("(main) argv[0]      : %s\n", argv[0]));
   LTWRAPPER_DEBUGPRINTF (("(main) program_name : %s\n", program_name));
@@ -2623,9 +2674,9 @@
   /* shwrapper_name transforms */
   strendzap (shwrapper_name, ".exe");
   tmp_pathspec = XMALLOC (char, (strlen (shwrapper_name) +
-                                strlen ("_ltshwrapper") + 1));
+                                strlen ("_ltshwrapperTMP") + 1));
   strcpy (tmp_pathspec, shwrapper_name);
-  strcat (tmp_pathspec, "_ltshwrapper");
+  strcat (tmp_pathspec, "_ltshwrapperTMP");
   XFREE (shwrapper_name);
   shwrapper_name = tmp_pathspec;
   tmp_pathspec = 0;
@@ -2688,19 +2739,28 @@
            case $host_os in
              mingw*)
                cat <<EOF
-  execv ("$lt_newargv0", (const char * const *) newargz);
+  /* execv doesn't actually work on mingw as expected on unix */
+  rval = _spawnv (_P_WAIT, "$lt_newargv0", (const char * const *) newargz);
+  if (rval == -1)
+    {
+      /* failed to start process */
+      LTWRAPPER_DEBUGPRINTF (("(main) failed to launch target 
\"$lt_newargv0\": errno = %d\n", errno)); 
+      return 127;
+    }
+  return rval;
+}
 EOF
                ;;
              *)
                cat <<EOF
   execv ("$lt_newargv0", newargz);
+  return rval; /* =127, but avoids unused variable warning */
+}
 EOF
                ;;
            esac
 
            cat <<"EOF"
-  return 127;
-}
 
 void *
 xmalloc (size_t num)
@@ -2977,7 +3037,7 @@
 }
 EOF
 }
-# end: func_emit_libtool_cwrapperexe_source
+# end: func_emit_cwrapperexe_src
 
 # func_mode_link arg...
 func_mode_link ()
@@ -6708,28 +6768,43 @@
        esac
        case $host in
          *cygwin* | *mingw* )
-           output_name=`basename $output`
-           output_path=`dirname $output`
+           func_basename "$output"
+           output_name=$func_basename_result
+           func_dirname "$output"
+           output_path=$func_dirname_result
+           if test -z "$output_path"; then
+             output_path=.
+           fi
            cwrappersource="$output_path/$objdir/lt-$output_name.c"
            cwrapper="$output_path/$output_name.exe"
            $RM $cwrappersource $cwrapper
            trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
 
-           func_emit_libtool_cwrapperexe_source > $cwrappersource
+           func_emit_cwrapperexe_src > $cwrappersource
 
-         # we should really use a build-platform specific compiler
-         # here, but OTOH, the wrappers (shell script and this C one)
-         # are only useful if you want to execute the "real" binary.
-         # Since the "real" binary is built for $host, then this
-         # wrapper might as well be built for $host, too.
-         $opt_dry_run || $LTCC $LTCFLAGS -s -o $cwrapper $cwrappersource
+           # we should really use a build-platform specific compiler
+           # here, but OTOH, the wrappers (shell script and this C one)
+           # are only useful if you want to execute the "real" binary.
+           # Since the "real" binary is built for $host, then this
+           # wrapper might as well be built for $host, too.
+           $opt_dry_run || $LTCC $LTCFLAGS -s -o $cwrapper $cwrappersource
+
+           # Now, create the wrapper script for func_source use:
+           func_ltwrapper_scriptname $cwrapper
+           $RM $func_ltwrapper_scriptname_result
+           trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 
2 15
+           $opt_dry_run || {
+             $cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
+           }
          ;;
-       esac
-       $RM $output
-       trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
+         * )
+           $RM $output
+           trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
 
-       func_emit_libtool_wrapper_script no > $output
-       chmod +x $output
+           func_emit_wrapper no > $output
+           chmod +x $output
+         ;;
+       esac
       }
       exit $EXIT_SUCCESS
       ;;
@@ -7179,8 +7254,15 @@
          esac
          # Do a test to see if this is a libtool program.
          if func_ltwrapper_p "$file"; then
-           relink_command=
-           func_source $dir/$noexename
+           if func_ltwrapper_executable_p "$file"; then
+             func_ltwrapper_scriptname "$file"
+             relink_command=
+             func_source $func_ltwrapper_scriptname_result
+             rmfiles="$rmfiles $func_ltwrapper_scriptname_result"
+           else
+             relink_command=
+             func_source $dir/$noexename
+           fi
 
            # note $name still contains .exe if it was in $file originally
            # as does the version of $file that was added into $rmfiles
Index: tests/destdir.at
===================================================================
RCS file: /cvsroot/libtool/libtool/tests/destdir.at,v
retrieving revision 1.5
diff -u -r1.5 destdir.at
--- tests/destdir.at    25 Mar 2007 12:12:43 -0000      1.5
+++ tests/destdir.at    17 Jun 2007 18:02:16 -0000
@@ -60,7 +60,7 @@
 mkdir $DESTDIR$libdir $DESTDIR$bindir
 AT_CHECK([$LIBTOOL --mode=install cp liba.la $DESTDIR$libdir/liba.la],
         [], [ignore], [ignore])
-AT_CHECK([$LIBTOOL --mode=install cp m $DESTDIR$bindir/m],
+AT_CHECK([$LIBTOOL --mode=install cp m$EXEEXT $DESTDIR$bindir/m$EXEEXT],
         [], [ignore], [ignore])
 $LIBTOOL --mode=clean rm -f liba.la m
 LT_AT_MVDIR(["$DESTDIR$libdir"], ["$libdir"])
@@ -99,7 +99,7 @@
         [], [ignore], [ignore])
 AT_CHECK([$LIBTOOL --mode=install cp liba.la $DESTDIR$libdir/liba.la],
         [], [ignore], [ignore])
-AT_CHECK([$LIBTOOL --mode=install cp m $DESTDIR$bindir/m],
+AT_CHECK([$LIBTOOL --mode=install cp m$EXEEXT $DESTDIR$bindir/m$EXEEXT],
         [], [ignore], [ignore])
 $LIBTOOL --mode=clean rm -f liba1dep.la liba2dep.la liba.la m
 LT_AT_MVDIR(["$DESTDIR$libdir"], ["$libdir"])
@@ -127,8 +127,8 @@
 LT_AT_EXEC_CHECK([$bindir/m])
 
 # TODO: make this more portable:
-if test "$OBJDUMP" != false && ($OBJDUMP -p $bindir/m) >/dev/null 2>&1; then
-  AT_CHECK([$OBJDUMP -p $bindir/m | $EGREP -i "R(UN)?PATH.*$DESTDIR"], [1])
+if test "$OBJDUMP" != false && ($OBJDUMP -p $bindir/m$EXEEXT) >/dev/null 2>&1; 
then
+  AT_CHECK([$OBJDUMP -p $bindir/m$EXEEXT | $EGREP -i "R(UN)?PATH.*$DESTDIR"], 
[1])
   . $libdir/liba.la
   set x $library_names
   lname=$2

reply via email to

[Prev in Thread] Current Thread [Next in Thread]