1 #***************************************************************************
3 # Project ___| | | | _ \| |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
8 # Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
10 # This software is licensed as described in the file COPYING, which
11 # you should have received as part of this distribution. The terms
12 # are also available at http://curl.haxx.se/docs/copyright.html.
14 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 # copies of the Software, and permit persons to whom the Software is
16 # furnished to do so, under the terms of the COPYING file.
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
22 #***************************************************************************
24 # File version for 'aclocal' use. Keep it a single number.
28 dnl CURL_CHECK_COMPILER
29 dnl -------------------------------------------------
30 dnl Verify if the C compiler being used is known.
32 AC_DEFUN([CURL_CHECK_COMPILER], [
37 flags_dbg_all="unknown"
38 flags_dbg_yes="unknown"
39 flags_dbg_off="unknown"
40 flags_opt_all="unknown"
41 flags_opt_yes="unknown"
42 flags_opt_off="unknown"
44 CURL_CHECK_COMPILER_DEC
45 CURL_CHECK_COMPILER_HP
46 CURL_CHECK_COMPILER_IBM
47 CURL_CHECK_COMPILER_INTEL
48 CURL_CHECK_COMPILER_GNU
50 if test "$compiler_id" = "unknown"; then
53 *** Warning: This configure script does not have information about the
54 *** compiler you are using, relative to the flags required to enable or
55 *** disable generation of debug info, optimization options or warnings.
57 *** Whatever settings are present in CFLAGS will be used for this run.
59 *** If you wish to help the cURL project to better support your compiler
60 *** you can report this and the required info on the libcurl development
61 *** mailing list: http://cool.haxx.se/mailman/listinfo/curl-library/
68 dnl CURL_CHECK_COMPILER_DEC
69 dnl -------------------------------------------------
70 dnl Verify if the C compiler being used is DEC's.
72 AC_DEFUN([CURL_CHECK_COMPILER_DEC], [
73 AC_MSG_CHECKING([whether we are using the DEC/Compaq C compiler])
74 CURL_CHECK_DEF([__DECC], [], [silent])
75 CURL_CHECK_DEF([__DECC_VER], [], [silent])
76 if test "$curl_cv_have_def___DECC" = "yes" &&
77 test "$curl_cv_have_def___DECC_VER" = "yes"; then
80 flags_dbg_all="-g -g0 -g1 -g2 -g3"
83 flags_opt_all="-O -O0 -O1 -O2 -O3 -O4"
92 dnl CURL_CHECK_COMPILER_GNU
93 dnl -------------------------------------------------
94 dnl Verify if the C compiler being used is GNU's.
96 AC_DEFUN([CURL_CHECK_COMPILER_GNU], [
97 AC_REQUIRE([CURL_CHECK_COMPILER_INTEL])dnl
99 AC_MSG_CHECKING([whether we are using the GNU C compiler])
100 CURL_CHECK_DEF([__GNUC__], [], [silent])
101 if test "$curl_cv_have_def___GNUC__" = "yes" &&
102 test "$compiler_id" = "unknown"; then
105 gccver=`$CC -dumpversion`
106 gccvhi=`echo $gccver | cut -d . -f1`
107 gccvlo=`echo $gccver | cut -d . -f2`
108 compiler_num=`(expr $gccvhi "*" 100 + $gccvlo) 2>/dev/null`
109 flags_dbg_all="-g -g0 -g1 -g2 -g3"
110 flags_dbg_all="$flags_dbg_all -ggdb"
111 flags_dbg_all="$flags_dbg_all -gstabs"
112 flags_dbg_all="$flags_dbg_all -gstabs+"
113 flags_dbg_all="$flags_dbg_all -gcoff"
114 flags_dbg_all="$flags_dbg_all -gxcoff"
115 flags_dbg_all="$flags_dbg_all -gdwarf-2"
116 flags_dbg_all="$flags_dbg_all -gvms"
119 flags_opt_all="-O -O0 -O1 -O2 -O3 -Os"
128 dnl CURL_CHECK_COMPILER_HP
129 dnl -------------------------------------------------
130 dnl Verify if the C compiler being used is HP's.
132 AC_DEFUN([CURL_CHECK_COMPILER_HP], [
133 AC_MSG_CHECKING([whether we are using the HP C compiler])
134 CURL_CHECK_DEF([__HP_cc], [], [silent])
135 if test "$curl_cv_have_def___HP_cc" = "yes"; then
138 flags_dbg_all="-g -s"
141 flags_opt_all="-O +O0 +O1 +O2 +O3 +O4"
150 dnl CURL_CHECK_COMPILER_IBM
151 dnl -------------------------------------------------
152 dnl Verify if the C compiler being used is IBM's.
154 AC_DEFUN([CURL_CHECK_COMPILER_IBM], [
155 AC_MSG_CHECKING([whether we are using the IBM C compiler])
156 CURL_CHECK_DEF([__IBMC__], [], [silent])
157 if test "$curl_cv_have_def___IBMC__" = "yes"; then
160 flags_dbg_all="-g -g0 -g1 -g2 -g3"
163 flags_opt_all="-O -O0 -O1 -O2 -O3 -O4 -O5"
164 flags_opt_all="$flags_opt_all -qnooptimize"
165 flags_opt_all="$flags_opt_all -qoptimize=0"
166 flags_opt_all="$flags_opt_all -qoptimize=1"
167 flags_opt_all="$flags_opt_all -qoptimize=2"
168 flags_opt_all="$flags_opt_all -qoptimize=3"
169 flags_opt_all="$flags_opt_all -qoptimize=4"
170 flags_opt_all="$flags_opt_all -qoptimize=5"
172 flags_opt_off="-qnooptimize"
179 dnl CURL_CHECK_COMPILER_INTEL
180 dnl -------------------------------------------------
181 dnl Verify if the C compiler being used is Intel's.
183 AC_DEFUN([CURL_CHECK_COMPILER_INTEL], [
184 AC_BEFORE([$0],[CURL_CHECK_COMPILER_GNU])dnl
185 AC_MSG_CHECKING([whether we are using the Intel C compiler])
186 CURL_CHECK_DEF([__INTEL_COMPILER], [], [silent])
187 if test "$curl_cv_have_def___INTEL_COMPILER" = "yes"; then
189 CURL_CHECK_DEF([__unix__], [], [silent])
190 if test "$curl_cv_have_def___unix__" = "yes"; then
191 compiler_id="ICC_unix"
192 flags_dbg_all="-g -g0"
195 flags_opt_all="-O -O0 -O1 -O2 -O3 -Os"
199 compiler_id="ICC_windows"
200 flags_dbg_all="/ZI /Zi /zI /zi /ZD /Zd /zD /zd /Z7 /z7 /Oy /Oy-"
201 flags_dbg_all="$flags_dbg_all /debug"
202 flags_dbg_all="$flags_dbg_all /debug:none"
203 flags_dbg_all="$flags_dbg_all /debug:minimal"
204 flags_dbg_all="$flags_dbg_all /debug:partial"
205 flags_dbg_all="$flags_dbg_all /debug:full"
206 flags_dbg_all="$flags_dbg_all /debug:semantic_stepping"
207 flags_dbg_all="$flags_dbg_all /debug:extended"
208 flags_dbg_yes="/Zi /Oy-"
209 flags_dbg_off="/debug:none /Oy-"
210 flags_opt_all="/O /O0 /O1 /O2 /O3 /Od /Og /Og- /Oi /Oi-"
214 compiler_num="$curl_cv_def___INTEL_COMPILER"
221 dnl CURL_SET_COMPILER_BASIC_OPTS
222 dnl -------------------------------------------------
223 dnl Sets compiler specific options/flags which do not
224 dnl depend on configure's debug, optimize or warnings
227 AC_DEFUN([CURL_SET_COMPILER_BASIC_OPTS], [
228 AC_REQUIRE([CURL_CHECK_COMPILER])dnl
230 if test "$compiler_id" = "DECC"; then
231 dnl Select strict ANSI C compiler mode
232 CFLAGS="$CFLAGS -std1"
233 dnl Turn off optimizer ANSI C aliasing rules
234 CFLAGS="$CFLAGS -noansi_alias"
235 dnl Generate warnings for missing function prototypes
236 CFLAGS="$CFLAGS -warnprotos"
237 dnl Change some warnings into fatal errors
238 CFLAGS="$CFLAGS -msg_fatal toofewargs,toomanyargs"
241 if test "$compiler_id" = "HPC"; then
242 dnl Disallow run-time dereferencing of null pointers
246 if test "$compiler_id" = "IBMC"; then
247 dnl Ensure that compiler optimizations are always thread-safe.
248 CFLAGS="$CFLAGS -qthreaded"
249 dnl Disable type based strict aliasing optimizations, using worst
250 dnl case aliasing assumptions when compiling. Type based aliasing
251 dnl would restrict the lvalues that could be safely used to access
253 CFLAGS="$CFLAGS -qnoansialias"
254 dnl Force compiler to stop after the compilation phase, without
255 dnl generating an object code file when compilation has errors.
256 CFLAGS="$CFLAGS -qhalt=e"
259 if test "$compiler_id" = "ICC_unix"; then
260 dnl On unix this compiler uses gcc's header files, so
261 dnl we select ANSI C89 dialect plus GNU extensions.
262 CPPFLAGS="$CPPFLAGS -std=gnu89"
263 dnl Change some warnings into errors
264 dnl #140: too many arguments in function call
265 dnl #147: declaration is incompatible with 'previous one'
266 dnl #165: too few arguments in function call
267 dnl #266: function declared implicitly
268 CPPFLAGS="$CPPFLAGS -we 140,147,165,266"
269 dnl Disable some remarks
270 dnl #279: controlling expression is constant
271 dnl #981: operands are evaluated in unspecified order
272 dnl #1469: "cc" clobber ignored
273 if test "$compiler_num" -lt "910"; then
274 CPPFLAGS="$CPPFLAGS -wd 279"
276 CPPFLAGS="$CPPFLAGS -wd 981,1469"
277 dnl Disable use of ANSI C aliasing rules in optimizations
278 CFLAGS="$CFLAGS -no-ansi-alias"
279 dnl Disable floating point optimizations
280 CFLAGS="$CFLAGS -fp-model precise"
285 dnl CURL_SET_COMPILER_DEBUG_OPTS
286 dnl -------------------------------------------------
287 dnl Sets compiler specific options/flags which depend
288 dnl on configure's debug option.
290 AC_DEFUN([CURL_SET_COMPILER_DEBUG_OPTS], [
291 AC_REQUIRE([CURL_CHECK_OPTION_DEBUG])dnl
292 AC_REQUIRE([CURL_CHECK_COMPILER])dnl
294 if test "$compiler_id" != "unknown"; then
296 ac_save_CFLAGS="$CFLAGS"
297 ac_save_CPPFLAGS="$CPPFLAGS"
299 honor_debug_option="yes"
300 CURL_VAR_STRIP([CFLAGS],[${flags_dbg_all}])
301 CURL_VAR_STRIP([CPPFLAGS],[${flags_dbg_all}])
302 if test "$want_debug" = "yes"; then
303 CFLAGS="$CFLAGS $flags_dbg_yes"
304 AC_MSG_CHECKING([if compiler accepts debug enabling flags $flags_dbg_yes])
306 if test "$want_debug" = "no"; then
307 CFLAGS="$CFLAGS $flags_dbg_off"
308 AC_MSG_CHECKING([if compiler accepts debug disabling flags $flags_dbg_off])
320 honor_debug_option="no"
323 if test "$honor_debug_option" = "no"; then
324 CFLAGS="$ac_save_CFLAGS"
325 CPPFLAGS="$ac_save_CPPFLAGS"
332 dnl CURL_SET_COMPILER_OPTIMIZE_OPTS
333 dnl -------------------------------------------------
334 dnl Sets compiler specific options/flags which depend
335 dnl on configure's optimize option.
337 AC_DEFUN([CURL_SET_COMPILER_OPTIMIZE_OPTS], [
338 AC_REQUIRE([CURL_CHECK_OPTION_OPTIMIZE])dnl
339 AC_REQUIRE([CURL_CHECK_COMPILER])dnl
341 if test "$compiler_id" != "unknown"; then
343 ac_save_CFLAGS="$CFLAGS"
344 ac_save_CPPFLAGS="$CPPFLAGS"
346 dnl If optimization request setting has not been explicitly specified,
347 dnl it has been derived from the debug setting and initially assumed.
348 dnl This initially assumed optimizer setting will finally be ignored
349 dnl if CFLAGS or CPPFLAGS already hold optimizer flags. This implies
350 dnl that an initially assumed optimizer setting might not be honored.
352 honor_optimize_option="yes"
353 if test "$want_optimize" = "assume_no" ||
354 test "$want_optimize" = "assume_yes"; then
355 AC_MSG_CHECKING([if compiler optimizer assumed setting might be used])
356 CURL_VAR_MATCH_IFELSE([CFLAGS],[${flags_opt_all}],[
357 honor_optimize_option="no"
359 CURL_VAR_MATCH_IFELSE([CPPFLAGS],[${flags_opt_all}],[
360 honor_optimize_option="no"
362 AC_MSG_RESULT([$honor_optimize_option])
363 if test "$honor_optimize_option" = "yes"; then
364 if test "$want_optimize" = "assume_yes"; then
367 if test "$want_optimize" = "assume_no"; then
373 if test "$honor_optimize_option" = "yes"; then
374 CURL_VAR_STRIP([CFLAGS],[${flags_opt_all}])
375 CURL_VAR_STRIP([CPPFLAGS],[${flags_opt_all}])
376 if test "$want_optimize" = "yes"; then
377 CFLAGS="$CFLAGS $flags_opt_yes"
378 AC_MSG_CHECKING([if compiler accepts optimizer enabling flags $flags_opt_yes])
380 if test "$want_optimize" = "no"; then
381 CFLAGS="$CFLAGS $flags_opt_off"
382 AC_MSG_CHECKING([if compiler accepts optimizer disabling flags $flags_opt_off])
394 honor_optimize_option="no"
398 if test "$honor_optimize_option" = "no"; then
399 CFLAGS="$ac_save_CFLAGS"
400 CPPFLAGS="$ac_save_CPPFLAGS"
407 dnl CURL_SET_COMPILER_WARNING_OPTS
408 dnl -------------------------------------------------
409 dnl Sets compiler options/flags which depend on
410 dnl configure's warnings given option.
412 AC_DEFUN([CURL_SET_COMPILER_WARNING_OPTS], [
413 AC_REQUIRE([CURL_CHECK_OPTION_WARNINGS])dnl
414 AC_REQUIRE([CURL_CHECK_COMPILER])dnl
416 if test "$compiler_id" = "DECC"; then
417 if test "$want_warnings" = "yes"; then
418 dnl Select a higher warning level than default level2
419 CFLAGS="$CFLAGS -msg_enable level3"
423 if test "$compiler_id" = "HPC"; then
424 if test "$want_warnings" = "yes"; then
425 dnl Issue all warnings
430 if test "$compiler_id" = "ICC_unix"; then
431 if test "$want_warnings" = "yes"; then
432 if test "$compiler_num" -gt "600"; then
433 dnl Show errors, warnings, and remarks
434 CPPFLAGS="$CPPFLAGS -Wall"
435 dnl Perform extra compile-time code checking
436 CPPFLAGS="$CPPFLAGS -Wcheck"
441 if test "$compiler_id" = "GNUC"; then
443 # FIXME: Some of these warnings should be changed into errors
444 # and moved to CURL-SET-COMPILER-BASIC-OPTS
446 if test "$want_warnings" = "yes"; then
447 dnl this is a set of options we believe *ALL* gcc versions support:
448 WARN="-W -Wall -Wwrite-strings -pedantic -Wpointer-arith -Wnested-externs -Winline -Wmissing-prototypes"
449 dnl -Wcast-align is a bit too annoying on all gcc versions ;-)
450 if test "$compiler_num" -ge "207"; then
452 WARN="$WARN -Wmissing-declarations"
454 if test "$compiler_num" -gt "295"; then
455 dnl only if the compiler is newer than 2.95 since we got lots of
456 dnl "`_POSIX_C_SOURCE' is not defined" in system headers with
457 dnl gcc 2.95.4 on FreeBSD 4.9!
458 WARN="$WARN -Wundef -Wno-long-long -Wsign-compare -Wshadow -Wno-multichar"
460 if test "$compiler_num" -ge "296"; then
461 dnl gcc 2.96 or later
462 WARN="$WARN -Wfloat-equal"
464 if test "$compiler_num" -gt "296"; then
465 dnl this option does not exist in 2.96
466 WARN="$WARN -Wno-format-nonliteral"
468 dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
469 dnl on i686-Linux as it gives us heaps with false positives.
470 dnl Also, on gcc 4.0.X it is totally unbearable and complains all
471 dnl over making it unusable for generic purposes. Let's not use it.
472 if test "$compiler_num" -ge "303"; then
473 dnl gcc 3.3 and later
474 WARN="$WARN -Wendif-labels -Wstrict-prototypes"
476 if test "$compiler_num" -ge "304"; then
477 # try these on gcc 3.4
478 WARN="$WARN -Wdeclaration-after-statement"
480 for flag in $CPPFLAGS; do
483 dnl Include path, provide a -isystem option for the same dir
484 dnl to prevent warnings in those dirs. The -isystem was not very
485 dnl reliable on earlier gcc versions.
486 add=`echo $flag | sed 's/^-I/-isystem /g'`
491 CFLAGS="$CFLAGS $WARN"
492 AC_MSG_NOTICE([Added this set of compiler options: $WARN])
499 dnl CURL_PROCESS_DEBUG_BUILD_OPTS
500 dnl -------------------------------------------------
501 dnl Settings which depend on configure's debug given
502 dnl option, and further configure the build process.
503 dnl Don't use this macro for compiler dependant stuff.
505 AC_DEFUN([CURL_PROCESS_DEBUG_BUILD_OPTS], [
506 AC_REQUIRE([CURL_CHECK_OPTION_DEBUG])dnl
507 AC_BEFORE([$0],[AC_PROG_LIBTOOL])dnl
509 if test "$want_debug" = "yes"; then
510 CPPFLAGS="$CPPFLAGS -DCURLDEBUG"
516 dnl CURL_CHECK_PROG_CC
517 dnl -------------------------------------------------
518 dnl Check for compiler program, preventing CFLAGS and
519 dnl CPPFLAGS from being unexpectedly changed.
521 AC_DEFUN([CURL_CHECK_PROG_CC], [
522 ac_save_CFLAGS="$CFLAGS"
523 ac_save_CPPFLAGS="$CPPFLAGS"
525 CFLAGS="$ac_save_CFLAGS"
526 CPPFLAGS="$ac_save_CPPFLAGS"
530 dnl CURL_VAR_MATCH (VARNAME, VALUE)
531 dnl -------------------------------------------------
532 dnl Verifies if shell variable VARNAME contains VALUE.
533 dnl Contents of variable VARNAME and VALUE are handled
534 dnl as whitespace separated lists of words. If at least
535 dnl one word of VALUE is present in VARNAME the match
536 dnl is considered positive, otherwise false.
538 AC_DEFUN([CURL_VAR_MATCH], [
539 ac_var_match_word="no"
540 for word1 in "${[$1]}"; do
541 for word2 in "[$2]"; do
542 if test "$word1" = "$word2"; then
543 ac_var_match_word="yes"
550 dnl CURL_VAR_MATCH_IFELSE (VARNAME, VALUE,
551 dnl [ACTION-IF-MATCH], [ACTION-IF-NOT-MATCH])
552 dnl -------------------------------------------------
553 dnl This performs a CURL_VAR_MATCH check and executes
554 dnl first branch if the match is positive, otherwise
555 dnl the second branch is executed.
557 AC_DEFUN([CURL_VAR_MATCH_IFELSE], [
558 CURL_VAR_MATCH([$1],[$2])
559 if test "$ac_var_match_word" = "yes"; then
567 dnl CURL_VAR_STRIP (VARNAME, VALUE)
568 dnl -------------------------------------------------
569 dnl Contents of variable VARNAME and VALUE are handled
570 dnl as whitespace separated lists of words. Each word
571 dnl from VALUE is removed from VARNAME when present.
573 AC_DEFUN([CURL_VAR_STRIP], [
575 for word1 in "${[$1]}"; do
576 ac_var_strip_word="no"
577 for word2 in "[$2]"; do
578 if test "$word1" = "$word2"; then
579 ac_var_strip_word="yes"
582 if test "$ac_var_strip_word" = "no"; then
583 ac_var_stripped="$ac_var_stripped $word1"
586 dnl squeeze whitespace out of result
587 [$1]=`eval echo $ac_var_stripped`