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