Hi Ralf,

Den 2010-06-24 20:17 skrev Ralf Wildenhues:
* Peter Rosin wrote on Thu, Jun 24, 2010 at 02:05:23PM CEST:
Den 2010-06-23 21:02 skrev Ralf Wildenhues:
This patch assumes that 'mt' is present, is what you think it is, and
doesn't allow an override.  On my GNU/Linux, mt is part of cpio and
controls magnetic tapes.  Is there possibility for similar confusion on
w32, or want of choice of a different mt version?  This should probably
use AC_CHECK_TOOL or so for this, and an _LT_DECL, similar to how
objdump, dlltool are handled in ltoptions.m4, but defaulting to ':' not
false.  Not that I can imagine anyone prefixing it with `$host-'.  But
it's probably prudent to check that it accepts -? or so (be sure to
quote the ?).

Hmm, if I want to check the exit status of "mt -?", is it ok to add
that check inside
        LT_OPTION_DEFINE([LT_INIT], [win32-dll],
(or however I should denote that code snippet)

I guess.  Wait.  Will mt be needed for programs also in packages using
only static libraries on w32, that maybe won't (or don't want to) use
the win32-dll option?  Then it needs to be outside of this option,
preferably in a new macro in libtool.m4, AC_REQUIREd by the macro(s)
that use(s) mt.

Yes, it might well be. It will be needed as soon as libtool is involved
with linking a program (and when it is using cl for that, of course).

or should I add a macro somewhere (where?) that is more like LT_PATH_NM?
I.e. walks the PATH and discards mt:s that do not appear to be the
intended mt.

Let's try the easy way first, but after the AC_CHECK_TOOL, ensure -? is
accepted.  I don't want magnetic tape action anywhere due to libtool.

Here's a first shot. I know that I haven't addressed the exeext comment
in your other reply, but I don't know what you want me to do. Please
advise further...

I also don't try to run the manifest tool if $MT = :, since I don't want
to remove the .manifest file in that case.

This patch combines the two patches into a single patch, as I see little
point in keeping them separate. I didn't do this before simply because
I had forgotten about the followup patch.

Do I need a NEWS entry for the new MT environment variable? Is the name
MT in too much contention? I can easily imagine that this is not going
to be the first MT variable in the world... But what should it be instead?

And, as always, thanks for reviewing and providing feedback!

Cheers,
Peter
commit 1d17594a93ee2e47deb7fc5f0e2199a33488661c
Author: Peter Rosin <peda@lysator.liu.se>
Date:   Fri Jun 25 00:04:09 2010 +0200

    For MSVC, embed the manifest as a resource in the executable.
    
    Fixes a lot of testsuite failures with MSVC 2003 (v8.0) and
    above (and perhaps also MSVC .Net) related to running programs
    that have been moved (e.g. installed) without their manifests
    also having been moved.
    
    * libltdl/m4/libtool.m4 (_LT_PATH_MT): New macro that locates
    the Manifest Tool (mt) and verifies that it is indeed the
    manifest tool. The result is stored in the new variable MT.
    (_LT_LINKER_SHLIBS) <postlink_cmds>: New tag variable.
    [ cygwin, mingw, cegcc ] <cl*>: Embed the manifest file as a
    resource. Make sure the embedding work regardless of if the
    @OUTPUT@ file name includes a trailing $EXEEXT.
    (_LT_LANG_CXX_CONFIG): Likewise.
    (_LT_LINKER_SHLIBS, _LT_LANG_CXX_CONFIG): Require _LT_PATH_MT
    added above.
    * libltdl/config/ltmain.m4sh (func_mode_link): After linking
    a program, replace @OUTPUT@ in $postlink_cmds and then execute
    the commands.
    * doc/libtool.texi (libtool script contents): Document
    new postlink_cmds variable.
    (LT_INIT): Add that the MT environment variable can be used
    to override the manifest tool to use.
    * tests/exeext.at: New. Make sure linking with both -o prog
    and -o prog$EXEEXT works.
    * Makefile.am (TESTSUITE_AT): Update.
    (TESTS_ENVIRONMENT): Propagate $(MT) to the testsuite.

diff --git a/ChangeLog b/ChangeLog
index a4e47ff..b4b3e4c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2010-06-25  Peter Rosin  <peda@lysator.liu.se>
+
+	For MSVC, embed the manifest as a resource in the executable.
+	Fixes a lot of testsuite failures with MSVC 2003 (v8.0) and
+	above (and perhaps also MSVC .Net) related to running programs
+	that have been moved (e.g. installed) without their manifests
+	also having been moved.
+	* libltdl/m4/libtool.m4 (_LT_PATH_MT): New macro that locates
+	the Manifest Tool (mt) and verifies that it is indeed the
+	manifest tool. The result is stored in the new variable MT.
+	(_LT_LINKER_SHLIBS) <postlink_cmds>: New tag variable.
+	[ cygwin, mingw, cegcc ] <cl*>: Embed the manifest file as a
+	resource. Make sure the embedding work regardless of if the
+	@OUTPUT@ file name includes a trailing $EXEEXT.
+	(_LT_LANG_CXX_CONFIG): Likewise.
+	(_LT_LINKER_SHLIBS, _LT_LANG_CXX_CONFIG): Require _LT_PATH_MT
+	added above.
+	* libltdl/config/ltmain.m4sh (func_mode_link): After linking
+	a program, replace @OUTPUT@ in $postlink_cmds and then execute
+	the commands.
+	* doc/libtool.texi (libtool script contents): Document
+	new postlink_cmds variable.
+	(LT_INIT): Add that the MT environment variable can be used
+	to override the manifest tool to use.
+	* tests/exeext.at: New. Make sure linking with both -o prog
+	and -o prog$EXEEXT works.
+	* Makefile.am (TESTSUITE_AT): Update.
+	(TESTS_ENVIRONMENT): Propagate $(MT) to the testsuite.
+
 2010-06-24  Peter Rosin  <peda@lysator.liu.se>
 
 	Add MSVC support.
diff --git a/Makefile.am b/Makefile.am
index 5822428..30b860e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -471,6 +471,7 @@ TESTSUITE_AT	= tests/testsuite.at \
 		  tests/search-path.at \
 		  tests/indirect_deps.at \
 		  tests/archive-in-archive.at \
+		  tests/exeext.at \
 		  tests/execute-mode.at \
 		  tests/bindir.at \
 		  tests/cwrapper.at \
@@ -519,7 +520,7 @@ EXTRA_DIST     += $(srcdir)/$(TESTSUITE) $(TESTSUITE_AT) $(srcdir)/tests/package
 TESTS_ENVIRONMENT = MAKE="$(MAKE)" CC="$(CC)" CFLAGS="$(CFLAGS)" \
 	CPP="$(CPP)" CPPFLAGS="$(CPPFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" \
 	LIBS="$(LIBS)" LN_S="$(LN_S)" NM="$(NM)" RANLIB="$(RANLIB)" \
-	STRIP="$(STRIP)" lt_INSTALL="$(INSTALL)" \
+	MT="$(MT)" STRIP="$(STRIP)" lt_INSTALL="$(INSTALL)" \
 	OBJEXT="$(OBJEXT)" EXEEXT="$(EXEEXT)" \
 	SHELL="$(SHELL)" CONFIG_SHELL="$(SHELL)" \
 	CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" CXXCPP="$(CXXCPP)" \
diff --git a/doc/libtool.texi b/doc/libtool.texi
index 7ae2c66..30a82ee 100644
--- a/doc/libtool.texi
+++ b/doc/libtool.texi
@@ -2306,6 +2306,11 @@ Program to use rather than checking for @command{as}.  Only used on
 Cygwin/MS-Windows at the moment.
 @end defvar
 
+@defvar MT
+Program to use rather than checking for @command{mt}, the Manifest Tool.
+Only used on Cygwin/MS-Windows at the moment.
+@end defvar
+
 With 1.3 era libtool, if you wanted to know any details of what
 libtool had discovered about your architecture and environment, you
 had to run the script with @option{--config} and grep through the
@@ -6199,6 +6204,15 @@ Commands run after installing a shared or static library, respectively.
 Commands run after uninstalling a shared or static library, respectively.
 @end defvar
 
+@defvar postlink_cmds
+Commands necessary for finishing linking programs. @code{postlink_cmds}
+are executed immediately after the program is linked. Any occurance of
+the string @code{@@OUTPUT@@} in @code{postlink_cmds} is replaced by the
+name of the created executable (i.e. not the wrapper, if a wrapper is
+generated) prior to execution. Normally disabled (i.e.
+@code{postlink_cmds} empty).
+@end defvar
+
 @defvar reload_cmds
 @defvarx reload_flag
 Commands to create a reloadable object.
diff --git a/libltdl/config/ltmain.m4sh b/libltdl/config/ltmain.m4sh
index a325e27..9618074 100644
--- a/libltdl/config/ltmain.m4sh
+++ b/libltdl/config/ltmain.m4sh
@@ -7448,6 +7448,11 @@ EOF
 	exit_status=0
 	func_show_eval "$link_command" 'exit_status=$?'
 
+	if test -n "$postlink_cmds"; then
+	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g'`
+	  func_execute_cmds "$postlink_cmds" 'exit $?'
+	fi
+
 	# Delete the generated files.
 	if test -f "$output_objdir/${outputname}S.${objext}"; then
 	  func_show_eval '$RM "$output_objdir/${outputname}S.${objext}"'
