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