testsuite: skip confirmation in 'gdb_reinitialize_dir'
[binutils-gdb.git] / libctf / configure.ac
blob64544b83a9f1e8e7d836182173f8928be56a28ff
1 dnl                                            -*- Autoconf -*-
2 dnl Process this file with autoconf to produce a configure script.
3 dnl
4 dnl   Copyright (C) 2019-2024 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
21 AC_PREREQ([2.64])
22 AC_INIT([libctf], [1.2.0])
23 AC_CONFIG_SRCDIR(ctf-impl.h)
24 AC_CANONICAL_BUILD
25 AC_CANONICAL_HOST
26 AC_CANONICAL_TARGET
27 AC_USE_SYSTEM_EXTENSIONS
28 AM_INIT_AUTOMAKE
29 AM_SILENT_RULES([yes])
31 # Checks for programs.
32 AC_PROG_MAKE_SET
33 AC_PROG_CC
34 AC_PROG_RANLIB
35 AM_PROG_AR
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.
40 AC_DISABLE_SHARED
42 LT_INIT
43 AC_SYS_LARGEFILE
44 LT_OUTPUT
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
61 # corrected.
62 ACX_PROG_CC_WARNINGS_ARE_ERRORS([manual])
64 AM_MAINTAINER_MODE
65 AM_INSTALL_LIBBFD
66 ACX_PROG_CC_WARNING_OPTS([-Wall], [ac_libctf_warn_cflags])
68 GCC_AC_FUNC_MMAP
69 # Needed for BFD capability checks.
70 AC_SEARCH_LIBS(dlsym, dl)
71 AM_ZLIB
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.
80 OLD_CFLAGS=$CFLAGS
81 OLD_LDFLAGS=$LDFLAGS
82 OLD_LIBS=$LIBS
83 OLD_CC=$CC
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>
94              #include <string.h>
95              #include "bfd.h"
96              #include "elf-bfd.h"],
97             [(void) bfd_section_from_elf_index (NULL, 0);
98              return 0;],
99             [ac_cv_libctf_bfd_elf=yes],
100             [ac_cv_libctf_bfd_elf=no])])
101 CFLAGS=$OLD_CFLAGS
102 LDFLAGS=$OLD_LDFLAGS
103 LIBS=$OLD_LIBS
104 CC=$OLD_CC
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.])
111 AC_C_BIGENDIAN
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],
123     [AC_LINK_IFELSE(
124        [AC_LANG_PROGRAM([[#undef qsort_r
125                           #include <stdlib.h>
126                           void qsort_r (void *, size_t, size_t,
127                                         int (*) (void const *, void const *,
128                                                  void *),
129                                         void *);
130                           void (*p) (void *, size_t, size_t,
131                                      int (*) (void const *, void const *,
132                                               void *),
133                                      void *) = qsort_r;
134                         ]])],
135        [ac_cv_libctf_qsort_r_signature=GNU],
136        [AC_LINK_IFELSE(
137           [AC_LANG_PROGRAM([[#undef qsort_r
138                              #include <stdlib.h>
139                              void qsort_r (void *, size_t, size_t, void *,
140                                            int (*) (void *,
141                                                     void const *,
142                                                     void const *));
143                              void (*p) (void *, size_t, size_t, void *,
144                                         int (*) (void *, void const *,
145                                                  void const *)) = qsort_r;
146                            ]])],
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;;
157 esac
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],
162   [AC_LINK_IFELSE(
163     [AC_LANG_PROGRAM([[#include <fcntl.h>
164                        #ifndef O_CLOEXEC
165                          choke me;
166                        #endif
167                      ]],
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.])
177 build_info=
178 makeinfo_too_old=
179 AC_CHECK_PROGS([MAKEINFO], makeinfo, [$MISSING makeinfo])
180 case " $build_configdirs " in
181   *" texinfo "*) MAKEINFO='$$r/$(BUILD_SUBDIR)/texinfo/makeinfo/makeinfo' ;;
182 esac
183 changequote(,)
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
188       build_info=yes
189     else
190         build_info=
191         makeinfo_too_old=t
192     fi
193 changequote([,])
194 if test -n "$makeinfo_too_old"; then
195     AC_MSG_WARN([
196 *** Makeinfo is too old. Info documentation will not be built.])
198 AC_SUBST(MAKEINFO)
199 AM_CONDITIONAL(BUILD_INFO, test "${build_info}" = yes)
201 CTF_LIBADD="-L`pwd`/../libiberty -liberty"
202 SHARED_LDFLAGS=
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.
215 changequote(,)dnl
216   x=`sed -n -e 's/^[    ]*PICFLAG[      ]*=[    ]*//p' < ../libiberty/Makefile | sed -n '$p'`
217 changequote([,])dnl
218   if test -n "$x"; then
219     CTF_LIBADD="-L`pwd`/../libiberty/pic -liberty"
220   fi
223 CTF_LIBADD="$CTF_LIBADD $LTLIBINTL"
225 if test "$enable_shared" = "yes"; then
226   case "${host}" in
227   # More hacks to build DLLs on Windows.
228     *-*-cygwin*)
229       SHARED_LDFLAGS="-no-undefined"
230       CTF_LIBADD="$CTF_LIBADD -lcygwin"
231       ;;
232   esac
234 AC_SUBST(SHARED_LDFLAGS)
235 AC_SUBST(CTF_LIBADD)
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 }
245 HAVE_TCL_TRY=false
246 if test "${ac_cv_libctf_tcl_try}" = "yes"; then
247     HAVE_TCL_TRY=true
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
253 # needed.
254 decommented_version_script=
255 no_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"
259    old_CFLAGS="$CFLAGS"
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"],
265                   [])
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],
274                     [])
275      LDFLAGS="$old_LDFLAGS"
276    fi
277    CFLAGS="$old_CFLAGS"
279    if test -z "$ac_cv_libctf_version_script"; then
280      ac_cv_libctf_version_script='-export-symbols-regex ctf_.*'
281      no_version_script=t
282    fi
283    rm -f conftest.ver])
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
288 # and fail to link.
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'"
302 else
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)
311 AC_OUTPUT
313 GNU_MAKE_JOBSERVER