1# woe32-dll.m4 serial 2
2dnl Copyright (C) 2005-2006 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl From Bruno Haible.
8
9# Add --disable-auto-import to the LDFLAGS if the linker supports it.
10# GNU ld has an --enable-auto-import option, and it is the default on Cygwin
11# since July 2005. But it has three fatal drawbacks:
12#   - It produces executables and shared libraries with relocations in the
13#     .text segment, defeating the principles of virtual memory.
14#   - For some constructs such as
15#         extern int var;
16#         int * const b = &var;
17#     it creates an executable that will give an error at runtime, rather
18#     than either a compile-time or link-time error or a working executable.
19#     (This is with both gcc and g++.) Whereas this code, not relying on
20#     auto-import:
21#         extern __declspec (dllimport) int var;
22#         int * const b = &var;
23#     gives a compile-time error with gcc and works with g++.
24#   - It doesn't work in some cases (references to a member field of an
25#     exported struct variable, or to a particular element of an exported
26#     array variable), requiring code modifications.  One platform
27#     dictates code modifications on all platforms.
28AC_DEFUN([gl_WOE32_DLL],
29[
30  AC_REQUIRE([AC_CANONICAL_HOST])
31  case "$host_os" in
32    mingw* | cygwin*)
33      AC_MSG_CHECKING([for auto-import of symbols])
34      AC_CACHE_VAL([gl_cv_ld_autoimport], [
35        gl_save_LDFLAGS="$LDFLAGS"
36        LDFLAGS="$LDFLAGS -Wl,--disable-auto-import"
37        AC_TRY_LINK([], [], [gl_cv_ld_autoimport=yes], [gl_cv_ld_autoimport=no])
38        LDFLAGS="$gl_save_LDFLAGS"])
39      AC_MSG_RESULT([$gl_cv_ld_autoimport])
40      if test $gl_cv_ld_autoimport = yes; then
41        LDFLAGS="$LDFLAGS -Wl,--disable-auto-import"
42      fi
43      ;;
44  esac
45])
46