1 dnl Process this with autoconf to create configure
5 AC_INIT([libffi], [3.0.12], [http://github.com/atgreen/libffi/issues])
6 AC_CONFIG_HEADERS([fficonfig.h])
9 target_alias=${target_alias-$host_alias}
11 . ${srcdir}/configure.host
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.
24 m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
25 m4_define([_AC_ARG_VAR_PRECIOUS],[])
29 m4_undefine([_AC_ARG_VAR_PRECIOUS])
30 m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
37 AC_CONFIG_MACRO_DIR([m4])
39 # Test for 64-bit build.
40 AC_CHECK_SIZEOF([size_t])
44 # The AX_CFLAGS_WARN_ALL macro doesn't currently work for sunpro
46 if test "$ax_cv_c_compiler_vendor" != "sun"; then
50 if test "x$GCC" = "xyes"; then
51 CFLAGS="$CFLAGS -fexceptions"
55 set CC_FOR_TARGET "$CC"
61 AC_CHECK_HEADERS(sys/mman.h)
63 AC_FUNC_MMAP_BLACKLIST
65 dnl The -no-testsuite modules omit the test subdir.
66 AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
71 TARGET=AARCH64; TARGETDIR=aarch64
75 TARGET=ALPHA; TARGETDIR=alpha;
76 # Support 128-bit long double, changeable via command-line switch.
77 HAVE_LONG_DOUBLE='defined(__LONG_DOUBLE_128__)'
81 TARGET=ARM; TARGETDIR=arm
84 amd64-*-freebsd* | amd64-*-openbsd*)
85 TARGET=X86_64; TARGETDIR=x86
89 TARGET=X86_64; TARGETDIR=x86
93 TARGET=X86_64; TARGETDIR=x86
97 TARGET=AVR32; TARGETDIR=avr32
101 TARGET=BFIN; TARGETDIR=bfin
105 TARGET=LIBFFI_CRIS; TARGETDIR=cris
109 TARGET=FRV; TARGETDIR=frv
112 hppa*-*-linux* | parisc*-*-linux* | hppa*-*-openbsd*)
113 TARGET=PA_LINUX; TARGETDIR=pa
116 TARGET=PA64_HPUX; TARGETDIR=pa
119 TARGET=PA_HPUX; TARGETDIR=pa
122 i?86-*-freebsd* | i?86-*-openbsd*)
123 TARGET=X86_FREEBSD; TARGETDIR=x86
125 i?86-win32* | i?86-*-cygwin* | i?86-*-mingw* | i?86-*-os2* | i?86-*-interix*)
126 TARGET=X86_WIN32; TARGETDIR=x86
127 # All mingw/cygwin/win32 builds require -no-undefined for sharedlib.
128 # We must also check with_cross_host to decide if this is a native
129 # or cross-build and select where to install dlls appropriately.
130 if test -n "$with_cross_host" &&
131 test x"$with_cross_host" != x"no"; then
132 AM_LTLDFLAGS='-no-undefined -bindir "$(toolexeclibdir)"';
134 AM_LTLDFLAGS='-no-undefined -bindir "$(bindir)"';
138 TARGET=X86_DARWIN; TARGETDIR=x86
140 i?86-*-solaris2.1[[0-9]]*)
142 if test $ac_cv_sizeof_size_t = 4; then
150 TARGET=X86_DARWIN; TARGETDIR=x86
153 x86_64-*-cygwin* | x86_64-*-mingw*)
154 TARGET=X86_WIN64; TARGETDIR=x86
155 # All mingw/cygwin/win32 builds require -no-undefined for sharedlib.
156 # We must also check with_cross_host to decide if this is a native
157 # or cross-build and select where to install dlls appropriately.
158 if test -n "$with_cross_host" &&
159 test x"$with_cross_host" != x"no"; then
160 AM_LTLDFLAGS='-no-undefined -bindir "$(toolexeclibdir)"';
162 AM_LTLDFLAGS='-no-undefined -bindir "$(bindir)"';
166 i?86-*-* | x86_64-*-*)
168 if test $ac_cv_sizeof_size_t = 4; then
183 TARGET=IA64; TARGETDIR=ia64
187 TARGET=M32R; TARGETDIR=m32r
191 TARGET=M68K; TARGETDIR=m68k
195 TARGET=MICROBLAZE; TARGETDIR=microblaze
199 TARGET=MOXIE; TARGETDIR=moxie
202 mips-sgi-irix5.* | mips-sgi-irix6.* | mips*-*-rtems*)
203 TARGET=MIPS; TARGETDIR=mips
205 mips*-*-linux* | mips*-*-openbsd*)
206 # Support 128-bit long double for NewABI.
207 HAVE_LONG_DOUBLE='defined(__mips64)'
208 TARGET=MIPS; TARGETDIR=mips
211 powerpc*-*-linux* | powerpc-*-sysv*)
212 TARGET=POWERPC; TARGETDIR=powerpc
215 TARGET=POWERPC; TARGETDIR=powerpc
218 TARGET=POWERPC; TARGETDIR=powerpc
220 powerpc-*-darwin* | powerpc64-*-darwin*)
221 TARGET=POWERPC_DARWIN; TARGETDIR=powerpc
223 powerpc-*-aix* | rs6000-*-aix*)
224 TARGET=POWERPC_AIX; TARGETDIR=powerpc
226 powerpc-*-freebsd* | powerpc-*-openbsd*)
227 TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc
229 powerpc64-*-freebsd*)
230 TARGET=POWERPC; TARGETDIR=powerpc
233 TARGET=POWERPC; TARGETDIR=powerpc
236 s390-*-* | s390x-*-*)
237 TARGET=S390; TARGETDIR=s390
240 sh-*-* | sh[[34]]*-*-*)
241 TARGET=SH; TARGETDIR=sh
244 TARGET=SH64; TARGETDIR=sh64
248 TARGET=SPARC; TARGETDIR=sparc
252 TARGET=TILE; TARGETDIR=tile
256 TARGET=XTENSA; TARGETDIR=xtensa
261 AC_SUBST(AM_RUNTESTFLAGS)
262 AC_SUBST(AM_LTLDFLAGS)
264 if test $TARGETDIR = unknown; then
265 AC_MSG_ERROR(["libffi has not been ported to $host."])
268 AM_CONDITIONAL(MIPS, test x$TARGET = xMIPS)
269 AM_CONDITIONAL(BFIN, test x$TARGET = xBFIN)
270 AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
271 AM_CONDITIONAL(X86, test x$TARGET = xX86)
272 AM_CONDITIONAL(X86_FREEBSD, test x$TARGET = xX86_FREEBSD)
273 AM_CONDITIONAL(X86_WIN32, test x$TARGET = xX86_WIN32)
274 AM_CONDITIONAL(X86_WIN64, test x$TARGET = xX86_WIN64)
275 AM_CONDITIONAL(X86_DARWIN, test x$TARGET = xX86_DARWIN)
276 AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA)
277 AM_CONDITIONAL(IA64, test x$TARGET = xIA64)
278 AM_CONDITIONAL(M32R, test x$TARGET = xM32R)
279 AM_CONDITIONAL(M68K, test x$TARGET = xM68K)
280 AM_CONDITIONAL(MICROBLAZE, test x$TARGET = xMICROBLAZE)
281 AM_CONDITIONAL(MOXIE, test x$TARGET = xMOXIE)
282 AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC)
283 AM_CONDITIONAL(POWERPC_AIX, test x$TARGET = xPOWERPC_AIX)
284 AM_CONDITIONAL(POWERPC_DARWIN, test x$TARGET = xPOWERPC_DARWIN)
285 AM_CONDITIONAL(POWERPC_FREEBSD, test x$TARGET = xPOWERPC_FREEBSD)
286 AM_CONDITIONAL(AARCH64, test x$TARGET = xAARCH64)
287 AM_CONDITIONAL(ARM, test x$TARGET = xARM)
288 AM_CONDITIONAL(AVR32, test x$TARGET = xAVR32)
289 AM_CONDITIONAL(LIBFFI_CRIS, test x$TARGET = xLIBFFI_CRIS)
290 AM_CONDITIONAL(FRV, test x$TARGET = xFRV)
291 AM_CONDITIONAL(S390, test x$TARGET = xS390)
292 AM_CONDITIONAL(X86_64, test x$TARGET = xX86_64)
293 AM_CONDITIONAL(SH, test x$TARGET = xSH)
294 AM_CONDITIONAL(SH64, test x$TARGET = xSH64)
295 AM_CONDITIONAL(PA_LINUX, test x$TARGET = xPA_LINUX)
296 AM_CONDITIONAL(PA_HPUX, test x$TARGET = xPA_HPUX)
297 AM_CONDITIONAL(PA64_HPUX, test x$TARGET = xPA64_HPUX)
298 AM_CONDITIONAL(TILE, test x$TARGET = xTILE)
299 AM_CONDITIONAL(XTENSA, test x$TARGET = xXTENSA)
302 AC_CHECK_FUNCS(memcpy)
305 AC_CHECK_SIZEOF(double)
306 AC_CHECK_SIZEOF(long double)
308 # Also AC_SUBST this variable for ffi.h.
309 if test -z "$HAVE_LONG_DOUBLE"; then
311 if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
312 if test $ac_cv_sizeof_long_double != 0; then
314 AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
318 AC_SUBST(HAVE_LONG_DOUBLE)
324 if test x$TARGET = xSPARC; then
325 AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
326 libffi_cv_as_sparc_ua_pcrel, [
327 save_CFLAGS="$CFLAGS"
328 save_LDFLAGS="$LDFLAGS"
329 CFLAGS="$CFLAGS -fpic"
330 LDFLAGS="$LDFLAGS -shared"
331 AC_TRY_LINK([asm (".text; foo: nop; .data; .align 4; .byte 0; .uaword %r_disp32(foo); .text");],,
332 [libffi_cv_as_sparc_ua_pcrel=yes],
333 [libffi_cv_as_sparc_ua_pcrel=no])
334 CFLAGS="$save_CFLAGS"
335 LDFLAGS="$save_LDFLAGS"])
336 if test "x$libffi_cv_as_sparc_ua_pcrel" = xyes; then
337 AC_DEFINE(HAVE_AS_SPARC_UA_PCREL, 1,
338 [Define if your assembler and linker support unaligned PC relative relocs.])
341 AC_CACHE_CHECK([assembler .register pseudo-op support],
342 libffi_cv_as_register_pseudo_op, [
343 libffi_cv_as_register_pseudo_op=unknown
344 # Check if we have .register
345 AC_TRY_COMPILE(,[asm (".register %g2, #scratch");],
346 [libffi_cv_as_register_pseudo_op=yes],
347 [libffi_cv_as_register_pseudo_op=no])
349 if test "x$libffi_cv_as_register_pseudo_op" = xyes; then
350 AC_DEFINE(HAVE_AS_REGISTER_PSEUDO_OP, 1,
351 [Define if your assembler supports .register.])
355 if test x$TARGET = xX86 || test x$TARGET = xX86_WIN32 || test x$TARGET = xX86_64; then
356 AC_CACHE_CHECK([assembler supports pc related relocs],
357 libffi_cv_as_x86_pcrel, [
358 libffi_cv_as_x86_pcrel=no
359 echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s
360 if $CC $CFLAGS -c conftest.s > /dev/null 2>&1; then
361 libffi_cv_as_x86_pcrel=yes
364 if test "x$libffi_cv_as_x86_pcrel" = xyes; then
365 AC_DEFINE(HAVE_AS_X86_PCREL, 1,
366 [Define if your assembler supports PC relative relocs.])
369 AC_CACHE_CHECK([assembler .ascii pseudo-op support],
370 libffi_cv_as_ascii_pseudo_op, [
371 libffi_cv_as_ascii_pseudo_op=unknown
372 # Check if we have .ascii
373 AC_TRY_COMPILE(,[asm (".ascii \\"string\\"");],
374 [libffi_cv_as_ascii_pseudo_op=yes],
375 [libffi_cv_as_ascii_pseudo_op=no])
377 if test "x$libffi_cv_as_ascii_pseudo_op" = xyes; then
378 AC_DEFINE(HAVE_AS_ASCII_PSEUDO_OP, 1,
379 [Define if your assembler supports .ascii.])
382 AC_CACHE_CHECK([assembler .string pseudo-op support],
383 libffi_cv_as_string_pseudo_op, [
384 libffi_cv_as_string_pseudo_op=unknown
385 # Check if we have .string
386 AC_TRY_COMPILE(,[asm (".string \\"string\\"");],
387 [libffi_cv_as_string_pseudo_op=yes],
388 [libffi_cv_as_string_pseudo_op=no])
390 if test "x$libffi_cv_as_string_pseudo_op" = xyes; then
391 AC_DEFINE(HAVE_AS_STRING_PSEUDO_OP, 1,
392 [Define if your assembler supports .string.])
396 # On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC.
397 AC_ARG_ENABLE(pax_emutramp,
398 [ --enable-pax_emutramp enable pax emulated trampolines, for we can't use PROT_EXEC],
399 if test "$enable_pax_emutramp" = "yes"; then
400 AC_DEFINE(FFI_MMAP_EXEC_EMUTRAMP_PAX, 1,
401 [Define this if you want to enable pax emulated trampolines])
404 if test x$TARGET = xX86_WIN64; then
406 if test "x$sys_symbol_underscore" = xyes; then
407 AC_DEFINE(SYMBOL_UNDERSCORE, 1, [Define if symbols are underscored.])
411 FFI_EXEC_TRAMPOLINE_TABLE=0
414 FFI_EXEC_TRAMPOLINE_TABLE=1
415 AC_DEFINE(FFI_EXEC_TRAMPOLINE_TABLE, 1,
416 [Cannot use PROT_EXEC on this target, so, we revert to
419 *-apple-darwin1* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris*)
420 AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
421 [Cannot use malloc on this target, so, we revert to
425 AM_CONDITIONAL(FFI_EXEC_TRAMPOLINE_TABLE, test x$FFI_EXEC_TRAMPOLINE_TABLE = x1)
426 AC_SUBST(FFI_EXEC_TRAMPOLINE_TABLE)
428 if test x$TARGET = xX86_64; then
429 AC_CACHE_CHECK([assembler supports unwind section type],
430 libffi_cv_as_x86_64_unwind_section_type, [
431 libffi_cv_as_x86_64_unwind_section_type=yes
432 echo '.section .eh_frame,"a",@unwind' > conftest.s
433 if $CC $CFLAGS -c conftest.s 2>&1 | grep -i warning > /dev/null; then
434 libffi_cv_as_x86_64_unwind_section_type=no
437 if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
438 AC_DEFINE(HAVE_AS_X86_64_UNWIND_SECTION_TYPE, 1,
439 [Define if your assembler supports unwind section type.])
443 if test "x$GCC" = "xyes"; then
444 AC_CACHE_CHECK([whether .eh_frame section should be read-only],
445 libffi_cv_ro_eh_frame, [
446 libffi_cv_ro_eh_frame=no
447 echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
448 if $CC $CFLAGS -c -fpic -fexceptions -o conftest.o conftest.c > /dev/null 2>&1; then
449 objdump -h conftest.o > conftest.dump 2>&1
450 libffi_eh_frame_line=`grep -n eh_frame conftest.dump | cut -d: -f 1`
451 libffi_test_line=`expr $libffi_eh_frame_line + 1`p
452 sed -n $libffi_test_line conftest.dump > conftest.line
453 if grep READONLY conftest.line > /dev/null; then
454 libffi_cv_ro_eh_frame=yes
459 if test "x$libffi_cv_ro_eh_frame" = xyes; then
460 AC_DEFINE(HAVE_RO_EH_FRAME, 1,
461 [Define if .eh_frame sections should be read-only.])
462 AC_DEFINE(EH_FRAME_FLAGS, "a",
463 [Define to the flags needed for the .section .eh_frame directive. ])
465 AC_DEFINE(EH_FRAME_FLAGS, "aw",
466 [Define to the flags needed for the .section .eh_frame directive. ])
469 AC_CACHE_CHECK([for __attribute__((visibility("hidden")))],
470 libffi_cv_hidden_visibility_attribute, [
471 echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1 ; }' > conftest.c
472 libffi_cv_hidden_visibility_attribute=no
473 if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
474 if grep '\.hidden.*foo' conftest.s >/dev/null; then
475 libffi_cv_hidden_visibility_attribute=yes
480 if test $libffi_cv_hidden_visibility_attribute = yes; then
481 AC_DEFINE(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE, 1,
482 [Define if __attribute__((visibility("hidden"))) is supported.])
487 #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
489 #define FFI_HIDDEN(name) .hidden name
491 #define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
495 #define FFI_HIDDEN(name)
508 [ --enable-debug debugging mode],
509 if test "$enable_debug" = "yes"; then
510 AC_DEFINE(FFI_DEBUG, 1, [Define this if you want extra debugging.])
512 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
514 AC_ARG_ENABLE(structs,
515 [ --disable-structs omit code for struct support],
516 if test "$enable_structs" = "no"; then
517 AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this is you do not want support for aggregate types.])
519 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
521 AC_ARG_ENABLE(raw-api,
522 [ --disable-raw-api make the raw api unavailable],
523 if test "$enable_raw_api" = "no"; then
524 AC_DEFINE(FFI_NO_RAW_API, 1, [Define this is you do not want support for the raw API.])
527 AC_ARG_ENABLE(purify-safety,
528 [ --enable-purify-safety purify-safe mode],
529 if test "$enable_purify_safety" = "yes"; then
530 AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
533 # These variables are only ever used when we cross-build to X86_WIN32.
534 # And we only support this with GCC, so...
535 if test "x$GCC" = "xyes"; then
536 if test -n "$with_cross_host" &&
537 test x"$with_cross_host" != x"no"; then
538 toolexecdir='$(exec_prefix)/$(target_alias)'
539 toolexeclibdir='$(toolexecdir)/lib'
541 toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
542 toolexeclibdir='$(libdir)'
544 multi_os_directory=`$CC -print-multi-os-directory`
545 case $multi_os_directory in
546 .) ;; # Avoid trailing /.
547 *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
549 AC_SUBST(toolexecdir)
551 toolexeclibdir='$(libdir)'
553 AC_SUBST(toolexeclibdir)
555 AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
556 AC_CONFIG_COMMANDS(src, [
557 test -d src || mkdir src
558 test -d src/$TARGETDIR || mkdir src/$TARGETDIR
559 ], [TARGETDIR="$TARGETDIR"])
561 AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h)
563 AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc)