Automatic date update in version.in
[binutils-gdb.git] / libctf / configure.ac
blobba4a144ce37f3cbbae2986d7715152f1ea4acdb2
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
21 AC_PREREQ(2.64)
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)
27 AC_CANONICAL_BUILD
28 AC_CANONICAL_HOST
29 AC_CANONICAL_TARGET
30 AC_USE_SYSTEM_EXTENSIONS
31 AM_INIT_AUTOMAKE
32 AM_SILENT_RULES([yes])
34 # Checks for programs.
35 AC_PROG_MAKE_SET
36 AC_PROG_CC
37 AC_PROG_RANLIB
38 AM_PROG_AR
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.
43 AC_DISABLE_SHARED
45 LT_INIT
46 AC_SYS_LARGEFILE
47 LT_OUTPUT
49 MISSING=`cd $ac_aux_dir && ${PWDCMD-pwd}`/missing
50 AC_CHECK_PROGS([ACLOCAL], [aclocal], [$MISSING aclocal])
51 AC_CHECK_PROGS([AUTOCONF], [autoconf], [$MISSING autoconf])
52 AC_CHECK_PROGS([AUTOHEADER], [autoheader], [$MISSING autoheader])
54 # Figure out what compiler warnings we can enable.
55 # See config/warnings.m4 for details.
57 ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wno-narrowing -Wwrite-strings \
58                           -Wmissing-format-attribute], [warn])
59 ACX_PROG_CC_WARNING_OPTS([-Wstrict-prototypes -Wmissing-prototypes \
60                           -Wold-style-definition], [c_warn])
61 ACX_PROG_CC_WARNING_ALMOST_PEDANTIC([-Wno-long-long])
63 # Only enable with --enable-werror-always until existing warnings are
64 # corrected.
65 ACX_PROG_CC_WARNINGS_ARE_ERRORS([manual])
67 AM_MAINTAINER_MODE
68 AM_INSTALL_LIBBFD
69 ACX_PROG_CC_WARNING_OPTS([-Wall], [ac_libctf_warn_cflags])
71 AC_FUNC_MMAP
72 # Needed for BFD capability checks.
73 AC_SEARCH_LIBS(dlsym, dl)
74 AM_ZLIB
75 AC_ZSTD
77 GCC_ENABLE([libctf-hash-debugging], [no], [], [Enable expensive debugging of CTF deduplication type hashing])
78 if test "${enable_libctf_hash_debugging}" = yes; then
79     AC_DEFINE(ENABLE_LIBCTF_HASH_DEBUGGING, 1, [Enable expensive debugging of CTF deduplication type hashing])
81 AM_CONDITIONAL(ENABLE_LIBCTF_HASH_DEBUGGING, test "${enable_libctf_hash_debugging}" = yes)
83 # Similar to GDB_AC_CHECK_BFD.
84 OLD_CFLAGS=$CFLAGS
85 OLD_LDFLAGS=$LDFLAGS
86 OLD_LIBS=$LIBS
87 OLD_CC=$CC
88 # Put the old CFLAGS/LDFLAGS last, in case the user's (C|LD)FLAGS
89 # points somewhere with bfd, with -I/foo/lib and -L/foo/lib.  We
90 # always want our bfd.
91 CC="./libtool --quiet --mode=link $OLD_CC"
92 CFLAGS="-I${srcdir}/../include -I../bfd -I${srcdir}/../bfd $CFLAGS"
93 ZLIBDIR=`echo $zlibdir | sed 's,\$(top_builddir)/,,g'`
94 LDFLAGS="-L../bfd -L../libiberty $ZLIBDIR $LDFLAGS"
95 intl=`echo $LIBINTL | sed 's,${top_builddir}/,,g'`
96 LIBS="-lbfd -liberty -lz $ZSTD_LIBS $intl $LIBS"
97 AC_CACHE_CHECK([for ELF support in BFD], ac_cv_libctf_bfd_elf,
98 [AC_TRY_LINK([#include <stdlib.h>
99              #include <string.h>
100              #include "bfd.h"
101              #include "elf-bfd.h"],
102             [(void) bfd_section_from_elf_index (NULL, 0);
103              return 0;],
104             [ac_cv_libctf_bfd_elf=yes],
105             [ac_cv_libctf_bfd_elf=no])])
106 CFLAGS=$OLD_CFLAGS
107 LDFLAGS=$OLD_LDFLAGS
108 LIBS=$OLD_LIBS
109 CC=$OLD_CC
111 if test $ac_cv_libctf_bfd_elf = yes; then
112   AC_DEFINE([HAVE_BFD_ELF], 1,
113             [Whether libbfd was configured for an ELF target.])
116 AC_C_BIGENDIAN
117 AC_CHECK_HEADERS(byteswap.h endian.h)
118 AC_CHECK_FUNCS(pread)
120 dnl Check for bswap_{16,32,64}
121 AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64], [], [], [[#include <byteswap.h>]])
122 AC_CHECK_DECLS([asprintf, vasprintf, stpcpy])
124 dnl Check for qsort_r.  (Taken from gnulib.)
125 AC_CHECK_FUNCS_ONCE([qsort_r])
126 if test $ac_cv_func_qsort_r = yes; then
127   AC_CACHE_CHECK([for qsort_r signature], [ac_cv_libctf_qsort_r_signature],
128     [AC_LINK_IFELSE(
129        [AC_LANG_PROGRAM([[#undef qsort_r
130                           #include <stdlib.h>
131                           void qsort_r (void *, size_t, size_t,
132                                         int (*) (void const *, void const *,
133                                                  void *),
134                                         void *);
135                           void (*p) (void *, size_t, size_t,
136                                      int (*) (void const *, void const *,
137                                               void *),
138                                      void *) = qsort_r;
139                         ]])],
140        [ac_cv_libctf_qsort_r_signature=GNU],
141        [AC_LINK_IFELSE(
142           [AC_LANG_PROGRAM([[#undef qsort_r
143                              #include <stdlib.h>
144                              void qsort_r (void *, size_t, size_t, void *,
145                                            int (*) (void *,
146                                                     void const *,
147                                                     void const *));
148                              void (*p) (void *, size_t, size_t, void *,
149                                         int (*) (void *, void const *,
150                                                  void const *)) = qsort_r;
151                            ]])],
152           [ac_cv_libctf_qsort_r_signature=BSD],
153           [ac_cv_libctf_qsort_r_signature=unknown])])])
156 case x$ac_cv_libctf_qsort_r_signature in
157   xGNU)     AC_DEFINE([HAVE_QSORT_R_ARG_LAST], 1,
158              [Whether a qsort_r exists with a void *arg as its last arg.]);;
159   xBSD)     AC_DEFINE([HAVE_QSORT_R_COMPAR_LAST], 1,
160              [Whether a qsort_r exists with the compar function as its last arg.]);;
161   *) ac_cv_libctf_qsort_r_signature=unknown;;
162 esac
164 AM_CONDITIONAL(NEED_CTF_QSORT_R, test "${ac_cv_libctf_qsort_r_signature}" = unknown)
166 AC_CACHE_CHECK([for O_CLOEXEC], [ac_cv_libctf_macro_O_CLOEXEC],
167   [AC_LINK_IFELSE(
168     [AC_LANG_PROGRAM([[#include <fcntl.h>
169                        #ifndef O_CLOEXEC
170                          choke me;
171                        #endif
172                      ]],
173                      [[return O_CLOEXEC;]])],
174     [ac_cv_libctf_macro_O_CLOEXEC=yes],
175     [ac_cv_libctf_macro_O_CLOEXEC=no])])
177 if test $ac_cv_libctf_macro_O_CLOEXEC = yes; then
178   AC_DEFINE([HAVE_O_CLOEXEC], 1,
179             [Whether the platform has a definition of O_CLOEXEC.])
182 build_info=
183 makeinfo_too_old=
184 AC_CHECK_PROGS([MAKEINFO], makeinfo, [$MISSING makeinfo])
185 case " $build_configdirs " in
186   *" texinfo "*) MAKEINFO='$$r/$(BUILD_SUBDIR)/texinfo/makeinfo/makeinfo' ;;
187 esac
188 changequote(,)
189     # We require texinfo to be 6.3 or later, for a working synindex
190     # and validatemenus: otherwise we fall back to /bin/true.
191     if ${MAKEINFO} --version \
192        | egrep 'texinfo[^0-9]*(6\.[3-9]|[7-9][0-9])' >/dev/null 2>&1; then
193       build_info=yes
194     else
195         build_info=
196         makeinfo_too_old=t
197     fi
198 changequote([,])
199 if test -n "$makeinfo_too_old"; then
200     AC_MSG_WARN([
201 *** Makeinfo is too old. Info documentation will not be built.])
203 AC_SUBST(MAKEINFO)
204 AM_CONDITIONAL(BUILD_INFO, test "${build_info}" = yes)
206 CTF_LIBADD="-L`pwd`/../libiberty -liberty"
207 SHARED_LDFLAGS=
209 # Horrible hacks to build DLLs on Windows and a shared library elsewhere.
210 if test "$enable_shared" = "yes"; then
211 # When building a shared libctf, link against the pic version of libiberty
212 # so that apps that use libctf won't need libiberty just to satisfy any
213 # libctf references.  We can't do that if a pic libiberty is unavailable
214 # since including non-pic # code would insert text relocations into libctf.
215 # Note that linking against libbfd as we do here, which is itself linked
216 # against libiberty, may not satisfy all the libctf libiberty references
217 # since libbfd may not pull in the entirety of libiberty.
218 # Also, jam libintl into the right place in all of this: after libiberty,
219 # which uses it, but before -lcygwin, which it uses.
220 changequote(,)dnl
221   x=`sed -n -e 's/^[    ]*PICFLAG[      ]*=[    ]*//p' < ../libiberty/Makefile | sed -n '$p'`
222 changequote([,])dnl
223   if test -n "$x"; then
224     CTF_LIBADD="-L`pwd`/../libiberty/pic -liberty"
225   fi
228 CTF_LIBADD="$CTF_LIBADD $LIBINTL"
230 if test "$enable_shared" = "yes"; then
231   case "${host}" in
232   # More hacks to build DLLs on Windows.
233     *-*-cygwin*)
234       SHARED_LDFLAGS="-no-undefined"
235       CTF_LIBADD="$CTF_LIBADD -lcygwin"
236       ;;
237   esac
239 AC_SUBST(SHARED_LDFLAGS)
240 AC_SUBST(CTF_LIBADD)
242 AC_PATH_PROG([EXPECT], [expect])
243 AC_CACHE_CHECK([for Tcl supporting try/catch], [ac_cv_libctf_tcl_try],
244   [ac_cv_libctf_tcl_try=`if test -z $EXPECT; then echo no; else $EXPECT << EOF
245 if @<:@llength @<:@info commands try@:>@@:>@ then { puts yes } else { puts no }
249 AM_CONDITIONAL(TCL_TRY, test "${ac_cv_libctf_tcl_try}" = yes)
251 # Use a version script, if possible, or an -export-symbols-regex otherwise.
252 decommented_version_script=
253 AC_CACHE_CHECK([for linker versioning flags], [ac_cv_libctf_version_script],
254   [echo 'FOO { global: mai*; local: ctf_fo*; };' > conftest.ver
255    old_LDFLAGS="$LDFLAGS"
256    old_CFLAGS="$CFLAGS"
257    LDFLAGS="$LDFLAGS -shared -Wl,--version-script=conftest.ver"
258    CFLAGS="$CFLAGS -fPIC"
259    AC_LINK_IFELSE([AC_LANG_SOURCE([[int ctf_foo (void) { return 0; }
260                                     int main (void) { return ctf_foo(); }]])],
261                   [ac_cv_libctf_version_script="-Wl,--version-script='$srcdir/libctf.ver'"],
262                   [])
263    LDFLAGS="$old_LDFLAGS"
265    if test -z "$ac_cv_libctf_version_script"; then
266      LDFLAGS="$LDFLAGS -shared -Wl,-B,local -Wl,-z,gnu-version-script=conftest.ver"
267      AC_LINK_IFELSE([AC_LANG_SOURCE([[int ctf_foo (void) { return 0; }
268                                       int main (void) { return ctf_foo(); }]])],
269                     [ac_cv_libctf_version_script="-Wl,-B,local -Wl,-z,gnu-version-script"
270                      decommented_version_script=t],
271                     [])
272      LDFLAGS="$old_LDFLAGS"
273    fi
274    CFLAGS="$old_CFLAGS"
276    if test -z "$ac_cv_libctf_version_script"; then
277      ac_cv_libctf_version_script='-export-symbols-regex ctf_.*'
278    fi
279    rm -f conftest.ver])
280 if test -n "$decommented_version_script"; then
281    # Solaris's version scripts use shell-style comments rather than the C-style
282    # used by GNU ld.  Use cpp to strip the comments out.  (cpp exists under this
283    # name on all platforms that support ld -z gnu-version-script.)
284    # Also ensure that no symbols exist in the version script for libctf-nobfd.so
285    # that do not exist in the shared library itself, since some linkers add such
286    # symbols with type NOTYPE.
287    /lib/cpp < $srcdir/libctf.ver > libctf-decommented.ver
288    grep -v 'libctf only' $srcdir/libctf.ver | /lib/cpp > libctf-nobfd-decommented.ver
289    VERSION_FLAGS="$ac_cv_libctf_version_script='libctf-decommented.ver'"
290    VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script='libctf-nobfd-decommented.ver'"
291 else
292    VERSION_FLAGS="$ac_cv_libctf_version_script"
293    VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script"
295 AC_SUBST(VERSION_FLAGS)
296 AC_SUBST(VERSION_FLAGS_NOBFD)
298 AC_CONFIG_FILES(Makefile)
299 AC_CONFIG_HEADERS(config.h)
300 AC_OUTPUT
302 GNU_MAKE_JOBSERVER