Blame m4/ax_compiler_flags_ldflags.m4

Packit 517f8c
# =============================================================================
Packit 517f8c
#  http://www.gnu.org/software/autoconf-archive/ax_compiler_flags_ldflags.html
Packit 517f8c
# =============================================================================
Packit 517f8c
#
Packit 517f8c
# SYNOPSIS
Packit 517f8c
#
Packit 517f8c
#   AX_COMPILER_FLAGS_LDFLAGS([VARIABLE], [IS-RELEASE], [EXTRA-BASE-FLAGS], [EXTRA-YES-FLAGS])
Packit 517f8c
#
Packit 517f8c
# DESCRIPTION
Packit 517f8c
#
Packit 517f8c
#   Add warning flags for the linker to VARIABLE, which defaults to
Packit 517f8c
#   WARN_LDFLAGS.  VARIABLE is AC_SUBST-ed by this macro, but must be
Packit 517f8c
#   manually added to the LDFLAGS variable for each target in the code base.
Packit 517f8c
#
Packit 517f8c
#   This macro depends on the environment set up by AX_COMPILER_FLAGS.
Packit 517f8c
#   Specifically, it uses the value of $ax_enable_compile_warnings to decide
Packit 517f8c
#   which flags to enable.
Packit 517f8c
#
Packit 517f8c
# LICENSE
Packit 517f8c
#
Packit 517f8c
#   Copyright (c) 2014, 2015 Philip Withnall <philip@tecnocode.co.uk>
Packit 517f8c
#
Packit 517f8c
#   Copying and distribution of this file, with or without modification, are
Packit 517f8c
#   permitted in any medium without royalty provided the copyright notice
Packit 517f8c
#   and this notice are preserved.  This file is offered as-is, without any
Packit 517f8c
#   warranty.
Packit 517f8c
Packit 517f8c
#serial 5
Packit 517f8c
Packit 517f8c
AC_DEFUN([AX_COMPILER_FLAGS_LDFLAGS],[
Packit 517f8c
    AX_REQUIRE_DEFINED([AX_APPEND_LINK_FLAGS])
Packit 517f8c
    AX_REQUIRE_DEFINED([AX_APPEND_FLAG])
Packit 517f8c
    AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])
Packit 517f8c
Packit 517f8c
    # Variable names
Packit 517f8c
    m4_define(ax_warn_ldflags_variable,
Packit 517f8c
              [m4_normalize(ifelse([$1],,[WARN_LDFLAGS],[$1]))])
Packit 517f8c
Packit 517f8c
    # Always pass -Werror=unknown-warning-option to get Clang to fail on bad
Packit 517f8c
    # flags, otherwise they are always appended to the warn_ldflags variable,
Packit 517f8c
    # and Clang warns on them for every compilation unit.
Packit 517f8c
    # If this is passed to GCC, it will explode, so the flag must be enabled
Packit 517f8c
    # conditionally.
Packit 517f8c
    AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option],[
Packit 517f8c
        ax_compiler_flags_test="-Werror=unknown-warning-option"
Packit 517f8c
    ],[
Packit 517f8c
        ax_compiler_flags_test=""
Packit 517f8c
    ])
Packit 517f8c
Packit 517f8c
    # Base flags
Packit 517f8c
    AX_APPEND_LINK_FLAGS([ dnl
Packit 517f8c
        -Wl,--no-as-needed dnl
Packit 517f8c
        $3 dnl
Packit 517f8c
    ],ax_warn_ldflags_variable,[$ax_compiler_flags_test])
Packit 517f8c
Packit 517f8c
    AS_IF([test "$ax_enable_compile_warnings" != "no"],[
Packit 517f8c
        # "yes" flags
Packit 517f8c
        AX_APPEND_LINK_FLAGS([$4 $5 $6 $7],
Packit 517f8c
                                ax_warn_ldflags_variable,
Packit 517f8c
                                [$ax_compiler_flags_test])
Packit 517f8c
    ])
Packit 517f8c
    AS_IF([test "$ax_enable_compile_warnings" = "error"],[
Packit 517f8c
        # "error" flags; -Werror has to be appended unconditionally because
Packit 517f8c
        # it's not possible to test for
Packit 517f8c
        #
Packit 517f8c
        # suggest-attribute=format is disabled because it gives too many false
Packit 517f8c
        # positives
Packit 517f8c
        AX_APPEND_LINK_FLAGS([ dnl
Packit 517f8c
            -Wl,--fatal-warnings dnl
Packit 517f8c
        ],ax_warn_ldflags_variable,[$ax_compiler_flags_test])
Packit 517f8c
    ])
Packit 517f8c
Packit 517f8c
    # Substitute the variables
Packit 517f8c
    AC_SUBST(ax_warn_ldflags_variable)
Packit 517f8c
])dnl AX_COMPILER_FLAGS