Do not build gtk3.22-client by default
[freeciv.git] / m4 / compiler.m4
blob0e86172350a507ca251ec1ca985f425f8ba8ed20
1 # Macros to check compiler options
4 # Helper function that adds flags (words) to variable listing them.
5 # Makes sure there is no extra spaces in any situation
7 # $1 - Name of the target variable
8 # $2 - Flags to add
10 AC_DEFUN([FC_ADD_WORDS_TO_VAR],
12 old_value="`eval echo '$'$1`"
13 if test "x$old_value" = "x" ; then
14   $1="$2"
15 elif test "x$2" != "x" ; then
16   $1="$old_value $2"
20 # Check if compiler supports given commandline parameter in language specific
21 # variable. If it does, it will be concatenated to variable. If several
22 # parameters are given, they are tested, and added to target variable,
23 # one at a time.
25 # $1 - Language
26 # $2 - Language specific variable
27 # $3 - Parameters to test
28 # $4 - Additional parameters
29 # $5 - Variable where to add
32 AC_DEFUN([FC_COMPILER_FLAGS],
34 AC_LANG_PUSH([$1])
36 flags_save="`eval echo '$'$2`"
37 accepted_flags=""
38 existing_flags="`eval echo '$'$5`"
40 for flag in $3
42   dnl We need -Werror to test any flags (it can't be tested itself)
43   dnl Without it, illegal flag will not give an error for us to detect
44   $2="-Werror $flags_save $existing_flags $accepted_flags $flag $4"
45   AC_COMPILE_IFELSE([AC_LANG_SOURCE([int a;])],
46                     [FC_ADD_WORDS_TO_VAR([accepted_flags], [$flag])])
47 done
48 FC_ADD_WORDS_TO_VAR([$5], [$accepted_flags])
50 $2="$flags_save"
52 AC_LANG_POP([$1])
55 # Commandline flag tests for C and C++
58 # $1 - Parameters to test
59 # $2 - Additional parameters
60 # $3 - Variable where to add
62 AC_DEFUN([FC_C_FLAGS],
64 FC_COMPILER_FLAGS([C], [CFLAGS], [$1], [$2], [$3])
68 AC_DEFUN([FC_CXX_FLAGS],
70 FC_COMPILER_FLAGS([C++], [CXXFLAGS], [$1], [$2], [$3])
73 # Commandline flag tests for linker
76 # $1 - Parameters to test
77 # $2 - Additional parameters
78 # $3 - Variable where to add
79 AC_DEFUN([FC_LD_FLAGS],
81 flags_save=$LDFLAGS
82 accepted_flags=""
83 existing_flags="`eval echo '$'$3`"
85 for flag in $1
87   LDFLAGS="$flags_save $existing_flags $accepted_flags $flag $2"
88   AC_LINK_IFELSE([AC_LANG_PROGRAM([], [int a;])],
89                  [FC_ADD_WORDS_TO_VAR([accepted_flags], [$flag])])
90 done
91 FC_ADD_WORDS_TO_VAR([$3], [$accepted_flags])
93 LDFLAGS="$flags_save"
96 # Does current C++ compiler work.
97 # Sets variable cxx_works accordingly.
98 AC_DEFUN([FC_WORKING_CXX],
100 AC_MSG_CHECKING([whether C++ compiler works])
102 AC_LANG_PUSH([C++])
104 AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
106 AC_MSG_RESULT([yes])
107 cxx_works=yes],
109 AC_MSG_RESULT([not])
110 cxx_works=no])
112 AC_LANG_POP([C++])