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