Version 3.28.1
[yelp.git] / m4 / ax_compiler_flags_ldflags.m4
blobad845c61ba95f7e0e2f7724365da6591ef11e872
1 # =============================================================================
2 #  http://www.gnu.org/software/autoconf-archive/ax_compiler_flags_ldflags.html
3 # =============================================================================
5 # SYNOPSIS
7 #   AX_COMPILER_FLAGS_LDFLAGS([VARIABLE], [IS-RELEASE], [EXTRA-BASE-FLAGS], [EXTRA-MINIMUM-FLAGS], [EXTRA-YES-FLAGS], [EXTRA-MAXIMUM-FLAGS], [EXTRA-ERROR-FLAGS])
9 # DESCRIPTION
11 #   Add warning flags for the linker to VARIABLE, which defaults to
12 #   WARN_LDFLAGS.  VARIABLE is AC_SUBST-ed by this macro, but must be
13 #   manually added to the LDFLAGS variable for each target in the code base.
15 #   This macro depends on the environment set up by AX_COMPILER_FLAGS.
16 #   Specifically, it uses the value of $ax_enable_compile_warnings to decide
17 #   which flags to enable.
19 # LICENSE
21 #   Copyright (c) 2014, 2015 Philip Withnall <philip@tecnocode.co.uk>
23 #   Copying and distribution of this file, with or without modification, are
24 #   permitted in any medium without royalty provided the copyright notice
25 #   and this notice are preserved.  This file is offered as-is, without any
26 #   warranty.
28 #serial 2
30 AC_DEFUN([AX_COMPILER_FLAGS_LDFLAGS],[
31     AX_REQUIRE_DEFINED([AX_APPEND_COMPILE_FLAGS])
32     AX_REQUIRE_DEFINED([AX_APPEND_FLAG])
33     AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])
35     # Variable names
36     m4_define(ax_warn_ldflags_variable,
37               [m4_normalize(ifelse([$1],,[WARN_LDFLAGS],[$1]))])
39     # Always pass -Werror=unknown-warning-option to get Clang to fail on bad
40     # flags, otherwise they are always appended to the warn_ldflags variable,
41     # and Clang warns on them for every compilation unit.
42     # If this is passed to GCC, it will explode, so the flag must be enabled
43     # conditionally.
44     AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option],[
45         ax_compiler_flags_test="-Werror=unknown-warning-option"
46     ],[
47         ax_compiler_flags_test=""
48     ])
50     # Base flags
51     AX_APPEND_COMPILE_FLAGS([ dnl
52         -Wl,--no-as-needed dnl
53         $3 dnl
54     ],ax_warn_ldflags_variable,[$ax_compiler_flags_test])
56     AS_IF([test "$ax_enable_compile_warnings" != "no"],[
57         # "minimum" flags
58         AX_APPEND_COMPILE_FLAGS([$4],
59                                 ax_warn_ldflags_variable,
60                                 [$ax_compiler_flags_test])
61     ])
62     AS_IF([test "$ax_enable_compile_warnings" != "no" -a \
63                 "$ax_enable_compile_warnings" != "minimum"],[
64         # "yes" flags
65         AX_APPEND_COMPILE_FLAGS([$5],
66                                 ax_warn_ldflags_variable,
67                                 [$ax_compiler_flags_test])
68     ])
69     AS_IF([test "$ax_enable_compile_warnings" = "maximum" -o \
70                 "$ax_enable_compile_warnings" = "error"],[
71         # "maximum" flags
72         AX_APPEND_COMPILE_FLAGS([$6],
73                                 ax_warn_ldflags_variable,
74                                 [$ax_compiler_flags_test])
75     ])
76     AS_IF([test "$ax_enable_compile_warnings" = "error"],[
77         # "error" flags; -Werror has to be appended unconditionally because
78         # it’s not possible to test for
79         #
80         # suggest-attribute=format is disabled because it gives too many false
81         # positives
82         AX_APPEND_COMPILE_FLAGS([ dnl
83             -Wl,--fatal-warnings dnl
84             $7 dnl
85         ],ax_warn_ldflags_variable,[$ax_compiler_flags_test])
86     ])
88     # Substitute the variables
89     AC_SUBST(ax_warn_ldflags_variable)
90 ])dnl AX_COMPILER_FLAGS