* [PATCH 1/3] kbuild: handle non-existing options in scripts/config
[not found] <cover.1243255664.git.mmarek@suse.cz>
@ 2009-05-25 12:55 ` Michal Marek
2009-05-25 13:11 ` Andi Kleen
2009-05-25 12:55 ` [PATCH 2/3] kbuild: simplify argument loop " Michal Marek
2009-05-25 12:55 ` [PATCH 3/3] kbuild: add generic --set option to scripts/config Michal Marek
2 siblings, 1 reply; 8+ messages in thread
From: Michal Marek @ 2009-05-25 12:55 UTC (permalink / raw)
To: Andi Kleen; +Cc: Sam Ravnborg, linux-kernel
If an option does not exist in .config, set it at the end of the file.
Signed-off-by: Michal Marek <mmarek@suse.cz>
---
scripts/config | 51 +++++++++++++++++++++++++++++++++------------------
1 files changed, 33 insertions(+), 18 deletions(-)
diff --git a/scripts/config b/scripts/config
index db6084b..144e4b0 100755
--- a/scripts/config
+++ b/scripts/config
@@ -26,8 +26,6 @@ options:
config doesn't check the validity of the .config file. This is done at next
make time.
-The options need to be already in the file before they can be changed,
-but sometimes you can cheat with the --*-after options.
EOL
exit 1
}
@@ -45,8 +43,33 @@ checkarg() {
ARG="`echo $ARG | tr a-z A-Z`"
}
-replace() {
- sed -i -e "$@" $FN
+# set_var name value [before-var]
+set_var() {
+ awk -vvar="$1" -vnew="$2" -vbefore="$3" '
+ function is_var(l, v)
+ {
+ return (l == "# " v " is not set" || l ~ "^" v "=");
+ }
+ {
+ if (is_var($0, var)) {
+ if (new)
+ print new;
+ new = "";
+ } else if (before && is_var($0, before)) {
+ print;
+ if (new)
+ print new;
+ new = "";
+ } else {
+ print;
+ }
+ }
+ END {
+ if (new)
+ print new;
+ }
+ ' "$FN" >"$FN.tmp"
+ mv -f "$FN.tmp" "$FN"
}
if [ "$1" = "--file" ]; then
@@ -70,20 +93,19 @@ while [ "$1" != "" ] ; do
case "$CMD" in
--enable|-e)
checkarg "$1"
- replace "s/# CONFIG_$ARG is not set/CONFIG_$ARG=y/"
+ set_var "CONFIG_$ARG" "CONFIG_$ARG=y"
shift
;;
--disable|-d)
checkarg "$1"
- replace "s/CONFIG_$ARG=[my]/# CONFIG_$ARG is not set/"
+ set_var "CONFIG_$ARG" "# CONFIG_$ARG is not set"
shift
;;
--module|-m)
checkarg "$1"
- replace "s/CONFIG_$ARG=y/CONFIG_$ARG=m/" \
- -e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=m/"
+ set_var "CONFIG_$ARG" "CONFIG_$ARG=m"
shift
;;
@@ -109,9 +131,7 @@ while [ "$1" != "" ] ; do
A=$ARG
checkarg "$2"
B=$ARG
- replace "/CONFIG_$A=[my]/aCONFIG_$B=y" \
- -e "/# CONFIG_$ARG is not set/a/CONFIG_$ARG=y" \
- -e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=y/"
+ set_var "CONFIG_$B" "CONFIG_$B=y" "CONFIG_$A"
shift
shift
;;
@@ -121,9 +141,7 @@ while [ "$1" != "" ] ; do
A=$ARG
checkarg "$2"
B=$ARG
- replace "/CONFIG_$A=[my]/a# CONFIG_$B is not set" \
- -e "/# CONFIG_$ARG is not set/a/# CONFIG_$ARG is not set" \
- -e "s/CONFIG_$ARG=[my]/# CONFIG_$ARG is not set/"
+ set_var "CONFIG_$B" "# CONFIG_$B is not set" "CONFIG_$A"
shift
shift
;;
@@ -133,10 +151,7 @@ while [ "$1" != "" ] ; do
A=$ARG
checkarg "$2"
B=$ARG
- replace "/CONFIG_$A=[my]/aCONFIG_$B=m" \
- -e "/# CONFIG_$ARG is not set/a/CONFIG_$ARG=m" \
- -e "s/CONFIG_$ARG=y/CONFIG_$ARG=m/" \
- -e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=m/"
+ set_var "CONFIG_$B" "CONFIG_$B=m" "CONFIG_$A"
shift
shift
;;
--
1.6.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] kbuild: simplify argument loop in scripts/config
[not found] <cover.1243255664.git.mmarek@suse.cz>
2009-05-25 12:55 ` [PATCH 1/3] kbuild: handle non-existing options in scripts/config Michal Marek
@ 2009-05-25 12:55 ` Michal Marek
2009-05-25 12:55 ` [PATCH 3/3] kbuild: add generic --set option to scripts/config Michal Marek
2 siblings, 0 replies; 8+ messages in thread
From: Michal Marek @ 2009-05-25 12:55 UTC (permalink / raw)
To: Andi Kleen; +Cc: Sam Ravnborg, linux-kernel
Signed-off-by: Michal Marek <mmarek@suse.cz>
---
scripts/config | 44 ++++++++++++++++----------------------------
1 files changed, 16 insertions(+), 28 deletions(-)
diff --git a/scripts/config b/scripts/config
index 144e4b0..731c4a7 100755
--- a/scripts/config
+++ b/scripts/config
@@ -77,8 +77,7 @@ if [ "$1" = "--file" ]; then
if [ "$FN" = "" ] ; then
usage
fi
- shift
- shift
+ shift 2
else
FN=.config
fi
@@ -91,26 +90,34 @@ while [ "$1" != "" ] ; do
CMD="$1"
shift
case "$CMD" in
- --enable|-e)
+ --refresh)
+ ;;
+ --*-after)
+ checkarg "$1"
+ A=$ARG
+ checkarg "$2"
+ B=$ARG
+ shift 2
+ ;;
+ --*)
checkarg "$1"
- set_var "CONFIG_$ARG" "CONFIG_$ARG=y"
shift
;;
+ esac
+ case "$CMD" in
+ --enable|-e)
+ set_var "CONFIG_$ARG" "CONFIG_$ARG=y"
+ ;;
--disable|-d)
- checkarg "$1"
set_var "CONFIG_$ARG" "# CONFIG_$ARG is not set"
- shift
;;
--module|-m)
- checkarg "$1"
set_var "CONFIG_$ARG" "CONFIG_$ARG=m"
- shift
;;
--state|-s)
- checkarg "$1"
if grep -q "# CONFIG_$ARG is not set" $FN ; then
echo n
else
@@ -123,37 +130,18 @@ while [ "$1" != "" ] ; do
echo "$V"
fi
fi
- shift
;;
--enable-after|-E)
- checkarg "$1"
- A=$ARG
- checkarg "$2"
- B=$ARG
set_var "CONFIG_$B" "CONFIG_$B=y" "CONFIG_$A"
- shift
- shift
;;
--disable-after|-D)
- checkarg "$1"
- A=$ARG
- checkarg "$2"
- B=$ARG
set_var "CONFIG_$B" "# CONFIG_$B is not set" "CONFIG_$A"
- shift
- shift
;;
--module-after|-M)
- checkarg "$1"
- A=$ARG
- checkarg "$2"
- B=$ARG
set_var "CONFIG_$B" "CONFIG_$B=m" "CONFIG_$A"
- shift
- shift
;;
# undocumented because it ignores --file (fixme)
--
1.6.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] kbuild: add generic --set option to scripts/config
[not found] <cover.1243255664.git.mmarek@suse.cz>
2009-05-25 12:55 ` [PATCH 1/3] kbuild: handle non-existing options in scripts/config Michal Marek
2009-05-25 12:55 ` [PATCH 2/3] kbuild: simplify argument loop " Michal Marek
@ 2009-05-25 12:55 ` Michal Marek
2009-05-25 13:13 ` Andi Kleen
2 siblings, 1 reply; 8+ messages in thread
From: Michal Marek @ 2009-05-25 12:55 UTC (permalink / raw)
To: Andi Kleen; +Cc: Sam Ravnborg, linux-kernel
Signed-off-by: Michal Marek <mmarek@suse.cz>
---
scripts/config | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/scripts/config b/scripts/config
index 731c4a7..38eeff7 100755
--- a/scripts/config
+++ b/scripts/config
@@ -9,8 +9,11 @@ config options command ...
commands:
--enable|-e option Enable option
--disable|-d option Disable option
- --module|-m option Turn option into a module
- --state|-s option Print state of option (n,y,m,undef)
+ --module|-m option Turn option into a module
+ --set option value Set option to arbitrary value
+ --set-str option value
+ Same as --set, bu quote value
+ --state|-s option Print state of option (n,y,m,undef)
--enable-after|-E beforeopt option
Enable option directly after other option
@@ -117,6 +120,16 @@ while [ "$1" != "" ] ; do
set_var "CONFIG_$ARG" "CONFIG_$ARG=m"
;;
+ --set)
+ set_var "CONFIG_$ARG" "CONFIG_$ARG=$1"
+ shift
+ ;;
+
+ --set-str)
+ set_var "CONFIG_$ARG" "CONFIG_$ARG=\"$1\""
+ shift
+ ;;
+
--state|-s)
if grep -q "# CONFIG_$ARG is not set" $FN ; then
echo n
--
1.6.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] kbuild: handle non-existing options in scripts/config
2009-05-25 12:55 ` [PATCH 1/3] kbuild: handle non-existing options in scripts/config Michal Marek
@ 2009-05-25 13:11 ` Andi Kleen
2009-05-25 13:21 ` Michal Marek
0 siblings, 1 reply; 8+ messages in thread
From: Andi Kleen @ 2009-05-25 13:11 UTC (permalink / raw)
To: Michal Marek; +Cc: Andi Kleen, Sam Ravnborg, linux-kernel
> -replace() {
> - sed -i -e "$@" $FN
> +# set_var name value [before-var]
> +set_var() {
> + awk -vvar="$1" -vnew="$2" -vbefore="$3" '
This seems rather complicated compared to what was there before.
I would just cmp the output file to the input file and if they are
the same then add it at the end with a echo
> + }
> + ' "$FN" >"$FN.tmp"
This should be a &&, otherwise you risk removing the output file
on ctrl-c
-Andi
--
ak@linux.intel.com -- Speaking for myself only.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] kbuild: add generic --set option to scripts/config
2009-05-25 12:55 ` [PATCH 3/3] kbuild: add generic --set option to scripts/config Michal Marek
@ 2009-05-25 13:13 ` Andi Kleen
2009-05-25 13:25 ` Michal Marek
0 siblings, 1 reply; 8+ messages in thread
From: Andi Kleen @ 2009-05-25 13:13 UTC (permalink / raw)
To: Michal Marek; +Cc: Andi Kleen, Sam Ravnborg, linux-kernel
> - --module|-m option Turn option into a module
> - --state|-s option Print state of option (n,y,m,undef)
> + --module|-m option Turn option into a module
> + --set option value Set option to arbitrary value
--set seems like fluff to me, it's redundant compared to what was there
before.
> + --set-str option value
> + Same as --set, bu quote value
But that's ok.
> + --state|-s option Print state of option (n,y,m,undef)
Thanks.
-Andi
--
ak@linux.intel.com -- Speaking for myself only.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] kbuild: handle non-existing options in scripts/config
2009-05-25 13:11 ` Andi Kleen
@ 2009-05-25 13:21 ` Michal Marek
0 siblings, 0 replies; 8+ messages in thread
From: Michal Marek @ 2009-05-25 13:21 UTC (permalink / raw)
To: Andi Kleen; +Cc: Sam Ravnborg, linux-kernel
Andi Kleen napsal(a):
>> -replace() {
>> - sed -i -e "$@" $FN
>> +# set_var name value [before-var]
>> +set_var() {
>> + awk -vvar="$1" -vnew="$2" -vbefore="$3" '
>
> This seems rather complicated compared to what was there before.
Calling the function is simpler otoh...
> I would just cmp the output file to the input file and if they are
> the same then add it at the end with a echo
Just doing that would duplicate the variable if it was already set to
the desired value, causing a "warning: override: reassigning to symbol"
warning from kbuild.
Hmm, willll try to simplify it somehow.
>
>> + }
>> + ' "$FN" >"$FN.tmp"
>
> This should be a &&, otherwise you risk removing the output file
> on ctrl-c
Ah, good point.
Michal
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] kbuild: add generic --set option to scripts/config
2009-05-25 13:13 ` Andi Kleen
@ 2009-05-25 13:25 ` Michal Marek
0 siblings, 0 replies; 8+ messages in thread
From: Michal Marek @ 2009-05-25 13:25 UTC (permalink / raw)
To: Andi Kleen; +Cc: Sam Ravnborg, linux-kernel
Andi Kleen napsal(a):
>> - --module|-m option Turn option into a module
>> - --state|-s option Print state of option (n,y,m,undef)
>> + --module|-m option Turn option into a module
>> + --set option value Set option to arbitrary value
>
> --set seems like fluff to me, it's redundant compared to what was there
> before.
It could be useful for setting integer options. I personally don't need
that, I just added it for completeness. I can remove it if you don't
like it.
Michal
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] kbuild: handle non-existing options in scripts/config
[not found] <cover.1243262102.git.mmarek@suse.cz>
@ 2009-05-25 14:43 ` Michal Marek
0 siblings, 0 replies; 8+ messages in thread
From: Michal Marek @ 2009-05-25 14:43 UTC (permalink / raw)
To: Andi Kleen; +Cc: Sam Ravnborg, linux-kernel
If an option does not exist in .config, set it at the end of the file.
Signed-off-by: Michal Marek <mmarek@suse.cz>
---
scripts/config | 46 ++++++++++++++++++++++++++++------------------
1 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/scripts/config b/scripts/config
index db6084b..22cceff 100755
--- a/scripts/config
+++ b/scripts/config
@@ -26,8 +26,6 @@ options:
config doesn't check the validity of the .config file. This is done at next
make time.
-The options need to be already in the file before they can be changed,
-but sometimes you can cheat with the --*-after options.
EOL
exit 1
}
@@ -45,8 +43,28 @@ checkarg() {
ARG="`echo $ARG | tr a-z A-Z`"
}
-replace() {
- sed -i -e "$@" $FN
+# set_var name value [before-var]
+set_var() {
+ awk -vnew="$2" "
+ /^# $1 is not set|^$1=/ {
+ if (new)
+ print new;
+ new = 0;
+ next;
+ }
+ \"$3\" && /^# $3 is not set|^$3=/ {
+ print;
+ if (new)
+ print new;
+ new = 0;
+ next;
+ }
+ { print }
+ END {
+ if (new)
+ print new;
+ }
+ " "$FN" >"$FN.tmp" && mv -f "$FN.tmp" "$FN"
}
if [ "$1" = "--file" ]; then
@@ -70,20 +88,19 @@ while [ "$1" != "" ] ; do
case "$CMD" in
--enable|-e)
checkarg "$1"
- replace "s/# CONFIG_$ARG is not set/CONFIG_$ARG=y/"
+ set_var "CONFIG_$ARG" "CONFIG_$ARG=y"
shift
;;
--disable|-d)
checkarg "$1"
- replace "s/CONFIG_$ARG=[my]/# CONFIG_$ARG is not set/"
+ set_var "CONFIG_$ARG" "# CONFIG_$ARG is not set"
shift
;;
--module|-m)
checkarg "$1"
- replace "s/CONFIG_$ARG=y/CONFIG_$ARG=m/" \
- -e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=m/"
+ set_var "CONFIG_$ARG" "CONFIG_$ARG=m"
shift
;;
@@ -109,9 +126,7 @@ while [ "$1" != "" ] ; do
A=$ARG
checkarg "$2"
B=$ARG
- replace "/CONFIG_$A=[my]/aCONFIG_$B=y" \
- -e "/# CONFIG_$ARG is not set/a/CONFIG_$ARG=y" \
- -e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=y/"
+ set_var "CONFIG_$B" "CONFIG_$B=y" "CONFIG_$A"
shift
shift
;;
@@ -121,9 +136,7 @@ while [ "$1" != "" ] ; do
A=$ARG
checkarg "$2"
B=$ARG
- replace "/CONFIG_$A=[my]/a# CONFIG_$B is not set" \
- -e "/# CONFIG_$ARG is not set/a/# CONFIG_$ARG is not set" \
- -e "s/CONFIG_$ARG=[my]/# CONFIG_$ARG is not set/"
+ set_var "CONFIG_$B" "# CONFIG_$B is not set" "CONFIG_$A"
shift
shift
;;
@@ -133,10 +146,7 @@ while [ "$1" != "" ] ; do
A=$ARG
checkarg "$2"
B=$ARG
- replace "/CONFIG_$A=[my]/aCONFIG_$B=m" \
- -e "/# CONFIG_$ARG is not set/a/CONFIG_$ARG=m" \
- -e "s/CONFIG_$ARG=y/CONFIG_$ARG=m/" \
- -e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=m/"
+ set_var "CONFIG_$B" "CONFIG_$B=m" "CONFIG_$A"
shift
shift
;;
--
1.6.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-05-25 14:43 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <cover.1243255664.git.mmarek@suse.cz>
2009-05-25 12:55 ` [PATCH 1/3] kbuild: handle non-existing options in scripts/config Michal Marek
2009-05-25 13:11 ` Andi Kleen
2009-05-25 13:21 ` Michal Marek
2009-05-25 12:55 ` [PATCH 2/3] kbuild: simplify argument loop " Michal Marek
2009-05-25 12:55 ` [PATCH 3/3] kbuild: add generic --set option to scripts/config Michal Marek
2009-05-25 13:13 ` Andi Kleen
2009-05-25 13:25 ` Michal Marek
[not found] <cover.1243262102.git.mmarek@suse.cz>
2009-05-25 14:43 ` [PATCH 1/3] kbuild: handle non-existing options in scripts/config Michal Marek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox