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