configure.ac 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. dnl Process this with autoconf to create configure
  2. AC_PREREQ(2.64)
  3. AC_INIT([libffi], [3.99999], [http://github.com/atgreen/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. # See if makeinfo has been installed and is modern enough
  10. # that we can use it.
  11. ACX_CHECK_PROG_VER([MAKEINFO], [makeinfo], [--version],
  12. [GNU texinfo.* \([0-9][0-9.]*\)],
  13. [4.[4-9]*|4.[1-9][0-9]*|[5-9]*|[1-9][0-9]*])
  14. AM_CONDITIONAL(BUILD_INFO, test $gcc_cv_prog_makeinfo_modern = "yes")
  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)
  32. # The same as in boehm-gc and libstdc++. Have to borrow it from there.
  33. # We must force CC to /not/ be precious variables; otherwise
  34. # the wrong, non-multilib-adjusted value will be used in multilibs.
  35. # As a side effect, we have to subst CFLAGS ourselves.
  36. # Also save and restore CFLAGS, since AC_PROG_CC will come up with
  37. # defaults of its own if none are provided.
  38. m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
  39. m4_define([_AC_ARG_VAR_PRECIOUS],[])
  40. save_CFLAGS=$CFLAGS
  41. AC_PROG_CC
  42. AC_PROG_CXX
  43. CFLAGS=$save_CFLAGS
  44. m4_undefine([_AC_ARG_VAR_PRECIOUS])
  45. m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
  46. AC_SUBST(CFLAGS)
  47. AM_PROG_AS
  48. AM_PROG_CC_C_O
  49. AC_PROG_LIBTOOL
  50. # Test for 64-bit build.
  51. AC_CHECK_SIZEOF([size_t])
  52. AM_MAINTAINER_MODE
  53. AC_CHECK_HEADERS(sys/mman.h)
  54. AC_CHECK_FUNCS([mmap mkostemp])
  55. AC_FUNC_MMAP_BLACKLIST
  56. dnl The -no-testsuite modules omit the test subdir.
  57. AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
  58. TARGETDIR="unknown"
  59. HAVE_LONG_DOUBLE_VARIANT=0
  60. . ${srcdir}/configure.host
  61. if test -n "${UNSUPPORTED}"; then
  62. AC_MSG_ERROR(["libffi has not been ported to $host."])
  63. fi
  64. AC_SUBST(AM_RUNTESTFLAGS)
  65. AC_SUBST(AM_LTLDFLAGS)
  66. AC_HEADER_STDC
  67. AC_CHECK_FUNCS(memcpy)
  68. AC_FUNC_ALLOCA
  69. AC_CHECK_SIZEOF(double)
  70. AC_CHECK_SIZEOF(long double)
  71. # Also AC_SUBST this variable for ffi.h.
  72. if test -z "$HAVE_LONG_DOUBLE"; then
  73. HAVE_LONG_DOUBLE=0
  74. if test $ac_cv_sizeof_long_double != 0; then
  75. if test $HAVE_LONG_DOUBLE_VARIANT != 0; then
  76. AC_DEFINE(HAVE_LONG_DOUBLE_VARIANT, 1, [Define if you support more than one size of the long double type])
  77. HAVE_LONG_DOUBLE=1
  78. else
  79. if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
  80. HAVE_LONG_DOUBLE=1
  81. AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
  82. fi
  83. fi
  84. fi
  85. fi
  86. AC_SUBST(HAVE_LONG_DOUBLE)
  87. AC_SUBST(HAVE_LONG_DOUBLE_VARIANT)
  88. AC_C_BIGENDIAN
  89. GCC_AS_CFI_PSEUDO_OP
  90. case "$TARGET" in
  91. SPARC)
  92. AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
  93. libffi_cv_as_sparc_ua_pcrel, [
  94. save_CFLAGS="$CFLAGS"
  95. save_LDFLAGS="$LDFLAGS"
  96. CFLAGS="$CFLAGS -fpic"
  97. LDFLAGS="$LDFLAGS -shared"
  98. AC_TRY_LINK([asm (".text; foo: nop; .data; .align 4; .byte 0; .uaword %r_disp32(foo); .text");],,
  99. [libffi_cv_as_sparc_ua_pcrel=yes],
  100. [libffi_cv_as_sparc_ua_pcrel=no])
  101. CFLAGS="$save_CFLAGS"
  102. LDFLAGS="$save_LDFLAGS"])
  103. if test "x$libffi_cv_as_sparc_ua_pcrel" = xyes; then
  104. AC_DEFINE(HAVE_AS_SPARC_UA_PCREL, 1,
  105. [Define if your assembler and linker support unaligned PC relative relocs.])
  106. fi
  107. AC_CACHE_CHECK([assembler .register pseudo-op support],
  108. libffi_cv_as_register_pseudo_op, [
  109. libffi_cv_as_register_pseudo_op=unknown
  110. # Check if we have .register
  111. AC_TRY_COMPILE(,[asm (".register %g2, #scratch");],
  112. [libffi_cv_as_register_pseudo_op=yes],
  113. [libffi_cv_as_register_pseudo_op=no])
  114. ])
  115. if test "x$libffi_cv_as_register_pseudo_op" = xyes; then
  116. AC_DEFINE(HAVE_AS_REGISTER_PSEUDO_OP, 1,
  117. [Define if your assembler supports .register.])
  118. fi
  119. ;;
  120. X86*)
  121. AC_CACHE_CHECK([assembler supports pc related relocs],
  122. libffi_cv_as_x86_pcrel, [
  123. libffi_cv_as_x86_pcrel=no
  124. echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s
  125. if $CC $CFLAGS -c conftest.s > /dev/null 2>&1; then
  126. libffi_cv_as_x86_pcrel=yes
  127. fi
  128. ])
  129. if test "x$libffi_cv_as_x86_pcrel" = xyes; then
  130. AC_DEFINE(HAVE_AS_X86_PCREL, 1,
  131. [Define if your assembler supports PC relative relocs.])
  132. fi
  133. ;;
  134. S390)
  135. AC_CACHE_CHECK([compiler uses zarch features],
  136. libffi_cv_as_s390_zarch, [
  137. libffi_cv_as_s390_zarch=no
  138. echo 'void foo(void) { bar(); bar(); }' > conftest.c
  139. if $CC $CFLAGS -S conftest.c > /dev/null 2>&1; then
  140. if grep -q brasl conftest.s; then
  141. libffi_cv_as_s390_zarch=yes
  142. fi
  143. fi
  144. ])
  145. if test "x$libffi_cv_as_s390_zarch" = xyes; then
  146. AC_DEFINE(HAVE_AS_S390_ZARCH, 1,
  147. [Define if the compiler uses zarch features.])
  148. fi
  149. ;;
  150. esac
  151. # On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC.
  152. AC_ARG_ENABLE(pax_emutramp,
  153. [ --enable-pax_emutramp enable pax emulated trampolines, for we can't use PROT_EXEC],
  154. if test "$enable_pax_emutramp" = "yes"; then
  155. AC_DEFINE(FFI_MMAP_EXEC_EMUTRAMP_PAX, 1,
  156. [Define this if you want to enable pax emulated trampolines])
  157. fi)
  158. FFI_EXEC_TRAMPOLINE_TABLE=0
  159. case "$target" in
  160. *arm*-apple-darwin* | aarch64-apple-darwin*)
  161. FFI_EXEC_TRAMPOLINE_TABLE=1
  162. AC_DEFINE(FFI_EXEC_TRAMPOLINE_TABLE, 1,
  163. [Cannot use PROT_EXEC on this target, so, we revert to
  164. alternative means])
  165. ;;
  166. *-apple-darwin1* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris*)
  167. AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
  168. [Cannot use malloc on this target, so, we revert to
  169. alternative means])
  170. ;;
  171. esac
  172. AM_CONDITIONAL(FFI_EXEC_TRAMPOLINE_TABLE, test x$FFI_EXEC_TRAMPOLINE_TABLE = x1)
  173. AC_SUBST(FFI_EXEC_TRAMPOLINE_TABLE)
  174. if test x$TARGET = xX86_64; then
  175. AC_CACHE_CHECK([toolchain supports unwind section type],
  176. libffi_cv_as_x86_64_unwind_section_type, [
  177. cat > conftest1.s << EOF
  178. .text
  179. .globl foo
  180. foo:
  181. jmp bar
  182. .section .eh_frame,"a",@unwind
  183. bar:
  184. EOF
  185. cat > conftest2.c << EOF
  186. extern void foo();
  187. int main(){foo();}
  188. EOF
  189. libffi_cv_as_x86_64_unwind_section_type=no
  190. # we ensure that we can compile _and_ link an assembly file containing an @unwind section
  191. # since the compiler can support it and not the linker (ie old binutils)
  192. if $CC -Wa,--fatal-warnings $CFLAGS -c conftest1.s > /dev/null 2>&1 && \
  193. $CC conftest2.c conftest1.o > /dev/null 2>&1 ; then
  194. libffi_cv_as_x86_64_unwind_section_type=yes
  195. fi
  196. ])
  197. if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
  198. AC_DEFINE(HAVE_AS_X86_64_UNWIND_SECTION_TYPE, 1,
  199. [Define if your assembler supports unwind section type.])
  200. fi
  201. fi
  202. if test "x$GCC" = "xyes"; then
  203. AC_CACHE_CHECK([whether .eh_frame section should be read-only],
  204. libffi_cv_ro_eh_frame, [
  205. libffi_cv_ro_eh_frame=no
  206. echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
  207. if $CC $CFLAGS -c -fpic -fexceptions -o conftest.o conftest.c > /dev/null 2>&1; then
  208. objdump -h conftest.o > conftest.dump 2>&1
  209. libffi_eh_frame_line=`grep -n eh_frame conftest.dump | cut -d: -f 1`
  210. if test "x$libffi_eh_frame_line" != "x"; then
  211. libffi_test_line=`expr $libffi_eh_frame_line + 1`p
  212. sed -n $libffi_test_line conftest.dump > conftest.line
  213. if grep READONLY conftest.line > /dev/null; then
  214. libffi_cv_ro_eh_frame=yes
  215. fi
  216. fi
  217. fi
  218. rm -f conftest.*
  219. ])
  220. if test "x$libffi_cv_ro_eh_frame" = xyes; then
  221. AC_DEFINE(HAVE_RO_EH_FRAME, 1,
  222. [Define if .eh_frame sections should be read-only.])
  223. AC_DEFINE(EH_FRAME_FLAGS, "a",
  224. [Define to the flags needed for the .section .eh_frame directive. ])
  225. else
  226. AC_DEFINE(EH_FRAME_FLAGS, "aw",
  227. [Define to the flags needed for the .section .eh_frame directive. ])
  228. fi
  229. AC_CACHE_CHECK([for __attribute__((visibility("hidden")))],
  230. libffi_cv_hidden_visibility_attribute, [
  231. echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1 ; }' > conftest.c
  232. libffi_cv_hidden_visibility_attribute=no
  233. if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
  234. if grep '\.hidden.*foo' conftest.s >/dev/null; then
  235. libffi_cv_hidden_visibility_attribute=yes
  236. fi
  237. fi
  238. rm -f conftest.*
  239. ])
  240. if test $libffi_cv_hidden_visibility_attribute = yes; then
  241. AC_DEFINE(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE, 1,
  242. [Define if __attribute__((visibility("hidden"))) is supported.])
  243. fi
  244. fi
  245. AH_BOTTOM([
  246. #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
  247. #ifdef LIBFFI_ASM
  248. #define FFI_HIDDEN(name) .hidden name
  249. #else
  250. #define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
  251. #endif
  252. #else
  253. #ifdef LIBFFI_ASM
  254. #define FFI_HIDDEN(name)
  255. #else
  256. #define FFI_HIDDEN
  257. #endif
  258. #endif
  259. ])
  260. AC_SUBST(TARGET)
  261. AC_SUBST(TARGETDIR)
  262. changequote(<,>)
  263. TARGET_OBJ=
  264. for i in $SOURCES; do
  265. TARGET_OBJ="${TARGET_OBJ} src/${TARGETDIR}/"`echo $i | sed 's/[cS]$/lo/'`
  266. done
  267. changequote([,])
  268. AC_SUBST(TARGET_OBJ)
  269. AC_SUBST(SHELL)
  270. AC_ARG_ENABLE(debug,
  271. [ --enable-debug debugging mode],
  272. if test "$enable_debug" = "yes"; then
  273. AC_DEFINE(FFI_DEBUG, 1, [Define this if you want extra debugging.])
  274. fi)
  275. AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
  276. AC_ARG_ENABLE(structs,
  277. [ --disable-structs omit code for struct support],
  278. if test "$enable_structs" = "no"; then
  279. AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this if you do not want support for aggregate types.])
  280. fi)
  281. AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
  282. AC_ARG_ENABLE(raw-api,
  283. [ --disable-raw-api make the raw api unavailable],
  284. if test "$enable_raw_api" = "no"; then
  285. AC_DEFINE(FFI_NO_RAW_API, 1, [Define this if you do not want support for the raw API.])
  286. fi)
  287. AC_ARG_ENABLE(purify-safety,
  288. [ --enable-purify-safety purify-safe mode],
  289. if test "$enable_purify_safety" = "yes"; then
  290. AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
  291. fi)
  292. if test -n "$with_cross_host" &&
  293. test x"$with_cross_host" != x"no"; then
  294. toolexecdir='$(exec_prefix)/$(target_alias)'
  295. toolexeclibdir='$(toolexecdir)/lib'
  296. else
  297. toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
  298. toolexeclibdir='$(libdir)'
  299. fi
  300. multi_os_directory=`$CC -print-multi-os-directory`
  301. case $multi_os_directory in
  302. .) ;; # Avoid trailing /.
  303. *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
  304. esac
  305. AC_SUBST(toolexecdir)
  306. AC_SUBST(toolexeclibdir)
  307. if test "${multilib}" = "yes"; then
  308. multilib_arg="--enable-multilib"
  309. else
  310. multilib_arg=
  311. fi
  312. AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
  313. AC_CONFIG_COMMANDS(src, [
  314. test -d src || mkdir src
  315. test -d src/$TARGETDIR || mkdir src/$TARGETDIR
  316. ], [TARGETDIR="$TARGETDIR"])
  317. AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h)
  318. AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc)
  319. AC_OUTPUT