-
Notifications
You must be signed in to change notification settings - Fork 20
/
check_buildflags.sh
executable file
·140 lines (120 loc) · 2.95 KB
/
check_buildflags.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
#!/usr/bin/env bash
#
# Ensure that configure enabled the plugouts as it was expected to.
#
# 2020-2021 (C) by Christian Garbs <[email protected]>
# Licensed under GNU GPL v1 or, at your option, any later version.
set -e
die()
{
echo "ERROR"
echo "$@"
echo
echo "dumping config.mk:"
cat config.mk
exit 1
}
key_contains()
{
local key="$1" searched="$2"
local -a values
read -a values -r < <(grep "^$key := " config.mk)
local value
# :2 skips the first two array entries ($key and ":=")
for value in "${values[@]:2}"; do
if [ "$value" = "$searched" ]; then
return 0
fi
done
return 1
}
expect_to_contain()
{
local key="$1" expected="$2"
printf 'check <%s> to contain <%s> .. ' "$key" "$expected"
if ! key_contains "$key" "$expected"; then
die "expected value <$expected> not found in key <$key>"
fi
echo "ok"
}
expect_to_not_contain()
{
local key="$1" unexpected="$2"
printf 'check <%s> to not contain <%s> .. ' "$key" "$unexpected"
if key_contains "$key" "$unexpected"; then
die "unexpected value <$unexpected> found in key <$key>"
fi
echo "ok"
}
# default configuration when all dependencies are available
i18n=yes
zlib=yes
harden=yes
sharedlib=no
verbosebuild=no
xgbsplay=no
prefix=/usr/local
# parse build configuration
for flag in "$@"; do
case "$flag" in
"")
;;
--disable-i18n)
i18n=no
;;
--disable-zlib)
zlib=no
;;
--disable-hardening)
harden=no
;;
--enable-sharedlibgbs)
sharedlib=yes
;;
--enable-verbosebuild)
verbosebuild=yes
;;
--with-xgbsplay)
xgbsplay=yes
;;
--prefix=*)
prefix="${flag#--prefix=}"
;;
*)
die "unhandled flag <$flag>"
;;
esac
done
# dump status
echo "expected configuration: i18n=$i18n zlib=$zlib harden=$harden sharedlib=$sharedlib"
echo "checking config.mk"
# test configuration
expect_to_contain use_i18n "$i18n"
if [ "$zlib" = yes ]; then
expect_to_contain EXTRA_LDFLAGS "-lz"
else
expect_to_not_contain EXTRA_LDFLAGS "-lz"
fi
if [ "$harden" = yes ]; then
expect_to_contain EXTRA_CFLAGS "-fstack-protector-strong"
expect_to_contain EXTRA_LDFLAGS "-fstack-protector-strong"
else
expect_to_not_contain EXTRA_CFLAGS "-fstack-protector"
expect_to_not_contain EXTRA_CFLAGS "-fstack-protector-strong"
expect_to_not_contain EXTRA_CFLAGS "-fstack-clash-protection"
expect_to_not_contain EXTRA_LDFLAGS "-fstack-protector"
expect_to_not_contain EXTRA_LDFLAGS "-fstack-protector-strong"
expect_to_not_contain EXTRA_LDFLAGS "-fstack-clash-protection"
fi
expect_to_contain use_sharedlibgbs "$sharedlib"
expect_to_contain use_verbosebuild "$verbosebuild"
if [ "$xgbsplay" = yes ]; then
expect_to_contain EXTRA_INSTALL "xgbsplay"
expect_to_contain EXTRA_UNINSTALL "xgbsplay"
else
expect_to_not_contain EXTRA_INSTALL "xgbsplay"
expect_to_not_contain EXTRA_UNINSTALL "xgbsplay"
fi
expect_to_contain prefix "$prefix"
# ok
echo "ok"