forked from iputils/iputils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·234 lines (185 loc) · 4.46 KB
/
build.sh
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/bin/sh -eux
# Copyright (c) 2019-2024 Petr Vorel <[email protected]>
CFLAGS="${CFLAGS:--Wformat -Werror=format-security -Werror=implicit-function-declaration -Werror=return-type -fno-common}"
CC="${CC:-gcc}"
BUILD_DIR="${BUILD_DIR:-builddir}"
PREFIX="${PREFIX:-$HOME/iputils-install}"
[ -z "${EXTRA_BUILD_OPTS:-}" ] && EXTRA_BUILD_OPTS="-DBUILD_HTML_MANS=true"
BUILD_OPTS="-Dprefix=$PREFIX $EXTRA_BUILD_OPTS"
[ -f "meson.cross" ] && BUILD_OPTS="--cross-file $PWD/meson.cross $BUILD_OPTS"
BINARIES='arping clockdiff ping/ping tracepath'
# NOTE: meson iself checkes for minimal version
# see meson_version in meson.build, it fails if not required
# Meson version is 0.37.1 but project requires >=0.40.
check_build_dependencies()
{
# ninja-build is not detected causes build failing => symlink to ninja
# needed for CentOS 7 but maybe for others
if ! command -v ninja > /dev/null; then
if command -v ninja-build > /dev/null; then
ln -sv $(command -v ninja-build) /usr/local/bin/ninja
else
echo "ninja binary not found (tried ninja and $NINJA on $PATH)" >&2
exit 1
fi
fi
command -v meson > /dev/null 2>&1 || { echo "meson binary not found" >&2; exit 1; }
}
print_versions()
{
echo "=== compiler version ==="
$CC --version
echo "=== meson version ==="
meson --version
echo "=== ninja version ==="
ninja --version
}
configure_32()
{
echo "=== configure_32 ==="
local arch="$(uname -m)"
local dir
CFLAGS="-m32 $CFLAGS"
if [ -z "${PKG_CONFIG_LIBDIR:-}" ]; then
if [ "$arch" != "x86_64" ]; then
echo "ERROR: auto-detection not supported platform $arch, export PKG_CONFIG_LIBDIR!"
exit 1
fi
for dir in /usr/lib/i386-linux-gnu/pkgconfig \
/usr/lib32/pkgconfig /usr/lib/pkgconfig; do
if [ -d "$dir" ]; then
PKG_CONFIG_LIBDIR="$dir"
break
fi
done
if [ -z "$PKG_CONFIG_LIBDIR" ]; then
echo "WARNING: PKG_CONFIG_LIBDIR not found, build might fail"
fi
export PKG_CONFIG_LIBDIR
fi
}
configure()
{
if [ "${BUILD_32:-}" ]; then
configure_32
fi
echo "=== configure ==="
echo "Build options: $BUILD_OPTS"
echo "CFLAGS: $CFLAGS"
export CFLAGS
meson setup $BUILD_DIR $BUILD_OPTS
}
build()
{
echo "=== build ==="
make -j$(getconf _NPROCESSORS_ONLN)
}
check_binaries()
{
echo "=== check_binaries ==="
local arch i
local bits="64"
case "${ARCH:-}" in
'') arch='x86-64';;
arm64) arch='aarch64';;
ppc64el) arch='PowerPC';;
s390x) arch='S/390';;
esac
if [ "${BUILD_32:-}" ]; then
bits=32
arch='80386'
fi
for i in $BINARIES; do
if echo "$EXTRA_BUILD_OPTS" | grep -i -q -- "-DBUILD_${i}=false"; then
echo "$i should not be build"
[ ! -x "$BUILD_DIR/$i" ]
continue
fi
[ -x "$BUILD_DIR/$i" ]
file "$BUILD_DIR/$i" | grep -E "$i.*${bits}-bit .*(executable|shared object).*$arch.*dynamically linked"
done
}
install()
{
echo "=== install ==="
make install
}
dist()
{
local formats="xztar,gztar,zip"
local tag="$(date +%Y%m%d)"
local f
echo "=== dist ($formats) ==="
meson dist -C $BUILD_DIR --formats $formats
for f in $(echo "$formats" | sed 's/,/ /g'); do
f=$(echo "$f" | sed 's/\(.*\)tar/tar.\1/')
f=$BUILD_DIR/meson-dist/iputils-$tag.$f
ls -lah $f
file $f | grep -E '(compressed|archive) data'
done
}
run_tests()
{
local ret
echo "=== tests ==="
cd $BUILD_DIR
meson test
ret=$?
echo "$ret test failures"
cd - > /dev/null
exit $ret
}
print_log()
{
local log="$BUILD_DIR/meson-logs/$1"
if [ ! -f "$log" ]; then
echo "'$log' is missing"
return
fi
echo "=== START $log ==="
cat $log
echo "=== END $log ==="
}
cd `dirname $0`
cmd=
case "${1:-}" in
build|build-log|check-binaries|configure|dependencies|dist|info|install|install-log|test|test-log|"") cmd="${1:-}";;
*) echo "ERROR: wrong command '$1'" >&2; exit 1;;
esac
if [ -z "$cmd" -o "$cmd" = "dependencies" ]; then
check_build_dependencies
fi
if [ -z "$cmd" -o "$cmd" = "info" ]; then
print_versions
fi
if [ -z "$cmd" -o "$cmd" = "configure" ]; then
configure
fi
if [ -z "$cmd" -o "$cmd" = "build" ]; then
build
fi
if [ -z "$cmd" -o "$cmd" = "check-binaries" ]; then
check_binaries
fi
if [ "$cmd" = "build-log" ]; then
print_log meson-log.txt
fi
if [ -z "$cmd" -o "$cmd" = "install" ]; then
install
fi
if [ -z "$cmd" -o "$cmd" = "dist" ]; then
dist
fi
if [ "$cmd" = "install-log" ]; then
print_log install-log.txt
fi
if [ -z "$cmd" -o "$cmd" = "test" ]; then
if [ -f "meson.cross" ]; then
echo "INFO: cross-compile build, skipping running tests" >&2
else
run_tests
fi
fi
if [ "$cmd" = "test-log" ]; then
print_log testlog.txt
fi