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=1 count=4 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 (AIX /dev/urandom returns zeroes quite often).
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"
41 mktempdir_diy
"$mktempdir_prefix"
44 # shellcheck disable=SC2006
47 mktemp
-d -t "${mktempdir_prefix}.XXXXXXXX"
50 mktempdir_diy
"$mktempdir_prefix"
55 # At least Linux and OpenBSD implementations require explicit trailing
56 # X'es in the template, so make it the same suffix as above.
57 mktemp
-d -t "${mktempdir_prefix}.XXXXXXXX"
67 # Try to make the current C compiler print its version information (usually
68 # multi-line) to stdout.
69 # shellcheck disable=SC2006
71 case `basename "$CC"` in
73 # GCC and Clang recognize --version, print to stdout and exit with 0.
77 # XL C for AIX recognizes -qversion, prints to stdout and exits with 0,
78 # but on an unknown command-line flag displays its man page and waits.
82 # Sun compilers recognize -V, print to stderr and exit with an error.
95 Linux|FreeBSD|NetBSD|OpenBSD
)
96 # Most likely Clang or GCC.
102 "$CC" --version ||
"$CC" -V ||
:
107 # For the current C compiler try to print a short and uniform identification
108 # string (such as "gcc-9.3.0") that is convenient to use in a case statement.
109 # shellcheck disable=SC2006
111 cc_id_firstline
=`print_cc_version | head -1`
113 cc_id_guessed
=`echo "$cc_id_firstline" | sed 's/^.*clang version \([0-9\.]*\).*$/clang-\1/'`
114 if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then
115 echo "$cc_id_guessed"
119 cc_id_guessed
=`echo "$cc_id_firstline" | sed 's/^IBM XL C.* for AIX, V\([0-9\.]*\).*$/xlc-\1/'`
120 if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then
121 echo "$cc_id_guessed"
125 cc_id_guessed
=`echo "$cc_id_firstline" | sed 's/^.* Sun C \([0-9\.]*\) .*$/suncc-\1/'`
126 if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then
127 echo "$cc_id_guessed"
131 cc_id_guessed
=`echo "$cc_id_firstline" | sed 's/^.* (.*) \([0-9\.]*\)$/gcc-\1/'`
132 if [ "$cc_id_firstline" != "$cc_id_guessed" ]; then
133 echo "$cc_id_guessed"
138 # For the current C compiler try to print CFLAGS value that tells to treat
139 # warnings as errors.
140 # shellcheck disable=SC2006
156 # No arithmetic expansion in Solaris /bin/sh before 11.
157 echo "${1:?} + 1" |
bc
160 # Display text in magenta.
162 # ANSI magenta, the imploded text, ANSI reset, newline.
163 printf '\033[35;1m%s\033[0m\n' "$*"
166 # Run a command after displaying it.
168 : "${1:?}" # Require at least one argument.
174 # shellcheck disable=SC2006
177 run_after_echo otool
-L "${1:?}"
180 run_after_echo ldd
"${1:?}"
185 # Beware that setting MATRIX_DEBUG for tcpdump or tcpslice will produce A LOT
186 # of additional output there and in any nested libpcap builds. Multiplied by
187 # the matrix size, the full output log size might exceed limits of some CI
188 # systems (as it had previously happened with Travis CI). Use with caution on
190 handle_matrix_debug
() {
191 [ "$MATRIX_DEBUG" != yes ] && return
192 echo '$ cat Makefile [...]'
193 sed '/^# DO NOT DELETE THIS LINE -- mkdep uses it.$/q' <Makefile
194 run_after_echo
cat config.h
195 [ "$CMAKE" = yes ] || run_after_echo
cat config.log
199 # shellcheck disable=SC2006
200 if [ "`uname -s`" = SunOS
] && [ "`uname -r`" = 5.11 ]; then
201 # In Solaris 11 /bin/sh the pathname expansion of "*" always includes
202 # "." and "..", so the straightforward rm would always fail.
206 if [ "$pd_each" != .
] && [ "$pd_each" != ..
]; then
216 # vi: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent :