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