diff options
author | Bryan Hundven <bryanhundven@gmail.com> | 2015-11-09 22:55:32 -0800 |
---|---|---|
committer | Bryan Hundven <bryanhundven@gmail.com> | 2015-11-12 16:15:39 -0800 |
commit | c4d14a97ad840891cfd3e088c6d8685e1c763ab6 (patch) | |
tree | 8ed6568228440afb4cd202d88441aa44195559f5 /scripts | |
parent | 930fa77076874655179341433b4f8066deefb0b8 (diff) | |
download | crosstool-ng-c4d14a97ad840891cfd3e088c6d8685e1c763ab6.tar.gz crosstool-ng-c4d14a97ad840891cfd3e088c6d8685e1c763ab6.tar.bz2 crosstool-ng-c4d14a97ad840891cfd3e088c6d8685e1c763ab6.zip |
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>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/functions | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/scripts/functions b/scripts/functions index 2261b8d0..f09df54b 100644 --- a/scripts/functions +++ b/scripts/functions @@ -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 +} |