Updated Friulian translation
[yelp.git] / m4 / ax_compiler_flags_cflags.m4
blob204f64c7709873caf70a7cc4dab9e80846d49491
1 # ============================================================================
2 #  http://www.gnu.org/software/autoconf-archive/ax_compiler_flags_cflags.html
3 # ============================================================================
5 # SYNOPSIS
7 #   AX_COMPILER_FLAGS_CFLAGS([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 C compiler to VARIABLE, which defaults to
12 #   WARN_CFLAGS.  VARIABLE is AC_SUBST-ed by this macro, but must be
13 #   manually added to the CFLAGS 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 5
30 AC_DEFUN([AX_COMPILER_FLAGS_CFLAGS],[
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_cflags_variable,
37               [m4_normalize(ifelse([$1],,[WARN_CFLAGS],[$1]))])
39     AC_LANG_PUSH([C])
41     # Always pass -Werror=unknown-warning-option to get Clang to fail on bad
42     # flags, otherwise they are always appended to the warn_cflags variable, and
43     # Clang warns on them for every compilation unit.
44     # If this is passed to GCC, it will explode, so the flag must be enabled
45     # conditionally.
46     AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option],[
47         ax_compiler_flags_test="-Werror=unknown-warning-option"
48     ],[
49         ax_compiler_flags_test=""
50     ])
52     # Base flags
53     AX_APPEND_COMPILE_FLAGS([ dnl
54         -fno-strict-aliasing dnl
55         $3 dnl
56     ],ax_warn_cflags_variable,[$ax_compiler_flags_test])
58     # In the flags below, when disabling specific flags, always add *both*
59     # -Wno-foo and -Wno-error=foo. This fixes the situation where (for example)
60     # we enable -Werror, disable a flag, and a build bot passes CFLAGS=-Wall,
61     # which effectively turns that flag back on again as an error.
62     AS_IF([test "$ax_enable_compile_warnings" != "no"],[
63         # "minimum" flags
64         AX_APPEND_COMPILE_FLAGS([ dnl
65             -Wall dnl
66             $4 dnl
67         ],ax_warn_cflags_variable,[$ax_compiler_flags_test])
68     ])
69     AS_IF([test "$ax_enable_compile_warnings" != "no" -a \
70                 "$ax_enable_compile_warnings" != "minimum"],[
71         # "yes" flags
72         AX_APPEND_COMPILE_FLAGS([ dnl
73             -Wextra dnl
74             -Wundef dnl
75             -Wnested-externs dnl
76             -Wwrite-strings dnl
77             -Wpointer-arith dnl
78             -Wmissing-declarations dnl
79             -Wmissing-prototypes dnl
80             -Wstrict-prototypes dnl
81             -Wredundant-decls dnl
82             -Wno-unused-parameter dnl
83             -Wno-error=unused-parameter dnl
84             -Wno-missing-field-initializers dnl
85             -Wno-error=missing-field-initializers dnl
86             -Wdeclaration-after-statement dnl
87             -Wformat=2 dnl
88             -Wold-style-definition dnl
89             -Wcast-align dnl
90             -Wformat-nonliteral dnl
91             -Wformat-security dnl
92             -Wsign-compare dnl
93             -Wstrict-aliasing dnl
94             -Wshadow dnl
95             -Winline dnl
96             -Wpacked dnl
97             -Wmissing-format-attribute dnl
98             -Wmissing-noreturn dnl
99             -Winit-self dnl
100             -Wredundant-decls dnl
101             -Wmissing-include-dirs dnl
102             -Wunused-but-set-variable dnl
103             -Warray-bounds dnl
104             -Wimplicit-function-declaration dnl
105             -Wreturn-type dnl
106             $5 dnl
107         ],ax_warn_cflags_variable,[$ax_compiler_flags_test])
108     ])
109     AS_IF([test "$ax_enable_compile_warnings" = "maximum" -o \
110                 "$ax_enable_compile_warnings" = "error"],[
111         # "maximum" flags
112         AX_APPEND_COMPILE_FLAGS([ dnl
113             -Wswitch-enum dnl
114             -Wswitch-default dnl
115             -Waggregate-return dnl
116             $6 dnl
117         ],ax_warn_cflags_variable,[$ax_compiler_flags_test])
118     ])
119     AS_IF([test "$ax_enable_compile_warnings" = "error"],[
120         # "error" flags; -Werror has to be appended unconditionally because
121         # it’s not possible to test for
122         #
123         # suggest-attribute=format is disabled because it gives too many false
124         # positives
125         AX_APPEND_FLAG([-Werror],ax_warn_cflags_variable)
127         AX_APPEND_COMPILE_FLAGS([ dnl
128             -Wno-suggest-attribute=format dnl
129             $7 dnl
130         ],ax_warn_cflags_variable,[$ax_compiler_flags_test])
131     ])
133     AC_LANG_POP([C])
135     # Substitute the variables
136     AC_SUBST(ax_warn_cflags_variable)
137 ])dnl AX_COMPILER_FLAGS