1 dnl Process this with autoconf to create configure
5 AC_INIT([libffi], [3.1], [http://github.com/atgreen/libffi/issues])
6 AC_CONFIG_HEADERS([fficonfig.h])
9 target_alias=${target_alias-$host_alias}
13 LDFLAGS=`echo $LDFLAGS | sed "s/\-B[^ ]*libgloss\/frv\///"`\ -B`pwd`/../libgloss/frv/
21 # The same as in boehm-gc and libstdc++. Have to borrow it from there.
22 # We must force CC to /not/ be precious variables; otherwise
23 # the wrong, non-multilib-adjusted value will be used in multilibs.
24 # As a side effect, we have to subst CFLAGS ourselves.
25 # Also save and restore CFLAGS, since AC_PROG_CC will come up with
26 # defaults of its own if none are provided.
28 m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
29 m4_define([_AC_ARG_VAR_PRECIOUS],[])
34 m4_undefine([_AC_ARG_VAR_PRECIOUS])
35 m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
42 AC_CONFIG_MACRO_DIR([m4])
44 # Test for 64-bit build.
45 AC_CHECK_SIZEOF([size_t])
49 # The AX_CFLAGS_WARN_ALL macro doesn't currently work for sunpro
51 if test "$ax_cv_c_compiler_vendor" != "sun"; then
55 if test "x$GCC" = "xyes"; then
56 CFLAGS="$CFLAGS -fexceptions"
60 set CC_FOR_TARGET "$CC"
61 set CXX_FOR_TARGET "$CXX"
66 AC_CHECK_HEADERS(sys/mman.h)
68 AC_FUNC_MMAP_BLACKLIST
70 dnl The -no-testsuite modules omit the test subdir.
71 AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
74 HAVE_LONG_DOUBLE_VARIANT=0
77 TARGET=AARCH64; TARGETDIR=aarch64
81 TARGET=ALPHA; TARGETDIR=alpha;
82 # Support 128-bit long double, changeable via command-line switch.
83 HAVE_LONG_DOUBLE='defined(__LONG_DOUBLE_128__)'
87 TARGET=ARC; TARGETDIR=arc
91 TARGET=ARM; TARGETDIR=arm
94 amd64-*-freebsd* | amd64-*-openbsd*)
95 TARGET=X86_64; TARGETDIR=x86
99 TARGET=X86_64; TARGETDIR=x86
103 TARGET=X86_64; TARGETDIR=x86
107 TARGET=AVR32; TARGETDIR=avr32
111 TARGET=BFIN; TARGETDIR=bfin
115 TARGET=LIBFFI_CRIS; TARGETDIR=cris
119 TARGET=FRV; TARGETDIR=frv
122 hppa*-*-linux* | parisc*-*-linux* | hppa*-*-openbsd*)
123 TARGET=PA_LINUX; TARGETDIR=pa
126 TARGET=PA64_HPUX; TARGETDIR=pa
129 TARGET=PA_HPUX; TARGETDIR=pa
132 i?86-*-freebsd* | i?86-*-openbsd*)
133 TARGET=X86_FREEBSD; TARGETDIR=x86
135 i?86-win32* | i?86-*-cygwin* | i?86-*-mingw* | i?86-*-os2* | i?86-*-interix*)
136 TARGET=X86_WIN32; TARGETDIR=x86
137 # All mingw/cygwin/win32 builds require -no-undefined for sharedlib.
138 # We must also check with_cross_host to decide if this is a native
139 # or cross-build and select where to install dlls appropriately.
140 if test -n "$with_cross_host" &&
141 test x"$with_cross_host" != x"no"; then
142 AM_LTLDFLAGS='-no-undefined -bindir "$(toolexeclibdir)"';
144 AM_LTLDFLAGS='-no-undefined -bindir "$(bindir)"';
148 TARGET=X86_DARWIN; TARGETDIR=x86
150 i?86-*-solaris2.1[[0-9]]*)
152 if test $ac_cv_sizeof_size_t = 4; then
160 TARGET=X86_DARWIN; TARGETDIR=x86
163 x86_64-*-cygwin* | x86_64-*-mingw*)
164 TARGET=X86_WIN64; TARGETDIR=x86
165 # All mingw/cygwin/win32 builds require -no-undefined for sharedlib.
166 # We must also check with_cross_host to decide if this is a native
167 # or cross-build and select where to install dlls appropriately.
168 if test -n "$with_cross_host" &&
169 test x"$with_cross_host" != x"no"; then
170 AM_LTLDFLAGS='-no-undefined -bindir "$(toolexeclibdir)"';
172 AM_LTLDFLAGS='-no-undefined -bindir "$(bindir)"';
176 i?86-*-* | x86_64-*-*)
178 if test $ac_cv_sizeof_size_t = 4; then
193 TARGET=IA64; TARGETDIR=ia64
197 TARGET=M32R; TARGETDIR=m32r
201 TARGET=M68K; TARGETDIR=m68k
205 TARGET=M88K; TARGETDIR=m88k
209 TARGET=MICROBLAZE; TARGETDIR=microblaze
213 TARGET=MOXIE; TARGETDIR=moxie
217 TARGET=METAG; TARGETDIR=metag
220 mips-sgi-irix5.* | mips-sgi-irix6.* | mips*-*-rtems*)
221 TARGET=MIPS; TARGETDIR=mips
223 mips*-*linux* | mips*-*-openbsd*)
224 # Support 128-bit long double for NewABI.
225 HAVE_LONG_DOUBLE='defined(__mips64)'
226 TARGET=MIPS; TARGETDIR=mips
230 TARGET=NIOS2; TARGETDIR=nios2
233 powerpc*-*-linux* | powerpc-*-sysv*)
234 TARGET=POWERPC; TARGETDIR=powerpc
235 HAVE_LONG_DOUBLE_VARIANT=1
238 TARGET=POWERPC; TARGETDIR=powerpc
241 TARGET=POWERPC; TARGETDIR=powerpc
243 powerpc-*-darwin* | powerpc64-*-darwin*)
244 TARGET=POWERPC_DARWIN; TARGETDIR=powerpc
246 powerpc-*-aix* | rs6000-*-aix*)
247 TARGET=POWERPC_AIX; TARGETDIR=powerpc
249 powerpc-*-freebsd* | powerpc-*-openbsd*)
250 TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc
251 HAVE_LONG_DOUBLE_VARIANT=1
253 powerpc64-*-freebsd*)
254 TARGET=POWERPC; TARGETDIR=powerpc
257 TARGET=POWERPC; TARGETDIR=powerpc
260 s390-*-* | s390x-*-*)
261 TARGET=S390; TARGETDIR=s390
264 sh-*-* | sh[[34]]*-*-*)
265 TARGET=SH; TARGETDIR=sh
268 TARGET=SH64; TARGETDIR=sh64
272 TARGET=SPARC; TARGETDIR=sparc
276 TARGET=TILE; TARGETDIR=tile
280 TARGET=VAX; TARGETDIR=vax
284 TARGET=XTENSA; TARGETDIR=xtensa
289 AC_SUBST(AM_RUNTESTFLAGS)
290 AC_SUBST(AM_LTLDFLAGS)
292 if test $TARGETDIR = unknown; then
293 AC_MSG_ERROR(["libffi has not been ported to $host."])
296 AM_CONDITIONAL(MIPS, test x$TARGET = xMIPS)
297 AM_CONDITIONAL(BFIN, test x$TARGET = xBFIN)
298 AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
299 AM_CONDITIONAL(X86, test x$TARGET = xX86)
300 AM_CONDITIONAL(X86_FREEBSD, test x$TARGET = xX86_FREEBSD)
301 AM_CONDITIONAL(X86_WIN32, test x$TARGET = xX86_WIN32)
302 AM_CONDITIONAL(X86_WIN64, test x$TARGET = xX86_WIN64)
303 AM_CONDITIONAL(X86_DARWIN, test x$TARGET = xX86_DARWIN)
304 AM_CONDITIONAL(X86_DARWIN32, test x$TARGET = xX86_DARWIN && test $ac_cv_sizeof_size_t = 4)
305 AM_CONDITIONAL(X86_DARWIN64, test x$TARGET = xX86_DARWIN && test $ac_cv_sizeof_size_t = 8)
306 AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA)
307 AM_CONDITIONAL(IA64, test x$TARGET = xIA64)
308 AM_CONDITIONAL(M32R, test x$TARGET = xM32R)
309 AM_CONDITIONAL(M68K, test x$TARGET = xM68K)
310 AM_CONDITIONAL(M88K, test x$TARGET = xM88K)
311 AM_CONDITIONAL(MICROBLAZE, test x$TARGET = xMICROBLAZE)
312 AM_CONDITIONAL(METAG, test x$TARGET = xMETAG)
313 AM_CONDITIONAL(MOXIE, test x$TARGET = xMOXIE)
314 AM_CONDITIONAL(NIOS2, test x$TARGET = xNIOS2)
315 AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC)
316 AM_CONDITIONAL(POWERPC_AIX, test x$TARGET = xPOWERPC_AIX)
317 AM_CONDITIONAL(POWERPC_DARWIN, test x$TARGET = xPOWERPC_DARWIN)
318 AM_CONDITIONAL(POWERPC_FREEBSD, test x$TARGET = xPOWERPC_FREEBSD)
319 AM_CONDITIONAL(AARCH64, test x$TARGET = xAARCH64)
320 AM_CONDITIONAL(ARC, test x$TARGET = xARC)
321 AM_CONDITIONAL(ARM, test x$TARGET = xARM)
322 AM_CONDITIONAL(AVR32, test x$TARGET = xAVR32)
323 AM_CONDITIONAL(LIBFFI_CRIS, test x$TARGET = xLIBFFI_CRIS)
324 AM_CONDITIONAL(FRV, test x$TARGET = xFRV)
325 AM_CONDITIONAL(S390, test x$TARGET = xS390)
326 AM_CONDITIONAL(X86_64, test x$TARGET = xX86_64)
327 AM_CONDITIONAL(SH, test x$TARGET = xSH)
328 AM_CONDITIONAL(SH64, test x$TARGET = xSH64)
329 AM_CONDITIONAL(PA_LINUX, test x$TARGET = xPA_LINUX)
330 AM_CONDITIONAL(PA_HPUX, test x$TARGET = xPA_HPUX)
331 AM_CONDITIONAL(PA64_HPUX, test x$TARGET = xPA64_HPUX)
332 AM_CONDITIONAL(TILE, test x$TARGET = xTILE)
333 AM_CONDITIONAL(VAX, test x$TARGET = xVAX)
334 AM_CONDITIONAL(XTENSA, test x$TARGET = xXTENSA)
337 AC_CHECK_FUNCS(memcpy)
340 AC_CHECK_SIZEOF(double)
341 AC_CHECK_SIZEOF(long double)
343 # Also AC_SUBST this variable for ffi.h.
344 if test -z "$HAVE_LONG_DOUBLE"; then
346 if test $ac_cv_sizeof_long_double != 0; then
347 if test $HAVE_LONG_DOUBLE_VARIANT != 0; then
348 AC_DEFINE(HAVE_LONG_DOUBLE_VARIANT, 1, [Define if you support more than one size of the long double type])
351 if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
353 AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
358 AC_SUBST(HAVE_LONG_DOUBLE)
359 AC_SUBST(HAVE_LONG_DOUBLE_VARIANT)
365 if test x$TARGET = xSPARC; then
366 AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
367 libffi_cv_as_sparc_ua_pcrel, [
368 save_CFLAGS="$CFLAGS"
369 save_LDFLAGS="$LDFLAGS"
370 CFLAGS="$CFLAGS -fpic"
371 LDFLAGS="$LDFLAGS -shared"
372 AC_TRY_LINK([asm (".text; foo: nop; .data; .align 4; .byte 0; .uaword %r_disp32(foo); .text");],,
373 [libffi_cv_as_sparc_ua_pcrel=yes],
374 [libffi_cv_as_sparc_ua_pcrel=no])
375 CFLAGS="$save_CFLAGS"
376 LDFLAGS="$save_LDFLAGS"])
377 if test "x$libffi_cv_as_sparc_ua_pcrel" = xyes; then
378 AC_DEFINE(HAVE_AS_SPARC_UA_PCREL, 1,
379 [Define if your assembler and linker support unaligned PC relative relocs.])
382 AC_CACHE_CHECK([assembler .register pseudo-op support],
383 libffi_cv_as_register_pseudo_op, [
384 libffi_cv_as_register_pseudo_op=unknown
385 # Check if we have .register
386 AC_TRY_COMPILE(,[asm (".register %g2, #scratch");],
387 [libffi_cv_as_register_pseudo_op=yes],
388 [libffi_cv_as_register_pseudo_op=no])
390 if test "x$libffi_cv_as_register_pseudo_op" = xyes; then
391 AC_DEFINE(HAVE_AS_REGISTER_PSEUDO_OP, 1,
392 [Define if your assembler supports .register.])
396 if test x$TARGET = xX86 || test x$TARGET = xX86_WIN32 || test x$TARGET = xX86_64; then
397 AC_CACHE_CHECK([assembler supports pc related relocs],
398 libffi_cv_as_x86_pcrel, [
399 libffi_cv_as_x86_pcrel=no
400 echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s
401 if $CC $CFLAGS -c conftest.s > /dev/null 2>&1; then
402 libffi_cv_as_x86_pcrel=yes
405 if test "x$libffi_cv_as_x86_pcrel" = xyes; then
406 AC_DEFINE(HAVE_AS_X86_PCREL, 1,
407 [Define if your assembler supports PC relative relocs.])
410 AC_CACHE_CHECK([assembler .ascii pseudo-op support],
411 libffi_cv_as_ascii_pseudo_op, [
412 libffi_cv_as_ascii_pseudo_op=unknown
413 # Check if we have .ascii
414 AC_TRY_COMPILE(,[asm (".ascii \\"string\\"");],
415 [libffi_cv_as_ascii_pseudo_op=yes],
416 [libffi_cv_as_ascii_pseudo_op=no])
418 if test "x$libffi_cv_as_ascii_pseudo_op" = xyes; then
419 AC_DEFINE(HAVE_AS_ASCII_PSEUDO_OP, 1,
420 [Define if your assembler supports .ascii.])
423 AC_CACHE_CHECK([assembler .string pseudo-op support],
424 libffi_cv_as_string_pseudo_op, [
425 libffi_cv_as_string_pseudo_op=unknown
426 # Check if we have .string
427 AC_TRY_COMPILE(,[asm (".string \\"string\\"");],
428 [libffi_cv_as_string_pseudo_op=yes],
429 [libffi_cv_as_string_pseudo_op=no])
431 if test "x$libffi_cv_as_string_pseudo_op" = xyes; then
432 AC_DEFINE(HAVE_AS_STRING_PSEUDO_OP, 1,
433 [Define if your assembler supports .string.])
437 # On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC.
438 AC_ARG_ENABLE(pax_emutramp,
439 [ --enable-pax_emutramp enable pax emulated trampolines, for we can't use PROT_EXEC],
440 if test "$enable_pax_emutramp" = "yes"; then
441 AC_DEFINE(FFI_MMAP_EXEC_EMUTRAMP_PAX, 1,
442 [Define this if you want to enable pax emulated trampolines])
446 if test "x$sys_symbol_underscore" = xyes; then
447 AC_DEFINE(SYMBOL_UNDERSCORE, 1, [Define if symbols are underscored.])
450 FFI_EXEC_TRAMPOLINE_TABLE=0
453 FFI_EXEC_TRAMPOLINE_TABLE=1
454 AC_DEFINE(FFI_EXEC_TRAMPOLINE_TABLE, 1,
455 [Cannot use PROT_EXEC on this target, so, we revert to
458 *-apple-darwin1* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris*)
459 AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
460 [Cannot use malloc on this target, so, we revert to
464 AM_CONDITIONAL(FFI_EXEC_TRAMPOLINE_TABLE, test x$FFI_EXEC_TRAMPOLINE_TABLE = x1)
465 AC_SUBST(FFI_EXEC_TRAMPOLINE_TABLE)
467 if test x$TARGET = xX86_64; then
468 AC_CACHE_CHECK([toolchain supports unwind section type],
469 libffi_cv_as_x86_64_unwind_section_type, [
470 cat > conftest1.s << EOF
475 .section .eh_frame,"a",@unwind
479 cat > conftest2.c << EOF
484 libffi_cv_as_x86_64_unwind_section_type=no
485 # we ensure that we can compile _and_ link an assembly file containing an @unwind section
486 # since the compiler can support it and not the linker (ie old binutils)
487 if $CC -Wa,--fatal-warnings $CFLAGS -c conftest1.s > /dev/null 2>&1 && \
488 $CC conftest2.c conftest1.o > /dev/null 2>&1 ; then
489 libffi_cv_as_x86_64_unwind_section_type=yes
492 if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
493 AC_DEFINE(HAVE_AS_X86_64_UNWIND_SECTION_TYPE, 1,
494 [Define if your assembler supports unwind section type.])
498 if test "x$GCC" = "xyes"; then
499 AC_CACHE_CHECK([whether .eh_frame section should be read-only],
500 libffi_cv_ro_eh_frame, [
501 libffi_cv_ro_eh_frame=no
502 echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
503 if $CC $CFLAGS -c -fpic -fexceptions -o conftest.o conftest.c > /dev/null 2>&1; then
504 objdump -h conftest.o > conftest.dump 2>&1
505 libffi_eh_frame_line=`grep -n eh_frame conftest.dump | cut -d: -f 1`
506 libffi_test_line=`expr $libffi_eh_frame_line + 1`p
507 sed -n $libffi_test_line conftest.dump > conftest.line
508 if grep READONLY conftest.line > /dev/null; then
509 libffi_cv_ro_eh_frame=yes
514 if test "x$libffi_cv_ro_eh_frame" = xyes; then
515 AC_DEFINE(HAVE_RO_EH_FRAME, 1,
516 [Define if .eh_frame sections should be read-only.])
517 AC_DEFINE(EH_FRAME_FLAGS, "a",
518 [Define to the flags needed for the .section .eh_frame directive. ])
520 AC_DEFINE(EH_FRAME_FLAGS, "aw",
521 [Define to the flags needed for the .section .eh_frame directive. ])
524 AC_CACHE_CHECK([for __attribute__((visibility("hidden")))],
525 libffi_cv_hidden_visibility_attribute, [
526 echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1 ; }' > conftest.c
527 libffi_cv_hidden_visibility_attribute=no
528 if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
529 if grep '\.hidden.*foo' conftest.s >/dev/null; then
530 libffi_cv_hidden_visibility_attribute=yes
535 if test $libffi_cv_hidden_visibility_attribute = yes; then
536 AC_DEFINE(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE, 1,
537 [Define if __attribute__((visibility("hidden"))) is supported.])
542 #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
544 #define FFI_HIDDEN(name) .hidden name
546 #define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
550 #define FFI_HIDDEN(name)
563 [ --enable-debug debugging mode],
564 if test "$enable_debug" = "yes"; then
565 AC_DEFINE(FFI_DEBUG, 1, [Define this if you want extra debugging.])
567 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
569 AC_ARG_ENABLE(structs,
570 [ --disable-structs omit code for struct support],
571 if test "$enable_structs" = "no"; then
572 AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this if you do not want support for aggregate types.])
574 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
576 AC_ARG_ENABLE(raw-api,
577 [ --disable-raw-api make the raw api unavailable],
578 if test "$enable_raw_api" = "no"; then
579 AC_DEFINE(FFI_NO_RAW_API, 1, [Define this if you do not want support for the raw API.])
582 AC_ARG_ENABLE(purify-safety,
583 [ --enable-purify-safety purify-safe mode],
584 if test "$enable_purify_safety" = "yes"; then
585 AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
588 # These variables are only ever used when we cross-build to X86_WIN32.
589 # And we only support this with GCC, so...
590 if test "x$GCC" = "xyes"; then
591 if test -n "$with_cross_host" &&
592 test x"$with_cross_host" != x"no"; then
593 toolexecdir='$(exec_prefix)/$(target_alias)'
594 toolexeclibdir='$(toolexecdir)/lib'
596 toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
597 toolexeclibdir='$(libdir)'
599 multi_os_directory=`$CC $CFLAGS -print-multi-os-directory`
600 case $multi_os_directory in
601 .) ;; # Avoid trailing /.
602 ../*) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
604 AC_SUBST(toolexecdir)
606 toolexeclibdir='$(libdir)'
608 AC_SUBST(toolexeclibdir)
610 AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
611 AC_CONFIG_COMMANDS(src, [
612 test -d src || mkdir src
613 test -d src/$TARGETDIR || mkdir src/$TARGETDIR
614 ], [TARGETDIR="$TARGETDIR"])
616 AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h)
618 AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc)