]>
Commit | Line | Data |
---|---|---|
f70aedc4 | 1 | ## Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
5d2e6f19 AJ |
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 | ## | |
6a56798f FC |
7 | |
8 | # check if the compiler accepts a supplied flag | |
94d8ab67 FC |
9 | # first argument is the variable containing the result |
10 | # (will be set to "yes" or "no") | |
6a56798f | 11 | # second argument is the flag to be tested, verbatim |
fa6307ae | 12 | # |
07f370ee | 13 | AC_DEFUN([SQUID_CC_CHECK_ARGUMENT],[ |
6a56798f FC |
14 | AC_CACHE_CHECK([whether compiler accepts $2],[$1], |
15 | [{ | |
16 | AC_REQUIRE([AC_PROG_CC]) | |
6936119e | 17 | SAVED_CFLAGS="$CFLAGS" |
6a56798f | 18 | SAVED_CXXFLAGS="$CXXFLAGS" |
707867d0 | 19 | CFLAGS="$CFLAGS $2" |
6a56798f FC |
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 | ||
3e1ce596 KB |
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]) | |
6936119e | 41 | SAVED_CFLAGS="$CFLAGS" |
3e1ce596 KB |
42 | SAVED_CXXFLAGS="$CXXFLAGS" |
43 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM($3,$4)],[$1=no],[],[$1=no]) | |
98dcfea4 | 44 | if test "x$$1" != "xno" ; then |
24b363ee | 45 | CFLAGS="$CFLAGS $2" |
3e1ce596 KB |
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 | }]) | |
3e1ce596 KB |
52 | ]) |
53 | ||
f9d138eb FC |
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 | |
07f370ee | 59 | # - none (undetected) |
fa6307ae | 60 | # |
f70e69c6 | 61 | AC_DEFUN([SQUID_CC_GUESS_VARIANT], [ |
f9d138eb FC |
62 | AC_CACHE_CHECK([what kind of compiler we're using],[squid_cv_compiler], |
63 | [ | |
64 | AC_REQUIRE([AC_PROG_CC]) | |
f9d138eb | 65 | dnl repeat the next block for each compiler, changing the |
f70e69c6 | 66 | dnl preprocessor definition so that it depends on platform-specific |
f9d138eb FC |
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 | |
ccaa562a FC |
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 | |
f70e69c6 FC |
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 | |
f9d138eb FC |
113 | dnl end of block to be repeated |
114 | if test -z "$squid_cv_compiler" ; then | |
07f370ee | 115 | squid_cv_compiler="none" |
f9d138eb | 116 | fi |
f70e69c6 FC |
117 | ]) dnl AC_CACHE_CHECK |
118 | ]) dnl AC_DEFUN | |
f9d138eb FC |
119 | |
120 | # define the flag to use to have the compiler treat warnings as errors | |
07f370ee | 121 | # requirs SQUID_CC_GUESS_VARIANT |
fa6307ae FC |
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) | |
59a09b98 | 127 | # squid_cv_cxx_option_werror (-Werror) |
fa6307ae FC |
128 | # squid_cv_cc_option_wall (-Wall) |
129 | # squid_cv_cc_option_optimize (-O3) | |
07f370ee | 130 | # |
fa6307ae | 131 | AC_DEFUN([SQUID_CC_GUESS_OPTIONS], [ |
07f370ee | 132 | AC_REQUIRE([SQUID_CC_GUESS_VARIANT]) |
e0eb5853 | 133 | AC_MSG_CHECKING([for compiler variant]) |
f9d138eb | 134 | case "$squid_cv_compiler" in |
fa6307ae FC |
135 | gcc) |
136 | squid_cv_cc_option_werror="-Werror" | |
59a09b98 | 137 | squid_cv_cxx_option_werror="-Werror" |
fa6307ae FC |
138 | squid_cv_cc_option_wall="-Wall" |
139 | squid_cv_cc_option_optimize="-O3" | |
e0eb5853 | 140 | squid_cv_cc_arg_pipe="-pipe" |
fa6307ae FC |
141 | ;; |
142 | sunstudio) | |
59a09b98 FC |
143 | squid_cv_cc_option_werror="-errwarn=%all -errtags" |
144 | squid_cv_cxx_option_werror="-errwarn=%all,no%badargtype2w,no%wbadinit,no%wbadasg -errtags" | |
fa6307ae FC |
145 | squid_cv_cc_option_wall="+w" |
146 | squid_cv_cc_option_optimize="-fast" | |
e0eb5853 | 147 | squid_cv_cc_arg_pipe="" |
fa6307ae | 148 | ;; |
f70e69c6 | 149 | clang) |
b9bb9562 FC |
150 | squid_cv_cxx_option_werror="-Werror -Qunused-arguments" |
151 | squid_cv_cc_option_werror="$squid_cv_cxx_option_werror" | |
f70e69c6 FC |
152 | squid_cv_cc_option_wall="-Wall" |
153 | squid_cv_cc_option_optimize="-O2" | |
154 | squid_cv_cc_arg_pipe="" | |
155 | ;; | |
ccaa562a FC |
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 | ;; | |
fa6307ae | 163 | *) |
59a09b98 | 164 | squid_cv_cxx_option_werror="" |
fa6307ae FC |
165 | squid_cv_cc_option_werror="" |
166 | squid_cv_cc_option_wall="" | |
e0eb5853 FC |
167 | squid_cv_cc_option_optimize="-O" |
168 | squid_cv_cc_arg_pipe="" | |
fa6307ae | 169 | ;; |
f9d138eb | 170 | esac |
e0eb5853 | 171 | AC_MSG_RESULT([$squid_cv_compiler]) |
f9d138eb | 172 | ]) |