1 dnl Process this with autoconf to create configure
5 AC_INIT([libffi], [3.1-rc1], [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],[])
33 m4_undefine([_AC_ARG_VAR_PRECIOUS])
34 m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
41 AC_CONFIG_MACRO_DIR([m4])
43 # Test for 64-bit build.
44 AC_CHECK_SIZEOF([size_t])
48 # The AX_CFLAGS_WARN_ALL macro doesn't currently work for sunpro
50 if test "$ax_cv_c_compiler_vendor" != "sun"; then
54 if test "x$GCC" = "xyes"; then
55 CFLAGS="$CFLAGS -fexceptions"
59 set CC_FOR_TARGET "$CC"
65 AC_CHECK_HEADERS(sys/mman.h)
67 AC_FUNC_MMAP_BLACKLIST
69 dnl The -no-testsuite modules omit the test subdir.
70 AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
73 HAVE_LONG_DOUBLE_VARIANT=0
76 TARGET=AARCH64; TARGETDIR=aarch64
80 TARGET=ALPHA; TARGETDIR=alpha;
81 # Support 128-bit long double, changeable via command-line switch.
82 HAVE_LONG_DOUBLE='defined(__LONG_DOUBLE_128__)'
86 TARGET=ARC; TARGETDIR=arc
90 TARGET=ARM; TARGETDIR=arm
93 amd64-*-freebsd* | amd64-*-openbsd*)
94 TARGET=X86_64; TARGETDIR=x86
98 TARGET=X86_64; TARGETDIR=x86
102 TARGET=X86_64; TARGETDIR=x86
106 TARGET=AVR32; TARGETDIR=avr32
110 TARGET=BFIN; TARGETDIR=bfin
114 TARGET=LIBFFI_CRIS; TARGETDIR=cris
118 TARGET=FRV; TARGETDIR=frv
121 hppa*-*-linux* | parisc*-*-linux* | hppa*-*-openbsd*)
122 TARGET=PA_LINUX; TARGETDIR=pa
125 TARGET=PA64_HPUX; TARGETDIR=pa
128 TARGET=PA_HPUX; TARGETDIR=pa
131 i?86-*-freebsd* | i?86-*-openbsd*)
132 TARGET=X86_FREEBSD; TARGETDIR=x86
134 i?86-win32* | i?86-*-cygwin* | i?86-*-mingw* | i?86-*-os2* | i?86-*-interix*)
135 TARGET=X86_WIN32; TARGETDIR=x86
136 # All mingw/cygwin/win32 builds require -no-undefined for sharedlib.
137 # We must also check with_cross_host to decide if this is a native
138 # or cross-build and select where to install dlls appropriately.
139 if test -n "$with_cross_host" &&
140 test x"$with_cross_host" != x"no"; then
141 AM_LTLDFLAGS='-no-undefined -bindir "$(toolexeclibdir)"';
143 AM_LTLDFLAGS='-no-undefined -bindir "$(bindir)"';
147 TARGET=X86_DARWIN; TARGETDIR=x86
149 i?86-*-solaris2.1[[0-9]]*)
151 if test $ac_cv_sizeof_size_t = 4; then
159 TARGET=X86_DARWIN; TARGETDIR=x86
162 x86_64-*-cygwin* | x86_64-*-mingw*)
163 TARGET=X86_WIN64; TARGETDIR=x86
164 # All mingw/cygwin/win32 builds require -no-undefined for sharedlib.
165 # We must also check with_cross_host to decide if this is a native
166 # or cross-build and select where to install dlls appropriately.
167 if test -n "$with_cross_host" &&
168 test x"$with_cross_host" != x"no"; then
169 AM_LTLDFLAGS='-no-undefined -bindir "$(toolexeclibdir)"';
171 AM_LTLDFLAGS='-no-undefined -bindir "$(bindir)"';
175 i?86-*-* | x86_64-*-*)
177 if test $ac_cv_sizeof_size_t = 4; then
192 TARGET=IA64; TARGETDIR=ia64
196 TARGET=M32R; TARGETDIR=m32r
200 TARGET=M68K; TARGETDIR=m68k
204 TARGET=M88K; TARGETDIR=m88k
208 TARGET=MICROBLAZE; TARGETDIR=microblaze
212 TARGET=MOXIE; TARGETDIR=moxie
216 TARGET=METAG; TARGETDIR=metag
219 mips-sgi-irix5.* | mips-sgi-irix6.* | mips*-*-rtems*)
220 TARGET=MIPS; TARGETDIR=mips
222 mips*-*linux* | mips*-*-openbsd*)
223 # Support 128-bit long double for NewABI.
224 HAVE_LONG_DOUBLE='defined(__mips64)'
225 TARGET=MIPS; TARGETDIR=mips
229 TARGET=NIOS2; TARGETDIR=nios2
232 powerpc*-*-linux* | powerpc-*-sysv*)
233 TARGET=POWERPC; TARGETDIR=powerpc
234 HAVE_LONG_DOUBLE_VARIANT=1
237 TARGET=POWERPC; TARGETDIR=powerpc
240 TARGET=POWERPC; TARGETDIR=powerpc
242 powerpc-*-darwin* | powerpc64-*-darwin*)
243 TARGET=POWERPC_DARWIN; TARGETDIR=powerpc
245 powerpc-*-aix* | rs6000-*-aix*)
246 TARGET=POWERPC_AIX; TARGETDIR=powerpc
248 powerpc-*-freebsd* | powerpc-*-openbsd*)
249 TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc
250 HAVE_LONG_DOUBLE_VARIANT=1
252 powerpc64-*-freebsd*)
253 TARGET=POWERPC; TARGETDIR=powerpc
256 TARGET=POWERPC; TARGETDIR=powerpc
259 s390-*-* | s390x-*-*)
260 TARGET=S390; TARGETDIR=s390
263 sh-*-* | sh[[34]]*-*-*)
264 TARGET=SH; TARGETDIR=sh
267 TARGET=SH64; TARGETDIR=sh64
271 TARGET=SPARC; TARGETDIR=sparc
275 TARGET=TILE; TARGETDIR=tile
279 TARGET=VAX; TARGETDIR=vax
283 TARGET=XTENSA; TARGETDIR=xtensa
288 AC_SUBST(AM_RUNTESTFLAGS)
289 AC_SUBST(AM_LTLDFLAGS)
291 if test $TARGETDIR = unknown; then
292 AC_MSG_ERROR(["libffi has not been ported to $host."])
295 AM_CONDITIONAL(MIPS, test x$TARGET = xMIPS)
296 AM_CONDITIONAL(BFIN, test x$TARGET = xBFIN)
297 AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
298 AM_CONDITIONAL(X86, test x$TARGET = xX86)
299 AM_CONDITIONAL(X86_FREEBSD, test x$TARGET = xX86_FREEBSD)
300 AM_CONDITIONAL(X86_WIN32, test x$TARGET = xX86_WIN32)
301 AM_CONDITIONAL(X86_WIN64, test x$TARGET = xX86_WIN64)
302 AM_CONDITIONAL(X86_DARWIN, test x$TARGET = xX86_DARWIN)
303 AM_CONDITIONAL(X86_DARWIN32, test x$TARGET = xX86_DARWIN && test $ac_cv_sizeof_size_t = 4)
304 AM_CONDITIONAL(X86_DARWIN64, test x$TARGET = xX86_DARWIN && test $ac_cv_sizeof_size_t = 8)
305 AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA)
306 AM_CONDITIONAL(IA64, test x$TARGET = xIA64)
307 AM_CONDITIONAL(M32R, test x$TARGET = xM32R)
308 AM_CONDITIONAL(M68K, test x$TARGET = xM68K)
309 AM_CONDITIONAL(M88K, test x$TARGET = xM88K)
310 AM_CONDITIONAL(MICROBLAZE, test x$TARGET = xMICROBLAZE)
311 AM_CONDITIONAL(METAG, test x$TARGET = xMETAG)
312 AM_CONDITIONAL(MOXIE, test x$TARGET = xMOXIE)
313 AM_CONDITIONAL(NIOS2, test x$TARGET = xNIOS2)
314 AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC)
315 AM_CONDITIONAL(POWERPC_AIX, test x$TARGET = xPOWERPC_AIX)
316 AM_CONDITIONAL(POWERPC_DARWIN, test x$TARGET = xPOWERPC_DARWIN)
317 AM_CONDITIONAL(POWERPC_FREEBSD, test x$TARGET = xPOWERPC_FREEBSD)
318 AM_CONDITIONAL(AARCH64, test x$TARGET = xAARCH64)
319 AM_CONDITIONAL(ARC, test x$TARGET = xARC)
320 AM_CONDITIONAL(ARM, test x$TARGET = xARM)
321 AM_CONDITIONAL(AVR32, test x$TARGET = xAVR32)
322 AM_CONDITIONAL(LIBFFI_CRIS, test x$TARGET = xLIBFFI_CRIS)
323 AM_CONDITIONAL(FRV, test x$TARGET = xFRV)
324 AM_CONDITIONAL(S390, test x$TARGET = xS390)
325 AM_CONDITIONAL(X86_64, test x$TARGET = xX86_64)
326 AM_CONDITIONAL(SH, test x$TARGET = xSH)
327 AM_CONDITIONAL(SH64, test x$TARGET = xSH64)
328 AM_CONDITIONAL(PA_LINUX, test x$TARGET = xPA_LINUX)
329 AM_CONDITIONAL(PA_HPUX, test x$TARGET = xPA_HPUX)
330 AM_CONDITIONAL(PA64_HPUX, test x$TARGET = xPA64_HPUX)
331 AM_CONDITIONAL(TILE, test x$TARGET = xTILE)
332 AM_CONDITIONAL(VAX, test x$TARGET = xVAX)
333 AM_CONDITIONAL(XTENSA, test x$TARGET = xXTENSA)
336 AC_CHECK_FUNCS(memcpy)
339 AC_CHECK_SIZEOF(double)
340 AC_CHECK_SIZEOF(long double)
342 # Also AC_SUBST this variable for ffi.h.
343 if test -z "$HAVE_LONG_DOUBLE"; then
345 if test $ac_cv_sizeof_long_double != 0; then
346 if test $HAVE_LONG_DOUBLE_VARIANT != 0; then
347 AC_DEFINE(HAVE_LONG_DOUBLE_VARIANT, 1, [Define if you support more than one size of the long double type])
350 if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
352 AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
357 AC_SUBST(HAVE_LONG_DOUBLE)
358 AC_SUBST(HAVE_LONG_DOUBLE_VARIANT)
364 if test x$TARGET = xSPARC; then
365 AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
366 libffi_cv_as_sparc_ua_pcrel, [
367 save_CFLAGS="$CFLAGS"
368 save_LDFLAGS="$LDFLAGS"
369 CFLAGS="$CFLAGS -fpic"
370 LDFLAGS="$LDFLAGS -shared"
371 AC_TRY_LINK([asm (".text; foo: nop; .data; .align 4; .byte 0; .uaword %r_disp32(foo); .text");],,
372 [libffi_cv_as_sparc_ua_pcrel=yes],
373 [libffi_cv_as_sparc_ua_pcrel=no])
374 CFLAGS="$save_CFLAGS"
375 LDFLAGS="$save_LDFLAGS"])
376 if test "x$libffi_cv_as_sparc_ua_pcrel" = xyes; then
377 AC_DEFINE(HAVE_AS_SPARC_UA_PCREL, 1,
378 [Define if your assembler and linker support unaligned PC relative relocs.])
381 AC_CACHE_CHECK([assembler .register pseudo-op support],
382 libffi_cv_as_register_pseudo_op, [
383 libffi_cv_as_register_pseudo_op=unknown
384 # Check if we have .register
385 AC_TRY_COMPILE(,[asm (".register %g2, #scratch");],
386 [libffi_cv_as_register_pseudo_op=yes],
387 [libffi_cv_as_register_pseudo_op=no])
389 if test "x$libffi_cv_as_register_pseudo_op" = xyes; then
390 AC_DEFINE(HAVE_AS_REGISTER_PSEUDO_OP, 1,
391 [Define if your assembler supports .register.])
395 if test x$TARGET = xX86 || test x$TARGET = xX86_WIN32 || test x$TARGET = xX86_64; then
396 AC_CACHE_CHECK([assembler supports pc related relocs],
397 libffi_cv_as_x86_pcrel, [
398 libffi_cv_as_x86_pcrel=no
399 echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s
400 if $CC $CFLAGS -c conftest.s > /dev/null 2>&1; then
401 libffi_cv_as_x86_pcrel=yes
404 if test "x$libffi_cv_as_x86_pcrel" = xyes; then
405 AC_DEFINE(HAVE_AS_X86_PCREL, 1,
406 [Define if your assembler supports PC relative relocs.])
409 AC_CACHE_CHECK([assembler .ascii pseudo-op support],
410 libffi_cv_as_ascii_pseudo_op, [
411 libffi_cv_as_ascii_pseudo_op=unknown
412 # Check if we have .ascii
413 AC_TRY_COMPILE(,[asm (".ascii \\"string\\"");],
414 [libffi_cv_as_ascii_pseudo_op=yes],
415 [libffi_cv_as_ascii_pseudo_op=no])
417 if test "x$libffi_cv_as_ascii_pseudo_op" = xyes; then
418 AC_DEFINE(HAVE_AS_ASCII_PSEUDO_OP, 1,
419 [Define if your assembler supports .ascii.])
422 AC_CACHE_CHECK([assembler .string pseudo-op support],
423 libffi_cv_as_string_pseudo_op, [
424 libffi_cv_as_string_pseudo_op=unknown
425 # Check if we have .string
426 AC_TRY_COMPILE(,[asm (".string \\"string\\"");],
427 [libffi_cv_as_string_pseudo_op=yes],
428 [libffi_cv_as_string_pseudo_op=no])
430 if test "x$libffi_cv_as_string_pseudo_op" = xyes; then
431 AC_DEFINE(HAVE_AS_STRING_PSEUDO_OP, 1,
432 [Define if your assembler supports .string.])
436 # On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC.
437 AC_ARG_ENABLE(pax_emutramp,
438 [ --enable-pax_emutramp enable pax emulated trampolines, for we can't use PROT_EXEC],
439 if test "$enable_pax_emutramp" = "yes"; then
440 AC_DEFINE(FFI_MMAP_EXEC_EMUTRAMP_PAX, 1,
441 [Define this if you want to enable pax emulated trampolines])
445 if test "x$sys_symbol_underscore" = xyes; then
446 AC_DEFINE(SYMBOL_UNDERSCORE, 1, [Define if symbols are underscored.])
449 FFI_EXEC_TRAMPOLINE_TABLE=0
452 FFI_EXEC_TRAMPOLINE_TABLE=1
453 AC_DEFINE(FFI_EXEC_TRAMPOLINE_TABLE, 1,
454 [Cannot use PROT_EXEC on this target, so, we revert to
457 *-apple-darwin1* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris*)
458 AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
459 [Cannot use malloc on this target, so, we revert to
463 AM_CONDITIONAL(FFI_EXEC_TRAMPOLINE_TABLE, test x$FFI_EXEC_TRAMPOLINE_TABLE = x1)
464 AC_SUBST(FFI_EXEC_TRAMPOLINE_TABLE)
466 if test x$TARGET = xX86_64; then
467 AC_CACHE_CHECK([toolchain supports unwind section type],
468 libffi_cv_as_x86_64_unwind_section_type, [
469 cat > conftest1.s << EOF
474 .section .eh_frame,"a",@unwind
478 cat > conftest2.c << EOF
483 libffi_cv_as_x86_64_unwind_section_type=no
484 # we ensure that we can compile _and_ link an assembly file containing an @unwind section
485 # since the compiler can support it and not the linker (ie old binutils)
486 if $CC -Wa,--fatal-warnings $CFLAGS -c conftest1.s > /dev/null 2>&1 && \
487 $CC conftest2.c conftest1.o > /dev/null 2>&1 ; then
488 libffi_cv_as_x86_64_unwind_section_type=yes
491 if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
492 AC_DEFINE(HAVE_AS_X86_64_UNWIND_SECTION_TYPE, 1,
493 [Define if your assembler supports unwind section type.])
497 if test "x$GCC" = "xyes"; then
498 AC_CACHE_CHECK([whether .eh_frame section should be read-only],
499 libffi_cv_ro_eh_frame, [
500 libffi_cv_ro_eh_frame=no
501 echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
502 if $CC $CFLAGS -c -fpic -fexceptions -o conftest.o conftest.c > /dev/null 2>&1; then
503 objdump -h conftest.o > conftest.dump 2>&1
504 libffi_eh_frame_line=`grep -n eh_frame conftest.dump | cut -d: -f 1`
505 libffi_test_line=`expr $libffi_eh_frame_line + 1`p
506 sed -n $libffi_test_line conftest.dump > conftest.line
507 if grep READONLY conftest.line > /dev/null; then
508 libffi_cv_ro_eh_frame=yes
513 if test "x$libffi_cv_ro_eh_frame" = xyes; then
514 AC_DEFINE(HAVE_RO_EH_FRAME, 1,
515 [Define if .eh_frame sections should be read-only.])
516 AC_DEFINE(EH_FRAME_FLAGS, "a",
517 [Define to the flags needed for the .section .eh_frame directive. ])
519 AC_DEFINE(EH_FRAME_FLAGS, "aw",
520 [Define to the flags needed for the .section .eh_frame directive. ])
523 AC_CACHE_CHECK([for __attribute__((visibility("hidden")))],
524 libffi_cv_hidden_visibility_attribute, [
525 echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1 ; }' > conftest.c
526 libffi_cv_hidden_visibility_attribute=no
527 if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
528 if grep '\.hidden.*foo' conftest.s >/dev/null; then
529 libffi_cv_hidden_visibility_attribute=yes
534 if test $libffi_cv_hidden_visibility_attribute = yes; then
535 AC_DEFINE(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE, 1,
536 [Define if __attribute__((visibility("hidden"))) is supported.])
541 #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
543 #define FFI_HIDDEN(name) .hidden name
545 #define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
549 #define FFI_HIDDEN(name)
562 [ --enable-debug debugging mode],
563 if test "$enable_debug" = "yes"; then
564 AC_DEFINE(FFI_DEBUG, 1, [Define this if you want extra debugging.])
566 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
568 AC_ARG_ENABLE(structs,
569 [ --disable-structs omit code for struct support],
570 if test "$enable_structs" = "no"; then
571 AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this if you do not want support for aggregate types.])
573 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
575 AC_ARG_ENABLE(raw-api,
576 [ --disable-raw-api make the raw api unavailable],
577 if test "$enable_raw_api" = "no"; then
578 AC_DEFINE(FFI_NO_RAW_API, 1, [Define this if you do not want support for the raw API.])
581 AC_ARG_ENABLE(purify-safety,
582 [ --enable-purify-safety purify-safe mode],
583 if test "$enable_purify_safety" = "yes"; then
584 AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
587 # These variables are only ever used when we cross-build to X86_WIN32.
588 # And we only support this with GCC, so...
589 if test "x$GCC" = "xyes"; then
590 if test -n "$with_cross_host" &&
591 test x"$with_cross_host" != x"no"; then
592 toolexecdir='$(exec_prefix)/$(target_alias)'
593 toolexeclibdir='$(toolexecdir)/lib'
595 toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
596 toolexeclibdir='$(libdir)'
598 multi_os_directory=`$CC -print-multi-os-directory`
599 case $multi_os_directory in
600 .) ;; # Avoid trailing /.
601 ../*) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
603 AC_SUBST(toolexecdir)
605 toolexeclibdir='$(libdir)'
607 AC_SUBST(toolexeclibdir)
609 AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
610 AC_CONFIG_COMMANDS(src, [
611 test -d src || mkdir src
612 test -d src/$TARGETDIR || mkdir src/$TARGETDIR
613 ], [TARGETDIR="$TARGETDIR"])
615 AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h)
617 AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc)