configure.ac 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. # configure.ac -- Backtrace configure script.
  2. # Copyright (C) 2012-2015 Free Software Foundation, Inc.
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions are
  5. # met:
  6. # (1) Redistributions of source code must retain the above copyright
  7. # notice, this list of conditions and the following disclaimer.
  8. # (2) Redistributions in binary form must reproduce the above copyright
  9. # notice, this list of conditions and the following disclaimer in
  10. # the documentation and/or other materials provided with the
  11. # distribution.
  12. # (3) The name of the author may not be used to
  13. # endorse or promote products derived from this software without
  14. # specific prior written permission.
  15. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  19. # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  23. # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  24. # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. # POSSIBILITY OF SUCH DAMAGE.
  26. AC_PREREQ(2.64)
  27. AC_INIT(package-unused, version-unused,, libbacktrace)
  28. AC_CONFIG_SRCDIR(backtrace.h)
  29. AC_CONFIG_HEADER(config.h)
  30. if test -n "${with_target_subdir}"; then
  31. AM_ENABLE_MULTILIB(, ..)
  32. fi
  33. AC_CANONICAL_SYSTEM
  34. target_alias=${target_alias-$host_alias}
  35. AC_USE_SYSTEM_EXTENSIONS
  36. libtool_VERSION=1:0:0
  37. AC_SUBST(libtool_VERSION)
  38. # 1.11.1: Require that version of automake.
  39. # foreign: Don't require README, INSTALL, NEWS, etc.
  40. # no-define: Don't define PACKAGE and VERSION.
  41. # no-dependencies: Don't generate automatic dependencies.
  42. # (because it breaks when using bootstrap-lean, since some of the
  43. # headers are gone at "make install" time).
  44. # -Wall: Issue all automake warnings.
  45. # -Wno-portability: Don't warn about constructs supported by GNU make.
  46. # (because GCC requires GNU make anyhow).
  47. AM_INIT_AUTOMAKE([1.11.1 foreign no-dist no-define no-dependencies -Wall -Wno-portability])
  48. AM_MAINTAINER_MODE
  49. AC_ARG_WITH(target-subdir,
  50. [ --with-target-subdir=SUBDIR Configuring in a subdirectory for target])
  51. # We must force CC to /not/ be precious variables; otherwise
  52. # the wrong, non-multilib-adjusted value will be used in multilibs.
  53. # As a side effect, we have to subst CFLAGS ourselves.
  54. m4_rename([_AC_ARG_VAR_PRECIOUS],[backtrace_PRECIOUS])
  55. m4_define([_AC_ARG_VAR_PRECIOUS],[])
  56. AC_PROG_CC
  57. m4_rename_force([backtrace_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
  58. AC_SUBST(CFLAGS)
  59. AC_PROG_RANLIB
  60. AC_PROG_AWK
  61. case "$AWK" in
  62. "") AC_MSG_ERROR([can't build without awk]) ;;
  63. esac
  64. LT_INIT([disable-shared])
  65. AM_PROG_LIBTOOL
  66. backtrace_supported=yes
  67. if test -n "${with_target_subdir}"; then
  68. # We are compiling a GCC library. We can assume that the unwind
  69. # library exists.
  70. BACKTRACE_FILE="backtrace.lo simple.lo"
  71. else
  72. AC_CHECK_HEADER([unwind.h],
  73. [AC_CHECK_FUNC([_Unwind_Backtrace],
  74. [BACKTRACE_FILE="backtrace.lo simple.lo"],
  75. [BACKTRACE_FILE="nounwind.lo"
  76. backtrace_supported=no])],
  77. [BACKTRACE_FILE="nounwind.lo"
  78. backtrace_supported=no])
  79. fi
  80. AC_SUBST(BACKTRACE_FILE)
  81. EXTRA_FLAGS=
  82. if test -n "${with_target_subdir}"; then
  83. EXTRA_FLAGS="-funwind-tables -frandom-seed=\$@"
  84. else
  85. AC_CACHE_CHECK([for -funwind-tables option],
  86. [libbacktrace_cv_c_unwind_tables],
  87. [CFLAGS_hold="$CFLAGS"
  88. CFLAGS="$CFLAGS -funwind-tables"
  89. AC_COMPILE_IFELSE(
  90. [AC_LANG_PROGRAM([static int f() { return 0; }], [return f();])],
  91. [libbacktrace_cv_c_unwind_tables=yes],
  92. [libbacktrace_cv_c_unwind_tables=no])
  93. CFLAGS="$CFLAGS_hold"])
  94. if test "$libbacktrace_cv_c_unwind_tables" = "yes"; then
  95. EXTRA_FLAGS=-funwind-tables
  96. fi
  97. AC_CACHE_CHECK([for -frandom-seed=string option],
  98. [libbacktrace_cv_c_random_seed_string],
  99. [CFLAGS_hold="$CFLAGS"
  100. CFLAGS="$CFLAGS -frandom-seed=conftest.lo"
  101. AC_COMPILE_IFELSE(
  102. [AC_LANG_PROGRAM([], [return 0;])],
  103. [libbacktrace_cv_c_random_seed_string=yes],
  104. [libbacktrace_cv_c_random_seed_string=no])
  105. CFLAGS="$CFLAGS_hold"])
  106. if test "$libbacktrace_cv_c_random_seed_string" = "yes"; then
  107. EXTRA_FLAGS="$EXTRA_FLAGS -frandom-seed=\$@"
  108. fi
  109. fi
  110. AC_SUBST(EXTRA_FLAGS)
  111. ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wstrict-prototypes \
  112. -Wmissing-prototypes -Wold-style-definition \
  113. -Wmissing-format-attribute -Wcast-qual],
  114. [WARN_FLAGS])
  115. if test -n "${with_target_subdir}"; then
  116. WARN_FLAGS="$WARN_FLAGS -Werror"
  117. fi
  118. AC_SUBST(WARN_FLAGS)
  119. if test -n "${with_target_subdir}"; then
  120. GCC_CHECK_UNWIND_GETIPINFO
  121. else
  122. ac_save_CFFLAGS="$CFLAGS"
  123. CFLAGS="$CFLAGS -Werror-implicit-function-declaration"
  124. AC_MSG_CHECKING([for _Unwind_GetIPInfo])
  125. AC_LINK_IFELSE(
  126. [AC_LANG_PROGRAM(
  127. [#include "unwind.h"
  128. struct _Unwind_Context *context;
  129. int ip_before_insn = 0;],
  130. [return _Unwind_GetIPInfo (context, &ip_before_insn);])],
  131. [have_unwind_getipinfo=yes], [have_unwind_getipinfo=no])
  132. CFLAGS="$ac_save_CFLAGS"
  133. AC_MSG_RESULT([$have_unwind_getipinfo])
  134. if test "$have_unwind_getipinfo" = "yes"; then
  135. AC_DEFINE(HAVE_GETIPINFO, 1, [Define if _Unwind_GetIPInfo is available.])
  136. fi
  137. fi
  138. # When building as a target library, shared libraries may want to link
  139. # this in. We don't want to provide another shared library to
  140. # complicate dependencies. Instead, we just compile with -fPIC.
  141. PIC_FLAG=
  142. if test -n "${with_target_subdir}"; then
  143. PIC_FLAG=-fPIC
  144. fi
  145. # Similarly, use -fPIC with --enable-host-shared:
  146. AC_ARG_ENABLE(host-shared,
  147. [AS_HELP_STRING([--enable-host-shared],
  148. [build host code as shared libraries])],
  149. [PIC_FLAG=-fPIC], [])
  150. AC_SUBST(PIC_FLAG)
  151. # Test for __sync support.
  152. AC_CACHE_CHECK([__sync extensions],
  153. [libbacktrace_cv_sys_sync],
  154. [if test -n "${with_target_subdir}"; then
  155. libbacktrace_cv_sys_sync=yes
  156. else
  157. AC_LINK_IFELSE(
  158. [AC_LANG_PROGRAM([int i;],
  159. [__sync_bool_compare_and_swap (&i, i, i);
  160. __sync_lock_test_and_set (&i, 1);
  161. __sync_lock_release (&i);])],
  162. [libbacktrace_cv_sys_sync=yes],
  163. [libbacktrace_cv_sys_sync=no])
  164. fi])
  165. BACKTRACE_SUPPORTS_THREADS=0
  166. if test "$libbacktrace_cv_sys_sync" = "yes"; then
  167. BACKTRACE_SUPPORTS_THREADS=1
  168. AC_DEFINE([HAVE_SYNC_FUNCTIONS], 1,
  169. [Define to 1 if you have the __sync functions])
  170. fi
  171. AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
  172. # Test for __atomic support.
  173. AC_CACHE_CHECK([__atomic extensions],
  174. [libbacktrace_cv_sys_atomic],
  175. [if test -n "${with_target_subdir}"; then
  176. libbacktrace_cv_sys_atomic=yes
  177. else
  178. AC_LINK_IFELSE(
  179. [AC_LANG_PROGRAM([int i;],
  180. [__atomic_load_n (&i, __ATOMIC_ACQUIRE);
  181. __atomic_store_n (&i, 1, __ATOMIC_RELEASE);])],
  182. [libbacktrace_cv_sys_atomic=yes],
  183. [libbacktrace_cv_sys_atomic=no])
  184. fi])
  185. if test "$libbacktrace_cv_sys_atomic" = "yes"; then
  186. AC_DEFINE([HAVE_ATOMIC_FUNCTIONS], 1,
  187. [Define to 1 if you have the __atomic functions])
  188. fi
  189. # The library needs to be able to read the executable itself. Compile
  190. # a file to determine the executable format. The awk script
  191. # filetype.awk prints out the file type.
  192. AC_CACHE_CHECK([output filetype],
  193. [libbacktrace_cv_sys_filetype],
  194. [filetype=
  195. AC_COMPILE_IFELSE(
  196. [AC_LANG_PROGRAM([int i;], [int j;])],
  197. [filetype=`${AWK} -f $srcdir/filetype.awk conftest.$ac_objext`],
  198. [AC_MSG_FAILURE([compiler failed])])
  199. libbacktrace_cv_sys_filetype=$filetype])
  200. # Match the file type to decide what files to compile.
  201. FORMAT_FILE=
  202. case "$libbacktrace_cv_sys_filetype" in
  203. elf*) FORMAT_FILE="elf.lo" ;;
  204. *) AC_MSG_WARN([could not determine output file type])
  205. FORMAT_FILE="unknown.lo"
  206. backtrace_supported=no
  207. ;;
  208. esac
  209. AC_SUBST(FORMAT_FILE)
  210. # ELF defines.
  211. elfsize=
  212. case "$libbacktrace_cv_sys_filetype" in
  213. elf32) elfsize=32 ;;
  214. elf64) elfsize=64 ;;
  215. esac
  216. AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
  217. BACKTRACE_SUPPORTED=0
  218. if test "$backtrace_supported" = "yes"; then
  219. BACKTRACE_SUPPORTED=1
  220. fi
  221. AC_SUBST(BACKTRACE_SUPPORTED)
  222. GCC_HEADER_STDINT(gstdint.h)
  223. AC_CHECK_HEADERS(sys/mman.h)
  224. if test "$ac_cv_header_sys_mman_h" = "no"; then
  225. have_mmap=no
  226. else
  227. if test -n "${with_target_subdir}"; then
  228. # When built as a GCC target library, we can't do a link test. We
  229. # simply assume that if we have mman.h, we have mmap.
  230. have_mmap=yes
  231. else
  232. AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
  233. fi
  234. fi
  235. if test "$have_mmap" = "no"; then
  236. VIEW_FILE=read.lo
  237. ALLOC_FILE=alloc.lo
  238. else
  239. VIEW_FILE=mmapio.lo
  240. AC_PREPROC_IFELSE([
  241. #include <sys/mman.h>
  242. #if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
  243. #error no MAP_ANONYMOUS
  244. #endif
  245. ], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo])
  246. fi
  247. AC_SUBST(VIEW_FILE)
  248. AC_SUBST(ALLOC_FILE)
  249. BACKTRACE_USES_MALLOC=0
  250. if test "$ALLOC_FILE" = "alloc.lo"; then
  251. BACKTRACE_USES_MALLOC=1
  252. fi
  253. AC_SUBST(BACKTRACE_USES_MALLOC)
  254. # Check for dl_iterate_phdr.
  255. AC_CHECK_HEADERS(link.h)
  256. if test "$ac_cv_header_link_h" = "no"; then
  257. have_dl_iterate_phdr=no
  258. else
  259. if test -n "${with_target_subdir}"; then
  260. # When built as a GCC target library, we can't do a link test.
  261. AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes],
  262. [have_dl_iterate_phdr=no])
  263. case "${host}" in
  264. *-*-solaris2.10*)
  265. # Avoid dl_iterate_phdr on Solaris 10, where it is in the
  266. # header file but is only in -ldl.
  267. have_dl_iterate_phdr=no ;;
  268. esac
  269. else
  270. AC_CHECK_FUNC([dl_iterate_phdr], [have_dl_iterate_phdr=yes],
  271. [have_dl_iterate_phdr=no])
  272. fi
  273. fi
  274. if test "$have_dl_iterate_phdr" = "yes"; then
  275. AC_DEFINE(HAVE_DL_ITERATE_PHDR, 1, [Define if dl_iterate_phdr is available.])
  276. fi
  277. # Check for the fcntl function.
  278. if test -n "${with_target_subdir}"; then
  279. case "${host}" in
  280. *-*-mingw*) have_fcntl=no ;;
  281. *) have_fcntl=yes ;;
  282. esac
  283. else
  284. AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
  285. fi
  286. if test "$have_fcntl" = "yes"; then
  287. AC_DEFINE([HAVE_FCNTL], 1,
  288. [Define to 1 if you have the fcntl function])
  289. fi
  290. AC_CHECK_DECLS(strnlen)
  291. # Check for getexecname function.
  292. if test -n "${with_target_subdir}"; then
  293. case "${host}" in
  294. *-*-solaris2*) have_getexecname=yes ;;
  295. *) have_getexecname=no ;;
  296. esac
  297. else
  298. AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
  299. fi
  300. if test "$have_getexecname" = "yes"; then
  301. AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
  302. fi
  303. AC_CACHE_CHECK([whether tests can run],
  304. [libbacktrace_cv_sys_native],
  305. [AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
  306. [libbacktrace_cv_sys_native=yes],
  307. [libbacktrace_cv_sys_native=no],
  308. [libbacktrace_cv_sys_native=no])])
  309. AM_CONDITIONAL(NATIVE, test "$libbacktrace_cv_sys_native" = "yes")
  310. if test "${multilib}" = "yes"; then
  311. multilib_arg="--enable-multilib"
  312. else
  313. multilib_arg=
  314. fi
  315. AC_CONFIG_FILES(Makefile backtrace-supported.h)
  316. # We need multilib support, but only if configuring for the target.
  317. AC_CONFIG_COMMANDS([default],
  318. [if test -n "$CONFIG_FILES"; then
  319. if test -n "${with_target_subdir}"; then
  320. # Multilibs need MULTISUBDIR defined correctly in certain makefiles so
  321. # that multilib installs will end up installed in the correct place.
  322. # The testsuite needs it for multilib-aware ABI baseline files.
  323. # To work around this not being passed down from config-ml.in ->
  324. # srcdir/Makefile.am -> srcdir/{src,libsupc++,...}/Makefile.am, manually
  325. # append it here. Only modify Makefiles that have just been created.
  326. #
  327. # Also, get rid of this simulated-VPATH thing that automake does.
  328. cat > vpsed << \_EOF
  329. s!`test -f '$<' || echo '$(srcdir)/'`!!
  330. _EOF
  331. for i in $SUBDIRS; do
  332. case $CONFIG_FILES in
  333. *${i}/Makefile*)
  334. #echo "Adding MULTISUBDIR to $i/Makefile"
  335. sed -f vpsed $i/Makefile > tmp
  336. grep '^MULTISUBDIR =' Makefile >> tmp
  337. mv tmp $i/Makefile
  338. ;;
  339. esac
  340. done
  341. rm vpsed
  342. fi
  343. fi
  344. ],
  345. [
  346. # Variables needed in config.status (file generation) which aren't already
  347. # passed by autoconf.
  348. SUBDIRS="$SUBDIRS"
  349. ])
  350. AC_OUTPUT