libssh2

Форк
0
/
acinclude.m4 
955 строк · 33.3 Кб
1
# Copyright (C) The libssh2 project and its contributors.
2
# SPDX-License-Identifier: BSD-3-Clause
3
dnl CURL_CPP_P
4
dnl
5
dnl Check if $cpp -P should be used for extract define values due to gcc 5
6
dnl splitting up strings and defines between line outputs. gcc by default
7
dnl (without -P) will show TEST EINVAL TEST as
8
dnl
9
dnl # 13 "conftest.c"
10
dnl TEST
11
dnl # 13 "conftest.c" 3 4
12
dnl     22
13
dnl # 13 "conftest.c"
14
dnl            TEST
15

16
AC_DEFUN([CURL_CPP_P], [
17
  AC_MSG_CHECKING([if cpp -P is needed])
18
  AC_EGREP_CPP([TEST.*TEST], [
19
 #include <errno.h>
20
TEST EINVAL TEST
21
  ], [cpp=no], [cpp=yes])
22
  AC_MSG_RESULT([$cpp])
23

24
  dnl we need cpp -P so check if it works then
25
  if test "x$cpp" = "xyes"; then
26
    AC_MSG_CHECKING([if cpp -P works])
27
    OLDCPPFLAGS=$CPPFLAGS
28
    CPPFLAGS="$CPPFLAGS -P"
29
    AC_EGREP_CPP([TEST.*TEST], [
30
 #include <errno.h>
31
TEST EINVAL TEST
32
    ], [cpp_p=yes], [cpp_p=no])
33
    AC_MSG_RESULT([$cpp_p])
34

35
    if test "x$cpp_p" = "xno"; then
36
      AC_MSG_WARN([failed to figure out cpp -P alternative])
37
      # without -P
38
      CPPPFLAG=""
39
    else
40
      # with -P
41
      CPPPFLAG="-P"
42
    fi
43
    dnl restore CPPFLAGS
44
    CPPFLAGS=$OLDCPPFLAGS
45
  else
46
    # without -P
47
    CPPPFLAG=""
48
  fi
49
])
50

51
dnl CURL_CHECK_DEF (SYMBOL, [INCLUDES], [SILENT])
52
dnl -------------------------------------------------
53
dnl Use the C preprocessor to find out if the given object-style symbol
54
dnl is defined and get its expansion. This macro will not use default
55
dnl includes even if no INCLUDES argument is given. This macro will run
56
dnl silently when invoked with three arguments. If the expansion would
57
dnl result in a set of double-quoted strings the returned expansion will
58
dnl actually be a single double-quoted string concatenating all them.
59

