]>
The Tcpdump Group git mirrors - tcpdump/blob - build_common.sh
50fcc388534f09314eac086a0e8e0628af283fbf
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"
68 # shellcheck disable=SC2006
69 case `basename "$CC"` in
71 # GCC and Clang recognize --version, print to stdout and exit with 0.
75 # XL C for AIX recognizes -qversion, prints to stdout and exits with 0,
76 # but on an unknown command-line flag displays its man page and waits.
80 # Sun compilers recognize -V, print to stderr and exit with an error.
84 "$CC" --version ||
"$CC" -V ||
:
90 # No arithmetic expansion in Solaris /bin/sh before 11.
91 echo "${1:?} + 1" |
bc
94 # Display text in magenta.
96 # ANSI magenta, the imploded text, ANSI reset, newline.
97 printf '\033[35;1m%s\033[0m\n' "$*"
100 # Run a command after displaying it.
102 : "${1:?}" # Require at least one argument.
108 # shellcheck disable=SC2006
111 run_after_echo otool
-L "${1:?}"
114 run_after_echo ldd
"${1:?}"
119 # Beware that setting MATRIX_DEBUG for tcpdump or tcpslice will produce A LOT
120 # of additional output there and in any nested libpcap builds. Multiplied by
121 # the matrix size, the full output log size might exceed limits of some CI
122 # systems (as it had previously happened with Travis CI). Use with caution on
124 handle_matrix_debug
() {
125 [ "$MATRIX_DEBUG" != yes ] && return
126 echo '$ cat Makefile [...]'
127 sed '/^# DO NOT DELETE THIS LINE -- mkdep uses it.$/q' <Makefile
128 run_after_echo
cat config.h
129 [ "$CMAKE" = yes ] || run_after_echo
cat config.log
133 # shellcheck disable=SC2006
134 if [ "`uname -s`" = SunOS
] && [ "`uname -r`" = 5.11 ]; then
135 # In Solaris 11 /bin/sh the pathname expansion of "*" always includes
136 # "." and "..", so the straightforward rm would always fail.
140 if [ "$pd_each" != .
] && [ "$pd_each" != ..
]; then
150 # vi: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent :