Print more information when an assertion fails in test suite (#649)
[platform/upstream/libffi.git] / configure.ac
1 dnl Process this with autoconf to create configure
2
3 AC_PREREQ(2.68)
4
5 AC_INIT([libffi], [3.4-rc1], [http://github.com/libffi/libffi/issues])
6 AC_CONFIG_HEADERS([fficonfig.h])
7
8 AC_CANONICAL_SYSTEM
9 target_alias=${target_alias-$host_alias}
10
11 case "${host}" in
12   frv*-elf)
13     LDFLAGS=`echo $LDFLAGS | sed "s/\-B[^ ]*libgloss\/frv\///"`\ -B`pwd`/../libgloss/frv/
14     ;;
15 esac
16
17 AX_ENABLE_BUILDDIR
18
19 AM_INIT_AUTOMAKE
20
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.
27
28 m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
29 m4_define([_AC_ARG_VAR_PRECIOUS],[])
30 save_CFLAGS=$CFLAGS
31 AC_PROG_CC
32 AC_PROG_CXX
33 CFLAGS=$save_CFLAGS
34 m4_undefine([_AC_ARG_VAR_PRECIOUS])
35 m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
36
37 AC_SUBST(CFLAGS)
38
39 AM_PROG_AS
40 AM_PROG_CC_C_O
41 AC_PROG_LIBTOOL
42 AC_CONFIG_MACRO_DIR([m4])
43
44 AC_CHECK_TOOL(READELF, readelf)
45
46 # Test for 64-bit build.
47 AC_CHECK_SIZEOF([size_t])
48
49 AX_COMPILER_VENDOR
50 AX_CC_MAXOPT
51 # The AX_CFLAGS_WARN_ALL macro doesn't currently work for sunpro
52 # compiler.
53 if test "$ax_cv_c_compiler_vendor" != "sun"; then
54   AX_CFLAGS_WARN_ALL
55 fi
56
57 if test "x$GCC" = "xyes"; then
58   CFLAGS="$CFLAGS -fexceptions"
59 fi
60
61 cat > local.exp <<EOF
62 set CC_FOR_TARGET "$CC"
63 set CXX_FOR_TARGET "$CXX"
64 set compiler_vendor "$ax_cv_c_compiler_vendor"
65 EOF
66
67 AM_MAINTAINER_MODE
68
69 AC_CHECK_HEADERS(sys/memfd.h)
70 AC_CHECK_FUNCS([memfd_create])
71
72 AC_CHECK_HEADERS(sys/mman.h)
73 AC_CHECK_FUNCS([mmap mkostemp mkstemp])
74 AC_FUNC_MMAP_BLACKLIST
75
76 dnl The -no-testsuite modules omit the test subdir.
77 AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
78
79 TARGETDIR="unknown"
80 HAVE_LONG_DOUBLE_VARIANT=0
81
82 . ${srcdir}/configure.host
83
84 if test -n "${UNSUPPORTED}"; then
85   AC_MSG_ERROR(["libffi has not been ported to $host."])
86 fi
87
88 AC_SUBST(AM_RUNTESTFLAGS)
89 AC_SUBST(AM_LTLDFLAGS)
90
91 AC_HEADER_STDC
92 AC_CHECK_FUNCS(memcpy)
93 AC_FUNC_ALLOCA
94
95 AC_CHECK_SIZEOF(double)
96 AC_CHECK_SIZEOF(long double)
97
98 # Also AC_SUBST this variable for ffi.h.
99 if test -z "$HAVE_LONG_DOUBLE"; then
100   HAVE_LONG_DOUBLE=0
101   if test $ac_cv_sizeof_long_double != 0; then
102     if test $HAVE_LONG_DOUBLE_VARIANT != 0; then
103       AC_DEFINE(HAVE_LONG_DOUBLE_VARIANT, 1, [Define if you support more than one size of the long double type])
104       HAVE_LONG_DOUBLE=1
105     else
106       if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
107         HAVE_LONG_DOUBLE=1
108         AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
109       fi
110     fi
111   fi
112 fi
113 AC_SUBST(HAVE_LONG_DOUBLE)
114 AC_SUBST(HAVE_LONG_DOUBLE_VARIANT)
115
116 AC_C_BIGENDIAN
117
118 GCC_AS_CFI_PSEUDO_OP
119
120 case "$TARGET" in
121   SPARC)
122     AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
123         libffi_cv_as_sparc_ua_pcrel, [
124         save_CFLAGS="$CFLAGS"
125         save_LDFLAGS="$LDFLAGS"
126         CFLAGS="$CFLAGS -fpic"
127         LDFLAGS="$LDFLAGS -shared"
128         AC_TRY_LINK([asm (".text; foo: nop; .data; .align 4; .byte 0; .uaword %r_disp32(foo); .text");],,
129                     [libffi_cv_as_sparc_ua_pcrel=yes],
130                     [libffi_cv_as_sparc_ua_pcrel=no])
131         CFLAGS="$save_CFLAGS"
132         LDFLAGS="$save_LDFLAGS"])
133     if test "x$libffi_cv_as_sparc_ua_pcrel" = xyes; then
134         AC_DEFINE(HAVE_AS_SPARC_UA_PCREL, 1,
135                   [Define if your assembler and linker support unaligned PC relative relocs.])
136     fi
137
138     AC_CACHE_CHECK([assembler .register pseudo-op support],
139        libffi_cv_as_register_pseudo_op, [
140        libffi_cv_as_register_pseudo_op=unknown
141        # Check if we have .register
142        AC_TRY_COMPILE(,[asm (".register %g2, #scratch");],
143                        [libffi_cv_as_register_pseudo_op=yes],
144                        [libffi_cv_as_register_pseudo_op=no])
145     ])
146     if test "x$libffi_cv_as_register_pseudo_op" = xyes; then
147        AC_DEFINE(HAVE_AS_REGISTER_PSEUDO_OP, 1,
148                [Define if your assembler supports .register.])
149     fi
150     ;;
151
152   X86*)
153     AC_CACHE_CHECK([assembler supports pc related relocs],
154         libffi_cv_as_x86_pcrel, [
155         libffi_cv_as_x86_pcrel=no
156         echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s
157         if $CC $CFLAGS -c conftest.s > /dev/null 2>&1; then
158             libffi_cv_as_x86_pcrel=yes
159         fi
160         ])
161     if test "x$libffi_cv_as_x86_pcrel" = xyes; then
162         AC_DEFINE(HAVE_AS_X86_PCREL, 1,
163                   [Define if your assembler supports PC relative relocs.])
164     fi
165     ;;
166
167   S390)
168     AC_CACHE_CHECK([compiler uses zarch features],
169         libffi_cv_as_s390_zarch, [
170         libffi_cv_as_s390_zarch=no
171         echo 'void foo(void) { bar(); bar(); }' > conftest.c
172         if $CC $CFLAGS -S conftest.c > /dev/null 2>&1; then
173             if grep -q brasl conftest.s; then
174                 libffi_cv_as_s390_zarch=yes
175             fi
176         fi
177         ])
178     if test "x$libffi_cv_as_s390_zarch" = xyes; then
179         AC_DEFINE(HAVE_AS_S390_ZARCH, 1,
180                   [Define if the compiler uses zarch features.])
181     fi
182     ;;
183 esac
184
185 AC_CACHE_CHECK([whether compiler supports pointer authentication],
186    libffi_cv_as_ptrauth, [
187    libffi_cv_as_ptrauth=unknown
188    AC_TRY_COMPILE(,[
189 #ifdef __clang__
190 # if __has_feature(ptrauth_calls)
191 #  define HAVE_PTRAUTH 1
192 # endif
193 #endif
194
195 #ifndef HAVE_PTRAUTH
196 # error Pointer authentication not supported
197 #endif
198                    ],
199                    [libffi_cv_as_ptrauth=yes],
200                    [libffi_cv_as_ptrauth=no])
201 ])
202 if test "x$libffi_cv_as_ptrauth" = xyes; then
203     AC_DEFINE(HAVE_PTRAUTH, 1,
204               [Define if your compiler supports pointer authentication.])
205 fi
206
207 # On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC.
208 AC_ARG_ENABLE(pax_emutramp,
209   [  --enable-pax_emutramp       enable pax emulated trampolines, for we can't use PROT_EXEC],
210   if test "$enable_pax_emutramp" = "yes"; then
211     AC_DEFINE(FFI_MMAP_EXEC_EMUTRAMP_PAX, 1,
212       [Define this if you want to enable pax emulated trampolines])
213   fi)
214
215 LT_SYS_SYMBOL_USCORE
216 if test "x$sys_symbol_underscore" = xyes; then
217     AC_DEFINE(SYMBOL_UNDERSCORE, 1, [Define if symbols are underscored.])
218 fi
219
220 FFI_EXEC_TRAMPOLINE_TABLE=0
221 case "$target" in
222      *arm*-apple-* | aarch64-apple-*)
223        FFI_EXEC_TRAMPOLINE_TABLE=1
224        AC_DEFINE(FFI_EXEC_TRAMPOLINE_TABLE, 1,
225                  [Cannot use PROT_EXEC on this target, so, we revert to
226                    alternative means])
227      ;;
228      *-apple-* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris* | *-linux-android*)
229        AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
230                  [Cannot use malloc on this target, so, we revert to
231                    alternative means])
232      ;;
233 esac
234 AM_CONDITIONAL(FFI_EXEC_TRAMPOLINE_TABLE, test x$FFI_EXEC_TRAMPOLINE_TABLE = x1)
235 AC_SUBST(FFI_EXEC_TRAMPOLINE_TABLE)
236
237 if test x$TARGET = xX86_64; then
238     AC_CACHE_CHECK([toolchain supports unwind section type],
239         libffi_cv_as_x86_64_unwind_section_type, [
240         cat  > conftest1.s << EOF
241 .text
242 .globl foo
243 foo:
244 jmp bar
245 .section .eh_frame,"a",@unwind
246 bar:
247 EOF
248
249         cat > conftest2.c  << EOF
250 extern void foo();
251 int main(){foo();}
252 EOF
253
254         libffi_cv_as_x86_64_unwind_section_type=no
255         # we ensure that we can compile _and_ link an assembly file containing an @unwind section
256         # since the compiler can support it and not the linker (ie old binutils)
257         if $CC -Wa,--fatal-warnings $CFLAGS -c conftest1.s > /dev/null 2>&1 && \
258            $CC conftest2.c conftest1.o > /dev/null 2>&1 ; then
259             libffi_cv_as_x86_64_unwind_section_type=yes
260         fi
261         ])
262     if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
263         AC_DEFINE(HAVE_AS_X86_64_UNWIND_SECTION_TYPE, 1,
264                   [Define if your assembler supports unwind section type.])
265     fi
266 fi
267
268 if test "x$GCC" = "xyes"; then
269   AX_CHECK_COMPILE_FLAG(-fno-lto, libffi_cv_no_lto=-fno-lto)
270
271   AC_CACHE_CHECK([whether .eh_frame section should be read-only],
272       libffi_cv_ro_eh_frame, [
273         libffi_cv_ro_eh_frame=yes
274         echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
275         if $CC $CFLAGS -c -fpic -fexceptions $libffi_cv_no_lto -o conftest.o conftest.c > /dev/null 2>&1; then
276             if $READELF -WS conftest.o | grep -q -n 'eh_frame .* WA'; then
277                 libffi_cv_ro_eh_frame=no
278             fi
279         fi
280         rm -f conftest.*
281       ])
282   if test "x$libffi_cv_ro_eh_frame" = xyes; then
283       AC_DEFINE(HAVE_RO_EH_FRAME, 1,
284               [Define if .eh_frame sections should be read-only.])
285       AC_DEFINE(EH_FRAME_FLAGS, "a",
286               [Define to the flags needed for the .section .eh_frame directive.  ])
287   else
288       AC_DEFINE(EH_FRAME_FLAGS, "aw",
289               [Define to the flags needed for the .section .eh_frame directive.  ])
290   fi
291
292   AC_CACHE_CHECK([for __attribute__((visibility("hidden")))],
293       libffi_cv_hidden_visibility_attribute, [
294         echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1  ; }' > conftest.c
295         libffi_cv_hidden_visibility_attribute=no
296         if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
297             if egrep '(\.hidden|\.private_extern).*foo' conftest.s >/dev/null; then
298                 libffi_cv_hidden_visibility_attribute=yes
299             fi
300         fi
301         rm -f conftest.*
302       ])
303   if test $libffi_cv_hidden_visibility_attribute = yes; then
304       AC_DEFINE(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE, 1,
305               [Define if __attribute__((visibility("hidden"))) is supported.])
306   fi
307 fi
308
309 AC_ARG_ENABLE(docs,
310               AC_HELP_STRING([--disable-docs],
311                              [Disable building of docs (default: no)]),
312               [enable_docs=no],
313               [enable_docs=yes])
314 AM_CONDITIONAL(BUILD_DOCS, [test x$enable_docs = xyes])
315
316 AH_BOTTOM([
317 #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
318 #ifdef LIBFFI_ASM
319 #ifdef __APPLE__
320 #define FFI_HIDDEN(name) .private_extern name
321 #else
322 #define FFI_HIDDEN(name) .hidden name
323 #endif
324 #else
325 #define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
326 #endif
327 #else
328 #ifdef LIBFFI_ASM
329 #define FFI_HIDDEN(name)
330 #else
331 #define FFI_HIDDEN
332 #endif
333 #endif
334 ])
335
336 AC_SUBST(TARGET)
337 AC_SUBST(TARGETDIR)
338
339 changequote(<,>)
340 TARGET_OBJ=
341 for i in $SOURCES; do
342   TARGET_OBJ="${TARGET_OBJ} src/${TARGETDIR}/"`echo $i | sed 's/[cS]$/lo/'`
343 done
344 changequote([,])
345 AC_SUBST(TARGET_OBJ)
346
347 AC_SUBST(SHELL)
348
349 AC_ARG_ENABLE(debug,
350 [  --enable-debug          debugging mode],
351   if test "$enable_debug" = "yes"; then
352     AC_DEFINE(FFI_DEBUG, 1, [Define this if you want extra debugging.])
353   fi)
354 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
355
356 AC_ARG_ENABLE(structs,
357 [  --disable-structs       omit code for struct support],
358   if test "$enable_structs" = "no"; then
359     AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this if you do not want support for aggregate types.])
360   fi)
361 AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
362
363 AC_ARG_ENABLE(raw-api,
364 [  --disable-raw-api       make the raw api unavailable],
365   if test "$enable_raw_api" = "no"; then
366     AC_DEFINE(FFI_NO_RAW_API, 1, [Define this if you do not want support for the raw API.])
367   fi)
368
369 AC_ARG_ENABLE(exec-static-tramp,
370 [  --disable-exec-static-tramp  disable use of static exec trampolines (enabled by default)])
371
372 if test "$enable_exec_static_tramp" != no; then
373 case "$target" in
374      *-cygwin*)
375      ;;
376      *arm*-*-linux-* | aarch64*-*-linux-* | i*86-*-linux-* | x86_64-*-linux-*)
377        AC_DEFINE(FFI_EXEC_STATIC_TRAMP, 1,
378                  [Define this if you want statically defined trampolines])
379      ;;
380 esac
381 fi
382
383 AC_ARG_ENABLE(purify-safety,
384 [  --enable-purify-safety  purify-safe mode],
385   if test "$enable_purify_safety" = "yes"; then
386     AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
387   fi)
388
389 AC_ARG_ENABLE(multi-os-directory,
390 [  --disable-multi-os-directory
391                           disable use of gcc --print-multi-os-directory to change the library installation directory])
392                           
393 # These variables are only ever used when we cross-build to X86_WIN32.
394 # And we only support this with GCC, so...
395 if test "x$GCC" = "xyes"; then
396   if test -n "$with_cross_host" &&
397      test x"$with_cross_host" != x"no"; then
398     toolexecdir='${exec_prefix}'/'$(target_alias)'
399     toolexeclibdir='${toolexecdir}'/lib
400   else
401     toolexecdir='${libdir}'/gcc-lib/'$(target_alias)'
402     toolexeclibdir='${libdir}'
403   fi
404   if test x"$enable_multi_os_directory" != x"no"; then
405     multi_os_directory=`$CC $CFLAGS -print-multi-os-directory`
406     case $multi_os_directory in
407       .) ;; # Avoid trailing /.
408       ../*) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
409     esac
410   fi
411   AC_SUBST(toolexecdir)
412 else
413   toolexeclibdir='${libdir}'
414 fi
415 AC_SUBST(toolexeclibdir)
416
417 # Check linker support.
418 LIBFFI_ENABLE_SYMVERS
419
420 AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
421 AC_CONFIG_COMMANDS(src, [
422 test -d src || mkdir src
423 test -d src/$TARGETDIR || mkdir src/$TARGETDIR
424 ], [TARGETDIR="$TARGETDIR"])
425
426 AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile doc/Makefile libffi.pc)
427
428 AC_OUTPUT
429
430 # Copy this file instead of using AC_CONFIG_LINK in order to support
431 # compiling with MSVC, which won't understand cygwin style symlinks.
432 cp ${srcdir}/src/$TARGETDIR/ffitarget.h include/ffitarget.h