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