libssh2
/
acinclude.m4
955 строк · 33.3 Кб
1# Copyright (C) The libssh2 project and its contributors.
2# SPDX-License-Identifier: BSD-3-Clause
3dnl CURL_CPP_P
4dnl
5dnl Check if $cpp -P should be used for extract define values due to gcc 5
6dnl splitting up strings and defines between line outputs. gcc by default
7dnl (without -P) will show TEST EINVAL TEST as
8dnl
9dnl # 13 "conftest.c"
10dnl TEST
11dnl # 13 "conftest.c" 3 4
12dnl 22
13dnl # 13 "conftest.c"
14dnl TEST
15
16AC_DEFUN([CURL_CPP_P], [
17AC_MSG_CHECKING([if cpp -P is needed])
18AC_EGREP_CPP([TEST.*TEST], [
19#include <errno.h>
20TEST EINVAL TEST
21], [cpp=no], [cpp=yes])
22AC_MSG_RESULT([$cpp])
23
24dnl we need cpp -P so check if it works then
25if test "x$cpp" = "xyes"; then
26AC_MSG_CHECKING([if cpp -P works])
27OLDCPPFLAGS=$CPPFLAGS
28CPPFLAGS="$CPPFLAGS -P"
29AC_EGREP_CPP([TEST.*TEST], [
30#include <errno.h>
31TEST EINVAL TEST
32], [cpp_p=yes], [cpp_p=no])
33AC_MSG_RESULT([$cpp_p])
34
35if test "x$cpp_p" = "xno"; then
36AC_MSG_WARN([failed to figure out cpp -P alternative])
37# without -P
38CPPPFLAG=""
39else
40# with -P
41CPPPFLAG="-P"
42fi
43dnl restore CPPFLAGS
44CPPFLAGS=$OLDCPPFLAGS
45else
46# without -P
47CPPPFLAG=""
48fi
49])
50
51dnl CURL_CHECK_DEF (SYMBOL, [INCLUDES], [SILENT])
52dnl -------------------------------------------------
53dnl Use the C preprocessor to find out if the given object-style symbol
54dnl is defined and get its expansion. This macro will not use default
55dnl includes even if no INCLUDES argument is given. This macro will run
56dnl silently when invoked with three arguments. If the expansion would
57dnl result in a set of double-quoted strings the returned expansion will
58dnl actually be a single double-quoted string concatenating all them.
59
60AC_DEFUN([CURL_CHECK_DEF], [
61AC_REQUIRE([CURL_CPP_P])dnl
62OLDCPPFLAGS=$CPPFLAGS
63# CPPPFLAG comes from CURL_CPP_P
64CPPFLAGS="$CPPFLAGS $CPPPFLAG"
65AS_VAR_PUSHDEF([ac_HaveDef], [curl_cv_have_def_$1])dnl
66AS_VAR_PUSHDEF([ac_Def], [curl_cv_def_$1])dnl
67if test -z "$SED"; then
68AC_MSG_ERROR([SED not set. Cannot continue without SED being set.])
69fi
70if test -z "$GREP"; then
71AC_MSG_ERROR([GREP not set. Cannot continue without GREP being set.])
72fi
73ifelse($3,,[AC_MSG_CHECKING([for preprocessor definition of $1])])
74tmp_exp=""
75AC_PREPROC_IFELSE([
76AC_LANG_SOURCE(
77ifelse($2,,,[$2])[[
78#ifdef $1
79CURL_DEF_TOKEN $1
80#endif
81]])
82],[
83tmp_exp=`eval "$ac_cpp conftest.$ac_ext" 2>/dev/null | \
84"$GREP" CURL_DEF_TOKEN 2>/dev/null | \
85"$SED" 's/.*CURL_DEF_TOKEN[[ ]][[ ]]*//' 2>/dev/null | \
86"$SED" 's/[["]][[ ]]*[["]]//g' 2>/dev/null`
87if test -z "$tmp_exp" || test "$tmp_exp" = "$1"; then
88tmp_exp=""
89fi
90])
91if test -z "$tmp_exp"; then
92AS_VAR_SET(ac_HaveDef, no)
93ifelse($3,,[AC_MSG_RESULT([no])])
94else
95AS_VAR_SET(ac_HaveDef, yes)
96AS_VAR_SET(ac_Def, $tmp_exp)
97ifelse($3,,[AC_MSG_RESULT([$tmp_exp])])
98fi
99AS_VAR_POPDEF([ac_Def])dnl
100AS_VAR_POPDEF([ac_HaveDef])dnl
101CPPFLAGS=$OLDCPPFLAGS
102])
103
104dnl CURL_CHECK_COMPILER_CLANG
105dnl -------------------------------------------------
106dnl Verify if compiler being used is clang.
107
108AC_DEFUN([CURL_CHECK_COMPILER_CLANG], [
109AC_BEFORE([$0],[CURL_CHECK_COMPILER_GNU_C])dnl
110AC_MSG_CHECKING([if compiler is clang])
111CURL_CHECK_DEF([__clang__], [], [silent])
112if test "$curl_cv_have_def___clang__" = "yes"; then
113AC_MSG_RESULT([yes])
114AC_MSG_CHECKING([if compiler is xlclang])
115CURL_CHECK_DEF([__ibmxl__], [], [silent])
116if test "$curl_cv_have_def___ibmxl__" = "yes" ; then
117dnl IBM's almost-compatible clang version
118AC_MSG_RESULT([yes])
119compiler_id="XLCLANG"
120else
121AC_MSG_RESULT([no])
122compiler_id="CLANG"
123fi
124flags_dbg_yes="-g"
125flags_opt_all="-O -O0 -O1 -O2 -Os -O3 -O4"
126flags_opt_yes="-O2"
127flags_opt_off="-O0"
128else
129AC_MSG_RESULT([no])
130fi
131])
132
133dnl **********************************************************************
134dnl CURL_DETECT_ICC ([ACTION-IF-YES])
135dnl
136dnl check if this is the Intel ICC compiler, and if so run the ACTION-IF-YES
137dnl sets the $ICC variable to "yes" or "no"
138dnl **********************************************************************
139AC_DEFUN([CURL_DETECT_ICC],
140[
141ICC="no"
142AC_MSG_CHECKING([for icc in use])
143if test "$GCC" = "yes"; then
144dnl check if this is icc acting as gcc in disguise
145AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
146dnl action if the text is found, this it has not been replaced by the
147dnl cpp
148ICC="no",
149dnl the text was not found, it was replaced by the cpp
150ICC="yes"
151AC_MSG_RESULT([yes])
152[$1]
153)
154fi
155if test "$ICC" = "no"; then
156# this is not ICC
157AC_MSG_RESULT([no])
158fi
159])
160
161dnl We create a function for detecting which compiler we use and then set as
162dnl pedantic compiler options as possible for that particular compiler. The
163dnl options are only used for debug-builds.
164
165AC_DEFUN([CURL_CC_DEBUG_OPTS],
166[
167if test "z$CLANG" = "z"; then
168CURL_CHECK_COMPILER_CLANG
169if test "z$compiler_id" = "zCLANG"; then
170CLANG="yes"
171else
172CLANG="no"
173fi
174fi
175if test "z$ICC" = "z"; then
176CURL_DETECT_ICC
177fi
178
179if test "$CLANG" = "yes"; then
180
181# indentation to match curl's m4/curl-compilers.m4
182
183dnl figure out clang version!
184AC_MSG_CHECKING([compiler version])
185fullclangver=`$CC -v 2>&1 | grep version`
186if echo $fullclangver | grep 'Apple' >/dev/null; then
187appleclang=1
188else
189appleclang=0
190fi
191clangver=`echo $fullclangver | grep "based on LLVM " | "$SED" 's/.*(based on LLVM \(@<:@0-9@:>@*\.@<:@0-9@:>@*\).*)/\1/'`
192if test -z "$clangver"; then
193clangver=`echo $fullclangver | "$SED" 's/.*version \(@<:@0-9@:>@*\.@<:@0-9@:>@*\).*/\1/'`
194oldapple=0
195else
196oldapple=1
197fi
198clangvhi=`echo $clangver | cut -d . -f1`
199clangvlo=`echo $clangver | cut -d . -f2`
200compiler_num=`(expr $clangvhi "*" 100 + $clangvlo) 2>/dev/null`
201if test "$appleclang" = '1' && test "$oldapple" = '0'; then
202dnl Starting with Xcode 7 / clang 3.7, Apple clang won't tell its upstream version
203if test "$compiler_num" -ge '1300'; then compiler_num='1200'
204elif test "$compiler_num" -ge '1205'; then compiler_num='1101'
205elif test "$compiler_num" -ge '1204'; then compiler_num='1000'
206elif test "$compiler_num" -ge '1107'; then compiler_num='900'
207elif test "$compiler_num" -ge '1103'; then compiler_num='800'
208elif test "$compiler_num" -ge '1003'; then compiler_num='700'
209elif test "$compiler_num" -ge '1001'; then compiler_num='600'
210elif test "$compiler_num" -ge '904'; then compiler_num='500'
211elif test "$compiler_num" -ge '902'; then compiler_num='400'
212elif test "$compiler_num" -ge '803'; then compiler_num='309'
213elif test "$compiler_num" -ge '703'; then compiler_num='308'
214else compiler_num='307'
215fi
216fi
217AC_MSG_RESULT([clang '$compiler_num' (raw: '$fullclangver' / '$clangver')])
218
219tmp_CFLAGS="-pedantic"
220if test "$want_werror" = "yes"; then
221LIBSSH2_CFLAG_EXTRAS="$LIBSSH2_CFLAG_EXTRAS -pedantic-errors"
222fi
223CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [all extra])
224CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [pointer-arith write-strings])
225CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [shadow])
226CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [inline nested-externs])
227CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-declarations])
228CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-prototypes])
229tmp_CFLAGS="$tmp_CFLAGS -Wno-long-long"
230CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [float-equal])
231CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [sign-compare])
232tmp_CFLAGS="$tmp_CFLAGS -Wno-multichar"
233CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [undef])
234tmp_CFLAGS="$tmp_CFLAGS -Wno-format-nonliteral"
235CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [endif-labels strict-prototypes])
236CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [declaration-after-statement])
237CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [cast-align])
238tmp_CFLAGS="$tmp_CFLAGS -Wno-system-headers"
239CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [shorten-64-to-32])
240#
241dnl Only clang 1.1 or later
242if test "$compiler_num" -ge "101"; then
243CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unused])
244fi
245#
246dnl Only clang 2.7 or later
247if test "$compiler_num" -ge "207"; then
248CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [address])
249CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [attributes])
250CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [bad-function-cast])
251CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [conversion])
252CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [div-by-zero format-security])
253CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [empty-body])
254CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-field-initializers])
255CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-noreturn])
256CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [old-style-definition])
257CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [redundant-decls])
258# CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [switch-enum]) # Not used because this basically disallows default case
259CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [type-limits])
260if test "x$have_windows_h" != "xyes"; then
261CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unused-macros]) # Seen to clash with libtool-generated stub code
262fi
263CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unreachable-code unused-parameter])
264fi
265#
266dnl Only clang 2.8 or later
267if test "$compiler_num" -ge "208"; then
268CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [ignored-qualifiers])
269CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [vla])
270fi
271#
272dnl Only clang 2.9 or later
273if test "$compiler_num" -ge "209"; then
274CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [sign-conversion])
275tmp_CFLAGS="$tmp_CFLAGS -Wno-error=sign-conversion" # FIXME
276CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [shift-sign-overflow])
277# CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [padded]) # Not used because we cannot change public structs
278fi
279#
280dnl Only clang 3.0 or later
281if test "$compiler_num" -ge "300"; then
282CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [language-extension-token])
283tmp_CFLAGS="$tmp_CFLAGS -Wformat=2"
284fi
285#
286dnl Only clang 3.2 or later
287if test "$compiler_num" -ge "302"; then
288CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [enum-conversion])
289CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [sometimes-uninitialized])
290case $host_os in
291cygwin* | mingw*)
292dnl skip missing-variable-declarations warnings for cygwin and
293dnl mingw because the libtool wrapper executable causes them
294;;
295*)
296CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-variable-declarations])
297;;
298esac
299fi
300#
301dnl Only clang 3.4 or later
302if test "$compiler_num" -ge "304"; then
303CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [header-guard])
304CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unused-const-variable])
305fi
306#
307dnl Only clang 3.5 or later
308if test "$compiler_num" -ge "305"; then
309CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [pragmas])
310CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unreachable-code-break])
311fi
312#
313dnl Only clang 3.6 or later
314if test "$compiler_num" -ge "306"; then
315CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [double-promotion])
316fi
317#
318dnl Only clang 3.9 or later
319if test "$compiler_num" -ge "309"; then
320CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [comma])
321# avoid the varargs warning, fixed in 4.0
322# https://bugs.llvm.org/show_bug.cgi?id=29140
323if test "$compiler_num" -lt "400"; then
324tmp_CFLAGS="$tmp_CFLAGS -Wno-varargs"
325fi
326fi
327dnl clang 7 or later
328if test "$compiler_num" -ge "700"; then
329CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [assign-enum])
330CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [extra-semi-stmt])
331fi
332dnl clang 10 or later
333if test "$compiler_num" -ge "1000"; then
334tmp_CFLAGS="$tmp_CFLAGS -Wimplicit-fallthrough" # we have silencing markup for clang 10.0 and above only
335fi
336
337CFLAGS="$CFLAGS $tmp_CFLAGS"
338
339AC_MSG_NOTICE([Added this set of compiler options: $tmp_CFLAGS])
340
341elif test "$GCC" = "yes"; then
342
343# indentation to match curl's m4/curl-compilers.m4
344
345dnl figure out gcc version!
346AC_MSG_CHECKING([compiler version])
347# strip '-suffix' parts, e.g. Ubuntu Windows cross-gcc returns '10-win32'
348gccver=`$CC -dumpversion | sed -E 's/-.+$//'`
349gccvhi=`echo $gccver | cut -d . -f1`
350if echo $gccver | grep -F "." >/dev/null; then
351gccvlo=`echo $gccver | cut -d . -f2`
352else
353gccvlo="0"
354fi
355compiler_num=`(expr $gccvhi "*" 100 + $gccvlo) 2>/dev/null`
356AC_MSG_RESULT([gcc '$compiler_num' (raw: '$gccver')])
357
358if test "$ICC" = "yes"; then
359dnl this is icc, not gcc.
360
361dnl ICC warnings we ignore:
362dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
363dnl "invalid format string conversion"
364dnl * 279 warns on static conditions in while expressions
365dnl * 981 warns on "operands are evaluated in unspecified order"
366dnl * 1418 "external definition with no prior declaration"
367dnl * 1419 warns on "external declaration in primary source file"
368dnl which we know and do on purpose.
369
370tmp_CFLAGS="-wd279,269,981,1418,1419"
371
372if test "$compiler_num" -gt "600"; then
373dnl icc 6.0 and older doesn't have the -Wall flag
374tmp_CFLAGS="-Wall $tmp_CFLAGS"
375fi
376else dnl $ICC = yes
377dnl this is a set of options we believe *ALL* gcc versions support:
378tmp_CFLAGS="-pedantic"
379if test "$want_werror" = "yes"; then
380LIBSSH2_CFLAG_EXTRAS="$LIBSSH2_CFLAG_EXTRAS -pedantic-errors"
381fi
382CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [all])
383tmp_CFLAGS="$tmp_CFLAGS -W"
384CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [pointer-arith write-strings])
385#
386dnl Only gcc 2.7 or later
387if test "$compiler_num" -ge "207"; then
388CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [inline nested-externs])
389CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-declarations])
390CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-prototypes])
391fi
392#
393dnl Only gcc 2.95 or later
394if test "$compiler_num" -ge "295"; then
395tmp_CFLAGS="$tmp_CFLAGS -Wno-long-long"
396CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [bad-function-cast])
397fi
398#
399dnl Only gcc 2.96 or later
400if test "$compiler_num" -ge "296"; then
401CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [float-equal])
402tmp_CFLAGS="$tmp_CFLAGS -Wno-multichar"
403CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [sign-compare])
404dnl -Wundef used only if gcc is 2.96 or later since we get
405dnl lots of "`_POSIX_C_SOURCE' is not defined" in system
406dnl headers with gcc 2.95.4 on FreeBSD 4.9
407CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [undef])
408fi
409#
410dnl Only gcc 2.97 or later
411if test "$compiler_num" -ge "297"; then
412tmp_CFLAGS="$tmp_CFLAGS -Wno-format-nonliteral"
413fi
414#
415dnl Only gcc 3.0 or later
416if test "$compiler_num" -ge "300"; then
417tmp_CFLAGS="$tmp_CFLAGS -Wno-system-headers"
418dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
419dnl on i686-Linux as it gives us heaps with false positives.
420dnl Also, on gcc 4.0.X it is totally unbearable and complains all
421dnl over making it unusable for generic purposes. Let's not use it.
422CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unused shadow])
423fi
424#
425dnl Only gcc 3.3 or later
426if test "$compiler_num" -ge "303"; then
427CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [endif-labels strict-prototypes])
428fi
429#
430dnl Only gcc 3.4 or later
431if test "$compiler_num" -ge "304"; then
432CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [declaration-after-statement])
433CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [old-style-definition])
434fi
435#
436dnl Only gcc 4.0 or later
437if test "$compiler_num" -ge "400"; then
438tmp_CFLAGS="$tmp_CFLAGS -Wstrict-aliasing=3"
439fi
440#
441dnl Only gcc 4.1 or later (possibly earlier)
442if test "$compiler_num" -ge "401"; then
443CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [attributes])
444CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [div-by-zero format-security])
445CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-field-initializers])
446CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-noreturn])
447CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unreachable-code unused-parameter])
448# CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [padded]) # Not used because we cannot change public structs
449CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [pragmas])
450CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [redundant-decls])
451# CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [switch-enum]) # Not used because this basically disallows default case
452CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unused-macros])
453fi
454#
455dnl Only gcc 4.2 or later
456if test "$compiler_num" -ge "402"; then
457CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [cast-align])
458fi
459#
460dnl Only gcc 4.3 or later
461if test "$compiler_num" -ge "403"; then
462CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [address])
463CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [type-limits old-style-declaration])
464CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-parameter-type empty-body])
465CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [clobbered ignored-qualifiers])
466CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [conversion trampolines])
467CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [sign-conversion])
468tmp_CFLAGS="$tmp_CFLAGS -Wno-error=sign-conversion" # FIXME
469CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [vla])
470dnl required for -Warray-bounds, included in -Wall
471tmp_CFLAGS="$tmp_CFLAGS -ftree-vrp"
472fi
473#
474dnl Only gcc 4.5 or later
475if test "$compiler_num" -ge "405"; then
476dnl Only windows targets
477case $host_os in
478mingw*)
479tmp_CFLAGS="$tmp_CFLAGS -Wno-pedantic-ms-format"
480;;
481esac
482fi
483#
484dnl Only gcc 4.6 or later
485if test "$compiler_num" -ge "406"; then
486CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [double-promotion])
487fi
488#
489dnl only gcc 4.8 or later
490if test "$compiler_num" -ge "408"; then
491tmp_CFLAGS="$tmp_CFLAGS -Wformat=2"
492fi
493#
494dnl Only gcc 5 or later
495if test "$compiler_num" -ge "500"; then
496tmp_CFLAGS="$tmp_CFLAGS -Warray-bounds=2"
497fi
498#
499dnl Only gcc 6 or later
500if test "$compiler_num" -ge "600"; then
501CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [shift-negative-value])
502tmp_CFLAGS="$tmp_CFLAGS -Wshift-overflow=2"
503CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [null-dereference])
504tmp_CFLAGS="$tmp_CFLAGS -fdelete-null-pointer-checks"
505CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [duplicated-cond])
506CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unused-const-variable])
507fi
508#
509dnl Only gcc 7 or later
510if test "$compiler_num" -ge "700"; then
511CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [duplicated-branches])
512CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [restrict])
513CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [alloc-zero])
514tmp_CFLAGS="$tmp_CFLAGS -Wformat-overflow=2"
515tmp_CFLAGS="$tmp_CFLAGS -Wformat-truncation=2"
516tmp_CFLAGS="$tmp_CFLAGS -Wimplicit-fallthrough"
517fi
518#
519dnl Only gcc 10 or later
520if test "$compiler_num" -ge "1000"; then
521CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [arith-conversion])
522CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [enum-conversion])
523fi
524
525for flag in $CPPFLAGS; do
526case "$flag" in
527-I*)
528dnl Include path, provide a -isystem option for the same dir
529dnl to prevent warnings in those dirs. The -isystem was not very
530dnl reliable on earlier gcc versions.
531add=`echo $flag | sed 's/^-I/-isystem /g'`
532tmp_CFLAGS="$tmp_CFLAGS $add"
533;;
534esac
535done
536
537fi dnl $ICC = no
538
539CFLAGS="$CFLAGS $tmp_CFLAGS"
540
541AC_MSG_NOTICE([Added this set of compiler options: $tmp_CFLAGS])
542
543else dnl $GCC = yes
544
545AC_MSG_NOTICE([Added no extra compiler options])
546
547fi dnl $GCC = yes
548
549dnl strip off optimizer flags
550NEWFLAGS=""
551for flag in $CFLAGS; do
552case "$flag" in
553-O*)
554dnl echo "cut off $flag"
555;;
556*)
557NEWFLAGS="$NEWFLAGS $flag"
558;;
559esac
560done
561CFLAGS=$NEWFLAGS
562
563]) dnl end of AC_DEFUN()
564
565dnl CURL_ADD_COMPILER_WARNINGS (WARNING-LIST, NEW-WARNINGS)
566dnl -------------------------------------------------------
567dnl Contents of variable WARNING-LIST and NEW-WARNINGS are
568dnl handled as whitespace separated lists of words.
569dnl Add each compiler warning from NEW-WARNINGS that has not
570dnl been disabled via CFLAGS to WARNING-LIST.
571
572AC_DEFUN([CURL_ADD_COMPILER_WARNINGS], [
573AC_REQUIRE([CURL_SHFUNC_SQUEEZE])dnl
574ac_var_added_warnings=""
575for warning in [$2]; do
576CURL_VAR_MATCH(CFLAGS, [-Wno-$warning -W$warning])
577if test "$ac_var_match_word" = "no"; then
578ac_var_added_warnings="$ac_var_added_warnings -W$warning"
579fi
580done
581dnl squeeze whitespace out of result
582[$1]="$[$1] $ac_var_added_warnings"
583squeeze [$1]
584])
585
586dnl CURL_SHFUNC_SQUEEZE
587dnl -------------------------------------------------
588dnl Declares a shell function squeeze() which removes
589dnl redundant whitespace out of a shell variable.
590
591AC_DEFUN([CURL_SHFUNC_SQUEEZE], [
592squeeze() {
593_sqz_result=""
594eval _sqz_input=\[$][$]1
595for _sqz_token in $_sqz_input; do
596if test -z "$_sqz_result"; then
597_sqz_result="$_sqz_token"
598else
599_sqz_result="$_sqz_result $_sqz_token"
600fi
601done
602eval [$]1=\$_sqz_result
603return 0
604}
605])
606
607dnl CURL_VAR_MATCH (VARNAME, VALUE)
608dnl -------------------------------------------------
609dnl Verifies if shell variable VARNAME contains VALUE.
610dnl Contents of variable VARNAME and VALUE are handled
611dnl as whitespace separated lists of words. If at least
612dnl one word of VALUE is present in VARNAME the match
613dnl is considered positive, otherwise false.
614
615AC_DEFUN([CURL_VAR_MATCH], [
616ac_var_match_word="no"
617for word1 in $[$1]; do
618for word2 in [$2]; do
619if test "$word1" = "$word2"; then
620ac_var_match_word="yes"
621fi
622done
623done
624])
625
626dnl CURL_CHECK_NONBLOCKING_SOCKET
627dnl -------------------------------------------------
628dnl Check for how to set a socket to non-blocking state. There seems to exist
629dnl four known different ways, with the one used almost everywhere being POSIX
630dnl and XPG3, while the other different ways for different systems (old BSD,
631dnl Windows and Amiga).
632dnl
633dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
634dnl O_NONBLOCK define is found but does not work. This condition is attempted
635dnl to get caught in this script by using an excessive number of #ifdefs...
636dnl
637AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
638[
639AC_MSG_CHECKING([non-blocking sockets style])
640
641AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
642/* headers for O_NONBLOCK test */
643#include <sys/types.h>
644#include <unistd.h>
645#include <fcntl.h>
646]], [[
647/* try to compile O_NONBLOCK */
648
649#if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
650# if defined(__SVR4) || defined(__srv4__)
651# define PLATFORM_SOLARIS
652# else
653# define PLATFORM_SUNOS4
654# endif
655#endif
656#if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
657# define PLATFORM_AIX_V3
658#endif
659
660#if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
661#error "O_NONBLOCK does not work on this platform"
662#endif
663int socket;
664int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
665]])],[
666dnl the O_NONBLOCK test was fine
667nonblock="O_NONBLOCK"
668AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
669],[
670dnl the code was bad, try a different program now, test 2
671
672AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
673/* headers for FIONBIO test */
674#include <unistd.h>
675#include <stropts.h>
676]], [[
677/* FIONBIO source test (old-style unix) */
678int socket;
679int flags = ioctl(socket, FIONBIO, &flags);
680]])],[
681dnl FIONBIO test was good
682nonblock="FIONBIO"
683AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
684],[
685dnl FIONBIO test was also bad
686dnl the code was bad, try a different program now, test 3
687
688AC_LINK_IFELSE([AC_LANG_PROGRAM([[
689/* headers for IoctlSocket test (Amiga?) */
690#include <sys/ioctl.h>
691]], [[
692/* IoctlSocket source code */
693int socket;
694int flags = IoctlSocket(socket, FIONBIO, (long)1);
695]])],[
696dnl ioctlsocket test was good
697nonblock="IoctlSocket"
698AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
699],[
700dnl Ioctlsocket did not compile, do test 4!
701AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
702/* headers for SO_NONBLOCK test (BeOS) */
703#include <socket.h>
704]], [[
705/* SO_NONBLOCK source code */
706long b = 1;
707int socket;
708int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
709]])],[
710dnl the SO_NONBLOCK test was good
711nonblock="SO_NONBLOCK"
712AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
713],[
714dnl test 4 did not compile!
715nonblock="nada"
716])
717dnl end of forth test
718
719])
720dnl end of third test
721
722])
723dnl end of second test
724
725])
726dnl end of non-blocking try-compile test
727AC_MSG_RESULT($nonblock)
728
729if test "$nonblock" = "nada"; then
730AC_MSG_WARN([non-block sockets disabled])
731fi
732])
733
734dnl CURL_CHECK_NEED_REENTRANT_SYSTEM
735dnl -------------------------------------------------
736dnl Checks if the preprocessor _REENTRANT definition
737dnl must be unconditionally done for this platform.
738dnl Internal macro for CURL_CONFIGURE_REENTRANT.
739
740AC_DEFUN([CURL_CHECK_NEED_REENTRANT_SYSTEM], [
741case $host in
742*-*-solaris* | *-*-hpux*)
743tmp_need_reentrant="yes"
744;;
745*)
746tmp_need_reentrant="no"
747;;
748esac
749])
750
751
752dnl CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT
753dnl -------------------------------------------------
754dnl This macro ensures that configuration tests done
755dnl after this will execute with preprocessor symbol
756dnl _REENTRANT defined. This macro also ensures that
757dnl the generated config file defines NEED_REENTRANT
758dnl and that in turn setup.h will define _REENTRANT.
759dnl Internal macro for CURL_CONFIGURE_REENTRANT.
760
761AC_DEFUN([CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT], [
762AC_DEFINE(NEED_REENTRANT, 1,
763[Define to 1 if _REENTRANT preprocessor symbol must be defined.])
764cat >>confdefs.h <<_EOF
765#ifndef _REENTRANT
766# define _REENTRANT
767#endif
768_EOF
769])
770
771
772dnl CURL_CONFIGURE_REENTRANT
773dnl -------------------------------------------------
774dnl This first checks if the preprocessor _REENTRANT
775dnl symbol is already defined. If it isn't currently
776dnl defined a set of checks are performed to verify
777dnl if its definition is required to make visible to
778dnl the compiler a set of *_r functions. Finally, if
779dnl _REENTRANT is already defined or needed it takes
780dnl care of making adjustments necessary to ensure
781dnl that it is defined equally for further configure
782dnl tests and generated config file.
783
784AC_DEFUN([CURL_CONFIGURE_REENTRANT], [
785AC_PREREQ([2.50])dnl
786#
787AC_MSG_CHECKING([if _REENTRANT is already defined])
788AC_COMPILE_IFELSE([
789AC_LANG_PROGRAM([[
790]],[[
791#ifdef _REENTRANT
792int dummy=1;
793#else
794force compilation error
795#endif
796]])
797],[
798AC_MSG_RESULT([yes])
799tmp_reentrant_initially_defined="yes"
800],[
801AC_MSG_RESULT([no])
802tmp_reentrant_initially_defined="no"
803])
804#
805if test "$tmp_reentrant_initially_defined" = "no"; then
806AC_MSG_CHECKING([if _REENTRANT is actually needed])
807CURL_CHECK_NEED_REENTRANT_SYSTEM
808
809if test "$tmp_need_reentrant" = "yes"; then
810AC_MSG_RESULT([yes])
811else
812AC_MSG_RESULT([no])
813fi
814fi
815#
816AC_MSG_CHECKING([if _REENTRANT is onwards defined])
817if test "$tmp_reentrant_initially_defined" = "yes" ||
818test "$tmp_need_reentrant" = "yes"; then
819CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT
820AC_MSG_RESULT([yes])
821else
822AC_MSG_RESULT([no])
823fi
824#
825])
826
827dnl LIBSSH2_LIB_HAVE_LINKFLAGS
828dnl --------------------------
829dnl Wrapper around AC_LIB_HAVE_LINKFLAGS to also check $prefix/lib, if set.
830dnl
831dnl autoconf only checks $prefix/lib64 if gcc -print-search-dirs output
832dnl includes a directory named lib64. So, to find libraries in $prefix/lib
833dnl we append -L$prefix/lib to LDFLAGS before checking.
834dnl
835dnl For convenience, $4 is expanded if [lib]$1 is found.
836
837AC_DEFUN([LIBSSH2_LIB_HAVE_LINKFLAGS], [
838libssh2_save_CPPFLAGS="$CPPFLAGS"
839libssh2_save_LDFLAGS="$LDFLAGS"
840
841if test "${with_lib$1_prefix+set}" = set; then
842CPPFLAGS="$CPPFLAGS${CPPFLAGS:+ }-I${with_lib$1_prefix}/include"
843LDFLAGS="$LDFLAGS${LDFLAGS:+ }-L${with_lib$1_prefix}/lib"
844fi
845
846AC_LIB_HAVE_LINKFLAGS([$1], [$2], [$3])
847
848if test "$ac_cv_lib$1" = "yes"; then :
849$4
850else
851CPPFLAGS="$libssh2_save_CPPFLAGS"
852LDFLAGS="$libssh2_save_LDFLAGS"
853fi
854])
855
856AC_DEFUN([LIBSSH2_CHECK_CRYPTO], [
857if test "$use_crypto" = "auto" && test "$found_crypto" = "none" || test "$use_crypto" = "$1"; then
858m4_case([$1],
859[openssl], [
860LIBSSH2_LIB_HAVE_LINKFLAGS([ssl], [crypto], [#include <openssl/ssl.h>], [
861AC_DEFINE(LIBSSH2_OPENSSL, 1, [Use $1])
862LIBSSH2_PC_REQUIRES_PRIVATE="$LIBSSH2_PC_REQUIRES_PRIVATE${LIBSSH2_PC_REQUIRES_PRIVATE:+,}libcrypto"
863found_crypto="$1"
864found_crypto_str="OpenSSL"
865])
866],
867
868[wolfssl], [
869if test "${with_libwolfssl_prefix+set}" = set; then
870CPPFLAGS="$CPPFLAGS${CPPFLAGS:+ }-I${with_libwolfssl_prefix}/include/wolfssl"
871else
872AC_MSG_ERROR([When using wolfSSL, must specify prefix with --with-libwolfssl-prefix in order to find OpenSSL compatibility headers.])
873fi
874LIBSSH2_LIB_HAVE_LINKFLAGS([wolfssl], [], [#include <wolfssl/options.h>], [
875AC_DEFINE(LIBSSH2_WOLFSSL, 1, [Use $1])
876LIBSSH2_PC_REQUIRES_PRIVATE="$LIBSSH2_PC_REQUIRES_PRIVATE${LIBSSH2_PC_REQUIRES_PRIVATE:+,}wolfssl"
877found_crypto="$1"
878])
879],
880
881[libgcrypt], [
882LIBSSH2_LIB_HAVE_LINKFLAGS([gcrypt], [], [#include <gcrypt.h>], [
883AC_DEFINE(LIBSSH2_LIBGCRYPT, 1, [Use $1])
884LIBSSH2_PC_REQUIRES_PRIVATE="$LIBSSH2_PC_REQUIRES_PRIVATE${LIBSSH2_PC_REQUIRES_PRIVATE:+,}libgcrypt"
885found_crypto="$1"
886])
887],
888
889[mbedtls], [
890LIBSSH2_LIB_HAVE_LINKFLAGS([mbedcrypto], [], [#include <mbedtls/version.h>], [
891AC_DEFINE(LIBSSH2_MBEDTLS, 1, [Use $1])
892LIBS="$LIBS -lmbedcrypto"
893found_crypto="$1"
894])
895],
896
897[wincng], [
898if test "x$have_windows_h" = "xyes"; then
899# Look for Windows Cryptography API: Next Generation
900
901LIBS="$LIBS -lcrypt32"
902
903# Check necessary for old-MinGW
904LIBSSH2_LIB_HAVE_LINKFLAGS([bcrypt], [], [
905#include <windows.h>
906#include <bcrypt.h>
907], [
908AC_DEFINE(LIBSSH2_WINCNG, 1, [Use $1])
909found_crypto="$1"
910found_crypto_str="Windows Cryptography API: Next Generation"
911])
912fi
913],
914)
915test "$found_crypto" = "none" &&
916crypto_errors="${crypto_errors}No $1 crypto library found!
917"
918fi
919])
920
921
922dnl LIBSSH2_CHECK_OPTION_WERROR
923dnl -------------------------------------------------
924dnl Verify if configure has been invoked with option
925dnl --enable-werror or --disable-werror, and set
926dnl shell variable want_werror as appropriate.
927
928AC_DEFUN([LIBSSH2_CHECK_OPTION_WERROR], [
929AC_BEFORE([$0],[LIBSSH2_CHECK_COMPILER])dnl
930AC_MSG_CHECKING([whether to enable compiler warnings as errors])
931OPT_COMPILER_WERROR="default"
932AC_ARG_ENABLE(werror,
933AS_HELP_STRING([--enable-werror],[Enable compiler warnings as errors])
934AS_HELP_STRING([--disable-werror],[Disable compiler warnings as errors]),
935OPT_COMPILER_WERROR=$enableval)
936case "$OPT_COMPILER_WERROR" in
937no)
938dnl --disable-werror option used
939want_werror="no"
940;;
941default)
942dnl configure option not specified
943want_werror="no"
944;;
945*)
946dnl --enable-werror option used
947want_werror="yes"
948;;
949esac
950AC_MSG_RESULT([$want_werror])
951
952if test X"$want_werror" = Xyes; then
953LIBSSH2_CFLAG_EXTRAS="$LIBSSH2_CFLAG_EXTRAS -Werror"
954fi
955])
956