Make sure we're running dejagnu tests with the right compiler.
[platform/upstream/libffi.git] / configure.ac
1 dnl Process this with autoconf to create configure
2
3 AC_PREREQ(2.68)
4
5 AC_INIT([libffi], [3.0.12-rc0], [http://gcc.gnu.org/bugs.html])
6 AC_CONFIG_HEADERS([fficonfig.h])
7
8 AC_CANONICAL_SYSTEM
9 target_alias=${target_alias-$host_alias}
10
11 . ${srcdir}/configure.host
12
13 AX_ENABLE_BUILDDIR
14
15 AM_INIT_AUTOMAKE
16
17 # The same as in boehm-gc and libstdc++. Have to borrow it from there.
18 # We must force CC to /not/ be precious variables; otherwise
19 # the wrong, non-multilib-adjusted value will be used in multilibs.
20 # As a side effect, we have to subst CFLAGS ourselves.
21 # Also save and restore CFLAGS, since AC_PROG_CC will come up with
22 # defaults of its own if none are provided.
23
24 m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
25 m4_define([_AC_ARG_VAR_PRECIOUS],[])
26 save_CFLAGS=$CFLAGS
27 AC_PROG_CC
28 CFLAGS=$save_CFLAGS
29 m4_undefine([_AC_ARG_VAR_PRECIOUS])
30 m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
31
32 AC_SUBST(CFLAGS)
33
34 AM_PROG_AS
35 AM_PROG_CC_C_O
36 AC_PROG_LIBTOOL
37 AC_CONFIG_MACRO_DIR([m4])
38
39 AX_CC_MAXOPT
40 AX_CFLAGS_WARN_ALL
41 if test "x$GCC" = "xyes"; then
42   CFLAGS="$CFLAGS -fexceptions"
43   touch testsuite/local.exp
44 else
45   cat > local.exp <<EOF
46 set CC_FOR_TARGET $CC  
47 EOF
48 fi
49
50 AM_MAINTAINER_MODE
51
52 AC_CHECK_HEADERS(sys/mman.h)
53 AC_CHECK_FUNCS(mmap)
54 AC_FUNC_MMAP_BLACKLIST
55
56 dnl The -no-testsuite modules omit the test subdir.
57 AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
58
59 TARGETDIR="unknown"
60 case "$host" in
61   aarch64*-*-*)
62         TARGET=AARCH64; TARGETDIR=aarch64
63         ;;
64
65   alpha*-*-*)
66         TARGET=ALPHA; TARGETDIR=alpha;
67         # Support 128-bit long double, changeable via command-line switch.
68         HAVE_LONG_DOUBLE='defined(__LONG_DOUBLE_128__)'
69         ;;
70
71   arm*-*-*)
72         TARGET=ARM; TARGETDIR=arm
73         ;;
74
75   amd64-*-freebsd* | amd64-*-openbsd*)
76         TARGET=X86_64; TARGETDIR=x86
77         ;;
78
79   amd64-*-freebsd*)
80         TARGET=X86_64; TARGETDIR=x86
81         ;;
82
83   amd64-*-freebsd*)
84         TARGET=X86_64; TARGETDIR=x86
85         ;;
86
87   avr32*-*-*)
88         TARGET=AVR32; TARGETDIR=avr32
89         ;;
90
91   bfin*)
92         TARGET=BFIN; TARGETDIR=bfin
93         ;;
94
95   cris-*-*)
96         TARGET=LIBFFI_CRIS; TARGETDIR=cris
97         ;;
98
99   frv-*-*)
100         TARGET=FRV; TARGETDIR=frv
101         ;;
102
103   hppa*-*-linux* | parisc*-*-linux* | hppa*-*-openbsd*)
104         TARGET=PA_LINUX; TARGETDIR=pa
105         ;;
106   hppa*64-*-hpux*)
107         TARGET=PA64_HPUX; TARGETDIR=pa
108         ;;
109   hppa*-*-hpux*)
110         TARGET=PA_HPUX; TARGETDIR=pa
111         ;;
112
113   i?86-*-freebsd* | i?86-*-openbsd*)
114         TARGET=X86_FREEBSD; TARGETDIR=x86
115         ;;
116   i?86-win32* | i?86-*-cygwin* | i?86-*-mingw* | i?86-*-os2* | i?86-*-interix*)
117         TARGET=X86_WIN32; TARGETDIR=x86
118         # All mingw/cygwin/win32 builds require -no-undefined for sharedlib.
119         # We must also check with_cross_host to decide if this is a native
120         # or cross-build and select where to install dlls appropriately.
121         if test -n "$with_cross_host" &&
122            test x"$with_cross_host" != x"no"; then
123           AM_LTLDFLAGS='-no-undefined -bindir "$(toolexeclibdir)"';
124         else
125           AM_LTLDFLAGS='-no-undefined -bindir "$(bindir)"';
126         fi
127         ;;
128   i?86-*-darwin*)
129         TARGET=X86_DARWIN; TARGETDIR=x86
130         ;;
131   i?86-*-solaris2.1[[0-9]]*)
132         TARGET=X86; TARGETDIR=x86
133         ;;
134   i?86-*-*)
135         TARGET=X86_64; TARGETDIR=x86
136         ;;
137
138   ia64*-*-*)
139         TARGET=IA64; TARGETDIR=ia64
140         ;;
141
142   m32r*-*-*)
143         TARGET=M32R; TARGETDIR=m32r
144         ;;
145
146   m68k-*-*)
147         TARGET=M68K; TARGETDIR=m68k
148         ;;
149
150   mips-sgi-irix5.* | mips-sgi-irix6.* | mips*-*-rtems*)
151         TARGET=MIPS; TARGETDIR=mips
152         ;;
153   mips*-*-linux* | mips*-*-openbsd*)
154         # Support 128-bit long double for NewABI.
155         HAVE_LONG_DOUBLE='defined(__mips64)'
156         TARGET=MIPS; TARGETDIR=mips
157         ;;
158
159   powerpc*-*-linux* | powerpc-*-sysv*)
160         TARGET=POWERPC; TARGETDIR=powerpc
161         ;;
162   powerpc-*-amigaos*)
163         TARGET=POWERPC; TARGETDIR=powerpc
164         ;;
165   powerpc-*-beos*)
166         TARGET=POWERPC; TARGETDIR=powerpc
167         ;;
168   powerpc-*-darwin* | powerpc64-*-darwin*)
169         TARGET=POWERPC_DARWIN; TARGETDIR=powerpc
170         ;;
171   powerpc-*-aix* | rs6000-*-aix*)
172         TARGET=POWERPC_AIX; TARGETDIR=powerpc
173         ;;
174   powerpc-*-freebsd* | powerpc-*-openbsd*)
175         TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc
176         ;;
177   powerpc64-*-freebsd*)
178         TARGET=POWERPC; TARGETDIR=powerpc
179         ;;
180   powerpc*-*-rtems*)
181         TARGET=POWERPC; TARGETDIR=powerpc
182         ;;
183
184   s390-*-* | s390x-*-*)
185         TARGET=S390; TARGETDIR=s390
186         ;;
187
188   sh-*-* | sh[[34]]*-*-*)
189         TARGET=SH; TARGETDIR=sh
190         ;;
191   sh64-*-* | sh5*-*-*)
192         TARGET=SH64; TARGETDIR=sh64
193         ;;
194
195   sparc*-*-*)
196         TARGET=SPARC; TARGETDIR=sparc
197         ;;
198
199   tile*-*)
200         TARGET=TILE; TARGETDIR=tile
201         ;;
202
203   x86_64-*-darwin*)
204         TARGET=X86_DARWIN; TARGETDIR=x86
205         ;;
206
207   x86_64-*-cygwin* | x86_64-*-mingw*)
208         TARGET=X86_WIN64; TARGETDIR=x86
209         # All mingw/cygwin/win32 builds require -no-undefined for sharedlib.
210         # We must also check with_cross_host to decide if this is a native
211         # or cross-build and select where to install dlls appropriately.
212         if test -n "$with_cross_host" &&
213            test x"$with_cross_host" != x"no"; then
214           AM_LTLDFLAGS='-no-undefined -bindir "$(toolexeclibdir)"';
215         else
216           AM_LTLDFLAGS='-no-undefined -bindir "$(bindir)"';
217         fi
218         ;;
219
220   x86_64-*-*)
221         TARGET=X86_64; TARGETDIR=x86
222         ;;
223 esac
224
225 AC_SUBST(AM_RUNTESTFLAGS)
226 AC_SUBST(AM_LTLDFLAGS)
227
228 if test $TARGETDIR = unknown; then
229   AC_MSG_ERROR(["libffi has not been ported to $host."])
230 fi
231
232 AM_CONDITIONAL(MIPS, test x$TARGET = xMIPS)
233 AM_CONDITIONAL(BFIN, test x$TARGET = xBFIN)
234 AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
235 AM_CONDITIONAL(X86, test x$TARGET = xX86)
236 AM_CONDITIONAL(X86_FREEBSD, test x$TARGET = xX86_FREEBSD)
237 AM_CONDITIONAL(X86_WIN32, test x$TARGET = xX86_WIN32)
238 AM_CONDITIONAL(X86_WIN64, test x$TARGET = xX86_WIN64)
239 AM_CONDITIONAL(X86_DARWIN, test x$TARGET = xX86_DARWIN)
240 AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA)
241 AM_CONDITIONAL(IA64, test x$TARGET = xIA64)
242 AM_CONDITIONAL(M32R, test x$TARGET = xM32R)
243 AM_CONDITIONAL(M68K, test x$TARGET = xM68K)
244 AM_CONDITIONAL(MOXIE, test x$TARGET = xMOXIE)
245 AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC)
246 AM_CONDITIONAL(POWERPC_AIX, test x$TARGET = xPOWERPC_AIX)
247 AM_CONDITIONAL(POWERPC_DARWIN, test x$TARGET = xPOWERPC_DARWIN)
248 AM_CONDITIONAL(POWERPC_FREEBSD, test x$TARGET = xPOWERPC_FREEBSD)
249 AM_CONDITIONAL(AARCH64, test x$TARGET = xAARCH64)
250 AM_CONDITIONAL(ARM, test x$TARGET = xARM)
251 AM_CONDITIONAL(AVR32, test x$TARGET = xAVR32)
252 AM_CONDITIONAL(LIBFFI_CRIS, test x$TARGET = xLIBFFI_CRIS)
253 AM_CONDITIONAL(FRV, test x$TARGET = xFRV)
254 AM_CONDITIONAL(S390, test x$TARGET = xS390)
255 AM_CONDITIONAL(X86_64, test x$TARGET = xX86_64)
256 AM_CONDITIONAL(SH, test x$TARGET = xSH)
257 AM_CONDITIONAL(SH64, test x$TARGET = xSH64)
258 AM_CONDITIONAL(PA_LINUX, test x$TARGET = xPA_LINUX)
259 AM_CONDITIONAL(PA_HPUX, test x$TARGET = xPA_HPUX)
260 AM_CONDITIONAL(PA64_HPUX, test x$TARGET = xPA64_HPUX)
261 AM_CONDITIONAL(TILE, test x$TARGET = xTILE)
262
263 AC_HEADER_STDC
264 AC_CHECK_FUNCS(memcpy)
265 AC_FUNC_ALLOCA
266
267 AC_CHECK_SIZEOF(double)
268 AC_CHECK_SIZEOF(long double)
269
270 # Also AC_SUBST this variable for ffi.h.
271 if test -z "$HAVE_LONG_DOUBLE"; then
272   HAVE_LONG_DOUBLE=0
273   if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
274     if test $ac_cv_sizeof_long_double != 0; then
275       HAVE_LONG_DOUBLE=1
276       AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
277     fi
278   fi
279 fi
280 AC_SUBST(HAVE_LONG_DOUBLE)
281
282 AC_C_BIGENDIAN
283
284 GCC_AS_CFI_PSEUDO_OP
285
286 if test x$TARGET = xSPARC; then
287     AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
288         libffi_cv_as_sparc_ua_pcrel, [
289         save_CFLAGS="$CFLAGS"
290         save_LDFLAGS="$LDFLAGS"
291         CFLAGS="$CFLAGS -fpic"
292         LDFLAGS="$LDFLAGS -shared"
293         AC_TRY_LINK([asm (".text; foo: nop; .data; .align 4; .byte 0; .uaword %r_disp32(foo); .text");],,
294                     [libffi_cv_as_sparc_ua_pcrel=yes],
295                     [libffi_cv_as_sparc_ua_pcrel=no])
296         CFLAGS="$save_CFLAGS"
297         LDFLAGS="$save_LDFLAGS"])
298     if test "x$libffi_cv_as_sparc_ua_pcrel" = xyes; then
299         AC_DEFINE(HAVE_AS_SPARC_UA_PCREL, 1,
300                   [Define if your assembler and linker support unaligned PC relative relocs.])
301     fi
302
303     AC_CACHE_CHECK([assembler .register pseudo-op support],
304        libffi_cv_as_register_pseudo_op, [
305        libffi_cv_as_register_pseudo_op=unknown
306        # Check if we have .register
307        AC_TRY_COMPILE([asm (".register %g2, #scratch");],,
308                        [libffi_cv_as_register_pseudo_op=yes],
309                        [libffi_cv_as_register_pseudo_op=no])
310     ])
311     if test "x$libffi_cv_as_register_pseudo_op" = xyes; then
312        AC_DEFINE(HAVE_AS_REGISTER_PSEUDO_OP, 1,
313                [Define if your assembler supports .register.])
314     fi
315 fi
316
317 if test x$TARGET = xX86 || test x$TARGET = xX86_WIN32 || test x$TARGET = xX86_64; then
318     AC_CACHE_CHECK([assembler supports pc related relocs],
319         libffi_cv_as_x86_pcrel, [
320         libffi_cv_as_x86_pcrel=yes
321         echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s
322         if $CC $CFLAGS -c conftest.s 2>&1 | $EGREP -i 'illegal|warning' > /dev/null; then
323             libffi_cv_as_x86_pcrel=no
324         fi
325         ])
326     if test "x$libffi_cv_as_x86_pcrel" = xyes; then
327         AC_DEFINE(HAVE_AS_X86_PCREL, 1,
328                   [Define if your assembler supports PC relative relocs.])
329     fi
330
331     AC_CACHE_CHECK([assembler .ascii pseudo-op support],
332        libffi_cv_as_ascii_pseudo_op, [
333        libffi_cv_as_ascii_pseudo_op=unknown
334        # Check if we have .ascii
335        AC_TRY_COMPILE([asm (".ascii \\"string\\"");],,
336                        [libffi_cv_as_ascii_pseudo_op=yes],
337                        [libffi_cv_as_ascii_pseudo_op=no])
338     ])
339     if test "x$libffi_cv_as_ascii_pseudo_op" = xyes; then
340        AC_DEFINE(HAVE_AS_ASCII_PSEUDO_OP, 1,
341                [Define if your assembler supports .ascii.])
342     fi
343
344     AC_CACHE_CHECK([assembler .string pseudo-op support],
345        libffi_cv_as_string_pseudo_op, [
346        libffi_cv_as_string_pseudo_op=unknown
347        # Check if we have .string
348        AC_TRY_COMPILE([asm (".string \\"string\\"");],,
349                        [libffi_cv_as_string_pseudo_op=yes],
350                        [libffi_cv_as_string_pseudo_op=no])
351     ])
352     if test "x$libffi_cv_as_string_pseudo_op" = xyes; then
353        AC_DEFINE(HAVE_AS_STRING_PSEUDO_OP, 1,
354                [Define if your assembler supports .string.])
355     fi
356 fi
357
358 # On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC.
359 AC_ARG_ENABLE(pax_emutramp,
360   [  --enable-pax_emutramp       enable pax emulated trampolines, for we can't use PROT_EXEC],
361   if test "$enable_pax_emutramp" = "yes"; then
362     AC_DEFINE(FFI_MMAP_EXEC_EMUTRAMP_PAX, 1,
363       [Define this if you want to enable pax emulated trampolines])
364   fi)
365
366 if test x$TARGET = xX86_WIN64; then
367     LT_SYS_SYMBOL_USCORE
368     if test "x$sys_symbol_underscore" = xyes; then
369         AC_DEFINE(SYMBOL_UNDERSCORE, 1, [Define if symbols are underscored.])
370     fi
371 fi
372
373 FFI_EXEC_TRAMPOLINE_TABLE=0
374 case "$target" in
375      *arm*-apple-darwin*)
376        FFI_EXEC_TRAMPOLINE_TABLE=1
377        AC_DEFINE(FFI_EXEC_TRAMPOLINE_TABLE, 1,
378                  [Cannot use PROT_EXEC on this target, so, we revert to
379                    alternative means])
380      ;;
381      *-apple-darwin1* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris*)
382        AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
383                  [Cannot use malloc on this target, so, we revert to
384                    alternative means])
385      ;;
386 esac
387 AM_CONDITIONAL(FFI_EXEC_TRAMPOLINE_TABLE, test x$FFI_EXEC_TRAMPOLINE_TABLE = x1)
388 AC_SUBST(FFI_EXEC_TRAMPOLINE_TABLE)
389
390 if test x$TARGET = xX86_64; then
391     AC_CACHE_CHECK([assembler supports unwind section type],
392         libffi_cv_as_x86_64_unwind_section_type, [
393         libffi_cv_as_x86_64_unwind_section_type=yes
394         echo '.section .eh_frame,"a",@unwind' > conftest.s
395         if $CC $CFLAGS -c conftest.s 2>&1 | grep -i warning > /dev/null; then
396             libffi_cv_as_x86_64_unwind_section_type=no
397         fi
398         ])
399     if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
400         AC_DEFINE(HAVE_AS_X86_64_UNWIND_SECTION_TYPE, 1,
401                   [Define if your assembler supports unwind section type.])
402     fi
403 fi
404
405 if test "x$GCC" = "xyes"; then
406   AC_CACHE_CHECK([whether .eh_frame section should be read-only],
407       libffi_cv_ro_eh_frame, [
408         libffi_cv_ro_eh_frame=no
409         echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
410         if $CC $CFLAGS -c -fpic -fexceptions -o conftest.o conftest.c > /dev/null 2>&1; then
411             objdump -h conftest.o > conftest.dump 2>&1
412             libffi_eh_frame_line=`grep -n eh_frame conftest.dump | cut -d: -f 1`
413             libffi_test_line=`expr $libffi_eh_frame_line + 1`p
414             sed -n $libffi_test_line conftest.dump > conftest.line
415             if grep READONLY conftest.line > /dev/null; then
416                 libffi_cv_ro_eh_frame=yes
417             fi
418         fi
419         rm -f conftest.*
420       ])
421   if test "x$libffi_cv_ro_eh_frame" = xyes; then
422       AC_DEFINE(HAVE_RO_EH_FRAME, 1,
423               [Define if .eh_frame sections should be read-only.])
424       AC_DEFINE(EH_FRAME_FLAGS, "a",
425               [Define to the flags needed for the .section .eh_frame directive.  ])
426   else
427       AC_DEFINE(EH_FRAME_FLAGS, "aw",
428               [Define to the flags needed for the .section .eh_frame directive.  ])
429   fi
430
431   AC_CACHE_CHECK([for __attribute__((visibility("hidden")))],
432       libffi_cv_hidden_visibility_attribute, [
433         echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1  ; }' > conftest.c
434         libffi_cv_hidden_visibility_attribute=no
435         if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
436             if grep '\.hidden.*foo' conftest.s >/dev/null; then
437                 libffi_cv_hidden_visibility_attribute=yes
438             fi
439         fi
440         rm -f conftest.*
441       ])
442   if test $libffi_cv_hidden_visibility_attribute = yes; then
443       AC_DEFINE(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE, 1,
444               [Define if __attribute__((visibility("hidden"))) is supported.])
445   fi
446 fi
447
448 AH_BOTTOM([
449 #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
450 #ifdef LIBFFI_ASM
451 #define FFI_HIDDEN(name) .hidden name
452 #else
453 #define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
454 #endif
455 #else
456 #ifdef LIBFFI_ASM
457 #define FFI_HIDDEN(name)
458 #else
459 #define FFI_HIDDEN
460 #endif
461 #endif
462 ])
463
464 AC_SUBST(TARGET)
465 AC_SUBST(TARGETDIR)
466
467 AC_SUBST(SHELL)
468
469 AC_ARG_ENABLE(debug,
470 [  --enable-debug          debugging mode],
471   if test "$enable_debug" = "yes"; then
472     AC_DEFINE(FFI_DEBUG, 1, [Define this if you want extra debugging.])
473   fi)
474 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
475
476 AC_ARG_ENABLE(structs,
477 [  --disable-structs       omit code for struct support],
478   if test "$enable_structs" = "no"; then
479     AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this is you do not want support for aggregate types.])
480   fi)
481 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
482
483 AC_ARG_ENABLE(raw-api,
484 [  --disable-raw-api       make the raw api unavailable],
485   if test "$enable_raw_api" = "no"; then
486     AC_DEFINE(FFI_NO_RAW_API, 1, [Define this is you do not want support for the raw API.])
487   fi)
488
489 AC_ARG_ENABLE(purify-safety,
490 [  --enable-purify-safety  purify-safe mode],
491   if test "$enable_purify_safety" = "yes"; then
492     AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
493   fi)
494
495 # These variables are only ever used when we cross-build to X86_WIN32.
496 # And we only support this with GCC, so...
497 if test x"$GCC" != x"no"; then
498   if test -n "$with_cross_host" &&
499      test x"$with_cross_host" != x"no"; then
500     toolexecdir='$(exec_prefix)/$(target_alias)'
501     toolexeclibdir='$(toolexecdir)/lib'
502   else
503     toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
504     toolexeclibdir='$(libdir)'
505   fi
506   multi_os_directory=`$CC -print-multi-os-directory`
507   case $multi_os_directory in
508     .) ;; # Avoid trailing /.
509     *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
510   esac
511   AC_SUBST(toolexecdir)
512   AC_SUBST(toolexeclibdir)
513 fi
514
515 AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
516 AC_CONFIG_COMMANDS(src, [
517 test -d src || mkdir src
518 test -d src/$TARGETDIR || mkdir src/$TARGETDIR
519 ], [TARGETDIR="$TARGETDIR"])
520
521 AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h)
522
523 AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc)
524
525 AC_OUTPUT