2 dnl Process this file with autoconf to produce a configure script.
4 dnl Copyright (C) 2019-2024 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)
27 AC_USE_SYSTEM_EXTENSIONS
29 AM_SILENT_RULES([yes])
31 # Checks for programs.
36 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.
46 MISSING=`cd $ac_aux_dir && ${PWDCMD-pwd}`/missing
47 AC_CHECK_PROGS([ACLOCAL], [aclocal], [$MISSING aclocal])
48 AC_CHECK_PROGS([AUTOCONF], [autoconf], [$MISSING autoconf])
49 AC_CHECK_PROGS([AUTOHEADER], [autoheader], [$MISSING autoheader])
51 # Figure out what compiler warnings we can enable.
52 # See config/warnings.m4 for details.
54 ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wno-narrowing -Wwrite-strings \
55 -Wmissing-format-attribute], [warn])
56 ACX_PROG_CC_WARNING_OPTS([-Wstrict-prototypes -Wmissing-prototypes \
57 -Wold-style-definition], [c_warn])
58 ACX_PROG_CC_WARNING_ALMOST_PEDANTIC([-Wno-long-long])
60 # Only enable with --enable-werror-always until existing warnings are
62 ACX_PROG_CC_WARNINGS_ARE_ERRORS([manual])
66 ACX_PROG_CC_WARNING_OPTS([-Wall], [ac_libctf_warn_cflags])
69 # Needed for BFD capability checks.
70 AC_SEARCH_LIBS(dlsym, dl)
73 GCC_ENABLE([libctf-hash-debugging], [no], [], [Enable expensive debugging of CTF deduplication type hashing])
74 if test "${enable_libctf_hash_debugging}" = yes; then
75 AC_DEFINE(ENABLE_LIBCTF_HASH_DEBUGGING, 1, [Enable expensive debugging of CTF deduplication type hashing])
77 AM_CONDITIONAL(ENABLE_LIBCTF_HASH_DEBUGGING, test "${enable_libctf_hash_debugging}" = yes)
79 # Similar to GDB_AC_CHECK_BFD.
84 # Put the old CFLAGS/LDFLAGS last, in case the user's (C|LD)FLAGS
85 # points somewhere with bfd, with -I/foo/lib and -L/foo/lib. We
86 # always want our bfd.
87 CC="./libtool --quiet --mode=link $OLD_CC"
88 CFLAGS="-I${srcdir}/../include -I../bfd -I${srcdir}/../bfd $CFLAGS"
89 LDFLAGS="-L../bfd -L../libiberty $LDFLAGS"
90 intl=`echo $LIBINTL | sed 's,${top_builddir}/,,g'`
91 LIBS="-lbfd -liberty $intl $LIBS"
92 AC_CACHE_CHECK([for ELF support in BFD], ac_cv_libctf_bfd_elf,
93 [AC_TRY_LINK([#include <stdlib.h>
96 #include "elf-bfd.h"],
97 [(void) bfd_section_from_elf_index (NULL, 0);
99 [ac_cv_libctf_bfd_elf=yes],
100 [ac_cv_libctf_bfd_elf=no])])
106 if test $ac_cv_libctf_bfd_elf = yes; then
107 AC_DEFINE([HAVE_BFD_ELF], 1,
108 [Whether libbfd was configured for an ELF target.])
112 AC_CHECK_HEADERS(byteswap.h endian.h valgrind/valgrind.h)
113 AC_CHECK_FUNCS(pread)
115 dnl Check for bswap_{16,32,64}
116 AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64], [], [], [[#include <byteswap.h>]])
117 AC_CHECK_DECLS([asprintf, vasprintf, stpcpy])
119 dnl Check for qsort_r. (Taken from gnulib.)
120 AC_CHECK_FUNCS_ONCE([qsort_r])
121 if test $ac_cv_func_qsort_r = yes; then
122 AC_CACHE_CHECK([for qsort_r signature], [ac_cv_libctf_qsort_r_signature],
124 [AC_LANG_PROGRAM([[#undef qsort_r
126 void qsort_r (void *, size_t, size_t,
127 int (*) (void const *, void const *,
130 void (*p) (void *, size_t, size_t,
131 int (*) (void const *, void const *,
135 [ac_cv_libctf_qsort_r_signature=GNU],
137 [AC_LANG_PROGRAM([[#undef qsort_r
139 void qsort_r (void *, size_t, size_t, void *,
143 void (*p) (void *, size_t, size_t, void *,
144 int (*) (void *, void const *,
145 void const *)) = qsort_r;
147 [ac_cv_libctf_qsort_r_signature=BSD],
148 [ac_cv_libctf_qsort_r_signature=unknown])])])
151 case x$ac_cv_libctf_qsort_r_signature in
152 xGNU) AC_DEFINE([HAVE_QSORT_R_ARG_LAST], 1,
153 [Whether a qsort_r exists with a void *arg as its last arg.]);;
154 xBSD) AC_DEFINE([HAVE_QSORT_R_COMPAR_LAST], 1,
155 [Whether a qsort_r exists with the compar function as its last arg.]);;
156 *) ac_cv_libctf_qsort_r_signature=unknown;;
159 AM_CONDITIONAL(NEED_CTF_QSORT_R, test "${ac_cv_libctf_qsort_r_signature}" = unknown)
161 AC_CACHE_CHECK([for O_CLOEXEC], [ac_cv_libctf_macro_O_CLOEXEC],
163 [AC_LANG_PROGRAM([[#include <fcntl.h>
168 [[return O_CLOEXEC;]])],
169 [ac_cv_libctf_macro_O_CLOEXEC=yes],
170 [ac_cv_libctf_macro_O_CLOEXEC=no])])
172 if test $ac_cv_libctf_macro_O_CLOEXEC = yes; then
173 AC_DEFINE([HAVE_O_CLOEXEC], 1,
174 [Whether the platform has a definition of O_CLOEXEC.])
179 AC_CHECK_PROGS([MAKEINFO], makeinfo, [$MISSING makeinfo])
180 case " $build_configdirs " in
181 *" texinfo "*) MAKEINFO='$$r/$(BUILD_SUBDIR)/texinfo/makeinfo/makeinfo' ;;
184 # We require texinfo to be 6.3 or later, for a working synindex
185 # and validatemenus: otherwise we fall back to /bin/true.
186 if ${MAKEINFO} --version \
187 | egrep 'texinfo[^0-9]*(6\.[3-9]|[7-9]|[1-6][0-9])' >/dev/null 2>&1; then
194 if test -n "$makeinfo_too_old"; then
196 *** Makeinfo is too old. Info documentation will not be built.])
199 AM_CONDITIONAL(BUILD_INFO, test "${build_info}" = yes)
201 CTF_LIBADD="-L`pwd`/../libiberty -liberty"
204 # Horrible hacks to build DLLs on Windows and a shared library elsewhere.
205 if test "$enable_shared" = "yes"; then
206 # When building a shared libctf, link against the pic version of libiberty
207 # so that apps that use libctf won't need libiberty just to satisfy any
208 # libctf references. We can't do that if a pic libiberty is unavailable
209 # since including non-pic # code would insert text relocations into libctf.
210 # Note that linking against libbfd as we do here, which is itself linked
211 # against libiberty, may not satisfy all the libctf libiberty references
212 # since libbfd may not pull in the entirety of libiberty.
213 # Also, jam libintl into the right place in all of this: after libiberty,
214 # which uses it, but before -lcygwin, which it uses.
216 x=`sed -n -e 's/^[ ]*PICFLAG[ ]*=[ ]*//p' < ../libiberty/Makefile | sed -n '$p'`
218 if test -n "$x"; then
219 CTF_LIBADD="-L`pwd`/../libiberty/pic -liberty"
223 CTF_LIBADD="$CTF_LIBADD $LTLIBINTL"
225 if test "$enable_shared" = "yes"; then
227 # More hacks to build DLLs on Windows.
229 SHARED_LDFLAGS="-no-undefined"
230 CTF_LIBADD="$CTF_LIBADD -lcygwin"
234 AC_SUBST(SHARED_LDFLAGS)
237 AC_PATH_PROG([EXPECT], [expect])
238 AC_CACHE_CHECK([for Tcl supporting try/catch], [ac_cv_libctf_tcl_try],
239 [ac_cv_libctf_tcl_try=`if test -z $EXPECT; then echo no; else $EXPECT << EOF
240 if @<:@llength @<:@info commands try@:>@@:>@ then { puts yes } else { puts no }
246 if test "${ac_cv_libctf_tcl_try}" = "yes"; then
249 AC_SUBST(HAVE_TCL_TRY)
251 # Use a version script, if possible, or an -export-symbols-regex otherwise.
252 # First figure out the version script flag: then massage the script, if
254 decommented_version_script=
256 AC_CACHE_CHECK([for linker versioning flags], [ac_cv_libctf_version_script],
257 [echo 'FOO { global: mai*; local: ctf_fo*; };' > conftest.ver
258 old_LDFLAGS="$LDFLAGS"
260 LDFLAGS="$LDFLAGS -shared -Wl,--version-script=conftest.ver"
261 CFLAGS="$CFLAGS -fPIC"
262 AC_LINK_IFELSE([AC_LANG_SOURCE([[int ctf_foo (void) { return 0; }
263 int main (void) { return ctf_foo(); }]])],
264 [ac_cv_libctf_version_script="-Wl,--version-script"],
266 LDFLAGS="$old_LDFLAGS"
268 if test -z "$ac_cv_libctf_version_script"; then
269 LDFLAGS="$LDFLAGS -shared -Wl,-B,local -Wl,-z,gnu-version-script=conftest.ver"
270 AC_LINK_IFELSE([AC_LANG_SOURCE([[int ctf_foo (void) { return 0; }
271 int main (void) { return ctf_foo(); }]])],
272 [ac_cv_libctf_version_script="-Wl,-B,local -Wl,-z,gnu-version-script"
273 decommented_version_script=t],
275 LDFLAGS="$old_LDFLAGS"
279 if test -z "$ac_cv_libctf_version_script"; then
280 ac_cv_libctf_version_script='-export-symbols-regex ctf_.*'
285 # Ensure that no symbols exist in the version script for libctf-nobfd.so
286 # that do not exist in the shared library itself, since some linkers (Solaris)
287 # add such symbols with type NOTYPE, and others (LLVM) complain loudly
289 grep -v 'libctf only' $srcdir/libctf.ver > libctf-nobfd.ver
291 if test -n "$decommented_version_script"; then
292 # Solaris's version scripts use shell-style comments rather than the C-style
293 # used by GNU ld. Use cpp to strip the comments out. (cpp exists under this
294 # name on all platforms that support ld -z gnu-version-script.)
295 /lib/cpp < $srcdir/libctf.ver > libctf-decommented.ver
296 /lib/cpp < $srcdir/libctf-nobfd.ver > libctf-nobfd-decommented.ver
297 VERSION_FLAGS="$ac_cv_libctf_version_script='libctf-decommented.ver'"
298 VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script='libctf-nobfd-decommented.ver'"
299 elif test -z "$no_version_script"; then
300 VERSION_FLAGS="$ac_cv_libctf_version_script='$srcdir/libctf.ver'"
301 VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script='libctf-nobfd.ver'"
303 VERSION_FLAGS="$ac_cv_libctf_version_script"
304 VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script"
306 AC_SUBST(VERSION_FLAGS)
307 AC_SUBST(VERSION_FLAGS_NOBFD)
309 AC_CONFIG_FILES(Makefile)
310 AC_CONFIG_HEADERS(config.h)