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