2 dnl Process this file with autoconf to produce a configure script.
4 dnl Copyright (C) 2019-2020 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 library], 1.2.0-pre)
23 AC_CONFIG_SRCDIR(ctf-impl.h)
24 AC_CONFIG_MACRO_DIR(../config)
25 AC_CONFIG_MACRO_DIR(../bfd)
26 AC_USE_SYSTEM_EXTENSIONS
29 # Checks for programs.
35 dnl Default to a non shared library. This may be overridden by the
36 dnl configure option --enable-shared.
42 MISSING=`cd $ac_aux_dir && ${PWDCMD-pwd}`/missing
43 AC_CHECK_PROGS([ACLOCAL], [aclocal], [$MISSING aclocal])
44 AC_CHECK_PROGS([AUTOCONF], [autoconf], [$MISSING autoconf])
45 AC_CHECK_PROGS([AUTOHEADER], [autoheader], [$MISSING autoheader])
47 # Figure out what compiler warnings we can enable.
48 # See config/warnings.m4 for details.
50 ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wno-narrowing -Wwrite-strings \
51 -Wmissing-format-attribute], [warn])
52 ACX_PROG_CC_WARNING_OPTS([-Wstrict-prototypes -Wmissing-prototypes \
53 -Wold-style-definition], [c_warn])
54 ACX_PROG_CC_WARNING_ALMOST_PEDANTIC([-Wno-long-long])
56 # Only enable with --enable-werror-always until existing warnings are
58 ACX_PROG_CC_WARNINGS_ARE_ERRORS([manual])
62 ACX_PROG_CC_WARNING_OPTS([-Wall], [ac_libctf_warn_cflags])
65 # Needed for BFD capability checks.
66 AC_SEARCH_LIBS(dlopen, dl)
69 # Similar to GDB_AC_CHECK_BFD.
73 # Put the old CFLAGS/LDFLAGS last, in case the user's (C|LD)FLAGS
74 # points somewhere with bfd, with -I/foo/lib and -L/foo/lib. We
75 # always want our bfd.
76 CFLAGS="-I${srcdir}/../include -I../bfd -I${srcdir}/../bfd $CFLAGS"
77 ZLIBDIR=`echo $zlibdir | sed 's,\$(top_builddir)/,,g'`
78 LDFLAGS="-L../bfd -L../libiberty $ZLIBDIR $LDFLAGS"
79 intl=`echo $LIBINTL | sed 's,${top_builddir}/,,g'`
80 LIBS="-lbfd -liberty -lz $intl $LIBS"
81 AC_CACHE_CHECK([for ELF support in BFD], ac_cv_libctf_bfd_elf,
82 [AC_TRY_LINK([#include <stdlib.h>
84 #include "elf-bfd.h"],
85 [(void) bfd_section_from_elf_index (NULL, 0);
87 [ac_cv_libctf_bfd_elf=yes],
88 [ac_cv_libctf_bfd_elf=no])])
93 if test $ac_cv_libctf_bfd_elf = yes; then
94 AC_DEFINE([HAVE_BFD_ELF], 1,
95 [Whether libbfd was configured for an ELF target.])
99 AC_CHECK_HEADERS(byteswap.h endian.h)
100 AC_CHECK_FUNCS(pread)
102 AC_CHECK_DECLS([asprintf])
104 dnl Check for qsort_r. (Taken from gnulib.)
105 AC_CHECK_FUNCS_ONCE([qsort_r])
106 if test $ac_cv_func_qsort_r = yes; then
107 AC_CACHE_CHECK([for qsort_r signature], [ac_cv_libctf_qsort_r_signature],
109 [AC_LANG_PROGRAM([[#undef qsort_r
111 void qsort_r (void *, size_t, size_t,
112 int (*) (void const *, void const *,
115 void (*p) (void *, size_t, size_t,
116 int (*) (void const *, void const *,
120 [ac_cv_libctf_qsort_r_signature=GNU],
122 [AC_LANG_PROGRAM([[#undef qsort_r
124 void qsort_r (void *, size_t, size_t, void *,
128 void (*p) (void *, size_t, size_t, void *,
129 int (*) (void *, void const *,
130 void const *)) = qsort_r;
132 [ac_cv_libctf_qsort_r_signature=BSD],
133 [ac_cv_libctf_qsort_r_signature=unknown])])])
136 case x$ac_cv_libctf_qsort_r_signature in
137 xGNU) AC_DEFINE([HAVE_QSORT_R_ARG_LAST], 1,
138 [Whether a qsort_r exists with a void *arg as its last arg.]);;
139 xBSD) AC_DEFINE([HAVE_QSORT_R_COMPAR_LAST], 1,
140 [Whether a qsort_r exists with the compar function as its last arg.]);;
141 *) ac_cv_libctf_qsort_r_signature=unknown;;
144 AM_CONDITIONAL(NEED_CTF_QSORT_R, test "${ac_cv_libctf_qsort_r_signature}" = unknown)
146 AC_CACHE_CHECK([for O_CLOEXEC], [ac_cv_libctf_macro_O_CLOEXEC],
148 [AC_LANG_PROGRAM([[#include <fcntl.h>
153 [[return O_CLOEXEC;]])],
154 [ac_cv_libctf_macro_O_CLOEXEC=yes],
155 [ac_cv_libctf_macro_O_CLOEXEC=no])])
157 if test $ac_cv_libctf_macro_O_CLOEXEC = yes; then
158 AC_DEFINE([HAVE_O_CLOEXEC], 1,
159 [Whether the platform has a definition of O_CLOEXEC.])
162 # Horrible hacks to build DLLs on Windows and a shared library elsewhere.
167 if test "$enable_shared" = "yes"; then
168 # When building a shared libctf, link against the pic version of libiberty
169 # so that apps that use libctf won't need libiberty just to satisfy any
171 # We can't do that if a pic libiberty is unavailable since including non-pic
172 # code would insert text relocations into libctf.
173 # Note that linking against libbfd as we do here, which is itself linked
174 # against libiberty, may not satisfy all the libctf libiberty references
175 # since libbfd may not pull in the entirety of libiberty.
177 x=`sed -n -e 's/^[ ]*PICFLAG[ ]*=[ ]*//p' < ../libiberty/Makefile | sed -n '$p'`
179 if test -n "$x"; then
180 SHARED_LIBADD="-L`pwd`/../libiberty/pic -liberty"
184 # More hacks to build DLLs on Windows.
186 SHARED_LDFLAGS="-no-undefined"
187 SHARED_LIBADD="-L`pwd`/../libiberty -liberty -L`pwd`/../intl -lintl -lcygwin"
188 BFD_LIBADD="-L`pwd`/../bfd -lbfd"
192 BFD_LIBADD="-Wl,`pwd`/../bfd/.libs/libbfd.dylib"
193 BFD_DEPENDENCIES="../bfd/libbfd.la"
196 case "$host_vendor" in
198 BFD_LIBADD="-Wl,`pwd`/../bfd/.libs/libbfd.sl"
201 BFD_LIBADD="-Wl,`pwd`/../bfd/.libs/libbfd.so"
204 BFD_DEPENDENCIES="../bfd/libbfd.la"
208 AC_SUBST(SHARED_LDFLAGS)
209 AC_SUBST(SHARED_LIBADD)
211 AC_SUBST(BFD_DEPENDENCIES)
213 # Use a version script, if possible, or an -export-symbols-regex otherwise.
214 VERSION_FLAGS='-export-symbols-regex ctf_.*'
215 if $LD --help 2>&1 | grep -- --version-script >/dev/null; then
216 VERSION_FLAGS="-Wl,--version-script='$srcdir/libctf.ver'"
218 AC_SUBST(VERSION_FLAGS)
220 AC_CONFIG_FILES(Makefile)
221 AC_CONFIG_HEADERS(config.h)