@@ -7493,6 +7498,12 @@ EOF
 	$opt_dry_run || $RM $output
 	# Link the executable and exit
 	func_show_eval "$link_command" 'exit $?'
+
+	if test -n "$postlink_cmds"; then
+	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g'`
+	  func_execute_cmds "$postlink_cmds" 'exit $?'
+	fi
+
 	exit $EXIT_SUCCESS
       fi
 
@@ -7526,6 +7537,11 @@ EOF
 
       func_show_eval "$link_command" 'exit $?'
 
+      if test -n "$postlink_cmds"; then
+	postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
+	func_execute_cmds "$postlink_cmds" 'exit $?'
+      fi
+
       # Now create the wrapper script.
       func_verbose "creating $output"
 
diff --git a/libltdl/m4/libtool.m4 b/libltdl/m4/libtool.m4
index 6955663..4046362 100644
--- a/libltdl/m4/libtool.m4
+++ b/libltdl/m4/libtool.m4
@@ -3323,6 +3323,28 @@ dnl AC_DEFUN([AM_PROG_NM], [])
 dnl AC_DEFUN([AC_PROG_NM], [])
 
 
+# _LT_PATH_MT
+# -----------
+# locate the manifest tool
+m4_defun([_LT_PATH_MT],
+[AC_CHECK_TOOL(MT, mt, :)
+test -z "$MT" && MT=mt
+AC_CACHE_CHECK([if $MT is a manifest tool], [lt_cv_mt_mainfest_tool],
+  [lt_cv_mt_mainfest_tool=no
+  (eval echo "\"\$as_me:$LINENO: $MT '-?'\"" >&AS_MESSAGE_LOG_FD)
+  (eval "$MT '-?'" 2>conftest.err > conftest.out)
+  cat conftest.err >&AS_MESSAGE_LOG_FD
+  if $GREP 'Manifest Tool' conftest.out > /dev/null; then
+    lt_cv_mt_mainfest_tool=yes
+  fi
+  rm -f conftest*])
+if test "x$lt_cv_mt_mainfest_tool" != xyes; then
+  MT=:
+fi
+_LT_DECL([], [MT], [1], [Manifest tool])dnl
+])# _LT_PATH_MT
+
+
 # LT_LIB_M
 # --------
 # check for math library
