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