60
AC_DEFUN([CURL_CHECK_DEF], [
61
  AC_REQUIRE([CURL_CPP_P])dnl
62
  OLDCPPFLAGS=$CPPFLAGS
63
  # CPPPFLAG comes from CURL_CPP_P
64
  CPPFLAGS="$CPPFLAGS $CPPPFLAG"
65
  AS_VAR_PUSHDEF([ac_HaveDef], [curl_cv_have_def_$1])dnl
66
  AS_VAR_PUSHDEF([ac_Def], [curl_cv_def_$1])dnl
67
  if test -z "$SED"; then
68
    AC_MSG_ERROR([SED not set. Cannot continue without SED being set.])
69
  fi
70
  if test -z "$GREP"; then
71
    AC_MSG_ERROR([GREP not set. Cannot continue without GREP being set.])
72
  fi
73
  ifelse($3,,[AC_MSG_CHECKING([for preprocessor definition of $1])])
74
  tmp_exp=""
75
  AC_PREPROC_IFELSE([
76
    AC_LANG_SOURCE(
77
ifelse($2,,,[$2])[[
78
#ifdef $1
79
CURL_DEF_TOKEN $1
80
#endif
81
    ]])
82
  ],[
83
    tmp_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`
87
    if test -z "$tmp_exp" || test "$tmp_exp" = "$1"; then
88
      tmp_exp=""
89
    fi
90
  ])
91
  if test -z "$tmp_exp"; then
92
    AS_VAR_SET(ac_HaveDef, no)
93
    ifelse($3,,[AC_MSG_RESULT([no])])
94
  else
95
    AS_VAR_SET(ac_HaveDef, yes)
96
    AS_VAR_SET(ac_Def, $tmp_exp)
97
    ifelse($3,,[AC_MSG_RESULT([$tmp_exp])])
98
  fi
99
  AS_VAR_POPDEF([ac_Def])dnl
100
  AS_VAR_POPDEF([ac_HaveDef])dnl
101
  CPPFLAGS=$OLDCPPFLAGS
102
])
103

104
dnl CURL_CHECK_COMPILER_CLANG
105
dnl -------------------------------------------------
106
dnl Verify if compiler being used is clang.
107

108
AC_DEFUN([CURL_CHECK_COMPILER_CLANG], [
109
  AC_BEFORE([$0],[CURL_CHECK_COMPILER_GNU_C])dnl
110
  AC_MSG_CHECKING([if compiler is clang])
111
  CURL_CHECK_DEF([__clang__], [], [silent])
112
  if test "$curl_cv_have_def___clang__" = "yes"; then
113
    AC_MSG_RESULT([yes])
114
    AC_MSG_CHECKING([if compiler is xlclang])
115
    CURL_CHECK_DEF([__ibmxl__], [], [silent])
116
    if test "$curl_cv_have_def___ibmxl__" = "yes" ; then
117
      dnl IBM's almost-compatible clang version
118
      AC_MSG_RESULT([yes])
119
      compiler_id="XLCLANG"
120
    else
121
      AC_MSG_RESULT([no])
122
      compiler_id="CLANG"
123
    fi
124
    flags_dbg_yes="-g"
125
    flags_opt_all="-O -O0 -O1 -O2 -Os -O3 -O4"
126
    flags_opt_yes="-O2"
127
    flags_opt_off="-O0"
128
  else
129
    AC_MSG_RESULT([no])
130
  fi
131
])
132

133
dnl **********************************************************************
134
dnl CURL_DETECT_ICC ([ACTION-IF-YES])
135
dnl
136
dnl check if this is the Intel ICC compiler, and if so run the ACTION-IF-YES
137
dnl sets the $ICC variable to "yes" or "no"
138
dnl **********************************************************************
139
AC_DEFUN([CURL_DETECT_ICC],
140
[
141
  ICC="no"
142
  AC_MSG_CHECKING([for icc in use])
143
  if test "$GCC" = "yes"; then
144
    dnl check if this is icc acting as gcc in disguise
145
    AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
146
      dnl action if the text is found, this it has not been replaced by the
147
      dnl cpp
148
      ICC="no",
149
      dnl the text was not found, it was replaced by the cpp
150
      ICC="yes"
151
      AC_MSG_RESULT([yes])
152
      [$1]
153
    )
154
  fi
155
  if test "$ICC" = "no"; then
156
    # this is not ICC
157
    AC_MSG_RESULT([no])
158
  fi
159
])
160

161
dnl We create a function for detecting which compiler we use and then set as
162
dnl pedantic compiler options as possible for that particular compiler. The
163
dnl options are only used for debug-builds.
164

165
AC_DEFUN([CURL_CC_DEBUG_OPTS],
166
[
167
  if test "z$CLANG" = "z"; then
168
    CURL_CHECK_COMPILER_CLANG
169
    if test "z$compiler_id" = "zCLANG"; then
170
      CLANG="yes"
171
    else
172
      CLANG="no"
173
    fi
174
  fi
175
  if test "z$ICC" = "z"; then
176
    CURL_DETECT_ICC
177
  fi
178

179
  if test "$CLANG" = "yes"; then
180

181
          # indentation to match curl's m4/curl-compilers.m4
182

183
          dnl figure out clang version!
184
          AC_MSG_CHECKING([compiler version])
185
          fullclangver=`$CC -v 2>&1 | grep version`
186
          if echo $fullclangver | grep 'Apple' >/dev/null; then
187
            appleclang=1
188
          else
189
            appleclang=0
190
          fi
191
          clangver=`echo $fullclangver | grep "based on LLVM " | "$SED" 's/.*(based on LLVM \(@<:@0-9@:>@*\.@<:@0-9@:>@*\).*)/\1/'`
192
          if test -z "$clangver"; then
193
            clangver=`echo $fullclangver | "$SED" 's/.*version \(@<:@0-9@:>@*\.@<:@0-9@:>@*\).*/\1/'`
194
            oldapple=0
195
          else
196
            oldapple=1
197
          fi
198
          clangvhi=`echo $clangver | cut -d . -f1`
199
          clangvlo=`echo $clangver | cut -d . -f2`
200
          compiler_num=`(expr $clangvhi "*" 100 + $clangvlo) 2>/dev/null`
201
          if test "$appleclang" = '1' && test "$oldapple" = '0'; then
202
            dnl Starting with Xcode 7 / clang 3.7, Apple clang won't tell its upstream version
203
            if   test "$compiler_num" -ge '1300'; then compiler_num='1200'
204
            elif test "$compiler_num" -ge '1205'; then compiler_num='1101'
205
            elif test "$compiler_num" -ge '1204'; then compiler_num='1000'
206
            elif test "$compiler_num" -ge '1107'; then compiler_num='900'
207
            elif test "$compiler_num" -ge '1103'; then compiler_num='800'
208
            elif test "$compiler_num" -ge '1003'; then compiler_num='700'
209
            elif test "$compiler_num" -ge '1001'; then compiler_num='600'
210
            elif test "$compiler_num" -ge  '904'; then compiler_num='500'
211
            elif test "$compiler_num" -ge  '902'; then compiler_num='400'
212
            elif test "$compiler_num" -ge  '803'; then compiler_num='309'
213
            elif test "$compiler_num" -ge  '703'; then compiler_num='308'
214
            else                                       compiler_num='307'
215
            fi
216
          fi
217
          AC_MSG_RESULT([clang '$compiler_num' (raw: '$fullclangver' / '$clangver')])
218

219
          tmp_CFLAGS="-pedantic"
220
          if test "$want_werror" = "yes"; then
221
            LIBSSH2_CFLAG_EXTRAS="$LIBSSH2_CFLAG_EXTRAS -pedantic-errors"
222
          fi
223
          CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [all extra])
224
          CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [pointer-arith write-strings])
225
          CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [shadow])
226
          CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [inline nested-externs])
227
          CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-declarations])
228
          CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-prototypes])
229
          tmp_CFLAGS="$tmp_CFLAGS -Wno-long-long"
230
          CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [float-equal])
231
          CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [sign-compare])
232
          tmp_CFLAGS="$tmp_CFLAGS -Wno-multichar"
233
          CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [undef])
234
          tmp_CFLAGS="$tmp_CFLAGS -Wno-format-nonliteral"
235
          CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [endif-labels strict-prototypes])
236
          CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [declaration-after-statement])
237
          CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [cast-align])
238
          tmp_CFLAGS="$tmp_CFLAGS -Wno-system-headers"
239
          CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [shorten-64-to-32])
240
          #
241
          dnl Only clang 1.1 or later
242
          if test "$compiler_num" -ge "101"; then
243
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unused])
244
          fi
245
          #
246
          dnl Only clang 2.7 or later
247
          if test "$compiler_num" -ge "207"; then
248
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [address])
249
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [attributes])
250
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [bad-function-cast])
251
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [conversion])
252
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [div-by-zero format-security])
253
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [empty-body])
254
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-field-initializers])
255
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-noreturn])
256
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [old-style-definition])
257
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [redundant-decls])
258
          # CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [switch-enum])       # Not used because this basically disallows default case
259
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [type-limits])
260
            if test "x$have_windows_h" != "xyes"; then
261
              CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unused-macros])  # Seen to clash with libtool-generated stub code
262
            fi
263
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unreachable-code unused-parameter])
264
          fi
265
          #
266
          dnl Only clang 2.8 or later
267
          if test "$compiler_num" -ge "208"; then
268
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [ignored-qualifiers])
269
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [vla])
270
          fi
271
          #
272
          dnl Only clang 2.9 or later
273
          if test "$compiler_num" -ge "209"; then
274
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [sign-conversion])
275
            tmp_CFLAGS="$tmp_CFLAGS -Wno-error=sign-conversion"           # FIXME
276
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [shift-sign-overflow])
277
          # CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [padded])  # Not used because we cannot change public structs
278
          fi
279
          #
280
          dnl Only clang 3.0 or later
281
          if test "$compiler_num" -ge "300"; then
282
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [language-extension-token])
283
            tmp_CFLAGS="$tmp_CFLAGS -Wformat=2"
284
          fi
285
          #
286
          dnl Only clang 3.2 or later
287
          if test "$compiler_num" -ge "302"; then
288
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [enum-conversion])
289
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [sometimes-uninitialized])
290
            case $host_os in
291
            cygwin* | mingw*)
292
              dnl skip missing-variable-declarations warnings for cygwin and
293
              dnl mingw because the libtool wrapper executable causes them
294
              ;;
295
            *)
296
              CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-variable-declarations])
297
              ;;
298
            esac
299
          fi
300
          #
301
          dnl Only clang 3.4 or later
302
          if test "$compiler_num" -ge "304"; then
303
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [header-guard])
304
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unused-const-variable])
305
          fi
306
          #
307
          dnl Only clang 3.5 or later
308
          if test "$compiler_num" -ge "305"; then
309
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [pragmas])
310
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unreachable-code-break])
311
          fi
312
          #
313
          dnl Only clang 3.6 or later
314
          if test "$compiler_num" -ge "306"; then
315
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [double-promotion])
316
          fi
317
          #
318
          dnl Only clang 3.9 or later
319
          if test "$compiler_num" -ge "309"; then
320
            CURL_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
323
            if test "$compiler_num" -lt "400"; then
324
              tmp_CFLAGS="$tmp_CFLAGS -Wno-varargs"
325
            fi
326
          fi
327
          dnl clang 7 or later
328
          if test "$compiler_num" -ge "700"; then
329
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [assign-enum])
330
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [extra-semi-stmt])
331
          fi
332
          dnl clang 10 or later
333
          if test "$compiler_num" -ge "1000"; then
334
            tmp_CFLAGS="$tmp_CFLAGS -Wimplicit-fallthrough"  # we have silencing markup for clang 10.0 and above only
335
          fi
336

337
          CFLAGS="$CFLAGS $tmp_CFLAGS"
338

339
          AC_MSG_NOTICE([Added this set of compiler options: $tmp_CFLAGS])
340

341
  elif test "$GCC" = "yes"; then
342

343
        # indentation to match curl's m4/curl-compilers.m4
344

345
        dnl figure out gcc version!
346
        AC_MSG_CHECKING([compiler version])
347
        # strip '-suffix' parts, e.g. Ubuntu Windows cross-gcc returns '10-win32'
348
        gccver=`$CC -dumpversion | sed -E 's/-.+$//'`
349
        gccvhi=`echo $gccver | cut -d . -f1`
350
        if echo $gccver | grep -F "." >/dev/null; then
351
          gccvlo=`echo $gccver | cut -d . -f2`
352
        else
353
          gccvlo="0"
354
        fi
355
        compiler_num=`(expr $gccvhi "*" 100 + $gccvlo) 2>/dev/null`
356
        AC_MSG_RESULT([gcc '$compiler_num' (raw: '$gccver')])
357

358
        if test "$ICC" = "yes"; then
359
          dnl this is icc, not gcc.
360

361
          dnl ICC warnings we ignore:
362
          dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
363
          dnl   "invalid format string conversion"
364
          dnl * 279 warns on static conditions in while expressions
365
          dnl * 981 warns on "operands are evaluated in unspecified order"
366
          dnl * 1418 "external definition with no prior declaration"
367
          dnl * 1419 warns on "external declaration in primary source file"
368
          dnl   which we know and do on purpose.
369

370
          tmp_CFLAGS="-wd279,269,981,1418,1419"
371

372
          if test "$compiler_num" -gt "600"; then
373
             dnl icc 6.0 and older doesn't have the -Wall flag
374
             tmp_CFLAGS="-Wall $tmp_CFLAGS"
375
          fi
376
        else dnl $ICC = yes
377
          dnl this is a set of options we believe *ALL* gcc versions support:
378
          tmp_CFLAGS="-pedantic"
379
          if test "$want_werror" = "yes"; then
380
            LIBSSH2_CFLAG_EXTRAS="$LIBSSH2_CFLAG_EXTRAS -pedantic-errors"
381
          fi
382
          CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [all])
383
          tmp_CFLAGS="$tmp_CFLAGS -W"
384
          CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [pointer-arith write-strings])
385
          #
386
          dnl Only gcc 2.7 or later
387
          if test "$compiler_num" -ge "207"; then
388
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [inline nested-externs])
389
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-declarations])
390
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-prototypes])
391
          fi
392
          #
393
          dnl Only gcc 2.95 or later
394
          if test "$compiler_num" -ge "295"; then
395
            tmp_CFLAGS="$tmp_CFLAGS -Wno-long-long"
396
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [bad-function-cast])
397
          fi
398
          #
399
          dnl Only gcc 2.96 or later
400
          if test "$compiler_num" -ge "296"; then
401
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [float-equal])
402
            tmp_CFLAGS="$tmp_CFLAGS -Wno-multichar"
403
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [sign-compare])
404
            dnl -Wundef used only if gcc is 2.96 or later since we get
405
            dnl lots of "`_POSIX_C_SOURCE' is not defined" in system
406
            dnl headers with gcc 2.95.4 on FreeBSD 4.9
407
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [undef])
408
          fi
409
          #
410
          dnl Only gcc 2.97 or later
411
          if test "$compiler_num" -ge "297"; then
412
            tmp_CFLAGS="$tmp_CFLAGS -Wno-format-nonliteral"
413
          fi
414
          #
415
          dnl Only gcc 3.0 or later
416
          if test "$compiler_num" -ge "300"; then
417
            tmp_CFLAGS="$tmp_CFLAGS -Wno-system-headers"
418
            dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
419
            dnl on i686-Linux as it gives us heaps with false positives.
420
            dnl Also, on gcc 4.0.X it is totally unbearable and complains all
421
            dnl over making it unusable for generic purposes. Let's not use it.
422
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unused shadow])
423
          fi
424
          #
425
          dnl Only gcc 3.3 or later
426
          if test "$compiler_num" -ge "303"; then
427
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [endif-labels strict-prototypes])
428
          fi
