Skip to content

Commit

Permalink
functions: Add global functions for manipulating kconfig options
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bhundven committed Nov 13, 2015
1 parent 930fa77 commit c4d14a9
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion scripts/functions
Expand Up @@ -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=$?
Expand Down Expand Up @@ -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
}

0 comments on commit c4d14a9

Please sign in to comment.