configure.ac 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. dnl Process this with autoconf to create configure
  2. AC_PREREQ(2.68)
  3. AC_INIT([libffi], [3.4.2], [http://github.com/libffi/libffi/issues])
  4. AC_CONFIG_HEADERS([fficonfig.h])
  5. AM_ENABLE_MULTILIB(, ..)
  6. AC_CANONICAL_SYSTEM
  7. target_alias=${target_alias-$host_alias}
  8. AM_INIT_AUTOMAKE([no-dist])
  9. # We would like our source tree to be readonly. However when releases or
  10. # pre-releases are generated, the flex/bison generated files as well as the
  11. # various formats of manuals need to be included along with the rest of the
  12. # sources. Therefore we have --enable-generated-files-in-srcdir to do
  13. # just that.
  14. AC_MSG_CHECKING(generated-files-in-srcdir)
  15. AC_ARG_ENABLE(generated-files-in-srcdir,
  16. AS_HELP_STRING([--enable-generated-files-in-srcdir],
  17. [put copies of generated files in source dir intended for creating source tarballs for users without texinfo bison or flex]),
  18. [case "$enableval" in
  19. yes) enable_generated_files_in_srcdir=yes ;;
  20. no) enable_generated_files_in_srcdir=no ;;
  21. *) AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
  22. esac],
  23. [enable_generated_files_in_srcdir=no])
  24. AC_MSG_RESULT($enable_generated_files_in_srcdir)
  25. AM_CONDITIONAL(GENINSRC, test "$enable_generated_files_in_srcdir" = yes)
  26. # The same as in boehm-gc and libstdc++. Have to borrow it from there.
  27. # We must force CC to /not/ be precious variables; otherwise
  28. # the wrong, non-multilib-adjusted value will be used in multilibs.
  29. # As a side effect, we have to subst CFLAGS ourselves.
  30. # Also save and restore CFLAGS, since AC_PROG_CC will come up with
  31. # defaults of its own if none are provided.
  32. m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
  33. m4_define([_AC_ARG_VAR_PRECIOUS],[])
  34. save_CFLAGS=$CFLAGS
  35. AC_PROG_CC
  36. AC_PROG_CXX
  37. CFLAGS=$save_CFLAGS
  38. m4_undefine([_AC_ARG_VAR_PRECIOUS])
  39. m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
  40. AC_SUBST(CFLAGS)
  41. # Add CET specific flags if CET is enabled
  42. GCC_CET_FLAGS(CET_FLAGS)
  43. AC_SUBST(CET_FLAGS)
  44. AM_PROG_AS
  45. AM_PROG_CC_C_O
  46. AC_PROG_LIBTOOL
  47. AC_CHECK_TOOL(READELF, readelf)
  48. # Test for 64-bit build.
  49. AC_CHECK_SIZEOF([size_t])
  50. cat > local.exp <<EOF
  51. set CC_FOR_TARGET "$CC"
  52. set CXX_FOR_TARGET "$CXX"
  53. set compiler_vendor "$ax_cv_c_compiler_vendor"
  54. EOF
  55. AM_MAINTAINER_MODE
  56. AC_CHECK_HEADERS(sys/memfd.h)
  57. AC_CHECK_FUNCS([memfd_create])
  58. AC_CHECK_HEADERS(sys/mman.h)
  59. AC_CHECK_FUNCS([mmap mkostemp mkstemp])
  60. AC_FUNC_MMAP_BLACKLIST
  61. dnl The -no-testsuite modules omit the test subdir.
  62. AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
  63. TARGETDIR="unknown"
  64. HAVE_LONG_DOUBLE_VARIANT=0
  65. . ${srcdir}/configure.host
  66. if test -n "${UNSUPPORTED}"; then
  67. AC_MSG_ERROR(["libffi has not been ported to $host."])
  68. fi
  69. AC_SUBST(AM_RUNTESTFLAGS)
  70. AC_SUBST(AM_LTLDFLAGS)
  71. AC_HEADER_STDC
  72. AC_CHECK_FUNCS(memcpy)
  73. AC_FUNC_ALLOCA
  74. AC_CHECK_SIZEOF(double)
  75. AC_CHECK_SIZEOF(long double)
  76. # Also AC_SUBST this variable for ffi.h.
  77. if test -z "$HAVE_LONG_DOUBLE"; then
  78. HAVE_LONG_DOUBLE=0
  79. if test $ac_cv_sizeof_long_double != 0; then
  80. if test $HAVE_LONG_DOUBLE_VARIANT != 0; then
  81. AC_DEFINE(HAVE_LONG_DOUBLE_VARIANT, 1, [Define if you support more than one size of the long double type])
  82. HAVE_LONG_DOUBLE=1
  83. else
  84. if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
  85. HAVE_LONG_DOUBLE=1
  86. AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
  87. fi
  88. fi
  89. fi
  90. fi
  91. AC_SUBST(HAVE_LONG_DOUBLE)
  92. AC_SUBST(HAVE_LONG_DOUBLE_VARIANT)
  93. AC_C_BIGENDIAN
  94. GCC_AS_CFI_PSEUDO_OP
  95. case "$TARGET" in
  96. SPARC)
  97. AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
  98. libffi_cv_as_sparc_ua_pcrel, [
  99. save_CFLAGS="$CFLAGS"
  100. save_LDFLAGS="$LDFLAGS"
  101. CFLAGS="$CFLAGS -fpic"
  102. LDFLAGS="$LDFLAGS -shared"
  103. AC_TRY_LINK([asm (".text; foo: nop; .data; .align 4; .byte 0; .uaword %r_disp32(foo); .text");],,
  104. [libffi_cv_as_sparc_ua_pcrel=yes],
  105. [libffi_cv_as_sparc_ua_pcrel=no])
  106. CFLAGS="$save_CFLAGS"
  107. LDFLAGS="$save_LDFLAGS"])
  108. if test "x$libffi_cv_as_sparc_ua_pcrel" = xyes; then
  109. AC_DEFINE(HAVE_AS_SPARC_UA_PCREL, 1,
  110. [Define if your assembler and linker support unaligned PC relative relocs.])
  111. fi
  112. AC_CACHE_CHECK([assembler .register pseudo-op support],
  113. libffi_cv_as_register_pseudo_op, [
  114. libffi_cv_as_register_pseudo_op=unknown
  115. # Check if we have .register
  116. AC_TRY_COMPILE(,[asm (".register %g2, #scratch");],
  117. [libffi_cv_as_register_pseudo_op=yes],
  118. [libffi_cv_as_register_pseudo_op=no])
  119. ])
  120. if test "x$libffi_cv_as_register_pseudo_op" = xyes; then
  121. AC_DEFINE(HAVE_AS_REGISTER_PSEUDO_OP, 1,
  122. [Define if your assembler supports .register.])
  123. fi
  124. ;;
  125. X86*)
  126. AC_CACHE_CHECK([assembler supports pc related relocs],
  127. libffi_cv_as_x86_pcrel, [
  128. libffi_cv_as_x86_pcrel=no
  129. echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s
  130. if $CC $CFLAGS -c conftest.s > /dev/null 2>&1; then
  131. libffi_cv_as_x86_pcrel=yes
  132. fi
  133. ])
  134. if test "x$libffi_cv_as_x86_pcrel" = xyes; then
  135. AC_DEFINE(HAVE_AS_X86_PCREL, 1,
  136. [Define if your assembler supports PC relative relocs.])
  137. fi
  138. ;;
  139. S390)
  140. AC_CACHE_CHECK([compiler uses zarch features],
  141. libffi_cv_as_s390_zarch, [
  142. libffi_cv_as_s390_zarch=no
  143. echo 'void foo(void) { bar(); bar(); }' > conftest.c
  144. if $CC $CFLAGS -S conftest.c > /dev/null 2>&1; then
  145. if grep -q brasl conftest.s; then
  146. libffi_cv_as_s390_zarch=yes
  147. fi
  148. fi
  149. ])
  150. if test "x$libffi_cv_as_s390_zarch" = xyes; then
  151. AC_DEFINE(HAVE_AS_S390_ZARCH, 1,
  152. [Define if the compiler uses zarch features.])
  153. fi
  154. ;;
  155. esac
  156. AC_CACHE_CHECK([whether compiler supports pointer authentication],
  157. libffi_cv_as_ptrauth, [
  158. libffi_cv_as_ptrauth=unknown
  159. AC_TRY_COMPILE(,[
  160. #ifdef __clang__
  161. # if __has_feature(ptrauth_calls)
  162. # define HAVE_PTRAUTH 1
  163. # endif
  164. #endif
  165. #ifndef HAVE_PTRAUTH
  166. # error Pointer authentication not supported
  167. #endif
  168. ],
  169. [libffi_cv_as_ptrauth=yes],
  170. [libffi_cv_as_ptrauth=no])
  171. ])
  172. if test "x$libffi_cv_as_ptrauth" = xyes; then
  173. AC_DEFINE(HAVE_PTRAUTH, 1,
  174. [Define if your compiler supports pointer authentication.])
  175. fi
  176. # On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC.
  177. AC_ARG_ENABLE(pax_emutramp,
  178. [ --enable-pax_emutramp enable pax emulated trampolines, for we can't use PROT_EXEC],
  179. if test "$enable_pax_emutramp" = "yes"; then
  180. AC_DEFINE(FFI_MMAP_EXEC_EMUTRAMP_PAX, 1,
  181. [Define this if you want to enable pax emulated trampolines])
  182. fi)
  183. FFI_EXEC_TRAMPOLINE_TABLE=0
  184. case "$target" in
  185. *arm*-apple-* | aarch64-apple-*)
  186. FFI_EXEC_TRAMPOLINE_TABLE=1
  187. AC_DEFINE(FFI_EXEC_TRAMPOLINE_TABLE, 1,
  188. [Cannot use PROT_EXEC on this target, so, we revert to
  189. alternative means])
  190. ;;
  191. *-apple-* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris* | *-linux-android*)
  192. AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
  193. [Cannot use malloc on this target, so, we revert to
  194. alternative means])
  195. ;;
  196. esac
  197. AM_CONDITIONAL(FFI_EXEC_TRAMPOLINE_TABLE, test x$FFI_EXEC_TRAMPOLINE_TABLE = x1)
  198. AC_SUBST(FFI_EXEC_TRAMPOLINE_TABLE)
  199. if test x$TARGET = xX86_64; then
  200. AC_CACHE_CHECK([toolchain supports unwind section type],
  201. libffi_cv_as_x86_64_unwind_section_type, [
  202. cat > conftest1.s << EOF
  203. .text
  204. .globl foo
  205. foo:
  206. jmp bar
  207. .section .eh_frame,"a",@unwind
  208. bar:
  209. EOF
  210. cat > conftest2.c << EOF
  211. extern void foo();
  212. int main(){foo();}
  213. EOF
  214. libffi_cv_as_x86_64_unwind_section_type=no
  215. # we ensure that we can compile _and_ link an assembly file containing an @unwind section
  216. # since the compiler can support it and not the linker (ie old binutils)
  217. if $CC -Wa,--fatal-warnings $CFLAGS -c conftest1.s > /dev/null 2>&1 && \
  218. $CC conftest2.c conftest1.o > /dev/null 2>&1 ; then
  219. libffi_cv_as_x86_64_unwind_section_type=yes
  220. fi
  221. ])
  222. if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
  223. AC_DEFINE(HAVE_AS_X86_64_UNWIND_SECTION_TYPE, 1,
  224. [Define if your assembler supports unwind section type.])
  225. fi
  226. fi
  227. if test "x$GCC" = "xyes"; then
  228. AC_CACHE_CHECK([whether .eh_frame section should be read-only],
  229. libffi_cv_ro_eh_frame, [
  230. libffi_cv_ro_eh_frame=yes
  231. echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
  232. if $CC $CFLAGS -c -fpic -fexceptions -fno-lto -o conftest.o conftest.c > /dev/null 2>&1; then
  233. if $READELF -WS conftest.o | grep -q -n 'eh_frame .* WA'; then
  234. libffi_cv_ro_eh_frame=no
  235. fi
  236. fi
  237. rm -f conftest.*
  238. ])
  239. if test "x$libffi_cv_ro_eh_frame" = xyes; then
  240. AC_DEFINE(HAVE_RO_EH_FRAME, 1,
  241. [Define if .eh_frame sections should be read-only.])
  242. AC_DEFINE(EH_FRAME_FLAGS, "a",
  243. [Define to the flags needed for the .section .eh_frame directive. ])
  244. else
  245. AC_DEFINE(EH_FRAME_FLAGS, "aw",
  246. [Define to the flags needed for the .section .eh_frame directive. ])
  247. fi
  248. AC_CACHE_CHECK([for __attribute__((visibility("hidden")))],
  249. libffi_cv_hidden_visibility_attribute, [
  250. echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1 ; }' > conftest.c
  251. libffi_cv_hidden_visibility_attribute=no
  252. if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
  253. if egrep '(\.hidden|\.private_extern).*foo' conftest.s >/dev/null; then
  254. libffi_cv_hidden_visibility_attribute=yes
  255. fi
  256. fi
  257. rm -f conftest.*
  258. ])
  259. if test $libffi_cv_hidden_visibility_attribute = yes; then
  260. AC_DEFINE(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE, 1,
  261. [Define if __attribute__((visibility("hidden"))) is supported.])
  262. fi
  263. fi
  264. # See if makeinfo has been installed and is modern enough
  265. # that we can use it.
  266. ACX_CHECK_PROG_VER([MAKEINFO], [makeinfo], [--version],
  267. [GNU texinfo.* \([0-9][0-9.]*\)],
  268. [4.[4-9]*|4.[1-9][0-9]*|[5-9]*|[1-9][0-9]*])
  269. AM_CONDITIONAL(BUILD_DOCS, test $gcc_cv_prog_makeinfo_modern = "yes")
  270. AH_BOTTOM([
  271. #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
  272. #ifdef LIBFFI_ASM
  273. #ifdef __APPLE__
  274. #define FFI_HIDDEN(name) .private_extern name
  275. #else
  276. #define FFI_HIDDEN(name) .hidden name
  277. #endif
  278. #else
  279. #define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
  280. #endif
  281. #else
  282. #ifdef LIBFFI_ASM
  283. #define FFI_HIDDEN(name)
  284. #else
  285. #define FFI_HIDDEN
  286. #endif
  287. #endif
  288. ])
  289. AC_SUBST(TARGET)
  290. AC_SUBST(TARGETDIR)
  291. changequote(<,>)
  292. TARGET_OBJ=
  293. for i in $SOURCES; do
  294. TARGET_OBJ="${TARGET_OBJ} src/${TARGETDIR}/"`echo $i | sed 's/[cS]$/lo/'`
  295. done
  296. changequote([,])
  297. AC_SUBST(TARGET_OBJ)
  298. AC_SUBST(SHELL)
  299. AC_ARG_ENABLE(debug,
  300. [ --enable-debug debugging mode],
  301. if test "$enable_debug" = "yes"; then
  302. AC_DEFINE(FFI_DEBUG, 1, [Define this if you want extra debugging.])
  303. fi)
  304. AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
  305. AC_ARG_ENABLE(structs,
  306. [ --disable-structs omit code for struct support],
  307. if test "$enable_structs" = "no"; then
  308. AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this if you do not want support for aggregate types.])
  309. fi)
  310. AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
  311. AC_ARG_ENABLE(raw-api,
  312. [ --disable-raw-api make the raw api unavailable],
  313. if test "$enable_raw_api" = "no"; then
  314. AC_DEFINE(FFI_NO_RAW_API, 1, [Define this if you do not want support for the raw API.])
  315. fi)
  316. AC_ARG_ENABLE(exec-static-tramp,
  317. [ --enable-exec-static-tramp enable use of static exec trampolines])
  318. if test "$enable_exec_static_tramp" = yes; then
  319. case "$target" in
  320. *-cygwin*)
  321. ;;
  322. *arm*-*-linux-* | aarch64*-*-linux-* | i*86-*-linux-* | x86_64-*-linux-*)
  323. AC_DEFINE(FFI_EXEC_STATIC_TRAMP, 1,
  324. [Define this if you want statically defined trampolines])
  325. ;;
  326. esac
  327. fi
  328. AC_ARG_ENABLE(purify-safety,
  329. [ --enable-purify-safety purify-safe mode],
  330. if test "$enable_purify_safety" = "yes"; then
  331. AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
  332. fi)
  333. GCC_WITH_TOOLEXECLIBDIR
  334. if test -n "$with_cross_host" &&
  335. test x"$with_cross_host" != x"no"; then
  336. toolexecdir='$(exec_prefix)/$(target_alias)'
  337. case ${with_toolexeclibdir} in
  338. no)
  339. toolexeclibdir='$(toolexecdir)/lib'
  340. ;;
  341. *)
  342. toolexeclibdir=${with_toolexeclibdir}
  343. ;;
  344. esac
  345. else
  346. toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
  347. toolexeclibdir='$(libdir)'
  348. fi
  349. multi_os_directory=`$CC -print-multi-os-directory`
  350. case $multi_os_directory in
  351. .) ;; # Avoid trailing /.
  352. *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
  353. esac
  354. AC_SUBST(toolexecdir)
  355. AC_SUBST(toolexeclibdir)
  356. if test "${multilib}" = "yes"; then
  357. multilib_arg="--enable-multilib"
  358. else
  359. multilib_arg=
  360. fi
  361. # Check linker support.
  362. LIBFFI_ENABLE_SYMVERS
  363. # Determine what GCC version number to use in filesystem paths.
  364. GCC_BASE_VER
  365. AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
  366. AC_CONFIG_COMMANDS(src, [
  367. test -d src || mkdir src
  368. test -d src/$TARGETDIR || mkdir src/$TARGETDIR
  369. ], [TARGETDIR="$TARGETDIR"])
  370. AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc)
  371. AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h)
  372. AC_OUTPUT