429
          #
430
          dnl Only gcc 3.4 or later
431
          if test "$compiler_num" -ge "304"; then
432
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [declaration-after-statement])
433
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [old-style-definition])
434
          fi
435
          #
436
          dnl Only gcc 4.0 or later
437
          if test "$compiler_num" -ge "400"; then
438
            tmp_CFLAGS="$tmp_CFLAGS -Wstrict-aliasing=3"
439
          fi
440
          #
441
          dnl Only gcc 4.1 or later (possibly earlier)
442
          if test "$compiler_num" -ge "401"; then
443
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [attributes])
444
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [div-by-zero format-security])
445
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-field-initializers])
446
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-noreturn])
447
            CURL_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
449
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [pragmas])
450
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [redundant-decls])
451
          # CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [switch-enum])      # Not used because this basically disallows default case
452
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unused-macros])
453
          fi
454
          #
455
          dnl Only gcc 4.2 or later
456
          if test "$compiler_num" -ge "402"; then
457
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [cast-align])
458
          fi
459
          #
460
          dnl Only gcc 4.3 or later
461
          if test "$compiler_num" -ge "403"; then
462
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [address])
463
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [type-limits old-style-declaration])
464
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [missing-parameter-type empty-body])
465
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [clobbered ignored-qualifiers])
466
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [conversion trampolines])
467
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [sign-conversion])
468
            tmp_CFLAGS="$tmp_CFLAGS -Wno-error=sign-conversion"          # FIXME
