diff options
author | Denis Ovsienko <denis@ovsienko.info> | 2021-07-25 23:06:11 +0100 |
---|---|---|
committer | Denis Ovsienko <denis@ovsienko.info> | 2021-07-25 23:17:36 +0100 |
commit | cdc3bc2359dc214dfedf5fc5dec4712058af7d33 (patch) | |
tree | a4827bc8f06c4c2ca47fb60427a9a019bc957dcb | |
parent | fbd44158e0d5e6bb0c9b05671f702ebcf68cc56d (diff) | |
download | tcpdump-cdc3bc2359dc214dfedf5fc5dec4712058af7d33.tar.gz |
CI: Refine C compilers handling. [skip appveyor]
In build_common.sh add minimal heuristics to print_cc_version() to help
it run the right command; add cc_id() and cc_werr_cflags() to pick the
right CFLAGS for the current compiler instead of the previously
hard-coded "-Werror". Add some comments.
In build.sh remove the CFLAGS exemptions for AIX and Solaris 9 builds,
which are in a better shape now and can complete specific subsets of the
full matrix without a warning. Set CFLAGS from cc_werr_cflags() to make
the best effort to catch as many warnings as possible. Let's see how well
that works.
-rwxr-xr-x | build.sh | 16 | ||||
-rw-r--r-- | build_common.sh | 68 |
2 files changed, 68 insertions, 16 deletions
@@ -54,22 +54,8 @@ run_after_echo make -s clean # again, it will trigger an error. # shellcheck disable=SC2006 case `uname -s` in - AIX) - CFLAGS= - ;; - SunOS) - # shellcheck disable=SC2006 - case `uname -r` in - 5.10|5.11) - CFLAGS=-Werror - ;; - *) - CFLAGS= - ;; - esac - ;; *) - CFLAGS=-Werror + CFLAGS=`cc_werr_cflags` ;; esac run_after_echo make -s ${CFLAGS:+CFLAGS="$CFLAGS"} diff --git a/build_common.sh b/build_common.sh index 50fcc388..8edd0b97 100644 --- a/build_common.sh +++ b/build_common.sh @@ -64,8 +64,10 @@ print_sysinfo() { date } +# Try to make the current C compiler print its version information (usually +# multi-line) to stdout. +# shellcheck disable=SC2006 print_cc_version() { - # shellcheck disable=SC2006 case `basename "$CC"` in gcc*|clang*) # GCC and Clang recognize --version, print to stdout and exit with 0. @@ -80,12 +82,76 @@ print_cc_version() { # Sun compilers recognize -V, print to stderr and exit with an error. "$CC" -V 2>&1 || : ;; + cc) + case `uname -s` in + SunOS) + # Most likely Sun C. + "$CC" -V 2>&1 || : + ;; + Darwin) + # Most likely Clang. + "$CC" --version + ;; + Linux|FreeBSD|NetBSD|OpenBSD) + # Most likely Clang or GCC. + "$CC" --version + ;; + esac + ;; *) "$CC" --version || "$CC" -V || : ;; esac } +# For the current C compiler try to print a short and uniform identification +# string (such as "gcc-9.3.0") that is convenient to use in a case statement. +# shellcheck disable=SC2006 +cc_id() { + cc_id_firstline=`print_cc_version | head -1` + + cc_id_guessed=`echo "$cc_id_firstline" | sed 's/^.*clang version \([0-9\.]*\).*$/clang-\1/'` + if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then + echo "$cc_id_guessed" + return + fi + + cc_id_guessed=`echo "$cc_id_firstline" | sed 's/^IBM XL C.* for AIX, V\([0-9\.]*\).*$/xlc-\1/'` + if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then + echo "$cc_id_guessed" + return + fi + + cc_id_guessed=`echo "$cc_id_firstline" | sed 's/^.* Sun C \([0-9\.]*\) .*$/suncc-\1/'` + if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then + echo "$cc_id_guessed" + return + fi + + cc_id_guessed=`echo "$cc_id_firstline" | sed 's/^.* (.*) \([0-9\.]*\)$/gcc-\1/'` + if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then + echo "$cc_id_guessed" + return + fi +} + +# For the current C compiler try to print CFLAGS value that tells to treat +# warnings as errors. +# shellcheck disable=SC2006 +cc_werr_cflags() { + case `cc_id` in + gcc-*|clang-*) + echo '-Werror' + ;; + xlc-*) + echo '-qhalt=w' + ;; + suncc-*) + echo '-errwarn=%all' + ;; + esac +} + increment() { # No arithmetic expansion in Solaris /bin/sh before 11. echo "${1:?} + 1" | bc |