Add an option to enable building libs from dlltool with delayed imports to support ReactOS

git-svn-id: svn+ssh://svn.code.sf.net/p/mingw-w64/code/trunk@3197 4407c894-4637-0410-b4f5-ada5f102cad1
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 3e80706..b5ba2c6 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -32,6 +32,9 @@
 AM_CFLAGS=$(cflags_underscores) -pipe -std=gnu99 @ADD_C_CXX_WARNING_FLAGS@ @ADD_C_ONLY_WARNING_FLAGS@
 AM_CXXFLAGS=@ADD_C_CXX_WARNING_FLAGS@ @ADD_CXX_ONLY_WARNING_FLAGS@
 AM_DLLTOOLFLAGS=$(dlltool_underscores) -k --as=$(AS) --output-lib $@
+if DELAY_IMPORT_LIBS
+  AM_DLLTOOLFLAGS += --output-delaylib $@.delayimp.a
+endif
 CPPFLAGS32=-m32
 CPPFLAGS64=-m64
 DLLTOOLFLAGS32=--as-flags=--32 -m i386
diff --git a/mingw-w64-crt/Makefile.in b/mingw-w64-crt/Makefile.in
index 8bd4bb0..4ede23b 100644
--- a/mingw-w64-crt/Makefile.in
+++ b/mingw-w64-crt/Makefile.in
@@ -98,7 +98,8 @@
 POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
-@ENABLE_TESTS_UNICODE_TRUE@am__append_1 = testcases/t_municode testcases/t_tmain
+@DELAY_IMPORT_LIBS_TRUE@am__append_1 = --output-delaylib $@.delayimp.a
+@ENABLE_TESTS_UNICODE_TRUE@am__append_2 = testcases/t_municode testcases/t_tmain
 check_PROGRAMS = $(am__EXEEXT_2) $(am__EXEEXT_4) $(am__EXEEXT_6)
 TESTS = $(am__EXEEXT_2) $(am__EXEEXT_4) $(am__EXEEXT_6)
 XFAIL_TESTS = testcases/t_nullptrexception$(EXEEXT) $(am__EXEEXT_7) \
@@ -111,25 +112,25 @@
 	build-aux/install-sh build-aux/missing
 
 # Build the libraries
-@LIB32_TRUE@am__append_2 = $(newcomplex_test_lib32)
+@LIB32_TRUE@am__append_3 = $(newcomplex_test_lib32)
 
 # Build the programs during make check.
-@LIB32_TRUE@am__append_3 = $(newcomplex_tests32)
+@LIB32_TRUE@am__append_4 = $(newcomplex_tests32)
 
 # Declare the tests.
-@LIB32_TRUE@am__append_4 = $(newcomplex_tests32)
+@LIB32_TRUE@am__append_5 = $(newcomplex_tests32)
 # Remove these when completed.
-@LIB32_TRUE@am__append_5 = 
+@LIB32_TRUE@am__append_6 = 
 
 # Build the libraries
-@LIB64_TRUE@am__append_6 = $(newcomplex_test_lib64)
+@LIB64_TRUE@am__append_7 = $(newcomplex_test_lib64)
 
 # Build the programs during make check.
-@LIB64_TRUE@am__append_7 = $(newcomplex_tests64)
+@LIB64_TRUE@am__append_8 = $(newcomplex_tests64)
 
 # Declare the tests.
-@LIB64_TRUE@am__append_8 = $(newcomplex_tests64)
-@LIB64_TRUE@am__append_9 = 
+@LIB64_TRUE@am__append_9 = $(newcomplex_tests64)
+@LIB64_TRUE@am__append_10 = 
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/configure.ac
@@ -2934,7 +2935,8 @@
 AM_CPPFLAGS = -D_CRTBLD $(sysincludes)
 AM_CFLAGS = $(cflags_underscores) -pipe -std=gnu99 @ADD_C_CXX_WARNING_FLAGS@ @ADD_C_ONLY_WARNING_FLAGS@
 AM_CXXFLAGS = @ADD_C_CXX_WARNING_FLAGS@ @ADD_CXX_ONLY_WARNING_FLAGS@
-AM_DLLTOOLFLAGS = $(dlltool_underscores) -k --as=$(AS) --output-lib $@
+AM_DLLTOOLFLAGS = $(dlltool_underscores) -k --as=$(AS) --output-lib $@ \
+	$(am__append_1)
 CPPFLAGS32 = -m32
 CPPFLAGS64 = -m64
 DLLTOOLFLAGS32 = --as-flags=--32 -m i386
@@ -3860,7 +3862,7 @@
 	testcases/t_setjmp testcases/t_sigv testcases/t_speed_powl \
 	testcases/t_stat testcases/t_stdint testcases/t_time \
 	testcases/t_tls1 testcases/t_trycatch testcases/t_wreaddir \
