1 ## Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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.
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
13 AC_DEFUN([SQUID_CC_CHECK_ARGUMENT],[
14 AC_CACHE_CHECK([whether compiler accepts $2],[$1],
16 AC_REQUIRE([AC_PROG_CC])
17 SAVED_CFLAGS="$CFLAGS"
18 SAVED_CXXFLAGS="$CXXFLAGS"
20 CXXFLAGS="$CXXFLAGS $2"
21 AC_TRY_LINK([],[int foo; ],
23 CFLAGS="$SAVED_CFLAGS"
24 CXXFLAGS="$SAVED_CXXFLAGS"
28 # Check if the compiler requires a supplied flag to build a test program.
29 # When cross-compiling set flags explicitly.
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
37 AC_DEFUN([SQUID_CC_REQUIRE_ARGUMENT],[
38 AC_CACHE_CHECK([whether compiler requires $2],[$1],
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
46 CXXFLAGS="$CXXFLAGS $2"
47 AC_COMPILE_IFELSE([AC_LANG_PROGRAM($3,$4)],[$1=yes],[$1=no],[$1=no])
49 CFLAGS="$SAVED_CFLAGS"
50 CXXFLAGS="$SAVED_CXXFLAGS"
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
61 AC_DEFUN([SQUID_CC_GUESS_VARIANT], [
62 AC_CACHE_CHECK([what kind of compiler we're using],[squid_cv_compiler],
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
69 if test -z "$squid_cv_compiler" ; then
72 #if !defined(__SUNPRO_C) && !defined(__SUNPRO_CC)
75 ]])],[squid_cv_compiler="sunstudio"],[])
78 if test -z "$squid_cv_compiler" ; then
82 #error "not Intel(R) C++ Compiler"
84 ]])],[squid_cv_compiler="icc"],[])
87 if test -z "$squid_cv_compiler" ; then
90 #if !defined(__clang__)
93 ]])],[squid_cv_compiler="clang"],[])
95 dnl microsoft visual c++
96 if test -z "$squid_cv_compiler" ; then
99 #if !defined(_MSC_VER)
100 #error "not Microsoft VC++"
102 ]])],[squid_cv_compiler="msvc"],[])
104 dnl gcc. MUST BE LAST as many other compilers also define it for compatibility
105 if test -z "$squid_cv_compiler" ; then
108 #if !defined(__GNUC__)
111 ]])],[squid_cv_compiler="gcc"],[])
113 dnl end of block to be repeated
114 if test -z "$squid_cv_compiler" ; then
115 squid_cv_compiler="none"
117 ]) dnl AC_CACHE_CHECK
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
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)
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
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"
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=""
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=""
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=""
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=""
171 AC_MSG_RESULT([$squid_cv_compiler])