2 dnl Process this file with autoconf to produce a configure script.
4 dnl Copyright (C) 2019-2022 Free Software Foundation, Inc.
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.
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.
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/>.
22 AC_INIT([libctf], 1.2.0)
23 AC_CONFIG_SRCDIR(ctf-impl.h)
24 AC_CONFIG_MACRO_DIR(..)
25 AC_CONFIG_MACRO_DIR(../config)
26 AC_CONFIG_MACRO_DIR(../bfd)
30 AC_USE_SYSTEM_EXTENSIONS
32 AM_SILENT_RULES([yes])
34 # Checks for programs.
39 ZW_GNU_GETTEXT_SISTER_DIR
41 dnl Default to a non shared library. This may be overridden by the
42 dnl configure option --enable-shared.
48 MISSING=`cd $ac_aux_dir && ${PWDCMD-pwd}`/missing
49 AC_CHECK_PROGS([ACLOCAL], [aclocal], [$MISSING aclocal])
50 AC_CHECK_PROGS([AUTOCONF], [autoconf], [$MISSING autoconf])
51 AC_CHECK_PROGS([AUTOHEADER], [autoheader], [$MISSING autoheader])
53 # Figure out what compiler warnings we can enable.
54 # See config/warnings.m4 for details.
56 ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wno-narrowing -Wwrite-strings \
57 -Wmissing-format-attribute], [warn])
58 ACX_PROG_CC_WARNING_OPTS([-Wstrict-prototypes -Wmissing-prototypes \
59 -Wold-style-definition], [c_warn])
60 ACX_PROG_CC_WARNING_ALMOST_PEDANTIC([-Wno-long-long])
62 # Only enable with --enable-werror-always until existing warnings are
64 ACX_PROG_CC_WARNINGS_ARE_ERRORS([manual])
68 ACX_PROG_CC_WARNING_OPTS([-Wall], [ac_libctf_warn_cflags])
71 # Needed for BFD capability checks.
72 AC_SEARCH_LIBS(dlsym, dl)
76 GCC_ENABLE([libctf-hash-debugging], [no], [], [Enable expensive debugging of CTF deduplication type hashing])
77 if test "${enable_libctf_hash_debugging}" = yes; then
78 AC_DEFINE(ENABLE_LIBCTF_HASH_DEBUGGING, 1, [Enable expensive debugging of CTF deduplication type hashing])
80 AM_CONDITIONAL(ENABLE_LIBCTF_HASH_DEBUGGING, test "${enable_libctf_hash_debugging}" = yes)
82 # Similar to GDB_AC_CHECK_BFD.
86 # Put the old CFLAGS/LDFLAGS last, in case the user's (C|LD)FLAGS
87 # points somewhere with bfd, with -I/foo/lib and -L/foo/lib. We
88 # always want our bfd.
89 CFLAGS="-I${srcdir}/../include -I../bfd -I${srcdir}/../bfd $CFLAGS"
90 ZLIBDIR=`echo $zlibdir | sed 's,\$(top_builddir)/,,g'`
91 LDFLAGS="-L../bfd -L../libiberty $ZLIBDIR $LDFLAGS"
92 intl=`echo $LIBINTL | sed 's,${top_builddir}/,,g'`
93 LIBS="-lbfd -liberty -lz $ZSTD_LIBS $intl $LIBS"
94 AC_CACHE_CHECK([for ELF support in BFD], ac_cv_libctf_bfd_elf,
95 [AC_TRY_LINK([#include <stdlib.h>
98 #include "elf-bfd.h"],
99 [(void) bfd_section_from_elf_index (NULL, 0);
101 [ac_cv_libctf_bfd_elf=yes],
102 [ac_cv_libctf_bfd_elf=no])])
107 if test $ac_cv_libctf_bfd_elf = yes; then
108 AC_DEFINE([HAVE_BFD_ELF], 1,
109 [Whether libbfd was configured for an ELF target.])
113 AC_CHECK_HEADERS(byteswap.h endian.h)
114 AC_CHECK_FUNCS(pread)
116 dnl Check for bswap_{16,32,64}
117 AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64], [], [], [[#include <byteswap.h>]])
118 AC_CHECK_DECLS([asprintf, vasprintf, stpcpy])
120 dnl Check for qsort_r. (Taken from gnulib.)
121 AC_CHECK_FUNCS_ONCE([qsort_r])
122 if test $ac_cv_func_qsort_r = yes; then
123 AC_CACHE_CHECK([for qsort_r signature], [ac_cv_libctf_qsort_r_signature],
125 [AC_LANG_PROGRAM([[#undef qsort_r
127 void qsort_r (void *, size_t, size_t,
128 int (*) (void const *, void const *,
131 void (*p) (void *, size_t, size_t,
132 int (*) (void const *, void const *,
136 [ac_cv_libctf_qsort_r_signature=GNU],
138 [AC_LANG_PROGRAM([[#undef qsort_r
140 void qsort_r (void *, size_t, size_t, void *,
144 void (*p) (void *, size_t, size_t, void *,
145 int (*) (void *, void const *,
146 void const *)) = qsort_r;
148 [ac_cv_libctf_qsort_r_signature=BSD],
149 [ac_cv_libctf_qsort_r_signature=unknown])])])
152 case x$ac_cv_libctf_qsort_r_signature in
153 xGNU) AC_DEFINE([HAVE_QSORT_R_ARG_LAST], 1,
154 [Whether a qsort_r exists with a void *arg as its last arg.]);;
155 xBSD) AC_DEFINE([HAVE_QSORT_R_COMPAR_LAST], 1,
156 [Whether a qsort_r exists with the compar function as its last arg.]);;
157 *) ac_cv_libctf_qsort_r_signature=unknown;;
160 AM_CONDITIONAL(NEED_CTF_QSORT_R, test "${ac_cv_libctf_qsort_r_signature}" = unknown)
162 AC_CACHE_CHECK([for O_CLOEXEC], [ac_cv_libctf_macro_O_CLOEXEC],
164 [AC_LANG_PROGRAM([[#include <fcntl.h>
169 [[return O_CLOEXEC;]])],
170 [ac_cv_libctf_macro_O_CLOEXEC=yes],
171 [ac_cv_libctf_macro_O_CLOEXEC=no])])
173 if test $ac_cv_libctf_macro_O_CLOEXEC = yes; then
174 AC_DEFINE([HAVE_O_CLOEXEC], 1,
175 [Whether the platform has a definition of O_CLOEXEC.])
180 AC_CHECK_PROGS([MAKEINFO], makeinfo, [$MISSING makeinfo])
181 case " $build_configdirs " in
182 *" texinfo "*) MAKEINFO='$$r/$(BUILD_SUBDIR)/texinfo/makeinfo/makeinfo' ;;
185 # We require texinfo to be 6.3 or later, for a working synindex
186 # and validatemenus: otherwise we fall back to /bin/true.
187 if ${MAKEINFO} --version \
188 | egrep 'texinfo[^0-9]*(6\.[3-9]|[7-9][0-9])' >/dev/null 2>&1; then
195 if test -n "$makeinfo_too_old"; then
197 *** Makeinfo is too old. Info documentation will not be built.])
200 AM_CONDITIONAL(BUILD_INFO, test "${build_info}" = yes)
202 CTF_LIBADD="-L`pwd`/../libiberty -liberty"
205 # Horrible hacks to build DLLs on Windows and a shared library elsewhere.
206 if test "$enable_shared" = "yes"; then
207 # When building a shared libctf, link against the pic version of libiberty
208 # so that apps that use libctf won't need libiberty just to satisfy any
209 # libctf references. We can't do that if a pic libiberty is unavailable
210 # since including non-pic # code would insert text relocations into libctf.
211 # Note that linking against libbfd as we do here, which is itself linked
212 # against libiberty, may not satisfy all the libctf libiberty references
213 # since libbfd may not pull in the entirety of libiberty.
214 # Also, jam libintl into the right place in all of this: after libiberty,
215 # which uses it, but before -lcygwin, which it uses.
217 x=`sed -n -e 's/^[ ]*PICFLAG[ ]*=[ ]*//p' < ../libiberty/Makefile | sed -n '$p'`
219 if test -n "$x"; then
220 CTF_LIBADD="-L`pwd`/../libiberty/pic -liberty"
224 CTF_LIBADD="$CTF_LIBADD $LIBINTL"
226 if test "$enable_shared" = "yes"; then
228 # More hacks to build DLLs on Windows.
230 SHARED_LDFLAGS="-no-undefined"
231 CTF_LIBADD="$CTF_LIBADD -lcygwin"
235 AC_SUBST(SHARED_LDFLAGS)
238 AC_PATH_PROG([EXPECT], [expect])
239 AC_CACHE_CHECK([for Tcl supporting try/catch], [ac_cv_libctf_tcl_try],
240 [ac_cv_libctf_tcl_try=`if test -z $EXPECT; then echo no; else $EXPECT << EOF
241 if @<:@llength @<:@info commands try@:>@@:>@ then { puts yes } else { puts no }
245 AM_CONDITIONAL(TCL_TRY, test "${ac_cv_libctf_tcl_try}" = yes)
247 # Use a version script, if possible, or an -export-symbols-regex otherwise.
248 decommented_version_script=
249 AC_CACHE_CHECK([for linker versioning flags], [ac_cv_libctf_version_script],
250 [echo 'FOO { global: mai*; local: ctf_fo*; };' > conftest.ver
251 old_LDFLAGS="$LDFLAGS"
253 LDFLAGS="$LDFLAGS -shared -Wl,--version-script=conftest.ver"
254 CFLAGS="$CFLAGS -fPIC"
255 AC_LINK_IFELSE([AC_LANG_SOURCE([[int ctf_foo (void) { return 0; }
256 int main (void) { return ctf_foo(); }]])],
257 [ac_cv_libctf_version_script="-Wl,--version-script='$srcdir/libctf.ver'"],
259 LDFLAGS="$old_LDFLAGS"
261 if test -z "$ac_cv_libctf_version_script"; then
262 LDFLAGS="$LDFLAGS -shared -Wl,-B,local -Wl,-z,gnu-version-script=conftest.ver"
263 AC_LINK_IFELSE([AC_LANG_SOURCE([[int ctf_foo (void) { return 0; }
264 int main (void) { return ctf_foo(); }]])],
265 [ac_cv_libctf_version_script="-Wl,-B,local -Wl,-z,gnu-version-script"
266 decommented_version_script=t],
268 LDFLAGS="$old_LDFLAGS"
272 if test -z "$ac_cv_libctf_version_script"; then
273 ac_cv_libctf_version_script='-export-symbols-regex ctf_.*'
276 if test -n "$decommented_version_script"; then
277 # Solaris's version scripts use shell-style comments rather than the C-style
278 # used by GNU ld. Use cpp to strip the comments out. (cpp exists under this
279 # name on all platforms that support ld -z gnu-version-script.)
280 # Also ensure that no symbols exist in the version script for libctf-nobfd.so
281 # that do not exist in the shared library itself, since some linkers add such
282 # symbols with type NOTYPE.
283 /lib/cpp < $srcdir/libctf.ver > libctf-decommented.ver
284 grep -v 'libctf only' $srcdir/libctf.ver | /lib/cpp > libctf-nobfd-decommented.ver
285 VERSION_FLAGS="$ac_cv_libctf_version_script='libctf-decommented.ver'"
286 VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script='libctf-nobfd-decommented.ver'"
288 VERSION_FLAGS="$ac_cv_libctf_version_script"
289 VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script"
291 AC_SUBST(VERSION_FLAGS)
292 AC_SUBST(VERSION_FLAGS_NOBFD)
294 AC_CONFIG_FILES(Makefile)
295 AC_CONFIG_HEADERS(config.h)