functions: Add global functions for manipulating kconfig options

This commit adds 4 new functions to aid in the process of managing a
kconfig .config file:

* CT_KconfigSetOption <option> <value> <file>
* CT_KconfigEnableOption <option> <file>
* CT_KconfigDisableOption <option> <file>
* CT_KconfigDeleteOption <option> <file>

(akin to how buildroot manages the uClibc.config)

These functions are global so that we can manage any component that also
uses kconfig, or to be able to use it internally on Crosstool-NG's
kconfig files.

Last but not least, be consistent and update sed to be ${sed}!

Signed-off-by: Bryan Hundven <bryanhundven@gmail.com>
This commit is contained in:
Bryan Hundven 2015-11-09 22:55:32 -08:00
parent 930fa77076
commit c4d14a97ad

View File

@ -842,7 +842,7 @@ CT_GetGit() {
local url="${3}"
local _out_cset="${4}"
local ref=$(echo "${cset_or_ref}" | sed -n 's/^ref=\(.*\)/\1/p')
local ref=$(echo "${cset_or_ref}" | ${sed} -n 's/^ref=\(.*\)/\1/p')
if [ -n "$ref" ]; then
local matches=$(git ls-remote --exit-code "$url" --refs "${ref}")
local result=$?
@ -1428,3 +1428,51 @@ CT_DoLoadState(){
exec >>"${tmp_log_file}"
rm -f "${state_dir}/tail.log"
}
# This function sets a kconfig option to a specific value in a .config file
# Usage: CT_KconfigSetOption <option> <value> <file>
CT_KconfigSetOption() {
option="$1"
value="$2"
file="$3"
${grep} -E -q "^${option}=.*" "${file}" && \
${sed} -i -r -e "s;^${option}=.*$;${option}=${value};" "${file}" || \
${grep} -E -q "^# ${option} is not set$" "${file}" && \
${sed} -i -r -e "s;^# ${option} is not set$;${option}=${value};" "${file}" || \
echo "${option}=${value}" >> "${file}"
}
# This function enables a kconfig option to '=y' in a .config file
# Usage: CT_KconfigEnableOption <option> <file>
CT_KconfigEnableOption() {
option="$1"
file="$2"
CT_KconfigSetOption "${option}" "y" "${file}"
}
# This function disables a kconfig option in a .config file
# Usage: CT_KconfigDisableOption <option> <file>
CT_KconfigDisableOption() {
option="${1}"
file="${2}"
${grep} -E -q "^# ${option} is not set$" "${file}" || \
${grep} -E -q "^${option}=.*$" "${file}" && \
${sed} -i -r -e "s;^${option}=.*$;# ${option} is not set;" "${file}" || \
echo "# ${option} is not set" >> "${file}"
}
# This function deletes a kconfig option in a .config file, no matter if it
# is set or commented out.
# Usage: CT_KconfigDeleteOption <option> <file>
CT_KconfigDeleteOption() {
option="${1}"
file="${2}"
${grep} -E -q "^# ${option} is not set$" "${file}" && \
${sed} -i -r -e "/^# ${option} is not set$/d" "${file}" || \
${grep} -E -q "^${option}=.*$" "${file}" && \
${sed} -i -r -e "/^${option}=.*$/d" "${file}" || true
}