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