1 1.1 christos dnl -*- Autoconf -*- 2 1.1 christos dnl Process this file with autoconf to produce a configure script. 3 1.1 christos dnl 4 1.1.1.3 christos dnl Copyright (C) 2019-2024 Free Software Foundation, Inc. 5 1.1 christos dnl 6 1.1 christos dnl This file is free software; you can redistribute it and/or modify 7 1.1 christos dnl it under the terms of the GNU General Public License as published by 8 1.1 christos dnl the Free Software Foundation; either version 2 of the License, or 9 1.1 christos dnl (at your option) any later version. 10 1.1 christos dnl 11 1.1 christos dnl This program is distributed in the hope that it will be useful, 12 1.1 christos dnl but WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.1 christos dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 1.1 christos dnl GNU General Public License for more details. 15 1.1 christos dnl 16 1.1 christos dnl You should have received a copy of the GNU General Public License 17 1.1 christos dnl along with this program; see the file COPYING. If not see 18 1.1 christos dnl <http://www.gnu.org/licenses/>. 19 1.1 christos dnl 20 1.1 christos 21 1.1.1.4 christos AC_PREREQ([2.64]) 22 1.1.1.4 christos AC_INIT([libctf], [1.2.0]) 23 1.1 christos AC_CONFIG_SRCDIR(ctf-impl.h) 24 1.1.1.2 christos AC_CANONICAL_BUILD 25 1.1.1.2 christos AC_CANONICAL_HOST 26 1.1.1.2 christos AC_CANONICAL_TARGET 27 1.1 christos AC_USE_SYSTEM_EXTENSIONS 28 1.1 christos AM_INIT_AUTOMAKE 29 1.1.1.2 christos AM_SILENT_RULES([yes]) 30 1.1 christos 31 1.1 christos # Checks for programs. 32 1.1 christos AC_PROG_MAKE_SET 33 1.1 christos AC_PROG_CC 34 1.1 christos AC_PROG_RANLIB 35 1.1 christos AM_PROG_AR 36 1.1 christos ZW_GNU_GETTEXT_SISTER_DIR 37 1.1 christos 38 1.1 christos dnl Default to a non shared library. This may be overridden by the 39 1.1 christos dnl configure option --enable-shared. 40 1.1 christos AC_DISABLE_SHARED 41 1.1 christos 42 1.1 christos LT_INIT 43 1.1 christos AC_SYS_LARGEFILE 44 1.1.1.2 christos LT_OUTPUT 45 1.1 christos 46 1.1 christos MISSING=`cd $ac_aux_dir && ${PWDCMD-pwd}`/missing 47 1.1 christos AC_CHECK_PROGS([ACLOCAL], [aclocal], [$MISSING aclocal]) 48 1.1 christos AC_CHECK_PROGS([AUTOCONF], [autoconf], [$MISSING autoconf]) 49 1.1 christos AC_CHECK_PROGS([AUTOHEADER], [autoheader], [$MISSING autoheader]) 50 1.1 christos 51 1.1 christos # Figure out what compiler warnings we can enable. 52 1.1 christos # See config/warnings.m4 for details. 53 1.1 christos 54 1.1 christos ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wno-narrowing -Wwrite-strings \ 55 1.1 christos -Wmissing-format-attribute], [warn]) 56 1.1 christos ACX_PROG_CC_WARNING_OPTS([-Wstrict-prototypes -Wmissing-prototypes \ 57 1.1 christos -Wold-style-definition], [c_warn]) 58 1.1 christos ACX_PROG_CC_WARNING_ALMOST_PEDANTIC([-Wno-long-long]) 59 1.1 christos 60 1.1 christos # Only enable with --enable-werror-always until existing warnings are 61 1.1 christos # corrected. 62 1.1 christos ACX_PROG_CC_WARNINGS_ARE_ERRORS([manual]) 63 1.1 christos 64 1.1 christos AM_MAINTAINER_MODE 65 1.1 christos AM_INSTALL_LIBBFD 66 1.1 christos ACX_PROG_CC_WARNING_OPTS([-Wall], [ac_libctf_warn_cflags]) 67 1.1 christos 68 1.1.1.3 christos GCC_AC_FUNC_MMAP 69 1.1 christos # Needed for BFD capability checks. 70 1.1.1.2 christos AC_SEARCH_LIBS(dlsym, dl) 71 1.1 christos AM_ZLIB 72 1.1 christos 73 1.1 christos GCC_ENABLE([libctf-hash-debugging], [no], [], [Enable expensive debugging of CTF deduplication type hashing]) 74 1.1 christos if test "${enable_libctf_hash_debugging}" = yes; then 75 1.1 christos AC_DEFINE(ENABLE_LIBCTF_HASH_DEBUGGING, 1, [Enable expensive debugging of CTF deduplication type hashing]) 76 1.1 christos fi 77 1.1 christos AM_CONDITIONAL(ENABLE_LIBCTF_HASH_DEBUGGING, test "${enable_libctf_hash_debugging}" = yes) 78 1.1 christos 79 1.1 christos # Similar to GDB_AC_CHECK_BFD. 80 1.1 christos OLD_CFLAGS=$CFLAGS 81 1.1 christos OLD_LDFLAGS=$LDFLAGS 82 1.1 christos OLD_LIBS=$LIBS 83 1.1.1.2 christos OLD_CC=$CC 84 1.1 christos # Put the old CFLAGS/LDFLAGS last, in case the user's (C|LD)FLAGS 85 1.1 christos # points somewhere with bfd, with -I/foo/lib and -L/foo/lib. We 86 1.1 christos # always want our bfd. 87 1.1.1.2 christos CC="./libtool --quiet --mode=link $OLD_CC" 88 1.1 christos CFLAGS="-I${srcdir}/../include -I../bfd -I${srcdir}/../bfd $CFLAGS" 89 1.1.1.2 christos LDFLAGS="-L../bfd -L../libiberty $LDFLAGS" 90 1.1 christos intl=`echo $LIBINTL | sed 's,${top_builddir}/,,g'` 91 1.1.1.2 christos LIBS="-lbfd -liberty $intl $LIBS" 92 1.1 christos AC_CACHE_CHECK([for ELF support in BFD], ac_cv_libctf_bfd_elf, 93 1.1 christos [AC_TRY_LINK([#include <stdlib.h> 94 1.1.1.2 christos #include <string.h> 95 1.1 christos #include "bfd.h" 96 1.1 christos #include "elf-bfd.h"], 97 1.1 christos [(void) bfd_section_from_elf_index (NULL, 0); 98 1.1 christos return 0;], 99 1.1 christos [ac_cv_libctf_bfd_elf=yes], 100 1.1 christos [ac_cv_libctf_bfd_elf=no])]) 101 1.1 christos CFLAGS=$OLD_CFLAGS 102 1.1 christos LDFLAGS=$OLD_LDFLAGS 103 1.1 christos LIBS=$OLD_LIBS 104 1.1.1.2 christos CC=$OLD_CC 105 1.1 christos 106 1.1 christos if test $ac_cv_libctf_bfd_elf = yes; then 107 1.1 christos AC_DEFINE([HAVE_BFD_ELF], 1, 108 1.1 christos [Whether libbfd was configured for an ELF target.]) 109 1.1 christos fi 110 1.1 christos 111 1.1 christos AC_C_BIGENDIAN 112 1.1.1.4 christos AC_CHECK_HEADERS(byteswap.h endian.h valgrind/valgrind.h) 113 1.1 christos AC_CHECK_FUNCS(pread) 114 1.1 christos 115 1.1 christos dnl Check for bswap_{16,32,64} 116 1.1 christos AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64], [], [], [[#include <byteswap.h>]]) 117 1.1 christos AC_CHECK_DECLS([asprintf, vasprintf, stpcpy]) 118 1.1 christos 119 1.1 christos dnl Check for qsort_r. (Taken from gnulib.) 120 1.1 christos AC_CHECK_FUNCS_ONCE([qsort_r]) 121 1.1 christos if test $ac_cv_func_qsort_r = yes; then 122 1.1 christos AC_CACHE_CHECK([for qsort_r signature], [ac_cv_libctf_qsort_r_signature], 123 1.1 christos [AC_LINK_IFELSE( 124 1.1 christos [AC_LANG_PROGRAM([[#undef qsort_r 125 1.1 christos #include <stdlib.h> 126 1.1 christos void qsort_r (void *, size_t, size_t, 127 1.1 christos int (*) (void const *, void const *, 128 1.1 christos void *), 129 1.1 christos void *); 130 1.1 christos void (*p) (void *, size_t, size_t, 131 1.1 christos int (*) (void const *, void const *, 132 1.1 christos void *), 133 1.1 christos void *) = qsort_r; 134 1.1 christos ]])], 135 1.1 christos [ac_cv_libctf_qsort_r_signature=GNU], 136 1.1 christos [AC_LINK_IFELSE( 137 1.1 christos [AC_LANG_PROGRAM([[#undef qsort_r 138 1.1 christos #include <stdlib.h> 139 1.1 christos void qsort_r (void *, size_t, size_t, void *, 140 1.1 christos int (*) (void *, 141 1.1 christos void const *, 142 1.1 christos void const *)); 143 1.1 christos void (*p) (void *, size_t, size_t, void *, 144 1.1 christos int (*) (void *, void const *, 145 1.1 christos void const *)) = qsort_r; 146 1.1 christos ]])], 147 1.1 christos [ac_cv_libctf_qsort_r_signature=BSD], 148 1.1 christos [ac_cv_libctf_qsort_r_signature=unknown])])]) 149 1.1 christos fi 150 1.1 christos 151 1.1 christos case x$ac_cv_libctf_qsort_r_signature in 152 1.1 christos xGNU) AC_DEFINE([HAVE_QSORT_R_ARG_LAST], 1, 153 1.1 christos [Whether a qsort_r exists with a void *arg as its last arg.]);; 154 1.1 christos xBSD) AC_DEFINE([HAVE_QSORT_R_COMPAR_LAST], 1, 155 1.1 christos [Whether a qsort_r exists with the compar function as its last arg.]);; 156 1.1 christos *) ac_cv_libctf_qsort_r_signature=unknown;; 157 1.1 christos esac 158 1.1 christos 159 1.1 christos AM_CONDITIONAL(NEED_CTF_QSORT_R, test "${ac_cv_libctf_qsort_r_signature}" = unknown) 160 1.1 christos 161 1.1 christos AC_CACHE_CHECK([for O_CLOEXEC], [ac_cv_libctf_macro_O_CLOEXEC], 162 1.1 christos [AC_LINK_IFELSE( 163 1.1 christos [AC_LANG_PROGRAM([[#include <fcntl.h> 164 1.1 christos #ifndef O_CLOEXEC 165 1.1 christos choke me; 166 1.1 christos #endif 167 1.1 christos ]], 168 1.1 christos [[return O_CLOEXEC;]])], 169 1.1 christos [ac_cv_libctf_macro_O_CLOEXEC=yes], 170 1.1 christos [ac_cv_libctf_macro_O_CLOEXEC=no])]) 171 1.1 christos 172 1.1 christos if test $ac_cv_libctf_macro_O_CLOEXEC = yes; then 173 1.1 christos AC_DEFINE([HAVE_O_CLOEXEC], 1, 174 1.1 christos [Whether the platform has a definition of O_CLOEXEC.]) 175 1.1 christos fi 176 1.1 christos 177 1.1.1.2 christos build_info= 178 1.1.1.2 christos makeinfo_too_old= 179 1.1.1.2 christos AC_CHECK_PROGS([MAKEINFO], makeinfo, [$MISSING makeinfo]) 180 1.1.1.2 christos case " $build_configdirs " in 181 1.1.1.2 christos *" texinfo "*) MAKEINFO='$$r/$(BUILD_SUBDIR)/texinfo/makeinfo/makeinfo' ;; 182 1.1.1.2 christos esac 183 1.1.1.2 christos changequote(,) 184 1.1.1.2 christos # We require texinfo to be 6.3 or later, for a working synindex 185 1.1.1.2 christos # and validatemenus: otherwise we fall back to /bin/true. 186 1.1.1.2 christos if ${MAKEINFO} --version \ 187 1.1.1.3 christos | egrep 'texinfo[^0-9]*(6\.[3-9]|[7-9]|[1-6][0-9])' >/dev/null 2>&1; then 188 1.1.1.2 christos build_info=yes 189 1.1.1.2 christos else 190 1.1.1.2 christos build_info= 191 1.1.1.2 christos makeinfo_too_old=t 192 1.1.1.2 christos fi 193 1.1.1.2 christos changequote([,]) 194 1.1.1.2 christos if test -n "$makeinfo_too_old"; then 195 1.1.1.2 christos AC_MSG_WARN([ 196 1.1.1.2 christos *** Makeinfo is too old. Info documentation will not be built.]) 197 1.1.1.2 christos fi 198 1.1.1.2 christos AC_SUBST(MAKEINFO) 199 1.1.1.2 christos AM_CONDITIONAL(BUILD_INFO, test "${build_info}" = yes) 200 1.1.1.2 christos 201 1.1.1.2 christos CTF_LIBADD="-L`pwd`/../libiberty -liberty" 202 1.1 christos SHARED_LDFLAGS= 203 1.1.1.2 christos 204 1.1.1.2 christos # Horrible hacks to build DLLs on Windows and a shared library elsewhere. 205 1.1 christos if test "$enable_shared" = "yes"; then 206 1.1 christos # When building a shared libctf, link against the pic version of libiberty 207 1.1 christos # so that apps that use libctf won't need libiberty just to satisfy any 208 1.1.1.2 christos # libctf references. We can't do that if a pic libiberty is unavailable 209 1.1.1.2 christos # since including non-pic # code would insert text relocations into libctf. 210 1.1 christos # Note that linking against libbfd as we do here, which is itself linked 211 1.1 christos # against libiberty, may not satisfy all the libctf libiberty references 212 1.1 christos # since libbfd may not pull in the entirety of libiberty. 213 1.1.1.2 christos # Also, jam libintl into the right place in all of this: after libiberty, 214 1.1.1.2 christos # which uses it, but before -lcygwin, which it uses. 215 1.1 christos changequote(,)dnl 216 1.1 christos x=`sed -n -e 's/^[ ]*PICFLAG[ ]*=[ ]*//p' < ../libiberty/Makefile | sed -n '$p'` 217 1.1 christos changequote([,])dnl 218 1.1 christos if test -n "$x"; then 219 1.1.1.2 christos CTF_LIBADD="-L`pwd`/../libiberty/pic -liberty" 220 1.1 christos fi 221 1.1.1.2 christos fi 222 1.1 christos 223 1.1.1.3 christos CTF_LIBADD="$CTF_LIBADD $LTLIBINTL" 224 1.1.1.2 christos 225 1.1.1.2 christos if test "$enable_shared" = "yes"; then 226 1.1 christos case "${host}" in 227 1.1 christos # More hacks to build DLLs on Windows. 228 1.1 christos *-*-cygwin*) 229 1.1 christos SHARED_LDFLAGS="-no-undefined" 230 1.1.1.2 christos CTF_LIBADD="$CTF_LIBADD -lcygwin" 231 1.1 christos ;; 232 1.1 christos esac 233 1.1 christos fi 234 1.1 christos AC_SUBST(SHARED_LDFLAGS) 235 1.1.1.2 christos AC_SUBST(CTF_LIBADD) 236 1.1.1.2 christos 237 1.1.1.2 christos AC_PATH_PROG([EXPECT], [expect]) 238 1.1.1.2 christos AC_CACHE_CHECK([for Tcl supporting try/catch], [ac_cv_libctf_tcl_try], 239 1.1.1.2 christos [ac_cv_libctf_tcl_try=`if test -z $EXPECT; then echo no; else $EXPECT << EOF 240 1.1.1.2 christos if @<:@llength @<:@info commands try@:>@@:>@ then { puts yes } else { puts no } 241 1.1.1.2 christos EOF 242 1.1.1.2 christos fi` 243 1.1.1.2 christos ]) 244 1.1.1.3 christos 245 1.1.1.3 christos HAVE_TCL_TRY=false 246 1.1.1.3 christos if test "${ac_cv_libctf_tcl_try}" = "yes"; then 247 1.1.1.3 christos HAVE_TCL_TRY=true 248 1.1.1.3 christos fi 249 1.1.1.3 christos AC_SUBST(HAVE_TCL_TRY) 250 1.1 christos 251 1.1 christos # Use a version script, if possible, or an -export-symbols-regex otherwise. 252 1.1.1.3 christos # First figure out the version script flag: then massage the script, if 253 1.1.1.3 christos # needed. 254 1.1.1.2 christos decommented_version_script= 255 1.1.1.3 christos no_version_script= 256 1.1.1.2 christos AC_CACHE_CHECK([for linker versioning flags], [ac_cv_libctf_version_script], 257 1.1.1.2 christos [echo 'FOO { global: mai*; local: ctf_fo*; };' > conftest.ver 258 1.1.1.2 christos old_LDFLAGS="$LDFLAGS" 259 1.1.1.2 christos old_CFLAGS="$CFLAGS" 260 1.1.1.2 christos LDFLAGS="$LDFLAGS -shared -Wl,--version-script=conftest.ver" 261 1.1.1.2 christos CFLAGS="$CFLAGS -fPIC" 262 1.1.1.2 christos AC_LINK_IFELSE([AC_LANG_SOURCE([[int ctf_foo (void) { return 0; } 263 1.1.1.2 christos int main (void) { return ctf_foo(); }]])], 264 1.1.1.3 christos [ac_cv_libctf_version_script="-Wl,--version-script"], 265 1.1.1.2 christos []) 266 1.1.1.2 christos LDFLAGS="$old_LDFLAGS" 267 1.1.1.2 christos 268 1.1.1.2 christos if test -z "$ac_cv_libctf_version_script"; then 269 1.1.1.2 christos LDFLAGS="$LDFLAGS -shared -Wl,-B,local -Wl,-z,gnu-version-script=conftest.ver" 270 1.1.1.2 christos AC_LINK_IFELSE([AC_LANG_SOURCE([[int ctf_foo (void) { return 0; } 271 1.1.1.2 christos int main (void) { return ctf_foo(); }]])], 272 1.1.1.2 christos [ac_cv_libctf_version_script="-Wl,-B,local -Wl,-z,gnu-version-script" 273 1.1.1.2 christos decommented_version_script=t], 274 1.1.1.2 christos []) 275 1.1.1.2 christos LDFLAGS="$old_LDFLAGS" 276 1.1.1.2 christos fi 277 1.1.1.2 christos CFLAGS="$old_CFLAGS" 278 1.1.1.2 christos 279 1.1.1.2 christos if test -z "$ac_cv_libctf_version_script"; then 280 1.1.1.2 christos ac_cv_libctf_version_script='-export-symbols-regex ctf_.*' 281 1.1.1.3 christos no_version_script=t 282 1.1.1.2 christos fi 283 1.1.1.2 christos rm -f conftest.ver]) 284 1.1.1.3 christos 285 1.1.1.3 christos # Ensure that no symbols exist in the version script for libctf-nobfd.so 286 1.1.1.3 christos # that do not exist in the shared library itself, since some linkers (Solaris) 287 1.1.1.3 christos # add such symbols with type NOTYPE, and others (LLVM) complain loudly 288 1.1.1.3 christos # and fail to link. 289 1.1.1.3 christos grep -v 'libctf only' $srcdir/libctf.ver > libctf-nobfd.ver 290 1.1.1.3 christos 291 1.1.1.2 christos if test -n "$decommented_version_script"; then 292 1.1.1.2 christos # Solaris's version scripts use shell-style comments rather than the C-style 293 1.1.1.2 christos # used by GNU ld. Use cpp to strip the comments out. (cpp exists under this 294 1.1.1.2 christos # name on all platforms that support ld -z gnu-version-script.) 295 1.1.1.2 christos /lib/cpp < $srcdir/libctf.ver > libctf-decommented.ver 296 1.1.1.3 christos /lib/cpp < $srcdir/libctf-nobfd.ver > libctf-nobfd-decommented.ver 297 1.1.1.2 christos VERSION_FLAGS="$ac_cv_libctf_version_script='libctf-decommented.ver'" 298 1.1.1.2 christos VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script='libctf-nobfd-decommented.ver'" 299 1.1.1.3 christos elif test -z "$no_version_script"; then 300 1.1.1.3 christos VERSION_FLAGS="$ac_cv_libctf_version_script='$srcdir/libctf.ver'" 301 1.1.1.3 christos VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script='libctf-nobfd.ver'" 302 1.1.1.2 christos else 303 1.1.1.2 christos VERSION_FLAGS="$ac_cv_libctf_version_script" 304 1.1.1.2 christos VERSION_FLAGS_NOBFD="$ac_cv_libctf_version_script" 305 1.1 christos fi 306 1.1 christos AC_SUBST(VERSION_FLAGS) 307 1.1.1.2 christos AC_SUBST(VERSION_FLAGS_NOBFD) 308 1.1 christos 309 1.1 christos AC_CONFIG_FILES(Makefile) 310 1.1 christos AC_CONFIG_HEADERS(config.h) 311 1.1 christos AC_OUTPUT 312 1.1.1.2 christos 313 1.1.1.2 christos GNU_MAKE_JOBSERVER 314