469
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [vla])
470
            dnl required for -Warray-bounds, included in -Wall
471
            tmp_CFLAGS="$tmp_CFLAGS -ftree-vrp"
472
          fi
473
          #
474
          dnl Only gcc 4.5 or later
475
          if test "$compiler_num" -ge "405"; then
476
            dnl Only windows targets
477
            case $host_os in
478
            mingw*)
479
              tmp_CFLAGS="$tmp_CFLAGS -Wno-pedantic-ms-format"
480
              ;;
481
            esac
482
          fi
483
          #
484
          dnl Only gcc 4.6 or later
485
          if test "$compiler_num" -ge "406"; then
486
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [double-promotion])
487
          fi
488
          #
489
          dnl only gcc 4.8 or later
490
          if test "$compiler_num" -ge "408"; then
491
            tmp_CFLAGS="$tmp_CFLAGS -Wformat=2"
492
          fi
493
          #
494
          dnl Only gcc 5 or later
495
          if test "$compiler_num" -ge "500"; then
496
            tmp_CFLAGS="$tmp_CFLAGS -Warray-bounds=2"
497
          fi
498
          #
499
          dnl Only gcc 6 or later
500
          if test "$compiler_num" -ge "600"; then
501
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [shift-negative-value])
502
            tmp_CFLAGS="$tmp_CFLAGS -Wshift-overflow=2"
