diff --git a/.gitignore b/.gitignore index 65b333a2..41a32eef 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ /config.status /configure /lib/ +!/lib/Makefile.am /maint.mk # Wildcard Ignores *~ diff --git a/bootstrap.conf b/bootstrap.conf index 2182e44a..bd90ecb9 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -18,7 +18,7 @@ # gnulib library name gnulib_name=libgnu -gnulib_tool_option_extras= +gnulib_tool_option_extras="--makefile-name=gnulib.mk" use_libtool=0 checkout_only_file= diff --git a/configure.ac b/configure.ac index 53cf142a..531f0311 100644 --- a/configure.ac +++ b/configure.ac @@ -48,7 +48,7 @@ AC_CONFIG_SRCDIR([src/wget.h]) dnl dnl Automake setup dnl -AM_INIT_AUTOMAKE([1.9]) +AM_INIT_AUTOMAKE([subdir-objects]) dnl dnl Get canonical host @@ -324,6 +324,111 @@ case $host_os in ;; 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 + nw="$nw -Wcast-function-type" # gcc 8, very noisy + nw="$nw -Wabi" # gcc 8, very noisy + nw="$nw -Wunused-macros" # triggers in auto-generated lex css parser, #pragma doesn't work, conflicts with -Werror + 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 + if test $GCC_VERSION -ge 5; then + WARN_CFLAGS="$WARN_CFLAGS -fdiagnostics-color=always" + fi + if test "$cross_compiling" = yes; then + WARN_CFLAGS="$WARN_CFLAGS -Wno-format" + fi + if test $GCC_VERSION -ge 8; then + WARN_CFLAGS="$WARN_CFLAGS -Wno-cast-function-type" + fi + # WARN_CFLAGS="$WARN_CFLAGS -Werror" + + # We use a slightly smaller set of warning options for lib/. + # Remove the following and save the result in GNULIB_WARN_CFLAGS. + # Removing is not enough if these switches are implicitly set by other + # flags like -Wall or -Wextra. We have to explicitly unset them + # with -Wno-.... + nw= + nw="$nw -Wpedantic" + nw="$nw -Wsign-compare" + nw="$nw -Wunused-parameter" + nw="$nw -Wswitch-default" + nw="$nw -Wformat-nonliteral" + nw="$nw -Wsuggest-attribute=pure" + nw="$nw -Wunsafe-loop-optimizations" + nw="$nw -Wundef" + nw="$nw -Wswitch-enum" + nw="$nw -Wbad-function-cast" + nw="$nw -Wredundant-decls" + nw="$nw -Werror" + wget_WORD_REMOVE([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw]) + wget_WORD_REMOVE([CFLAGS], [$CFLAGS], [-Werror]) + + # disable options implicitly set by other options + GNULIB_WARN_CFLAGS="-Wno-error $GNULIB_WARN_CFLAGS" + GNULIB_WARN_CFLAGS="$GNULIB_WARN_CFLAGS -Wno-sign-compare -Wno-unused-parameter -Wno-alloca" + GNULIB_WARN_CFLAGS="$GNULIB_WARN_CFLAGS -Wno-float-conversion -Wno-cast-function-type" + if test "$cross_compiling" = yes; then + GNULIB_WARN_CFLAGS="$GNULIB_WARN_CFLAGS -Wno-incompatible-pointer-types" + fi + + 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 -Wno-unused-macros" + WARN_CFLAGS="$WARN_CFLAGS -Wno-missing-field-initializers" + + # remove all flags from WARN_FLAGS that are already in CFLAGS + # wget_WORD_REMOVE([WARN_CFLAGS], [$WARN_CFLAGS], [$CFLAGS]) + + wget_WORD_REMOVE([CFLAGS], [$CFLAGS], [-Werror]) + + # disable verbose options + GNULIB_WARN_CFLAGS="-Wno-error $GNULIB_WARN_CFLAGS" + GNULIB_WARN_CFLAGS="$WARN_CFLAGS -Wno-sign-compare -Wno-unused-parameter -Wno-undef -Wno-format-nonliteral" + GNULIB_WARN_CFLAGS="$GNULIB_WARN_CFLAGS -Wno-conversion -Wno-disabled-macro-expansion -Wno-c++98-compat" + GNULIB_WARN_CFLAGS="$GNULIB_WARN_CFLAGS -Wno-gnu-statement-expression -Wno-shorten-64-to-32 -Wno-switch-enum" + GNULIB_WARN_CFLAGS="$GNULIB_WARN_CFLAGS -Wno-unused-macros -Wno-missing-field-initializers" + GNULIB_WARN_CFLAGS="$GNULIB_WARN_CFLAGS -Wno-gnu-zero-variadic-macro-arguments -Wno-conditional-uninitialized" + GNULIB_WARN_CFLAGS="$GNULIB_WARN_CFLAGS -Wno-comma -Wno-assign-enum -Wno-unreachable-code -Wno-error" + GNULIB_WARN_CFLAGS="$GNULIB_WARN_CFLAGS -Wno-missing-field-initializers" + + # remove all flags from GNULIB_WARN_FLAGS that are already in CFLAGS + # wget_WORD_REMOVE([GNULIB_WARN_CFLAGS], [$GNULIB_WARN_CFLAGS], [$CFLAGS]) + fi + + AC_SUBST([WARN_CFLAGS]) + AC_SUBST([GNULIB_WARN_CFLAGS]) +fi + dnl dnl Checks for libraries. @@ -845,7 +950,7 @@ AC_MSG_NOTICE([Summary of build options: Host OS: $host_os Install prefix: $prefix Compiler: $CC - CFlags: $CFLAGS $CPPFLAGS + CFlags: $CFLAGS $CPPFLAGS $WARN_CFLAGS LDFlags: $LDFLAGS Libs: $LIBS SSL: $with_ssl diff --git a/lib/Makefile.am b/lib/Makefile.am new file mode 100644 index 00000000..d90142a5 --- /dev/null +++ b/lib/Makefile.am @@ -0,0 +1,13 @@ +MOSTLYCLEANFILES = +noinst_LTLIBRARIES = +EXTRA_DIST = +BUILT_SOURCES = +MOSTLYCLEANDIRS = +CLEANFILES = +SUFFIXES = +noinst_LIBRARIES = +MAINTAINERCLEANFILES = + +AM_CFLAGS = $(GNULIB_WARN_CFLAGS) $(WERROR_CFLAGS) + +include gnulib.mk diff --git a/m4/wget_manywarnings.m4 b/m4/wget_manywarnings.m4 new file mode 100644 index 00000000..d9c81b18 --- /dev/null +++ b/m4/wget_manywarnings.m4 @@ -0,0 +1,92 @@ +# wget_manywarnings.m4 serial 1 +dnl Copyright (C) 2016-2019 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!~/