Blame m4/ax_compiler_flags_cflags.m4

Packit 130fc8
# ============================================================================
Packit 130fc8
#  http://www.gnu.org/software/autoconf-archive/ax_compiler_flags_cflags.html
Packit 130fc8
# ============================================================================
Packit 130fc8
#
Packit 130fc8
# SYNOPSIS
Packit 130fc8
#
Packit 130fc8
#   AX_COMPILER_FLAGS_CFLAGS([VARIABLE], [IS-RELEASE], [EXTRA-BASE-FLAGS], [EXTRA-YES-FLAGS])
Packit 130fc8
#
Packit 130fc8
# DESCRIPTION
Packit 130fc8
#
Packit 130fc8
#   Add warning flags for the C compiler to VARIABLE, which defaults to
Packit 130fc8
#   WARN_CFLAGS.  VARIABLE is AC_SUBST-ed by this macro, but must be
Packit 130fc8
#   manually added to the CFLAGS variable for each target in the code base.
Packit 130fc8
#
Packit 130fc8
#   This macro depends on the environment set up by AX_COMPILER_FLAGS.
Packit 130fc8
#   Specifically, it uses the value of $ax_enable_compile_warnings to decide
Packit 130fc8
#   which flags to enable.
Packit 130fc8
#
Packit 130fc8
# LICENSE
Packit 130fc8
#
Packit 130fc8
#   Copyright (c) 2014, 2015 Philip Withnall <philip@tecnocode.co.uk>
Packit 130fc8
#
Packit 130fc8
#   Copying and distribution of this file, with or without modification, are
Packit 130fc8
#   permitted in any medium without royalty provided the copyright notice
Packit 130fc8
#   and this notice are preserved.  This file is offered as-is, without any
Packit 130fc8
#   warranty.
Packit 130fc8
Packit 130fc8
#serial 11
Packit 130fc8
Packit 130fc8
AC_DEFUN([AX_COMPILER_FLAGS_CFLAGS],[
Packit 130fc8
    AC_REQUIRE([AC_PROG_SED])
Packit 130fc8
    AX_REQUIRE_DEFINED([AX_APPEND_COMPILE_FLAGS])
Packit 130fc8
    AX_REQUIRE_DEFINED([AX_APPEND_FLAG])
Packit 130fc8
    AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])
Packit 130fc8
Packit 130fc8
    # Variable names
Packit 130fc8
    m4_define(ax_warn_cflags_variable,
Packit 130fc8
              [m4_normalize(ifelse([$1],,[WARN_CFLAGS],[$1]))])
Packit 130fc8
Packit 130fc8
    AC_LANG_PUSH([C])
Packit 130fc8
Packit 130fc8
    # Always pass -Werror=unknown-warning-option to get Clang to fail on bad
Packit 130fc8
    # flags, otherwise they are always appended to the warn_cflags variable, and
Packit 130fc8
    # Clang warns on them for every compilation unit.
Packit 130fc8
    # If this is passed to GCC, it will explode, so the flag must be enabled
Packit 130fc8
    # conditionally.
Packit 130fc8
    AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option],[
Packit 130fc8
        ax_compiler_flags_test="-Werror=unknown-warning-option"
Packit 130fc8
    ],[
Packit 130fc8
        ax_compiler_flags_test=""
Packit 130fc8
    ])
Packit 130fc8
Packit 130fc8
    # Base flags
Packit 130fc8
    AX_APPEND_COMPILE_FLAGS([ dnl
Packit 130fc8
        -fno-strict-aliasing dnl
Packit 130fc8
        $3 dnl
Packit 130fc8
    ],ax_warn_cflags_variable,[$ax_compiler_flags_test])
