-
Notifications
You must be signed in to change notification settings - Fork 3
/
make-config.sh
executable file
·151 lines (127 loc) · 3.93 KB
/
make-config.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
#!/bin/bash
# Copyright © 2018 ANSSI. All rights reserved.
# Distributed under the terms of the GNU General Public License v2
set -e -u -o pipefail
readonly SELFNAME="${BASH_SOURCE[0]##*/}"
readonly SELFPATH="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
_version_less_or_equal() {
gawk -f "$SELFPATH"/version_compare.awk -v A="$1" -v B="$2" <&-
test $? "-ne" 1
}
MINICONFIG_CAT=""
MINICONFIG_SORT=""
# initial miniconfig idea from Rob Landley and Piotr Karbowski (foo-miniconfig)
generate_config() {
local config configset subconfigset config_suffix err_msg
local missing=()
local unwanted=()
local gcc=false
MINICONFIG_CAT="$(mktemp)"
MINICONFIG_SORT="$(mktemp)"
config_suffix="$(sed -n -e 's/^VERSION *= *\([0-9]\+\)/\1/p' "${S}/Makefile")"
config_suffix+=".$(sed -n -e 's/^PATCHLEVEL *= *\([0-9]\+\)/\1/p' "${S}/Makefile")"
echo "[*] Kernel configuration set:"
for configset in "$@"; do
if [[ -f "${CONFIGDIR}/kernel_config/${configset}" ]]; then
echo "[*] ${configset}"
cat "${CONFIGDIR}/kernel_config/${configset}" >> "${MINICONFIG_CAT}"
for subconfigset in $(ls ${CONFIGDIR}/kernel_config/${configset}-* 2>/dev/null); do
# FIXME: removal of a config option in a new kernel version
# is not handled. Theoretically an option removed from Kconfig
# should have no impact anymore in the source code, but we
# still might want to disable an option starting from a certain
# kernel version (e.g. disable buggy option for kernels newer
# than 4.x).
subconfigset="${subconfigset##${CONFIGDIR}/kernel_config/}"
if _version_less_or_equal "${subconfigset##*-}" "${config_suffix}"; then
echo "[*] ${subconfigset}"
cat "${CONFIGDIR}/kernel_config/${subconfigset}" \
>> "${MINICONFIG_CAT}"
fi
done
else
die "There is no ${configset} configuration set"
fi
done
sort -u "${MINICONFIG_CAT}" > "${MINICONFIG_SORT}"
rm "${MINICONFIG_CAT}"
pushd "${S}" >/dev/null
make ARCH="${ARCH}" KCONFIG_ALLCONFIG="${MINICONFIG_SORT}" allnoconfig
# check consistency
while read config; do
if ! grep -q "^${config}\$" .config; then
missing+=("${config}")
if ! $gcc && grep -q "CONFIG_GCC_PLUGIN" <<< "$config"; then
gcc=true
fi
fi
done < "${MINICONFIG_SORT}"
if [[ "${#missing[@]}" -ne 0 ]]; then
if $gcc ; then
echo "HINT: You need a gcc with plugin support. For some distros (e.g. Debian), you may need to install the supporting headers explicitly in addition to the normal gcc package."
fi
err_msg="Missing ${#missing[@]} entry from ${MINICONFIG_SORT}: ${missing[*]}"
if [[ "$DEBUG" -eq 0 ]]; then
die "$err_msg"
else
warn "$err_msg"
fi
fi
popd >/dev/null
# check blacklisted options
while read config; do
if grep -q "^${config}=" "${S}/.config"; then
unwanted+=("${config}")
fi
done < "${CONFIGDIR}/kernel_config/blacklist"
if [[ "${#unwanted[@]}" -ne 0 ]]; then
err_msg="${#unwanted[@]} entry blacklisted but appearing in final .config: ${unwanted[*]}"
if [[ "$DEBUG" -eq 0 ]]; then
die "$err_msg"
else
warn "$err_msg"
fi
fi
}
warn() {
echo "WARNING: $*" >&2
}
die() {
echo "ERROR: $*" >&2
exit 1
}
_cleanup() {
local torm
local torm_list=("${MINICONFIG_CAT}" "${MINICONFIG_SORT}")
set +e
for torm in "${torm_list[@]}"; do
if [[ -f "${torm}" ]]; then
rm -- "${torm}"
fi
done
}
if [[ $# -lt 1 ]]; then
echo "usage: $(basename -- "$0") <configset>..." >&2
echo >&2
echo "example: $(basename -- "$0") basic cpu/intel cpu/x86_64 misc_drivers net/basic security/basic" >&2
exit 1
fi
set -u -e -o pipefail
if [[ -z "${CONFIGDIR:-}" ]]; then
CONFIGDIR="$SELFPATH"
fi
if [[ -z "${S:-}" ]]; then
S="$(pwd)"
fi
if [[ -z "${ARCH:-}" ]]; then
ARCH="$(uname -m)"
echo "WARNING: ARCH env variable was not specified, defaulting to x86_64"
fi
: ${DEBUG:=0}
if [[ ! -f "${S}/Makefile" ]]; then
echo "Need to be run in a Linux source directory." >&2
exit 1
fi
trap _cleanup QUIT INT TERM EXIT
generate_config "$@"
# vim: set ts=4 sts=4 sw=4 noet: