+2009-04-01 Simon Josefsson <simon@josefsson.org>
+
+ * modules/lib-msvc-compat: New module. Thanks to Bruno Haible
+ <bruno@clisp.org>, Ralf Wildenhues <Ralf.Wildenhues@gmx.de>, and
+ Eric Blake <ebb9@byu.net> for review.
+ * MODULES.html.sh: Add lib-msvc-compat.
+ * doc/gnulib.texi: Link to new section.
+ * m4/ld-output-def.m4: New file.
+ * doc/ld-output-def.texi: New file.
+
2009-04-01 Simon Josefsson <simon@josefsson.org>
Rename ld-version-script to lib-symbol-versions. Suggested by
--- /dev/null
+@node Visual Studio Compatibility
+@section Visual Studio Compatibility
+@cindex DEF files
+@cindex LD DEF files
+
+The @code{lib-msvc-compat} module detects whether the linker supports
+@code{--output-def} when building a library. That parameter is used
+to generate a DEF file for a shared library (DLL). DEF files are
+useful for developers that use Visual Studio to develop programs that
+links to your library. See the GNU LD manual for more information.
+
+There are other ways to create a DEF file, but we believe they are all
+sub-optimal to using @code{--output-def} during the build process.
+The variants we have considered include:
+
+@itemize @bullet
+@item Use DUMPBIN /EXPORTS.
+The tool does not generate DEF files directly, so its output needs to
+be post processed manually. The tool is documented to potentially not
+work with non-MS development tools
+(@url{http://support.microsoft.com/kb/131313/en-us}), which is the
+case when MinGW is used to build the library.
+
+@item Use IMPDEF.
+There is a tool called IMPDEF
+(@url{http://sei.pku.edu.cn/~caodg/course/c/reference/win32/tools/dlltool.html})
+that can generate DEF files. However, it is not part of a standard
+Visual Studio installation. Further, it is documented as being an
+unreliable process.
+
+@item Use DLLTOOL.
+The dlltool is part of the MinGW suite, and thus not part of a
+standard Visual Studio installation. The documentation for the IMPDEF
+tool claims that DLLTOOL is the wrong tool for this job. Finally,
+DLLTOOL does not generate DEF files directly, so it requires
+post-processing of the output.
+
+@end itemize
+
+If you are using libtool to build your shared library, here is how to
+use this module. Import @code{lib-msvc-compat} to your project, and
+then add the following lines to the @code{Makefile.am} that builds the
+library:
+
+@smallexample
+if HAVE_LD_OUTPUT_DEF
+libfoo_la_LDFLAGS += -Wl,--output-def,libfoo-$(SOVERSION).def
+defexecdir = $(bindir)
+defexec_DATA = libfoo-$(SOVERSION).def
+DISTCLEANFILES += $(defexec_DATA)
+endif
+@end smallexample
+
+The @code{SOVERSION} variable needs to be defined. It should be the
+shared library version number used in the DLL filename. For Windows
+targets you compute this value from the values you pass to Libtool's
+@code{-version-info}. Assuming you have variables @code{LT_CURRENT}
+and @code{LT_AGE} defined for the @code{CURRENT} and @code{AGE}
+libtool version integers, you compute @code{SOVERSION} as follows:
+
+@smallexample
+SOVERSION=`expr $@{LT_CURRENT@} - $@{LT_AGE@}`
+AC_SUBST(SOVERSION)
+@end smallexample
--- /dev/null
+# ld-output-def.m4 serial 2
+dnl Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Simon Josefsson
+
+# gl_LD_OUTPUT_DEF()
+# -------------
+# Check if linker supports -Wl,--output-def and define automake
+# conditional HAVE_LD_OUTPUT_DEF if it is.
+AC_DEFUN([gl_LD_OUTPUT_DEF],
+[
+ AC_CACHE_CHECK([if gcc/ld supports -Wl,--output-def],
+ [gl_cv_ld_output_def],
+ [if test "$enable_shared" = no; then
+ gl_cv_ld_output_def="not needed, shared libraries are disabled"
+ else
+ gl_ldflags_save=$LDFLAGS
+ LDFLAGS="-Wl,--output-def,conftest.def"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
+ [gl_cv_ld_output_def=yes],
+ [gl_cv_ld_output_def=no])
+ rm -f conftest.def
+ LDFLAGS="$gl_ldflags_save"
+ fi])
+ AM_CONDITIONAL([HAVE_LD_OUTPUT_DEF], test "x$gl_cv_ld_output_def" = "xyes")
+])