1# =========================================================================== 2# http://www.gnu.org/software/autoconf-archive/ax_compiler_flags.html 3# =========================================================================== 4# 5# SYNOPSIS 6# 7# AX_COMPILER_FLAGS([CFLAGS-VARIABLE], [LDFLAGS-VARIABLE], [IS-RELEASE], [EXTRA-BASE-CFLAGS], [EXTRA-YES-CFLAGS], [UNUSED], [UNUSED], [UNUSED], [EXTRA-BASE-LDFLAGS], [EXTRA-YES-LDFLAGS], [UNUSED], [UNUSED], [UNUSED]) 8# 9# DESCRIPTION 10# 11# Check for the presence of an --enable-compile-warnings option to 12# configure, defaulting to "error" in normal operation, or "yes" if 13# IS-RELEASE is equal to "yes". Return the value in the variable 14# $ax_enable_compile_warnings. 15# 16# Depending on the value of --enable-compile-warnings, different compiler 17# warnings are checked to see if they work with the current compiler and, 18# if so, are appended to CFLAGS-VARIABLE and LDFLAGS-VARIABLE. This 19# allows a consistent set of baseline compiler warnings to be used across 20# a code base, irrespective of any warnings enabled locally by individual 21# developers. By standardising the warnings used by all developers of a 22# project, the project can commit to a zero-warnings policy, using -Werror 23# to prevent compilation if new warnings are introduced. This makes 24# catching bugs which are flagged by warnings a lot easier. 25# 26# By providing a consistent --enable-compile-warnings argument across all 27# projects using this macro, continuous integration systems can easily be 28# configured the same for all projects. Automated systems or build 29# systems aimed at beginners may want to pass the --disable-Werror 30# argument to unconditionally prevent warnings being fatal. 31# 32# --enable-compile-warnings can take the values: 33# 34# * no: Base compiler warnings only; not even -Wall. 35# * yes: The above, plus a broad range of useful warnings. 36# * error: The above, plus -Werror so that all warnings are fatal. 37# Use --disable-Werror to override this and disable fatal 38# warnings. 39# 40# The set of base and enabled flags can be augmented using the 41# EXTRA-*-CFLAGS and EXTRA-*-LDFLAGS variables, which are tested and 42# appended to the output variable if --enable-compile-warnings is not 43# "no". Flags should not be disabled using these arguments, as the entire 44# point of AX_COMPILER_FLAGS is to enforce a consistent set of useful 45# compiler warnings on code, using warnings which have been chosen for low 46# false positive rates. If a compiler emits false positives for a 47# warning, a #pragma should be used in the code to disable the warning 48# locally. See: 49# 50# https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas 51# 52# The EXTRA-* variables should only be used to supply extra warning flags, 53# and not general purpose compiler flags, as they are controlled by 54# configure options such as --disable-Werror. 55# 56# IS-RELEASE can be used to disable -Werror when making a release, which 57# is useful for those hairy moments when you just want to get the release 58# done as quickly as possible. Set it to "yes" to disable -Werror. By 59# default, it uses the value of $ax_is_release, so if you are using the 60# AX_IS_RELEASE macro, there is no need to pass this parameter. For 61# example: 62# 63# AX_IS_RELEASE([git-directory]) 64# AX_COMPILER_FLAGS() 65# 66# CFLAGS-VARIABLE defaults to WARN_CFLAGS, and LDFLAGS-VARIABLE defaults 67# to WARN_LDFLAGS. Both variables are AC_SUBST-ed by this macro, but must 68# be manually added to the CFLAGS and LDFLAGS variables for each target in 69# the code base. 70# 71# If C++ language support is enabled with AC_PROG_CXX, which must occur 72# before this macro in configure.ac, warning flags for the C++ compiler 73# are AC_SUBST-ed as WARN_CXXFLAGS, and must be manually added to the 74# CXXFLAGS variables for each target in the code base. EXTRA-*-CFLAGS can 75# be used to augment the base and enabled flags. 76# 77# Warning flags for g-ir-scanner (from GObject Introspection) are 78# AC_SUBST-ed as WARN_SCANNERFLAGS. This variable must be manually added 79# to the SCANNERFLAGS variable for each GIR target in the code base. If 80# extra g-ir-scanner flags need to be enabled, the AX_COMPILER_FLAGS_GIR 81# macro must be invoked manually. 82# 83# AX_COMPILER_FLAGS may add support for other tools in future, in addition 84# to the compiler and linker. No extra EXTRA-* variables will be added 85# for those tools, and all extra support will still use the single 86# --enable-compile-warnings configure option. For finer grained control 87# over the flags for individual tools, use AX_COMPILER_FLAGS_CFLAGS, 88# AX_COMPILER_FLAGS_LDFLAGS and AX_COMPILER_FLAGS_* for new tools. 89# 90# The UNUSED variables date from a previous version of this macro, and are 91# automatically appended to the preceding non-UNUSED variable. They should 92# be left empty in new uses of the macro. 93# 94# LICENSE 95# 96# Copyright (c) 2014, 2015 Philip Withnall <philip@tecnocode.co.uk> 97# Copyright (c) 2015 David King <amigadave@amigadave.com> 98# 99# Copying and distribution of this file, with or without modification, are 100# permitted in any medium without royalty provided the copyright notice 101# and this notice are preserved. This file is offered as-is, without any 102# warranty. 103 104#serial 13 105 106# _AX_COMPILER_FLAGS_LANG([LANGNAME]) 107m4_defun([_AX_COMPILER_FLAGS_LANG], 108[m4_ifdef([_AX_COMPILER_FLAGS_LANG_]$1[_enabled], [], 109 [m4_define([_AX_COMPILER_FLAGS_LANG_]$1[_enabled], [])dnl 110 AX_REQUIRE_DEFINED([AX_COMPILER_FLAGS_]$1[FLAGS])])dnl 111]) 112 113AC_DEFUN([AX_COMPILER_FLAGS],[ 114 # C support is enabled by default. 115 _AX_COMPILER_FLAGS_LANG([C]) 116 # Only enable C++ support if AC_PROG_CXX is called. The redefinition of 117 # AC_PROG_CXX is so that a fatal error is emitted if this macro is called 118 # before AC_PROG_CXX, which would otherwise cause no C++ warnings to be 119 # checked. 120 AC_PROVIDE_IFELSE([AC_PROG_CXX], 121 [_AX_COMPILER_FLAGS_LANG([CXX])], 122 [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[_AX_COMPILER_FLAGS_LANG([CXX])])]) 123 AX_REQUIRE_DEFINED([AX_COMPILER_FLAGS_LDFLAGS]) 124 125 # Default value for IS-RELEASE is $ax_is_release 126 ax_compiler_flags_is_release=m4_tolower(m4_normalize(ifelse([$3],, 127 [$ax_is_release], 128 [$3]))) 129 130 AC_ARG_ENABLE([compile-warnings], 131 AS_HELP_STRING([--enable-compile-warnings=@<:@no/yes/error@:>@], 132 [Enable compiler warnings and errors]),, 133 [AS_IF([test "$ax_compiler_flags_is_release" = "yes"], 134 [enable_compile_warnings="yes"], 135 [enable_compile_warnings="error"])]) 136 AC_ARG_ENABLE([Werror], 137 AS_HELP_STRING([--disable-Werror], 138 [Unconditionally make all compiler warnings non-fatal]),, 139 [enable_Werror=maybe]) 140 141 # Return the user's chosen warning level 142 AS_IF([test "$enable_Werror" = "no" -a \ 143 "$enable_compile_warnings" = "error"],[ 144 enable_compile_warnings="yes" 145 ]) 146 147 ax_enable_compile_warnings=$enable_compile_warnings 148 149 AX_COMPILER_FLAGS_CFLAGS([$1],[$ax_compiler_flags_is_release], 150 [$4],[$5 $6 $7 $8]) 151 m4_ifdef([_AX_COMPILER_FLAGS_LANG_CXX_enabled], 152 [AX_COMPILER_FLAGS_CXXFLAGS([WARN_CXXFLAGS], 153 [$ax_compiler_flags_is_release], 154 [$4],[$5 $6 $7 $8])]) 155 AX_COMPILER_FLAGS_LDFLAGS([$2],[$ax_compiler_flags_is_release], 156 [$9],[$10 $11 $12 $13]) 157 AX_COMPILER_FLAGS_GIR([WARN_SCANNERFLAGS],[$ax_compiler_flags_is_release]) 158])dnl AX_COMPILER_FLAGS 159