| 1 |
# wget_manywarnings.m4 serial 1 |
| 2 |
dnl Copyright (C) 2016-2024 Free Software Foundation, Inc. |
| 3 |
dnl This file is free software; the Free Software Foundation |
| 4 |
dnl gives unlimited permission to copy and/or distribute it, |
| 5 |
dnl with or without modifications, as long as this notice is preserved. |
| 6 |
|
| 7 |
dnl From Tim Ruehsen |
| 8 |
|
| 9 |
# wget_WORD_SET(RESULT, SET, WORDS) |
| 10 |
# -------------------------------------------------- |
| 11 |
# Add each word in WORDS to SET if not already there and store in RESULT. |
| 12 |
# Words separated by whitespace. |
| 13 |
AC_DEFUN([wget_WORD_SET], [ |
| 14 |
ret=$2 |
| 15 |
words=" $2 " |
| 16 |
for word in $3; do |
| 17 |
if test "${words#*" $word "}" = "$words"; then ret="$ret $word"; fi |
| 18 |
done |
| 19 |
$1=$ret |
| 20 |
]) |
| 21 |
|
| 22 |
# wget_WORD_REMOVE(RESULT, SET, WORDS) |
| 23 |
# -------------------------------------------------- |
| 24 |
# Remove each word in WORDS from SET and store in RESULT. |
| 25 |
# Words separated by whitespace. |
| 26 |
AC_DEFUN([wget_WORD_REMOVE], [ |
| 27 |
ret= |
| 28 |
words=" $3 " |
| 29 |
for word in $2; do |
| 30 |
if test "${words#*" $word "}" = "$words"; then ret="$ret $word"; fi |
| 31 |
done |
| 32 |
$1=$ret |
| 33 |
]) |
| 34 |
|
| 35 |
# wget_MANYWARNINGS(VARIABLE, LANGUAGE) |
| 36 |
# ----------------------------- |
| 37 |
# Add LANGUAGE related GCC warnings to VARIABLE. |
| 38 |
# This only works for gcc >= 4.3. |
| 39 |
AC_DEFUN([wget_MANYWARNINGS], [ |
| 40 |
# |
| 41 |
# check if manywarnings is requested |
| 42 |
# |
| 43 |
AC_ARG_ENABLE([manywarnings], |
| 44 |
[AS_HELP_STRING([--enable-manywarnings], [Turn on extra compiler warnings (for developers)])], |
| 45 |
[case $enableval in |
| 46 |
yes|no) ;; |
| 47 |
*) AC_MSG_ERROR([Bad value $enableval for --enable-manywarnings option]) ;; |
| 48 |
esac |
| 49 |
wget_manywarnings=$enableval |
| 50 |
], [ |
| 51 |
test -f .manywarnings && wget_manywarnings=yes || wget_manywarnings=no |
| 52 |
] |
| 53 |
) |
| 54 |
|
| 55 |
$1="" |
| 56 |
|
| 57 |
if test "$wget_manywarnings" = yes; then |
| 58 |
# AC_PROG_CC sets $GCC to 'yes' if compiler is gcc |
| 59 |
# AC_REQUIRE([AC_PROG_CC]) |
| 60 |
|
| 61 |
case $CC in |
| 62 |
*gcc*) CCNAME="gcc";; |
| 63 |
*clang*) CCNAME="clang";; |
| 64 |
esac |
| 65 |
|
| 66 |
if test "$CCNAME" = "gcc"; then |
| 67 |
test -n "$2" && wget_LANGUAGE=$2 || wget_LANGUAGE=C |
| 68 |
|
| 69 |
# add -Wall -Wextra to reduce number of warn flags |
| 70 |
wget_WORD_SET([wget_WARN_CFLAGS], [$CFLAGS], ["-Wall -Wextra -Wformat=2"]) |
| 71 |
|
| 72 |
# collect all disabled warn flags in $WARN_CFLAGS |
| 73 |
wget_WARN_CFLAGS=$wget_WARN_CFLAGS" "$($CC $wget_WARN_CFLAGS -Q --help=warning,$wget_LANGUAGE|\ |
| 74 |
awk '{ if (([$]2 == "[[disabled]]" || [$]2 == "")\ |
| 75 |
&& [$]1!~/=/ && [$]1~/^-W/ && [$]1!~/</ && [$]1!="-Wall") print [$]1 }') |
| 76 |
|
| 77 |
GCC_VERSION=$($CC -dumpversion | cut -f1 -d.) |
| 78 |
if test $GCC_VERSION -ge 6; then |
| 79 |
wget_WARN_CFLAGS=$wget_WARN_CFLAGS" -Warray-bounds=2 -Wnormalized=nfc -Wshift-overflow=2 -Wunused-const-variable=2" |
| 80 |
fi |
| 81 |
if test $GCC_VERSION -ge 7; then |
| 82 |
wget_WARN_CFLAGS=$wget_WARN_CFLAGS" -Wformat-overflow=2 -Wformat-truncation=1 -Wstringop-overflow=2" |
| 83 |
fi |
| 84 |
|
| 85 |
elif test "$CCNAME" = "clang"; then |
| 86 |
# set all warn flags on |
| 87 |
wget_WORD_SET([wget_WARN_CFLAGS], [$CFLAGS], ["-Weverything"]) |
| 88 |
fi |
| 89 |
|
| 90 |
$1=$wget_WARN_CFLAGS |
| 91 |
fi |
| 92 |
]) |