]> git.ipfire.org Git - thirdparty/squid.git/blob - acinclude/compiler-flags.m4
SourceFormat Enforcement
[thirdparty/squid.git] / acinclude / compiler-flags.m4
1 ## Copyright (C) 1996-2017 The Squid Software Foundation and contributors
2 ##
3 ## Squid software is distributed under GPLv2+ license and includes
4 ## contributions from numerous individuals and organizations.
5 ## Please see the COPYING and CONTRIBUTORS files for details.
6 ##
7
8 # check if the compiler accepts a supplied flag
9 # first argument is the variable containing the result
10 # (will be set to "yes" or "no")
11 # second argument is the flag to be tested, verbatim
12 #
13 AC_DEFUN([SQUID_CC_CHECK_ARGUMENT],[
14 AC_CACHE_CHECK([whether compiler accepts $2],[$1],
15 [{
16 AC_REQUIRE([AC_PROG_CC])
17 SAVED_CFLAGS="$CFLAGS"
18 SAVED_CXXFLAGS="$CXXFLAGS"
19 CFLAGS="$CFLAGS $2"
20 CXXFLAGS="$CXXFLAGS $2"
21 AC_TRY_LINK([],[int foo; ],
22 [$1=yes],[$1=no])
23 CFLAGS="$SAVED_CFLAGS"
24 CXXFLAGS="$SAVED_CXXFLAGS"
25 }])
26 ])
27
28 # Check if the compiler requires a supplied flag to build a test program.
29 # When cross-compiling set flags explicitly.
30 #
31 # first argument is the variable containing the result
32 # (will be set to "yes" or "no")
33 # second argument is the flag to be tested, verbatim
34 # third is the #include and global setup for test program, verbatim
35 # fourth is the test program to compile, verbatim
36 #
37 AC_DEFUN([SQUID_CC_REQUIRE_ARGUMENT],[
38 AC_CACHE_CHECK([whether compiler requires $2],[$1],
39 [{
40 AC_REQUIRE([AC_PROG_CC])
41 SAVED_CFLAGS="$CFLAGS"
42 SAVED_CXXFLAGS="$CXXFLAGS"
43 AC_COMPILE_IFELSE([AC_LANG_PROGRAM($3,$4)],[$1=no],[],[$1=no])
44 if test "x$1" != "xno" ; then
45 CFLAGS="$CFLAGS $2"
46 CXXFLAGS="$CXXFLAGS $2"
47 AC_COMPILE_IFELSE([AC_LANG_PROGRAM($3,$4)],[$1=yes],[$1=no],[$1=no])
48 fi
49 CFLAGS="$SAVED_CFLAGS"
50 CXXFLAGS="$SAVED_CXXFLAGS"
51 }])
52 ])
53
54 # detect what kind of compiler we're using, either by using hints from
55 # autoconf itself, or by using predefined preprocessor macros
56 # sets the variable squid_cv_compiler to one of
57 # - gcc
58 # - sunstudio
59 # - none (undetected)
60 #
61 AC_DEFUN([SQUID_CC_GUESS_VARIANT], [
62 AC_CACHE_CHECK([what kind of compiler we're using],[squid_cv_compiler],
63 [
64 AC_REQUIRE([AC_PROG_CC])
65 dnl repeat the next block for each compiler, changing the
66 dnl preprocessor definition so that it depends on platform-specific
67 dnl predefined macros
68 dnl SunPro CC
69 if test -z "$squid_cv_compiler" ; then
70 AC_COMPILE_IFELSE([
71 AC_LANG_PROGRAM([[
72 #if !defined(__SUNPRO_C) && !defined(__SUNPRO_CC)
73 #error "not sunpro c"
74 #endif
75 ]])],[squid_cv_compiler="sunstudio"],[])
76 fi
77 dnl Intel CC
78 if test -z "$squid_cv_compiler" ; then
79 AC_COMPILE_IFELSE([
80 AC_LANG_PROGRAM([[
81 #if !defined(__ICC)
82 #error "not Intel(R) C++ Compiler"
83 #endif
84 ]])],[squid_cv_compiler="icc"],[])
85 fi
86 dnl clang
87 if test -z "$squid_cv_compiler" ; then
88 AC_COMPILE_IFELSE([
89 AC_LANG_PROGRAM([[
90 #if !defined(__clang__)
91 #error "not clang"
92 #endif
93 ]])],[squid_cv_compiler="clang"],[])
94 fi
95 dnl microsoft visual c++
96 if test -z "$squid_cv_compiler" ; then
97 AC_COMPILE_IFELSE([
98 AC_LANG_PROGRAM([[
99 #if !defined(_MSC_VER)
100 #error "not Microsoft VC++"
101 #endif
102 ]])],[squid_cv_compiler="msvc"],[])
103 fi
104 dnl gcc. MUST BE LAST as many other compilers also define it for compatibility
105 if test -z "$squid_cv_compiler" ; then
106 AC_COMPILE_IFELSE([
107 AC_LANG_PROGRAM([[
108 #if !defined(__GNUC__)
109 #error "not gcc"
110 #endif
111 ]])],[squid_cv_compiler="gcc"],[])
112 fi
113 dnl end of block to be repeated
114 if test -z "$squid_cv_compiler" ; then
115 squid_cv_compiler="none"
116 fi
117 ]) dnl AC_CACHE_CHECK
118 ]) dnl AC_DEFUN
119
120 # define the flag to use to have the compiler treat warnings as errors
121 # requirs SQUID_CC_GUESS_VARIANT
122 # Sets a few variables to contain some compiler-dependent command line
123 # options, or to empty strings if the compiler doesn't support those
124 # options
125 # They are (with their GCC equivalent):
126 # squid_cv_cc_option_werror (-Werror)
127 # squid_cv_cxx_option_werror (-Werror)
128 # squid_cv_cc_option_wall (-Wall)
129 # squid_cv_cc_option_optimize (-O3)
130 #
131 AC_DEFUN([SQUID_CC_GUESS_OPTIONS], [
132 AC_REQUIRE([SQUID_CC_GUESS_VARIANT])
133 AC_MSG_CHECKING([for compiler variant])
134 case "$squid_cv_compiler" in
135 gcc)
136 squid_cv_cc_option_werror="-Werror"
137 squid_cv_cxx_option_werror="-Werror"
138 squid_cv_cc_option_wall="-Wall"
139 squid_cv_cc_option_optimize="-O3"
140 squid_cv_cc_arg_pipe="-pipe"
141 ;;
142 sunstudio)
143 squid_cv_cc_option_werror="-errwarn=%all -errtags"
144 squid_cv_cxx_option_werror="-errwarn=%all,no%badargtype2w,no%wbadinit,no%wbadasg -errtags"
145 squid_cv_cc_option_wall="+w"
146 squid_cv_cc_option_optimize="-fast"
147 squid_cv_cc_arg_pipe=""
148 ;;
149 clang)
150 squid_cv_cxx_option_werror="-Werror -Qunused-arguments"
151 squid_cv_cc_option_werror="$squid_cv_cxx_option_werror"
152 squid_cv_cc_option_wall="-Wall"
153 squid_cv_cc_option_optimize="-O2"
154 squid_cv_cc_arg_pipe=""
155 ;;
156 icc)
157 squid_cv_cxx_option_werror="-Werror"
158 squid_cv_cc_option_werror="$squid_cv_cxx_option_werror"
159 squid_cv_cc_option_wall="-Wall"
160 squid_cv_cc_option_optimize="-O2"
161 squid_cv_cc_arg_pipe=""
162 ;;
163 *)
164 squid_cv_cxx_option_werror=""
165 squid_cv_cc_option_werror=""
166 squid_cv_cc_option_wall=""
167 squid_cv_cc_option_optimize="-O"
168 squid_cv_cc_arg_pipe=""
169 ;;
170 esac
171 AC_MSG_RESULT([$squid_cv_compiler])
172 ])