503
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [null-dereference])
504
            tmp_CFLAGS="$tmp_CFLAGS -fdelete-null-pointer-checks"
505
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [duplicated-cond])
506
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [unused-const-variable])
507
          fi
508
          #
509
          dnl Only gcc 7 or later
510
          if test "$compiler_num" -ge "700"; then
511
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [duplicated-branches])
512
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [restrict])
513
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [alloc-zero])
514
            tmp_CFLAGS="$tmp_CFLAGS -Wformat-overflow=2"
515
            tmp_CFLAGS="$tmp_CFLAGS -Wformat-truncation=2"
516
            tmp_CFLAGS="$tmp_CFLAGS -Wimplicit-fallthrough"
517
          fi
518
          #
519
          dnl Only gcc 10 or later
520
          if test "$compiler_num" -ge "1000"; then
521
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [arith-conversion])
522
            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [enum-conversion])
523
          fi
524

525
          for flag in $CPPFLAGS; do
526
            case "$flag" in
527
             -I*)
528
               dnl Include path, provide a -isystem option for the same dir
529
               dnl to prevent warnings in those dirs. The -isystem was not very
530
               dnl reliable on earlier gcc versions.
531
               add=`echo $flag | sed 's/^-I/-isystem /g'`
532
               tmp_CFLAGS="$tmp_CFLAGS $add"
533
               ;;
534
            esac
535
          done
536

537
    fi dnl $ICC = no
538

539
    CFLAGS="$CFLAGS $tmp_CFLAGS"
540

541
    AC_MSG_NOTICE([Added this set of compiler options: $tmp_CFLAGS])
542

543
  else dnl $GCC = yes
544

545
    AC_MSG_NOTICE([Added no extra compiler options])
546

547
  fi dnl $GCC = yes
548

549
  dnl strip off optimizer flags
550
  NEWFLAGS=""
551
  for flag in $CFLAGS; do
552
    case "$flag" in
553
    -O*)
554
      dnl echo "cut off $flag"
555
      ;;
556
    *)
557
      NEWFLAGS="$NEWFLAGS $flag"
558
      ;;
559
    esac
560
  done
561
  CFLAGS=$NEWFLAGS
562

563
]) dnl end of AC_DEFUN()
564

565
dnl CURL_ADD_COMPILER_WARNINGS (WARNING-LIST, NEW-WARNINGS)
566
dnl -------------------------------------------------------
567
dnl Contents of variable WARNING-LIST and NEW-WARNINGS are
568
dnl handled as whitespace separated lists of words.
569
dnl Add each compiler warning from NEW-WARNINGS that has not
570
dnl been disabled via CFLAGS to WARNING-LIST.
571

