Daily bump.
[official-gcc.git] / libffi / configure.ac
blobbff5a1e718936107674ba9879bb86074fa00290a
1 dnl Process this with autoconf to create configure
3 AC_PREREQ(2.68)
5 AC_INIT([libffi], [3.4.2], [http://github.com/libffi/libffi/issues])
6 AC_CONFIG_HEADERS([fficonfig.h])
8 AM_ENABLE_MULTILIB(, ..)
10 AC_CANONICAL_SYSTEM
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
19 # just that.
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]),
24 [case "$enableval" in
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]);;
28  esac],
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],[])
42 save_CFLAGS=$CFLAGS
43 AC_PROG_CC
44 AC_PROG_CXX
45 CFLAGS=$save_CFLAGS
46 m4_undefine([_AC_ARG_VAR_PRECIOUS])
47 m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
49 AC_SUBST(CFLAGS)
51 AM_PROG_AS
52 AM_PROG_CC_C_O
53 AC_PROG_LIBTOOL
55 AC_CHECK_TOOL(READELF, readelf)
57 # Test for 64-bit build.
58 AC_CHECK_SIZEOF([size_t])
60 cat > local.exp <<EOF
61 set CC_FOR_TARGET "$CC"
62 set CXX_FOR_TARGET "$CXX"
63 set compiler_vendor "$ax_cv_c_compiler_vendor"
64 EOF
66 AM_MAINTAINER_MODE
68 AC_CHECK_HEADERS(sys/memfd.h)
69 AC_CHECK_FUNCS([memfd_create])
71 AC_CHECK_HEADERS(sys/mman.h)
72 AC_CHECK_FUNCS([mmap mkostemp mkstemp])
73 AC_FUNC_MMAP_BLACKLIST
75 dnl The -no-testsuite modules omit the test subdir.
76 AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
78 TARGETDIR="unknown"
79 HAVE_LONG_DOUBLE_VARIANT=0
81 . ${srcdir}/configure.host
83 if test -n "${UNSUPPORTED}"; then
84   AC_MSG_ERROR(["libffi has not been ported to $host."])
87 AC_SUBST(AM_RUNTESTFLAGS)
88 AC_SUBST(AM_LTLDFLAGS)
90 AC_HEADER_STDC
91 AC_CHECK_FUNCS(memcpy)
92 AC_FUNC_ALLOCA
94 AC_CHECK_SIZEOF(double)
95 AC_CHECK_SIZEOF(long double)
97 # Also AC_SUBST this variable for ffi.h.
98 if test -z "$HAVE_LONG_DOUBLE"; then
99   HAVE_LONG_DOUBLE=0
100   if test $ac_cv_sizeof_long_double != 0; then
101     if test $HAVE_LONG_DOUBLE_VARIANT != 0; then
102       AC_DEFINE(HAVE_LONG_DOUBLE_VARIANT, 1, [Define if you support more than one size of the long double type])
103       HAVE_LONG_DOUBLE=1
104     else
105       if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
106         HAVE_LONG_DOUBLE=1
107         AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
108       fi
109     fi
110   fi
112 AC_SUBST(HAVE_LONG_DOUBLE)
113 AC_SUBST(HAVE_LONG_DOUBLE_VARIANT)
115 AC_C_BIGENDIAN
117 GCC_AS_CFI_PSEUDO_OP
119 case "$TARGET" in
120   SPARC)
121     AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
122         libffi_cv_as_sparc_ua_pcrel, [
123         save_CFLAGS="$CFLAGS"
124         save_LDFLAGS="$LDFLAGS"
125         CFLAGS="$CFLAGS -fpic"
126         LDFLAGS="$LDFLAGS -shared"
127         AC_TRY_LINK([asm (".text; foo: nop; .data; .align 4; .byte 0; .uaword %r_disp32(foo); .text");],,
128                     [libffi_cv_as_sparc_ua_pcrel=yes],
129                     [libffi_cv_as_sparc_ua_pcrel=no])
130         CFLAGS="$save_CFLAGS"
131         LDFLAGS="$save_LDFLAGS"])
132     if test "x$libffi_cv_as_sparc_ua_pcrel" = xyes; then
133         AC_DEFINE(HAVE_AS_SPARC_UA_PCREL, 1,
134                   [Define if your assembler and linker support unaligned PC relative relocs.])
135     fi
137     AC_CACHE_CHECK([assembler .register pseudo-op support],
138        libffi_cv_as_register_pseudo_op, [
139        libffi_cv_as_register_pseudo_op=unknown
140        # Check if we have .register
141        AC_TRY_COMPILE(,[asm (".register %g2, #scratch");],
142                        [libffi_cv_as_register_pseudo_op=yes],
143                        [libffi_cv_as_register_pseudo_op=no])
144     ])
145     if test "x$libffi_cv_as_register_pseudo_op" = xyes; then
146        AC_DEFINE(HAVE_AS_REGISTER_PSEUDO_OP, 1,
147                [Define if your assembler supports .register.])
148     fi
149     ;;
151   X86*)
152     AC_CACHE_CHECK([assembler supports pc related relocs],
153         libffi_cv_as_x86_pcrel, [
154         libffi_cv_as_x86_pcrel=no
155         echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s
156         if $CC $CFLAGS -c conftest.s > /dev/null 2>&1; then
157             libffi_cv_as_x86_pcrel=yes
158         fi
159         ])
160     if test "x$libffi_cv_as_x86_pcrel" = xyes; then
161         AC_DEFINE(HAVE_AS_X86_PCREL, 1,
162                   [Define if your assembler supports PC relative relocs.])
163     fi
164     ;;
166   S390)
167     AC_CACHE_CHECK([compiler uses zarch features],
168         libffi_cv_as_s390_zarch, [
169         libffi_cv_as_s390_zarch=no
170         echo 'void foo(void) { bar(); bar(); }' > conftest.c
171         if $CC $CFLAGS -S conftest.c > /dev/null 2>&1; then
172             if grep -q brasl conftest.s; then
173                 libffi_cv_as_s390_zarch=yes
174             fi
175         fi
176         ])
177     if test "x$libffi_cv_as_s390_zarch" = xyes; then
178         AC_DEFINE(HAVE_AS_S390_ZARCH, 1,
179                   [Define if the compiler uses zarch features.])
180     fi
181     ;;
182 esac
184 AC_CACHE_CHECK([whether compiler supports pointer authentication],
185    libffi_cv_as_ptrauth, [
186    libffi_cv_as_ptrauth=unknown
187    AC_TRY_COMPILE(,[
188 #ifdef __clang__
189 # if __has_feature(ptrauth_calls)
190 #  define HAVE_PTRAUTH 1
191 # endif
192 #endif
194 #ifndef HAVE_PTRAUTH
195 # error Pointer authentication not supported
196 #endif
197                    ],
198                    [libffi_cv_as_ptrauth=yes],
199                    [libffi_cv_as_ptrauth=no])
201 if test "x$libffi_cv_as_ptrauth" = xyes; then
202     AC_DEFINE(HAVE_PTRAUTH, 1,
203               [Define if your compiler supports pointer authentication.])
206 # On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC.
207 AC_ARG_ENABLE(pax_emutramp,
208   [  --enable-pax_emutramp       enable pax emulated trampolines, for we can't use PROT_EXEC],
209   if test "$enable_pax_emutramp" = "yes"; then
210     AC_DEFINE(FFI_MMAP_EXEC_EMUTRAMP_PAX, 1,
211       [Define this if you want to enable pax emulated trampolines])
212   fi)
214 FFI_EXEC_TRAMPOLINE_TABLE=0
215 case "$target" in
216      *arm*-apple-* | aarch64-apple-*)
217        FFI_EXEC_TRAMPOLINE_TABLE=1
218        AC_DEFINE(FFI_EXEC_TRAMPOLINE_TABLE, 1,
219                  [Cannot use PROT_EXEC on this target, so, we revert to
220                    alternative means])
221      ;;
222      *-apple-* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris* | *-linux-android*)
223        AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
224                  [Cannot use malloc on this target, so, we revert to
225                    alternative means])
226      ;;
227 esac
228 AM_CONDITIONAL(FFI_EXEC_TRAMPOLINE_TABLE, test x$FFI_EXEC_TRAMPOLINE_TABLE = x1)
229 AC_SUBST(FFI_EXEC_TRAMPOLINE_TABLE)
231 if test x$TARGET = xX86_64; then
232     AC_CACHE_CHECK([toolchain supports unwind section type],
233         libffi_cv_as_x86_64_unwind_section_type, [
234         cat  > conftest1.s << EOF
235 .text
236 .globl foo
237 foo:
238 jmp bar
239 .section .eh_frame,"a",@unwind
240 bar:
243         cat > conftest2.c  << EOF
244 extern void foo();
245 int main(){foo();}
248         libffi_cv_as_x86_64_unwind_section_type=no
249         # we ensure that we can compile _and_ link an assembly file containing an @unwind section
250         # since the compiler can support it and not the linker (ie old binutils)
251         if $CC -Wa,--fatal-warnings $CFLAGS -c conftest1.s > /dev/null 2>&1 && \
252            $CC conftest2.c conftest1.o > /dev/null 2>&1 ; then
253             libffi_cv_as_x86_64_unwind_section_type=yes
254         fi
255         ])
256     if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
257         AC_DEFINE(HAVE_AS_X86_64_UNWIND_SECTION_TYPE, 1,
258                   [Define if your assembler supports unwind section type.])
259     fi
262 if test "x$GCC" = "xyes"; then
263   AC_CACHE_CHECK([whether .eh_frame section should be read-only],
264       libffi_cv_ro_eh_frame, [
265         libffi_cv_ro_eh_frame=yes
266         echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
267         if $CC $CFLAGS -c -fpic -fexceptions -fno-lto -o conftest.o conftest.c > /dev/null 2>&1; then
268             if $READELF -WS conftest.o | grep -q -n 'eh_frame .* WA'; then
269                 libffi_cv_ro_eh_frame=no
270             fi
271         fi
272         rm -f conftest.*
273       ])
274   if test "x$libffi_cv_ro_eh_frame" = xyes; then
275       AC_DEFINE(HAVE_RO_EH_FRAME, 1,
276               [Define if .eh_frame sections should be read-only.])
277       AC_DEFINE(EH_FRAME_FLAGS, "a",
278               [Define to the flags needed for the .section .eh_frame directive.  ])
279   else
280       AC_DEFINE(EH_FRAME_FLAGS, "aw",
281               [Define to the flags needed for the .section .eh_frame directive.  ])
282   fi
284   AC_CACHE_CHECK([for __attribute__((visibility("hidden")))],
285       libffi_cv_hidden_visibility_attribute, [
286         echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1  ; }' > conftest.c
287         libffi_cv_hidden_visibility_attribute=no
288         if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
289             if egrep '(\.hidden|\.private_extern).*foo' conftest.s >/dev/null; then
290                 libffi_cv_hidden_visibility_attribute=yes
291             fi
292         fi
293         rm -f conftest.*
294       ])
295   if test $libffi_cv_hidden_visibility_attribute = yes; then
296       AC_DEFINE(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE, 1,
297               [Define if __attribute__((visibility("hidden"))) is supported.])
298   fi
301 # See if makeinfo has been installed and is modern enough
302 # that we can use it.
303 ACX_CHECK_PROG_VER([MAKEINFO], [makeinfo], [--version],
304                    [GNU texinfo.* \([0-9][0-9.]*\)],
305                    [4.[4-9]*|4.[1-9][0-9]*|[5-9]*|[1-9][0-9]*])
306 AM_CONDITIONAL(BUILD_DOCS, test $gcc_cv_prog_makeinfo_modern = "yes")
308 AH_BOTTOM([
309 #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
310 #ifdef LIBFFI_ASM
311 #ifdef __APPLE__
312 #define FFI_HIDDEN(name) .private_extern name
313 #else
314 #define FFI_HIDDEN(name) .hidden name
315 #endif
316 #else
317 #define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
318 #endif
319 #else
320 #ifdef LIBFFI_ASM
321 #define FFI_HIDDEN(name)
322 #else
323 #define FFI_HIDDEN
324 #endif
325 #endif
328 AC_SUBST(TARGET)
329 AC_SUBST(TARGETDIR)
331 changequote(<,>)
332 TARGET_OBJ=
333 for i in $SOURCES; do
334   TARGET_OBJ="${TARGET_OBJ} src/${TARGETDIR}/"`echo $i | sed 's/[cS]$/lo/'`
335 done
336 changequote([,])
337 AC_SUBST(TARGET_OBJ)
339 AC_SUBST(SHELL)
341 AC_ARG_ENABLE(debug,
342 [  --enable-debug          debugging mode],
343   if test "$enable_debug" = "yes"; then
344     AC_DEFINE(FFI_DEBUG, 1, [Define this if you want extra debugging.])
345   fi)
346 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
348 AC_ARG_ENABLE(structs,
349 [  --disable-structs       omit code for struct support],
350   if test "$enable_structs" = "no"; then
351     AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this if you do not want support for aggregate types.])
352   fi)
353 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
355 AC_ARG_ENABLE(raw-api,
356 [  --disable-raw-api       make the raw api unavailable],
357   if test "$enable_raw_api" = "no"; then
358     AC_DEFINE(FFI_NO_RAW_API, 1, [Define this if you do not want support for the raw API.])
359   fi)
361 AC_ARG_ENABLE(exec-static-tramp,
362 [  --enable-exec-static-tramp  enable use of static exec trampolines])
364 if test "$enable_exec_static_tramp" = yes; then
365 case "$target" in
366      *-cygwin*)
367      ;;
368      *arm*-*-linux-* | aarch64*-*-linux-* | i*86-*-linux-* | x86_64-*-linux-*)
369        AC_DEFINE(FFI_EXEC_STATIC_TRAMP, 1,
370                  [Define this if you want statically defined trampolines])
371      ;;
372 esac
375 AC_ARG_ENABLE(purify-safety,
376 [  --enable-purify-safety  purify-safe mode],
377   if test "$enable_purify_safety" = "yes"; then
378     AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
379   fi)
381 GCC_WITH_TOOLEXECLIBDIR
383 if test -n "$with_cross_host" &&
384    test x"$with_cross_host" != x"no"; then
385   toolexecdir='$(exec_prefix)/$(target_alias)'
386   case ${with_toolexeclibdir} in
387     no)
388       toolexeclibdir='$(toolexecdir)/lib'
389       ;;
390     *)
391       toolexeclibdir=${with_toolexeclibdir}
392       ;;
393   esac
394 else
395   toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
396   toolexeclibdir='$(libdir)'
398 multi_os_directory=`$CC -print-multi-os-directory`
399 case $multi_os_directory in
400   .) ;; # Avoid trailing /.
401   *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
402 esac
403 AC_SUBST(toolexecdir)
404 AC_SUBST(toolexeclibdir)
406 if test "${multilib}" = "yes"; then
407   multilib_arg="--enable-multilib"
408 else
409   multilib_arg=
412 # Check linker support.
413 LIBFFI_ENABLE_SYMVERS
415 # Determine what GCC version number to use in filesystem paths.
416 GCC_BASE_VER
418 AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
419 AC_CONFIG_COMMANDS(src, [
420 test -d src || mkdir src
421 test -d src/$TARGETDIR || mkdir src/$TARGETDIR
422 ], [TARGETDIR="$TARGETDIR"])
424 AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc)
426 AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h)
428 AC_OUTPUT