1 dnl Process this with autoconf to create configure
5 AC_INIT([libffi], [3.4.2], [http://github.com/libffi/libffi/issues])
6 AC_CONFIG_HEADERS([fficonfig.h])
8 AM_ENABLE_MULTILIB(, ..)
11 target_alias=${target_alias-$host_alias}
13 AM_INIT_AUTOMAKE([no-dist])
15 # We would like our source tree to be readonly. However when releases or
16 # pre-releases are generated, the flex/bison generated files as well as the
17 # various formats of manuals need to be included along with the rest of the
18 # sources. Therefore we have --enable-generated-files-in-srcdir to do
20 AC_MSG_CHECKING(generated-files-in-srcdir)
21 AC_ARG_ENABLE(generated-files-in-srcdir,
22 AS_HELP_STRING([--enable-generated-files-in-srcdir],
23 [put copies of generated files in source dir intended for creating source tarballs for users without texinfo bison or flex]),
25 yes) enable_generated_files_in_srcdir=yes ;;
26 no) enable_generated_files_in_srcdir=no ;;
27 *) AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
29 [enable_generated_files_in_srcdir=no])
30 AC_MSG_RESULT($enable_generated_files_in_srcdir)
31 AM_CONDITIONAL(GENINSRC, test "$enable_generated_files_in_srcdir" = yes)
33 # The same as in boehm-gc and libstdc++. Have to borrow it from there.
34 # We must force CC to /not/ be precious variables; otherwise
35 # the wrong, non-multilib-adjusted value will be used in multilibs.
36 # As a side effect, we have to subst CFLAGS ourselves.
37 # Also save and restore CFLAGS, since AC_PROG_CC will come up with
38 # defaults of its own if none are provided.
40 m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
41 m4_define([_AC_ARG_VAR_PRECIOUS],[])
46 m4_undefine([_AC_ARG_VAR_PRECIOUS])
47 m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
51 # Add CET specific flags if CET is enabled
52 GCC_CET_FLAGS(CET_FLAGS)
59 AC_CHECK_TOOL(READELF, readelf)
61 # Test for 64-bit build.
62 AC_CHECK_SIZEOF([size_t])
65 set CC_FOR_TARGET "$CC"
66 set CXX_FOR_TARGET "$CXX"
67 set compiler_vendor "$ax_cv_c_compiler_vendor"
72 AC_CHECK_HEADERS(sys/memfd.h)
73 AC_CHECK_FUNCS([memfd_create])
75 AC_CHECK_HEADERS(sys/mman.h)
76 AC_CHECK_FUNCS([mmap mkostemp mkstemp])
77 AC_FUNC_MMAP_BLACKLIST
79 dnl The -no-testsuite modules omit the test subdir.
80 AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
83 HAVE_LONG_DOUBLE_VARIANT=0
85 . ${srcdir}/configure.host
87 if test -n "${UNSUPPORTED}"; then
88 AC_MSG_ERROR(["libffi has not been ported to $host."])
91 AC_SUBST(AM_RUNTESTFLAGS)
92 AC_SUBST(AM_LTLDFLAGS)
95 AC_CHECK_FUNCS(memcpy)
98 AC_CHECK_SIZEOF(double)
99 AC_CHECK_SIZEOF(long double)
101 # Also AC_SUBST this variable for ffi.h.
102 if test -z "$HAVE_LONG_DOUBLE"; then
104 if test $ac_cv_sizeof_long_double != 0; then
105 if test $HAVE_LONG_DOUBLE_VARIANT != 0; then
106 AC_DEFINE(HAVE_LONG_DOUBLE_VARIANT, 1, [Define if you support more than one size of the long double type])
109 if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
111 AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
116 AC_SUBST(HAVE_LONG_DOUBLE)
117 AC_SUBST(HAVE_LONG_DOUBLE_VARIANT)
125 AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
126 libffi_cv_as_sparc_ua_pcrel, [
127 save_CFLAGS="$CFLAGS"
128 save_LDFLAGS="$LDFLAGS"
129 CFLAGS="$CFLAGS -fpic"
130 LDFLAGS="$LDFLAGS -shared"
131 AC_TRY_LINK([asm (".text; foo: nop; .data; .align 4; .byte 0; .uaword %r_disp32(foo); .text");],,
132 [libffi_cv_as_sparc_ua_pcrel=yes],
133 [libffi_cv_as_sparc_ua_pcrel=no])
134 CFLAGS="$save_CFLAGS"
135 LDFLAGS="$save_LDFLAGS"])
136 if test "x$libffi_cv_as_sparc_ua_pcrel" = xyes; then
137 AC_DEFINE(HAVE_AS_SPARC_UA_PCREL, 1,
138 [Define if your assembler and linker support unaligned PC relative relocs.])
141 AC_CACHE_CHECK([assembler .register pseudo-op support],
142 libffi_cv_as_register_pseudo_op, [
143 libffi_cv_as_register_pseudo_op=unknown
144 # Check if we have .register
145 AC_TRY_COMPILE(,[asm (".register %g2, #scratch");],
146 [libffi_cv_as_register_pseudo_op=yes],
147 [libffi_cv_as_register_pseudo_op=no])
149 if test "x$libffi_cv_as_register_pseudo_op" = xyes; then
150 AC_DEFINE(HAVE_AS_REGISTER_PSEUDO_OP, 1,
151 [Define if your assembler supports .register.])
156 AC_CACHE_CHECK([assembler supports pc related relocs],
157 libffi_cv_as_x86_pcrel, [
158 libffi_cv_as_x86_pcrel=no
159 echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s
160 if $CC $CFLAGS -c conftest.s > /dev/null 2>&1; then
161 libffi_cv_as_x86_pcrel=yes
164 if test "x$libffi_cv_as_x86_pcrel" = xyes; then
165 AC_DEFINE(HAVE_AS_X86_PCREL, 1,
166 [Define if your assembler supports PC relative relocs.])
171 AC_CACHE_CHECK([compiler uses zarch features],
172 libffi_cv_as_s390_zarch, [
173 libffi_cv_as_s390_zarch=no
174 echo 'void foo(void) { bar(); bar(); }' > conftest.c
175 if $CC $CFLAGS -S conftest.c > /dev/null 2>&1; then
176 if grep -q brasl conftest.s; then
177 libffi_cv_as_s390_zarch=yes
181 if test "x$libffi_cv_as_s390_zarch" = xyes; then
182 AC_DEFINE(HAVE_AS_S390_ZARCH, 1,
183 [Define if the compiler uses zarch features.])
188 AC_CACHE_CHECK([whether compiler supports pointer authentication],
189 libffi_cv_as_ptrauth, [
190 libffi_cv_as_ptrauth=unknown
193 # if __has_feature(ptrauth_calls)
194 # define HAVE_PTRAUTH 1
199 # error Pointer authentication not supported
202 [libffi_cv_as_ptrauth=yes],
203 [libffi_cv_as_ptrauth=no])
205 if test "x$libffi_cv_as_ptrauth" = xyes; then
206 AC_DEFINE(HAVE_PTRAUTH, 1,
207 [Define if your compiler supports pointer authentication.])
210 # On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC.
211 AC_ARG_ENABLE(pax_emutramp,
212 [ --enable-pax_emutramp enable pax emulated trampolines, for we can't use PROT_EXEC],
213 if test "$enable_pax_emutramp" = "yes"; then
214 AC_DEFINE(FFI_MMAP_EXEC_EMUTRAMP_PAX, 1,
215 [Define this if you want to enable pax emulated trampolines])
218 FFI_EXEC_TRAMPOLINE_TABLE=0
220 *arm*-apple-* | aarch64-apple-*)
221 FFI_EXEC_TRAMPOLINE_TABLE=1
222 AC_DEFINE(FFI_EXEC_TRAMPOLINE_TABLE, 1,
223 [Cannot use PROT_EXEC on this target, so, we revert to
226 *-apple-* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris* | *-linux-android*)
227 AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
228 [Cannot use malloc on this target, so, we revert to
232 AM_CONDITIONAL(FFI_EXEC_TRAMPOLINE_TABLE, test x$FFI_EXEC_TRAMPOLINE_TABLE = x1)
233 AC_SUBST(FFI_EXEC_TRAMPOLINE_TABLE)
235 if test x$TARGET = xX86_64; then
236 AC_CACHE_CHECK([toolchain supports unwind section type],
237 libffi_cv_as_x86_64_unwind_section_type, [
238 cat > conftest1.s << EOF
243 .section .eh_frame,"a",@unwind
247 cat > conftest2.c << EOF
252 libffi_cv_as_x86_64_unwind_section_type=no
253 # we ensure that we can compile _and_ link an assembly file containing an @unwind section
254 # since the compiler can support it and not the linker (ie old binutils)
255 if $CC -Wa,--fatal-warnings $CFLAGS -c conftest1.s > /dev/null 2>&1 && \
256 $CC conftest2.c conftest1.o > /dev/null 2>&1 ; then
257 libffi_cv_as_x86_64_unwind_section_type=yes
260 if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
261 AC_DEFINE(HAVE_AS_X86_64_UNWIND_SECTION_TYPE, 1,
262 [Define if your assembler supports unwind section type.])
266 if test "x$GCC" = "xyes"; then
267 AC_CACHE_CHECK([whether .eh_frame section should be read-only],
268 libffi_cv_ro_eh_frame, [
269 libffi_cv_ro_eh_frame=yes
270 echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
271 if $CC $CFLAGS -c -fpic -fexceptions -fno-lto -o conftest.o conftest.c > /dev/null 2>&1; then
272 if $READELF -WS conftest.o | grep -q -n 'eh_frame .* WA'; then
273 libffi_cv_ro_eh_frame=no
278 if test "x$libffi_cv_ro_eh_frame" = xyes; then
279 AC_DEFINE(HAVE_RO_EH_FRAME, 1,
280 [Define if .eh_frame sections should be read-only.])
281 AC_DEFINE(EH_FRAME_FLAGS, "a",
282 [Define to the flags needed for the .section .eh_frame directive. ])
284 AC_DEFINE(EH_FRAME_FLAGS, "aw",
285 [Define to the flags needed for the .section .eh_frame directive. ])
288 AC_CACHE_CHECK([for __attribute__((visibility("hidden")))],
289 libffi_cv_hidden_visibility_attribute, [
290 echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1 ; }' > conftest.c
291 libffi_cv_hidden_visibility_attribute=no
292 if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
293 if egrep '(\.hidden|\.private_extern).*foo' conftest.s >/dev/null; then
294 libffi_cv_hidden_visibility_attribute=yes
299 if test $libffi_cv_hidden_visibility_attribute = yes; then
300 AC_DEFINE(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE, 1,
301 [Define if __attribute__((visibility("hidden"))) is supported.])
305 # See if makeinfo has been installed and is modern enough
306 # that we can use it.
307 ACX_CHECK_PROG_VER([MAKEINFO], [makeinfo], [--version],
308 [GNU texinfo.* \([0-9][0-9.]*\)],
309 [4.[4-9]*|4.[1-9][0-9]*|[5-9]*|[1-9][0-9]*])
310 AM_CONDITIONAL(BUILD_DOCS, test $gcc_cv_prog_makeinfo_modern = "yes")
313 #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
316 #define FFI_HIDDEN(name) .private_extern name
318 #define FFI_HIDDEN(name) .hidden name
321 #define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
325 #define FFI_HIDDEN(name)
337 for i in $SOURCES; do
338 TARGET_OBJ="${TARGET_OBJ} src/${TARGETDIR}/"`echo $i | sed 's/[cS]$/lo/'`
346 [ --enable-debug debugging mode],
347 if test "$enable_debug" = "yes"; then
348 AC_DEFINE(FFI_DEBUG, 1, [Define this if you want extra debugging.])
350 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
352 AC_ARG_ENABLE(structs,
353 [ --disable-structs omit code for struct support],
354 if test "$enable_structs" = "no"; then
355 AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this if you do not want support for aggregate types.])
357 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
359 AC_ARG_ENABLE(raw-api,
360 [ --disable-raw-api make the raw api unavailable],
361 if test "$enable_raw_api" = "no"; then
362 AC_DEFINE(FFI_NO_RAW_API, 1, [Define this if you do not want support for the raw API.])
365 AC_ARG_ENABLE(exec-static-tramp,
366 [ --enable-exec-static-tramp enable use of static exec trampolines])
368 if test "$enable_exec_static_tramp" = yes; then
372 *arm*-*-linux-* | aarch64*-*-linux-* | i*86-*-linux-* | x86_64-*-linux-*)
373 AC_DEFINE(FFI_EXEC_STATIC_TRAMP, 1,
374 [Define this if you want statically defined trampolines])
379 AC_ARG_ENABLE(purify-safety,
380 [ --enable-purify-safety purify-safe mode],
381 if test "$enable_purify_safety" = "yes"; then
382 AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
385 GCC_WITH_TOOLEXECLIBDIR
387 if test -n "$with_cross_host" &&
388 test x"$with_cross_host" != x"no"; then
389 toolexecdir='$(exec_prefix)/$(target_alias)'
390 case ${with_toolexeclibdir} in
392 toolexeclibdir='$(toolexecdir)/lib'
395 toolexeclibdir=${with_toolexeclibdir}
399 toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
400 toolexeclibdir='$(libdir)'
402 multi_os_directory=`$CC -print-multi-os-directory`
403 case $multi_os_directory in
404 .) ;; # Avoid trailing /.
405 *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
407 AC_SUBST(toolexecdir)
408 AC_SUBST(toolexeclibdir)
410 if test "${multilib}" = "yes"; then
411 multilib_arg="--enable-multilib"
416 # Check linker support.
417 LIBFFI_ENABLE_SYMVERS
419 # Determine what GCC version number to use in filesystem paths.
422 AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
423 AC_CONFIG_COMMANDS(src, [
424 test -d src || mkdir src
425 test -d src/$TARGETDIR || mkdir src/$TARGETDIR
426 ], [TARGETDIR="$TARGETDIR"])
428 AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc)
430 AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h)