d564792ba075bd42b0aa12bc769d76f38f97c6e9
[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 71
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           tmp_CFLAGS="$tmp_CFLAGS -Wstrict-aliasing=3"
874           #
875           dnl Only clang 1.1 or later
876           if test "$compiler_num" -ge "101"; then
877             tmp_CFLAGS="$tmp_CFLAGS -Wunused"
878           fi
879         fi
880         ;;
881         #
882       DEC_C)
883         #
884         if test "$want_warnings" = "yes"; then
885           dnl Select a higher warning level than default level2
886           tmp_CFLAGS="$tmp_CFLAGS -msg_enable level3"
887         fi
888         ;;
889         #
890       GNU_C)
891         #
892         if test "$want_warnings" = "yes"; then
893           #
894           dnl Do not enable -pedantic when cross-compiling with a gcc older
895           dnl than 3.0, to avoid warnings from third party system headers.
896           if test "x$cross_compiling" != "xyes" ||
897             test "$compiler_num" -ge "300"; then
898             tmp_CFLAGS="$tmp_CFLAGS -pedantic"
899           fi
900           #
901           dnl Set of options we believe *ALL* gcc versions support:
902           tmp_CFLAGS="$tmp_CFLAGS -Wall -W"
903           #
904           dnl Only gcc 1.4 or later
905           if test "$compiler_num" -ge "104"; then
906             tmp_CFLAGS="$tmp_CFLAGS -Wpointer-arith -Wwrite-strings"
907             dnl If not cross-compiling with a gcc older than 3.0
908             if test "x$cross_compiling" != "xyes" ||
909               test "$compiler_num" -ge "300"; then
910               tmp_CFLAGS="$tmp_CFLAGS -Wunused -Wshadow"
911             fi
912           fi
913           #
914           dnl Only gcc 2.7 or later
915           if test "$compiler_num" -ge "207"; then
916             tmp_CFLAGS="$tmp_CFLAGS -Winline -Wnested-externs"
917             dnl If not cross-compiling with a gcc older than 3.0
918             if test "x$cross_compiling" != "xyes" ||
919               test "$compiler_num" -ge "300"; then
920               tmp_CFLAGS="$tmp_CFLAGS -Wmissing-declarations"
921               tmp_CFLAGS="$tmp_CFLAGS -Wmissing-prototypes"
922             fi
923           fi
924           #
925           dnl Only gcc 2.95 or later
926           if test "$compiler_num" -ge "295"; then
927             tmp_CFLAGS="$tmp_CFLAGS -Wno-long-long"
928           fi
929           #
930           dnl Only gcc 2.96 or later
931           if test "$compiler_num" -ge "296"; then
932             tmp_CFLAGS="$tmp_CFLAGS -Wfloat-equal"
933             tmp_CFLAGS="$tmp_CFLAGS -Wno-multichar -Wsign-compare"
934             dnl -Wundef used only if gcc is 2.96 or later since we get
935             dnl lots of "`_POSIX_C_SOURCE' is not defined" in system
936             dnl headers with gcc 2.95.4 on FreeBSD 4.9
937             tmp_CFLAGS="$tmp_CFLAGS -Wundef"
938           fi
939           #
940           dnl Only gcc 2.97 or later
941           if test "$compiler_num" -ge "297"; then
942             tmp_CFLAGS="$tmp_CFLAGS -Wno-format-nonliteral"
943           fi
944           #
945           dnl Only gcc 3.0 or later
946           if test "$compiler_num" -ge "300"; then
947             dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
948             dnl on i686-Linux as it gives us heaps with false positives.
949             dnl Also, on gcc 4.0.X it is totally unbearable and complains all
950             dnl over making it unusable for generic purposes. Let's not use it.
951             tmp_CFLAGS="$tmp_CFLAGS"
952           fi
953           #
954           dnl Only gcc 3.3 or later
955           if test "$compiler_num" -ge "303"; then
956             tmp_CFLAGS="$tmp_CFLAGS -Wendif-labels -Wstrict-prototypes"
957           fi
958           #
959           dnl Only gcc 3.4 or later
960           if test "$compiler_num" -ge "304"; then
961             tmp_CFLAGS="$tmp_CFLAGS -Wdeclaration-after-statement"
962           fi
963           #
964           dnl Only gcc 4.0 or later
965           if test "$compiler_num" -ge "400"; then
966             tmp_CFLAGS="$tmp_CFLAGS -Wstrict-aliasing=3"
967           fi
968           #
969           dnl Only gcc 4.2 or later
970           if test "$compiler_num" -ge "402"; then
971             tmp_CFLAGS="$tmp_CFLAGS -Wcast-align"
972           fi
973           #
974           dnl Only gcc 4.3 or later
975           if test "$compiler_num" -ge "403"; then
976             tmp_CFLAGS="$tmp_CFLAGS -Wtype-limits -Wold-style-declaration"
977             tmp_CFLAGS="$tmp_CFLAGS -Wmissing-parameter-type -Wempty-body"
978             tmp_CFLAGS="$tmp_CFLAGS -Wclobbered -Wignored-qualifiers"
979             tmp_CFLAGS="$tmp_CFLAGS -Wconversion -Wno-sign-conversion -Wvla"
980           fi
981           #
982           dnl Only gcc 4.5 or later
983           if test "$compiler_num" -ge "405"; then
984             dnl Only windows targets
985             if test "$curl_cv_have_def__WIN32" = "yes"; then
986               tmp_CFLAGS="$tmp_CFLAGS -Wno-pedantic-ms-format"
987             fi
988           fi
989           #
990         fi
991         #
992         dnl Do not issue warnings for code in system include paths.
993         if test "$compiler_num" -ge "300"; then
994           tmp_CFLAGS="$tmp_CFLAGS -Wno-system-headers"
995         else
996           dnl When cross-compiling with a gcc older than 3.0, disable
997           dnl some warnings triggered on third party system headers.
998           if test "x$cross_compiling" = "xyes"; then
999             if test "$compiler_num" -ge "104"; then
1000               dnl gcc 1.4 or later
1001               tmp_CFLAGS="$tmp_CFLAGS -Wno-unused -Wno-shadow"
1002             fi
1003             if test "$compiler_num" -ge "207"; then
1004               dnl gcc 2.7 or later
1005               tmp_CFLAGS="$tmp_CFLAGS -Wno-missing-declarations"
1006               tmp_CFLAGS="$tmp_CFLAGS -Wno-missing-prototypes"
1007             fi
1008           fi
1009         fi
1010         ;;
1011         #
1012       HP_UX_C)
1013         #
1014         if test "$want_warnings" = "yes"; then
1015           dnl Issue all warnings
1016           tmp_CFLAGS="$tmp_CFLAGS +w1"
1017         fi
1018         ;;
1019         #
1020       IBM_C)
1021         #
1022         dnl Placeholder
1023         tmp_CFLAGS="$tmp_CFLAGS"
1024         ;;
1025         #
1026       INTEL_UNIX_C)
1027         #
1028         if test "$want_warnings" = "yes"; then
1029           if test "$compiler_num" -gt "600"; then
1030             dnl Show errors, warnings, and remarks
1031             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wall -w2"
1032             dnl Perform extra compile-time code checking
1033             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wcheck"
1034             dnl Warn on nested comments
1035             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wcomment"
1036             dnl Show warnings relative to deprecated features
1037             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wdeprecated"
1038             dnl Enable warnings for missing prototypes
1039             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wmissing-prototypes"
1040             dnl Enable warnings for 64-bit portability issues
1041             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wp64"
1042             dnl Enable warnings for questionable pointer arithmetic
1043             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wpointer-arith"
1044             dnl Check for function return typw issues
1045             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wreturn-type"
1046             dnl Warn on variable declarations hiding a previous one
1047             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wshadow"
1048             dnl Warn when a variable is used before initialized
1049             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wuninitialized"
1050             dnl Warn if a declared function is not used
1051             tmp_CPPFLAGS="$tmp_CPPFLAGS -Wunused-function"
1052           fi
1053         fi
1054         dnl Disable using EBP register in optimizations
1055         tmp_CFLAGS="$tmp_CFLAGS -fno-omit-frame-pointer"
1056         dnl Disable use of ANSI C aliasing rules in optimizations
1057         tmp_CFLAGS="$tmp_CFLAGS -fno-strict-aliasing"
1058         dnl Value-safe optimizations on floating-point data
1059         tmp_CFLAGS="$tmp_CFLAGS -fp-model precise"
1060         dnl Only icc 10.0 or later
1061         if test "$compiler_num" -ge "1000"; then
1062           dnl Disable vectorizer diagnostic information
1063           tmp_CFLAGS="$tmp_CFLAGS -vec-report0"
1064         fi
1065         ;;
1066         #
1067       INTEL_WINDOWS_C)
1068         #
1069         dnl Placeholder
1070         tmp_CFLAGS="$tmp_CFLAGS"
1071         ;;
1072         #
1073       LCC)
1074         #
1075         if test "$want_warnings" = "yes"; then
1076           dnl Highest warning level is double -A, next is single -A.
1077           dnl Due to the big number of warnings these trigger on third
1078           dnl party header files it is impractical for us to use any of
1079           dnl them here. If you want them simply define it in CPPFLAGS.
1080           tmp_CFLAGS="$tmp_CFLAGS"
1081         fi
1082         ;;
1083         #
1084       SGI_MIPS_C)
1085         #
1086         if test "$want_warnings" = "yes"; then
1087           dnl Perform stricter semantic and lint-like checks
1088           tmp_CFLAGS="$tmp_CFLAGS -fullwarn"
1089         fi
1090         ;;
1091         #
1092       SGI_MIPSPRO_C)
1093         #
1094         if test "$want_warnings" = "yes"; then
1095           dnl Perform stricter semantic and lint-like checks
1096           tmp_CFLAGS="$tmp_CFLAGS -fullwarn"
1097           dnl Disable some remarks
1098           dnl #1209: controlling expression is constant
1099           tmp_CFLAGS="$tmp_CFLAGS -woff 1209"
1100         fi
1101         ;;
1102         #
1103       SUNPRO_C)
1104         #
1105         if test "$want_warnings" = "yes"; then
1106           dnl Perform stricter semantic and lint-like checks
1107           tmp_CFLAGS="$tmp_CFLAGS -v"
1108         fi
1109         ;;
1110         #
1111       TINY_C)
1112         #
1113         if test "$want_warnings" = "yes"; then
1114           dnl Activate all warnings
1115           tmp_CFLAGS="$tmp_CFLAGS -Wall"
1116           dnl Make string constants be of type const char *
1117           tmp_CFLAGS="$tmp_CFLAGS -Wwrite-strings"
1118           dnl Warn use of unsupported GCC features ignored by TCC
1119           tmp_CFLAGS="$tmp_CFLAGS -Wunsupported"
1120         fi
1121         ;;
1122         #
1123       WATCOM_UNIX_C)
1124         #
1125         if test "$want_warnings" = "yes"; then
1126           dnl Issue all warnings
1127           tmp_CFLAGS="$tmp_CFLAGS -Wall -Wextra"
1128         fi
1129         ;;
1130         #
1131       WATCOM_WINDOWS_C)
1132         #
1133         dnl Placeholder
1134         tmp_CFLAGS="$tmp_CFLAGS"
1135         ;;
1136         #
1137     esac
1138     #
1139     squeeze tmp_CPPFLAGS
1140     squeeze tmp_CFLAGS
1141     #
1142     if test ! -z "$tmp_CFLAGS" || test ! -z "$tmp_CPPFLAGS"; then
1143       AC_MSG_CHECKING([if compiler accepts strict warning options])
1144       CPPFLAGS="$tmp_save_CPPFLAGS $tmp_CPPFLAGS"
1145       CFLAGS="$tmp_save_CFLAGS $tmp_CFLAGS"
1146       squeeze CPPFLAGS
1147       squeeze CFLAGS
1148       CARES_COMPILER_WORKS_IFELSE([
1149         AC_MSG_RESULT([yes])
1150         AC_MSG_NOTICE([compiler options added: $tmp_CFLAGS $tmp_CPPFLAGS])
1151       ],[
1152         AC_MSG_RESULT([no])
1153         AC_MSG_WARN([compiler options rejected: $tmp_CFLAGS $tmp_CPPFLAGS])
1154         dnl restore initial settings
1155         CPPFLAGS="$tmp_save_CPPFLAGS"
1156         CFLAGS="$tmp_save_CFLAGS"
1157       ])
1158     fi
1159     #
1160   fi
1161 ])
1162
1163
1164 dnl CARES_SHFUNC_SQUEEZE
1165 dnl -------------------------------------------------
1166 dnl Declares a shell function squeeze() which removes
1167 dnl redundant whitespace out of a shell variable.
1168
1169 AC_DEFUN([CARES_SHFUNC_SQUEEZE], [
1170 squeeze() {
1171   _sqz_result=""
1172   eval _sqz_input=\[$][$]1
1173   for _sqz_token in $_sqz_input; do
1174     if test -z "$_sqz_result"; then
1175       _sqz_result="$_sqz_token"
1176     else
1177       _sqz_result="$_sqz_result $_sqz_token"
1178     fi
1179   done
1180   eval [$]1=\$_sqz_result
1181   return 0
1182 }
1183 ])
1184
1185
1186 dnl CARES_CHECK_CURLDEBUG
1187 dnl -------------------------------------------------
1188 dnl Settings which depend on configure's curldebug given
1189 dnl option, and other additional configure pre-requisites.
1190 dnl Using the curl debug memory tracking feature in c-ares
1191 dnl is a hack that actually can only be used/enabled when
1192 dnl c-ares is built directly in curl's CVS tree, as a static
1193 dnl library or as a shared one on those systems on which
1194 dnl shared libraries support undefined symbols, along with
1195 dnl an equally configured libcurl.
1196
1197 AC_DEFUN([CARES_CHECK_CURLDEBUG], [
1198   AC_REQUIRE([CARES_SHFUNC_SQUEEZE])dnl
1199   cares_builddir=`pwd`
1200   supports_curldebug="unknown"
1201   if test "$want_curldebug" = "yes"; then
1202     if test "x$enable_shared" != "xno" &&
1203       test "x$enable_shared" != "xyes"; then
1204       AC_MSG_WARN([unknown enable_shared setting.])
1205       supports_curldebug="no"
1206     fi
1207     if test "x$enable_static" != "xno" &&
1208       test "x$enable_static" != "xyes"; then
1209       AC_MSG_WARN([unknown enable_static setting.])
1210       supports_curldebug="no"
1211     fi
1212     if test "$supports_curldebug" != "no"; then
1213       if test "$enable_shared" = "yes" &&
1214         test "$need_no_undefined" = "yes"; then
1215         supports_curldebug="no"
1216         AC_MSG_WARN([shared library does not support undefined symbols.])
1217       fi
1218       if test ! -f "$srcdir/../include/curl/curlbuild.h.dist"; then
1219         AC_MSG_WARN([c-ares source not embedded in curl's CVS tree.])
1220         supports_curldebug="no"
1221       elif test ! -f "$srcdir/../include/curl/Makefile.in"; then
1222         AC_MSG_WARN([curl's buildconf has not been run.])
1223         supports_curldebug="no"
1224       elif test ! -f "$cares_builddir/../libcurl.pc" ||
1225         test ! -f "$cares_builddir/../include/curl/curlbuild.h"; then
1226         AC_MSG_WARN([curl's configure has not been run.])
1227         supports_curldebug="no"
1228       elif test ! -f "$cares_builddir/../lib/curl_config.h"; then
1229         AC_MSG_WARN([libcurl's curl_config.h is missing.])
1230         supports_curldebug="no"
1231       elif test ! -f "$cares_builddir/../config.status"; then
1232         AC_MSG_WARN([curl's config.status is missing.])
1233         supports_curldebug="no"
1234       fi
1235       if test "$supports_curldebug" != "no"; then
1236         grep '^#define USE_ARES' "$cares_builddir/../lib/curl_config.h" >/dev/null
1237         if test "$?" -ne "0"; then
1238           AC_MSG_WARN([libcurl configured without c-ares support.])
1239           supports_curldebug="no"
1240         fi
1241       fi
1242       if test "$supports_curldebug" != "no"; then
1243         grep 'CPPFLAGS.*CURLDEBUG' "$cares_builddir/../config.status" >/dev/null
1244         if test "$?" -ne "0"; then
1245           AC_MSG_WARN([libcurl configured without curldebug support.])
1246           supports_curldebug="no"
1247         fi
1248       fi
1249     fi
1250   fi
1251   #
1252   if test "$want_curldebug" = "yes"; then
1253     AC_MSG_CHECKING([if curl debug memory tracking can be enabled])
1254     test "$supports_curldebug" = "no" || supports_curldebug="yes"
1255     AC_MSG_RESULT([$supports_curldebug])
1256     if test "$supports_curldebug" = "no"; then
1257       AC_MSG_WARN([cannot enable curl debug memory tracking.])
1258       want_curldebug="no"
1259     fi
1260   fi
1261   #
1262   if test "$want_curldebug" = "yes"; then
1263     dnl TODO: Verify if the BUILDING_LIBCURL definition is still required.
1264     AC_DEFINE(BUILDING_LIBCURL, 1, [when building as static part of libcurl])
1265     CPPFLAGS="-DCURLDEBUG $CPPFLAGS"
1266     squeeze CPPFLAGS
1267   fi
1268   #
1269   if test "$want_debug" = "yes"; then
1270     CPPFLAGS="-DDEBUGBUILD $CPPFLAGS"
1271     squeeze CPPFLAGS
1272   fi
1273 ])
1274
1275
1276 dnl CARES_CHECK_NO_UNDEFINED
1277 dnl -------------------------------------------------
1278 dnl Checks if the -no-undefined flag must be used when
1279 dnl building shared libraries. This is required on all
1280 dnl systems on which shared libraries should not have
1281 dnl references to undefined symbols. This check should
1282 dnl not be done before AC-PROG-LIBTOOL.
1283
1284 AC_DEFUN([CARES_CHECK_NO_UNDEFINED], [
1285   AC_BEFORE([$0],[CARES_CHECK_CURLDEBUG])dnl
1286   AC_MSG_CHECKING([if shared libraries need -no-undefined])
1287   need_no_undefined="no"
1288   case $host in
1289     *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-cegcc* | *-*-aix*)
1290       need_no_undefined="yes"
1291       ;;
1292   esac
1293   if test "x$allow_undefined" = "xno"; then
1294     need_no_undefined="yes"
1295   elif test "x$allow_undefined_flag" = "xunsupported"; then
1296     need_no_undefined="yes"
1297   fi
1298   AC_MSG_RESULT($need_no_undefined)
1299 ])
1300
1301
1302 dnl CARES_CHECK_PROG_CC
1303 dnl -------------------------------------------------
1304 dnl Check for compiler program, preventing CFLAGS and
1305 dnl CPPFLAGS from being unexpectedly changed.
1306
1307 AC_DEFUN([CARES_CHECK_PROG_CC], [
1308   ac_save_CFLAGS="$CFLAGS"
1309   ac_save_CPPFLAGS="$CPPFLAGS"
1310   AC_PROG_CC
1311   CFLAGS="$ac_save_CFLAGS"
1312   CPPFLAGS="$ac_save_CPPFLAGS"
1313 ])
1314
1315
1316 dnl CARES_CHECK_COMPILER_HALT_ON_ERROR
1317 dnl -------------------------------------------------
1318 dnl Verifies if the compiler actually halts after the
1319 dnl compilation phase without generating any object
1320 dnl code file, when the source compiles with errors.
1321
1322 AC_DEFUN([CARES_CHECK_COMPILER_HALT_ON_ERROR], [
1323   AC_MSG_CHECKING([if compiler halts on compilation errors])
1324   AC_COMPILE_IFELSE([
1325     AC_LANG_PROGRAM([[
1326     ]],[[
1327       force compilation error
1328     ]])
1329   ],[
1330     AC_MSG_RESULT([no])
1331     AC_MSG_ERROR([compiler does not halt on compilation errors.])
1332   ],[
1333     AC_MSG_RESULT([yes])
1334   ])
1335 ])
1336
1337
1338 dnl CARES_CHECK_COMPILER_ARRAY_SIZE_NEGATIVE
1339 dnl -------------------------------------------------
1340 dnl Verifies if the compiler actually halts after the
1341 dnl compilation phase without generating any object
1342 dnl code file, when the source code tries to define a
1343 dnl type for a constant array with negative dimension.
1344
1345 AC_DEFUN([CARES_CHECK_COMPILER_ARRAY_SIZE_NEGATIVE], [
1346   AC_REQUIRE([CARES_CHECK_COMPILER_HALT_ON_ERROR])dnl
1347   AC_MSG_CHECKING([if compiler halts on negative sized arrays])
1348   AC_COMPILE_IFELSE([
1349     AC_LANG_PROGRAM([[
1350       typedef char bad_t[sizeof(char) == sizeof(int) ? -1 : -1 ];
1351     ]],[[
1352       bad_t dummy;
1353     ]])
1354   ],[
1355     AC_MSG_RESULT([no])
1356     AC_MSG_ERROR([compiler does not halt on negative sized arrays.])
1357   ],[
1358     AC_MSG_RESULT([yes])
1359   ])
1360 ])
1361
1362
1363 dnl CARES_CHECK_COMPILER_STRUCT_MEMBER_SIZE
1364 dnl -------------------------------------------------
1365 dnl Verifies if the compiler is capable of handling the
1366 dnl size of a struct member, struct which is a function
1367 dnl result, as a compilation-time condition inside the
1368 dnl type definition of a constant array.
1369
1370 AC_DEFUN([CARES_CHECK_COMPILER_STRUCT_MEMBER_SIZE], [
1371   AC_REQUIRE([CARES_CHECK_COMPILER_ARRAY_SIZE_NEGATIVE])dnl
1372   AC_MSG_CHECKING([if compiler struct member size checking works])
1373   tst_compiler_check_one_works="unknown"
1374   AC_COMPILE_IFELSE([
1375     AC_LANG_PROGRAM([[
1376       struct mystruct {
1377         int  mi;
1378         char mc;
1379         struct mystruct *next;
1380       };
1381       struct mystruct myfunc();
1382       typedef char good_t1[sizeof(myfunc().mi) == sizeof(int)  ? 1 : -1 ];
1383       typedef char good_t2[sizeof(myfunc().mc) == sizeof(char) ? 1 : -1 ];
1384     ]],[[
1385       good_t1 dummy1;
1386       good_t2 dummy2;
1387     ]])
1388   ],[
1389     tst_compiler_check_one_works="yes"
1390   ],[
1391     tst_compiler_check_one_works="no"
1392     sed 's/^/cc-src: /' conftest.$ac_ext >&6
1393     sed 's/^/cc-err: /' conftest.err >&6
1394   ])
1395   tst_compiler_check_two_works="unknown"
1396   AC_COMPILE_IFELSE([
1397     AC_LANG_PROGRAM([[
1398       struct mystruct {
1399         int  mi;
1400         char mc;
1401         struct mystruct *next;
1402       };
1403       struct mystruct myfunc();
1404       typedef char bad_t1[sizeof(myfunc().mi) != sizeof(int)  ? 1 : -1 ];
1405       typedef char bad_t2[sizeof(myfunc().mc) != sizeof(char) ? 1 : -1 ];
1406     ]],[[
1407       bad_t1 dummy1;
1408       bad_t2 dummy2;
1409     ]])
1410   ],[
1411     tst_compiler_check_two_works="no"
1412   ],[
1413     tst_compiler_check_two_works="yes"
1414   ])
1415   if test "$tst_compiler_check_one_works" = "yes" &&
1416     test "$tst_compiler_check_two_works" = "yes"; then
1417     AC_MSG_RESULT([yes])
1418   else
1419     AC_MSG_RESULT([no])
1420     AC_MSG_ERROR([compiler fails struct member size checking.])
1421   fi
1422 ])
1423
1424
1425 dnl CARES_CHECK_COMPILER_SYMBOL_HIDING
1426 dnl -------------------------------------------------
1427 dnl Verify if compiler supports hiding library internal symbols, setting
1428 dnl shell variable supports_symbol_hiding value as appropriate, as well as
1429 dnl variables symbol_hiding_CFLAGS and symbol_hiding_EXTERN when supported.
1430
1431 AC_DEFUN([CARES_CHECK_COMPILER_SYMBOL_HIDING], [
1432   AC_REQUIRE([CARES_CHECK_COMPILER])dnl
1433   AC_BEFORE([$0],[CARES_CONFIGURE_SYMBOL_HIDING])dnl
1434   AC_MSG_CHECKING([if compiler supports hiding library internal symbols])
1435   supports_symbol_hiding="no"
1436   symbol_hiding_CFLAGS=""
1437   symbol_hiding_EXTERN=""
1438   tmp_CFLAGS=""
1439   tmp_EXTERN=""
1440   case "$compiler_id" in
1441     CLANG)
1442       dnl All versions of clang support -fvisibility=
1443       tmp_EXTERN="__attribute__ ((__visibility__ (\"default\")))"
1444       tmp_CFLAGS="-fvisibility=hidden"
1445       supports_symbol_hiding="yes"
1446       ;;
1447     GNU_C)
1448       dnl Only gcc 3.4 or later
1449       if test "$compiler_num" -ge "304"; then
1450         if $CC --help --verbose 2>&1 | grep fvisibility= > /dev/null ; then
1451           tmp_EXTERN="__attribute__ ((__visibility__ (\"default\")))"
1452           tmp_CFLAGS="-fvisibility=hidden"
1453           supports_symbol_hiding="yes"
1454         fi
1455       fi
1456       ;;
1457     INTEL_UNIX_C)
1458       dnl Only icc 9.0 or later
1459       if test "$compiler_num" -ge "900"; then
1460         if $CC --help --verbose 2>&1 | grep fvisibility= > /dev/null ; then
1461           tmp_save_CFLAGS="$CFLAGS"
1462           CFLAGS="$CFLAGS -fvisibility=hidden"
1463           AC_LINK_IFELSE([
1464             AC_LANG_PROGRAM([[
1465 #             include <stdio.h>
1466             ]],[[
1467               printf("icc fvisibility bug test");
1468             ]])
1469           ],[
1470             tmp_EXTERN="__attribute__ ((__visibility__ (\"default\")))"
1471             tmp_CFLAGS="-fvisibility=hidden"
1472             supports_symbol_hiding="yes"
1473           ])
1474           CFLAGS="$tmp_save_CFLAGS"
1475         fi
1476       fi
1477       ;;
1478     SUNPRO_C)
1479       if $CC 2>&1 | grep flags >/dev/null && $CC -flags | grep xldscope= >/dev/null ; then
1480         tmp_EXTERN="__global"
1481         tmp_CFLAGS="-xldscope=hidden"
1482         supports_symbol_hiding="yes"
1483       fi
1484       ;;
1485   esac
1486   if test "$supports_symbol_hiding" = "yes"; then
1487     tmp_save_CFLAGS="$CFLAGS"
1488     CFLAGS="$tmp_save_CFLAGS $tmp_CFLAGS"
1489     squeeze CFLAGS
1490     AC_COMPILE_IFELSE([
1491       AC_LANG_PROGRAM([[
1492         $tmp_EXTERN char *dummy(char *buff);
1493         char *dummy(char *buff)
1494         {
1495          if(buff)
1496            return ++buff;
1497          else
1498            return buff;
1499         }
1500       ]],[[
1501         char b[16];
1502         char *r = dummy(&b[0]);
1503         if(r)
1504           return (int)*r;
1505       ]])
1506     ],[
1507       supports_symbol_hiding="yes"
1508       if test -f conftest.err; then
1509         grep 'visibility' conftest.err >/dev/null
1510         if test "$?" -eq "0"; then
1511           supports_symbol_hiding="no"
1512         fi
1513       fi
1514     ],[
1515       supports_symbol_hiding="no"
1516       echo " " >&6
1517       sed 's/^/cc-src: /' conftest.$ac_ext >&6
1518       sed 's/^/cc-err: /' conftest.err >&6
1519       echo " " >&6
1520     ])
1521     CFLAGS="$tmp_save_CFLAGS"
1522   fi
1523   if test "$supports_symbol_hiding" = "yes"; then
1524     AC_MSG_RESULT([yes])
1525     symbol_hiding_CFLAGS="$tmp_CFLAGS"
1526     symbol_hiding_EXTERN="$tmp_EXTERN"
1527   else
1528     AC_MSG_RESULT([no])
1529   fi
1530 ])
1531
1532
1533 dnl CARES_VAR_MATCH (VARNAME, VALUE)
1534 dnl -------------------------------------------------
1535 dnl Verifies if shell variable VARNAME contains VALUE.
1536 dnl Contents of variable VARNAME and VALUE are handled
1537 dnl as whitespace separated lists of words. If at least
1538 dnl one word of VALUE is present in VARNAME the match
1539 dnl is considered positive, otherwise false.
1540
1541 AC_DEFUN([CARES_VAR_MATCH], [
1542   ac_var_match_word="no"
1543   for word1 in $[$1]; do
1544     for word2 in [$2]; do
1545       if test "$word1" = "$word2"; then
1546         ac_var_match_word="yes"
1547       fi
1548     done
1549   done
1550 ])
1551
1552
1553 dnl CARES_VAR_MATCH_IFELSE (VARNAME, VALUE,
1554 dnl                        [ACTION-IF-MATCH], [ACTION-IF-NOT-MATCH])
1555 dnl -------------------------------------------------
1556 dnl This performs a CURL_VAR_MATCH check and executes
1557 dnl first branch if the match is positive, otherwise
1558 dnl the second branch is executed.
1559
1560 AC_DEFUN([CARES_VAR_MATCH_IFELSE], [
1561   CARES_VAR_MATCH([$1],[$2])
1562   if test "$ac_var_match_word" = "yes"; then
1563   ifelse($3,,:,[$3])
1564   ifelse($4,,,[else
1565     $4])
1566   fi
1567 ])
1568
1569
1570 dnl CARES_VAR_STRIP (VARNAME, VALUE)
1571 dnl -------------------------------------------------
1572 dnl Contents of variable VARNAME and VALUE are handled
1573 dnl as whitespace separated lists of words. Each word
1574 dnl from VALUE is removed from VARNAME when present.
1575
1576 AC_DEFUN([CARES_VAR_STRIP], [
1577   AC_REQUIRE([CARES_SHFUNC_SQUEEZE])dnl
1578   ac_var_stripped=""
1579   for word1 in $[$1]; do
1580     ac_var_strip_word="no"
1581     for word2 in [$2]; do
1582       if test "$word1" = "$word2"; then
1583         ac_var_strip_word="yes"
1584       fi
1585     done
1586     if test "$ac_var_strip_word" = "no"; then
1587       ac_var_stripped="$ac_var_stripped $word1"
1588     fi
1589   done
1590   dnl squeeze whitespace out of result
1591   [$1]="$ac_var_stripped"
1592   squeeze [$1]
1593 ])
1594