2 dnl Process this file with autoconf to produce a configure script.
4 dnl Copyright (C) 2019-2021 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
33 # Checks for programs.
38 ZW_GNU_GETTEXT_SISTER_DIR
40 dnl Default to a non shared library. This may be overridden by the
41 dnl configure option --enable-shared.
47 MISSING=`cd $ac_aux_dir && ${PWDCMD-pwd}`/missing
48 AC_CHECK_PROGS([ACLOCAL], [aclocal], [$MISSING aclocal])
49 AC_CHECK_PROGS([AUTOCONF], [autoconf], [$MISSING autoconf])
50 AC_CHECK_PROGS([AUTOHEADER], [autoheader], [$MISSING autoheader])
52 # Figure out what compiler warnings we can enable.
53 # See config/warnings.m4 for details.
55 ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wno-narrowing -Wwrite-strings \
56 -Wmissing-format-attribute], [warn])
57 ACX_PROG_CC_WARNING_OPTS([-Wstrict-prototypes -Wmissing-prototypes \
58 -Wold-style-definition], [c_warn])
59 ACX_PROG_CC_WARNING_ALMOST_PEDANTIC([-Wno-long-long])
61 # Only enable with --enable-werror-always until existing warnings are
63 ACX_PROG_CC_WARNINGS_ARE_ERRORS([manual])
67 ACX_PROG_CC_WARNING_OPTS([-Wall], [ac_libctf_warn_cflags])
70 # Needed for BFD capability checks.
71 AC_SEARCH_LIBS(dlopen, dl)
74 GCC_ENABLE([libctf-hash-debugging], [no], [], [Enable expensive debugging of CTF deduplication type hashing])
75 if test "${enable_libctf_hash_debugging}" = yes; then
76 AC_DEFINE(ENABLE_LIBCTF_HASH_DEBUGGING, 1, [Enable expensive debugging of CTF deduplication type hashing])
78 AM_CONDITIONAL(ENABLE_LIBCTF_HASH_DEBUGGING, test "${enable_libctf_hash_debugging}" = yes)
80 # 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 CFLAGS="-I${srcdir}/../include -I../bfd -I${srcdir}/../bfd $CFLAGS"
88 ZLIBDIR=`echo $zlibdir | sed 's,\$(top_builddir)/,,g'`
89 LDFLAGS="-L../bfd -L../libiberty $ZLIBDIR $LDFLAGS"
90 intl=`echo $LIBINTL | sed 's,${top_builddir}/,,g'`
91 LIBS="-lbfd -liberty -lz $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])])
105 if test $ac_cv_libctf_bfd_elf = yes; then
106 AC_DEFINE([HAVE_BFD_ELF], 1,
107 [Whether libbfd was configured for an ELF target.])
111 AC_CHECK_HEADERS(byteswap.h endian.h)
112 AC_CHECK_FUNCS(pread)
114 dnl Check for bswap_{16,32,64}
115 AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64], [], [], [[#include <byteswap.h>]])
116 AC_CHECK_DECLS([asprintf, vasprintf, stpcpy])
118 dnl Check for qsort_r. (Taken from gnulib.)
119 AC_CHECK_FUNCS_ONCE([qsort_r])
120 if test $ac_cv_func_qsort_r = yes; then
121 AC_CACHE_CHECK([for qsort_r signature], [ac_cv_libctf_qsort_r_signature],
123 [AC_LANG_PROGRAM([[#undef qsort_r
125 void qsort_r (void *, size_t, size_t,
126 int (*) (void const *, void const *,
129 void (*p) (void *, size_t, size_t,
130 int (*) (void const *, void const *,
134 [ac_cv_libctf_qsort_r_signature=GNU],
136 [AC_LANG_PROGRAM([[#undef qsort_r
138 void qsort_r (void *, size_t, size_t, void *,
142 void (*p) (void *, size_t, size_t, void *,
143 int (*) (void *, void const *,
144 void const *)) = qsort_r;
146 [ac_cv_libctf_qsort_r_signature=BSD],
147 [ac_cv_libctf_qsort_r_signature=unknown])])])
150 case x$ac_cv_libctf_qsort_r_signature in
151 xGNU) AC_DEFINE([HAVE_QSORT_R_ARG_LAST], 1,
152 [Whether a qsort_r exists with a void *arg as its last arg.]);;
153 xBSD) AC_DEFINE([HAVE_QSORT_R_COMPAR_LAST], 1,
154 [Whether a qsort_r exists with the compar function as its last arg.]);;
155 *) ac_cv_libctf_qsort_r_signature=unknown;;
158 AM_CONDITIONAL(NEED_CTF_QSORT_R, test "${ac_cv_libctf_qsort_r_signature}" = unknown)
160 AC_CACHE_CHECK([for O_CLOEXEC], [ac_cv_libctf_macro_O_CLOEXEC],
162 [AC_LANG_PROGRAM([[#include <fcntl.h>
167 [[return O_CLOEXEC;]])],
168 [ac_cv_libctf_macro_O_CLOEXEC=yes],
169 [ac_cv_libctf_macro_O_CLOEXEC=no])])
171 if test $ac_cv_libctf_macro_O_CLOEXEC = yes; then
172 AC_DEFINE([HAVE_O_CLOEXEC], 1,
173 [Whether the platform has a definition of O_CLOEXEC.])
176 CTF_LIBADD="-L`pwd`/../libiberty -liberty"
179 # Horrible hacks to build DLLs on Windows and a shared library elsewhere.
180 if test "$enable_shared" = "yes"; then
181 # When building a shared libctf, link against the pic version of libiberty
182 # so that apps that use libctf won't need libiberty just to satisfy any
183 # libctf references. We can't do that if a pic libiberty is unavailable
184 # since including non-pic # code would insert text relocations into libctf.
185 # Note that linking against libbfd as we do here, which is itself linked
186 # against libiberty, may not satisfy all the libctf libiberty references
187 # since libbfd may not pull in the entirety of libiberty.
188 # Also, jam libintl into the right place in all of this: after libiberty,
189 # which uses it, but before -lcygwin, which it uses.
191 x=`sed -n -e 's/^[ ]*PICFLAG[ ]*=[ ]*//p' < ../libiberty/Makefile | sed -n '$p'`
193 if test -n "$x"; then
194 CTF_LIBADD="-L`pwd`/../libiberty/pic -liberty"
198 CTF_LIBADD="$CTF_LIBADD $LIBINTL"
200 if test "$enable_shared" = "yes"; then
202 # More hacks to build DLLs on Windows.
204 SHARED_LDFLAGS="-no-undefined"
205 CTF_LIBADD="$CTF_LIBADD -lcygwin"
209 AC_SUBST(SHARED_LDFLAGS)
212 AC_PATH_PROG([EXPECT], [expect])
213 AC_CACHE_CHECK([for Tcl supporting try/catch], [ac_cv_libctf_tcl_try],
214 [ac_cv_libctf_tcl_try=`if test -z $EXPECT; then echo no; else $EXPECT << EOF
215 if @<:@llength @<:@info commands try@:>@@:>@ then { puts yes } else { puts no }
219 AM_CONDITIONAL(TCL_TRY, test "${ac_cv_libctf_tcl_try}" = yes)
221 # Use a version script, if possible, or an -export-symbols-regex otherwise.
222 VERSION_FLAGS='-export-symbols-regex ctf_.*'
223 if $LD --help 2>&1 | grep -- --version-script >/dev/null; then
224 VERSION_FLAGS="-Wl,--version-script='$srcdir/libctf.ver'"
226 AC_SUBST(VERSION_FLAGS)
228 AC_CONFIG_FILES(Makefile)
229 AC_CONFIG_HEADERS(config.h)