add packaging
[platform/upstream/gettext.git] / m4 / woe32-dll.m4
1 # woe32-dll.m4 serial 3
2 dnl Copyright (C) 2005-2006, 2011 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl 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.
28 # See <http://www.haible.de/bruno/woe32dll.html> for more details.
29 AC_DEFUN([gl_WOE32_DLL],
30 [
31   AC_REQUIRE([AC_CANONICAL_HOST])
32   case "$host_os" in
33     mingw* | cygwin*)
34       AC_MSG_CHECKING([for auto-import of symbols])
35       AC_CACHE_VAL([gl_cv_ld_autoimport], [
36         gl_save_LDFLAGS="$LDFLAGS"
37         LDFLAGS="$LDFLAGS -Wl,--disable-auto-import"
38         AC_TRY_LINK([], [], [gl_cv_ld_autoimport=yes], [gl_cv_ld_autoimport=no])
39         LDFLAGS="$gl_save_LDFLAGS"])
40       AC_MSG_RESULT([$gl_cv_ld_autoimport])
41       if test $gl_cv_ld_autoimport = yes; then
42         LDFLAGS="$LDFLAGS -Wl,--disable-auto-import"
43       fi
44       ;;
45   esac
46 ])