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