configury: improve dlsym underscore detection.
[m4/ericb.git] / configure.ac
blob342aecfc542740448fbbd28e7b2b859a6a48ed81
1 # Configure template for GNU m4.           -*-Autoconf-*-
2 # Copyright (C) 1991-1994, 2000-2002, 2004-2014 Free Software
3 # Foundation, Inc.
5 # This file is part of GNU M4.
7 # GNU M4 is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # GNU M4 is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 dnl We depend on autotest's ./testsuite -C.
21 AC_PREREQ([2.62])
23 ## ------------------------ ##
24 ## Autoconf initialization. ##
25 ## ------------------------ ##
26 m4_define([M4_VERSION],
27           m4_esyscmd([build-aux/git-version-gen .tarball-version]))
28 m4_bmatch(m4_defn([M4_VERSION]), [^[0-9]], [],
29           [m4_define([M4_VERSION], [1.9a])])
30 AC_INIT([GNU M4], m4_defn([M4_VERSION]), [bug-m4@gnu.org])
32 AC_CONFIG_SRCDIR([src/m4.h])
33 AC_CONFIG_AUX_DIR([build-aux])
34 AC_CONFIG_MACRO_DIR([build-aux/m4])
35 AC_CONFIG_LIBOBJ_DIR([m4/gnu])
36 AC_CONFIG_TESTDIR([tests])
37 AC_CONFIG_HEADERS([config.h])
38 AC_CONFIG_FILES([tests/m4], [chmod +x tests/m4])
41 ## -------------------------- ##
42 ## M4 specific configuration. ##
43 ## -------------------------- ##
44 dnl Autoconf recommends that packages use lowercase for their package-specific
45 dnl prefix for cache variables.  But in the case of m4, that collides with
46 dnl the m4_ namespace provided by m4sugar, so we prefer M4_ as our
47 dnl package-specific prefix.
48 m4_pattern_forbid([^M4_[A-Z]])
50 AC_DEFUN([M4_DEFAULT_PRELOAD], [])
51 M4_default_preload="M4_DEFAULT_PRELOAD"
54 ## ------------------------ ##
55 ## Automake Initialization. ##
56 ## ------------------------ ##
57 AM_INIT_AUTOMAKE([1.10b subdir-objects dist-bzip2 dist-xz
58 color-tests parallel-tests silent-rules]
59 m4_if(m4_index(m4_defn([M4_VERSION]), [-]), [-1], [gnits], [gnu]))
60 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
63 ## ------------------ ##
64 ## C compiler checks. ##
65 ## ------------------ ##
66 AC_PROG_CC
67 AC_DEFUN([gl_CXX_CHOICE_DEFAULT_NO])
68 M4_EARLY
70 # Maintainer note - comment this line out if you plan to rerun
71 # GNULIB_POSIXCHECK testing to see if M4 should be using more modules.
72 # Leave it uncommented for normal releases, for faster ./configure.
73 gl_ASSERT_NO_GNULIB_POSIXCHECK
75 AC_SYS_LARGEFILE
76 AC_PROG_CPP
77 AM_PROG_CC_C_O
78 M4_CHECK_DEBUGGING
81 ## --------------------------- ##
82 ## C compiler characteristics. ##
83 ## --------------------------- ##
84 AC_TYPE_SIZE_T
85 AC_CHECK_SIZEOF([long long int])
87 AS_CASE([$host], [*-*-os2*], [OS2_LDFLAGS=-Zargs-resp])
88 AC_SUBST([OS2_LDFLAGS])
91 ## ----------------------- ##
92 ## Libtool initialization. ##
93 ## ----------------------- ##
94 LT_PREREQ([2.2])
95 LT_INIT([shared dlopen win32-dll])
97 AC_ARG_ENABLE([gcc-warnings],
98   [AS_HELP_STRING([--enable-gcc-warnings],
99                   [turn on lots of GCC warnings (for developers)])],
100   [case $enableval in
101      yes|no) ;;
102      *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
103    esac
104    gl_gcc_warnings=$enableval],
105   [gl_gcc_warnings=no]
108 if test "$gl_gcc_warnings" = yes; then
109   gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
110   AC_SUBST([WERROR_CFLAGS])
112   # This, $nw, is the list of warnings we disable.
113   nw=
114   nw="$nw -Waggregate-return"       # K&R is anachronistic
115   nw="$nw -Wtraditional-conversion" # K&R is anachronistic
116   nw="$nw -Wundef"                  # K&R is anachronistic
117   nw="$nw -Wlong-long"              # C90 is anachronistic
118   nw="$nw -Wsystem-headers"         # Don't let system headers trigger warnings
119   nw="$nw -Wpadded"                 # Our structs are not packed
120   nw="$nw -Wformat-nonliteral"      # Needed in builtin.c
121   nw="$nw -Wconversion"             # Too many warnings for now
122   nw="$nw -Wsign-conversion"        # Too many warnings for now
123   nw="$nw -Wcast-qual"              # Too many warnings for now
124   nw="$nw -Wswitch-enum"            # Too many warnings for now
125   # gcc 4.4.6 complains enum-compare is C++ only; gcc 4.7.0 implies it in -Wall
126   nw="$nw -Wenum-compare"
128   # Gnulib uses '#pragma GCC diagnostic push' to silence some
129   # warnings, but older gcc doesn't support this.
130   AC_CACHE_CHECK([whether pragma GCC diagnostic push works],
131     [M4_cv_gcc_pragma_push_works], [
132     save_CFLAGS=$CFLAGS
133     CFLAGS='-Wunknown-pragmas -Werror'
134     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
135       #pragma GCC diagnostic push
136       #pragma GCC diagnostic pop
137     ]])],
138     [M4_cv_gcc_pragma_push_works=yes],
139     [M4_cv_gcc_pragma_push_works=no])
140     CFLAGS=$save_CFLAGS])
141   if test $M4_cv_gcc_pragma_push_works = no; then
142     nw="$nw -Wmissing-prototypes"
143     nw="$nw -Wmissing-declarations"
144     nw="$nw -Wunreachable-code"
145   fi
147   gl_MANYWARN_ALL_GCC([ws])
148   gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
149   for w in $ws; do
150     gl_WARN_ADD([$w])
151   done
153   gl_WARN_ADD([-fdiagnostics-show-option])
154   gl_WARN_ADD([-funit-at-a-time])
156   AC_SUBST([WARN_CFLAGS])
158   AH_VERBATIM([FORTIFY_SOURCE],
159   [/* Enable compile-time and run-time bounds-checking, and some warnings,
160       without upsetting newer glibc. */
161    #if defined __OPTIMIZE__ && __OPTIMIZE__
162    # define _FORTIFY_SOURCE 2
163    #endif
164   ])
167 # Use gcc's -pipe option if available: for faster compilation.
168 case "$CFLAGS" in
169   *-pipe* ) ;;
170         * ) _LT_COMPILER_OPTION([if $compiler supports -pipe],
171                 [M4_cv_prog_compiler_pipe],
172                 [-pipe -c conftest.$ac_ext], [],
173                 [CFLAGS="$CFLAGS -pipe"])
174               ;;
175 esac
178 ## ------------------------------- ##
179 ## Dynamic Loader Characteristics. ##
180 ## ------------------------------- ##
182 LT_LIB_DLLOAD
183 LT_SYS_SYMBOL_USCORE
185 LT_SYS_MODULE_EXT
187 if test yes = "$sys_symbol_underscore"; then
188   libm4_shlibext=$libltdl_cv_shlibext
190   AC_MSG_CHECKING([whether dlsym requires underscore prefixed symbols])
191   AC_CACHE_VAL([libm4_cv_sys_dlsym_uscore], [dnl
192     libname=conftmod # stay within 8.3 filename limits!
193     cat >$libname.$ac_ext <<_M4_EOF
194 [#line $LINENO "configure"
195 #include "confdefs.h"
196 /* When -fvisibility=hidden is used, assume the code has been annotated
197    correspondingly for the symbols needed.  */
198 #if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3))
199 int fnord () __attribute__((visibility("default")));
200 #endif
201 int fnord () { return 42; }]
202 _M4_EOF
204     # fn_module_cmds module_cmds
205     # Execute tilde-delimited MODULE_CMDS with environment primed for
206     # ${module_cmds} or ${archive_cmds} type content.
207     fn_module_cmds ()
208     {( # subshell avoids polluting parent global environment
209         module_cmds_save_ifs=$IFS; IFS='~'
210         for cmd in $1; do
211           IFS=$module_cmds_save_ifs
212           libobjs=$libname.$ac_objext; lib=$libname$libm4_shlibext
213           rpath=/not-exists; soname=$libname$libm4_shlibext; output_objdir=.
214           major=; versuffix=; verstring=; deplibs=
215           ECHO=echo; wl=$lt_prog_compiler_wl; allow_undefined_flag=
216           eval $cmd
217         done
218         IFS=$module_cmds_save_ifs
219     )}
221     # Compile a loadable module using libtool macro expansion results.
222     $CC $pic_flag -c $libname.$ac_ext
223     fn_module_cmds "${module_cmds:-$archive_cmds}"
225     # Try to fetch fnord with dlsym().
226     libm4_dlunknown=0; libm4_dlnouscore=1; libm4_dluscore=2
227     cat >conftest.$ac_ext <<_M4_EOF
228 [#line $LINENO "configure"
229 #include "confdefs.h"
230 #if HAVE_DLFCN_H
231 #include <dlfcn.h>
232 #endif
233 #include <stdio.h>
234 #ifndef RTLD_GLOBAL
235 #  ifdef DL_GLOBAL
236 #    define RTLD_GLOBAL DL_GLOBAL
237 #  else
238 #    define RTLD_GLOBAL 0
239 #  endif
240 #endif
241 #ifndef RTLD_NOW
242 #  ifdef DL_NOW
243 #    define RTLD_NOW DL_NOW
244 #  else
245 #    define RTLD_NOW 0
246 #  endif
247 #endif
248 int main () {
249   void *handle = dlopen ("`pwd`/$libname$libm4_shlibext", RTLD_GLOBAL|RTLD_NOW);
250   int status = $libm4_dlunknown;
251   if (handle) {
252     if (dlsym (handle, "fnord"))
253       status = $libm4_dlnouscore;
254     else {
255       if (dlsym (handle, "_fnord"))
256         status = $libm4_dluscore;
257       else
258         puts (dlerror ());
259     }
260     dlclose (handle);
261   } else
262     puts (dlerror ());
263   return status;
265 _M4_EOF
266     if AC_TRY_EVAL(ac_link) && test -s "conftest$ac_exeext" 2>/dev/null; then
267       (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null
268       libm4_status=$?
269       case x$libm4_status in
270         x$libm4_dlnouscore) libm4_cv_sys_dlsym_uscore=no ;;
271         x$libm4_dluscore) libm4_cv_sys_dlsym_uscore=yes ;;
272         x*) libm4_cv_sys_dlsym_uscore=unknown ;;
273       esac
274     fi
275     rm -rf conftest* $libname*
276   ])
277   sys_dlsym_uscore=$libm4_cv_sys_dlsym_uscore
278   AC_MSG_RESULT($sys_dlsym_uscore)
279   if test yes = "$sys_dlsym_uscore"; then
280     AC_DEFINE([DLSYM_USCORE], [1],
281       [Define if dlsym() requires a leading underscore in symbol names.])
282   fi
285 AC_DEFINE_UNQUOTED([PATH_SEPARATOR], ['$PATH_SEPARATOR'],
286                    [Define this to system search path delimiter])
289 ## ---------------- ##
290 ## Gettext support. ##
291 ## ---------------- ##
292 AM_GNU_GETTEXT([external])
293 AM_GNU_GETTEXT_NEED([need-formatstring-macros])
294 AM_GNU_GETTEXT_VERSION([0.16])
295 M4_GNU_GETTEXT
298 ## --------------- ##
299 ## Gnulib support. ##
300 ## --------------- ##
301 M4_INIT
303 gl_VERSION_ETC
305 # Gnulib doesn't always do things quite the way M4 would like...
306 M4_ERROR
307 M4_GETOPT
308 M4_OBSTACK
309 M4_REGEX
310 M4_RENAME
313 ## ------------------------- ##
314 ## C headers required by M4. ##
315 ## ------------------------- ##
316 AC_CHECK_HEADERS_ONCE([limits.h])
318 if test $ac_cv_header_stdbool_h = yes; then
319   INCLUDE_STDBOOL_H='#include <stdbool.h>'
320 else
321   INCLUDE_STDBOOL_H='#include <gnu/stdbool.h>'
323 AC_SUBST([INCLUDE_STDBOOL_H])
326 ## --------------------------------- ##
327 ## Library functions required by M4. ##
328 ## --------------------------------- ##
329 AC_CHECK_FUNCS_ONCE([calloc strerror])
331 AM_WITH_DMALLOC
333 M4_SYS_STACKOVF
335 # This is for the modules
336 AC_STRUCT_TM
337 AC_FUNC_STRFTIME
338 AC_CHECK_FUNCS_ONCE([getcwd gethostname mktime uname])
341 ## ------------------ ##
342 ## Configure options. ##
343 ## ------------------ ##
345 M4_LIB_GMP
346 AM_CONDITIONAL([USE_GMP], [test "x$USE_GMP" = xyes])
347 M4_SYSCMD
350 ## -------- ##
351 ## Outputs. ##
352 ## -------- ##
353 AC_CONFIG_FILES([
354 Makefile
355 doc/Makefile
356 m4/gnu/Makefile
357 m4/system.h:m4/system_.h
358 tests/atlocal
359 tests/gnu/Makefile
362 AC_OUTPUT