572
AC_DEFUN([CURL_ADD_COMPILER_WARNINGS], [
573
  AC_REQUIRE([CURL_SHFUNC_SQUEEZE])dnl
574
  ac_var_added_warnings=""
575
  for warning in [$2]; do
576
    CURL_VAR_MATCH(CFLAGS, [-Wno-$warning -W$warning])
577
    if test "$ac_var_match_word" = "no"; then
578
      ac_var_added_warnings="$ac_var_added_warnings -W$warning"
579
    fi
580
  done
581
  dnl squeeze whitespace out of result
582
  [$1]="$[$1] $ac_var_added_warnings"
583
  squeeze [$1]
584
])
585

586
dnl CURL_SHFUNC_SQUEEZE
587
dnl -------------------------------------------------
588
dnl Declares a shell function squeeze() which removes
589
dnl redundant whitespace out of a shell variable.
590

591
AC_DEFUN([CURL_SHFUNC_SQUEEZE], [
592
squeeze() {
593
  _sqz_result=""
594
  eval _sqz_input=\[$][$]1
595
  for _sqz_token in $_sqz_input; do
596
    if test -z "$_sqz_result"; then
597
      _sqz_result="$_sqz_token"
598
    else
599
      _sqz_result="$_sqz_result $_sqz_token"
600
    fi
601
  done
602
  eval [$]1=\$_sqz_result
603
  return 0
604
}
605
])
606

607
dnl CURL_VAR_MATCH (VARNAME, VALUE)
608
dnl -------------------------------------------------
609
dnl Verifies if shell variable VARNAME contains VALUE.
610
dnl Contents of variable VARNAME and VALUE are handled
611
dnl as whitespace separated lists of words. If at least
612
dnl one word of VALUE is present in VARNAME the match
613
dnl is considered positive, otherwise false.
614

615
AC_DEFUN([CURL_VAR_MATCH], [
616
  ac_var_match_word="no"
617
  for word1 in $[$1]; do
618
    for word2 in [$2]; do
619
      if test "$word1" = "$word2"; then
620
        ac_var_match_word="yes"
621
      fi
622
    done
623
  done
624
])
625

626
dnl CURL_CHECK_NONBLOCKING_SOCKET
627
dnl -------------------------------------------------
628
dnl Check for how to set a socket to non-blocking state. There seems to exist
629
dnl four known different ways, with the one used almost everywhere being POSIX
630
dnl and XPG3, while the other different ways for different systems (old BSD,
631
dnl Windows and Amiga).
632
dnl
633
dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
634
dnl O_NONBLOCK define is found but does not work. This condition is attempted
635
dnl to get caught in this script by using an excessive number of #ifdefs...
636
dnl
637
AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
638
[
639
  AC_MSG_CHECKING([non-blocking sockets style])
640

641
  AC_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
663
  int socket;
664
  int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
665
]])],[
666
dnl the O_NONBLOCK test was fine
667
nonblock="O_NONBLOCK"
668
AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
669
],[
670
dnl the code was bad, try a different program now, test 2
671

672
  AC_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) */
678
 int socket;
679
 int flags = ioctl(socket, FIONBIO, &flags);
680
]])],[
681
dnl FIONBIO test was good
682
nonblock="FIONBIO"
683
AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
684
],[
685
dnl FIONBIO test was also bad
686
dnl the code was bad, try a different program now, test 3
687

688
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[
689
/* headers for IoctlSocket test (Amiga?) */
690
#include <sys/ioctl.h>
691
]], [[
692
/* IoctlSocket source code */
693
 int socket;
694
 int flags = IoctlSocket(socket, FIONBIO, (long)1);
695
]])],[
696
dnl ioctlsocket test was good
697
nonblock="IoctlSocket"
698
AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
699
],[
700
dnl Ioctlsocket did not compile, do test 4!
701
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
702
/* headers for SO_NONBLOCK test (BeOS) */
703
#include <socket.h>
704
]], [[
705
/* SO_NONBLOCK source code */
706
 long b = 1;
707
 int socket;
708
 int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
709
]])],[
710
dnl the SO_NONBLOCK test was good
711
nonblock="SO_NONBLOCK"
712
AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
713
],[
714
dnl test 4 did not compile!
715
nonblock="nada"
716
])
717
dnl end of forth test
718

719
])
720
dnl end of third test
721

722
])
723
dnl end of second test
724

725
])
726
dnl end of non-blocking try-compile test
727
  AC_MSG_RESULT($nonblock)
728

729
  if test "$nonblock" = "nada"; then
730
    AC_MSG_WARN([non-block sockets disabled])
731
  fi
732
])
733

734
dnl CURL_CHECK_NEED_REENTRANT_SYSTEM
735
dnl -------------------------------------------------
736
dnl Checks if the preprocessor _REENTRANT definition
737
dnl must be unconditionally done for this platform.
738
dnl Internal macro for CURL_CONFIGURE_REENTRANT.
739

