]> git.ipfire.org Git - ipfire-3.x.git/blame - kernel/scripts/configure
kernel: configure: Pass arch as an extra argument
[ipfire-3.x.git] / kernel / scripts / configure
CommitLineData
4c928ab7
MT
1#!/bin/bash
2###############################################################################
3# IPFire.org - An Open Source Firewall Solution #
4# Copyright (C) - IPFire Development Team <info@ipfire.org> #
5###############################################################################
6
7BASEDIR=$(dirname ${0})
8SCRIPTS_DIR=${BASEDIR}
9
7f6f4de5
MT
10# x86_64
11CONFIGS="x86_64:default"
12
d5383c43
MT
13# aarch64
14CONFIGS="${CONFIGS} aarch64:default"
15
7f6f4de5 16# armv7hl
dc4bd821 17CONFIGS="${CONFIGS} armv7hl:default"
7f6f4de5 18
d5383c43
MT
19PLATFORMS="x86 arm"
20declare -A SUBPLATFORMS
21SUBPLATFORMS=(
22 [arm]="arm64 arm32"
23)
24
a91f6da9
MT
25search_kernel_dir() {
26 local dir
27 for dir in /builddir/source/linux-*; do
28 if [ -d "${dir}" ]; then
29 echo "${dir}"
30 break
31 fi
32 done
33}
34
d5383c43
MT
35function get_platform() {
36 local arch="${1}"
37
38 case "${arch}" in
39 aarch64|arm*)
40 echo "arm"
41 ;;
42 x86_64|i?86)
43 echo "x86"
44 ;;
45 *)
46 return 1
47 ;;
48 esac
49}
50
51function get_subplatform() {
52 local arch="${1}"
53
54 case "${arch}" in
55 aarch64)
56 echo "arm64"
57 ;;
58 arm*)
59 echo "arm32"
60 ;;
61 *)
62 return 1
63 ;;
64 esac
65}
66
67function get_kernel_arch() {
68 local arch="${1}"
69
70 case "${arch}" in
71 aarch64)
72 echo "arm64"
73 ;;
74 arm*)
75 echo "arm"
76 ;;
e7f50e45 77 x86_64)
d5383c43
MT
78 echo "x86"
79 ;;
80 esac
81}
82
4c928ab7
MT
83function merge_config() {
84 local arch=${1}
85 local flavour=${2}
86 local output=${3}
87 shift 3
88
89 local arg
90 for arg in arch flavour output; do
91 if [ -z "${!arg}" ]; then
92 echo >&2 "merge usage: <arch> <flavour> <output filename>"
93 exit 2
94 fi
95 done
96
1349854e 97 local config_mode="olddefconfig"
4c928ab7
MT
98 local extra_configs
99 while [ $# -gt 0 ]; do
100 case "${1}" in
101 --mode=*)
102 config_mode=${1#--mode=}
103 shift
104 ;;
105 -*)
106 echo >&2 "Unknown option: ${1}"
107 ;;
108 *)
109 extra_configs="${extra_configs} ${1}"
110 ;;
111 esac
112 shift
113 done
114
115 local configs="${extra_configs} config-generic"
116
117 case "${arch}:${flavour}" in
118 # x86
119 x86_64:default)
e7f50e45 120 configs="${configs} config-x86-generic"
4c928ab7
MT
121 ;;
122
d5383c43
MT
123 # ARM64
124 aarch64:default)
125 configs="${configs} config-arm-generic config-arm64-generic"
126 ;;
127
4c928ab7 128 # ARM
7f6f4de5 129 armv7hl:default)
d5383c43 130 configs="${configs} config-arm-generic config-arm32-generic"
302e8df8 131 ;;
4c928ab7
MT
132 *)
133 echo >&2 "ERROR: Invalid parameters given: $@"
134 return 1
135 ;;
136 esac
137
4c928ab7
MT
138 # Merge the configuration files from its elementary configuration
139 # files.
140 local tmp_out=$(mktemp)
141 local tmp_in=$(mktemp)
142
143 local config
144 for config in ${configs}; do
145 cat ${tmp_out} > ${tmp_in}
146 perl ${SCRIPTS_DIR}/merge.pl \
cc7a96d3 147 ${tmp_in} ${config} > ${tmp_out}
4c928ab7
MT
148 done
149
150 if [ "${config_mode}" != "none" ]; then
1349854e 151 echo "Running 'make olddefconfig' for ${arch} (${flavour})..."
d5383c43 152 local kernel_arch="$(get_kernel_arch "${arch}")"
4c928ab7
MT
153 (
154 cd ${KERNEL_DIR}
155 cat ${tmp_out} > .config
156 make ARCH="${kernel_arch}" ${config_mode}
157 cat .config > ${tmp_out}
158 )
159 fi
160
161 cat ${tmp_out} > ${output}
162 rm -f ${tmp_in} ${tmp_out}
163}
164
165# This function runs an interactive "make oldconfig".
7a079046 166function make_config() {
fa4b3a6b
MT
167 local action="${1}"
168 local arch="${2}"
169
170 # Default to x86_64 when no arch is given
171 if [ -z "${arch}" ]; then
172 arch="x86_64"
173 fi
a8e51819
MT
174
175 # Detect kernel arch
176 local kernel_arch="$(get_kernel_arch "${arch}")"
4c928ab7
MT
177 local flavour="default"
178
179 local config_in=$(mktemp)
180 local config_out=$(mktemp)
181 local diff_out=$(mktemp)
182
183 merge_config ${arch} ${flavour} ${config_in} --mode=none
184
185 (
7a079046 186 pushd ${KERNEL_DIR}
4c928ab7
MT
187 cat ${config_in} > .config
188
189 echo "You may now edit the configuration..."
fa4b3a6b 190 make ARCH=${kernel_arch} "${action}"
4c928ab7
MT
191
192 cat .config > ${config_out}
7a079046 193 popd
4c928ab7
MT
194 )
195
196 ${SCRIPTS_DIR}/configdiff.py ${config_in} ${config_out} > ${diff_out}
197
198 # Update the rest of the configurations.
199 diff_configs ${diff_out} --mode=oldconfig
200
201 rm -f ${config_in} ${config_out} ${diff_out}
202}
203
204# config-generic
205# Intersection of all files.
4c928ab7
MT
206# config-x86-x86_64
207# Diff against merge of (config-generic and config-x86-generic).
208
209function diff_configs() {
210 local extra_configs="$@"
211
d5383c43
MT
212 local filename
213 local platform
214 local subplatform
215
216 declare -A platform_configs
217 declare -A subplatform_configs
4c928ab7
MT
218
219 tmpdir=$(mktemp -d)
220
221 for config in ${CONFIGS}; do
222 arch=${config%:*}
223 flavour=${config#*:}
224
225 filename=${tmpdir}/config-${arch}-${flavour}
226
227 merge_config ${arch} ${flavour} ${filename} ${extra_configs}
228
d5383c43
MT
229 platform="$(get_platform "${arch}")"
230 subplatform="$(get_subplatform "${arch}")"
302e8df8 231
d5383c43
MT
232 if [ -n "${subplatform}" ]; then
233 subplatform_configs[${subplatform}]="${subplatform_configs[${subplatform}]} ${filename}"
234 else
235 platform_configs[${platform}]="${platform_configs[${platform}]} ${filename}"
236 fi
4c928ab7
MT
237 done
238
d5383c43
MT
239 local common_configs
240 for platform in ${PLATFORMS}; do
241 for subplatform in ${SUBPLATFORMS[${platform}]}; do
242 filename="${tmpdir}/config-${subplatform}-common"
243 ${SCRIPTS_DIR}/configcommon.py ${subplatform_configs[${subplatform}]} \
244 > ${filename}
245
246 platform_configs[${platform}]="${platform_configs[${platform}]} ${filename}"
247 done
248
249 filename="${tmpdir}/config-${platform}-common"
250 ${SCRIPTS_DIR}/configcommon.py ${platform_configs[${platform}]} \
4c928ab7
MT
251 > ${filename}
252
253 common_configs="${common_configs} ${filename}"
254 done
255
256 ${SCRIPTS_DIR}/configcommon.py ${common_configs} > ${tmpdir}/config-generic
257
d5383c43
MT
258 for platform in ${PLATFORMS}; do
259 for subplatform in ${SUBPLATFORMS[${platform}]}; do
260 ${SCRIPTS_DIR}/configdiff.py \
261 ${tmpdir}/config-${platform}-common \
262 ${tmpdir}/config-${subplatform}-common \
263 > ${tmpdir}/config-${subplatform}-generic
264 done
265
266 ${SCRIPTS_DIR}/configdiff.py \
267 ${tmpdir}/config-generic \
268 ${tmpdir}/config-${platform}-common \
269 > ${tmpdir}/config-${platform}-generic
302e8df8
MT
270 done
271
4c928ab7
MT
272 for config in ${CONFIGS}; do
273 arch=${config%:*}
274 flavour=${config#*:}
275
4c928ab7
MT
276 filename=${tmpdir}/config-${arch}-${flavour}
277
278 case "${config}" in
43556e68 279 aarch64:default|armv7hl:default|x86_64:default)
d5383c43
MT
280 # Virtual configuration
281 rm -f ${filename}
282 continue
283 ;;
4c928ab7 284 *)
d5383c43
MT
285 platform="$(get_subplatform "${arch}" || get_platform "${arch}")"
286 ${SCRIPTS_DIR}/configdiff.py ${tmpdir}/config-${platform}-common \
4c928ab7
MT
287 ${filename} > ${filename}.tmp
288 ;;
289 esac
290 mv ${filename}{.tmp,}
291 done
292 rm -f ${tmpdir}/config-*-common
293
294 for config in ${tmpdir}/*; do
295 if ! cmp $(basename ${config}) ${config} &>/dev/null; then
296 echo "$(basename ${config}) has changed."
297 fi
298 cat ${config} > $(basename ${config})
299 done
300
301 rm -rf ${tmpdir}
302}
303
a91f6da9 304KERNEL_DIR="$(search_kernel_dir)"
4c928ab7
MT
305
306# Parse commandline.
307while [ $# -gt 0 ]; do
308 arg=${1}; shift
309 case "${arg}" in
4c928ab7
MT
310 help|"")
311 echo "${0} - available commands:"
312 echo " * merge <arch> <flavour> <output filename>"
7a079046 313 echo " * menuconfig"
4c928ab7 314 echo " * oldconfig"
34869f6e 315 echo " * olddefconfig"
4c928ab7
MT
316 exit 0
317 ;;
26f31cb7 318 listnewconfig|menuconfig|merge|oldconfig|olddefconfig)
4c928ab7 319 action=${arg}
fa4b3a6b 320 break
4c928ab7
MT
321 ;;
322 esac
323done
324
325if [ -z "${KERNEL_DIR}" ]; then
a91f6da9 326 echo >&2 "KERNEL_DIR was not set!"
4c928ab7
MT
327 exit 2
328fi
329
330if [ -z "${action}" ]; then
331 echo >&2 "No action given... Try ${0} help."
332 exit 2
333fi
334
335case "${action}" in
336 merge)
337 merge_config $@
338 exit $?
339 ;;
26f31cb7 340 listnewconfig|menuconfig|oldconfig|olddefconfig)
fa4b3a6b 341 make_config "${action}" "$@"
4c928ab7
MT
342 exit $?
343 ;;
4c928ab7
MT
344esac
345
346exit 1