tests: run-low_high_pc.sh: drop redundant 'lx' suffix
[platform/upstream/elfutils.git] / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2 dnl Configure input file for elfutils.                     -*-autoconf-*-
3 dnl
4 dnl Copyright (C) 1996-2019 Red Hat, Inc.
5 dnl Copyright (C) 2022 Mark J. Wielaard <mark@klomp.org>
6 dnl
7 dnl This file is part of elfutils.
8 dnl
9 dnl  This file is free software; you can redistribute it and/or modify
10 dnl  it under the terms of the GNU General Public License as published by
11 dnl  the Free Software Foundation; either version 3 of the License, or
12 dnl  (at your option) any later version.
13 dnl
14 dnl  elfutils is distributed in the hope that it will be useful, but
15 dnl  WITHOUT ANY WARRANTY; without even the implied warranty of
16 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 dnl  GNU General Public License for more details.
18 dnl
19 dnl  You should have received a copy of the GNU General Public License
20 dnl  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 AC_INIT([elfutils],[0.187],[https://sourceware.org/bugzilla],[elfutils],[http://elfutils.org/])
22
23 dnl Workaround for older autoconf < 2.64
24 m4_ifndef([AC_PACKAGE_URL],
25          [AC_DEFINE([PACKAGE_URL], ["http://elfutils.org/"],
26                     [Define to home page for this package])
27           AC_SUBST([PACKAGE_URL], ["http://elfutils.org/"])])
28
29 LIBDEBUGINFOD_SONAME=libdebuginfod.so.1
30 AC_SUBST([LIBDEBUGINFOD_SONAME])
31
32 # We want eu- as default program prefix if none was given by the user.
33 # But if the user explicitly provided --program-prefix="" then pretend
34 # it wasn't set at all (NONE). We want to test this really early before
35 # configure has a chance to use the value.
36
37 if test "x$program_prefix" = "xNONE"; then
38   AC_MSG_NOTICE([No --program-prefix given, using "eu-"])
39   program_prefix="eu-"
40 elif test "x$program_prefix" = "x"; then
41   AC_MSG_NOTICE([Using no program-prefix])
42   program_prefix=NONE
43 fi
44
45 AC_CONFIG_AUX_DIR([config])
46 AC_CONFIG_FILES([config/Makefile])
47
48 AC_COPYRIGHT([Copyright (C) 1996-2022 The elfutils developers.])
49 AC_PREREQ(2.63)                 dnl Minimum Autoconf version required.
50
51 dnl We use GNU make extensions; automake 1.10 defaults to -Wportability.
52 AM_INIT_AUTOMAKE([gnits 1.11 -Wno-portability dist-bzip2 no-dist-gzip parallel-tests])
53 AM_MAINTAINER_MODE
54
55 AM_SILENT_RULES([yes])
56
57 AC_CONFIG_SRCDIR([libelf/libelf.h])
58 AC_CONFIG_FILES([Makefile])
59 AC_CONFIG_HEADERS([config.h])
60
61 dnl The RPM spec file.  We substitute a few values in the file.
62 AC_CONFIG_FILES([elfutils.spec:config/elfutils.spec.in])
63
64 dnl debuginfo-server client & server parts.
65 AC_CONFIG_FILES([debuginfod/Makefile debuginfod/debuginfod.h])
66
67 AC_CANONICAL_HOST
68
69 AC_ARG_ENABLE(deterministic-archives,
70 [AS_HELP_STRING([--enable-deterministic-archives],
71                 [ar and ranlib default to -D behavior])], [
72 if test "${enableval}" = no; then
73   default_ar_deterministic=false
74 else
75   default_ar_deterministic=true
76 fi], [default_ar_deterministic=false])
77 AC_DEFINE_UNQUOTED(DEFAULT_AR_DETERMINISTIC, $default_ar_deterministic,
78                    [Should ar and ranlib use -D behavior by default?])
79
80 AC_ARG_ENABLE([thread-safety],
81 AS_HELP_STRING([--enable-thread-safety],
82                [enable thread safety of libraries EXPERIMENTAL]),
83                use_locks=$enableval, use_locks=no)
84 AM_CONDITIONAL(USE_LOCKS, test "$use_locks" = yes)
85 AS_IF([test "$use_locks" = yes], [AC_DEFINE(USE_LOCKS)])
86 AS_IF([test "$use_locks" = yes],
87       [AC_MSG_WARN([thread-safety is EXPERIMENTAL tests might fail.])])
88
89 AH_TEMPLATE([USE_LOCKS], [Defined if libraries should be thread-safe.])
90
91 AC_PROG_CC_C99
92 AC_PROG_CXX
93 AC_PROG_RANLIB
94 AC_PROG_YACC
95 AM_PROG_LEX
96 # Only available since automake 1.12
97 m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
98 AC_CHECK_TOOL([READELF], [readelf])
99 AC_CHECK_TOOL([NM], [nm])
100
101 AC_CACHE_CHECK([whether gcc supports __attribute__((visibility()))],
102         ac_cv_visibility, [dnl
103 save_CFLAGS="$CFLAGS"
104 CFLAGS="$save_CFLAGS -Werror"
105 AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl
106 int __attribute__((visibility("hidden")))
107 foo (int a)
108 {
109   return a;
110 }])], ac_cv_visibility=yes, ac_cv_visibility=no)
111 CFLAGS="$save_CFLAGS"])
112 if test "$ac_cv_visibility" = "yes"; then
113         AC_DEFINE([HAVE_VISIBILITY], [1],
114                   [Defined if __attribute__((visibility())) is supported])
115 fi
116
117 AC_CACHE_CHECK([whether gcc supports __attribute__((gcc_struct))],
118         ac_cv_gcc_struct, [dnl
119 save_CFLAGS="$CFLAGS"
120 CFLAGS="$save_CFLAGS -Werror"
121 AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl
122 struct test { int x; } __attribute__((gcc_struct));
123 ])], ac_cv_gcc_struct=yes, ac_cv_gcc_struct=no)
124 CFLAGS="$save_CFLAGS"])
125 if test "$ac_cv_gcc_struct" = "yes"; then
126         AC_DEFINE([HAVE_GCC_STRUCT], [1],
127                   [Defined if __attribute__((gcc_struct)) is supported])
128 fi
129
130 AC_CACHE_CHECK([whether gcc supports -fPIC], ac_cv_fpic, [dnl
131 save_CFLAGS="$CFLAGS"
132 CFLAGS="$save_CFLAGS -fPIC -Werror"
133 AC_COMPILE_IFELSE([AC_LANG_SOURCE()], ac_cv_fpic=yes, ac_cv_fpic=no)
134 CFLAGS="$save_CFLAGS"
135 ])
136 if test "$ac_cv_fpic" = "yes"; then
137         fpic_CFLAGS="-fPIC"
138 else
139         fpic_CFLAGS=""
140 fi
141 AC_SUBST([fpic_CFLAGS])
142
143 AC_CACHE_CHECK([whether gcc supports -fPIE], ac_cv_fpie, [dnl
144 save_CFLAGS="$CFLAGS"
145 CFLAGS="$save_CFLAGS -fPIE -Werror"
146 AC_COMPILE_IFELSE([AC_LANG_SOURCE()], ac_cv_fpie=yes, ac_cv_fpie=no)
147 CFLAGS="$save_CFLAGS"
148 ])
149 if test "$ac_cv_fpie" = "yes"; then
150         fpie_CFLAGS="-fPIE"
151 else
152         fpie_CFLAGS=""
153 fi
154 AC_SUBST([fpie_CFLAGS])
155
156 dso_LDFLAGS="-shared"
157
158 ZDEFS_LDFLAGS="-Wl,-z,defs"
159 AC_CACHE_CHECK([whether gcc supports $ZDEFS_LDFLAGS], ac_cv_zdefs, [dnl
160 save_LDFLAGS="$LDFLAGS"
161 LDFLAGS="$ZDEFS_LDFLAGS $save_LDFLAGS"
162 AC_LINK_IFELSE([AC_LANG_PROGRAM()], ac_cv_zdefs=yes, ac_cv_zdefs=no)
163 LDFLAGS="$save_LDFLAGS"
164 ])
165 if test "$ac_cv_zdefs" = "yes"; then
166         dso_LDFLAGS="$dso_LDFLAGS $ZDEFS_LDFLAGS"
167 fi
168
169 # We really want build-ids. Warn and force generating them if gcc was
170 # configure without --enable-linker-build-id
171 AC_CACHE_CHECK([whether the compiler generates build-ids], ac_cv_buildid, [dnl
172 AC_LINK_IFELSE([AC_LANG_PROGRAM()],[ac_cv_buildid=yes; $READELF -n conftest$EXEEXT | grep -q NT_GNU_BUILD_ID || ac_cv_buildid=no],AC_MSG_FAILURE([unexpected compile failure]))])
173 if test "$ac_cv_buildid" = "no"; then
174         AC_MSG_WARN([compiler doesn't generate build-id by default])
175         LDFLAGS="$LDFLAGS -Wl,--build-id"
176 fi
177
178 ZRELRO_LDFLAGS="-Wl,-z,relro"
179 AC_CACHE_CHECK([whether gcc supports $ZRELRO_LDFLAGS], ac_cv_zrelro, [dnl
180 save_LDFLAGS="$LDFLAGS"
181 LDFLAGS="$ZRELRO_LDFLAGS $save_LDFLAGS"
182 AC_LINK_IFELSE([AC_LANG_PROGRAM()], ac_cv_zrelro=yes, ac_cv_zrelro=no)
183 LDFLAGS="$save_LDFLAGS"
184 ])
185 if test "$ac_cv_zrelro" = "yes"; then
186         dso_LDFLAGS="$dso_LDFLAGS $ZRELRO_LDFLAGS"
187 fi
188
189 AC_SUBST([dso_LDFLAGS])
190
191 AC_CACHE_CHECK([for __thread support], ac_cv_tls, [dnl
192 # Use the same flags that we use for our DSOs, so the test is representative.
193 # Some old compiler/linker/libc combinations fail some ways and not others.
194 save_CFLAGS="$CFLAGS"
195 save_LDFLAGS="$LDFLAGS"
196 CFLAGS="$fpic_CFLAGS $CFLAGS"
197 LDFLAGS="$dso_LDFLAGS $LDFLAGS"
198 AC_LINK_IFELSE([dnl
199 AC_LANG_PROGRAM([[#include <stdlib.h>
200 #undef __thread
201 static __thread int a; int foo (int b) { return a + b; }]],
202                 [[exit (foo (0));]])],
203                ac_cv_tls=yes, ac_cv_tls=no)
204 CFLAGS="$save_CFLAGS"
205 LDFLAGS="$save_LDFLAGS"])
206 AS_IF([test "x$ac_cv_tls" != xyes],
207       AC_MSG_ERROR([__thread support required]))
208
209 dnl Before 4.9 gcc doesn't ship stdatomic.h, but the necessary atomics are
210 dnl available by (at least) 4.7. So if the system doesn't have a stdatomic.h we
211 dnl fall back on one copied from FreeBSD that handles the difference.
212 AC_CACHE_CHECK([whether gcc provides stdatomic.h], ac_cv_has_stdatomic,
213   [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <stdatomic.h>]])],
214                      ac_cv_has_stdatomic=yes, ac_cv_has_stdatomic=no)])
215 AM_CONDITIONAL(HAVE_STDATOMIC_H, test "x$ac_cv_has_stdatomic" = xyes)
216 AS_IF([test "x$ac_cv_has_stdatomic" = xyes], [AC_DEFINE(HAVE_STDATOMIC_H)])
217
218 AH_TEMPLATE([HAVE_STDATOMIC_H], [Define to 1 if `stdatomic.h` is provided by the
219                                  system, 0 otherwise.])
220
221 dnl This test must come as early as possible after the compiler configuration
222 dnl tests, because the choice of the file model can (in principle) affect
223 dnl whether functions and headers are available, whether they work, etc.
224 AC_SYS_LARGEFILE
225
226 dnl Older glibc had a broken fts that didn't work with Large File Systems.
227 dnl We want the version that can handler LFS, but include workaround if we
228 dnl get a bad one. Add define to CFLAGS (not AC_DEFINE it) since we need to
229 dnl check it before including config.h (which might define _FILE_OFFSET_BITS).
230 AC_CACHE_CHECK([whether fts.h is bad when included (with LFS)], ac_cv_bad_fts,
231   [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <fts.h>]])],
232                      ac_cv_bad_fts=no, ac_cv_bad_fts=yes)])
233 AS_IF([test "x$ac_cv_bad_fts" = "xyes"],
234       [CFLAGS="$CFLAGS -DBAD_FTS=1" CXXFLAGS="$CXXFLAGS -DBAD_FTS=1"])
235
236 # See if we can add -D_FORTIFY_SOURCE=2 or =3. Don't do it if it is already
237 # (differently) defined or if it generates warnings/errors because we
238 # don't use the right optimisation level (string.h will warn about that).
239 AC_MSG_CHECKING([whether to add -D_FORTIFY_SOURCE=2 or =3 to CFLAGS])
240 case "$CFLAGS" in
241   *-D_FORTIFY_SOURCE=*)
242     AC_MSG_RESULT([no, already there])
243     ;;
244   *)
245     save_CFLAGS="$CFLAGS"
246     # Try 3 first.
247     CFLAGS="-D_FORTIFY_SOURCE=3 $save_CFLAGS -Werror"
248     fortified_cflags=""
249     AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
250       #include <string.h>
251       int main() { return 0; }
252     ]])], [ AC_MSG_RESULT([yes -D_FORTIFY_SOURCE=3])
253             fortified_cflags="-D_FORTIFY_SOURCE=3" ], [])
254
255     # If that didn't work, try 2.
256     if test -z "$fortified_cflags"; then
257       CFLAGS="-D_FORTIFY_SOURCE=2 $save_CFLAGS -Werror"
258       AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
259         #include <string.h>
260         int main() { return 0; }
261       ]])], [ AC_MSG_RESULT([yes -D_FORTIFY_SOURCE=2])
262               fortified_cflags="-D_FORTIFY_SOURCE=2" ],
263               [ AC_MSG_RESULT([no, cannot be used])])
264     fi
265     CFLAGS="$fortified_cflags $save_CFLAGS"
266     CXXFLAGS="$fortified_cflags $CXXFLAGS"
267     ;;
268 esac
269
270 dnl enable debugging of branch prediction.
271 AC_ARG_ENABLE([debugpred],
272 AS_HELP_STRING([--enable-debugpred],[build binaries with support to debug branch prediction]),
273 [use_debugpred=$enableval], [use_debugpred=no])
274 case $use_debugpred in
275  yes) use_debugpred_val=1 ;;
276  *)   use_debugpred_val=0 ;;
277 esac
278 AC_SUBST([DEBUGPRED], $use_debugpred_val)
279
280 dnl Enable gprof support.
281 AC_ARG_ENABLE([gprof],
282 AS_HELP_STRING([--enable-gprof],[build binaries with gprof support]), [use_gprof=$enableval], [use_gprof=no])
283 if test "$use_gprof" = yes; then
284   CFLAGS="$CFLAGS -pg"
285   LDFLAGS="$LDFLAGS -pg"
286 fi
287 AM_CONDITIONAL(GPROF, test "$use_gprof" = yes)
288
289 # Enable gcov support.
290 AC_ARG_ENABLE([gcov],
291 AS_HELP_STRING([--enable-gcov],[build binaries with gcov support]), [use_gcov=$enableval], [use_gcov=no])
292 if test "$use_gcov" = yes; then
293   CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
294   CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage"
295   LDFLAGS="$LDFLAGS -fprofile-arcs"
296   AC_CHECK_PROG([GCOV], [gcov], [gcov])
297   AC_CHECK_PROG([LCOV], [lcov], [lcov])
298   AC_CHECK_PROG([GENHTML], [genhtml], [genhtml])
299 fi
300 AM_CONDITIONAL(GCOV, test "$use_gcov" = yes)
301
302 AC_ARG_ENABLE([sanitize-undefined],
303               AS_HELP_STRING([--enable-sanitize-undefined],
304                              [Use gcc undefined behaviour sanitizer]),
305                              [use_undefined=$enableval], [use_undefined=no])
306 if test "$use_undefined" = yes; then
307   old_CFLAGS="$CFLAGS"
308   old_CXXFLAGS="$CXXFLAGS"
309   # We explicitly use unaligned access when possible (see ALLOW_UNALIGNED)
310   # We want to fail immediately on first error, don't try to recover.
311   CFLAGS="$CFLAGS -fsanitize=undefined -fno-sanitize-recover"
312   CXXFLAGS="$CXXFLAGS -fsanitize=undefined -fno-sanitize-recover"
313   AC_LINK_IFELSE([AC_LANG_SOURCE([int main (int argc, char **argv) { return 0; }])], use_undefined=yes, use_undefined=no)
314   AS_IF([test "x$use_undefined" != xyes],
315         AC_MSG_WARN([gcc undefined behaviour sanitizer not available])
316         CFLAGS="$old_CFLAGS" CXXFLAGS="$old_CXXFLAGS")
317 fi
318 case $use_undefined in
319  yes) check_undefined_val=1 ;;
320  *)   check_undefined_val=0 ;;
321 esac
322 AC_DEFINE_UNQUOTED(CHECK_UNDEFINED, $check_undefined_val,
323                    [Building with -fsanitize=undefined or not])
324
325 AC_ARG_ENABLE([sanitize-address],
326               AS_HELP_STRING([--enable-sanitize-address],
327                              [Use gcc address sanitizer]),
328                              [use_address=$enableval], [use_address=no])
329 if test "$use_address" = yes; then
330   old_CFLAGS="$CFLAGS"
331   old_CXXFLAGS="$CXXFLAGS"
332   old_LDFLAGS="$LDFLAGS"
333   # We want to fail immediately on first error, don't try to recover.
334   CFLAGS="$CFLAGS -fsanitize=address -fno-sanitize-recover"
335   CXXFLAGS="$CXXFLAGS -fsanitize=address -fno-sanitize-recover"
336   # Some compilers don't handle -fsanatize=address correctly with --no-undefined
337   LDFLAGS="-Wl,-z,defs -shared"
338   AC_LINK_IFELSE([AC_LANG_SOURCE([int main (int argc, char **argv) { return 0; }])], use_address=yes, use_address=no)
339   AS_IF([test "x$use_address" != xyes],
340         AC_MSG_WARN([gcc address sanitizer not available])
341         CFLAGS="$old_CFLAGS" CXXFLAGS="$old_CXXFLAGS")
342   LDFLAGS="$old_LDFLAGS"
343 fi
344 AM_CONDITIONAL(USE_ADDRESS_SANITIZER, test "$use_address" = yes)
345
346 AC_ARG_ENABLE([valgrind],
347 AS_HELP_STRING([--enable-valgrind],[run all tests under valgrind]),
348 [use_valgrind=$enableval], [use_valgrind=no])
349 if test "$use_valgrind" = yes; then
350   if test "$use_address" = yes; then
351     AC_MSG_ERROR([cannot enable valgrind and sanitize address together])
352   fi
353   AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no)
354   if test "$HAVE_VALGRIND" = "no"; then
355     AC_MSG_ERROR([valgrind not found])
356   fi
357 fi
358 AM_CONDITIONAL(USE_VALGRIND, test "$use_valgrind" = yes)
359
360 AC_ARG_WITH([valgrind],
361 AS_HELP_STRING([--with-valgrind],[include directory for Valgrind headers]),
362 [with_valgrind_headers=$withval], [with_valgrind_headers=no])
363 if test "x$with_valgrind_headers" != xno; then
364     save_CFLAGS="$CFLAGS"
365     CFLAGS="$CFLAGS -I$with_valgrind_headers"
366     AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
367       #include <valgrind/valgrind.h>
368       int main() { return 0; }
369     ]])], [ HAVE_VALGRIND_HEADERS="yes"
370             CFLAGS="$save_CFLAGS -I$with_valgrind_headers" ],
371           [ AC_MSG_ERROR([invalid valgrind include directory: $with_valgrind_headers]) ])
372 fi
373
374 AC_ARG_ENABLE([valgrind-annotations],
375 AS_HELP_STRING([--enable-valgrind-annotations],[insert extra annotations for better valgrind support]),
376 [use_vg_annotations=$enableval], [use_vg_annotations=no])
377 if test "$use_vg_annotations" = yes; then
378     if test "x$HAVE_VALGRIND_HEADERS" != "xyes"; then
379       AC_MSG_CHECKING([whether Valgrind headers are available])
380       AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
381         #include <valgrind/valgrind.h>
382         int main() { return 0; }
383       ]])], [ AC_MSG_RESULT([yes]) ],
384             [ AC_MSG_ERROR([valgrind annotations requested but no headers are available]) ])
385     fi
386 fi
387 AM_CONDITIONAL(USE_VG_ANNOTATIONS, test "$use_vg_annotations" = yes)
388
389 AC_ARG_ENABLE([install-elfh],
390 AS_HELP_STRING([--enable-install-elfh],[install elf.h in include dir]),
391                [install_elfh=$enableval], [install_elfh=no])
392 AM_CONDITIONAL(INSTALL_ELFH, test "$install_elfh" = yes)
393
394 AM_CONDITIONAL(BUILD_STATIC, [dnl
395 test "$use_gprof" = yes -o "$use_gcov" = yes])
396
397 AC_ARG_ENABLE([tests-rpath],
398 AS_HELP_STRING([--enable-tests-rpath],[build $ORIGIN-using rpath into tests]),
399                [tests_use_rpath=$enableval], [tests_use_rpath=no])
400 AM_CONDITIONAL(TESTS_RPATH, test "$tests_use_rpath" = yes)
401
402 dnl zlib is mandatory.
403 save_LIBS="$LIBS"
404 LIBS=
405 eu_ZIPLIB(zlib,ZLIB,z,gzdirect,gzip)
406 AS_IF([test "x$with_zlib" = xno], [AC_MSG_ERROR([zlib not found but is required])])
407 LIBS="$save_LIBS"
408
409 dnl Test for bzlib and xz/lzma/zstd, gives BZLIB/LZMALIB/ZSTD .am
410 dnl conditional and config.h USE_BZLIB/USE_LZMALIB/USE_ZSTD #define.
411 save_LIBS="$LIBS"
412 LIBS=
413 eu_ZIPLIB(bzlib,BZLIB,bz2,BZ2_bzdopen,bzip2)
414 # We need this since bzip2 doesn't have a pkgconfig file.
415 BZ2_LIB="$LIBS"
416 AC_SUBST([BZ2_LIB])
417 eu_ZIPLIB(lzma,LZMA,lzma,lzma_auto_decoder,[LZMA (xz)])
418 AS_IF([test "x$with_lzma" = xyes], [LIBLZMA="liblzma"], [LIBLZMA=""])
419 AC_SUBST([LIBLZMA])
420 eu_ZIPLIB(zstd,ZSTD,zstd,ZSTD_decompress,[ZSTD (zst)])
421 AS_IF([test "x$with_zstd" = xyes], [LIBZSTD="libzstd"], [LIBLZSTD=""])
422 AC_SUBST([LIBZSTD])
423 zip_LIBS="$LIBS"
424 LIBS="$save_LIBS"
425 AC_SUBST([zip_LIBS])
426
427 AC_CHECK_DECLS([memrchr, rawmemchr],[],[],
428                [#define _GNU_SOURCE
429                 #include <string.h>])
430 AC_CHECK_DECLS([powerof2],[],[],[#include <sys/param.h>])
431 AC_CHECK_DECLS([mempcpy],[],[],
432                [#define _GNU_SOURCE
433                 #include <string.h>])
434 AC_CHECK_DECLS([reallocarray],[],[],
435                [#define _GNU_SOURCE
436                 #include <stdlib.h>])
437
438 AC_CHECK_FUNCS([process_vm_readv mremap])
439
440 AS_IF([test "x$ac_cv_func_mremap" = "xno"],
441       [AC_MSG_WARN([elf_update needs mremap to support ELF_C_RDWR_MMAP])])
442
443 AC_CHECK_HEADERS([error.h])
444 AC_CHECK_HEADERS([err.h])
445
446 old_CFLAGS="$CFLAGS"
447 CFLAGS="$CFLAGS -D_GNU_SOURCE"
448 AC_FUNC_STRERROR_R()
449 CFLAGS="$old_CFLAGS"
450
451 AC_CHECK_LIB([stdc++], [__cxa_demangle], [dnl
452 AC_DEFINE([USE_DEMANGLE], [1], [Defined if demangling is enabled])])
453 AM_CONDITIONAL(DEMANGLE, test "x$ac_cv_lib_stdcpp___cxa_demangle" = "xyes")
454 AS_IF([test "x$ac_cv_lib_stdcpp___cxa_demangle" = "xyes"],
455       [enable_demangler=yes],[enable_demangler=no])
456
457 AC_ARG_ENABLE([textrelcheck],
458 AS_HELP_STRING([--disable-textrelcheck],
459                [Disable textrelcheck being a fatal error]))
460 AM_CONDITIONAL(FATAL_TEXTREL, [test "x$enable_textrelcheck" != "xno"])
461 AS_IF([test "x$enable_textrelcheck" != "xno"],
462       [enable_textrelcheck=yes],[enable_textrelcheck=no])
463
464 AC_ARG_ENABLE([symbol-versioning],
465 AS_HELP_STRING([--disable-symbol-versioning],
466                [Disable symbol versioning in shared objects]))
467
468 AC_CACHE_CHECK([whether symbol versioning is supported], ac_cv_symbol_versioning, [dnl
469 AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl
470 #define NEW_VERSION(name, version) \
471   asm (".symver " #name "," #name "@@@" #version);
472 int foo(int x) { return x + 1; }
473 NEW_VERSION (foo, ELFUTILS_12.12)
474 ])], ac_cv_symbol_versioning=yes, ac_cv_symbol_versioning=no)])
475 if test "$ac_cv_symbol_versioning" = "no"; then
476     if test "x$enable_symbol_versioning" != "xno"; then
477         AC_MSG_ERROR([Symbol versioning is not supported.
478                       Use --disable-symbol-versioning to build without.])
479     fi
480 fi
481
482 AM_CONDITIONAL(SYMBOL_VERSIONING, [test "x$enable_symbol_versioning" != "xno"])
483 AS_IF([test "x$enable_symbol_versioning" = "xno"],
484       [AC_MSG_WARN([Disabling symbol versioning breaks ABI compatibility.])
485        enable_symbol_versioning=no],[enable_symbol_versioning=yes])
486
487 AC_CACHE_CHECK([whether gcc accepts -Wstack-usage], ac_cv_stack_usage, [dnl
488 old_CFLAGS="$CFLAGS"
489 CFLAGS="$CFLAGS -Wstack-usage=262144 -Werror"
490 AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
491                   ac_cv_stack_usage=yes, ac_cv_stack_usage=no)
492 CFLAGS="$old_CFLAGS"])
493 AM_CONDITIONAL(ADD_STACK_USAGE_WARNING, [test "x$ac_cv_stack_usage" != "xno"])
494
495 # -Wlogical-op was too fragile in the past, make sure we get a sane one.
496 AC_CACHE_CHECK([whether gcc has a sane -Wlogical-op], ac_cv_logical_op, [dnl
497 old_CFLAGS="$CFLAGS"
498 CFLAGS="$CFLAGS -Wlogical-op -Werror"
499 AC_COMPILE_IFELSE([AC_LANG_SOURCE(
500         [#define FLAG 1
501         int f (int r, int f) { return (r && (FLAG || (FLAG & f))); }])],
502                   ac_cv_logical_op=yes, ac_cv_logical_op=no)
503 CFLAGS="$old_CFLAGS"])
504 AM_CONDITIONAL(SANE_LOGICAL_OP_WARNING,
505                [test "x$ac_cv_logical_op" != "xno"])
506
507 # -Wduplicated-cond was added by GCC6
508 AC_CACHE_CHECK([whether gcc accepts -Wduplicated-cond], ac_cv_duplicated_cond, [dnl
509 old_CFLAGS="$CFLAGS"
510 CFLAGS="$CFLAGS -Wduplicated-cond -Werror"
511 AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
512                   ac_cv_duplicated_cond=yes, ac_cv_duplicated_cond=no)
513 CFLAGS="$old_CFLAGS"])
514 AM_CONDITIONAL(HAVE_DUPLICATED_COND_WARNING,
515                [test "x$ac_cv_duplicated_cond" != "xno"])
516
517 # -Wnull-dereference was added by GCC6
518 AC_CACHE_CHECK([whether gcc accepts -Wnull-dereference], ac_cv_null_dereference, [dnl
519 old_CFLAGS="$CFLAGS"
520 CFLAGS="$CFLAGS -Wnull-dereference -Werror"
521 AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
522                   ac_cv_null_dereference=yes, ac_cv_null_dereference=no)
523 CFLAGS="$old_CFLAGS"])
524 AM_CONDITIONAL(HAVE_NULL_DEREFERENCE_WARNING,
525                [test "x$ac_cv_null_dereference" != "xno"])
526
527 # -Wimplicit-fallthrough was added by GCC7
528 AC_CACHE_CHECK([whether gcc accepts -Wimplicit-fallthrough], ac_cv_implicit_fallthrough, [dnl
529 old_CFLAGS="$CFLAGS"
530 CFLAGS="$CFLAGS -Wimplicit-fallthrough -Werror"
531 AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
532                   ac_cv_implicit_fallthrough=yes, ac_cv_implicit_fallthrough=no)
533 CFLAGS="$old_CFLAGS"])
534 AM_CONDITIONAL(HAVE_IMPLICIT_FALLTHROUGH_WARNING,
535                [test "x$ac_cv_implicit_fallthrough" != "xno"])
536
537 # Check whether the compiler additionally accepts -Wimplicit-fallthrough=5
538 # GCC accepts this and 5 means "don't parse any fallthrough comments and
539 # only accept the fallthrough attribute"
540 AC_CACHE_CHECK([whether the compiler accepts -Wimplicit-fallthrough=5], ac_cv_implicit_fallthrough_5, [dnl
541 old_CFLAGS="$CFLAGS"
542 CFLAGS="$CFLAGS -Wimplicit-fallthrough=5 -Werror"
543 AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
544                   ac_cv_implicit_fallthrough_5=yes, ac_cv_implicit_fallthrough_5=no)
545 CFLAGS="$old_CFLAGS"])
546 AM_CONDITIONAL(HAVE_IMPLICIT_FALLTHROUGH_5_WARNING,
547                [test "x$ac_cv_implicit_fallthrough_5" != "xno"])
548
549 # Assume the fallthrough attribute is supported if -Wimplict-fallthrough is supported
550 if test "$ac_cv_implicit_fallthrough" = "yes"; then
551         AC_DEFINE([HAVE_FALLTHROUGH], [1],
552                   [Defined if __attribute__((fallthrough)) is supported])
553 fi
554
555 AC_CACHE_CHECK([whether the compiler accepts -Wtrampolines], ac_cv_trampolines, [dnl
556 old_CFLAGS="$CFLAGS"
557 CFLAGS="$CFLAGS -Wtrampolines -Werror"
558 AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
559                   ac_cv_trampolines=yes, ac_cv_trampolines=no)
560 CFLAGS="$old_CFLAGS"])
561 AM_CONDITIONAL(HAVE_TRAMPOLINES_WARNING,
562                [test "x$ac_cv_trampolines" != "xno"])
563
564 AC_CACHE_CHECK([whether the compiler accepts -Wno-packed-not-aligned], ac_cv_no_packed_not_aligned, [dnl
565 old_CFLAGS="$CFLAGS"
566 CFLAGS="$CFLAGS -Wno-packed-not-aligned -Werror"
567 AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
568                   ac_cv_no_packed_not_aligned=yes, ac_cv_no_packed_not_aligned=no)
569 CFLAGS="$old_CFLAGS"])
570 AM_CONDITIONAL(HAVE_NO_PACKED_NOT_ALIGNED_WARNING,
571                [test "x$ac_cv_no_packed_not_aligned" != "xno"])
572
573 saved_LIBS="$LIBS"
574 AC_SEARCH_LIBS([argp_parse], [argp])
575 LIBS="$saved_LIBS"
576 case "$ac_cv_search_argp_parse" in
577         no) AC_MSG_FAILURE([failed to find argp_parse]) ;;
578         -l*) argp_LDADD="$ac_cv_search_argp_parse" ;;
579         *) argp_LDADD= ;;
580 esac
581 AC_SUBST([argp_LDADD])
582
583 saved_LIBS="$LIBS"
584 AC_SEARCH_LIBS([fts_close], [fts])
585 LIBS="$saved_LIBS"
586 case "$ac_cv_search_fts_close" in
587         no) AC_MSG_FAILURE([failed to find fts_close]) ;;
588         -l*) fts_LIBS="$ac_cv_search_fts_close" ;;
589         *) fts_LIBS= ;;
590 esac
591 AC_SUBST([fts_LIBS])
592
593 saved_LIBS="$LIBS"
594 AC_SEARCH_LIBS([_obstack_free], [obstack])
595 LIBS="$saved_LIBS"
596 case "$ac_cv_search__obstack_free" in
597         no) AC_MSG_FAILURE([failed to find _obstack_free]) ;;
598         -l*) obstack_LIBS="$ac_cv_search__obstack_free" ;;
599         *) obstack_LIBS= ;;
600 esac
601 AC_SUBST([obstack_LIBS])
602
603 dnl The directories with content.
604
605 dnl Documentation.
606 AC_CONFIG_FILES([doc/Makefile])
607
608 dnl Support library.
609 AC_CONFIG_FILES([lib/Makefile])
610
611 dnl ELF library.
612 AC_CONFIG_FILES([libelf/Makefile])
613
614 dnl Higher-level ELF support library.
615 AC_CONFIG_FILES([libebl/Makefile])
616
617 dnl DWARF-ELF Lower-level Functions support library.
618 AC_CONFIG_FILES([libdwelf/Makefile])
619
620 dnl DWARF library.
621 AC_CONFIG_FILES([libdw/Makefile])
622
623 dnl Higher-level DWARF support library.
624 AC_CONFIG_FILES([libdwfl/Makefile])
625
626 dnl CPU handling library.
627 AC_CONFIG_FILES([libcpu/Makefile])
628
629 dnl Assembler library.
630 AC_CONFIG_FILES([libasm/Makefile])
631
632 dnl CPU-specific backend libraries.
633 AC_CONFIG_FILES([backends/Makefile])
634
635 dnl Tools.
636 AC_CONFIG_FILES([src/Makefile po/Makefile.in])
637
638 dnl Test suite.
639 AC_CONFIG_FILES([tests/Makefile])
640
641 dnl pkgconfig files
642 AC_CONFIG_FILES([config/libelf.pc config/libdw.pc config/libdebuginfod.pc])
643
644 dnl As long as "git grep 'PRI[diouxX]' po" reports matches in
645 dnl translatable strings, we must use need-formatstring-macros here.
646 AM_GNU_GETTEXT([external], [need-formatstring-macros])
647
648 dnl AM_GNU_GETTEXT_VERSION is still needed for old versions
649 dnl of autoreconf that do not recognize AM_GNU_GETTEXT_REQUIRE_VERSION.
650 dnl 0.19.6 is the first version of gettext that provides
651 dnl AM_GNU_GETTEXT_REQUIRE_VERSION support.
652 AM_GNU_GETTEXT_VERSION([0.19.6])
653 AM_GNU_GETTEXT_REQUIRE_VERSION([0.19.6])
654
655 dnl Appended to the config.h file.
656 dnl We hide all kinds of configuration magic in lib/eu-config.h.
657 AH_BOTTOM([#include <eu-config.h>])
658
659 dnl Version compatibility header.
660 AC_CONFIG_FILES([version.h:config/version.h.in])
661 AC_SUBST([eu_version])
662
663 # 1.234<whatever> -> 1234<whatever>
664 case "$PACKAGE_VERSION" in
665 [[0-9]].*) eu_version=`echo "$PACKAGE_VERSION" | sed 's@\.@@'` ;;
666 *)         AC_MSG_ERROR([confused by version number '$PACKAGE_VERSION']) ;;
667 esac
668 case "$eu_version" in
669 *.*)
670   # 1234.567 -> "1234", "567"
671   eu_extra_version="${eu_version#*.}"
672   eu_version="${eu_version%%.*}"
673   case "$eu_extra_version" in
674   [[0-9]][[0-9]][[0-9]]) ;;
675   [[0-9]][[0-9]])       eu_extra_version="${eu_extra_version}0" ;;
676   [[0-9]])              eu_extra_version="${eu_extra_version}00" ;;
677   *) AC_MSG_ERROR([confused by version number '$PACKAGE_VERSION']) ;;
678   esac
679   ;;
680 *)
681   eu_extra_version=000
682   ;;
683 esac
684
685 case "$eu_version" in
686       0[[0-9]][[0-9]][[0-9]]) eu_version="${eu_version#0}$eu_extra_version" ;;
687 [[0-9]][[0-9]][[0-9]][[0-9]]) eu_version="${eu_version}$eu_extra_version" ;;
688 [[0-9]][[0-9]][[0-9]])        eu_version="${eu_version}0$eu_extra_version" ;;
689 [[0-9]][[0-9]])               eu_version="${eu_version}00$eu_extra_version";;
690 *) AC_MSG_ERROR([confused by version number '$PACKAGE_VERSION']) ;;
691 esac
692
693 # Round up to the next release API (x.y) version.
694 eu_version=$(( (eu_version + 999) / 1000 ))
695
696 AC_CHECK_SIZEOF(long)
697
698 # On aarch64 before glibc 2.20 we would get the kernel user_pt_regs instead
699 # of the user_regs_struct from sys/user.h. They are structurally the same
700 # but we get either one or the other.
701 AC_CHECK_TYPE([struct user_regs_struct],
702               [sys_user_has_user_regs=yes], [sys_user_has_user_regs=no],
703               [[#include <sys/ptrace.h>]
704                [#include <sys/time.h>]
705                [#include <sys/user.h>]])
706 if test "$sys_user_has_user_regs" = "yes"; then
707   AC_DEFINE(HAVE_SYS_USER_REGS, 1,
708             [Define to 1 if <sys/user.h> defines struct user_regs_struct])
709 fi
710
711 # On a 64-bit host where can can use $CC -m32, we'll run two sets of tests.
712 utrace_BIARCH
713 CC_BIARCH="$CC $utrace_biarch"
714 AC_SUBST([CC_BIARCH])
715
716 # In maintainer mode we really need flex and bison.
717 # Otherwise we really need a release dir with maintainer files generated.
718 if test "x$enable_maintainer_mode" = xyes; then
719   AC_CHECK_PROG(HAVE_FLEX, flex, yes, no)
720   if test "$HAVE_FLEX" = "no"; then
721     AC_MSG_ERROR([flex needed in maintainer mode])
722   fi
723   AC_CHECK_PROG(HAVE_BISON, bison, yes, no)
724   if test "$HAVE_BISON" = "no"; then
725     AC_MSG_ERROR([bison needed in maintainer mode])
726   fi
727   AC_CHECK_PROG(HAVE_GAWK, gawk, yes, no)
728   if test "$HAVE_GAWK" = "no"; then
729     AC_MSG_ERROR([gawk needed in maintainer mode])
730   fi
731 else
732   if test ! -f ${srcdir}/libdw/known-dwarf.h; then
733     AC_MSG_ERROR([No libdw/known-dwarf.h. configure --enable-maintainer-mode])
734   fi
735 fi
736
737 # The testfiles are all compressed, we need bunzip2 when running make check
738 AC_CHECK_PROG(HAVE_BUNZIP2, bunzip2, yes, no)
739 if test "$HAVE_BUNZIP2" = "no"; then
740   AC_MSG_WARN([No bunzip2, needed to run make check])
741 fi
742
743 # For tests that need to use zstd compression
744 AC_CHECK_PROG(HAVE_ZSTD, zstd, yes, no)
745 AM_CONDITIONAL([HAVE_ZSTD],[test "x$HAVE_ZSTD" = "xyes"])
746
747 # Look for libcurl for libdebuginfod minimum version as per rhel7.
748 AC_ARG_ENABLE([libdebuginfod],AS_HELP_STRING([--enable-libdebuginfod], [Build debuginfod client library (can be =dummy)]))
749 AS_IF([test "x$enable_libdebuginfod" != "xno"], [
750     if test "x$enable_libdebuginfod" != "xdummy"; then
751       AC_MSG_NOTICE([checking libdebuginfod dependencies, --disable-libdebuginfod or --enable-libdebuginfo=dummy to skip])
752       enable_libdebuginfod=yes # presume success
753       PKG_PROG_PKG_CONFIG
754       PKG_CHECK_MODULES([libcurl],[libcurl >= 7.29.0],[],[enable_libdebuginfod=no])
755       if test "x$enable_libdebuginfod" = "xno"; then
756         AC_MSG_ERROR([dependencies not found, use --disable-libdebuginfod to disable or --enable-libdebuginfod=dummy to build a (bootstrap) dummy library.])
757       fi
758     else
759       AC_MSG_NOTICE([building (bootstrap) dummy libdebuginfo library])
760     fi
761 ])
762
763 AC_CHECK_LIB(pthread, pthread_setname_np, [
764                       AC_DEFINE([HAVE_PTHREAD_SETNAME_NP],[1],[Enable pthread_setname_np])])
765
766 AS_IF([test "x$enable_libdebuginfod" = "xyes" || test "x$enable_libdebuginfod" = "xdummy"],
767       [AC_DEFINE([ENABLE_LIBDEBUGINFOD], [1], [Enable libdebuginfod])])
768 AS_IF([test "x$enable_libdebuginfod" = "xdummy"],
769       [AC_DEFINE([DUMMY_LIBDEBUGINFOD], [1], [Build dummy libdebuginfod])])
770 AM_CONDITIONAL([LIBDEBUGINFOD],[test "x$enable_libdebuginfod" = "xyes" || test "x$enable_libdebuginfod" = "xdummy"])
771 AM_CONDITIONAL([DUMMY_LIBDEBUGINFOD],[test "x$enable_libdebuginfod" = "xdummy"])
772
773 # Look for libmicrohttpd, libarchive, sqlite for debuginfo server
774 # minimum versions as per rhel7.
775 AC_ARG_ENABLE([debuginfod],AS_HELP_STRING([--enable-debuginfod], [Build debuginfod server]))
776 AS_IF([test "x$enable_debuginfod" != "xno"], [
777     AC_MSG_NOTICE([checking debuginfod C++11 support, --disable-debuginfod to skip])
778     AX_CXX_COMPILE_STDCXX(11, noext, mandatory)
779     AC_MSG_NOTICE([checking debuginfod dependencies, --disable-debuginfod to skip])
780     if test "x$enable_libdebuginfod" = "xno"; then
781       AC_MSG_ERROR([need libdebuginfod (or dummy), use --disable-debuginfod to disable.])
782     fi
783     enable_debuginfod=yes # presume success
784     PKG_PROG_PKG_CONFIG
785     PKG_CHECK_MODULES([libmicrohttpd],[libmicrohttpd >= 0.9.33],[],[enable_debuginfod=no])
786     PKG_CHECK_MODULES([oldlibmicrohttpd],[libmicrohttpd < 0.9.51],[old_libmicrohttpd=yes],[old_libmicrohttpd=no])
787     PKG_CHECK_MODULES([sqlite3],[sqlite3 >= 3.7.17],[],[enable_debuginfod=no])
788     PKG_CHECK_MODULES([libarchive],[libarchive >= 3.1.2],[],[enable_debuginfod=no])
789     if test "x$enable_debuginfod" = "xno"; then
790       AC_MSG_ERROR([dependencies not found, use --disable-debuginfod to disable.])
791     fi
792 ])
793
794 AS_IF([test "x$enable_debuginfod" != "xno"],AC_DEFINE([ENABLE_DEBUGINFOD],[1],[Build debuginfod]))
795 AM_CONDITIONAL([DEBUGINFOD],[test "x$enable_debuginfod" = "xyes"])
796 AM_CONDITIONAL([OLD_LIBMICROHTTPD],[test "x$old_libmicrohttpd" = "xyes"])
797
798 dnl for /etc/profile.d/elfutils.{csh,sh}
799 default_debuginfod_urls=""
800 AC_ARG_ENABLE(debuginfod-urls,
801             [AS_HELP_STRING([--enable-debuginfod-urls@<:@=URLS@:>@],[add URLS to profile.d DEBUGINFOD_URLS])],
802             [if test "x${enableval}" = "xyes";
803              then default_debuginfod_urls="https://debuginfod.elfutils.org/";
804              elif test "x${enableval}" != "xno"; then
805              default_debuginfod_urls="${enableval}";
806              fi],
807             [default_debuginfod_urls=""])
808 AC_SUBST(DEBUGINFOD_URLS, $default_debuginfod_urls)                
809 AC_CONFIG_FILES([config/profile.sh config/profile.csh])
810
811 AC_OUTPUT
812
813 AC_MSG_NOTICE([
814 =====================================================================
815         elfutils: ${PACKAGE_VERSION} (eu_version: ${eu_version})
816 =====================================================================
817
818     Prefix                             : ${prefix}
819     Program prefix ("eu-" recommended) : ${program_prefix}
820     Source code location               : ${srcdir}
821     Maintainer mode                    : ${enable_maintainer_mode}
822     build arch                         : ${ac_cv_build}
823
824     CFLAGS=${CFLAGS}
825     CXXFLAGS=${CXXFLAGS}
826
827   RECOMMENDED FEATURES (should all be yes)
828     gzip support                       : ${with_zlib}
829     bzip2 support                      : ${with_bzlib}
830     lzma/xz support                    : ${with_lzma}
831     zstd support                       : ${with_zstd}
832     libstdc++ demangle support         : ${enable_demangler}
833     File textrel check                 : ${enable_textrelcheck}
834     Symbol versioning                  : ${enable_symbol_versioning}
835
836   NOT RECOMMENDED FEATURES (should all be no)
837     Experimental thread safety         : ${use_locks}
838     install elf.h                      : ${install_elfh}
839
840   OTHER FEATURES
841     Deterministic archives by default  : ${default_ar_deterministic}
842     Native language support            : ${USE_NLS}
843     Extra Valgrind annotations         : ${use_vg_annotations}
844     libdebuginfod client support       : ${enable_libdebuginfod}
845     Debuginfod server support          : ${enable_debuginfod}
846     Default DEBUGINFOD_URLS            : ${default_debuginfod_urls}
847
848   EXTRA TEST FEATURES (used with make check)
849     have bunzip2 installed (required)  : ${HAVE_BUNZIP2}
850     have zstd installed                : ${HAVE_ZSTD}
851     debug branch prediction            : ${use_debugpred}
852     gprof support                      : ${use_gprof}
853     gcov support                       : ${use_gcov}
854     run all tests under valgrind       : ${use_valgrind}
855     gcc undefined behaviour sanitizer  : ${use_undefined}
856     gcc address sanitizer              : ${use_address}
857     use rpath in tests                 : ${tests_use_rpath}
858     test biarch                        : ${utrace_cv_cc_biarch}
859 ])
860
861 if test "$install_elfh" = yes; then
862   if test "${prefix}" = "/usr/local" -o "${prefix}" = "/usr"; then
863     AC_MSG_WARN([installing elf.h in ${includedir} might conflict with glibc/system elf.h])
864   fi
865 fi