@@ -4259,6 +4281,7 @@ _LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1],
 m4_defun([_LT_LINKER_SHLIBS],
 [AC_REQUIRE([LT_PATH_LD])dnl
 AC_REQUIRE([LT_PATH_NM])dnl
+m4_require([_LT_PATH_MT])dnl
 m4_require([_LT_FILEUTILS_DEFAULTS])dnl
 m4_require([_LT_DECL_EGREP])dnl
 m4_require([_LT_DECL_SED])dnl
@@ -4858,6 +4881,15 @@ _LT_EOF
 	_LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1,DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols'
 	# Don't use ranlib
 	_LT_TAGVAR(old_postinstall_cmds, $1)='chmod 644 $oldlib'
+	_LT_TAGVAR(postlink_cmds, $1)='lt_outputfile="@OUTPUT@"~
+	  case "$lt_outputfile" in
+	    *.[[eE][xX][eE]]) ;;
+	    *) lt_outputfile="$lt_outputfile.exe" ;;
+	  esac~
+	  if test "$MT" != ":" && test -f "$lt_outputfile.manifest"; then
+	    $MT -manifest "$lt_outputfile.manifest" -outputresource:"$lt_outputfile" || exit 1;
+	    $RM "$lt_outputfile.manifest";
+	  fi'
 	;;
       *)
 	# Assume MSVC wrapper
