X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/7c6a734dff3d95d0ed761be5634e65d25bd9b317..refs/heads/master:/build_common.sh diff --git a/build_common.sh b/build_common.sh index 02776148..ce9349ed 100644 --- a/build_common.sh +++ b/build_common.sh @@ -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,9 @@ 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. + # XXX - is MSYS2 GNU-based, so that it would be like Linux? mktemp -d -t "${mktempdir_prefix}.XXXXXXXX" ;; esac @@ -61,11 +60,10 @@ 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 - gcc*|egcc*|clang*) + gcc*|egcc*|clang*|tcc*) # GCC and Clang recognize --version, print to stdout and exit with 0. "$CC" --version ;; @@ -97,13 +95,22 @@ cc_version_nocache() { ;; esac ;; + cl) + # Visual Studio's compiler doesn't have a "print the compiler + # version" option, but we can get version information by + # running it with no options, sending its standard error to + # the standard output, and throwing out the usage message; + # as we have MSYS2, we can just "head" it out. + # + # XXX - does it exit with an error? + "$CC" 2>&1 | head -2 + ;; *) "$CC" --version || "$CC" -V || : ;; esac } -# shellcheck disable=SC2006 cc_version() { echo "${cc_version_cached:=`cc_version_nocache`}" } @@ -116,7 +123,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,6 +145,23 @@ cc_id_nocache() { return fi + cc_id_guessed=`echo "$cc_id_firstline" | sed 's/^Microsoft (R) C\/C++ Optimizing Compiler Version \([0-9\.]*\) .*$/msvc-\1/'` + if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then + echo "$cc_id_guessed" + return + fi + + # Examples of installed packages: + # "tcc version 0.9.27 (x86_64 Linux)" + # "tcc version 0.9.27 2023-07-05 mob@5b28165 (x86_64 OpenBSD)" + # Example of a development version: + # "tcc version 0.9.28rc 2024-04-28 mob@0aca8611 (x86_64 Linux)" + cc_id_guessed=`echo "$cc_id_firstline" | sed 's/^.*tcc version \([0-9\.rc]*\).*$/tcc-\1/'` + if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then + echo "$cc_id_guessed" + return + fi + # OpenBSD default GCC: # "gcc (GCC) 4.2.1 20070719" # RedHat GCC: @@ -161,7 +184,6 @@ cc_id_nocache() { fi } -# shellcheck disable=SC2006 cc_id() { echo "${cc_id_cached:=`cc_id_nocache`}" } @@ -174,10 +196,9 @@ 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-*) + gcc-*|clang-*|tcc-*) echo '-Werror' ;; xlc-*) @@ -186,13 +207,19 @@ cc_werr_cflags() { echo '-qhalt=w' ;; suncc-*) - echo '-errwarn=%all' + # GCC and Clang print an identification for every warning, which is + # useful for root cause analysis and bug fixing. Sun C does not do it + # by default, but an additional option makes the style more consistent. + echo '-errwarn=%all -errtags=yes' + ;; + msvc-*) + # XXX - what? + echo '' ;; esac } # 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) @@ -202,7 +229,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. @@ -214,13 +240,35 @@ os_id() { : "${os_id_version:=`uname -v`}" echo "${os_id_version}.${os_id_release}" ;; - Darwin|NetBSD|OpenBSD|SunOS) + Darwin|GNU|OpenBSD|SunOS) echo "$os_id_release" ;; - FreeBSD|Linux) + FreeBSD|NetBSD|Linux) # Meaningful version is usually the substring before the first dash. + # Or the first underscore. echo "$os_id_release" | sed 's/^\([0-9\.]*\).*$/\1/' ;; + Haiku) + # The complete version is a substring before the first space, e.g.: + # * "hrevNNNNN" for a release without updates, e.g. hrev56578 for + # R1/beta4, also for a clean build of master branch; + # * "hrevNNNNN+MM" for a release with updates; + # * "hrevNNNNN-MM" for a build of a branch that is ahead of the master + # branch; + # * "hrevNNNNN_MMMM_KK" for a CI build of a Gerrit review; + # * something else for a build of a working copy with the changes not + # yet committed. + # With this system it is not clear which version components would be + # meaningful to relate with the build result, so let's return the + # complete version and leave any interpretation to the user. + : "${os_id_version:=`uname -v`}" + echo "$os_id_version" | sed -E 's/^(hrev[^ ]+).+$/\1/' + ;; + MSYS*) + # uname -s produces "MSYS_NT-{NT version?}-{build?} + # uname -r produces MSYS2 version? + echo "$os_id_version", MSYS "$os_id_release" + ;; *) echo 'UNKNOWN' ;; @@ -229,7 +277,8 @@ os_id() { increment() { # No arithmetic expansion in Solaris /bin/sh before 11. - echo "${1:?} + 1" | bc + # shellcheck disable=SC2003 + expr "${1:?}" + 1 } # Display text in magenta. @@ -246,11 +295,16 @@ 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:?}" + ;; + MSYS*) + run_after_echo dumpbin /dependents "${1:?}" + ;; *) run_after_echo ldd "${1:?}" ;; @@ -271,7 +325,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.