configure.ac 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. dnl -*- Autoconf -*-
  2. dnl Process this file with autoconf to produce a configure script.
  3. dnl
  4. dnl Copyright (C) 2019-2022 Free Software Foundation, Inc.
  5. dnl
  6. dnl This file is free software; you can redistribute it and/or modify
  7. dnl it under the terms of the GNU General Public License as published by
  8. dnl the Free Software Foundation; either version 2 of the License, or
  9. dnl (at your option) any later version.
  10. dnl
  11. dnl This program is distributed in the hope that it will be useful,
  12. dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. dnl GNU General Public License for more details.
  15. dnl
  16. dnl You should have received a copy of the GNU General Public License
  17. dnl along with this program; see the file COPYING. If not see
  18. dnl <http://www.gnu.org/licenses/>.
  19. dnl
  20. AC_PREREQ(2.64)
  21. AC_INIT([libctf], 1.2.0)
  22. AC_CONFIG_SRCDIR(ctf-impl.h)
  23. AC_CONFIG_MACRO_DIR(..)
  24. AC_CONFIG_MACRO_DIR(../config)
  25. AC_CONFIG_MACRO_DIR(../bfd)
  26. AC_CANONICAL_BUILD
  27. AC_CANONICAL_HOST
  28. AC_CANONICAL_TARGET
  29. AC_USE_SYSTEM_EXTENSIONS
  30. AM_INIT_AUTOMAKE
  31. AM_SILENT_RULES([yes])
  32. # Checks for programs.
  33. AC_PROG_MAKE_SET
  34. AC_PROG_CC
  35. AC_PROG_RANLIB
  36. AM_PROG_AR
  37. ZW_GNU_GETTEXT_SISTER_DIR
  38. dnl Default to a non shared library. This may be overridden by the
  39. dnl configure option --enable-shared.
  40. AC_DISABLE_SHARED
  41. LT_INIT
  42. AC_SYS_LARGEFILE
  43. MISSING=`cd $ac_aux_dir && ${PWDCMD-pwd}`/missing
  44. AC_CHECK_PROGS([ACLOCAL], [aclocal], [$MISSING aclocal])
  45. AC_CHECK_PROGS([AUTOCONF], [autoconf], [$MISSING autoconf])
  46. AC_CHECK_PROGS([AUTOHEADER], [autoheader], [$MISSING autoheader])
  47. # Figure out what compiler warnings we can enable.
  48. # See config/warnings.m4 for details.
  49. ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wno-narrowing -Wwrite-strings \
  50. -Wmissing-format-attribute], [warn])
  51. ACX_PROG_CC_WARNING_OPTS([-Wstrict-prototypes -Wmissing-prototypes \
  52. -Wold-style-definition], [c_warn])
  53. ACX_PROG_CC_WARNING_ALMOST_PEDANTIC([-Wno-long-long])
  54. # Only enable with --enable-werror-always until existing warnings are
  55. # corrected.
  56. ACX_PROG_CC_WARNINGS_ARE_ERRORS([manual])
  57. AM_MAINTAINER_MODE
  58. AM_INSTALL_LIBBFD
  59. ACX_PROG_CC_WARNING_OPTS([-Wall], [ac_libctf_warn_cflags])
  60. AC_FUNC_MMAP
  61. # Needed for BFD capability checks.
  62. AC_SEARCH_LIBS(dlsym, dl)
  63. AM_ZLIB
  64. GCC_ENABLE([libctf-hash-debugging], [no], [], [Enable expensive debugging of CTF deduplication type hashing])
  65. if test "${enable_libctf_hash_debugging}" = yes; then
  66. AC_DEFINE(ENABLE_LIBCTF_HASH_DEBUGGING, 1, [Enable expensive debugging of CTF deduplication type hashing])
  67. fi
  68. AM_CONDITIONAL(ENABLE_LIBCTF_HASH_DEBUGGING, test "${enable_libctf_hash_debugging}" = yes)
  69. # Similar to GDB_AC_CHECK_BFD.
  70. OLD_CFLAGS=$CFLAGS
  71. OLD_LDFLAGS=$LDFLAGS
  72. OLD_LIBS=$LIBS
  73. # Put the old CFLAGS/LDFLAGS last, in case the user's (C|LD)FLAGS
  74. # points somewhere with bfd, with -I/foo/lib and -L/foo/lib. We
  75. # always want our bfd.
  76. CFLAGS="-I${srcdir}/../include -I../bfd -I${srcdir}/../bfd $CFLAGS"
  77. ZLIBDIR=`echo $zlibdir | sed 's,\$(top_builddir)/,,g'`
  78. LDFLAGS="-L../bfd -L../libiberty $ZLIBDIR $LDFLAGS"
  79. intl=`echo $LIBINTL | sed 's,${top_builddir}/,,g'`
  80. LIBS="-lbfd -liberty -lz $intl $LIBS"
  81. AC_CACHE_CHECK([for ELF support in BFD], ac_cv_libctf_bfd_elf,
  82. [AC_TRY_LINK([#include <stdlib.h>
  83. #include <string.h>
  84. #include "bfd.h"
  85. #include "elf-bfd.h"],
  86. [(void) bfd_section_from_elf_index (NULL, 0);
  87. return 0;],
  88. [ac_cv_libctf_bfd_elf=yes],
  89. [ac_cv_libctf_bfd_elf=no])])
  90. CFLAGS=$OLD_CFLAGS
  91. LDFLAGS=$OLD_LDFLAGS
  92. LIBS=$OLD_LIBS
  93. if test $ac_cv_libctf_bfd_elf = yes; then
  94. AC_DEFINE([HAVE_BFD_ELF], 1,
  95. [Whether libbfd was configured for an ELF target.])
  96. fi
  97. AC_C_BIGENDIAN
  98. AC_CHECK_HEADERS(byteswap.h endian.h)
  99. AC_CHECK_FUNCS(pread)
  100. dnl Check for bswap_{16,32,64}
  101. AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64], [], [], [[#include <byteswap.h>]])
  102. AC_CHECK_DECLS([asprintf, vasprintf, stpcpy])
  103. dnl Check for qsort_r. (Taken from gnulib.)
  104. AC_CHECK_FUNCS_ONCE([qsort_r])
  105. if test $ac_cv_func_qsort_r = yes; then
  106. AC_CACHE_CHECK([for qsort_r signature], [ac_cv_libctf_qsort_r_signature],
  107. [AC_LINK_IFELSE(
  108. [AC_LANG_PROGRAM([[#undef qsort_r
  109. #include <stdlib.h>
  110. void qsort_r (void *, size_t, size_t,
  111. int (*) (void const *, void const *,
  112. void *),
  113. void *);
  114. void (*p) (void *, size_t, size_t,
  115. int (*) (void const *, void const *,
  116. void *),
  117. void *) = qsort_r;
  118. ]])],
  119. [ac_cv_libctf_qsort_r_signature=GNU],
  120. [AC_LINK_IFELSE(
  121. [AC_LANG_PROGRAM([[#undef qsort_r
  122. #include <stdlib.h>
  123. void qsort_r (void *, size_t, size_t, void *,
  124. int (*) (void *,
  125. void const *,
  126. void const *));
  127. void (*p) (void *, size_t, size_t, void *,
  128. int (*) (void *, void const *,
  129. void const *)) = qsort_r;
  130. ]])],
  131. [ac_cv_libctf_qsort_r_signature=BSD],
  132. [ac_cv_libctf_qsort_r_signature=unknown])])])
  133. fi
  134. case x$ac_cv_libctf_qsort_r_signature in
  135. xGNU) AC_DEFINE([HAVE_QSORT_R_ARG_LAST], 1,
  136. [Whether a qsort_r exists with a void *arg as its last arg.]);;
  137. xBSD) AC_DEFINE([HAVE_QSORT_R_COMPAR_LAST], 1,
  138. [Whether a qsort_r exists with the compar function as its last arg.]);;
  139. *) ac_cv_libctf_qsort_r_signature=unknown;;
  140. esac
  141. AM_CONDITIONAL(NEED_CTF_QSORT_R, test "${ac_cv_libctf_qsort_r_signature}" = unknown)
  142. AC_CACHE_CHECK([for O_CLOEXEC], [ac_cv_libctf_macro_O_CLOEXEC],
  143. [AC_LINK_IFELSE(
  144. [AC_LANG_PROGRAM([[#include <fcntl.h>
  145. #ifndef O_CLOEXEC
  146. choke me;
  147. #endif
  148. ]],
  149. [[return O_CLOEXEC;]])],
  150. [ac_cv_libctf_macro_O_CLOEXEC=yes],
  151. [ac_cv_libctf_macro_O_CLOEXEC=no])])
  152. if test $ac_cv_libctf_macro_O_CLOEXEC = yes; then
  153. AC_DEFINE([HAVE_O_CLOEXEC], 1,
  154. [Whether the platform has a definition of O_CLOEXEC.])
  155. fi
  156. build_info=
  157. makeinfo_too_old=
  158. AC_CHECK_PROGS([MAKEINFO], makeinfo, [$MISSING makeinfo])
  159. case " $build_configdirs " in
  160. *" texinfo "*) MAKEINFO='$$r/$(BUILD_SUBDIR)/texinfo/makeinfo/makeinfo' ;;
  161. esac
  162. changequote(,)
  163. # We require texinfo to be 6.3 or later, for a working synindex
  164. # and validatemenus: otherwise we fall back to /bin/true.
  165. if ${MAKEINFO} --version \
  166. | egrep 'texinfo[^0-9]*(6\.[3-9]|[7-9][0-9])' >/dev/null 2>&1; then
  167. build_info=yes
  168. else
  169. build_info=
  170. makeinfo_too_old=t
  171. fi
  172. changequote([,])
  173. if test -n "$makeinfo_too_old"; then
  174. AC_MSG_WARN([
  175. *** Makeinfo is too old. Info documentation will not be built.])
  176. fi
  177. AC_SUBST(MAKEINFO)
  178. AM_CONDITIONAL(BUILD_INFO, test "${build_info}" = yes)
  179. CTF_LIBADD="-L`pwd`/../libiberty -liberty"
  180. SHARED_LDFLAGS=
  181. # Horrible hacks to build DLLs on Windows and a shared library elsewhere.
  182. if test "$enable_shared" = "yes"; then
  183. # When building a shared libctf, link against the pic version of libiberty
  184. # so that apps that use libctf won't need libiberty just to satisfy any
  185. # libctf references. We can't do that if a pic libiberty is unavailable
  186. # since including non-pic # code would insert text relocations into libctf.
  187. # Note that linking against libbfd as we do here, which is itself linked
  188. # against libiberty, may not satisfy all the libctf libiberty references
  189. # since libbfd may not pull in the entirety of libiberty.
  190. # Also, jam libintl into the right place in all of this: after libiberty,
  191. # which uses it, but before -lcygwin, which it uses.
  192. changequote(,)dnl
  193. x=`sed -n -e 's/^[ ]*PICFLAG[ ]*=[ ]*//p' < ../libiberty/Makefile | sed -n '$p'`
  194. changequote([,])dnl
  195. if test -n "$x"; then
  196. CTF_LIBADD="-L`pwd`/../libiberty/pic -liberty"
  197. fi
  198. fi
  199. CTF_LIBADD="$CTF_LIBADD $LIBINTL"
  200. if test "$enable_shared" = "yes"; then
  201. case "${host}" in
  202. # More hacks to build DLLs on Windows.
  203. *-*-cygwin*)
  204. SHARED_LDFLAGS="-no-undefined"
  205. CTF_LIBADD="$CTF_LIBADD -lcygwin"
  206. ;;
  207. esac
  208. fi
  209. AC_SUBST(SHARED_LDFLAGS)
  210. AC_SUBST(CTF_LIBADD)
  211. AC_PATH_PROG([EXPECT], [expect])
  212. AC_CACHE_CHECK([for Tcl supporting try/catch], [ac_cv_libctf_tcl_try],
  213. [ac_cv_libctf_tcl_try=`if test -z $EXPECT; then echo no; else $EXPECT << EOF
  214. if @<:@llength @<:@info commands try@:>@@:>@ then { puts yes } else { puts no }
  215. EOF
  216. fi`
  217. ])
  218. AM_CONDITIONAL(TCL_TRY, test "${ac_cv_libctf_tcl_try}" = yes)
  219. # Use a version script, if possible, or an -export-symbols-regex otherwise.
  220. decommented_version_script=
  221. AC_CACHE_CHECK([for linker versioning flags], [ac_cv_libctf_version_script],
  222. [echo 'FOO { global: mai*; local: ctf_fo*; };' > conftest.ver
  223. old_LDFLAGS="$LDFLAGS"
  224. old_CFLAGS="$CFLAGS"
  225. LDFLAGS="$LDFLAGS -shared -Wl,--version-script=conftest.ver"
  226. CFLAGS="$CFLAGS -fPIC"
  227. AC_LINK_IFELSE([AC_LANG_SOURCE([[int ctf_foo (void) { return 0; }
  228. int main (void) { return ctf_foo(); }]])],
  229. [ac_cv_libctf_version_script="-Wl,--version-script='$srcdir/libctf.ver'"],
  230. [])
  231. LDFLAGS="$old_LDFLAGS"
  232. if test -z "$ac_cv_libctf_version_script"; then
  233. LDFLAGS="$LDFLAGS -shared -Wl,-B,local -Wl,-z,gnu-version-script=conftest.ver"
  234. AC_LINK_IFELSE([AC_LANG_SOURCE([[int ctf_foo (void) { return 0; }
  235. int main (void) { return ctf_foo(); }]])],
  236. [ac_cv_libctf_version_script="-Wl,-B,local -Wl,-z,gnu-version-script"
  237. decommented_version_script=t],
  238. [])
  239. LDFLAGS="$old_LDFLAGS"
  240. fi
  241. CFLAGS="$old_CFLAGS"
  242. if test -z "$ac_cv_libctf_version_script"; then
  243. ac_cv_libctf_version_script='-export-symbols-regex ctf_.*'
  244. fi
  245. rm -f conftest.ver])
  246. if test -n "$decommented_version_script"; then
  247. # Solaris's version scripts use shell-style comments rather than the C-style
  248. # used by GNU ld. Use cpp to strip the comments out. (cpp exists under this
  249. # name on all platforms that support ld -z gnu-version-script.)
  250. # Also ensure that no symbols exist in the version script for libctf-nobfd.so
  251. # that do not exist in the shared library itself, since some linkers add such
  252. # symbols with type NOTYPE.
  253. /lib/cpp < $srcdir/libctf.ver > libctf-decommented.ver
  254. grep -v 'libctf only' $srcdir/libctf.ver | /lib/cpp > libctf-nobfd-decommented.ver
  255. VERSION_FLAGS="$ac_cv_libctf_version_script='libctf-decommented.ver'"
  256. VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script='libctf-nobfd-decommented.ver'"
  257. else
  258. VERSION_FLAGS="$ac_cv_libctf_version_script"
  259. VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script"
  260. fi
  261. AC_SUBST(VERSION_FLAGS)
  262. AC_SUBST(VERSION_FLAGS_NOBFD)
  263. AC_CONFIG_FILES(Makefile)
  264. AC_CONFIG_HEADERS(config.h)
  265. AC_OUTPUT
  266. GNU_MAKE_JOBSERVER