3 # The only purpose of the above shebang is to orient shellcheck right.
4 # To make CI scripts maintenance simpler, copies of this file in the
5 # libpcap, tcpdump and tcpslice git repositories should be identical.
6 # Please mind that Solaris /bin/sh before 11 does not support the $()
7 # command substitution syntax, hence the SC2006 directives.
9 # A poor man's mktemp(1) for OSes that don't have one (e.g. AIX 7, Solaris 9).
12 # /bin/sh implements $RANDOM in AIX 7, but not in Solaris before 11,
13 # thus use dd and od instead.
14 # shellcheck disable=SC2006
15 mktempdir_diy_suffix
=`dd if=/dev/urandom bs=4 count=1 2>/dev/null | od -t x -A n | head -1 | tr -d '\t '`
16 [ -z "$mktempdir_diy_suffix" ] && return 1
17 mktempdir_diy_path
="${TMPDIR:-/tmp}/${1:?}.${mktempdir_diy_suffix}"
18 # "test -e" would be more appropriate, but it is not available in
19 # Solaris /bin/sh before 11.
20 if [ ! -d "$mktempdir_diy_path" ]; then
21 mkdir
"$mktempdir_diy_path"
22 chmod go
= "$mktempdir_diy_path"
23 echo "$mktempdir_diy_path"
26 # Try again (very unlikely, just in case).
31 mktempdir_prefix
=${1:-tmp}
32 # shellcheck disable=SC2006
34 Darwin-
*|FreeBSD-
*|NetBSD-
*)
35 # In these operating systems mktemp(1) always appends an implicit
36 # ".XXXXXXXX" suffix to the requested template when creating a
37 # temporary directory.
38 mktemp
-d -t "$mktempdir_prefix"
40 SunOS-5.10|SunOS-5.11
)
41 # Although the suffix is optional, specify it for consistent results.
42 mktemp
-d -t "${mktempdir_prefix}.XXXXXXXX"
45 mktempdir_diy
"$mktempdir_prefix"
48 # At least Linux and OpenBSD implementations require explicit trailing
49 # X'es in the template, so make it the same suffix as above.
50 mktemp
-d -t "${mktempdir_prefix}.XXXXXXXX"
57 printf 'OS identification: '
62 # Try to make the current C compiler print its version information (usually
63 # multi-line) to stdout.
64 # shellcheck disable=SC2006
65 cc_version_nocache
() {
67 case `basename "$CC"` in
69 # GCC and Clang recognize --version, print to stdout and exit with 0.
73 # XL C 12.1 and 13.1 recognize "-qversion", print to stdout and exit
74 # with 0. XL C 12.1 on an unknown command-line flag displays its man
76 # XL C 16.1 recognizes "-qversion" and "--version", prints to stdout
77 # and exits with 0. Community Edition also prints a banner to stderr.
78 "$CC" -qversion 2>/dev
/null
81 # Sun compilers recognize -V, print to stderr and exit with an error.
94 Linux-
*|FreeBSD-
*|NetBSD-
*|OpenBSD-
*)
95 # Most likely Clang or GCC.
101 "$CC" --version ||
"$CC" -V ||
:
106 # shellcheck disable=SC2006
108 echo "${cc_version_cached:=`cc_version_nocache`}"
113 printf 'Compiler identification: '
117 # For the current C compiler try to print a short and uniform identification
118 # string (such as "gcc-9.3.0") that is convenient to use in a case statement.
119 # shellcheck disable=SC2006
121 cc_id_firstline
=`cc_version | head -1`
122 : "${cc_id_firstline:?}"
124 cc_id_guessed
=`echo "$cc_id_firstline" | sed 's/^.*clang version \([0-9\.]*\).*$/clang-\1/'`
125 if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then
126 echo "$cc_id_guessed"
130 cc_id_guessed
=`echo "$cc_id_firstline" | sed 's/^IBM XL C.*, V\([0-9\.]*\).*$/xlc-\1/'`
131 if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then
132 echo "$cc_id_guessed"
136 cc_id_guessed
=`echo "$cc_id_firstline" | sed 's/^.* Sun C \([0-9\.]*\) .*$/suncc-\1/'`
137 if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then
138 echo "$cc_id_guessed"
142 cc_id_guessed
=`echo "$cc_id_firstline" | sed 's/^.* (.*) \([0-9\.]*\)$/gcc-\1/'`
143 if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then
144 echo "$cc_id_guessed"
149 # shellcheck disable=SC2006
151 echo "${cc_id_cached:=`cc_id_nocache`}"
154 # Call this function each time CC has changed.
160 # For the current C compiler try to print CFLAGS value that tells to treat
161 # warnings as errors.
162 # shellcheck disable=SC2006
169 # XL C 12.1 and 13.1 recognize "-qhalt=w". XL C 16.1 recognizes that
179 # Tell whether "gcc" is a symlink to Clang (this is the case on macOS).
180 # shellcheck disable=SC2006
181 gcc_is_clang_in_disguise
() {
182 case `cc_id`/`basename "${CC:?}"` in
190 # shellcheck disable=SC2006
192 # OS does not change between builds or in the middle of a build, so it is
193 # fine to cache uname output.
194 : "${os_id_sysname:=`uname -s`}"
195 printf '%s-' "$os_id_sysname"
196 : "${os_id_release:=`uname -r`}"
197 case "$os_id_sysname" in
199 : "${os_id_version:=`uname -v`}"
200 echo "${os_id_version}.${os_id_release}"
202 Darwin|NetBSD|OpenBSD|SunOS
)
203 echo "$os_id_release"
206 # Meaningful version is usually the substring before the first dash.
207 echo "$os_id_release" |
sed 's/^\([0-9\.]*\).*$/\1/'
216 # No arithmetic expansion in Solaris /bin/sh before 11.
217 echo "${1:?} + 1" |
bc
220 # Display text in magenta.
222 # ANSI magenta, the imploded text, ANSI reset, newline.
223 printf '\033[35;1m%s\033[0m\n' "$*"
226 # Run a command after displaying it.
228 : "${1:?}" # Require at least one argument.
234 # shellcheck disable=SC2006
237 run_after_echo otool
-L "${1:?}"
240 run_after_echo ldd
"${1:?}"
245 # Beware that setting MATRIX_DEBUG for tcpdump or tcpslice will produce A LOT
246 # of additional output there and in any nested libpcap builds. Multiplied by
247 # the matrix size, the full output log size might exceed limits of some CI
248 # systems (as it had previously happened with Travis CI). Use with caution on
250 handle_matrix_debug
() {
251 [ "$MATRIX_DEBUG" != yes ] && return
252 echo '$ cat Makefile [...]'
253 sed '/^# DO NOT DELETE THIS LINE -- mkdep uses it.$/q' <Makefile
254 run_after_echo
cat config.h
255 [ "$CMAKE" = yes ] || run_after_echo
cat config.log
259 # shellcheck disable=SC2006
260 if [ "`os_id`" = SunOS-5.11
]; then
261 # In Solaris 11 /bin/sh the pathname expansion of "*" always includes
262 # "." and "..", so the straightforward rm would always fail.
266 if [ "$pd_each" != .
] && [ "$pd_each" != ..
]; then
276 # vi: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent :