xref: /netbsd-src/external/gpl3/gdb/dist/libctf/configure.ac (revision 12989c96ee862c63521a9ead8c44629b7a2ba9b1)
18dffb485Schristosdnl                                            -*- Autoconf -*-
28dffb485Schristosdnl Process this file with autoconf to produce a configure script.
38dffb485Schristosdnl
4*12989c96Schristosdnl   Copyright (C) 2019-2024 Free Software Foundation, Inc.
58dffb485Schristosdnl
68dffb485Schristosdnl This file is free software; you can redistribute it and/or modify
78dffb485Schristosdnl it under the terms of the GNU General Public License as published by
88dffb485Schristosdnl the Free Software Foundation; either version 2 of the License, or
98dffb485Schristosdnl (at your option) any later version.
108dffb485Schristosdnl
118dffb485Schristosdnl This program is distributed in the hope that it will be useful,
128dffb485Schristosdnl but WITHOUT ANY WARRANTY; without even the implied warranty of
138dffb485Schristosdnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
148dffb485Schristosdnl GNU General Public License for more details.
158dffb485Schristosdnl
168dffb485Schristosdnl You should have received a copy of the GNU General Public License
178dffb485Schristosdnl along with this program; see the file COPYING.  If not see
188dffb485Schristosdnl <http://www.gnu.org/licenses/>.
198dffb485Schristosdnl
208dffb485Schristos
218dffb485SchristosAC_PREREQ(2.64)
228dffb485SchristosAC_INIT([libctf], 1.2.0)
238dffb485SchristosAC_CONFIG_SRCDIR(ctf-impl.h)
244b169a6bSchristosAC_CANONICAL_BUILD
254b169a6bSchristosAC_CANONICAL_HOST
264b169a6bSchristosAC_CANONICAL_TARGET
278dffb485SchristosAC_USE_SYSTEM_EXTENSIONS
288dffb485SchristosAM_INIT_AUTOMAKE
294b169a6bSchristosAM_SILENT_RULES([yes])
308dffb485Schristos
318dffb485Schristos# Checks for programs.
328dffb485SchristosAC_PROG_MAKE_SET
338dffb485SchristosAC_PROG_CC
348dffb485SchristosAC_PROG_RANLIB
358dffb485SchristosAM_PROG_AR
368dffb485SchristosZW_GNU_GETTEXT_SISTER_DIR
378dffb485Schristos
388dffb485Schristosdnl Default to a non shared library.  This may be overridden by the
398dffb485Schristosdnl configure option --enable-shared.
408dffb485SchristosAC_DISABLE_SHARED
418dffb485Schristos
428dffb485SchristosLT_INIT
438dffb485SchristosAC_SYS_LARGEFILE
444b169a6bSchristosLT_OUTPUT
458dffb485Schristos
468dffb485SchristosMISSING=`cd $ac_aux_dir && ${PWDCMD-pwd}`/missing
478dffb485SchristosAC_CHECK_PROGS([ACLOCAL], [aclocal], [$MISSING aclocal])
488dffb485SchristosAC_CHECK_PROGS([AUTOCONF], [autoconf], [$MISSING autoconf])
498dffb485SchristosAC_CHECK_PROGS([AUTOHEADER], [autoheader], [$MISSING autoheader])
508dffb485Schristos
518dffb485Schristos# Figure out what compiler warnings we can enable.
528dffb485Schristos# See config/warnings.m4 for details.
538dffb485Schristos
548dffb485SchristosACX_PROG_CC_WARNING_OPTS([-W -Wall -Wno-narrowing -Wwrite-strings \
558dffb485Schristos			  -Wmissing-format-attribute], [warn])
568dffb485SchristosACX_PROG_CC_WARNING_OPTS([-Wstrict-prototypes -Wmissing-prototypes \
578dffb485Schristos			  -Wold-style-definition], [c_warn])
588dffb485SchristosACX_PROG_CC_WARNING_ALMOST_PEDANTIC([-Wno-long-long])
598dffb485Schristos
608dffb485Schristos# Only enable with --enable-werror-always until existing warnings are
618dffb485Schristos# corrected.
628dffb485SchristosACX_PROG_CC_WARNINGS_ARE_ERRORS([manual])
638dffb485Schristos
648dffb485SchristosAM_MAINTAINER_MODE
658dffb485SchristosAM_INSTALL_LIBBFD
668dffb485SchristosACX_PROG_CC_WARNING_OPTS([-Wall], [ac_libctf_warn_cflags])
678dffb485Schristos
68*12989c96SchristosGCC_AC_FUNC_MMAP
698dffb485Schristos# Needed for BFD capability checks.
704b169a6bSchristosAC_SEARCH_LIBS(dlsym, dl)
718dffb485SchristosAM_ZLIB
728dffb485Schristos
738dffb485SchristosGCC_ENABLE([libctf-hash-debugging], [no], [], [Enable expensive debugging of CTF deduplication type hashing])
748dffb485Schristosif test "${enable_libctf_hash_debugging}" = yes; then
758dffb485Schristos    AC_DEFINE(ENABLE_LIBCTF_HASH_DEBUGGING, 1, [Enable expensive debugging of CTF deduplication type hashing])
768dffb485Schristosfi
778dffb485SchristosAM_CONDITIONAL(ENABLE_LIBCTF_HASH_DEBUGGING, test "${enable_libctf_hash_debugging}" = yes)
788dffb485Schristos
798dffb485Schristos# Similar to GDB_AC_CHECK_BFD.
808dffb485SchristosOLD_CFLAGS=$CFLAGS
818dffb485SchristosOLD_LDFLAGS=$LDFLAGS
828dffb485SchristosOLD_LIBS=$LIBS
834b169a6bSchristosOLD_CC=$CC
848dffb485Schristos# Put the old CFLAGS/LDFLAGS last, in case the user's (C|LD)FLAGS
858dffb485Schristos# points somewhere with bfd, with -I/foo/lib and -L/foo/lib.  We
868dffb485Schristos# always want our bfd.
874b169a6bSchristosCC="./libtool --quiet --mode=link $OLD_CC"
888dffb485SchristosCFLAGS="-I${srcdir}/../include -I../bfd -I${srcdir}/../bfd $CFLAGS"
894b169a6bSchristosLDFLAGS="-L../bfd -L../libiberty $LDFLAGS"
908dffb485Schristosintl=`echo $LIBINTL | sed 's,${top_builddir}/,,g'`
914b169a6bSchristosLIBS="-lbfd -liberty $intl $LIBS"
928dffb485SchristosAC_CACHE_CHECK([for ELF support in BFD], ac_cv_libctf_bfd_elf,
938dffb485Schristos[AC_TRY_LINK([#include <stdlib.h>
944b169a6bSchristos	     #include <string.h>
958dffb485Schristos	     #include "bfd.h"
968dffb485Schristos	     #include "elf-bfd.h"],
978dffb485Schristos	    [(void) bfd_section_from_elf_index (NULL, 0);
988dffb485Schristos	     return 0;],
998dffb485Schristos	    [ac_cv_libctf_bfd_elf=yes],
1008dffb485Schristos	    [ac_cv_libctf_bfd_elf=no])])
1018dffb485SchristosCFLAGS=$OLD_CFLAGS
1028dffb485SchristosLDFLAGS=$OLD_LDFLAGS
1038dffb485SchristosLIBS=$OLD_LIBS
1044b169a6bSchristosCC=$OLD_CC
1058dffb485Schristos
1068dffb485Schristosif test $ac_cv_libctf_bfd_elf = yes; then
1078dffb485Schristos  AC_DEFINE([HAVE_BFD_ELF], 1,
1088dffb485Schristos	    [Whether libbfd was configured for an ELF target.])
1098dffb485Schristosfi
1108dffb485Schristos
1118dffb485SchristosAC_C_BIGENDIAN
1128dffb485SchristosAC_CHECK_HEADERS(byteswap.h endian.h)
1138dffb485SchristosAC_CHECK_FUNCS(pread)
1148dffb485Schristos
1158dffb485Schristosdnl Check for bswap_{16,32,64}
1168dffb485SchristosAC_CHECK_DECLS([bswap_16, bswap_32, bswap_64], [], [], [[#include <byteswap.h>]])
1178dffb485SchristosAC_CHECK_DECLS([asprintf, vasprintf, stpcpy])
1188dffb485Schristos
1198dffb485Schristosdnl Check for qsort_r.  (Taken from gnulib.)
1208dffb485SchristosAC_CHECK_FUNCS_ONCE([qsort_r])
1218dffb485Schristosif test $ac_cv_func_qsort_r = yes; then
1228dffb485Schristos  AC_CACHE_CHECK([for qsort_r signature], [ac_cv_libctf_qsort_r_signature],
1238dffb485Schristos    [AC_LINK_IFELSE(
1248dffb485Schristos       [AC_LANG_PROGRAM([[#undef qsort_r
1258dffb485Schristos                          #include <stdlib.h>
1268dffb485Schristos                          void qsort_r (void *, size_t, size_t,
1278dffb485Schristos                                        int (*) (void const *, void const *,
1288dffb485Schristos                                                 void *),
1298dffb485Schristos                                        void *);
1308dffb485Schristos                          void (*p) (void *, size_t, size_t,
1318dffb485Schristos                                     int (*) (void const *, void const *,
1328dffb485Schristos                                              void *),
1338dffb485Schristos                                     void *) = qsort_r;
1348dffb485Schristos                        ]])],
1358dffb485Schristos       [ac_cv_libctf_qsort_r_signature=GNU],
1368dffb485Schristos       [AC_LINK_IFELSE(
1378dffb485Schristos          [AC_LANG_PROGRAM([[#undef qsort_r
1388dffb485Schristos	                     #include <stdlib.h>
1398dffb485Schristos                             void qsort_r (void *, size_t, size_t, void *,
1408dffb485Schristos                                           int (*) (void *,
1418dffb485Schristos                                                    void const *,
1428dffb485Schristos                                                    void const *));
1438dffb485Schristos                             void (*p) (void *, size_t, size_t, void *,
1448dffb485Schristos                                        int (*) (void *, void const *,
1458dffb485Schristos                                                 void const *)) = qsort_r;
1468dffb485Schristos                           ]])],
1478dffb485Schristos          [ac_cv_libctf_qsort_r_signature=BSD],
1488dffb485Schristos          [ac_cv_libctf_qsort_r_signature=unknown])])])
1498dffb485Schristosfi
1508dffb485Schristos
1518dffb485Schristoscase x$ac_cv_libctf_qsort_r_signature in
1528dffb485Schristos  xGNU)     AC_DEFINE([HAVE_QSORT_R_ARG_LAST], 1,
1538dffb485Schristos	     [Whether a qsort_r exists with a void *arg as its last arg.]);;
1548dffb485Schristos  xBSD)     AC_DEFINE([HAVE_QSORT_R_COMPAR_LAST], 1,
1558dffb485Schristos	     [Whether a qsort_r exists with the compar function as its last arg.]);;
1568dffb485Schristos  *) ac_cv_libctf_qsort_r_signature=unknown;;
1578dffb485Schristosesac
1588dffb485Schristos
1598dffb485SchristosAM_CONDITIONAL(NEED_CTF_QSORT_R, test "${ac_cv_libctf_qsort_r_signature}" = unknown)
1608dffb485Schristos
1618dffb485SchristosAC_CACHE_CHECK([for O_CLOEXEC], [ac_cv_libctf_macro_O_CLOEXEC],
1628dffb485Schristos  [AC_LINK_IFELSE(
1638dffb485Schristos    [AC_LANG_PROGRAM([[#include <fcntl.h>
1648dffb485Schristos                       #ifndef O_CLOEXEC
1658dffb485Schristos                         choke me;
1668dffb485Schristos                       #endif
1678dffb485Schristos                     ]],
1688dffb485Schristos                     [[return O_CLOEXEC;]])],
1698dffb485Schristos    [ac_cv_libctf_macro_O_CLOEXEC=yes],
1708dffb485Schristos    [ac_cv_libctf_macro_O_CLOEXEC=no])])
1718dffb485Schristos
1728dffb485Schristosif test $ac_cv_libctf_macro_O_CLOEXEC = yes; then
1738dffb485Schristos  AC_DEFINE([HAVE_O_CLOEXEC], 1,
1748dffb485Schristos	    [Whether the platform has a definition of O_CLOEXEC.])
1758dffb485Schristosfi
1768dffb485Schristos
1774b169a6bSchristosbuild_info=
1784b169a6bSchristosmakeinfo_too_old=
1794b169a6bSchristosAC_CHECK_PROGS([MAKEINFO], makeinfo, [$MISSING makeinfo])
1804b169a6bSchristoscase " $build_configdirs " in
1814b169a6bSchristos  *" texinfo "*) MAKEINFO='$$r/$(BUILD_SUBDIR)/texinfo/makeinfo/makeinfo' ;;
1824b169a6bSchristosesac
1834b169a6bSchristoschangequote(,)
1844b169a6bSchristos    # We require texinfo to be 6.3 or later, for a working synindex
1854b169a6bSchristos    # and validatemenus: otherwise we fall back to /bin/true.
1864b169a6bSchristos    if ${MAKEINFO} --version \
187*12989c96Schristos       | egrep 'texinfo[^0-9]*(6\.[3-9]|[7-9]|[1-6][0-9])' >/dev/null 2>&1; then
1884b169a6bSchristos      build_info=yes
1894b169a6bSchristos    else
1904b169a6bSchristos        build_info=
1914b169a6bSchristos        makeinfo_too_old=t
1924b169a6bSchristos    fi
1934b169a6bSchristoschangequote([,])
1944b169a6bSchristosif test -n "$makeinfo_too_old"; then
1954b169a6bSchristos    AC_MSG_WARN([
1964b169a6bSchristos*** Makeinfo is too old. Info documentation will not be built.])
1974b169a6bSchristosfi
1984b169a6bSchristosAC_SUBST(MAKEINFO)
1994b169a6bSchristosAM_CONDITIONAL(BUILD_INFO, test "${build_info}" = yes)
2004b169a6bSchristos
2014b169a6bSchristosCTF_LIBADD="-L`pwd`/../libiberty -liberty"
2028dffb485SchristosSHARED_LDFLAGS=
2034b169a6bSchristos
2044b169a6bSchristos# Horrible hacks to build DLLs on Windows and a shared library elsewhere.
2058dffb485Schristosif test "$enable_shared" = "yes"; then
2068dffb485Schristos# When building a shared libctf, link against the pic version of libiberty
2078dffb485Schristos# so that apps that use libctf won't need libiberty just to satisfy any
2084b169a6bSchristos# libctf references.  We can't do that if a pic libiberty is unavailable
2094b169a6bSchristos# since including non-pic # code would insert text relocations into libctf.
2108dffb485Schristos# Note that linking against libbfd as we do here, which is itself linked
2118dffb485Schristos# against libiberty, may not satisfy all the libctf libiberty references
2128dffb485Schristos# since libbfd may not pull in the entirety of libiberty.
2134b169a6bSchristos# Also, jam libintl into the right place in all of this: after libiberty,
2144b169a6bSchristos# which uses it, but before -lcygwin, which it uses.
2158dffb485Schristoschangequote(,)dnl
2168dffb485Schristos  x=`sed -n -e 's/^[ 	]*PICFLAG[ 	]*=[ 	]*//p' < ../libiberty/Makefile | sed -n '$p'`
2178dffb485Schristoschangequote([,])dnl
2188dffb485Schristos  if test -n "$x"; then
2194b169a6bSchristos    CTF_LIBADD="-L`pwd`/../libiberty/pic -liberty"
2204b169a6bSchristos  fi
2218dffb485Schristosfi
2228dffb485Schristos
223*12989c96SchristosCTF_LIBADD="$CTF_LIBADD $LTLIBINTL"
2244b169a6bSchristos
2254b169a6bSchristosif test "$enable_shared" = "yes"; then
2268dffb485Schristos  case "${host}" in
2278dffb485Schristos  # More hacks to build DLLs on Windows.
2288dffb485Schristos    *-*-cygwin*)
2298dffb485Schristos      SHARED_LDFLAGS="-no-undefined"
2304b169a6bSchristos      CTF_LIBADD="$CTF_LIBADD -lcygwin"
2318dffb485Schristos      ;;
2328dffb485Schristos  esac
2338dffb485Schristosfi
2348dffb485SchristosAC_SUBST(SHARED_LDFLAGS)
2354b169a6bSchristosAC_SUBST(CTF_LIBADD)
2364b169a6bSchristos
2374b169a6bSchristosAC_PATH_PROG([EXPECT], [expect])
2384b169a6bSchristosAC_CACHE_CHECK([for Tcl supporting try/catch], [ac_cv_libctf_tcl_try],
2394b169a6bSchristos  [ac_cv_libctf_tcl_try=`if test -z $EXPECT; then echo no; else $EXPECT << EOF
2404b169a6bSchristosif @<:@llength @<:@info commands try@:>@@:>@ then { puts yes } else { puts no }
2414b169a6bSchristosEOF
2424b169a6bSchristosfi`
2434b169a6bSchristos])
244*12989c96Schristos
245*12989c96SchristosHAVE_TCL_TRY=false
246*12989c96Schristosif test "${ac_cv_libctf_tcl_try}" = "yes"; then
247*12989c96Schristos    HAVE_TCL_TRY=true
248*12989c96Schristosfi
249*12989c96SchristosAC_SUBST(HAVE_TCL_TRY)
2508dffb485Schristos
2518dffb485Schristos# Use a version script, if possible, or an -export-symbols-regex otherwise.
252*12989c96Schristos# First figure out the version script flag: then massage the script, if
253*12989c96Schristos# needed.
2544b169a6bSchristosdecommented_version_script=
255*12989c96Schristosno_version_script=
2564b169a6bSchristosAC_CACHE_CHECK([for linker versioning flags], [ac_cv_libctf_version_script],
2574b169a6bSchristos  [echo 'FOO { global: mai*; local: ctf_fo*; };' > conftest.ver
2584b169a6bSchristos   old_LDFLAGS="$LDFLAGS"
2594b169a6bSchristos   old_CFLAGS="$CFLAGS"
2604b169a6bSchristos   LDFLAGS="$LDFLAGS -shared -Wl,--version-script=conftest.ver"
2614b169a6bSchristos   CFLAGS="$CFLAGS -fPIC"
2624b169a6bSchristos   AC_LINK_IFELSE([AC_LANG_SOURCE([[int ctf_foo (void) { return 0; }
2634b169a6bSchristos				    int main (void) { return ctf_foo(); }]])],
264*12989c96Schristos		  [ac_cv_libctf_version_script="-Wl,--version-script"],
2654b169a6bSchristos		  [])
2664b169a6bSchristos   LDFLAGS="$old_LDFLAGS"
2674b169a6bSchristos
2684b169a6bSchristos   if test -z "$ac_cv_libctf_version_script"; then
2694b169a6bSchristos     LDFLAGS="$LDFLAGS -shared -Wl,-B,local -Wl,-z,gnu-version-script=conftest.ver"
2704b169a6bSchristos     AC_LINK_IFELSE([AC_LANG_SOURCE([[int ctf_foo (void) { return 0; }
2714b169a6bSchristos				      int main (void) { return ctf_foo(); }]])],
2724b169a6bSchristos		    [ac_cv_libctf_version_script="-Wl,-B,local -Wl,-z,gnu-version-script"
2734b169a6bSchristos		     decommented_version_script=t],
2744b169a6bSchristos		    [])
2754b169a6bSchristos     LDFLAGS="$old_LDFLAGS"
2764b169a6bSchristos   fi
2774b169a6bSchristos   CFLAGS="$old_CFLAGS"
2784b169a6bSchristos
2794b169a6bSchristos   if test -z "$ac_cv_libctf_version_script"; then
2804b169a6bSchristos     ac_cv_libctf_version_script='-export-symbols-regex ctf_.*'
281*12989c96Schristos     no_version_script=t
2824b169a6bSchristos   fi
2834b169a6bSchristos   rm -f conftest.ver])
284*12989c96Schristos
285*12989c96Schristos# Ensure that no symbols exist in the version script for libctf-nobfd.so
286*12989c96Schristos# that do not exist in the shared library itself, since some linkers (Solaris)
287*12989c96Schristos# add such symbols with type NOTYPE, and others (LLVM) complain loudly
288*12989c96Schristos# and fail to link.
289*12989c96Schristosgrep -v 'libctf only' $srcdir/libctf.ver > libctf-nobfd.ver
290*12989c96Schristos
2914b169a6bSchristosif test -n "$decommented_version_script"; then
2924b169a6bSchristos   # Solaris's version scripts use shell-style comments rather than the C-style
2934b169a6bSchristos   # used by GNU ld.  Use cpp to strip the comments out.  (cpp exists under this
2944b169a6bSchristos   # name on all platforms that support ld -z gnu-version-script.)
2954b169a6bSchristos   /lib/cpp < $srcdir/libctf.ver > libctf-decommented.ver
296*12989c96Schristos   /lib/cpp < $srcdir/libctf-nobfd.ver > libctf-nobfd-decommented.ver
2974b169a6bSchristos   VERSION_FLAGS="$ac_cv_libctf_version_script='libctf-decommented.ver'"
2984b169a6bSchristos   VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script='libctf-nobfd-decommented.ver'"
299*12989c96Schristoselif test -z "$no_version_script"; then
300*12989c96Schristos   VERSION_FLAGS="$ac_cv_libctf_version_script='$srcdir/libctf.ver'"
301*12989c96Schristos   VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script='libctf-nobfd.ver'"
3024b169a6bSchristoselse
3034b169a6bSchristos   VERSION_FLAGS="$ac_cv_libctf_version_script"
3044b169a6bSchristos   VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script"
3058dffb485Schristosfi
3068dffb485SchristosAC_SUBST(VERSION_FLAGS)
3074b169a6bSchristosAC_SUBST(VERSION_FLAGS_NOBFD)
3088dffb485Schristos
3098dffb485SchristosAC_CONFIG_FILES(Makefile)
3108dffb485SchristosAC_CONFIG_HEADERS(config.h)
3118dffb485SchristosAC_OUTPUT
3124b169a6bSchristos
3134b169a6bSchristosGNU_MAKE_JOBSERVER
314