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