From 71a8648145861cebde04cebf4de8ce10e21b7904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim Rühsen?= Date: Sun, 18 Jun 2017 12:33:08 +0200 Subject: [PATCH] Add m4/wget_manywarnings This enables (if switched on) basically all warnings for gcc and clang. Exceptions are explicitly controlled in configure.ac. To enable by default: create a file '.manywarnings' Enable explicitly : ./configure --enable-manywarnings Disable explicitly: ./configure --disable-manywarnings New warnings of new compiler versions are automatically added. This module works much faster than the 'manywarnings' module from gnulib. Created for developers and Continuous Integration. --- configure.ac | 53 ++++++++++++++++++++++++++++ m4/wget_manywarnings.m4 | 88 ++++++++++++++++++++++++++++++++++++++++++++++ src/microhttpd/Makefile.am | 2 +- 3 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 m4/wget_manywarnings.m4 diff --git a/configure.ac b/configure.ac index 443dcf24..b4b28748 100644 --- a/configure.ac +++ b/configure.ac @@ -338,6 +338,59 @@ netbsd*) ;; esac + +# enable all possible compiler warnings in WARN_FLAGS +# +# to enable by default: create a file '.manywarnings' +# enable explicitly : ./configure --enable-manywarnings +# disable explicitly: ./configure --disable-manywarnings +wget_MANYWARNINGS(WARN_CFLAGS, C) + +if test -n "$WARN_CFLAGS"; then + if test "$CCNAME" = "gcc"; then + # Set up list of unwanted warnings + nw+ nw="$nw -Wsystem-headers" # System headers may trigger lot's of useless warnings + nw="$nw -Wvla" # This project is C99 + nw="$nw -Wstack-protector" + nw="$nw -Wmissing-field-initializer" + nw="$nw -Wtraditional" + nw="$nw -Wtraditional-conversion" + nw="$nw -Wc++-compat" + nw="$nw -Wcast-qual" + nw="$nw -Wconversion" + nw="$nw -Wsign-conversion" + nw="$nw -Wunsuffixed-float-constants" + nw="$nw -Wdeclaration-after-statement" # C89 only, messing up gcc < 5 + if test "$cross_compiling" = yes; then + nw="$nw -Wformat" + fi + + # remove unwanted warn flags + wget_WORD_REMOVE([WARN_CFLAGS], [$WARN_CFLAGS], [$nw]) + + # add more flags as you like + WARN_CFLAGS="$WARN_CFLAGS -fdiagnostics-color=always" + if test "$cross_compiling" = yes; then + WARN_CFLAGS="$WARN_CFLAGS -Wno-format" + fi + # WARN_CFLAGS="$WARN_CFLAGS -Werror" + + elif test "$CCNAME" = "clang"; then + # setup flags for this project + WARN_CFLAGS="$WARN_CFLAGS -Wno-system-headers -Wno-vla -Wno-cast-qual -Wno-padded" + WARN_CFLAGS="$WARN_CFLAGS -Wno-reserved-id-macro -Wno-sign-conversion -Wno-disabled-macro-expansion" + WARN_CFLAGS="$WARN_CFLAGS -Wno-documentation -Wno-documentation-unknown-command" + WARN_CFLAGS="$WARN_CFLAGS -Wno-covered-switch-default" + + # remove all flags from WARN_FLAGS that are already in CFLAGS + # wget_WORD_REMOVE([WARN_CFLAGS], [$WARN_CFLAGS], [$CFLAGS]) + fi + + AC_SUBST([WARN_CFLAGS]) +fi + + AC_ARG_WITH([threads], [AS_HELP_STRING([--with-threads=LIB],[choose threading library (posix, w32, auto) [auto]])], [], [with_threads='auto']) diff --git a/m4/wget_manywarnings.m4 b/m4/wget_manywarnings.m4 new file mode 100644 index 00000000..61033282 --- /dev/null +++ b/m4/wget_manywarnings.m4 @@ -0,0 +1,88 @@ +# wget_manywarnings.m4 serial 1 +dnl Copyright (C) 2016 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Tim Ruehsen + +# wget_WORD_SET(RESULT, SET, WORDS) +# -------------------------------------------------- +# Add each word in WORDS to SET if not already there and store in RESULT. +# Words separated by whitespace. +AC_DEFUN([wget_WORD_SET], [ + ret=$2 + words=" $2 " + for word in $3; do + if test "${words#*" $word "}" = "$words"; then ret="$ret $word"; fi + done + $1=$ret +]) + +# wget_WORD_REMOVE(RESULT, SET, WORDS) +# -------------------------------------------------- +# Remove each word in WORDS from SET and store in RESULT. +# Words separated by whitespace. +AC_DEFUN([wget_WORD_REMOVE], [ + ret+ words=" $3 " + for word in $2; do + if test "${words#*" $word "}" = "$words"; then ret="$ret $word"; fi + done + $1=$ret +]) + +# wget_MANYWARNINGS(VARIABLE, LANGUAGE) +# ----------------------------- +# Add LANGUAGE related GCC warnings to VARIABLE. +# This only works for gcc >= 4.3. +AC_DEFUN([wget_MANYWARNINGS], [ + # + # check if manywarnings is requested + # + AC_ARG_ENABLE([manywarnings], + [AS_HELP_STRING([--enable-manywarnings], [Turn on extra compiler warnings (for developers)])], + [case $enableval in + yes|no) ;; + *) AC_MSG_ERROR([Bad value $enableval for --enable-manywarnings option]) ;; + esac + wget_manywarnings=$enableval + ], [ + test -f .manywarnings && wget_manywarnings=yes || wget_manywarnings=no + ] + ) + + $1="" + + if test "$wget_manywarnings" = yes; then + # AC_PROG_CC sets $GCC to 'yes' if compiler is gcc + # AC_REQUIRE([AC_PROG_CC]) + + case $CC in + *gcc*) CCNAME="gcc";; + *clang*) CCNAME="clang";; + esac + + if test "$CCNAME" = "gcc"; then + test -n "$2" && wget_LANGUAGE=$2 || wget_LANGUAGE=C + + # add -Wall -Wextra to reduce number of warn flags + wget_WORD_SET([wget_WARN_CFLAGS], [$CFLAGS], ["-Wall -Wextra -Wformat=2"]) + + # collect all disabled warn flags in $WARN_CFLAGS + wget_WARN_CFLAGS=$wget_WARN_CFLAGS" "$($CC $wget_WARN_CFLAGS -Q --help=warning,$wget_LANGUAGE|\ + awk '{ if (([$]2 == "[[disabled]]" || [$]2 == "") && [$]1!~/=/ && [$]1~/^-W/&& [$]1!="-Wall") print [$]1 }') + + GCC_VERSION=$($CC -dumpversion | cut -f1 -d.) + if test $GCC_VERSION -ge 6; then + wget_WARN_CFLAGS=$wget_WARN_CFLAGS" -Warray-bounds=2 -Wnormalized=nfc -Wshift-overflow=2 -Wunused-const-variable=2" + fi + + elif test "$CCNAME" = "clang"; then + # set all warn flags on + wget_WORD_SET([wget_WARN_CFLAGS], [$CFLAGS], ["-Weverything"]) + fi + + $1=$wget_WARN_CFLAGS + fi +]) diff --git a/src/microhttpd/Makefile.am b/src/microhttpd/Makefile.am index 5ae900ac..b35d0482 100644 --- a/src/microhttpd/Makefile.am +++ b/src/microhttpd/Makefile.am @@ -3,7 +3,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/include \ -I$(top_srcdir)/src/microhttpd -AM_CFLAGS = $(HIDDEN_VISIBILITY_CFLAGS) +AM_CFLAGS = $(HIDDEN_VISIBILITY_CFLAGS) $(WARN_CFLAGS) lib_LTLIBRARIES = \ libmicrohttpd.la -- 2.11.0