remove extra space
[platform/upstream/curl.git] / m4 / curl-compilers.m4
1 #***************************************************************************
2 #                                  _   _ ____  _
3 #  Project                     ___| | | |  _ \| |
4 #                             / __| | | | |_) | |
5 #                            | (__| |_| |  _ <| |___
6 #                             \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
9 #
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.
13 #
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.
17 #
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
20 #
21 # $Id$
22 #***************************************************************************
23
24 # File version for 'aclocal' use. Keep it a single number.
25 # serial 23
26
27
28 dnl CURL_CHECK_COMPILER
29 dnl -------------------------------------------------
30 dnl Verify if the C compiler being used is known.
31
32 AC_DEFUN([CURL_CHECK_COMPILER], [
33   #
34   compiler_id="unknown"
35   compiler_num="0"
36   #
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"
43   #
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
49   CURL_CHECK_COMPILER_LCC
50   CURL_CHECK_COMPILER_SGI_MIPSpro_C
51   CURL_CHECK_COMPILER_SGI_MIPS_C
52   CURL_CHECK_COMPILER_SUN
53   CURL_CHECK_COMPILER_TINYC
54   #
55   if test "$compiler_id" = "unknown"; then
56   cat <<_EOF 1>&2
57 ***
58 *** Warning: This configure script does not have information about the
59 *** compiler you are using, relative to the flags required to enable or
60 *** disable generation of debug info, optimization options or warnings.
61 ***
62 *** Whatever settings are present in CFLAGS will be used for this run.
63 ***
64 *** If you wish to help the cURL project to better support your compiler
65 *** you can report this and the required info on the libcurl development
66 *** mailing list: http://cool.haxx.se/mailman/listinfo/curl-library/
67 ***
68 _EOF
69   fi
70 ])
71
72
73 dnl CURL_CHECK_COMPILER_DEC
74 dnl -------------------------------------------------
75 dnl Verify if the C compiler being used is DEC's.
76
77 AC_DEFUN([CURL_CHECK_COMPILER_DEC], [
78   AC_MSG_CHECKING([whether we are using the DEC/Compaq C compiler])
79   CURL_CHECK_DEF([__DECC], [], [silent])
80   CURL_CHECK_DEF([__DECC_VER], [], [silent])
81   if test "$curl_cv_have_def___DECC" = "yes" &&
82     test "$curl_cv_have_def___DECC_VER" = "yes"; then
83     AC_MSG_RESULT([yes])
84     compiler_id="DECC"
85     flags_dbg_all="-g -g0 -g1 -g2 -g3"
86     flags_dbg_yes="-g2"
87     flags_dbg_off="-g0"
88     flags_opt_all="-O -O0 -O1 -O2 -O3 -O4"
89     flags_opt_yes="-O1"
90     flags_opt_off="-O0"
91   else
92     AC_MSG_RESULT([no])
93   fi
94 ])
95
96
97 dnl CURL_CHECK_COMPILER_GNU
98 dnl -------------------------------------------------
99 dnl Verify if the C compiler being used is GNU's.
100
101 AC_DEFUN([CURL_CHECK_COMPILER_GNU], [
102   AC_REQUIRE([CURL_CHECK_COMPILER_INTEL])dnl
103   #
104   AC_MSG_CHECKING([whether we are using the GNU C compiler])
105   CURL_CHECK_DEF([__GNUC__], [], [silent])
106   if test "$curl_cv_have_def___GNUC__" = "yes" &&
107     test "$compiler_id" = "unknown"; then
108     AC_MSG_RESULT([yes])
109     compiler_id="GNUC"
110     gccver=`$CC -dumpversion`
111     gccvhi=`echo $gccver | cut -d . -f1`
112     gccvlo=`echo $gccver | cut -d . -f2`
113     compiler_num=`(expr $gccvhi "*" 100 + $gccvlo) 2>/dev/null`
114     flags_dbg_all="-g -g0 -g1 -g2 -g3"
115     flags_dbg_all="$flags_dbg_all -ggdb"
116     flags_dbg_all="$flags_dbg_all -gstabs"
117     flags_dbg_all="$flags_dbg_all -gstabs+"
118     flags_dbg_all="$flags_dbg_all -gcoff"
119     flags_dbg_all="$flags_dbg_all -gxcoff"
120     flags_dbg_all="$flags_dbg_all -gdwarf-2"
121     flags_dbg_all="$flags_dbg_all -gvms"
122     flags_dbg_yes="-g"
123     flags_dbg_off="-g0"
124     flags_opt_all="-O -O0 -O1 -O2 -O3 -Os"
125     flags_opt_yes="-O2"
126     flags_opt_off="-O0"
127   else
128     AC_MSG_RESULT([no])
129   fi
130 ])
131
132
133 dnl CURL_CHECK_COMPILER_HP
134 dnl -------------------------------------------------
135 dnl Verify if the C compiler being used is HP's.
136
137 AC_DEFUN([CURL_CHECK_COMPILER_HP], [
138   AC_MSG_CHECKING([whether we are using the HP C compiler])
139   CURL_CHECK_DEF([__HP_cc], [], [silent])
140   if test "$curl_cv_have_def___HP_cc" = "yes"; then
141     AC_MSG_RESULT([yes])
142     compiler_id="HPUXC"
143     flags_dbg_all="-g -s"
144     flags_dbg_yes="-g"
145     flags_dbg_off="-s"
146     flags_opt_all="-O +O0 +O1 +O2 +O3 +O4"
147     flags_opt_yes="+O2"
148     flags_opt_off="+O0"
149   else
150     AC_MSG_RESULT([no])
151   fi
152 ])
153
154
155 dnl CURL_CHECK_COMPILER_IBM
156 dnl -------------------------------------------------
157 dnl Verify if the C compiler being used is IBM's.
158
159 AC_DEFUN([CURL_CHECK_COMPILER_IBM], [
160   AC_MSG_CHECKING([whether we are using the IBM C compiler])
161   CURL_CHECK_DEF([__IBMC__], [], [silent])
162   if test "$curl_cv_have_def___IBMC__" = "yes"; then
163     AC_MSG_RESULT([yes])
164     compiler_id="IBMC"
165     flags_dbg_all="-g -g0 -g1 -g2 -g3"
166     flags_dbg_yes="-g"
167     flags_dbg_off=""
168     flags_opt_all="-O -O0 -O1 -O2 -O3 -O4 -O5"
169     flags_opt_all="$flags_opt_all -qnooptimize"
170     flags_opt_all="$flags_opt_all -qoptimize=0"
171     flags_opt_all="$flags_opt_all -qoptimize=1"
172     flags_opt_all="$flags_opt_all -qoptimize=2"
173     flags_opt_all="$flags_opt_all -qoptimize=3"
174     flags_opt_all="$flags_opt_all -qoptimize=4"
175     flags_opt_all="$flags_opt_all -qoptimize=5"
176     flags_opt_yes="-O2"
177     flags_opt_off="-qnooptimize"
178   else
179     AC_MSG_RESULT([no])
180   fi
181 ])
182
183
184 dnl CURL_CHECK_COMPILER_INTEL
185 dnl -------------------------------------------------
186 dnl Verify if the C compiler being used is Intel's.
187
188 AC_DEFUN([CURL_CHECK_COMPILER_INTEL], [
189   AC_BEFORE([$0],[CURL_CHECK_COMPILER_GNU])dnl
190   AC_MSG_CHECKING([whether we are using the Intel C compiler])
191   CURL_CHECK_DEF([__INTEL_COMPILER], [], [silent])
192   if test "$curl_cv_have_def___INTEL_COMPILER" = "yes"; then
193     AC_MSG_RESULT([yes])
194     CURL_CHECK_DEF([__unix__], [], [silent])
195     if test "$curl_cv_have_def___unix__" = "yes"; then
196       compiler_id="ICC_unix"
197       flags_dbg_all="-g -g0"
198       flags_dbg_yes="-g"
199       flags_dbg_off="-g0"
200       flags_opt_all="-O -O0 -O1 -O2 -O3 -Os"
201       flags_opt_yes="-O2"
202       flags_opt_off="-O0"
203     else
204       compiler_id="ICC_windows"
205       flags_dbg_all="/ZI /Zi /zI /zi /ZD /Zd /zD /zd /Z7 /z7 /Oy /Oy-"
206       flags_dbg_all="$flags_dbg_all /debug"
207       flags_dbg_all="$flags_dbg_all /debug:none"
208       flags_dbg_all="$flags_dbg_all /debug:minimal"
209       flags_dbg_all="$flags_dbg_all /debug:partial"
210       flags_dbg_all="$flags_dbg_all /debug:full"
211       flags_dbg_all="$flags_dbg_all /debug:semantic_stepping"
212       flags_dbg_all="$flags_dbg_all /debug:extended"
213       flags_dbg_yes="/Zi /Oy-"
214       flags_dbg_off="/debug:none /Oy-"
215       flags_opt_all="/O /O0 /O1 /O2 /O3 /Od /Og /Og- /Oi /Oi-"
216       flags_opt_yes="/O2"
217       flags_opt_off="/Od"
218     fi
219     compiler_num="$curl_cv_def___INTEL_COMPILER"
220   else
221     AC_MSG_RESULT([no])
222   fi
223 ])
224
225
226 dnl CURL_CHECK_COMPILER_LCC
227 dnl -------------------------------------------------
228 dnl Verify if the C compiler being used is LCC.
229
230 AC_DEFUN([CURL_CHECK_COMPILER_LCC], [
231   AC_MSG_CHECKING([whether we are using the LCC C compiler])
232   CURL_CHECK_DEF([__LCC__], [], [silent])
233   if test "$curl_cv_have_def___LCC__" = "yes"; then
234     AC_MSG_RESULT([yes])
235     compiler_id="LCC"
236     flags_dbg_all="-g"
237     flags_dbg_yes="-g"
238     flags_dbg_off=""
239     flags_opt_all=""
240     flags_opt_yes=""
241     flags_opt_off=""
242   else
243     AC_MSG_RESULT([no])
244   fi
245 ])
246
247
248 dnl CURL_CHECK_COMPILER_SGI_MIPS_C
249 dnl -------------------------------------------------
250 dnl Verify if the C compiler being used is SGI's.
251
252 AC_DEFUN([CURL_CHECK_COMPILER_SGI_MIPS_C], [
253   AC_REQUIRE([CURL_CHECK_COMPILER_SGI_MIPSpro_C])dnl
254   AC_MSG_CHECKING([if compiler is SGI MIPS C])
255   CURL_CHECK_DEF([__GNUC__], [], [silent])
256   CURL_CHECK_DEF([__sgi], [], [silent])
257   if test "$curl_cv_have_def___GNUC__" = "no" &&
258     test "$curl_cv_have_def___sgi" = "yes" &&
259     test "$compiler_id" = "unknown"; then
260     AC_MSG_RESULT([yes])
261     compiler_id="SGI_MIPS_C"
262     flags_dbg_all="-g -g0 -g1 -g2 -g3"
263     flags_dbg_yes="-g"
264     flags_dbg_off="-g0"
265     flags_opt_all="-O -O0 -O1 -O2 -O3 -Ofast"
266     flags_opt_yes="-O2"
267     flags_opt_off="-O0"
268   else
269     AC_MSG_RESULT([no])
270   fi
271 ])
272
273
274 dnl CURL_CHECK_COMPILER_SGI_MIPSpro_C
275 dnl -------------------------------------------------
276 dnl Verify if the C compiler being used is SGI's.
277
278 AC_DEFUN([CURL_CHECK_COMPILER_SGI_MIPSpro_C], [
279   AC_BEFORE([$0],[CURL_CHECK_COMPILER_SGI_MIPS_C])dnl
280   AC_MSG_CHECKING([if compiler is SGI MIPSpro C])
281   CURL_CHECK_DEF([__GNUC__], [], [silent])
282   CURL_CHECK_DEF([_SGI_COMPILER_VERSION], [], [silent])
283   if test "$curl_cv_have_def___GNUC__" = "no" &&
284     test "$curl_cv_have_def__SGI_COMPILER_VERSION" = "yes"; then
285     AC_MSG_RESULT([yes])
286     compiler_id="SGI_MIPSpro_C"
287     flags_dbg_all="-g -g0 -g1 -g2 -g3"
288     flags_dbg_yes="-g"
289     flags_dbg_off="-g0"
290     flags_opt_all="-O -O0 -O1 -O2 -O3 -Ofast"
291     flags_opt_yes="-O2"
292     flags_opt_off="-O0"
293   else
294     AC_MSG_RESULT([no])
295   fi
296 ])
297
298
299 dnl CURL_CHECK_COMPILER_SUN
300 dnl -------------------------------------------------
301 dnl Verify if the C compiler being used is SUN's.
302
303 AC_DEFUN([CURL_CHECK_COMPILER_SUN], [
304   AC_MSG_CHECKING([whether we are using the SUN C compiler])
305   CURL_CHECK_DEF([__SUNPRO_C], [], [silent])
306   if test "$curl_cv_have_def___SUNPRO_C" = "yes"; then
307     AC_MSG_RESULT([yes])
308     compiler_id="SUNC"
309     flags_dbg_all="-g -s"
310     flags_dbg_yes="-g"
311     flags_dbg_off="-s"
312     flags_opt_all="-O -xO -xO1 -xO2 -xO3 -xO4 -xO5"
313     flags_opt_yes="-xO2"
314     flags_opt_off=""
315   else
316     AC_MSG_RESULT([no])
317   fi
318 ])
319
320
321 dnl CURL_CHECK_COMPILER_TINYC
322 dnl -------------------------------------------------
323 dnl Verify if the C compiler being used is TINYC.
324
325 AC_DEFUN([CURL_CHECK_COMPILER_TINYC], [
326   AC_MSG_CHECKING([whether we are using the TinyCC C compiler])
327   CURL_CHECK_DEF([__TINYC__], [], [silent])
328   if test "$curl_cv_have_def___TINYC__" = "yes"; then
329     AC_MSG_RESULT([yes])
330     compiler_id="TINYC"
331     flags_dbg_all="-g -b"
332     flags_dbg_yes="-g -b"
333     flags_dbg_off=""
334     flags_opt_all=""
335     flags_opt_yes=""
336     flags_opt_off=""
337   else
338     AC_MSG_RESULT([no])
339   fi
340 ])
341
342
343 dnl CURL_CONVERT_INCLUDE_TO_ISYSTEM
344 dnl -------------------------------------------------
345 dnl Changes standard include paths present in CFLAGS
346 dnl and CPPFLAGS into isystem include paths. This is
347 dnl done to prevent GNUC from generating warnings on
348 dnl headers from these locations, even though this is
349 dnl not reliable on ancient GNUC versions.
350
351 AC_DEFUN([CURL_CONVERT_INCLUDE_TO_ISYSTEM], [
352   tmp_has_include="no"
353   tmp_chg_FLAGS=$CFLAGS
354   for word1 in $tmp_chg_FLAGS; do
355     case "$word1" in
356       -I*)
357         tmp_has_include="yes"
358         ;;
359     esac
360   done
361   if test "$tmp_has_include" = "yes"; then
362     tmp_chg_FLAGS=`echo $tmp_chg_FLAGS | sed 's/^-I/ -isystem /g'`
363     tmp_chg_FLAGS=`echo $tmp_chg_FLAGS | sed 's/ -I/ -isystem /g'`
364     CFLAGS=`eval echo $tmp_chg_FLAGS`
365   fi
366   tmp_has_include="no"
367   tmp_chg_FLAGS=$CPPFLAGS
368   for word1 in $tmp_chg_FLAGS; do
369     case "$word1" in
370       -I*)
371         tmp_has_include="yes"
372         ;;
373     esac
374   done
375   if test "$tmp_has_include" = "yes"; then
376     tmp_chg_FLAGS=`echo $tmp_chg_FLAGS | sed 's/^-I/ -isystem /g'`
377     tmp_chg_FLAGS=`echo $tmp_chg_FLAGS | sed 's/ -I/ -isystem /g'`
378     CPPFLAGS=`eval echo $tmp_chg_FLAGS`
379   fi
380 ])
381
382
383 dnl CURL_COMPILER_WORKS_IFELSE ([ACTION-IF-WORKS], [ACTION-IF-NOT-WORKS])
384 dnl -------------------------------------------------
385 dnl Verify if the C compiler seems to work with the
386 dnl settings that are 'active' at the time the test
387 dnl is performed.
388
389 AC_DEFUN([CURL_COMPILER_WORKS_IFELSE], [
390   dnl compilation capability verification
391   tmp_compiler_works="unknown"
392   AC_COMPILE_IFELSE([
393     AC_LANG_PROGRAM([[
394     ]],[[
395       int i = 1;
396       return i;
397     ]])
398   ],[
399     tmp_compiler_works="yes"
400   ],[
401     tmp_compiler_works="no"
402     echo " " >&6
403     sed 's/^/cc-fail> /' conftest.err >&6
404     echo " " >&6
405   ])
406   dnl linking capability verification
407   if test "$tmp_compiler_works" = "yes"; then
408     AC_LINK_IFELSE([
409       AC_LANG_PROGRAM([[
410       ]],[[
411         int i = 1;
412         return i;
413       ]])
414     ],[
415       tmp_compiler_works="yes"
416     ],[
417       tmp_compiler_works="no"
418       echo " " >&6
419       sed 's/^/ln-fail> /' conftest.err >&6
420       echo " " >&6
421     ])
422   fi
423   dnl only do runtime verification when not cross-compiling
424   if test "x$cross_compiling" != "xyes" &&
425     test "$tmp_compiler_works" = "yes"; then
426     AC_RUN_IFELSE([
427       AC_LANG_PROGRAM([[
428 #       ifdef __STDC__
429 #         include <stdlib.h>
430 #       endif
431       ]],[[
432         int i = 0;
433         exit(i);
434       ]])
435     ],[
436       tmp_compiler_works="yes"
437     ],[
438       tmp_compiler_works="no"
439       echo " " >&6
440       echo "rn-fail test program exited with status $ac_status" >&6
441       echo " " >&6
442     ])
443   fi
444   dnl branch upon test result
445   if test "$tmp_compiler_works" = "yes"; then
446   ifelse($1,,:,[$1])
447   ifelse($2,,,[else
448     $2])
449   fi
450 ])
451
452
453 dnl CURL_SET_COMPILER_BASIC_OPTS
454 dnl -------------------------------------------------
455 dnl Sets compiler specific options/flags which do not
456 dnl depend on configure's debug, optimize or warnings
457 dnl options.
458
459 AC_DEFUN([CURL_SET_COMPILER_BASIC_OPTS], [
460   AC_REQUIRE([CURL_CHECK_COMPILER])dnl
461   #
462   if test "$compiler_id" != "unknown"; then
463     #
464     if test "$compiler_id" = "GNUC"; then
465       CURL_CONVERT_INCLUDE_TO_ISYSTEM
466     fi
467     #
468     tmp_save_CPPFLAGS="$CPPFLAGS"
469     tmp_save_CFLAGS="$CFLAGS"
470     tmp_CPPFLAGS=""
471     tmp_CFLAGS=""
472     #
473     case "$compiler_id" in
474         #
475       DECC)
476         #
477         dnl Select strict ANSI C compiler mode
478         tmp_CFLAGS="$tmp_CFLAGS -std1"
479         dnl Turn off optimizer ANSI C aliasing rules
480         tmp_CFLAGS="$tmp_CFLAGS -noansi_alias"
481         dnl Generate warnings for missing function prototypes
482         tmp_CFLAGS="$tmp_CFLAGS -warnprotos"
483         dnl Change some warnings into fatal errors
484         tmp_CFLAGS="$tmp_CFLAGS -msg_fatal toofewargs,toomanyargs"
485         ;;
486         #
487       GNUC)
488         #
489         dnl Placeholder
490         tmp_CFLAGS="$tmp_CFLAGS"
491         ;;
492         #
493       HPUXC)
494         #
495         dnl Disallow run-time dereferencing of null pointers
496         tmp_CFLAGS="$tmp_CFLAGS -z"
497         dnl Disable some remarks
498         dnl #4227: padding struct with n bytes to align member
499         dnl #4255: padding size of struct with n bytes to alignment boundary
500         tmp_CFLAGS="$tmp_CFLAGS +W 4227,4255"
501         ;;
502         #
503       IBMC)
504         #
505         dnl Ensure that compiler optimizations are always thread-safe.
506         tmp_CFLAGS="$tmp_CFLAGS -qthreaded"
507         dnl Disable type based strict aliasing optimizations, using worst
508         dnl case aliasing assumptions when compiling. Type based aliasing
509         dnl would restrict the lvalues that could be safely used to access
510         dnl a data object.
511         tmp_CFLAGS="$tmp_CFLAGS -qnoansialias"
512         dnl Force compiler to stop after the compilation phase, without
513         dnl generating an object code file when compilation has errors.
514         tmp_CFLAGS="$tmp_CFLAGS -qhalt=e"
515         ;;
516         #
517       ICC_unix)
518         #
519         dnl On unix this compiler uses gcc's header files, so
520         dnl we select ANSI C89 dialect plus GNU extensions.
521         tmp_CPPFLAGS="$tmp_CPPFLAGS -std=gnu89"
522         dnl Change some warnings into errors
523         dnl #140: too many arguments in function call
524         dnl #147: declaration is incompatible with 'previous one'
525         dnl #165: too few arguments in function call
526         dnl #266: function declared implicitly
527         tmp_CPPFLAGS="$tmp_CPPFLAGS -we 140,147,165,266"
528         dnl Disable some remarks
529         dnl #279: controlling expression is constant
530         dnl #981: operands are evaluated in unspecified order
531         dnl #1469: "cc" clobber ignored
532         tmp_CPPFLAGS="$tmp_CPPFLAGS -wd 279,981,1469"
533         dnl Disable use of ANSI C aliasing rules in optimizations
534         tmp_CFLAGS="$tmp_CFLAGS -no-ansi-alias"
535         dnl Disable floating point optimizations
536         tmp_CFLAGS="$tmp_CFLAGS -fp-model precise"
537         ;;
538         #
539       ICC_windows)
540         #
541         dnl Placeholder
542         tmp_CFLAGS="$tmp_CFLAGS"
543         ;;
544         #
545       LCC)
546         #
547         dnl Disallow run-time dereferencing of null pointers
548         tmp_CFLAGS="$tmp_CFLAGS -n"
549         ;;
550         #
551       SGI_MIPS_C)
552         #
553         dnl Placeholder
554         tmp_CFLAGS="$tmp_CFLAGS"
555         ;;
556         #
557       SGI_MIPSpro_C)
558         #
559         dnl Placeholder
560         tmp_CFLAGS="$tmp_CFLAGS"
561         ;;
562         #
563       SUNC)
564         #
565         dnl Placeholder
566         tmp_CFLAGS="$tmp_CFLAGS"
567         ;;
568         #
569       TINYC)
570         #
571         dnl Placeholder
572         tmp_CFLAGS="$tmp_CFLAGS"
573         ;;
574         #
575     esac
576     #
577     tmp_CPPFLAGS=`eval echo $tmp_CPPFLAGS`
578     tmp_CFLAGS=`eval echo $tmp_CFLAGS`
579     #
580     if test ! -z "$tmp_CFLAGS" || test ! -z "$tmp_CPPFLAGS"; then
581       AC_MSG_CHECKING([if compiler accepts some basic options])
582       CPPFLAGS=`eval echo $tmp_save_CPPFLAGS $tmp_CPPFLAGS`
583       CFLAGS=`eval echo $tmp_save_CFLAGS $tmp_CFLAGS`
584       CURL_COMPILER_WORKS_IFELSE([
585         AC_MSG_RESULT([yes])
586         AC_MSG_NOTICE([compiler options added: $tmp_CFLAGS $tmp_CPPFLAGS])
587       ],[
588         AC_MSG_RESULT([no])
589         AC_MSG_WARN([compiler options rejected: $tmp_CFLAGS $tmp_CPPFLAGS])
590         dnl restore initial settings
591         CPPFLAGS="$tmp_save_CPPFLAGS"
592         CFLAGS="$tmp_save_CFLAGS"
593       ])
594     fi
595     #
596   fi
597 ])
598
599
600 dnl CURL_SET_COMPILER_DEBUG_OPTS
601 dnl -------------------------------------------------
602 dnl Sets compiler specific options/flags which depend
603 dnl on configure's debug option.
604
605 AC_DEFUN([CURL_SET_COMPILER_DEBUG_OPTS], [
606   AC_REQUIRE([CURL_CHECK_OPTION_DEBUG])dnl
607   AC_REQUIRE([CURL_CHECK_COMPILER])dnl
608   #
609   if test "$compiler_id" != "unknown"; then
610     #
611     tmp_save_CFLAGS="$CFLAGS"
612     tmp_save_CPPFLAGS="$CPPFLAGS"
613     #
614     tmp_options=""
615     tmp_CFLAGS="$CFLAGS"
616     tmp_CPPFLAGS="$CPPFLAGS"
617     CURL_VAR_STRIP([tmp_CFLAGS],[$flags_dbg_all])
618     CURL_VAR_STRIP([tmp_CPPFLAGS],[$flags_dbg_all])
619     #
620     if test "$want_debug" = "yes"; then
621       AC_MSG_CHECKING([if compiler accepts debug enabling options])
622       tmp_options="$flags_dbg_yes"
623     fi
624     if test "$want_debug" = "no"; then
625       AC_MSG_CHECKING([if compiler accepts debug disabling options])
626       tmp_options="$flags_dbg_off"
627     fi
628     #
629     CPPFLAGS=`eval echo $tmp_CPPFLAGS`
630     CFLAGS=`eval echo $tmp_CFLAGS $tmp_options`
631     CURL_COMPILER_WORKS_IFELSE([
632       AC_MSG_RESULT([yes])
633       AC_MSG_NOTICE([compiler options added: $tmp_options])
634     ],[
635       AC_MSG_RESULT([no])
636       AC_MSG_WARN([compiler options rejected: $tmp_options])
637       dnl restore initial settings
638       CPPFLAGS="$tmp_save_CPPFLAGS"
639       CFLAGS="$tmp_save_CFLAGS"
640     ])
641     #
642   fi
643 ])
644
645
646 dnl CURL_SET_COMPILER_OPTIMIZE_OPTS
647 dnl -------------------------------------------------
648 dnl Sets compiler specific options/flags which depend
649 dnl on configure's optimize option.
650
651 AC_DEFUN([CURL_SET_COMPILER_OPTIMIZE_OPTS], [
652   AC_REQUIRE([CURL_CHECK_OPTION_OPTIMIZE])dnl
653   AC_REQUIRE([CURL_CHECK_COMPILER])dnl
654   #
655   if test "$compiler_id" != "unknown"; then
656     #
657     tmp_save_CFLAGS="$CFLAGS"
658     tmp_save_CPPFLAGS="$CPPFLAGS"
659     #
660     tmp_options=""
661     tmp_CFLAGS="$CFLAGS"
662     tmp_CPPFLAGS="$CPPFLAGS"
663     honor_optimize_option="yes"
664     #
665     dnl If optimization request setting has not been explicitly specified,
666     dnl it has been derived from the debug setting and initially assumed.
667     dnl This initially assumed optimizer setting will finally be ignored
668     dnl if CFLAGS or CPPFLAGS already hold optimizer flags. This implies
669     dnl that an initially assumed optimizer setting might not be honored.
670     #
671     if test "$want_optimize" = "assume_no" ||
672        test "$want_optimize" = "assume_yes"; then
673       AC_MSG_CHECKING([if compiler optimizer assumed setting might be used])
674       CURL_VAR_MATCH_IFELSE([tmp_CFLAGS],[$flags_opt_all],[
675         honor_optimize_option="no"
676       ])
677       CURL_VAR_MATCH_IFELSE([tmp_CPPFLAGS],[$flags_opt_all],[
678         honor_optimize_option="no"
679       ])
680       AC_MSG_RESULT([$honor_optimize_option])
681       if test "$honor_optimize_option" = "yes"; then
682         if test "$want_optimize" = "assume_yes"; then
683           want_optimize="yes"
684         fi
685         if test "$want_optimize" = "assume_no"; then
686           want_optimize="no"
687         fi
688       fi
689     fi
690     #
691     if test "$honor_optimize_option" = "yes"; then
692       CURL_VAR_STRIP([tmp_CFLAGS],[$flags_opt_all])
693       CURL_VAR_STRIP([tmp_CPPFLAGS],[$flags_opt_all])
694       if test "$want_optimize" = "yes"; then
695         AC_MSG_CHECKING([if compiler accepts optimizer enabling options])
696         tmp_options="$flags_opt_yes"
697       fi
698       if test "$want_optimize" = "no"; then
699         AC_MSG_CHECKING([if compiler accepts optimizer disabling options])
700         tmp_options="$flags_opt_off"
701       fi
702       CPPFLAGS=`eval echo $tmp_CPPFLAGS`
703       CFLAGS=`eval echo $tmp_CFLAGS $tmp_options`
704       CURL_COMPILER_WORKS_IFELSE([
705         AC_MSG_RESULT([yes])
706         AC_MSG_NOTICE([compiler options added: $tmp_options])
707       ],[
708         AC_MSG_RESULT([no])
709         AC_MSG_WARN([compiler options rejected: $tmp_options])
710         dnl restore initial settings
711         CPPFLAGS="$tmp_save_CPPFLAGS"
712         CFLAGS="$tmp_save_CFLAGS"
713       ])
714     fi
715     #
716   fi
717 ])
718
719
720 dnl CURL_SET_COMPILER_WARNING_OPTS
721 dnl -------------------------------------------------
722 dnl Sets compiler options/flags which depend on
723 dnl configure's warnings given option.
724
725 AC_DEFUN([CURL_SET_COMPILER_WARNING_OPTS], [
726   AC_REQUIRE([CURL_CHECK_OPTION_WARNINGS])dnl
727   AC_REQUIRE([CURL_CHECK_COMPILER])dnl
728   #
729   if test "$compiler_id" != "unknown"; then
730     #
731     tmp_save_CPPFLAGS="$CPPFLAGS"
732     tmp_save_CFLAGS="$CFLAGS"
733     tmp_CPPFLAGS=""
734     tmp_CFLAGS=""
735     #
736     case "$compiler_id" in
737         #
738       DECC)
739         #
740         if test "$want_warnings" = "yes"; then
741           dnl Select a higher warning level than default level2
742           tmp_CFLAGS="$tmp_CFLAGS -msg_enable level3"
743         fi
744         ;;
745         #
746       GNUC)
747         #
748         if test "$want_warnings" = "yes"; then
749           dnl Set of options we believe *ALL* gcc versions support:
750           tmp_CFLAGS="$tmp_CFLAGS -pedantic -Wall -W -Winline -Wnested-externs"
751           tmp_CFLAGS="$tmp_CFLAGS -Wmissing-prototypes -Wpointer-arith"
752           tmp_CFLAGS="$tmp_CFLAGS -Wwrite-strings"
753           dnl -Wcast-align is a bit too annoying on all gcc versions ;-)
754           if test "$compiler_num" -ge "207"; then
755             dnl gcc 2.7 or later
756             tmp_CFLAGS="$tmp_CFLAGS -Wmissing-declarations"
757           fi
758           if test "$compiler_num" -gt "295"; then
759             dnl only if the compiler is newer than 2.95 since we got lots of
760             dnl "`_POSIX_C_SOURCE' is not defined" in system headers with
761             dnl gcc 2.95.4 on FreeBSD 4.9!
762             tmp_CFLAGS="$tmp_CFLAGS -Wno-long-long -Wno-multichar -Wshadow"
763             tmp_CFLAGS="$tmp_CFLAGS -Wsign-compare -Wundef"
764           fi
765           if test "$compiler_num" -ge "296"; then
766             dnl gcc 2.96 or later
767             tmp_CFLAGS="$tmp_CFLAGS -Wfloat-equal"
768           fi
769           if test "$compiler_num" -gt "296"; then
770             dnl this option does not exist in 2.96
771             tmp_CFLAGS="$tmp_CFLAGS -Wno-format-nonliteral"
772           fi
773           dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
774           dnl on i686-Linux as it gives us heaps with false positives.
775           dnl Also, on gcc 4.0.X it is totally unbearable and complains all
776           dnl over making it unusable for generic purposes. Let's not use it.
777           if test "$compiler_num" -ge "303"; then
778             dnl gcc 3.3 and later
779             tmp_CFLAGS="$tmp_CFLAGS -Wendif-labels -Wstrict-prototypes"
780           fi
781           if test "$compiler_num" -ge "304"; then
782             dnl gcc 3.4 and later
783             tmp_CFLAGS="$tmp_CFLAGS -Wdeclaration-after-statement"
784           fi
785         fi
786         ;;
787         #
788       HPUXC)
789         #
790         if test "$want_warnings" = "yes"; then
791           dnl Issue all warnings
792           dnl tmp_CFLAGS="$tmp_CFLAGS +w1"
793           dnl Due to the HP-UX socklen_t issue it is insane to use the +w1
794           dnl warning level. Until the issue is somehow fixed we will just
795           dnl use the +w2 warning level.
796           tmp_CFLAGS="$tmp_CFLAGS +w2"
797         fi
798         ;;
799         #
800       IBMC)
801         #
802         dnl Placeholder
803         tmp_CFLAGS="$tmp_CFLAGS"
804         ;;
805         #
806       ICC_unix)
807         #
808         if test "$want_warnings" = "yes"; then
809           if test "$compiler_num" -gt "600"; then
810             dnl Show errors, warnings, and remarks
811             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wall"
812             dnl Perform extra compile-time code checking
813             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wcheck"
814           fi
815         fi
816         ;;
817         #
818       ICC_windows)
819         #
820         dnl Placeholder
821         tmp_CFLAGS="$tmp_CFLAGS"
822         ;;
823         #
824       LCC)
825         #
826         if test "$want_warnings" = "yes"; then
827           dnl Highest warning level is double -A, next is single -A.
828           dnl Due to the big number of warnings this triggers on third
829           dnl party header files it is impratical for us to use this
830           dnl warning level here. If you want them define it in CFLAGS.
831           tmp_CFLAGS="$tmp_CFLAGS -A"
832         fi
833         ;;
834         #
835       SGI_MIPS_C)
836         #
837         if test "$want_warnings" = "yes"; then
838           dnl Perform stricter semantic and lint-like checks
839           tmp_CFLAGS="$tmp_CFLAGS -fullwarn"
840         fi
841         ;;
842         #
843       SGI_MIPSpro_C)
844         #
845         if test "$want_warnings" = "yes"; then
846           dnl Perform stricter semantic and lint-like checks
847           tmp_CFLAGS="$tmp_CFLAGS -fullwarn"
848           dnl Disable some remarks
849           dnl #1209: controlling expression is constant
850           tmp_CFLAGS="$tmp_CFLAGS -woff 1209"
851         fi
852         ;;
853         #
854       SUNC)
855         #
856         if test "$want_warnings" = "yes"; then
857           dnl Perform stricter semantic and lint-like checks
858           tmp_CFLAGS="$tmp_CFLAGS -v"
859         fi
860         ;;
861         #
862       TINYC)
863         #
864         if test "$want_warnings" = "yes"; then
865           dnl Activate all warnings
866           tmp_CFLAGS="$tmp_CFLAGS -Wall"
867           dnl Make string constants be of type const char *
868           tmp_CFLAGS="$tmp_CFLAGS -Wwrite-strings"
869           dnl Warn use of unsupported GCC features ignored by TCC
870           tmp_CFLAGS="$tmp_CFLAGS -Wunsupported"
871         fi
872         ;;
873         #
874     esac
875     #
876     tmp_CPPFLAGS=`eval echo $tmp_CPPFLAGS`
877     tmp_CFLAGS=`eval echo $tmp_CFLAGS`
878     #
879     if test ! -z "$tmp_CFLAGS" || test ! -z "$tmp_CPPFLAGS"; then
880       AC_MSG_CHECKING([if compiler accepts strict warning options])
881       CPPFLAGS=`eval echo $tmp_save_CPPFLAGS $tmp_CPPFLAGS`
882       CFLAGS=`eval echo $tmp_save_CFLAGS $tmp_CFLAGS`
883       CURL_COMPILER_WORKS_IFELSE([
884         AC_MSG_RESULT([yes])
885         AC_MSG_NOTICE([compiler options added: $tmp_CFLAGS $tmp_CPPFLAGS])
886       ],[
887         AC_MSG_RESULT([no])
888         AC_MSG_WARN([compiler options rejected: $tmp_CFLAGS $tmp_CPPFLAGS])
889         dnl restore initial settings
890         CPPFLAGS="$tmp_save_CPPFLAGS"
891         CFLAGS="$tmp_save_CFLAGS"
892       ])
893     fi
894     #
895   fi
896 ])
897
898
899 dnl CURL_PROCESS_DEBUG_BUILD_OPTS
900 dnl -------------------------------------------------
901 dnl Settings which depend on configure's debug given
902 dnl option, and further configure the build process.
903 dnl Don't use this macro for compiler dependant stuff.
904
905 AC_DEFUN([CURL_PROCESS_DEBUG_BUILD_OPTS], [
906   AC_REQUIRE([CURL_CHECK_OPTION_DEBUG])dnl
907   AC_BEFORE([$0],[AC_PROG_LIBTOOL])dnl
908   #
909   if test "$want_debug" = "yes"; then
910     CPPFLAGS="$CPPFLAGS -DCURLDEBUG"
911   fi
912   #
913 ])
914
915
916 dnl CURL_CHECK_PROG_CC
917 dnl -------------------------------------------------
918 dnl Check for compiler program, preventing CFLAGS and
919 dnl CPPFLAGS from being unexpectedly changed.
920
921 AC_DEFUN([CURL_CHECK_PROG_CC], [
922   ac_save_CFLAGS="$CFLAGS"
923   ac_save_CPPFLAGS="$CPPFLAGS"
924   AC_PROG_CC
925   CFLAGS="$ac_save_CFLAGS"
926   CPPFLAGS="$ac_save_CPPFLAGS"
927 ])
928
929
930 dnl CURL_VAR_MATCH (VARNAME, VALUE)
931 dnl -------------------------------------------------
932 dnl Verifies if shell variable VARNAME contains VALUE.
933 dnl Contents of variable VARNAME and VALUE are handled
934 dnl as whitespace separated lists of words. If at least
935 dnl one word of VALUE is present in VARNAME the match
936 dnl is considered positive, otherwise false.
937
938 AC_DEFUN([CURL_VAR_MATCH], [
939   ac_var_match_word="no"
940   for word1 in $[$1]; do
941     for word2 in [$2]; do
942       if test "$word1" = "$word2"; then
943         ac_var_match_word="yes"
944       fi
945     done
946   done
947 ])
948
949
950 dnl CURL_VAR_MATCH_IFELSE (VARNAME, VALUE,
951 dnl                        [ACTION-IF-MATCH], [ACTION-IF-NOT-MATCH])
952 dnl -------------------------------------------------
953 dnl This performs a CURL_VAR_MATCH check and executes
954 dnl first branch if the match is positive, otherwise
955 dnl the second branch is executed.
956
957 AC_DEFUN([CURL_VAR_MATCH_IFELSE], [
958   CURL_VAR_MATCH([$1],[$2])
959   if test "$ac_var_match_word" = "yes"; then
960   ifelse($3,,:,[$3])
961   ifelse($4,,,[else
962     $4])
963   fi
964 ])
965
966
967 dnl CURL_VAR_STRIP (VARNAME, VALUE)
968 dnl -------------------------------------------------
969 dnl Contents of variable VARNAME and VALUE are handled
970 dnl as whitespace separated lists of words. Each word
971 dnl from VALUE is removed from VARNAME when present.
972
973 AC_DEFUN([CURL_VAR_STRIP], [
974   ac_var_stripped=""
975   for word1 in $[$1]; do
976     ac_var_strip_word="no"
977     for word2 in [$2]; do
978       if test "$word1" = "$word2"; then
979         ac_var_strip_word="yes"
980       fi
981     done
982     if test "$ac_var_strip_word" = "no"; then
983       ac_var_stripped="$ac_var_stripped $word1"
984     fi
985   done
986   dnl squeeze whitespace out of result
987   [$1]=`eval echo $ac_var_stripped`
988 ])