740
AC_DEFUN([CURL_CHECK_NEED_REENTRANT_SYSTEM], [
741
  case $host in
742
    *-*-solaris* | *-*-hpux*)
743
      tmp_need_reentrant="yes"
744
      ;;
745
    *)
746
      tmp_need_reentrant="no"
747
      ;;
748
  esac
749
])
750

751

752
dnl CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT
753
dnl -------------------------------------------------
754
dnl This macro ensures that configuration tests done
755
dnl after this will execute with preprocessor symbol
756
dnl _REENTRANT defined. This macro also ensures that
757
dnl the generated config file defines NEED_REENTRANT
758
dnl and that in turn setup.h will define _REENTRANT.
759
dnl Internal macro for CURL_CONFIGURE_REENTRANT.
760

761
AC_DEFUN([CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT], [
762
AC_DEFINE(NEED_REENTRANT, 1,
763
  [Define to 1 if _REENTRANT preprocessor symbol must be defined.])
764
cat >>confdefs.h <<_EOF
765
#ifndef _REENTRANT
766
#  define _REENTRANT
767
#endif
768
_EOF
769
])
770

771

772
dnl CURL_CONFIGURE_REENTRANT
773
dnl -------------------------------------------------
774
dnl This first checks if the preprocessor _REENTRANT
775
dnl symbol is already defined. If it isn't currently
776
dnl defined a set of checks are performed to verify
777
dnl if its definition is required to make visible to
778
dnl the compiler a set of *_r functions. Finally, if
779
dnl _REENTRANT is already defined or needed it takes
780
dnl care of making adjustments necessary to ensure
781
dnl that it is defined equally for further configure
782
dnl tests and generated config file.
783

784
AC_DEFUN([CURL_CONFIGURE_REENTRANT], [
785
  AC_PREREQ([2.50])dnl
786
  #
787
  AC_MSG_CHECKING([if _REENTRANT is already defined])
788
  AC_COMPILE_IFELSE([
789
    AC_LANG_PROGRAM([[
790
    ]],[[
791
#ifdef _REENTRANT
792
      int dummy=1;
793
#else
794
      force compilation error
795
#endif
796
    ]])
797
  ],[
798
    AC_MSG_RESULT([yes])
799
    tmp_reentrant_initially_defined="yes"
800
  ],[
801
    AC_MSG_RESULT([no])
802
    tmp_reentrant_initially_defined="no"
803
  ])
804
  #
805
  if test "$tmp_reentrant_initially_defined" = "no"; then
806
    AC_MSG_CHECKING([if _REENTRANT is actually needed])
807
    CURL_CHECK_NEED_REENTRANT_SYSTEM
808

809
    if test "$tmp_need_reentrant" = "yes"; then
810
      AC_MSG_RESULT([yes])
811
    else
812
      AC_MSG_RESULT([no])
813
    fi
814
  fi
815
  #
816
  AC_MSG_CHECKING([if _REENTRANT is onwards defined])
817
  if test "$tmp_reentrant_initially_defined" = "yes" ||
818
    test "$tmp_need_reentrant" = "yes"; then
819
    CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT
820
    AC_MSG_RESULT([yes])
821
  else
822
    AC_MSG_RESULT([no])
823
  fi
824
  #
825
])
826

827
dnl LIBSSH2_LIB_HAVE_LINKFLAGS
828
dnl --------------------------
829
dnl Wrapper around AC_LIB_HAVE_LINKFLAGS to also check $prefix/lib, if set.
830
dnl
831
dnl autoconf only checks $prefix/lib64 if gcc -print-search-dirs output
832
dnl includes a directory named lib64. So, to find libraries in $prefix/lib
833
dnl we append -L$prefix/lib to LDFLAGS before checking.
834
dnl
835
dnl For convenience, $4 is expanded if [lib]$1 is found.
836

837
AC_DEFUN([LIBSSH2_LIB_HAVE_LINKFLAGS], [
838
  libssh2_save_CPPFLAGS="$CPPFLAGS"
839
  libssh2_save_LDFLAGS="$LDFLAGS"
840

841
  if test "${with_lib$1_prefix+set}" = set; then
842
    CPPFLAGS="$CPPFLAGS${CPPFLAGS:+ }-I${with_lib$1_prefix}/include"
843
    LDFLAGS="$LDFLAGS${LDFLAGS:+ }-L${with_lib$1_prefix}/lib"
844
  fi
845

846
  AC_LIB_HAVE_LINKFLAGS([$1], [$2], [$3])
847

848
  if test "$ac_cv_lib$1" = "yes"; then :
849
    $4
850
  else
851
    CPPFLAGS="$libssh2_save_CPPFLAGS"
852
    LDFLAGS="$libssh2_save_LDFLAGS"
853
  fi
854
])
855

