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