Packit 130fc8
Packit 130fc8
    AS_IF([test "$ax_enable_compile_warnings" != "no"],[
Packit 130fc8
        # "yes" flags
Packit 130fc8
        AX_APPEND_COMPILE_FLAGS([ dnl
Packit 130fc8
            -Wall dnl
Packit 130fc8
            -Wextra dnl
Packit 130fc8
            -Wundef dnl
Packit 130fc8
            -Wnested-externs dnl
Packit 130fc8
            -Wwrite-strings dnl
Packit 130fc8
            -Wpointer-arith dnl
Packit 130fc8
            -Wmissing-declarations dnl
Packit 130fc8
            -Wmissing-prototypes dnl
Packit 130fc8
            -Wstrict-prototypes dnl
Packit 130fc8
            -Wredundant-decls dnl
Packit 130fc8
            -Wno-unused-parameter dnl
Packit 130fc8
            -Wno-missing-field-initializers dnl
Packit 130fc8
            -Wdeclaration-after-statement dnl
Packit 130fc8
            -Wformat=2 dnl
Packit 130fc8
            -Wold-style-definition dnl
Packit 130fc8
            -Wcast-align dnl
Packit 130fc8
            -Wformat-nonliteral dnl
Packit 130fc8
            -Wformat-security dnl
Packit 130fc8
            -Wsign-compare dnl
Packit 130fc8
            -Wstrict-aliasing dnl
Packit 130fc8
            -Wshadow dnl
Packit 130fc8
            -Winline dnl
Packit 130fc8
            -Wpacked dnl
Packit 130fc8
            -Wmissing-format-attribute dnl
Packit 130fc8
            -Wmissing-noreturn dnl
Packit 130fc8
            -Winit-self dnl
Packit 130fc8
            -Wredundant-decls dnl
Packit 130fc8
            -Wmissing-include-dirs dnl
Packit 130fc8
            -Wunused-but-set-variable dnl
Packit 130fc8
            -Warray-bounds dnl
Packit 130fc8
            -Wimplicit-function-declaration dnl
Packit 130fc8
            -Wreturn-type dnl
Packit 130fc8
            -Wswitch-enum dnl
Packit 130fc8
            -Wswitch-default dnl
Packit 130fc8
            $4 dnl
Packit 130fc8
            $5 dnl
Packit 130fc8
            $6 dnl
Packit 130fc8
            $7 dnl
Packit 130fc8
        ],ax_warn_cflags_variable,[$ax_compiler_flags_test])
Packit 130fc8
    ])
Packit 130fc8
    AS_IF([test "$ax_enable_compile_warnings" = "error"],[
Packit 130fc8
        # "error" flags; -Werror has to be appended unconditionally because
Packit 130fc8
        # it's not possible to test for
Packit 130fc8
        #
Packit 130fc8
        # suggest-attribute=format is disabled because it gives too many false
Packit 130fc8
        # positives
Packit 130fc8
        AX_APPEND_FLAG([-Werror],ax_warn_cflags_variable)
Packit 130fc8
Packit 130fc8
        AX_APPEND_COMPILE_FLAGS([ dnl
Packit 130fc8
            -Wno-suggest-attribute=format dnl
Packit 130fc8
        ],ax_warn_cflags_variable,[$ax_compiler_flags_test])
Packit 130fc8
    ])
Packit 130fc8
Packit 130fc8
    # In the flags below, when disabling specific flags, always add *both*
Packit 130fc8
    # -Wno-foo and -Wno-error=foo. This fixes the situation where (for example)
Packit 130fc8
    # we enable -Werror, disable a flag, and a build bot passes CFLAGS=-Wall,
Packit 130fc8
    # which effectively turns that flag back on again as an error.
Packit 130fc8
    for flag in $ax_warn_cflags_variable; do
Packit 130fc8
        AS_CASE([$flag],
Packit 130fc8
                [-Wno-*=*],[],
Packit 130fc8
                [-Wno-*],[
Packit 130fc8
                    AX_APPEND_COMPILE_FLAGS([-Wno-error=$(AS_ECHO([$flag]) | $SED 's/^-Wno-//')],
Packit 130fc8
                                            ax_warn_cflags_variable,
Packit 130fc8
                                            [$ax_compiler_flags_test])
Packit 130fc8
                ])
Packit 130fc8
    done
Packit 130fc8
Packit 130fc8
    AC_LANG_POP([C])
Packit 130fc8
Packit 130fc8
    # Substitute the variables
Packit 130fc8
    AC_SUBST(ax_warn_cflags_variable)
Packit 130fc8
])dnl AX_COMPILER_FLAGS