forked from the-tcpdump-group/libpcap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_common.sh
More file actions
150 lines (138 loc) · 4.5 KB
/
Copy pathbuild_common.sh
File metadata and controls
150 lines (138 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/sh -e
# The only purpose of the above shebang is to orient shellcheck right.
# 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.
# 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=1 count=4 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}"
# "test -e" would be more appropriate, but it is not available in
# Solaris /bin/sh before 11.
if [ ! -d "$mktempdir_diy_path" ]; then
mkdir "$mktempdir_diy_path"
chmod go= "$mktempdir_diy_path"
echo "$mktempdir_diy_path"
break
fi
# Try again (AIX /dev/urandom returns zeroes quite often).
done
}
mktempdir() {
mktempdir_prefix=${1:-tmp}
# shellcheck disable=SC2006
case `uname -s` in
Darwin|FreeBSD|NetBSD)
# In these operating systems mktemp(1) always appends an implicit
# ".XXXXXXXX" suffix to the requested template when creating a
# temporary directory.
mktemp -d -t "$mktempdir_prefix"
;;
AIX)
mktempdir_diy "$mktempdir_prefix"
;;
SunOS)
# shellcheck disable=SC2006
case `uname -r` in
5.10|5.11)
mktemp -d -t "${mktempdir_prefix}.XXXXXXXX"
;;
*)
mktempdir_diy "$mktempdir_prefix"
;;
esac
;;
*)
# At least 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
}
print_sysinfo() {
uname -a
date
}
print_cc_version() {
# shellcheck disable=SC2006
case `basename "$CC"` in
gcc*|clang*)
# GCC and Clang recognize --version, print to stdout and exit with 0.
"$CC" --version
;;
xl*)
# XL C for AIX recognizes -qversion, prints to stdout and exits with 0,
# but on an unknown command-line flag displays its man page and waits.
"$CC" -qversion
;;
sun*)
# Sun compilers recognize -V, print to stderr and exit with an error.
"$CC" -V 2>&1 || :
;;
*)
"$CC" --version || "$CC" -V || :
;;
esac
}
increment() {
# No arithmetic expansion in Solaris /bin/sh before 11.
echo "${1:?} + 1" | bc
}
# Display text in magenta.
echo_magenta() {
# ANSI magenta, the imploded text, ANSI reset, newline.
printf '\033[35;1m%s\033[0m\n' "$*"
}
# Run a command after displaying it.
run_after_echo() {
: "${1:?}" # Require at least one argument.
printf '$ %s\n' "$*"
"$@"
}
print_so_deps() {
# shellcheck disable=SC2006
case `uname -s` in
Darwin)
run_after_echo otool -L "${1:?}"
;;
*)
run_after_echo ldd "${1:?}"
;;
esac
}
# Beware that setting MATRIX_DEBUG for tcpdump or tcpslice will produce A LOT
# of additional output there and in any nested libpcap builds. Multiplied by
# the matrix size, the full output log size might exceed limits of some CI
# systems (as it had previously happened with Travis CI). Use with caution on
# a reduced matrix.
handle_matrix_debug() {
[ "$MATRIX_DEBUG" != yes ] && return
echo '$ cat Makefile [...]'
sed '/^# DO NOT DELETE THIS LINE -- mkdep uses it.$/q' <Makefile
run_after_echo cat config.h
[ "$CMAKE" = yes ] || run_after_echo cat config.log
}
purge_directory() {
# shellcheck disable=SC2006
if [ "`uname -s`" = SunOS ] && [ "`uname -r`" = 5.11 ]; then
# In Solaris 11 /bin/sh the pathname expansion of "*" always includes
# "." and "..", so the straightforward rm would always fail.
(
cd "${1:?}"
for pd_each in *; do
if [ "$pd_each" != . ] && [ "$pd_each" != .. ]; then
rm -rf "$pd_each"
fi
done
)
else
rm -rf "${1:?}"/*
fi
}
# vi: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent :