1 dnl Process this with autoconf to create configure
5 AC_INIT([libffi], [3.2.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)
67 AC_CHECK_FUNCS([mmap mkostemp])
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
234 TARGET=OR1K; TARGETDIR=or1k
237 powerpc*-*-linux* | powerpc-*-sysv*)
238 TARGET=POWERPC; TARGETDIR=powerpc
239 HAVE_LONG_DOUBLE_VARIANT=1
242 TARGET=POWERPC; TARGETDIR=powerpc
245 TARGET=POWERPC; TARGETDIR=powerpc
247 powerpc-*-darwin* | powerpc64-*-darwin*)
248 TARGET=POWERPC_DARWIN; TARGETDIR=powerpc
250 powerpc-*-aix* | rs6000-*-aix*)
251 TARGET=POWERPC_AIX; TARGETDIR=powerpc
253 powerpc-*-freebsd* | powerpc-*-openbsd*)
254 TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc
255 HAVE_LONG_DOUBLE_VARIANT=1
257 powerpc64-*-freebsd*)
258 TARGET=POWERPC; TARGETDIR=powerpc
261 TARGET=POWERPC; TARGETDIR=powerpc
264 s390-*-* | s390x-*-*)
265 TARGET=S390; TARGETDIR=s390
268 sh-*-* | sh[[34]]*-*-*)
269 TARGET=SH; TARGETDIR=sh
272 TARGET=SH64; TARGETDIR=sh64
276 TARGET=SPARC; TARGETDIR=sparc
280 TARGET=TILE; TARGETDIR=tile
284 TARGET=VAX; TARGETDIR=vax
288 TARGET=XTENSA; TARGETDIR=xtensa
293 AC_SUBST(AM_RUNTESTFLAGS)
294 AC_SUBST(AM_LTLDFLAGS)
296 if test $TARGETDIR = unknown; then
297 AC_MSG_ERROR(["libffi has not been ported to $host."])
300 AM_CONDITIONAL(MIPS, test x$TARGET = xMIPS)
301 AM_CONDITIONAL(BFIN, test x$TARGET = xBFIN)
302 AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
303 AM_CONDITIONAL(X86, test x$TARGET = xX86)
304 AM_CONDITIONAL(X86_FREEBSD, test x$TARGET = xX86_FREEBSD)
305 AM_CONDITIONAL(X86_WIN32, test x$TARGET = xX86_WIN32)
306 AM_CONDITIONAL(X86_WIN64, test x$TARGET = xX86_WIN64)
307 AM_CONDITIONAL(X86_DARWIN, test x$TARGET = xX86_DARWIN)
308 AM_CONDITIONAL(X86_DARWIN32, test x$TARGET = xX86_DARWIN && test $ac_cv_sizeof_size_t = 4)
309 AM_CONDITIONAL(X86_DARWIN64, test x$TARGET = xX86_DARWIN && test $ac_cv_sizeof_size_t = 8)
310 AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA)
311 AM_CONDITIONAL(IA64, test x$TARGET = xIA64)
312 AM_CONDITIONAL(M32R, test x$TARGET = xM32R)
313 AM_CONDITIONAL(M68K, test x$TARGET = xM68K)
314 AM_CONDITIONAL(M88K, test x$TARGET = xM88K)
315 AM_CONDITIONAL(MICROBLAZE, test x$TARGET = xMICROBLAZE)
316 AM_CONDITIONAL(METAG, test x$TARGET = xMETAG)
317 AM_CONDITIONAL(MOXIE, test x$TARGET = xMOXIE)
318 AM_CONDITIONAL(NIOS2, test x$TARGET = xNIOS2)
319 AM_CONDITIONAL(OR1K, test x$TARGET = xOR1K)
320 AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC)
321 AM_CONDITIONAL(POWERPC_AIX, test x$TARGET = xPOWERPC_AIX)
322 AM_CONDITIONAL(POWERPC_DARWIN, test x$TARGET = xPOWERPC_DARWIN)
323 AM_CONDITIONAL(POWERPC_FREEBSD, test x$TARGET = xPOWERPC_FREEBSD)
324 AM_CONDITIONAL(AARCH64, test x$TARGET = xAARCH64)
325 AM_CONDITIONAL(ARC, test x$TARGET = xARC)
326 AM_CONDITIONAL(ARM, test x$TARGET = xARM)
327 AM_CONDITIONAL(AVR32, test x$TARGET = xAVR32)
328 AM_CONDITIONAL(LIBFFI_CRIS, test x$TARGET = xLIBFFI_CRIS)
329 AM_CONDITIONAL(FRV, test x$TARGET = xFRV)
330 AM_CONDITIONAL(S390, test x$TARGET = xS390)
331 AM_CONDITIONAL(X86_64, test x$TARGET = xX86_64)
332 AM_CONDITIONAL(SH, test x$TARGET = xSH)
333 AM_CONDITIONAL(SH64, test x$TARGET = xSH64)
334 AM_CONDITIONAL(PA_LINUX, test x$TARGET = xPA_LINUX)
335 AM_CONDITIONAL(PA_HPUX, test x$TARGET = xPA_HPUX)
336 AM_CONDITIONAL(PA64_HPUX, test x$TARGET = xPA64_HPUX)
337 AM_CONDITIONAL(TILE, test x$TARGET = xTILE)
338 AM_CONDITIONAL(VAX, test x$TARGET = xVAX)
339 AM_CONDITIONAL(XTENSA, test x$TARGET = xXTENSA)
342 AC_CHECK_FUNCS(memcpy)
345 AC_CHECK_SIZEOF(double)
346 AC_CHECK_SIZEOF(long double)
348 # Also AC_SUBST this variable for ffi.h.
349 if test -z "$HAVE_LONG_DOUBLE"; then
351 if test $ac_cv_sizeof_long_double != 0; then
352 if test $HAVE_LONG_DOUBLE_VARIANT != 0; then
353 AC_DEFINE(HAVE_LONG_DOUBLE_VARIANT, 1, [Define if you support more than one size of the long double type])
356 if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
358 AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
363 AC_SUBST(HAVE_LONG_DOUBLE)
364 AC_SUBST(HAVE_LONG_DOUBLE_VARIANT)
370 if test x$TARGET = xSPARC; then
371 AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
372 libffi_cv_as_sparc_ua_pcrel, [
373 save_CFLAGS="$CFLAGS"
374 save_LDFLAGS="$LDFLAGS"
375 CFLAGS="$CFLAGS -fpic"
376 LDFLAGS="$LDFLAGS -shared"
377 AC_TRY_LINK([asm (".text; foo: nop; .data; .align 4; .byte 0; .uaword %r_disp32(foo); .text");],,
378 [libffi_cv_as_sparc_ua_pcrel=yes],
379 [libffi_cv_as_sparc_ua_pcrel=no])
380 CFLAGS="$save_CFLAGS"
381 LDFLAGS="$save_LDFLAGS"])
382 if test "x$libffi_cv_as_sparc_ua_pcrel" = xyes; then
383 AC_DEFINE(HAVE_AS_SPARC_UA_PCREL, 1,
384 [Define if your assembler and linker support unaligned PC relative relocs.])
387 AC_CACHE_CHECK([assembler .register pseudo-op support],
388 libffi_cv_as_register_pseudo_op, [
389 libffi_cv_as_register_pseudo_op=unknown
390 # Check if we have .register
391 AC_TRY_COMPILE(,[asm (".register %g2, #scratch");],
392 [libffi_cv_as_register_pseudo_op=yes],
393 [libffi_cv_as_register_pseudo_op=no])
395 if test "x$libffi_cv_as_register_pseudo_op" = xyes; then
396 AC_DEFINE(HAVE_AS_REGISTER_PSEUDO_OP, 1,
397 [Define if your assembler supports .register.])
401 if test x$TARGET = xX86 || test x$TARGET = xX86_WIN32 || test x$TARGET = xX86_64; then
402 AC_CACHE_CHECK([assembler supports pc related relocs],
403 libffi_cv_as_x86_pcrel, [
404 libffi_cv_as_x86_pcrel=no
405 echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s
406 if $CC $CFLAGS -c conftest.s > /dev/null 2>&1; then
407 libffi_cv_as_x86_pcrel=yes
410 if test "x$libffi_cv_as_x86_pcrel" = xyes; then
411 AC_DEFINE(HAVE_AS_X86_PCREL, 1,
412 [Define if your assembler supports PC relative relocs.])
415 AC_CACHE_CHECK([assembler .ascii pseudo-op support],
416 libffi_cv_as_ascii_pseudo_op, [
417 libffi_cv_as_ascii_pseudo_op=unknown
418 # Check if we have .ascii
419 AC_TRY_COMPILE(,[asm (".ascii \\"string\\"");],
420 [libffi_cv_as_ascii_pseudo_op=yes],
421 [libffi_cv_as_ascii_pseudo_op=no])
423 if test "x$libffi_cv_as_ascii_pseudo_op" = xyes; then
424 AC_DEFINE(HAVE_AS_ASCII_PSEUDO_OP, 1,
425 [Define if your assembler supports .ascii.])
428 AC_CACHE_CHECK([assembler .string pseudo-op support],
429 libffi_cv_as_string_pseudo_op, [
430 libffi_cv_as_string_pseudo_op=unknown
431 # Check if we have .string
432 AC_TRY_COMPILE(,[asm (".string \\"string\\"");],
433 [libffi_cv_as_string_pseudo_op=yes],
434 [libffi_cv_as_string_pseudo_op=no])
436 if test "x$libffi_cv_as_string_pseudo_op" = xyes; then
437 AC_DEFINE(HAVE_AS_STRING_PSEUDO_OP, 1,
438 [Define if your assembler supports .string.])
442 # On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC.
443 AC_ARG_ENABLE(pax_emutramp,
444 [ --enable-pax_emutramp enable pax emulated trampolines, for we can't use PROT_EXEC],
445 if test "$enable_pax_emutramp" = "yes"; then
446 AC_DEFINE(FFI_MMAP_EXEC_EMUTRAMP_PAX, 1,
447 [Define this if you want to enable pax emulated trampolines])
451 if test "x$sys_symbol_underscore" = xyes; then
452 AC_DEFINE(SYMBOL_UNDERSCORE, 1, [Define if symbols are underscored.])
455 FFI_EXEC_TRAMPOLINE_TABLE=0
458 FFI_EXEC_TRAMPOLINE_TABLE=1
459 AC_DEFINE(FFI_EXEC_TRAMPOLINE_TABLE, 1,
460 [Cannot use PROT_EXEC on this target, so, we revert to
463 *-apple-darwin1* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris*)
464 AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
465 [Cannot use malloc on this target, so, we revert to
469 AM_CONDITIONAL(FFI_EXEC_TRAMPOLINE_TABLE, test x$FFI_EXEC_TRAMPOLINE_TABLE = x1)
470 AC_SUBST(FFI_EXEC_TRAMPOLINE_TABLE)
472 if test x$TARGET = xX86_64; then
473 AC_CACHE_CHECK([toolchain supports unwind section type],
474 libffi_cv_as_x86_64_unwind_section_type, [
475 cat > conftest1.s << EOF
480 .section .eh_frame,"a",@unwind
484 cat > conftest2.c << EOF
489 libffi_cv_as_x86_64_unwind_section_type=no
490 # we ensure that we can compile _and_ link an assembly file containing an @unwind section
491 # since the compiler can support it and not the linker (ie old binutils)
492 if $CC -Wa,--fatal-warnings $CFLAGS -c conftest1.s > /dev/null 2>&1 && \
493 $CC conftest2.c conftest1.o > /dev/null 2>&1 ; then
494 libffi_cv_as_x86_64_unwind_section_type=yes
497 if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
498 AC_DEFINE(HAVE_AS_X86_64_UNWIND_SECTION_TYPE, 1,
499 [Define if your assembler supports unwind section type.])
503 if test "x$GCC" = "xyes"; then
504 AC_CACHE_CHECK([whether .eh_frame section should be read-only],
505 libffi_cv_ro_eh_frame, [
506 libffi_cv_ro_eh_frame=no
507 echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
508 if $CC $CFLAGS -c -fpic -fexceptions -o conftest.o conftest.c > /dev/null 2>&1; then
509 objdump -h conftest.o > conftest.dump 2>&1
510 libffi_eh_frame_line=`grep -n eh_frame conftest.dump | cut -d: -f 1`
511 libffi_test_line=`expr $libffi_eh_frame_line + 1`p
512 sed -n $libffi_test_line conftest.dump > conftest.line
513 if grep READONLY conftest.line > /dev/null; then
514 libffi_cv_ro_eh_frame=yes
519 if test "x$libffi_cv_ro_eh_frame" = xyes; then
520 AC_DEFINE(HAVE_RO_EH_FRAME, 1,
521 [Define if .eh_frame sections should be read-only.])
522 AC_DEFINE(EH_FRAME_FLAGS, "a",
523 [Define to the flags needed for the .section .eh_frame directive. ])
525 AC_DEFINE(EH_FRAME_FLAGS, "aw",
526 [Define to the flags needed for the .section .eh_frame directive. ])
529 AC_CACHE_CHECK([for __attribute__((visibility("hidden")))],
530 libffi_cv_hidden_visibility_attribute, [
531 echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1 ; }' > conftest.c
532 libffi_cv_hidden_visibility_attribute=no
533 if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
534 if grep '\.hidden.*foo' conftest.s >/dev/null; then
535 libffi_cv_hidden_visibility_attribute=yes
540 if test $libffi_cv_hidden_visibility_attribute = yes; then
541 AC_DEFINE(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE, 1,
542 [Define if __attribute__((visibility("hidden"))) is supported.])
547 #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
549 #define FFI_HIDDEN(name) .hidden name
551 #define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
555 #define FFI_HIDDEN(name)
568 [ --enable-debug debugging mode],
569 if test "$enable_debug" = "yes"; then
570 AC_DEFINE(FFI_DEBUG, 1, [Define this if you want extra debugging.])
572 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
574 AC_ARG_ENABLE(structs,
575 [ --disable-structs omit code for struct support],
576 if test "$enable_structs" = "no"; then
577 AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this if you do not want support for aggregate types.])
579 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
581 AC_ARG_ENABLE(raw-api,
582 [ --disable-raw-api make the raw api unavailable],
583 if test "$enable_raw_api" = "no"; then
584 AC_DEFINE(FFI_NO_RAW_API, 1, [Define this if you do not want support for the raw API.])
587 AC_ARG_ENABLE(purify-safety,
588 [ --enable-purify-safety purify-safe mode],
589 if test "$enable_purify_safety" = "yes"; then
590 AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
593 # These variables are only ever used when we cross-build to X86_WIN32.
594 # And we only support this with GCC, so...
595 if test "x$GCC" = "xyes"; then
596 if test -n "$with_cross_host" &&
597 test x"$with_cross_host" != x"no"; then
598 toolexecdir="${exec_prefix}"/'$(target_alias)'
599 toolexeclibdir="${toolexecdir}"/lib
601 toolexecdir="${libdir}"/gcc-lib/'$(target_alias)'
602 toolexeclibdir="${libdir}"
604 multi_os_directory=`$CC $CFLAGS -print-multi-os-directory`
605 case $multi_os_directory in
606 .) ;; # Avoid trailing /.
607 ../*) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
609 AC_SUBST(toolexecdir)
611 toolexeclibdir="${libdir}"
613 AC_SUBST(toolexeclibdir)
615 AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
616 AC_CONFIG_COMMANDS(src, [
617 test -d src || mkdir src
618 test -d src/$TARGETDIR || mkdir src/$TARGETDIR
619 ], [TARGETDIR="$TARGETDIR"])
621 AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h)
623 AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc)