]> The Tcpdump Group git mirrors - tcpdump/commitdiff
CI: Refine C compilers handling. [skip appveyor]
authorDenis Ovsienko <[email protected]>
Sun, 25 Jul 2021 22:06:11 +0000 (23:06 +0100)
committerDenis Ovsienko <[email protected]>
Sun, 25 Jul 2021 22:17:36 +0000 (23:17 +0100)
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.

build.sh
build_common.sh

index b5f205890de02ade7264666d6c8e66d4448f316e..d0c9a6941ab007df2b40daa8868c1505f2afbaa1 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -54,22 +54,8 @@ run_after_echo make -s clean
 # again, it will trigger an error.
 # shellcheck disable=SC2006
 case `uname -s` in
 # 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"}
         ;;
 esac
 run_after_echo make -s ${CFLAGS:+CFLAGS="$CFLAGS"}
index 50fcc388534f09314eac086a0e8e0628af283fbf..8edd0b971ea3b71aa9db3d82877d7554e36bf665 100644 (file)
@@ -64,8 +64,10 @@ print_sysinfo() {
     date
 }
 
     date
 }
 
+# Try to make the current C compiler print its version information (usually
+# multi-line) to stdout.
+# shellcheck disable=SC2006
 print_cc_version() {
 print_cc_version() {
-    # shellcheck disable=SC2006
     case `basename "$CC"` in
     gcc*|clang*)
         # GCC and Clang recognize --version, print to stdout and exit with 0.
     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 || :
         ;;
         # 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
 }
 
     *)
         "$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
 increment() {
     # No arithmetic expansion in Solaris /bin/sh before 11.
     echo "${1:?} + 1" | bc