856
AC_DEFUN([LIBSSH2_CHECK_CRYPTO], [
857
if test "$use_crypto" = "auto" && test "$found_crypto" = "none" || test "$use_crypto" = "$1"; then
858
m4_case([$1],
859
[openssl], [
860
  LIBSSH2_LIB_HAVE_LINKFLAGS([ssl], [crypto], [#include <openssl/ssl.h>], [
861
    AC_DEFINE(LIBSSH2_OPENSSL, 1, [Use $1])
862
    LIBSSH2_PC_REQUIRES_PRIVATE="$LIBSSH2_PC_REQUIRES_PRIVATE${LIBSSH2_PC_REQUIRES_PRIVATE:+,}libcrypto"
863
    found_crypto="$1"
864
    found_crypto_str="OpenSSL"
865
  ])
866
],
867

868
[wolfssl], [
869
  if test "${with_libwolfssl_prefix+set}" = set; then
870
    CPPFLAGS="$CPPFLAGS${CPPFLAGS:+ }-I${with_libwolfssl_prefix}/include/wolfssl"
871
  else
872
    AC_MSG_ERROR([When using wolfSSL, must specify prefix with --with-libwolfssl-prefix in order to find OpenSSL compatibility headers.])
873
  fi
874
  LIBSSH2_LIB_HAVE_LINKFLAGS([wolfssl], [], [#include <wolfssl/options.h>], [
875
    AC_DEFINE(LIBSSH2_WOLFSSL, 1, [Use $1])
876
    LIBSSH2_PC_REQUIRES_PRIVATE="$LIBSSH2_PC_REQUIRES_PRIVATE${LIBSSH2_PC_REQUIRES_PRIVATE:+,}wolfssl"
877
    found_crypto="$1"
878
  ])
879
],
880

881
[libgcrypt], [
882
  LIBSSH2_LIB_HAVE_LINKFLAGS([gcrypt], [], [#include <gcrypt.h>], [
883
    AC_DEFINE(LIBSSH2_LIBGCRYPT, 1, [Use $1])
884
    LIBSSH2_PC_REQUIRES_PRIVATE="$LIBSSH2_PC_REQUIRES_PRIVATE${LIBSSH2_PC_REQUIRES_PRIVATE:+,}libgcrypt"
885
    found_crypto="$1"
886
  ])
887
],
888

889
[mbedtls], [
890
  LIBSSH2_LIB_HAVE_LINKFLAGS([mbedcrypto], [], [#include <mbedtls/version.h>], [
891
    AC_DEFINE(LIBSSH2_MBEDTLS, 1, [Use $1])
892
    LIBS="$LIBS -lmbedcrypto"
893
    found_crypto="$1"
894
  ])
895
],
896

897
[wincng], [
898
  if test "x$have_windows_h" = "xyes"; then
899
    # Look for Windows Cryptography API: Next Generation
900

901
    LIBS="$LIBS -lcrypt32"
902

903
    # Check necessary for old-MinGW
904
    LIBSSH2_LIB_HAVE_LINKFLAGS([bcrypt], [], [
905
      #include <windows.h>
906
      #include <bcrypt.h>
907
    ], [
908
      AC_DEFINE(LIBSSH2_WINCNG, 1, [Use $1])
909
      found_crypto="$1"
910
      found_crypto_str="Windows Cryptography API: Next Generation"
911
    ])
912
  fi
913
],
914
)
915
  test "$found_crypto" = "none" &&
916
    crypto_errors="${crypto_errors}No $1 crypto library found!
917
"
918
fi
919
])
920

921

922
dnl LIBSSH2_CHECK_OPTION_WERROR
923
dnl -------------------------------------------------
924
dnl Verify if configure has been invoked with option
925
dnl --enable-werror or --disable-werror, and set
926
dnl shell variable want_werror as appropriate.
927

928
AC_DEFUN([LIBSSH2_CHECK_OPTION_WERROR], [
929
  AC_BEFORE([$0],[LIBSSH2_CHECK_COMPILER])dnl
930
  AC_MSG_CHECKING([whether to enable compiler warnings as errors])
931
  OPT_COMPILER_WERROR="default"
932
  AC_ARG_ENABLE(werror,
933
AS_HELP_STRING([--enable-werror],[Enable compiler warnings as errors])
934
AS_HELP_STRING([--disable-werror],[Disable compiler warnings as errors]),
935
  OPT_COMPILER_WERROR=$enableval)
936
  case "$OPT_COMPILER_WERROR" in
937
    no)
938
      dnl --disable-werror option used
939
      want_werror="no"
940
      ;;
941
    default)
942
      dnl configure option not specified
943
      want_werror="no"
944
      ;;
945
    *)
946
      dnl --enable-werror option used
947
      want_werror="yes"
948
      ;;
949
  esac
950
  AC_MSG_RESULT([$want_werror])
951

952
  if test X"$want_werror" = Xyes; then
953
    LIBSSH2_CFLAG_EXTRAS="$LIBSSH2_CFLAG_EXTRAS -Werror"
954
  fi
955
])
956

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.