2 ###############################################################################
3 # IPFire.org - An Open Source Firewall Solution #
4 # Copyright (C) - IPFire Development Team <info@ipfire.org> #
5 ###############################################################################
7 BASEDIR
="$(dirname "${0}")"
8 SCRIPTS_DIR
="${BASEDIR}"
20 for dir
in /builddir
/source
/linux-
*; do
21 if [ -d "${dir}" ]; then
30 for config
in ${CONFIGS[@]}; do
39 for config
in ${CONFIGS[@]}; do
40 if [ "${arch}:" = "${config%:*}:" ]; then
51 # Add any extra files first
52 local configs
=( "$@" )
54 # Add the generic configuration
55 configs
+=( "config-generic" )
57 # If flavour is not generic, we add *-generic
58 if [ "${flavour}" != "generic" ]; then
59 configs
+=( "config-${arch}-generic" )
62 # Add the architecture/flavour configuration
63 configs
+=( "config-${arch}-${flavour}" )
90 local config_in
="${3}"
91 local config_out
="${4}"
93 echo "Running 'make ${action}' for ${arch}..."
95 local kernel_arch
="$(get_kernel_arch "${arch}")"
97 pushd "${KERNEL_DIR}" >/dev
/null
99 cat "${config_in}" > ".config"
101 # Run the configuration program
102 make ARCH
="${kernel_arch}" "${action}"
104 # Write back the configuration file
105 cat ".config" > "${config_out}"
117 for arg
in arch flavour output
; do
118 if [ -z "${!arg}" ]; then
119 echo >&2 "merge usage: <arch> <flavour> <output filename>"
124 local configs
="$(configs "${arch}" "${flavour}" "$@
")"
126 # Merge the configuration files from its elementary configuration
128 local tmp_out
="$(mktemp)"
129 local tmp_in
="$(mktemp)"
132 for config
in ${configs}; do
133 cat "${tmp_out}" > "${tmp_in}"
135 if ! perl
"${SCRIPTS_DIR}/merge.pl" \
136 "${tmp_in}" "${config}" > "${tmp_out}"; then
137 echo >&2 "Could not merge configuration for ${arch} ${flavour}"
138 rm -f "${tmp_in}" "${tmp_out}"
143 cat "${tmp_out}" > "${output}"
144 rm -f "${tmp_in}" "${tmp_out}"
147 # This function runs an interactive "make oldconfig"
152 # Default to x86_64 when no arch is given
153 if [ -z "${arch}" ]; then
158 local flavour
="generic"
160 # Create a temporary directory
161 local tmpdir
="$(mktemp -d)"
163 # Merge configuration
164 if ! merge_config
"${arch}" "${flavour}" "${tmpdir}/.config.old"; then
165 echo "Could not merge configuration for ${arch} (${flavour})" >&2
169 # Open the kernel configuration editor (in the given mode)
170 if ! kernel_config
"${arch}" "${action}" "${tmpdir}/.config.old" "${tmpdir}/.config"; then
171 echo >&2 "Kernel configuration editing has been unsuccessful"
176 # Diff the old and changed configuration
177 if ! python3
"${SCRIPTS_DIR}/configdiff.py" \
178 "${tmpdir}/.config.old" "${tmpdir}/.config" > "${tmpdir}/diff"; then
183 # Check if the diff contains any data
184 if [ ! -s "${tmpdir}/diff" ]; then
185 echo "No changes found"
189 # Apply the diff to all configurations
190 if ! diff_configs
"${tmpdir}/diff"; then
202 local tmpdir
="$(mktemp -d)"
207 for config
in ${CONFIGS[@]}; do
209 flavour
="${config#*:}"
211 # Generate the filename
212 local filename
="${tmpdir}/full-${arch}-${flavour}"
214 # Merge configuration
215 if ! merge_config
"${arch}" "${flavour}" "${filename}" "$@"; then
220 # Run "oldconfig" to ensure there are no gaps in other architectures
221 kernel_config
"${arch}" "oldconfig" "${filename}" "${filename}"
223 # Collect all *-generic configurations
226 configs
+=( "${filename}" )
231 # Generate config-generic
232 if ! python3
"${SCRIPTS_DIR}/configcommon.py" "${configs[@]}" \
233 > "${tmpdir}/config-generic"; then
234 echo >&2 "Could not generate config-generic"
240 for arch
in $
(arches
); do
242 local flavours
="$(flavours_for_arch "${arch}")"
245 for flavour
in ${flavours}; do
246 local base_config
="${tmpdir}/config-${arch}-generic"
248 # config-${arch}-generic is handled in a special way and diffed
249 # directly against config-generic
252 base_config
="${tmpdir}/config-generic"
256 # Diff configurations
257 if ! python3
"${SCRIPTS_DIR}/configdiff.py" \
259 "${tmpdir}/full-${arch}-${flavour}" \
260 > "${tmpdir}/config-${arch}-${flavour}"; then
261 echo >&2 "Could not generate config-${arch}-${flavour}"
268 # List any changes and copy back the result
269 for config
in config-
*; do
270 if ! cmp "${tmpdir}/${config}" "${config}" &>/dev
/null
; then
271 echo "${config} has changed"
274 # Copy back configuration
275 cat "${tmpdir}/${config}" > "${config}"
284 KERNEL_DIR
="$(search_kernel_dir)"
291 while [ $# -gt 0 ]; do
297 KERNEL_DIR
="${arg#--kernel-dir=}"
300 listnewconfig|menuconfig|merge|oldconfig|olddefconfig
)
306 echo "${0} - available commands:"
307 echo " * merge <arch> <flavour> <output filename>"
310 echo " * olddefconfig"
316 # Check if KERNEL_DIR has been set and exists
317 if [ -z "${KERNEL_DIR}" -o ! -d "${KERNEL_DIR}" ]; then
318 echo >&2 "KERNEL_DIR was not set or does not exist!"
328 listnewconfig|menuconfig|oldconfig|olddefconfig
)
329 make_config
"${action}" "$@"
333 # Handle no or invalid actions
335 echo >&2 "No action given... Try ${0} help."