cares-compilers.m4: -Wno-pedantic-ms-format for Windows gcc 4.5 builds
[platform/upstream/c-ares.git] / m4 / cares-compilers.m4
1 #***************************************************************************
2 #
3 # Copyright (C) 2009-2012 by Daniel Stenberg et al
4 #
5 # Permission to use, copy, modify, and distribute this software and its
6 # documentation for any purpose and without fee is hereby granted, provided
7 # that the above copyright notice appear in all copies and that both that
8 # copyright notice and this permission notice appear in supporting
9 # documentation, and that the name of M.I.T. not be used in advertising or
10 # publicity pertaining to distribution of the software without specific,
11 # written prior permission.  M.I.T. makes no representations about the
12 # suitability of this software for any purpose.  It is provided "as is"
13 # without express or implied warranty.
14 #
15 #***************************************************************************
16
17 # File version for 'aclocal' use. Keep it a single number.
18 # serial 70
19
20
21 dnl CARES_CHECK_COMPILER
22 dnl -------------------------------------------------
23 dnl Verify if the C compiler being used is known.
24
25 AC_DEFUN([CARES_CHECK_COMPILER], [
26   AC_BEFORE([$0],[CARES_CHECK_NO_UNDEFINED])dnl
27   #
28   compiler_id="unknown"
29   compiler_num="0"
30   #
31   flags_dbg_all="unknown"
32   flags_dbg_yes="unknown"
33   flags_dbg_off="unknown"
34   flags_opt_all="unknown"
35   flags_opt_yes="unknown"
36   flags_opt_off="unknown"
37   #
38   flags_prefer_cppflags="no"
39   #
40   CARES_CHECK_COMPILER_DEC_C
41   CARES_CHECK_COMPILER_HPUX_C
42   CARES_CHECK_COMPILER_IBM_C
43   CARES_CHECK_COMPILER_INTEL_C
44   CARES_CHECK_COMPILER_CLANG
45   CARES_CHECK_COMPILER_GNU_C
46   CARES_CHECK_COMPILER_LCC
47   CARES_CHECK_COMPILER_SGI_MIPSPRO_C
48   CARES_CHECK_COMPILER_SGI_MIPS_C
49   CARES_CHECK_COMPILER_SUNPRO_C
50   CARES_CHECK_COMPILER_TINY_C
51   CARES_CHECK_COMPILER_WATCOM_C
52   #
53   if test "$compiler_id" = "unknown"; then
54   cat <<_EOF 1>&2
55 ***
56 *** Warning: This configure script does not have information about the
57 *** compiler you are using, relative to the flags required to enable or
58 *** disable generation of debug info, optimization options or warnings.
59 ***
60 *** Whatever settings are present in CFLAGS will be used for this run.
61 ***
62 *** If you wish to help the c-ares project to better support your compiler
63 *** you can report this and the required info on the c-ares development
64 *** mailing list: http://cool.haxx.se/mailman/listinfo/c-ares/
65 ***
66 _EOF
67   fi
68 ])
69
70
71 dnl CARES_CHECK_COMPILER_CLANG
72 dnl -------------------------------------------------
73 dnl Verify if compiler being used is clang.
74
75 AC_DEFUN([CARES_CHECK_COMPILER_CLANG], [
76   AC_BEFORE([$0],[CARES_CHECK_COMPILER_GNU_C])dnl
77   AC_MSG_CHECKING([if compiler is clang])
78   CURL_CHECK_DEF([__clang__], [], [silent])
79   if test "$curl_cv_have_def___clang__" = "yes"; then
80     AC_MSG_RESULT([yes])
81     compiler_id="CLANG"
82     clangver=`$CC -dumpversion`
83     clangvhi=`echo $clangver | cut -d . -f1`
84     clangvlo=`echo $clangver | cut -d . -f2`
85     compiler_num=`(expr $clangvhi "*" 100 + $clangvlo) 2>/dev/null`
86     flags_dbg_all="-g -g0 -g1 -g2 -g3"
87     flags_dbg_all="$flags_dbg_all -ggdb"
88     flags_dbg_all="$flags_dbg_all -gstabs"
89     flags_dbg_all="$flags_dbg_all -gstabs+"
90     flags_dbg_all="$flags_dbg_all -gcoff"
91     flags_dbg_all="$flags_dbg_all -gxcoff"
92     flags_dbg_all="$flags_dbg_all -gdwarf-2"
93     flags_dbg_all="$flags_dbg_all -gvms"
94     flags_dbg_yes="-g"
95     flags_dbg_off="-g0"
96     flags_opt_all="-O -O0 -O1 -O2 -Os -O3 -O4"
97     flags_opt_yes="-Os"
98     flags_opt_off="-O0"
99   else
100     AC_MSG_RESULT([no])
101   fi
102 ])
103
104
105 dnl CARES_CHECK_COMPILER_DEC_C
106 dnl -------------------------------------------------
107 dnl Verify if compiler being used is DEC C.
108
109 AC_DEFUN([CARES_CHECK_COMPILER_DEC_C], [
110   AC_MSG_CHECKING([if compiler is DEC/Compaq/HP C])
111   CURL_CHECK_DEF([__DECC], [], [silent])
112   CURL_CHECK_DEF([__DECC_VER], [], [silent])
113   if test "$curl_cv_have_def___DECC" = "yes" &&
114     test "$curl_cv_have_def___DECC_VER" = "yes"; then
115     AC_MSG_RESULT([yes])
116     compiler_id="DEC_C"
117     flags_dbg_all="-g -g0 -g1 -g2 -g3"
118     flags_dbg_yes="-g2"
119     flags_dbg_off="-g0"
120     flags_opt_all="-O -O0 -O1 -O2 -O3 -O4"
121     flags_opt_yes="-O1"
122     flags_opt_off="-O0"
123   else
124     AC_MSG_RESULT([no])
125   fi
126 ])
127
128
129 dnl CARES_CHECK_COMPILER_GNU_C
130 dnl -------------------------------------------------
131 dnl Verify if compiler being used is GNU C.
132
133 AC_DEFUN([CARES_CHECK_COMPILER_GNU_C], [
134   AC_REQUIRE([CARES_CHECK_COMPILER_INTEL_C])dnl
135   AC_REQUIRE([CARES_CHECK_COMPILER_CLANG])dnl
136   AC_MSG_CHECKING([if compiler is GNU C])
137   CURL_CHECK_DEF([__GNUC__], [], [silent])
138   if test "$curl_cv_have_def___GNUC__" = "yes" &&
139     test "$compiler_id" = "unknown"; then
140     AC_MSG_RESULT([yes])
141     compiler_id="GNU_C"
142     gccver=`$CC -dumpversion`
143     gccvhi=`echo $gccver | cut -d . -f1`
144     gccvlo=`echo $gccver | cut -d . -f2`
145     compiler_num=`(expr $gccvhi "*" 100 + $gccvlo) 2>/dev/null`
146     flags_dbg_all="-g -g0 -g1 -g2 -g3"
147     flags_dbg_all="$flags_dbg_all -ggdb"
148     flags_dbg_all="$flags_dbg_all -gstabs"
149     flags_dbg_all="$flags_dbg_all -gstabs+"
150     flags_dbg_all="$flags_dbg_all -gcoff"
151     flags_dbg_all="$flags_dbg_all -gxcoff"
152     flags_dbg_all="$flags_dbg_all -gdwarf-2"
153     flags_dbg_all="$flags_dbg_all -gvms"
154     flags_dbg_yes="-g"
155     flags_dbg_off="-g0"
156     flags_opt_all="-O -O0 -O1 -O2 -O3 -Os"
157     flags_opt_yes="-O2"
158     flags_opt_off="-O0"
159     CURL_CHECK_DEF([_WIN32], [], [silent])
160   else
161     AC_MSG_RESULT([no])
162   fi
163 ])
164
165
166 dnl CARES_CHECK_COMPILER_HPUX_C
167 dnl -------------------------------------------------
168 dnl Verify if compiler being used is HP-UX C.
169
170 AC_DEFUN([CARES_CHECK_COMPILER_HPUX_C], [
171   AC_MSG_CHECKING([if compiler is HP-UX C])
172   CURL_CHECK_DEF([__HP_cc], [], [silent])
173   if test "$curl_cv_have_def___HP_cc" = "yes"; then
174     AC_MSG_RESULT([yes])
175     compiler_id="HP_UX_C"
176     flags_dbg_all="-g -s"
177     flags_dbg_yes="-g"
178     flags_dbg_off="-s"
179     flags_opt_all="-O +O0 +O1 +O2 +O3 +O4"
180     flags_opt_yes="+O2"
181     flags_opt_off="+O0"
182   else
183     AC_MSG_RESULT([no])
184   fi
185 ])
186
187
188 dnl CARES_CHECK_COMPILER_IBM_C
189 dnl -------------------------------------------------
190 dnl Verify if compiler being used is IBM C.
191
192 AC_DEFUN([CARES_CHECK_COMPILER_IBM_C], [
193   AC_MSG_CHECKING([if compiler is IBM C])
194   CURL_CHECK_DEF([__IBMC__], [], [silent])
195   if test "$curl_cv_have_def___IBMC__" = "yes"; then
196     AC_MSG_RESULT([yes])
197     compiler_id="IBM_C"
198     flags_dbg_all="-g -g0 -g1 -g2 -g3"
199     flags_dbg_yes="-g"
200     flags_dbg_off=""
201     flags_opt_all="-O -O0 -O1 -O2 -O3 -O4 -O5"
202     flags_opt_all="$flags_opt_all -qnooptimize"
203     flags_opt_all="$flags_opt_all -qoptimize=0"
204     flags_opt_all="$flags_opt_all -qoptimize=1"
205     flags_opt_all="$flags_opt_all -qoptimize=2"
206     flags_opt_all="$flags_opt_all -qoptimize=3"
207     flags_opt_all="$flags_opt_all -qoptimize=4"
208     flags_opt_all="$flags_opt_all -qoptimize=5"
209     flags_opt_yes="-O2"
210     flags_opt_off="-qnooptimize"
211     flags_prefer_cppflags="yes"
212   else
213     AC_MSG_RESULT([no])
214   fi
215 ])
216
217
218 dnl CARES_CHECK_COMPILER_INTEL_C
219 dnl -------------------------------------------------
220 dnl Verify if compiler being used is Intel C.
221
222 AC_DEFUN([CARES_CHECK_COMPILER_INTEL_C], [
223   AC_BEFORE([$0],[CARES_CHECK_COMPILER_GNU_C])dnl
224   AC_MSG_CHECKING([if compiler is Intel C])
225   CURL_CHECK_DEF([__INTEL_COMPILER], [], [silent])
226   if test "$curl_cv_have_def___INTEL_COMPILER" = "yes"; then
227     AC_MSG_RESULT([yes])
228     compiler_num="$curl_cv_def___INTEL_COMPILER"
229     CURL_CHECK_DEF([__unix__], [], [silent])
230     if test "$curl_cv_have_def___unix__" = "yes"; then
231       compiler_id="INTEL_UNIX_C"
232       flags_dbg_all="-g -g0"
233       flags_dbg_yes="-g"
234       flags_dbg_off="-g0"
235       flags_opt_all="-O -O0 -O1 -O2 -O3 -Os"
236       flags_opt_yes="-O2"
237       flags_opt_off="-O0"
238     else
239       compiler_id="INTEL_WINDOWS_C"
240       flags_dbg_all="/ZI /Zi /zI /zi /ZD /Zd /zD /zd /Z7 /z7 /Oy /Oy-"
241       flags_dbg_all="$flags_dbg_all /debug"
242       flags_dbg_all="$flags_dbg_all /debug:none"
243       flags_dbg_all="$flags_dbg_all /debug:minimal"
244       flags_dbg_all="$flags_dbg_all /debug:partial"
245       flags_dbg_all="$flags_dbg_all /debug:full"
246       flags_dbg_all="$flags_dbg_all /debug:semantic_stepping"
247       flags_dbg_all="$flags_dbg_all /debug:extended"
248       flags_dbg_yes="/Zi /Oy-"
249       flags_dbg_off="/debug:none /Oy-"
250       flags_opt_all="/O /O0 /O1 /O2 /O3 /Od /Og /Og- /Oi /Oi-"
251       flags_opt_yes="/O2"
252       flags_opt_off="/Od"
253     fi
254   else
255     AC_MSG_RESULT([no])
256   fi
257 ])
258
259
260 dnl CARES_CHECK_COMPILER_LCC
261 dnl -------------------------------------------------
262 dnl Verify if compiler being used is LCC.
263
264 AC_DEFUN([CARES_CHECK_COMPILER_LCC], [
265   AC_MSG_CHECKING([if compiler is LCC])
266   CURL_CHECK_DEF([__LCC__], [], [silent])
267   if test "$curl_cv_have_def___LCC__" = "yes"; then
268     AC_MSG_RESULT([yes])
269     compiler_id="LCC"
270     flags_dbg_all="-g"
271     flags_dbg_yes="-g"
272     flags_dbg_off=""
273     flags_opt_all=""
274     flags_opt_yes=""
275     flags_opt_off=""
276   else
277     AC_MSG_RESULT([no])
278   fi
279 ])
280
281
282 dnl CARES_CHECK_COMPILER_SGI_MIPS_C
283 dnl -------------------------------------------------
284 dnl Verify if compiler being used is SGI MIPS C.
285
286 AC_DEFUN([CARES_CHECK_COMPILER_SGI_MIPS_C], [
287   AC_REQUIRE([CARES_CHECK_COMPILER_SGI_MIPSPRO_C])dnl
288   AC_MSG_CHECKING([if compiler is SGI MIPS C])
289   CURL_CHECK_DEF([__GNUC__], [], [silent])
290   CURL_CHECK_DEF([__sgi], [], [silent])
291   if test "$curl_cv_have_def___GNUC__" = "no" &&
292     test "$curl_cv_have_def___sgi" = "yes" &&
293     test "$compiler_id" = "unknown"; then
294     AC_MSG_RESULT([yes])
295     compiler_id="SGI_MIPS_C"
296     flags_dbg_all="-g -g0 -g1 -g2 -g3"
297     flags_dbg_yes="-g"
298     flags_dbg_off="-g0"
299     flags_opt_all="-O -O0 -O1 -O2 -O3 -Ofast"
300     flags_opt_yes="-O2"
301     flags_opt_off="-O0"
302   else
303     AC_MSG_RESULT([no])
304   fi
305 ])
306
307
308 dnl CARES_CHECK_COMPILER_SGI_MIPSPRO_C
309 dnl -------------------------------------------------
310 dnl Verify if compiler being used is SGI MIPSpro C.
311
312 AC_DEFUN([CARES_CHECK_COMPILER_SGI_MIPSPRO_C], [
313   AC_BEFORE([$0],[CARES_CHECK_COMPILER_SGI_MIPS_C])dnl
314   AC_MSG_CHECKING([if compiler is SGI MIPSpro C])
315   CURL_CHECK_DEF([__GNUC__], [], [silent])
316   CURL_CHECK_DEF([_COMPILER_VERSION], [], [silent])
317   CURL_CHECK_DEF([_SGI_COMPILER_VERSION], [], [silent])
318   if test "$curl_cv_have_def___GNUC__" = "no" &&
319     (test "$curl_cv_have_def__SGI_COMPILER_VERSION" = "yes" ||
320      test "$curl_cv_have_def__COMPILER_VERSION" = "yes"); then
321     AC_MSG_RESULT([yes])
322     compiler_id="SGI_MIPSPRO_C"
323     flags_dbg_all="-g -g0 -g1 -g2 -g3"
324     flags_dbg_yes="-g"
325     flags_dbg_off="-g0"
326     flags_opt_all="-O -O0 -O1 -O2 -O3 -Ofast"
327     flags_opt_yes="-O2"
328     flags_opt_off="-O0"
329   else
330     AC_MSG_RESULT([no])
331   fi
332 ])
333
334
335 dnl CARES_CHECK_COMPILER_SUNPRO_C
336 dnl -------------------------------------------------
337 dnl Verify if compiler being used is SunPro C.
338
339 AC_DEFUN([CARES_CHECK_COMPILER_SUNPRO_C], [
340   AC_MSG_CHECKING([if compiler is SunPro C])
341   CURL_CHECK_DEF([__SUNPRO_C], [], [silent])
342   if test "$curl_cv_have_def___SUNPRO_C" = "yes"; then
343     AC_MSG_RESULT([yes])
344     compiler_id="SUNPRO_C"
345     flags_dbg_all="-g -s"
346     flags_dbg_yes="-g"
347     flags_dbg_off="-s"
348     flags_opt_all="-O -xO -xO1 -xO2 -xO3 -xO4 -xO5"
349     flags_opt_yes="-xO2"
350     flags_opt_off=""
351   else
352     AC_MSG_RESULT([no])
353   fi
354 ])
355
356
357 dnl CARES_CHECK_COMPILER_TINY_C
358 dnl -------------------------------------------------
359 dnl Verify if compiler being used is Tiny C.
360
361 AC_DEFUN([CARES_CHECK_COMPILER_TINY_C], [
362   AC_MSG_CHECKING([if compiler is Tiny C])
363   CURL_CHECK_DEF([__TINYC__], [], [silent])
364   if test "$curl_cv_have_def___TINYC__" = "yes"; then
365     AC_MSG_RESULT([yes])
366     compiler_id="TINY_C"
367     flags_dbg_all="-g -b"
368     flags_dbg_yes="-g"
369     flags_dbg_off=""
370     flags_opt_all=""
371     flags_opt_yes=""
372     flags_opt_off=""
373   else
374     AC_MSG_RESULT([no])
375   fi
376 ])
377
378
379 dnl CARES_CHECK_COMPILER_WATCOM_C
380 dnl -------------------------------------------------
381 dnl Verify if compiler being used is Watcom C.
382
383 AC_DEFUN([CARES_CHECK_COMPILER_WATCOM_C], [
384   AC_MSG_CHECKING([if compiler is Watcom C])
385   CURL_CHECK_DEF([__WATCOMC__], [], [silent])
386   if test "$curl_cv_have_def___WATCOMC__" = "yes"; then
387     AC_MSG_RESULT([yes])
388     CURL_CHECK_DEF([__UNIX__], [], [silent])
389     if test "$curl_cv_have_def___UNIX__" = "yes"; then
390       compiler_id="WATCOM_UNIX_C"
391       flags_dbg_all="-g1 -g1+ -g2 -g3"
392       flags_dbg_yes="-g2"
393       flags_dbg_off=""
394       flags_opt_all="-O0 -O1 -O2 -O3"
395       flags_opt_yes="-O2"
396       flags_opt_off="-O0"
397     else
398       compiler_id="WATCOM_WINDOWS_C"
399       flags_dbg_all=""
400       flags_dbg_yes=""
401       flags_dbg_off=""
402       flags_opt_all=""
403       flags_opt_yes=""
404       flags_opt_off=""
405     fi
406   else
407     AC_MSG_RESULT([no])
408   fi
409 ])
410
411
412 dnl CARES_CONVERT_INCLUDE_TO_ISYSTEM
413 dnl -------------------------------------------------
414 dnl Changes standard include paths present in CFLAGS
415 dnl and CPPFLAGS into isystem include paths. This is
416 dnl done to prevent GNUC from generating warnings on
417 dnl headers from these locations, although on ancient
418 dnl GNUC versions these warnings are not silenced.
419
420 AC_DEFUN([CARES_CONVERT_INCLUDE_TO_ISYSTEM], [
421   AC_REQUIRE([CARES_SHFUNC_SQUEEZE])dnl
422   AC_REQUIRE([CARES_CHECK_COMPILER])dnl
423   if test "$compiler_id" = "GNU_C" ||
424     test "$compiler_id" = "CLANG"; then
425     tmp_has_include="no"
426     tmp_chg_FLAGS="$CFLAGS"
427     for word1 in $tmp_chg_FLAGS; do
428       case "$word1" in
429         -I*)
430           tmp_has_include="yes"
431           ;;
432       esac
433     done
434     if test "$tmp_has_include" = "yes"; then
435       tmp_chg_FLAGS=`echo "$tmp_chg_FLAGS" | "$SED" 's/^-I/ -isystem /g'`
436       tmp_chg_FLAGS=`echo "$tmp_chg_FLAGS" | "$SED" 's/ -I/ -isystem /g'`
437       CFLAGS="$tmp_chg_FLAGS"
438       squeeze CFLAGS
439     fi
440     tmp_has_include="no"
441     tmp_chg_FLAGS="$CPPFLAGS"
442     for word1 in $tmp_chg_FLAGS; do
443       case "$word1" in
444         -I*)
445           tmp_has_include="yes"
446           ;;
447       esac
448     done
449     if test "$tmp_has_include" = "yes"; then
450       tmp_chg_FLAGS=`echo "$tmp_chg_FLAGS" | "$SED" 's/^-I/ -isystem /g'`
451       tmp_chg_FLAGS=`echo "$tmp_chg_FLAGS" | "$SED" 's/ -I/ -isystem /g'`
452       CPPFLAGS="$tmp_chg_FLAGS"
453       squeeze CPPFLAGS
454     fi
455   fi
456 ])
457
458
459 dnl CARES_COMPILER_WORKS_IFELSE ([ACTION-IF-WORKS], [ACTION-IF-NOT-WORKS])
460 dnl -------------------------------------------------
461 dnl Verify if the C compiler seems to work with the
462 dnl settings that are 'active' at the time the test
463 dnl is performed.
464
465 AC_DEFUN([CARES_COMPILER_WORKS_IFELSE], [
466   dnl compilation capability verification
467   tmp_compiler_works="unknown"
468   AC_COMPILE_IFELSE([
469     AC_LANG_PROGRAM([[
470     ]],[[
471       int i = 1;
472       return i;
473     ]])
474   ],[
475     tmp_compiler_works="yes"
476   ],[
477     tmp_compiler_works="no"
478     echo " " >&6
479     sed 's/^/cc-fail: /' conftest.err >&6
480     echo " " >&6
481   ])
482   dnl linking capability verification
483   if test "$tmp_compiler_works" = "yes"; then
484     AC_LINK_IFELSE([
485       AC_LANG_PROGRAM([[
486       ]],[[
487         int i = 1;
488         return i;
489       ]])
490     ],[
491       tmp_compiler_works="yes"
492     ],[
493       tmp_compiler_works="no"
494       echo " " >&6
495       sed 's/^/link-fail: /' conftest.err >&6
496       echo " " >&6
497     ])
498   fi
499   dnl only do runtime verification when not cross-compiling
500   if test "x$cross_compiling" != "xyes" &&
501     test "$tmp_compiler_works" = "yes"; then
502     AC_RUN_IFELSE([
503       AC_LANG_PROGRAM([[
504 #       ifdef __STDC__
505 #         include <stdlib.h>
506 #       endif
507       ]],[[
508         int i = 0;
509         exit(i);
510       ]])
511     ],[
512       tmp_compiler_works="yes"
513     ],[
514       tmp_compiler_works="no"
515       echo " " >&6
516       echo "run-fail: test program exited with status $ac_status" >&6
517       echo " " >&6
518     ])
519   fi
520   dnl branch upon test result
521   if test "$tmp_compiler_works" = "yes"; then
522   ifelse($1,,:,[$1])
523   ifelse($2,,,[else
524     $2])
525   fi
526 ])
527
528
529 dnl CARES_SET_COMPILER_BASIC_OPTS
530 dnl -------------------------------------------------
531 dnl Sets compiler specific options/flags which do not
532 dnl depend on configure's debug, optimize or warnings
533 dnl options.
534
535 AC_DEFUN([CARES_SET_COMPILER_BASIC_OPTS], [
536   AC_REQUIRE([CARES_CHECK_COMPILER])dnl
537   AC_REQUIRE([CARES_SHFUNC_SQUEEZE])dnl
538   #
539   if test "$compiler_id" != "unknown"; then
540     #
541     if test "$compiler_id" = "GNU_C" ||
542       test "$compiler_id" = "CLANG"; then
543       CARES_CONVERT_INCLUDE_TO_ISYSTEM
544     fi
545     #
546     tmp_save_CPPFLAGS="$CPPFLAGS"
547     tmp_save_CFLAGS="$CFLAGS"
548     tmp_CPPFLAGS=""
549     tmp_CFLAGS=""
550     #
551     case "$compiler_id" in
552         #
553       CLANG)
554         #
555         dnl Disable warnings for unused arguments, otherwise clang will
556         dnl warn about compile-time arguments used during link-time, like
557         dnl -O and -g and -pedantic.
558         tmp_CFLAGS="$tmp_CFLAGS -Qunused-arguments"
559         ;;
560         #
561       DEC_C)
562         #
563         dnl Select strict ANSI C compiler mode
564         tmp_CFLAGS="$tmp_CFLAGS -std1"
565         dnl Turn off optimizer ANSI C aliasing rules
566         tmp_CFLAGS="$tmp_CFLAGS -noansi_alias"
567         dnl Generate warnings for missing function prototypes
568         tmp_CFLAGS="$tmp_CFLAGS -warnprotos"
569         dnl Change some warnings into fatal errors
570         tmp_CFLAGS="$tmp_CFLAGS -msg_fatal toofewargs,toomanyargs"
571         ;;
572         #
573       GNU_C)
574         #
575         dnl Placeholder
576         tmp_CFLAGS="$tmp_CFLAGS"
577         ;;
578         #
579       HP_UX_C)
580         #
581         dnl Disallow run-time dereferencing of null pointers
582         tmp_CFLAGS="$tmp_CFLAGS -z"
583         dnl Disable some remarks
584         dnl #4227: padding struct with n bytes to align member
585         dnl #4255: padding size of struct with n bytes to alignment boundary
586         tmp_CFLAGS="$tmp_CFLAGS +W 4227,4255"
587         ;;
588         #
589       IBM_C)
590         #
591         dnl Ensure that compiler optimizations are always thread-safe.
592         tmp_CPPFLAGS="$tmp_CPPFLAGS -qthreaded"
593         dnl Disable type based strict aliasing optimizations, using worst
594         dnl case aliasing assumptions when compiling. Type based aliasing
595         dnl would restrict the lvalues that could be safely used to access
596         dnl a data object.
597         tmp_CPPFLAGS="$tmp_CPPFLAGS -qnoansialias"
598         dnl Force compiler to stop after the compilation phase, without
599         dnl generating an object code file when compilation has errors.
600         tmp_CPPFLAGS="$tmp_CPPFLAGS -qhalt=e"
601         ;;
602         #
603       INTEL_UNIX_C)
604         #
605         dnl On unix this compiler uses gcc's header files, so
606         dnl we select ANSI C89 dialect plus GNU extensions.
607         tmp_CFLAGS="$tmp_CFLAGS -std=gnu89"
608         dnl Change some warnings into errors
609         dnl #140: too many arguments in function call
610         dnl #147: declaration is incompatible with 'previous one'
611         dnl #165: too few arguments in function call
612         dnl #266: function declared implicitly
613         tmp_CPPFLAGS="$tmp_CPPFLAGS -we 140,147,165,266"
614         dnl Disable some remarks
615         dnl #279: controlling expression is constant
616         dnl #981: operands are evaluated in unspecified order
617         dnl #1469: "cc" clobber ignored
618         tmp_CPPFLAGS="$tmp_CPPFLAGS -wd 279,981,1469"
619         ;;
620         #
621       INTEL_WINDOWS_C)
622         #
623         dnl Placeholder
624         tmp_CFLAGS="$tmp_CFLAGS"
625         ;;
626         #
627       LCC)
628         #
629         dnl Disallow run-time dereferencing of null pointers
630         tmp_CFLAGS="$tmp_CFLAGS -n"
631         ;;
632         #
633       SGI_MIPS_C)
634         #
635         dnl Placeholder
636         tmp_CFLAGS="$tmp_CFLAGS"
637         ;;
638         #
639       SGI_MIPSPRO_C)
640         #
641         dnl Placeholder
642         tmp_CFLAGS="$tmp_CFLAGS"
643         ;;
644         #
645       SUNPRO_C)
646         #
647         dnl Placeholder
648         tmp_CFLAGS="$tmp_CFLAGS"
649         ;;
650         #
651       TINY_C)
652         #
653         dnl Placeholder
654         tmp_CFLAGS="$tmp_CFLAGS"
655         ;;
656         #
657       WATCOM_UNIX_C)
658         #
659         dnl Placeholder
660         tmp_CFLAGS="$tmp_CFLAGS"
661         ;;
662         #
663       WATCOM_WINDOWS_C)
664         #
665         dnl Placeholder
666         tmp_CFLAGS="$tmp_CFLAGS"
667         ;;
668         #
669     esac
670     #
671     squeeze tmp_CPPFLAGS
672     squeeze tmp_CFLAGS
673     #
674     if test ! -z "$tmp_CFLAGS" || test ! -z "$tmp_CPPFLAGS"; then
675       AC_MSG_CHECKING([if compiler accepts some basic options])
676       CPPFLAGS="$tmp_save_CPPFLAGS $tmp_CPPFLAGS"
677       CFLAGS="$tmp_save_CFLAGS $tmp_CFLAGS"
678       squeeze CPPFLAGS
679       squeeze CFLAGS
680       CARES_COMPILER_WORKS_IFELSE([
681         AC_MSG_RESULT([yes])
682         AC_MSG_NOTICE([compiler options added: $tmp_CFLAGS $tmp_CPPFLAGS])
683       ],[
684         AC_MSG_RESULT([no])
685         AC_MSG_WARN([compiler options rejected: $tmp_CFLAGS $tmp_CPPFLAGS])
686         dnl restore initial settings
687         CPPFLAGS="$tmp_save_CPPFLAGS"
688         CFLAGS="$tmp_save_CFLAGS"
689       ])
690     fi
691     #
692   fi
693 ])
694
695
696 dnl CARES_SET_COMPILER_DEBUG_OPTS
697 dnl -------------------------------------------------
698 dnl Sets compiler specific options/flags which depend
699 dnl on configure's debug option.
700
701 AC_DEFUN([CARES_SET_COMPILER_DEBUG_OPTS], [
702   AC_REQUIRE([CARES_CHECK_OPTION_DEBUG])dnl
703   AC_REQUIRE([CARES_CHECK_COMPILER])dnl
704   AC_REQUIRE([CARES_SHFUNC_SQUEEZE])dnl
705   #
706   if test "$compiler_id" != "unknown"; then
707     #
708     tmp_save_CFLAGS="$CFLAGS"
709     tmp_save_CPPFLAGS="$CPPFLAGS"
710     #
711     tmp_options=""
712     tmp_CFLAGS="$CFLAGS"
713     tmp_CPPFLAGS="$CPPFLAGS"
714     CARES_VAR_STRIP([tmp_CFLAGS],[$flags_dbg_all])
715     CARES_VAR_STRIP([tmp_CPPFLAGS],[$flags_dbg_all])
716     #
717     if test "$want_debug" = "yes"; then
718       AC_MSG_CHECKING([if compiler accepts debug enabling options])
719       tmp_options="$flags_dbg_yes"
720     fi
721     if test "$want_debug" = "no"; then
722       AC_MSG_CHECKING([if compiler accepts debug disabling options])
723       tmp_options="$flags_dbg_off"
724     fi
725     #
726     if test "$flags_prefer_cppflags" = "yes"; then
727       CPPFLAGS="$tmp_CPPFLAGS $tmp_options"
728       CFLAGS="$tmp_CFLAGS"
729     else
730       CPPFLAGS="$tmp_CPPFLAGS"
731       CFLAGS="$tmp_CFLAGS $tmp_options"
732     fi
733     squeeze CPPFLAGS
734     squeeze CFLAGS
735     CARES_COMPILER_WORKS_IFELSE([
736       AC_MSG_RESULT([yes])
737       AC_MSG_NOTICE([compiler options added: $tmp_options])
738     ],[
739       AC_MSG_RESULT([no])
740       AC_MSG_WARN([compiler options rejected: $tmp_options])
741       dnl restore initial settings
742       CPPFLAGS="$tmp_save_CPPFLAGS"
743       CFLAGS="$tmp_save_CFLAGS"
744     ])
745     #
746   fi
747 ])
748
749
750 dnl CARES_SET_COMPILER_OPTIMIZE_OPTS
751 dnl -------------------------------------------------
752 dnl Sets compiler specific options/flags which depend
753 dnl on configure's optimize option.
754
755 AC_DEFUN([CARES_SET_COMPILER_OPTIMIZE_OPTS], [
756   AC_REQUIRE([CARES_CHECK_OPTION_OPTIMIZE])dnl
757   AC_REQUIRE([CARES_CHECK_COMPILER])dnl
758   AC_REQUIRE([CARES_SHFUNC_SQUEEZE])dnl
759   #
760   if test "$compiler_id" != "unknown"; then
761     #
762     tmp_save_CFLAGS="$CFLAGS"
763     tmp_save_CPPFLAGS="$CPPFLAGS"
764     #
765     tmp_options=""
766     tmp_CFLAGS="$CFLAGS"
767     tmp_CPPFLAGS="$CPPFLAGS"
768     honor_optimize_option="yes"
769     #
770     dnl If optimization request setting has not been explicitly specified,
771     dnl it has been derived from the debug setting and initially assumed.
772     dnl This initially assumed optimizer setting will finally be ignored
773     dnl if CFLAGS or CPPFLAGS already hold optimizer flags. This implies
774     dnl that an initially assumed optimizer setting might not be honored.
775     #
776     if test "$want_optimize" = "assume_no" ||
777        test "$want_optimize" = "assume_yes"; then
778       AC_MSG_CHECKING([if compiler optimizer assumed setting might be used])
779       CARES_VAR_MATCH_IFELSE([tmp_CFLAGS],[$flags_opt_all],[
780         honor_optimize_option="no"
781       ])
782       CARES_VAR_MATCH_IFELSE([tmp_CPPFLAGS],[$flags_opt_all],[
783         honor_optimize_option="no"
784       ])
785       AC_MSG_RESULT([$honor_optimize_option])
786       if test "$honor_optimize_option" = "yes"; then
787         if test "$want_optimize" = "assume_yes"; then
788           want_optimize="yes"
789         fi
790         if test "$want_optimize" = "assume_no"; then
791           want_optimize="no"
792         fi
793       fi
794     fi
795     #
796     if test "$honor_optimize_option" = "yes"; then
797       CARES_VAR_STRIP([tmp_CFLAGS],[$flags_opt_all])
798       CARES_VAR_STRIP([tmp_CPPFLAGS],[$flags_opt_all])
799       if test "$want_optimize" = "yes"; then
800         AC_MSG_CHECKING([if compiler accepts optimizer enabling options])
801         tmp_options="$flags_opt_yes"
802       fi
803       if test "$want_optimize" = "no"; then
804         AC_MSG_CHECKING([if compiler accepts optimizer disabling options])
805         tmp_options="$flags_opt_off"
806       fi
807       if test "$flags_prefer_cppflags" = "yes"; then
808         CPPFLAGS="$tmp_CPPFLAGS $tmp_options"
809         CFLAGS="$tmp_CFLAGS"
810       else
811         CPPFLAGS="$tmp_CPPFLAGS"
812         CFLAGS="$tmp_CFLAGS $tmp_options"
813       fi
814       squeeze CPPFLAGS
815       squeeze CFLAGS
816       CARES_COMPILER_WORKS_IFELSE([
817         AC_MSG_RESULT([yes])
818         AC_MSG_NOTICE([compiler options added: $tmp_options])
819       ],[
820         AC_MSG_RESULT([no])
821         AC_MSG_WARN([compiler options rejected: $tmp_options])
822         dnl restore initial settings
823         CPPFLAGS="$tmp_save_CPPFLAGS"
824         CFLAGS="$tmp_save_CFLAGS"
825       ])
826     fi
827     #
828   fi
829 ])
830
831
832 dnl CARES_SET_COMPILER_WARNING_OPTS
833 dnl -------------------------------------------------
834 dnl Sets compiler options/flags which depend on
835 dnl configure's warnings given option.
836
837 AC_DEFUN([CARES_SET_COMPILER_WARNING_OPTS], [
838   AC_REQUIRE([CARES_CHECK_OPTION_WARNINGS])dnl
839   AC_REQUIRE([CARES_CHECK_COMPILER])dnl
840   AC_REQUIRE([CARES_SHFUNC_SQUEEZE])dnl
841   #
842   if test "$compiler_id" != "unknown"; then
843     #
844     tmp_save_CPPFLAGS="$CPPFLAGS"
845     tmp_save_CFLAGS="$CFLAGS"
846     tmp_CPPFLAGS=""
847     tmp_CFLAGS=""
848     #
849     case "$compiler_id" in
850         #
851       CLANG)
852         #
853         if test "$want_warnings" = "yes"; then
854           dnl All versions of clang support the same warnings as at least
855           dnl gcc 4.2.1 except -Wunused.
856           tmp_CFLAGS="$tmp_CFLAGS -pedantic"
857           tmp_CFLAGS="$tmp_CFLAGS -Wall -Wextra"
858           tmp_CFLAGS="$tmp_CFLAGS -Wpointer-arith -Wwrite-strings"
859           tmp_CFLAGS="$tmp_CFLAGS -Wshadow"
860           tmp_CFLAGS="$tmp_CFLAGS -Winline -Wnested-externs"
861           tmp_CFLAGS="$tmp_CFLAGS -Wmissing-declarations"
862           tmp_CFLAGS="$tmp_CFLAGS -Wmissing-prototypes"
863           tmp_CFLAGS="$tmp_CFLAGS -Wno-long-long"
864           tmp_CFLAGS="$tmp_CFLAGS -Wfloat-equal"
865           tmp_CFLAGS="$tmp_CFLAGS -Wno-multichar -Wsign-compare"
866           tmp_CFLAGS="$tmp_CFLAGS -Wundef"
867           tmp_CFLAGS="$tmp_CFLAGS -Wno-format-nonliteral"
868           tmp_CFLAGS="$tmp_CFLAGS -Wendif-labels -Wstrict-prototypes"
869           tmp_CFLAGS="$tmp_CFLAGS -Wdeclaration-after-statement"
870           tmp_CFLAGS="$tmp_CFLAGS -Wcast-align"
871           tmp_CFLAGS="$tmp_CFLAGS -Wno-system-headers"
872           tmp_CFLAGS="$tmp_CFLAGS -Wshorten-64-to-32"
873           #
874           dnl Only clang 1.1 or later
875           if test "$compiler_num" -ge "101"; then
876             tmp_CFLAGS="$tmp_CFLAGS -Wunused"
877           fi
878         fi
879         ;;
880         #
881       DEC_C)
882         #
883         if test "$want_warnings" = "yes"; then
884           dnl Select a higher warning level than default level2
885           tmp_CFLAGS="$tmp_CFLAGS -msg_enable level3"
886         fi
887         ;;
888         #
889       GNU_C)
890         #
891         if test "$want_warnings" = "yes"; then
892           #
893           dnl Do not enable -pedantic when cross-compiling with a gcc older
894           dnl than 3.0, to avoid warnings from third party system headers.
895           if test "x$cross_compiling" != "xyes" ||
896             test "$compiler_num" -ge "300"; then
897             tmp_CFLAGS="$tmp_CFLAGS -pedantic"
898           fi
899           #
900           dnl Set of options we believe *ALL* gcc versions support:
901           tmp_CFLAGS="$tmp_CFLAGS -Wall -W"
902           #
903           dnl Only gcc 1.4 or later
904           if test "$compiler_num" -ge "104"; then
905             tmp_CFLAGS="$tmp_CFLAGS -Wpointer-arith -Wwrite-strings"
906             dnl If not cross-compiling with a gcc older than 3.0
907             if test "x$cross_compiling" != "xyes" ||
908               test "$compiler_num" -ge "300"; then
909               tmp_CFLAGS="$tmp_CFLAGS -Wunused -Wshadow"
910             fi
911           fi
912           #
913           dnl Only gcc 2.7 or later
914           if test "$compiler_num" -ge "207"; then
915             tmp_CFLAGS="$tmp_CFLAGS -Winline -Wnested-externs"
916             dnl If not cross-compiling with a gcc older than 3.0
917             if test "x$cross_compiling" != "xyes" ||
918               test "$compiler_num" -ge "300"; then
919               tmp_CFLAGS="$tmp_CFLAGS -Wmissing-declarations"
920               tmp_CFLAGS="$tmp_CFLAGS -Wmissing-prototypes"
921             fi
922           fi
923           #
924           dnl Only gcc 2.95 or later
925           if test "$compiler_num" -ge "295"; then
926             tmp_CFLAGS="$tmp_CFLAGS -Wno-long-long"
927           fi
928           #
929           dnl Only gcc 2.96 or later
930           if test "$compiler_num" -ge "296"; then
931             tmp_CFLAGS="$tmp_CFLAGS -Wfloat-equal"
932             tmp_CFLAGS="$tmp_CFLAGS -Wno-multichar -Wsign-compare"
933             dnl -Wundef used only if gcc is 2.96 or later since we get
934             dnl lots of "`_POSIX_C_SOURCE' is not defined" in system
935             dnl headers with gcc 2.95.4 on FreeBSD 4.9
936             tmp_CFLAGS="$tmp_CFLAGS -Wundef"
937           fi
938           #
939           dnl Only gcc 2.97 or later
940           if test "$compiler_num" -ge "297"; then
941             tmp_CFLAGS="$tmp_CFLAGS -Wno-format-nonliteral"
942           fi
943           #
944           dnl Only gcc 3.0 or later
945           if test "$compiler_num" -ge "300"; then
946             dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
947             dnl on i686-Linux as it gives us heaps with false positives.
948             dnl Also, on gcc 4.0.X it is totally unbearable and complains all
949             dnl over making it unusable for generic purposes. Let's not use it.
950             tmp_CFLAGS="$tmp_CFLAGS"
951           fi
952           #
953           dnl Only gcc 3.3 or later
954           if test "$compiler_num" -ge "303"; then
955             tmp_CFLAGS="$tmp_CFLAGS -Wendif-labels -Wstrict-prototypes"
956           fi
957           #
958           dnl Only gcc 3.4 or later
959           if test "$compiler_num" -ge "304"; then
960             tmp_CFLAGS="$tmp_CFLAGS -Wdeclaration-after-statement"
961           fi
962           #
963           dnl Only gcc 4.2 or later
964           if test "$compiler_num" -ge "402"; then
965             tmp_CFLAGS="$tmp_CFLAGS -Wcast-align"
966           fi
967           #
968           dnl Only gcc 4.3 or later
969           if test "$compiler_num" -ge "403"; then
970             tmp_CFLAGS="$tmp_CFLAGS -Wtype-limits -Wold-style-declaration"
971             tmp_CFLAGS="$tmp_CFLAGS -Wmissing-parameter-type -Wempty-body"
972             tmp_CFLAGS="$tmp_CFLAGS -Wclobbered -Wignored-qualifiers"
973             tmp_CFLAGS="$tmp_CFLAGS -Wconversion -Wno-sign-conversion -Wvla"
974           fi
975           #
976           dnl Only gcc 4.5 or later
977           if test "$compiler_num" -ge "405"; then
978             dnl Only windows targets
979             if test "$curl_cv_have_def__WIN32" = "yes"; then
980               tmp_CFLAGS="$tmp_CFLAGS -Wno-pedantic-ms-format"
981             fi
982           fi
983           #
984         fi
985         #
986         dnl Do not issue warnings for code in system include paths.
987         if test "$compiler_num" -ge "300"; then
988           tmp_CFLAGS="$tmp_CFLAGS -Wno-system-headers"
989         else
990           dnl When cross-compiling with a gcc older than 3.0, disable
991           dnl some warnings triggered on third party system headers.
992           if test "x$cross_compiling" = "xyes"; then
993             if test "$compiler_num" -ge "104"; then
994               dnl gcc 1.4 or later
995               tmp_CFLAGS="$tmp_CFLAGS -Wno-unused -Wno-shadow"
996             fi
997             if test "$compiler_num" -ge "207"; then
998               dnl gcc 2.7 or later
999               tmp_CFLAGS="$tmp_CFLAGS -Wno-missing-declarations"
1000               tmp_CFLAGS="$tmp_CFLAGS -Wno-missing-prototypes"
1001             fi
1002           fi
1003         fi
1004         ;;
1005         #
1006       HP_UX_C)
1007         #
1008         if test "$want_warnings" = "yes"; then
1009           dnl Issue all warnings
1010           tmp_CFLAGS="$tmp_CFLAGS +w1"
1011         fi
1012         ;;
1013         #
1014       IBM_C)
1015         #
1016         dnl Placeholder
1017         tmp_CFLAGS="$tmp_CFLAGS"
1018         ;;
1019         #
1020       INTEL_UNIX_C)
1021         #
1022         if test "$want_warnings" = "yes"; then
1023           if test "$compiler_num" -gt "600"; then
1024             dnl Show errors, warnings, and remarks
1025             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wall -w2"
1026             dnl Perform extra compile-time code checking
1027             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wcheck"
1028             dnl Warn on nested comments
1029             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wcomment"
1030             dnl Show warnings relative to deprecated features
1031             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wdeprecated"
1032             dnl Enable warnings for missing prototypes
1033             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wmissing-prototypes"
1034             dnl Enable warnings for 64-bit portability issues
1035             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wp64"
1036             dnl Enable warnings for questionable pointer arithmetic
1037             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wpointer-arith"
1038             dnl Check for function return typw issues
1039             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wreturn-type"
1040             dnl Warn on variable declarations hiding a previous one
1041             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wshadow"
1042             dnl Warn when a variable is used before initialized
1043             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wuninitialized"
1044             dnl Warn if a declared function is not used
1045             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wunused-function"
1046           fi
1047         fi
1048         dnl Disable using EBP register in optimizations
1049         tmp_CFLAGS="$tmp_CFLAGS -fno-omit-frame-pointer"
1050         dnl Disable use of ANSI C aliasing rules in optimizations
1051         tmp_CFLAGS="$tmp_CFLAGS -fno-strict-aliasing"
1052         dnl Value-safe optimizations on floating-point data
1053         tmp_CFLAGS="$tmp_CFLAGS -fp-model precise"
1054         dnl Only icc 10.0 or later
1055         if test "$compiler_num" -ge "1000"; then
1056           dnl Disable vectorizer diagnostic information
1057           tmp_CFLAGS="$tmp_CFLAGS -vec-report0"
1058         fi
1059         ;;
1060         #
1061       INTEL_WINDOWS_C)
1062         #
1063         dnl Placeholder
1064         tmp_CFLAGS="$tmp_CFLAGS"
1065         ;;
1066         #
1067       LCC)
1068         #
1069         if test "$want_warnings" = "yes"; then
1070           dnl Highest warning level is double -A, next is single -A.
1071           dnl Due to the big number of warnings these trigger on third
1072           dnl party header files it is impractical for us to use any of
1073           dnl them here. If you want them simply define it in CPPFLAGS.
1074           tmp_CFLAGS="$tmp_CFLAGS"
1075         fi
1076         ;;
1077         #
1078       SGI_MIPS_C)
1079         #
1080         if test "$want_warnings" = "yes"; then
1081           dnl Perform stricter semantic and lint-like checks
1082           tmp_CFLAGS="$tmp_CFLAGS -fullwarn"
1083         fi
1084         ;;
1085         #
1086       SGI_MIPSPRO_C)
1087         #
1088         if test "$want_warnings" = "yes"; then
1089           dnl Perform stricter semantic and lint-like checks
1090           tmp_CFLAGS="$tmp_CFLAGS -fullwarn"
1091           dnl Disable some remarks
1092           dnl #1209: controlling expression is constant
1093           tmp_CFLAGS="$tmp_CFLAGS -woff 1209"
1094         fi
1095         ;;
1096         #
1097       SUNPRO_C)
1098         #
1099         if test "$want_warnings" = "yes"; then
1100           dnl Perform stricter semantic and lint-like checks
1101           tmp_CFLAGS="$tmp_CFLAGS -v"
1102         fi
1103         ;;
1104         #
1105       TINY_C)
1106         #
1107         if test "$want_warnings" = "yes"; then
1108           dnl Activate all warnings
1109           tmp_CFLAGS="$tmp_CFLAGS -Wall"
1110           dnl Make string constants be of type const char *
1111           tmp_CFLAGS="$tmp_CFLAGS -Wwrite-strings"
1112           dnl Warn use of unsupported GCC features ignored by TCC
1113           tmp_CFLAGS="$tmp_CFLAGS -Wunsupported"
1114         fi
1115         ;;
1116         #
1117       WATCOM_UNIX_C)
1118         #
1119         if test "$want_warnings" = "yes"; then
1120           dnl Issue all warnings
1121           tmp_CFLAGS="$tmp_CFLAGS -Wall -Wextra"
1122         fi
1123         ;;
1124         #
1125       WATCOM_WINDOWS_C)
1126         #
1127         dnl Placeholder
1128         tmp_CFLAGS="$tmp_CFLAGS"
1129         ;;
1130         #
1131     esac
1132     #
1133     squeeze tmp_CPPFLAGS
1134     squeeze tmp_CFLAGS
1135     #
1136     if test ! -z "$tmp_CFLAGS" || test ! -z "$tmp_CPPFLAGS"; then
1137       AC_MSG_CHECKING([if compiler accepts strict warning options])
1138       CPPFLAGS="$tmp_save_CPPFLAGS $tmp_CPPFLAGS"
1139       CFLAGS="$tmp_save_CFLAGS $tmp_CFLAGS"
1140       squeeze CPPFLAGS
1141       squeeze CFLAGS
1142       CARES_COMPILER_WORKS_IFELSE([
1143         AC_MSG_RESULT([yes])
1144         AC_MSG_NOTICE([compiler options added: $tmp_CFLAGS $tmp_CPPFLAGS])
1145       ],[
1146         AC_MSG_RESULT([no])
1147         AC_MSG_WARN([compiler options rejected: $tmp_CFLAGS $tmp_CPPFLAGS])
1148         dnl restore initial settings
1149         CPPFLAGS="$tmp_save_CPPFLAGS"
1150         CFLAGS="$tmp_save_CFLAGS"
1151       ])
1152     fi
1153     #
1154   fi
1155 ])
1156
1157
1158 dnl CARES_SHFUNC_SQUEEZE
1159 dnl -------------------------------------------------
1160 dnl Declares a shell function squeeze() which removes
1161 dnl redundant whitespace out of a shell variable.
1162
1163 AC_DEFUN([CARES_SHFUNC_SQUEEZE], [
1164 squeeze() {
1165   _sqz_result=""
1166   eval _sqz_input=\[$][$]1
1167   for _sqz_token in $_sqz_input; do
1168     if test -z "$_sqz_result"; then
1169       _sqz_result="$_sqz_token"
1170     else
1171       _sqz_result="$_sqz_result $_sqz_token"
1172     fi
1173   done
1174   eval [$]1=\$_sqz_result
1175   return 0
1176 }
1177 ])
1178
1179
1180 dnl CARES_CHECK_CURLDEBUG
1181 dnl -------------------------------------------------
1182 dnl Settings which depend on configure's curldebug given
1183 dnl option, and other additional configure pre-requisites.
1184 dnl Using the curl debug memory tracking feature in c-ares
1185 dnl is a hack that actually can only be used/enabled when
1186 dnl c-ares is built directly in curl's CVS tree, as a static
1187 dnl library or as a shared one on those systems on which
1188 dnl shared libraries support undefined symbols, along with
1189 dnl an equally configured libcurl.
1190
1191 AC_DEFUN([CARES_CHECK_CURLDEBUG], [
1192   AC_REQUIRE([CARES_SHFUNC_SQUEEZE])dnl
1193   cares_builddir=`pwd`
1194   supports_curldebug="unknown"
1195   if test "$want_curldebug" = "yes"; then
1196     if test "x$enable_shared" != "xno" &&
1197       test "x$enable_shared" != "xyes"; then
1198       AC_MSG_WARN([unknown enable_shared setting.])
1199       supports_curldebug="no"
1200     fi
1201     if test "x$enable_static" != "xno" &&
1202       test "x$enable_static" != "xyes"; then
1203       AC_MSG_WARN([unknown enable_static setting.])
1204       supports_curldebug="no"
1205     fi
1206     if test "$supports_curldebug" != "no"; then
1207       if test "$enable_shared" = "yes" &&
1208         test "$need_no_undefined" = "yes"; then
1209         supports_curldebug="no"
1210         AC_MSG_WARN([shared library does not support undefined symbols.])
1211       fi
1212       if test ! -f "$srcdir/../include/curl/curlbuild.h.dist"; then
1213         AC_MSG_WARN([c-ares source not embedded in curl's CVS tree.])
1214         supports_curldebug="no"
1215       elif test ! -f "$srcdir/../include/curl/Makefile.in"; then
1216         AC_MSG_WARN([curl's buildconf has not been run.])
1217         supports_curldebug="no"
1218       elif test ! -f "$cares_builddir/../libcurl.pc" ||
1219         test ! -f "$cares_builddir/../include/curl/curlbuild.h"; then
1220         AC_MSG_WARN([curl's configure has not been run.])
1221         supports_curldebug="no"
1222       elif test ! -f "$cares_builddir/../lib/curl_config.h"; then
1223         AC_MSG_WARN([libcurl's curl_config.h is missing.])
1224         supports_curldebug="no"
1225       elif test ! -f "$cares_builddir/../config.status"; then
1226         AC_MSG_WARN([curl's config.status is missing.])
1227         supports_curldebug="no"
1228       fi
1229       if test "$supports_curldebug" != "no"; then
1230         grep '^#define USE_ARES' "$cares_builddir/../lib/curl_config.h" >/dev/null
1231         if test "$?" -ne "0"; then
1232           AC_MSG_WARN([libcurl configured without c-ares support.])
1233           supports_curldebug="no"
1234         fi
1235       fi
1236       if test "$supports_curldebug" != "no"; then
1237         grep 'CPPFLAGS.*CURLDEBUG' "$cares_builddir/../config.status" >/dev/null
1238         if test "$?" -ne "0"; then
1239           AC_MSG_WARN([libcurl configured without curldebug support.])
1240           supports_curldebug="no"
1241         fi
1242       fi
1243     fi
1244   fi
1245   #
1246   if test "$want_curldebug" = "yes"; then
1247     AC_MSG_CHECKING([if curl debug memory tracking can be enabled])
1248     test "$supports_curldebug" = "no" || supports_curldebug="yes"
1249     AC_MSG_RESULT([$supports_curldebug])
1250     if test "$supports_curldebug" = "no"; then
1251       AC_MSG_WARN([cannot enable curl debug memory tracking.])
1252       want_curldebug="no"
1253     fi
1254   fi
1255   #
1256   if test "$want_curldebug" = "yes"; then
1257     dnl TODO: Verify if the BUILDING_LIBCURL definition is still required.
1258     AC_DEFINE(BUILDING_LIBCURL, 1, [when building as static part of libcurl])
1259     CPPFLAGS="-DCURLDEBUG $CPPFLAGS"
1260     squeeze CPPFLAGS
1261   fi
1262   #
1263   if test "$want_debug" = "yes"; then
1264     CPPFLAGS="-DDEBUGBUILD $CPPFLAGS"
1265     squeeze CPPFLAGS
1266   fi
1267 ])
1268
1269
1270 dnl CARES_CHECK_NO_UNDEFINED
1271 dnl -------------------------------------------------
1272 dnl Checks if the -no-undefined flag must be used when
1273 dnl building shared libraries. This is required on all
1274 dnl systems on which shared libraries should not have
1275 dnl references to undefined symbols. This check should
1276 dnl not be done before AC-PROG-LIBTOOL.
1277
1278 AC_DEFUN([CARES_CHECK_NO_UNDEFINED], [
1279   AC_BEFORE([$0],[CARES_CHECK_CURLDEBUG])dnl
1280   AC_MSG_CHECKING([if shared libraries need -no-undefined])
1281   need_no_undefined="no"
1282   case $host in
1283     *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-cegcc* | *-*-aix*)
1284       need_no_undefined="yes"
1285       ;;
1286   esac
1287   if test "x$allow_undefined" = "xno"; then
1288     need_no_undefined="yes"
1289   elif test "x$allow_undefined_flag" = "xunsupported"; then
1290     need_no_undefined="yes"
1291   fi
1292   AC_MSG_RESULT($need_no_undefined)
1293 ])
1294
1295
1296 dnl CARES_CHECK_PROG_CC
1297 dnl -------------------------------------------------
1298 dnl Check for compiler program, preventing CFLAGS and
1299 dnl CPPFLAGS from being unexpectedly changed.
1300
1301 AC_DEFUN([CARES_CHECK_PROG_CC], [
1302   ac_save_CFLAGS="$CFLAGS"
1303   ac_save_CPPFLAGS="$CPPFLAGS"
1304   AC_PROG_CC
1305   CFLAGS="$ac_save_CFLAGS"
1306   CPPFLAGS="$ac_save_CPPFLAGS"
1307 ])
1308
1309
1310 dnl CARES_CHECK_COMPILER_HALT_ON_ERROR
1311 dnl -------------------------------------------------
1312 dnl Verifies if the compiler actually halts after the
1313 dnl compilation phase without generating any object
1314 dnl code file, when the source compiles with errors.
1315
1316 AC_DEFUN([CARES_CHECK_COMPILER_HALT_ON_ERROR], [
1317   AC_MSG_CHECKING([if compiler halts on compilation errors])
1318   AC_COMPILE_IFELSE([
1319     AC_LANG_PROGRAM([[
1320     ]],[[
1321       force compilation error
1322     ]])
1323   ],[
1324     AC_MSG_RESULT([no])
1325     AC_MSG_ERROR([compiler does not halt on compilation errors.])
1326   ],[
1327     AC_MSG_RESULT([yes])
1328   ])
1329 ])
1330
1331
1332 dnl CARES_CHECK_COMPILER_ARRAY_SIZE_NEGATIVE
1333 dnl -------------------------------------------------
1334 dnl Verifies if the compiler actually halts after the
1335 dnl compilation phase without generating any object
1336 dnl code file, when the source code tries to define a
1337 dnl type for a constant array with negative dimension.
1338
1339 AC_DEFUN([CARES_CHECK_COMPILER_ARRAY_SIZE_NEGATIVE], [
1340   AC_REQUIRE([CARES_CHECK_COMPILER_HALT_ON_ERROR])dnl
1341   AC_MSG_CHECKING([if compiler halts on negative sized arrays])
1342   AC_COMPILE_IFELSE([
1343     AC_LANG_PROGRAM([[
1344       typedef char bad_t[sizeof(char) == sizeof(int) ? -1 : -1 ];
1345     ]],[[
1346       bad_t dummy;
1347     ]])
1348   ],[
1349     AC_MSG_RESULT([no])
1350     AC_MSG_ERROR([compiler does not halt on negative sized arrays.])
1351   ],[
1352     AC_MSG_RESULT([yes])
1353   ])
1354 ])
1355
1356
1357 dnl CARES_CHECK_COMPILER_STRUCT_MEMBER_SIZE
1358 dnl -------------------------------------------------
1359 dnl Verifies if the compiler is capable of handling the
1360 dnl size of a struct member, struct which is a function
1361 dnl result, as a compilation-time condition inside the
1362 dnl type definition of a constant array.
1363
1364 AC_DEFUN([CARES_CHECK_COMPILER_STRUCT_MEMBER_SIZE], [
1365   AC_REQUIRE([CARES_CHECK_COMPILER_ARRAY_SIZE_NEGATIVE])dnl
1366   AC_MSG_CHECKING([if compiler struct member size checking works])
1367   tst_compiler_check_one_works="unknown"
1368   AC_COMPILE_IFELSE([
1369     AC_LANG_PROGRAM([[
1370       struct mystruct {
1371         int  mi;
1372         char mc;
1373         struct mystruct *next;
1374       };
1375       struct mystruct myfunc();
1376       typedef char good_t1[sizeof(myfunc().mi) == sizeof(int)  ? 1 : -1 ];
1377       typedef char good_t2[sizeof(myfunc().mc) == sizeof(char) ? 1 : -1 ];
1378     ]],[[
1379       good_t1 dummy1;
1380       good_t2 dummy2;
1381     ]])
1382   ],[
1383     tst_compiler_check_one_works="yes"
1384   ],[
1385     tst_compiler_check_one_works="no"
1386     sed 's/^/cc-src: /' conftest.$ac_ext >&6
1387     sed 's/^/cc-err: /' conftest.err >&6
1388   ])
1389   tst_compiler_check_two_works="unknown"
1390   AC_COMPILE_IFELSE([
1391     AC_LANG_PROGRAM([[
1392       struct mystruct {
1393         int  mi;
1394         char mc;
1395         struct mystruct *next;
1396       };
1397       struct mystruct myfunc();
1398       typedef char bad_t1[sizeof(myfunc().mi) != sizeof(int)  ? 1 : -1 ];
1399       typedef char bad_t2[sizeof(myfunc().mc) != sizeof(char) ? 1 : -1 ];
1400     ]],[[
1401       bad_t1 dummy1;
1402       bad_t2 dummy2;
1403     ]])
1404   ],[
1405     tst_compiler_check_two_works="no"
1406   ],[
1407     tst_compiler_check_two_works="yes"
1408   ])
1409   if test "$tst_compiler_check_one_works" = "yes" &&
1410     test "$tst_compiler_check_two_works" = "yes"; then
1411     AC_MSG_RESULT([yes])
1412   else
1413     AC_MSG_RESULT([no])
1414     AC_MSG_ERROR([compiler fails struct member size checking.])
1415   fi
1416 ])
1417
1418
1419 dnl CARES_CHECK_COMPILER_SYMBOL_HIDING
1420 dnl -------------------------------------------------
1421 dnl Verify if compiler supports hiding library internal symbols, setting
1422 dnl shell variable supports_symbol_hiding value as appropriate, as well as
1423 dnl variables symbol_hiding_CFLAGS and symbol_hiding_EXTERN when supported.
1424
1425 AC_DEFUN([CARES_CHECK_COMPILER_SYMBOL_HIDING], [
1426   AC_REQUIRE([CARES_CHECK_COMPILER])dnl
1427   AC_BEFORE([$0],[CARES_CONFIGURE_SYMBOL_HIDING])dnl
1428   AC_MSG_CHECKING([if compiler supports hiding library internal symbols])
1429   supports_symbol_hiding="no"
1430   symbol_hiding_CFLAGS=""
1431   symbol_hiding_EXTERN=""
1432   tmp_CFLAGS=""
1433   tmp_EXTERN=""
1434   case "$compiler_id" in
1435     CLANG)
1436       dnl All versions of clang support -fvisibility=
1437       tmp_EXTERN="__attribute__ ((__visibility__ (\"default\")))"
1438       tmp_CFLAGS="-fvisibility=hidden"
1439       supports_symbol_hiding="yes"
1440       ;;
1441     GNU_C)
1442       dnl Only gcc 3.4 or later
1443       if test "$compiler_num" -ge "304"; then
1444         if $CC --help --verbose 2>&1 | grep fvisibility= > /dev/null ; then
1445           tmp_EXTERN="__attribute__ ((__visibility__ (\"default\")))"
1446           tmp_CFLAGS="-fvisibility=hidden"
1447           supports_symbol_hiding="yes"
1448         fi
1449       fi
1450       ;;
1451     INTEL_UNIX_C)
1452       dnl Only icc 9.0 or later
1453       if test "$compiler_num" -ge "900"; then
1454         if $CC --help --verbose 2>&1 | grep fvisibility= > /dev/null ; then
1455           tmp_save_CFLAGS="$CFLAGS"
1456           CFLAGS="$CFLAGS -fvisibility=hidden"
1457           AC_LINK_IFELSE([
1458             AC_LANG_PROGRAM([[
1459 #             include <stdio.h>
1460             ]],[[
1461               printf("icc fvisibility bug test");
1462             ]])
1463           ],[
1464             tmp_EXTERN="__attribute__ ((__visibility__ (\"default\")))"
1465             tmp_CFLAGS="-fvisibility=hidden"
1466             supports_symbol_hiding="yes"
1467           ])
1468           CFLAGS="$tmp_save_CFLAGS"
1469         fi
1470       fi
1471       ;;
1472     SUNPRO_C)
1473       if $CC 2>&1 | grep flags >/dev/null && $CC -flags | grep xldscope= >/dev/null ; then
1474         tmp_EXTERN="__global"
1475         tmp_CFLAGS="-xldscope=hidden"
1476         supports_symbol_hiding="yes"
1477       fi
1478       ;;
1479   esac
1480   if test "$supports_symbol_hiding" = "yes"; then
1481     tmp_save_CFLAGS="$CFLAGS"
1482     CFLAGS="$tmp_save_CFLAGS $tmp_CFLAGS"
1483     squeeze CFLAGS
1484     AC_COMPILE_IFELSE([
1485       AC_LANG_PROGRAM([[
1486         $tmp_EXTERN char *dummy(char *buff);
1487         char *dummy(char *buff)
1488         {
1489          if(buff)
1490            return ++buff;
1491          else
1492            return buff;
1493         }
1494       ]],[[
1495         char b[16];
1496         char *r = dummy(&b[0]);
1497         if(r)
1498           return (int)*r;
1499       ]])
1500     ],[
1501       supports_symbol_hiding="yes"
1502       if test -f conftest.err; then
1503         grep 'visibility' conftest.err >/dev/null
1504         if test "$?" -eq "0"; then
1505           supports_symbol_hiding="no"
1506         fi
1507       fi
1508     ],[
1509       supports_symbol_hiding="no"
1510       echo " " >&6
1511       sed 's/^/cc-src: /' conftest.$ac_ext >&6
1512       sed 's/^/cc-err: /' conftest.err >&6
1513       echo " " >&6
1514     ])
1515     CFLAGS="$tmp_save_CFLAGS"
1516   fi
1517   if test "$supports_symbol_hiding" = "yes"; then
1518     AC_MSG_RESULT([yes])
1519     symbol_hiding_CFLAGS="$tmp_CFLAGS"
1520     symbol_hiding_EXTERN="$tmp_EXTERN"
1521   else
1522     AC_MSG_RESULT([no])
1523   fi
1524 ])
1525
1526
1527 dnl CARES_VAR_MATCH (VARNAME, VALUE)
1528 dnl -------------------------------------------------
1529 dnl Verifies if shell variable VARNAME contains VALUE.
1530 dnl Contents of variable VARNAME and VALUE are handled
1531 dnl as whitespace separated lists of words. If at least
1532 dnl one word of VALUE is present in VARNAME the match
1533 dnl is considered positive, otherwise false.
1534
1535 AC_DEFUN([CARES_VAR_MATCH], [
1536   ac_var_match_word="no"
1537   for word1 in $[$1]; do
1538     for word2 in [$2]; do
1539       if test "$word1" = "$word2"; then
1540         ac_var_match_word="yes"
1541       fi
1542     done
1543   done
1544 ])
1545
1546
1547 dnl CARES_VAR_MATCH_IFELSE (VARNAME, VALUE,
1548 dnl                        [ACTION-IF-MATCH], [ACTION-IF-NOT-MATCH])
1549 dnl -------------------------------------------------
1550 dnl This performs a CURL_VAR_MATCH check and executes
1551 dnl first branch if the match is positive, otherwise
1552 dnl the second branch is executed.
1553
1554 AC_DEFUN([CARES_VAR_MATCH_IFELSE], [
1555   CARES_VAR_MATCH([$1],[$2])
1556   if test "$ac_var_match_word" = "yes"; then
1557   ifelse($3,,:,[$3])
1558   ifelse($4,,,[else
1559     $4])
1560   fi
1561 ])
1562
1563
1564 dnl CARES_VAR_STRIP (VARNAME, VALUE)
1565 dnl -------------------------------------------------
1566 dnl Contents of variable VARNAME and VALUE are handled
1567 dnl as whitespace separated lists of words. Each word
1568 dnl from VALUE is removed from VARNAME when present.
1569
1570 AC_DEFUN([CARES_VAR_STRIP], [
1571   AC_REQUIRE([CARES_SHFUNC_SQUEEZE])dnl
1572   ac_var_stripped=""
1573   for word1 in $[$1]; do
1574     ac_var_strip_word="no"
1575     for word2 in [$2]; do
1576       if test "$word1" = "$word2"; then
1577         ac_var_strip_word="yes"
1578       fi
1579     done
1580     if test "$ac_var_strip_word" = "no"; then
1581       ac_var_stripped="$ac_var_stripped $word1"
1582     fi
1583   done
1584   dnl squeeze whitespace out of result
1585   [$1]="$ac_var_stripped"
1586   squeeze [$1]
1587 ])
1588