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