842e329eb31ea175cc6de0c257381e97d1d1e15c
[platform/upstream/pygobject2.git] / m4 / ax_compiler_flags_ldflags.m4
1 # ==============================================================================
2 #  https://www.gnu.org/software/autoconf-archive/ax_compiler_flags_ldflags.html
3 # ==============================================================================
4 #
5 # SYNOPSIS
6 #
7 #   AX_COMPILER_FLAGS_LDFLAGS([VARIABLE], [IS-RELEASE], [EXTRA-BASE-FLAGS], [EXTRA-YES-FLAGS])
8 #
9 # DESCRIPTION
10 #
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.
14 #
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.
18 #
19 # LICENSE
20 #
21 #   Copyright (c) 2014, 2015 Philip Withnall <philip@tecnocode.co.uk>
22 #
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.
27
28 #serial 8
29
30 AC_DEFUN([AX_COMPILER_FLAGS_LDFLAGS],[
31     AX_REQUIRE_DEFINED([AX_APPEND_LINK_FLAGS])
32     AX_REQUIRE_DEFINED([AX_APPEND_FLAG])
33     AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])
34     AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG])
35
36     # Variable names
37     m4_define([ax_warn_ldflags_variable],
38               [m4_normalize(ifelse([$1],,[WARN_LDFLAGS],[$1]))])
39
40     # Always pass -Werror=unknown-warning-option to get Clang to fail on bad
41     # flags, otherwise they are always appended to the warn_ldflags variable,
42     # and Clang warns on them for every compilation unit.
43     # If this is passed to GCC, it will explode, so the flag must be enabled
44     # conditionally.
45     AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option],[
46         ax_compiler_flags_test="-Werror=unknown-warning-option"
47     ],[
48         ax_compiler_flags_test=""
49     ])
50
51     # macOS linker does not have --as-needed
52     AX_CHECK_LINK_FLAG([-Wl,--no-as-needed], [
53         ax_compiler_flags_as_needed_option="-Wl,--no-as-needed"
54     ], [
55         ax_compiler_flags_as_needed_option=""
56     ])
57
58     # macOS linker speaks with a different accent
59     ax_compiler_flags_fatal_warnings_option=""
60     AX_CHECK_LINK_FLAG([-Wl,--fatal-warnings], [
61         ax_compiler_flags_fatal_warnings_option="-Wl,--fatal-warnings"
62     ])
63     AX_CHECK_LINK_FLAG([-Wl,-fatal_warnings], [
64         ax_compiler_flags_fatal_warnings_option="-Wl,-fatal_warnings"
65     ])
66
67     # Base flags
68     AX_APPEND_LINK_FLAGS([ dnl
69         $ax_compiler_flags_as_needed_option dnl
70         $3 dnl
71     ],ax_warn_ldflags_variable,[$ax_compiler_flags_test])
72
73     AS_IF([test "$ax_enable_compile_warnings" != "no"],[
74         # "yes" flags
75         AX_APPEND_LINK_FLAGS([$4 $5 $6 $7],
76                                 ax_warn_ldflags_variable,
77                                 [$ax_compiler_flags_test])
78     ])
79     AS_IF([test "$ax_enable_compile_warnings" = "error"],[
80         # "error" flags; -Werror has to be appended unconditionally because
81         # it's not possible to test for
82         #
83         # suggest-attribute=format is disabled because it gives too many false
84         # positives
85         AX_APPEND_LINK_FLAGS([ dnl
86             $ax_compiler_flags_fatal_warnings_option dnl
87         ],ax_warn_ldflags_variable,[$ax_compiler_flags_test])
88     ])
89
90     # Substitute the variables
91     AC_SUBST(ax_warn_ldflags_variable)
92 ])dnl AX_COMPILER_FLAGS