]> The Tcpdump Group git mirrors - tcpdump/blobdiff - build_common.sh
gre: add support for MikroTik Ethernet-over-IP hack.
[tcpdump] / build_common.sh
index 21d62b835dd8bdf2d8f0e22c70087481f9512219..3264d2e9dc3a18dee46d10d61bd04123db83ab07 100644 (file)
@@ -4,14 +4,13 @@
 # To make CI scripts maintenance simpler, copies of this file in the
 # libpcap, tcpdump and tcpslice git repositories should be identical.
 # Please mind that Solaris /bin/sh before 11 does not support the $()
-# command substitution syntax, hence the SC2006 directives.
+# command substitution syntax, hence the "-e SC2006" flag in Makefile.
 
 # A poor man's mktemp(1) for OSes that don't have one (e.g. AIX 7, Solaris 9).
 mktempdir_diy() {
     while true; do
         # /bin/sh implements $RANDOM in AIX 7, but not in Solaris before 11,
         # thus use dd and od instead.
-        # shellcheck disable=SC2006
         mktempdir_diy_suffix=`dd if=/dev/urandom bs=4 count=1 2>/dev/null | od -t x -A n | head -1 | tr -d '\t '`
         [ -z "$mktempdir_diy_suffix" ] && return 1
         mktempdir_diy_path="${TMPDIR:-/tmp}/${1:?}.${mktempdir_diy_suffix}"
@@ -29,7 +28,6 @@ mktempdir_diy() {
 
 mktempdir() {
     mktempdir_prefix=${1:-tmp}
-    # shellcheck disable=SC2006
     case `os_id` in
     Darwin-*|FreeBSD-*|NetBSD-*)
         # In these operating systems mktemp(1) always appends an implicit
@@ -45,8 +43,8 @@ mktempdir() {
         mktempdir_diy "$mktempdir_prefix"
         ;;
     *)
-        # At least Linux and OpenBSD implementations require explicit trailing
-        # X'es in the template, so make it the same suffix as above.
+        # At least Haiku, Linux and OpenBSD implementations require explicit
+        # trailing X'es in the template, so make it the same suffix as above.
         mktemp -d -t "${mktempdir_prefix}.XXXXXXXX"
         ;;
     esac
@@ -61,7 +59,6 @@ print_sysinfo() {
 
 # Try to make the current C compiler print its version information (usually
 # multi-line) to stdout.
-# shellcheck disable=SC2006
 cc_version_nocache() {
     : "${CC:?}"
     case `basename "$CC"` in
@@ -103,7 +100,6 @@ cc_version_nocache() {
     esac
 }
 
-# shellcheck disable=SC2006
 cc_version() {
     echo "${cc_version_cached:=`cc_version_nocache`}"
 }
@@ -116,7 +112,6 @@ print_cc_version() {
 
 # 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_nocache() {
     cc_id_firstline=`cc_version | head -1`
     : "${cc_id_firstline:?}"
@@ -139,14 +134,28 @@ cc_id_nocache() {
         return
     fi
 
-    cc_id_guessed=`echo "$cc_id_firstline" | sed 's/^.* (.*) \([0-9\.]*\)$/gcc-\1/'`
+    # OpenBSD default GCC:
+    # "gcc (GCC) 4.2.1 20070719"
+    # RedHat GCC:
+    # "gcc (GCC) 8.3.1 20190223 (Red Hat 8.3.1-2)"
+    # "gcc (GCC) 10.3.1 20210422 (Red Hat 10.3.1-1)"
+    # other GCC packages:
+    # "sparc-sun-solaris2.9-gcc (GCC) 4.2.0 (gccfss)"
+    # "gcc (GCC) 5.5.0"
+    # "gcc (nb4 20200810) 7.5.0"
+    # "gcc (OpenIndiana 7.5.0-il-0) 7.5.0"
+    # "gcc (Debian 8.3.0-6) 8.3.0"
+    # "gcc (Raspbian 8.3.0-6+rpi1) 8.3.0"
+    # "egcc (GCC) 8.4.0"
+    # "gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0"
+    # "gcc (FreeBSD Ports Collection) 10.3.0"
+    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
 }
 
-# shellcheck disable=SC2006
 cc_id() {
     echo "${cc_id_cached:=`cc_id_nocache`}"
 }
@@ -159,7 +168,6 @@ discard_cc_cache() {
 
 # 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-*)
@@ -177,7 +185,6 @@ cc_werr_cflags() {
 }
 
 # Tell whether "gcc" is a symlink to Clang (this is the case on macOS).
-# shellcheck disable=SC2006
 gcc_is_clang_in_disguise() {
     case `cc_id`/`basename "${CC:?}"` in
     clang-*/gcc)
@@ -187,7 +194,6 @@ gcc_is_clang_in_disguise() {
     return 1
 }
 
-# shellcheck disable=SC2006
 os_id() {
     # OS does not change between builds or in the middle of a build, so it is
     # fine to cache uname output.
@@ -206,6 +212,14 @@ os_id() {
         # Meaningful version is usually the substring before the first dash.
         echo "$os_id_release" | sed 's/^\([0-9\.]*\).*$/\1/'
         ;;
+    Haiku)
+        # Meaningful version is the substring before the plus sign.
+        # "hrev56578" stands for "R1/beta4".
+        # "hrev55181" stands for "R1/beta3".
+        # "hrev54154" stands for "R1/beta2".
+        : "${os_id_version:=`uname -v`}"
+        echo "$os_id_version" | sed 's/^\(hrev.*\)+.*$/\1/'
+        ;;
     *)
         echo 'UNKNOWN'
         ;;
@@ -231,11 +245,13 @@ run_after_echo() {
 }
 
 print_so_deps() {
-    # shellcheck disable=SC2006
     case `os_id` in
     Darwin-*)
         run_after_echo otool -L "${1:?}"
         ;;
+    Haiku-*)
+        run_after_echo objdump -p "${1:?}"
+        ;;
     *)
         run_after_echo ldd "${1:?}"
         ;;
@@ -256,7 +272,6 @@ handle_matrix_debug() {
 }
 
 purge_directory() {
-    # shellcheck disable=SC2006
     if [ "`os_id`" = SunOS-5.11 ]; then
         # In Solaris 11 /bin/sh the pathname expansion of "*" always includes
         # "." and "..", so the straightforward rm would always fail.