-	$(am__append_1)
+	$(am__append_2)
 testcases_tstmaincpp_SOURCES = testcases/tstmaincpp.cpp
 testcases_t_trycatch_SOURCES = testcases/t_trycatch.cpp
 testcases_t_intrinc_CFLAGS = -std=c99
@@ -3869,7 +3871,7 @@
 
 # Do not specify TESTS = check_PROGRAMS, because some TESTS
 # may not be check_PROGRAMS.
-check_LIBRARIES = $(am__append_2) $(am__append_6)
+check_LIBRARIES = $(am__append_3) $(am__append_7)
 
 # Complex library check sources.
 check_complex_lib_sources = \
diff --git a/mingw-w64-crt/configure b/mingw-w64-crt/configure
index 1242018..861692b 100755
--- a/mingw-w64-crt/configure
+++ b/mingw-w64-crt/configure
@@ -607,6 +607,8 @@
 CPP
 ENABLE_TESTS_UNICODE_FALSE
 ENABLE_TESTS_UNICODE_TRUE
+DELAY_IMPORT_LIBS_FALSE
+DELAY_IMPORT_LIBS_TRUE
 PRIVATE_EXPORTS_FALSE
 PRIVATE_EXPORTS_TRUE
 UNDERSCORES_FALSE
@@ -738,6 +740,7 @@
 enable_wildcard
 enable_leading_underscores
 enable_private_exports
+enable_delay_import_libs
 enable_tests_unicode
 enable_warnings
 '
@@ -1388,6 +1391,8 @@
                           calling convention
   --enable-private-exports
                           Enable exporting private internal functions
+  --enable-delay-import-libs
+                          Enable creation of delay-import libraries
   --enable-tests-unicode  Enable the unicode testsuite without testing the
                           compiler for support.
   --enable-warnings[=0-5] Enable compile time warnings [default=3]
@@ -5136,6 +5141,34 @@
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_private_exports" >&5
 $as_echo "$enable_private_exports" >&6; }
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable delay import libs" >&5
+$as_echo_n "checking whether to enable delay import libs... " >&6; }
+# Check whether --enable-delay-import-libs was given.
+if test "${enable_delay_import_libs+set}" = set; then :
+  enableval=$enable_delay_import_libs;
+else
+  enable_delay_import_libs=no
+fi
+
+case $enable_delay_import_libs in #(
+  yes) :
+     ;; #(
+  no) :
+     ;; #(
+  *) :
+    as_fn_error "Please only use --enable-delay-import-libs  or --disable-delay-import-libs, without any additional arguments." "$LINENO" 5 ;;
+esac
+ if test $enable_delay_import_libs = yes; then
+  DELAY_IMPORT_LIBS_TRUE=
+  DELAY_IMPORT_LIBS_FALSE='#'
+else
+  DELAY_IMPORT_LIBS_TRUE='#'
+  DELAY_IMPORT_LIBS_FALSE=
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_delay_import_libs" >&5
+$as_echo "$enable_delay_import_libs" >&6; }
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports -municode" >&5
 $as_echo_n "checking whether the compiler supports -municode... " >&6; }
 # Check whether --enable-tests-unicode was given.
@@ -5806,6 +5839,10 @@
   as_fn_error "conditional \"PRIVATE_EXPORTS\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${DELAY_IMPORT_LIBS_TRUE}" && test -z "${DELAY_IMPORT_LIBS_FALSE}"; then
+  as_fn_error "conditional \"DELAY_IMPORT_LIBS\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${ENABLE_TESTS_UNICODE_TRUE}" && test -z "${ENABLE_TESTS_UNICODE_FALSE}"; then
   as_fn_error "conditional \"ENABLE_TESTS_UNICODE\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
diff --git a/mingw-w64-crt/configure.ac b/mingw-w64-crt/configure.ac
index f2bba92..3f96014 100644
--- a/mingw-w64-crt/configure.ac
+++ b/mingw-w64-crt/configure.ac
@@ -164,6 +164,19 @@
 AM_CONDITIONAL([PRIVATE_EXPORTS],[test $enable_private_exports = yes])
 AC_MSG_RESULT([$enable_private_exports])
 
+AC_MSG_CHECKING([whether to enable delay import libs])
+AC_ARG_ENABLE([delay-import-libs],
+  [AS_HELP_STRING([--enable-delay-import-libs],
+    [Enable creation of delay-import libraries])],
+  [],
+  [enable_delay_import_libs=no])
+AS_CASE([$enable_delay_import_libs],
+  [yes],[],
+  [no],[],
+  [AC_MSG_ERROR([Please only use --enable-delay-import-libs  or --disable-delay-import-libs, without any additional arguments.])])
+AM_CONDITIONAL([DELAY_IMPORT_LIBS],[test $enable_delay_import_libs = yes])
+AC_MSG_RESULT([$enable_delay_import_libs])
+
 AC_MSG_CHECKING([whether the compiler supports -municode])
 AC_ARG_ENABLE([tests-unicode],
   [AS_HELP_STRING([--enable-tests-unicode],