2017-04-22 18:41:50 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
2011-07-03 23:02:16 +02:00
|
|
|
set -e
|
|
|
|
|
2017-04-22 18:41:50 -07:00
|
|
|
# Accept overrides from command line if needed
|
|
|
|
sed=${SED:-sed}
|
|
|
|
grep=${GREP:-grep}
|
|
|
|
|
|
|
|
# Generate either a choice or a menuconfig with the specified entries.
|
2011-07-03 23:02:16 +02:00
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# generate a choice:
|
2017-04-22 18:41:50 -07:00
|
|
|
# gen_choice <out-file> <label> <config-prefix> <base-dir> \
|
|
|
|
# <conditionals> entry [entry...]
|
2011-07-03 23:02:16 +02:00
|
|
|
#
|
|
|
|
# generate a menuconfig:
|
2017-04-22 18:41:50 -07:00
|
|
|
# gen_menu <out-file> <label> <config-prefix> <base-dir> \
|
|
|
|
# entry [entry...]
|
2011-07-03 23:02:16 +02:00
|
|
|
#
|
|
|
|
# where:
|
|
|
|
# out-file
|
|
|
|
# put the generated choice/menuconfig into that file
|
|
|
|
# for choices, it acts as the base bname of the file, the secondary
|
|
|
|
# parts (the .in.2) are put in out-file.2
|
|
|
|
#
|
|
|
|
# label
|
|
|
|
# name for the entries family
|
|
|
|
# eg. Architecture, Kernel...
|
|
|
|
#
|
|
|
|
# config-prefix
|
|
|
|
# prefix for the choice entries
|
|
|
|
# eg. ARCH, KERNEL...
|
|
|
|
#
|
|
|
|
# base-dir
|
|
|
|
# base directory containing config files
|
|
|
|
# eg. config/arch, config/kernel...
|
|
|
|
#
|
|
|
|
# conditionals (valid only for choice)
|
|
|
|
# generate backend conditionals if Y/y, don't if anything else
|
|
|
|
# if 'Y' (or 'y'), a dependency on the backen mode will be added
|
|
|
|
# to each entry
|
|
|
|
#
|
|
|
|
# entry [entry...]
|
|
|
|
# a list of entry/ies toadd to the choice/menuconfig
|
|
|
|
# eg.:
|
|
|
|
# arm mips sh x86...
|
|
|
|
# linux cygwin mingw32 solaris...
|
|
|
|
# ...
|
|
|
|
#
|
2017-04-22 18:41:50 -07:00
|
|
|
|
|
|
|
# Helper: find the base names of all *.in files in a given directory
|
|
|
|
get_components() {
|
|
|
|
local dir="${1}"
|
|
|
|
local f b
|
|
|
|
|
|
|
|
for f in ${dir}/*.in; do
|
|
|
|
b=${f#${dir}/}
|
|
|
|
echo ${b%.in}
|
|
|
|
done
|
|
|
|
}
|
2011-07-03 23:02:16 +02:00
|
|
|
|
|
|
|
# Generate a choice
|
|
|
|
# See above for usage
|
|
|
|
gen_choice() {
|
|
|
|
local out_file="${1}"
|
|
|
|
local label="${2}"
|
|
|
|
local cfg_prefix="${3}"
|
|
|
|
local base_dir="${4}"
|
|
|
|
local cond="${5}"
|
|
|
|
local file entry _entry
|
|
|
|
|
|
|
|
# Generate the part-1
|
|
|
|
exec >"${out_file}"
|
|
|
|
printf '# %s menu\n' "${label}"
|
|
|
|
printf '# Generated file, do not edit!!!\n'
|
|
|
|
printf '\n'
|
|
|
|
printf 'choice GEN_CHOICE_%s\n' "${cfg_prefix}"
|
|
|
|
printf ' bool\n'
|
|
|
|
printf ' prompt "%s"\n' "${label}"
|
|
|
|
printf '\n'
|
2017-04-22 18:41:50 -07:00
|
|
|
for entry in `get_components ${base_dir}`; do
|
2011-07-03 23:02:16 +02:00
|
|
|
file="${base_dir}/${entry}.in"
|
2017-02-26 19:06:35 -08:00
|
|
|
_entry=$(printf '%s\n' "${entry}" |"${sed}" -r -s -e 's/[-.+]/_/g;')
|
2011-07-03 23:02:16 +02:00
|
|
|
printf 'config %s_%s\n' "${cfg_prefix}" "${_entry}"
|
|
|
|
printf ' bool\n'
|
|
|
|
printf ' prompt "%s"\n' "${entry}"
|
|
|
|
if [ "${cond}" = "Y" -o "${cond}" = "y" ]; then
|
|
|
|
printf ' depends on %s_%s_AVAILABLE\n' "${cfg_prefix}" "${_entry}"
|
|
|
|
fi
|
2017-02-26 19:06:35 -08:00
|
|
|
"${sed}" -r -e '/^## depends on /!d; s/^## / /;' ${file} 2>/dev/null
|
|
|
|
"${sed}" -r -e '/^## select /!d; s/^## / /;' ${file} 2>/dev/null
|
|
|
|
if "${grep}" -E '^## help' ${file} >/dev/null 2>&1; then
|
2011-07-03 23:02:16 +02:00
|
|
|
printf ' help\n'
|
2017-02-26 19:06:35 -08:00
|
|
|
"${sed}" -r -e '/^## help ?/!d; s/^## help ?/ /;' ${file} 2>/dev/null
|
2011-07-03 23:02:16 +02:00
|
|
|
fi
|
|
|
|
printf '\n'
|
|
|
|
done
|
|
|
|
printf 'endchoice\n'
|
|
|
|
|
2017-04-22 18:41:50 -07:00
|
|
|
for entry in `get_components ${base_dir}`; do
|
2011-07-03 23:02:16 +02:00
|
|
|
file="${base_dir}/${entry}.in"
|
2017-02-26 19:06:35 -08:00
|
|
|
_entry=$(printf '%s\n' "${entry}" |"${sed}" -r -s -e 's/[-.+]/_/g;')
|
2011-07-03 23:02:16 +02:00
|
|
|
printf '\n'
|
|
|
|
if [ "${cond}" = "Y" -o "${cond}" = "y" ]; then
|
|
|
|
printf 'config %s_%s_AVAILABLE\n' "${cfg_prefix}" "${_entry}"
|
|
|
|
printf ' bool\n'
|
|
|
|
printf ' default y if'
|
|
|
|
printf ' BACKEND_%s = "%s"' "${cfg_prefix}" "${entry}"
|
|
|
|
printf ' || BACKEND_%s = ""' "${cfg_prefix}"
|
|
|
|
printf ' || ! BACKEND\n'
|
|
|
|
fi
|
|
|
|
printf 'if %s_%s\n' "${cfg_prefix}" "${_entry}"
|
|
|
|
printf 'config %s\n' "${cfg_prefix}"
|
|
|
|
printf ' default "%s" if %s_%s\n' "${entry}" "${cfg_prefix}" "${_entry}"
|
|
|
|
printf 'source "%s"\n' "${file}"
|
|
|
|
printf 'endif\n'
|
|
|
|
done
|
|
|
|
|
|
|
|
# Generate the part-2
|
|
|
|
exec >"${out_file}.2"
|
|
|
|
printf '# %s second part options\n' "${label}"
|
|
|
|
printf '# Generated file, do not edit!!!\n'
|
2017-04-22 18:41:50 -07:00
|
|
|
for entry in `get_components ${base_dir}`; do
|
2011-07-03 23:02:16 +02:00
|
|
|
file="${base_dir}/${entry}.in"
|
2017-02-26 19:06:35 -08:00
|
|
|
_entry=$(printf '%s\n' "${entry}" |"${sed}" -r -s -e 's/[-.+]/_/g;')
|
2011-07-03 23:02:16 +02:00
|
|
|
if [ -f "${file}.2" ]; then
|
|
|
|
printf '\n'
|
|
|
|
printf 'if %s_%s\n' "${cfg_prefix}" "${_entry}"
|
|
|
|
printf 'comment "%s other options"\n' "${entry}"
|
|
|
|
printf 'source "%s.2"\n' "${file}"
|
|
|
|
printf 'endif\n'
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Generate a menuconfig
|
|
|
|
# See above for usage
|
|
|
|
gen_menu() {
|
|
|
|
local out_file="${1}"
|
|
|
|
local label="${2}"
|
|
|
|
local cfg_prefix="${3}"
|
|
|
|
local base_dir="${4}"
|
|
|
|
local file entry _entry
|
|
|
|
|
2017-02-03 17:49:45 -08:00
|
|
|
# Generate the menuconfig
|
2011-07-03 23:02:16 +02:00
|
|
|
exec >"${out_file}"
|
|
|
|
printf '# %s menu\n' "${label}"
|
|
|
|
printf '# Generated file, do not edit!!!\n'
|
|
|
|
printf '\n'
|
2017-04-22 18:41:50 -07:00
|
|
|
for entry in `get_components ${base_dir}`; do
|
2011-07-03 23:02:16 +02:00
|
|
|
file="${base_dir}/${entry}.in"
|
2017-02-26 19:06:35 -08:00
|
|
|
_entry=$(printf '%s\n' "${entry}" |"${sed}" -r -s -e 's/[-.+]/_/g;')
|
2011-07-03 23:02:16 +02:00
|
|
|
printf 'menuconfig %s_%s\n' "${cfg_prefix}" "${_entry}"
|
|
|
|
printf ' bool\n'
|
2017-02-26 19:06:35 -08:00
|
|
|
if "${grep}" -E '^## default' ${file} >/dev/null 2>&1; then
|
|
|
|
"${sed}" -r -e '/^## default ?/!d; s/^## default ?/ default /;' ${file} 2>/dev/null
|
2015-05-29 21:40:49 +01:00
|
|
|
fi
|
2011-07-03 23:02:16 +02:00
|
|
|
printf ' prompt "%s"\n' "${entry}"
|
2017-02-26 19:06:35 -08:00
|
|
|
"${sed}" -r -e '/^## depends on /!d; s/^## / /;' ${file} 2>/dev/null
|
|
|
|
"${sed}" -r -e '/^## select /!d; s/^## / /;' ${file} 2>/dev/null
|
|
|
|
if "${grep}" -E '^## help' ${file} >/dev/null 2>&1; then
|
2011-07-03 23:02:16 +02:00
|
|
|
printf ' help\n'
|
2017-02-26 19:06:35 -08:00
|
|
|
"${sed}" -r -e '/^## help ?/!d; s/^## help ?/ /;' ${file} 2>/dev/null
|
2011-07-03 23:02:16 +02:00
|
|
|
fi
|
|
|
|
printf '\n'
|
|
|
|
printf 'if %s_%s\n' "${cfg_prefix}" "${_entry}"
|
|
|
|
printf 'source "%s"\n' "${file}"
|
|
|
|
printf 'endif\n'
|
|
|
|
printf '\n'
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-04-22 18:41:50 -07:00
|
|
|
mkdir -p config/gen
|
|
|
|
gen_choice config/gen/arch.in "Target Architecture" "ARCH" "config/arch" "Y"
|
|
|
|
gen_choice config/gen/kernel.in "Target OS" "KERNEL" "config/kernel" "Y"
|
|
|
|
gen_choice config/gen/cc.in "Compiler" "CC" "config/cc" "N"
|
|
|
|
gen_choice config/gen/binutils.in "Binutils" "BINUTILS" "config/binutils" "N"
|
|
|
|
gen_choice config/gen/libc.in "C library" "LIBC" "config/libc" "Y"
|
|
|
|
gen_menu config/gen/debug.in "Debug facilities" "DEBUG" "config/debug"
|
|
|
|
gen_menu config/gen/companion_tools.in "Companion tools" "COMP_TOOLS" "config/companion_tools"
|