@@ -5411,6 +5443,8 @@ _LT_TAGDECL([], [include_expsyms], [1],
     [Symbols that must always be exported])
 _LT_TAGDECL([], [prelink_cmds], [2],
     [Commands necessary for linking programs (against libraries) with templates])
+_LT_TAGDECL([], [postlink_cmds], [2],
+    [Commands necessary for finishing linking programs])
 _LT_TAGDECL([], [file_list_spec], [1],
     [Specify filename containing input files])
 dnl FIXME: Not yet implemented
@@ -5512,6 +5546,7 @@ CC="$lt_save_CC"
 m4_defun([_LT_LANG_CXX_CONFIG],
 [m4_require([_LT_FILEUTILS_DEFAULTS])dnl
 m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_PATH_MT])dnl
 if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
     ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
     (test "X$CXX" != "Xg++"))) ; then
@@ -5834,6 +5869,15 @@ if test "$_lt_caught_CXX_error" != yes; then
 	  _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
 	  # Don't use ranlib
 	  _LT_TAGVAR(old_postinstall_cmds, $1)='chmod 644 $oldlib'
+	  _LT_TAGVAR(postlink_cmds, $1)='lt_outputfile="@OUTPUT@"~
+	    case "$lt_outputfile" in
+	      *.[[eE][xX][eE]]) ;;
+	      *) lt_outputfile="$lt_outputfile.exe" ;;
+	    esac~
+	    if test "$MT" != ":" && test -f "$lt_outputfile.manifest"; then
+	      $MT -manifest "$lt_outputfile.manifest" -outputresource:"$lt_outputfile" || exit 1;
+	      $RM "$lt_outputfile.manifest";
+	    fi'
 	  ;;
 	*)
 	  # g++
diff --git a/tests/exeext.at b/tests/exeext.at
new file mode 100644
index 0000000..ee5d755
--- /dev/null
+++ b/tests/exeext.at
@@ -0,0 +1,53 @@
+# exeext.at -- ensure that exeext handling works  -*- Autotest -*-
+#
+#   Copyright (C) 2010 Free Software Foundation, Inc.
+#   Written by Peter Rosin
+#
+#   This file is part of GNU Libtool.
+#
+# GNU Libtool 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 of
+# the License, or (at your option) any later version.
+#
+# GNU Libtool 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 GNU Libtool; see the file COPYING.  If not, a copy
+# can be downloaded from  http://www.gnu.org/licenses/gpl.html,
+# or obtained by writing to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+####
+
+
+AT_SETUP([both of -o prog and -o prog$EXEEXT work])
+AT_KEYWORDS([libtool])
+
+AT_CHECK([test -n "$EXEEXT" || exit 77])
+
+bin=`pwd`/bin
+binext=`pwd`/binext
+mkdir src $bin srcext $binext
+
+AT_DATA(src/prog.c,
+[[
+int main(void) { return 0; }
+]])
+
+$CC $CPPFLAGS $CFLAGS -c src/prog.c -o src/prog.$OBJEXT
+
+AT_CHECK($LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o src/prog src/prog.$OBJEXT,
+	 [0], [ignore], [ignore])
+AT_CHECK($LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o srcext/prog$EXEEXT src/prog.$OBJEXT,
+	 [0], [ignore], [ignore])
+
+$LIBTOOL --mode=install cp src/prog $bin/prog
+$LIBTOOL --mode=install cp srcext/prog$EXEEXT $binext/prog$EXEEXT
+
+LT_AT_EXEC_CHECK([$bin/prog])
+LT_AT_EXEC_CHECK([$binext/prog$EXEEXT])
+
+AT_CLEANUP

Reply via email to