LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more)
@ 2010-07-31 21:29 Sam Ravnborg
  2010-07-31 21:31 ` [PATCH] kconfig: use long options in conf Sam Ravnborg
                   ` (10 more replies)
  0 siblings, 11 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:29 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild, Uwe Kleine-K?nig, Randy Dunlap,
	Roman Zippel, Aristeu Rozanski

This is an update of patches previous posted.

Version 2 have addressed the following feedback:
- Drop the idea of introducing allrandconfig (Michal, Randy)
- Do more code refactoring (Michal)
- Use long options in conf.c (Michal)
- savedefconfig shall list symbols in same order as in .config (Uwe)
 
The major feature is the introduction of "make savedefconfig".

Make savedefconfig creates a minimal configuration
as have been discussed recently and which is already
done for arm and powerpc.
savedefconfig utilise the knowledge kconfig has to do so
much faster than the phyton script posted.

The implementation was checked against several arm defconfigs.
This was btw. a great source as it allowed me to finetune the
implementation without having to spent hours looking at the
generated files.

One minor issue was not solved..
when a symbol has a default value that is not within
a valid range (the range may be limited by another symbol),
then savedefconfig saves the config symbol with the default value.
The final configuration is OK and this is so seldom that
it does not matter in practice.
[I found only one symbol that in a few configurations triggered this]

Introducing savedefconfig does not say that I dislike the idea
of specifying defconfigs partly/fully using Kconfig fragments.
We just needed something better than the brute-force phython
script and I could see this being usefull anyway.


The patch also introduce another new target: alldefconfig
alldefconfig creates a configuration with all symbols equals
their default value.
Now where we start to use the default values even more this
can be usefull to check that there is a sensible set of
default values.

alldefconfig proved good as testing for savedefconfig

    make alldefconfig
    make savedefconfig

Creates an empty defconfig file - because all symbols has
their default value.


The patchset in addition contains the following changes:
- use long options in conf.c.
  This increased the readability of this file quite a lot
- rename of loose_nonint_oldconfig to oldnoconfig
- replace nonint_oldconfig with listnewconfig
  listnewconfig does not exit with a failure code
  if there is new options. nonint_oldconfig did so
- improved warnings for recursive dependencies
  this also fixes a segmentation fault I have seen in handling
  recursive dependecies

I consider this version ready for merge.
The patches are created on top of kbuild.git for-next.

I will trim cc: in the actual patches.

Note: the patch from Roman Zippel is an old patch I digged up.
Unfortunately I have not heard from Roman lately.
I have in private mail suggested Michal to take over
kconfig maintainership to document the current state of affairs.

	Sam

Roman Zippel (1):
      kconfig: print more info when we see a recursive dependency

Sam Ravnborg (8):
      kconfig: use long options in conf
      kconfig: rename loose_nonint_oldconfig => oldnoconfig
      kconfig: change nonint_oldconfig to listnewconfig
      kconfig: save location of config symbols
      kconfig: add alldefconfig
      kconfig: refactor code in symbol.c
      kconfig: code refactoring in confdata.c
      kconfig: add savedefconfig

 Documentation/kbuild/kconfig.txt |    2 +-
 scripts/kconfig/Makefile         |   87 ++++++-------
 scripts/kconfig/conf.c           |  196 ++++++++++++++--------------
 scripts/kconfig/confdata.c       |  213 +++++++++++++++++++++----------
 scripts/kconfig/expr.h           |    1 +
 scripts/kconfig/lkc.h            |    2 +
 scripts/kconfig/lkc_proto.h      |    1 +
 scripts/kconfig/menu.c           |    2 +
 scripts/kconfig/symbol.c         |  264 ++++++++++++++++++++++++++++++++++----
 9 files changed, 526 insertions(+), 242 deletions(-)


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH] kconfig: use long options in conf
  2010-07-31 21:29 [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
@ 2010-07-31 21:31 ` Sam Ravnborg
  2010-07-31 21:31 ` [PATCH] kconfig: rename loose_nonint_oldconfig => oldnoconfig Sam Ravnborg
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:31 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Sam Ravnborg

The list of options supported by conf is growing
and their abbreviation did not resemble anything usefull.

So drop the single letter options in favour of long options.

The long options are named equal to what we know from
the make target.
The internal implmentation was changed to match this,
resulting in much more readable code.

Support for short options is dropped - no one is supposed
to call this program direct anyway.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---
 scripts/kconfig/Makefile |   70 +++++++++-----------
 scripts/kconfig/conf.c   |  161 +++++++++++++++++++++------------------------
 2 files changed, 105 insertions(+), 126 deletions(-)

diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 0a34335..b712bdb 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -21,17 +21,17 @@ menuconfig: $(obj)/mconf
 	$< $(Kconfig)
 
 config: $(obj)/conf
-	$< $(Kconfig)
+	$< --oldaskconfig $(Kconfig)
 
 nconfig: $(obj)/nconf
 	$< $(Kconfig)
 
 oldconfig: $(obj)/conf
-	$< -o $(Kconfig)
+	$< --$@ $(Kconfig)
 
 silentoldconfig: $(obj)/conf
 	$(Q)mkdir -p include/generated
-	$< -s $(Kconfig)
+	$< --$@ $(Kconfig)
 
 # if no path is given, then use src directory to find file
 ifdef LSMOD
@@ -44,15 +44,15 @@ endif
 localmodconfig: $(obj)/streamline_config.pl $(obj)/conf
 	$(Q)mkdir -p include/generated
 	$(Q)perl $< $(srctree) $(Kconfig) $(LSMOD_F) > .tmp.config
-	$(Q)if [ -f .config ]; then 				\
-			cmp -s .tmp.config .config ||		\
-			(mv -f .config .config.old.1;		\
-			 mv -f .tmp.config .config;		\
-			 $(obj)/conf -s $(Kconfig);		\
-			 mv -f .config.old.1 .config.old)	\
-	else							\
-			mv -f .tmp.config .config;		\
-			$(obj)/conf -s $(Kconfig);		\
+	$(Q)if [ -f .config ]; then					\
+			cmp -s .tmp.config .config ||			\
+			(mv -f .config .config.old.1;			\
+			 mv -f .tmp.config .config;			\
+			 $(obj)/conf --silentoldconfig $(Kconfig);	\
+			 mv -f .config.old.1 .config.old)		\
+	else								\
+			mv -f .tmp.config .config;			\
+			$(obj)/conf --silentoldconfig $(Kconfig);	\
 	fi
 	$(Q)rm -f .tmp.config
 
@@ -60,24 +60,18 @@ localyesconfig: $(obj)/streamline_config.pl $(obj)/conf
 	$(Q)mkdir -p include/generated
 	$(Q)perl $< $(srctree) $(Kconfig) $(LSMOD_F) > .tmp.config
 	$(Q)sed -i s/=m/=y/ .tmp.config
-	$(Q)if [ -f .config ]; then 				\
-			cmp -s .tmp.config .config ||		\
-			(mv -f .config .config.old.1;		\
-			 mv -f .tmp.config .config;		\
-			 $(obj)/conf -s $(Kconfig);		\
-			 mv -f .config.old.1 .config.old)	\
-	else							\
-			mv -f .tmp.config .config;		\
-			$(obj)/conf -s $(Kconfig);		\
+	$(Q)if [ -f .config ]; then					\
+			cmp -s .tmp.config .config ||			\
+			(mv -f .config .config.old.1;			\
+			 mv -f .tmp.config .config;			\
+			 $(obj)/conf --silentoldconfig $(Kconfig);	\
+			 mv -f .config.old.1 .config.old)		\
+	else								\
+			mv -f .tmp.config .config;			\
+			$(obj)/conf --silentoldconfig $(Kconfig);	\
 	fi
 	$(Q)rm -f .tmp.config
 
-nonint_oldconfig: $(obj)/conf
-	$< -b $(Kconfig)
-
-loose_nonint_oldconfig: $(obj)/conf
-	$< -B $(Kconfig)
-
 # Create new linux.pot file
 # Adjust charset to UTF-8 in .po file to accept UTF-8 in Kconfig files
 # The symlink is used to repair a deficiency in arch/um
@@ -101,30 +95,26 @@ update-po-config: $(obj)/kxgettext $(obj)/gconf.glade.h
 	$(Q)rm -f arch/um/Kconfig.arch
 	$(Q)rm -f $(obj)/config.pot
 
-PHONY += randconfig allyesconfig allnoconfig allmodconfig defconfig
-
-randconfig: $(obj)/conf
-	$< -r $(Kconfig)
+PHONY += allnoconfig allyesconfig allmodconfig randconfig
 
-allyesconfig: $(obj)/conf
-	$< -y $(Kconfig)
+allnoconfig allyesconfig allmodconfig randconfig: $(obj)/conf
+	$< --$@ $(Kconfig)
 
-allnoconfig: $(obj)/conf
-	$< -n $(Kconfig)
+PHONY += nonint_oldconfig loose_nonint_oldconfig defconfig
 
-allmodconfig: $(obj)/conf
-	$< -m $(Kconfig)
+nonint_oldconfig loose_nonint_oldconfig: $(obj)/conf
+	$< --$@ $(Kconfig)
 
 defconfig: $(obj)/conf
 ifeq ($(KBUILD_DEFCONFIG),)
-	$< -d $(Kconfig)
+	$< --defconfig $(Kconfig)
 else
 	@echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'"
-	$(Q)$< -D arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
+	$(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
 endif
 
 %_defconfig: $(obj)/conf
-	$(Q)$< -D arch/$(SRCARCH)/configs/$@ $(Kconfig)
+	$(Q)$< --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)
 
 # Help text used by make help
 help:
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index bde01b4..2dec584 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -10,6 +10,7 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+#include <getopt.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 
@@ -23,18 +24,19 @@
 static void conf(struct menu *menu);
 static void check_conf(struct menu *menu);
 
-enum {
-	ask_all,
-	ask_new,
-	ask_silent,
-	dont_ask,
-	dont_ask_dont_tell,
-	set_default,
-	set_yes,
-	set_mod,
-	set_no,
-	set_random
-} input_mode = ask_all;
+enum input_mode {
+	oldaskconfig,
+	silentoldconfig,
+	oldconfig,
+	allnoconfig,
+	allyesconfig,
+	allmodconfig,
+	randconfig,
+	defconfig,
+	nonint_oldconfig,
+	loose_nonint_oldconfig,
+} input_mode = oldaskconfig;
+
 char *defconfig_file;
 
 static int indent = 1;
@@ -100,14 +102,14 @@ static int conf_askvalue(struct symbol *sym, const char *def)
 	}
 
 	switch (input_mode) {
-	case ask_new:
-	case ask_silent:
+	case oldconfig:
+	case silentoldconfig:
 		if (sym_has_value(sym)) {
 			printf("%s\n", def);
 			return 0;
 		}
 		check_stdin();
-	case ask_all:
+	case oldaskconfig:
 		fflush(stdout);
 		fgets(line, 128, stdin);
 		return 1;
@@ -297,15 +299,15 @@ static int conf_choice(struct menu *menu)
 			printf("?");
 		printf("]: ");
 		switch (input_mode) {
-		case ask_new:
-		case ask_silent:
+		case oldconfig:
+		case silentoldconfig:
 			if (!is_new) {
 				cnt = def;
 				printf("%d\n", cnt);
 				break;
 			}
 			check_stdin();
-		case ask_all:
+		case oldaskconfig:
 			fflush(stdout);
 			fgets(line, 128, stdin);
 			strip(line);
@@ -363,9 +365,9 @@ static void conf(struct menu *menu)
 
 		switch (prop->type) {
 		case P_MENU:
-			if ((input_mode == ask_silent ||
-			     input_mode == dont_ask ||
-			     input_mode == dont_ask_dont_tell) &&
+			if ((input_mode == silentoldconfig ||
+			     input_mode == nonint_oldconfig ||
+			     input_mode == loose_nonint_oldconfig) &&
 			    rootEntry != menu) {
 				check_conf(menu);
 				return;
@@ -424,9 +426,9 @@ static void check_conf(struct menu *menu)
 	if (sym && !sym_has_value(sym)) {
 		if (sym_is_changable(sym) ||
 		    (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
-			if (input_mode == dont_ask ||
-			    input_mode == dont_ask_dont_tell) {
-				if (input_mode == dont_ask &&
+			if (input_mode == nonint_oldconfig ||
+			    input_mode == loose_nonint_oldconfig) {
+				if (input_mode == nonint_oldconfig &&
 				    sym->name && !sym_is_choice_value(sym)) {
 					if (!unset_variables)
 						fprintf(stderr, "The following"
@@ -448,6 +450,20 @@ static void check_conf(struct menu *menu)
 		check_conf(child);
 }
 
+static struct option long_opts[] = {
+	{"oldaskconfig",    no_argument,       NULL, oldaskconfig},
+	{"oldconfig",       no_argument,       NULL, oldconfig},
+	{"silentoldconfig", no_argument,       NULL, silentoldconfig},
+	{"defconfig",       optional_argument, NULL, defconfig},
+	{"allnoconfig",     no_argument,       NULL, allnoconfig},
+	{"allyesconfig",    no_argument,       NULL, allyesconfig},
+	{"allmodconfig",    no_argument,       NULL, allmodconfig},
+	{"randconfig",      no_argument,       NULL, randconfig},
+	{"nonint_oldconfig",       no_argument, NULL, nonint_oldconfig},
+	{"loose_nonint_oldconfig", no_argument, NULL, loose_nonint_oldconfig},
+	{NULL, 0, NULL, 0}
+};
+
 int main(int ac, char **av)
 {
 	int opt;
@@ -458,38 +474,16 @@ int main(int ac, char **av)
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
 
-	while ((opt = getopt(ac, av, "osbBdD:nmyrh")) != -1) {
+	while ((opt = getopt_long_only(ac, av, "", long_opts, NULL)) != -1) {
+		input_mode = (enum input_mode)opt;
 		switch (opt) {
-		case 'o':
-			input_mode = ask_silent;
-			break;
-		case 's':
-			input_mode = ask_silent;
+		case silentoldconfig:
 			sync_kconfig = 1;
 			break;
-		case 'b':
-			input_mode = dont_ask;
-			break;
-		case 'B':
-			input_mode = dont_ask_dont_tell;
-			break;
-		case 'd':
-			input_mode = set_default;
-			break;
-		case 'D':
-			input_mode = set_default;
+		case defconfig:
 			defconfig_file = optarg;
 			break;
-		case 'n':
-			input_mode = set_no;
-			break;
-		case 'm':
-			input_mode = set_mod;
-			break;
-		case 'y':
-			input_mode = set_yes;
-			break;
-		case 'r':
+		case randconfig:
 		{
 			struct timeval now;
 			unsigned int seed;
@@ -502,17 +496,12 @@ int main(int ac, char **av)
 
 			seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
 			srand(seed);
-
-			input_mode = set_random;
 			break;
 		}
-		case 'h':
-			printf(_("See README for usage info\n"));
-			exit(0);
-			break;
-		default:
+		case '?':
 			fprintf(stderr, _("See README for usage info\n"));
 			exit(1);
+			break;
 		}
 	}
 	if (ac == optind) {
@@ -537,7 +526,7 @@ int main(int ac, char **av)
 	}
 
 	switch (input_mode) {
-	case set_default:
+	case defconfig:
 		if (!defconfig_file)
 			defconfig_file = conf_get_default_confname();
 		if (conf_read(defconfig_file)) {
@@ -547,27 +536,27 @@ int main(int ac, char **av)
 			exit(1);
 		}
 		break;
-	case ask_silent:
-	case ask_all:
-	case ask_new:
-	case dont_ask:
-	case dont_ask_dont_tell:
+	case silentoldconfig:
+	case oldaskconfig:
+	case oldconfig:
+	case nonint_oldconfig:
+	case loose_nonint_oldconfig:
 		conf_read(NULL);
 		break;
-	case set_no:
-	case set_mod:
-	case set_yes:
-	case set_random:
+	case allnoconfig:
+	case allyesconfig:
+	case allmodconfig:
+	case randconfig:
 		name = getenv("KCONFIG_ALLCONFIG");
 		if (name && !stat(name, &tmpstat)) {
 			conf_read_simple(name, S_DEF_USER);
 			break;
 		}
 		switch (input_mode) {
-		case set_no:	 name = "allno.config"; break;
-		case set_mod:	 name = "allmod.config"; break;
-		case set_yes:	 name = "allyes.config"; break;
-		case set_random: name = "allrandom.config"; break;
+		case allnoconfig:	name = "allno.config"; break;
+		case allyesconfig:	name = "allyes.config"; break;
+		case allmodconfig:	name = "allmod.config"; break;
+		case randconfig:	name = "allrandom.config"; break;
 		default: break;
 		}
 		if (!stat(name, &tmpstat))
@@ -592,37 +581,37 @@ int main(int ac, char **av)
 	}
 
 	switch (input_mode) {
-	case set_no:
+	case allnoconfig:
 		conf_set_all_new_symbols(def_no);
 		break;
-	case set_yes:
+	case allyesconfig:
 		conf_set_all_new_symbols(def_yes);
 		break;
-	case set_mod:
+	case allmodconfig:
 		conf_set_all_new_symbols(def_mod);
 		break;
-	case set_random:
+	case randconfig:
 		conf_set_all_new_symbols(def_random);
 		break;
-	case set_default:
+	case defconfig:
 		conf_set_all_new_symbols(def_default);
 		break;
-	case ask_new:
-	case ask_all:
+	case oldconfig:
+	case oldaskconfig:
 		rootEntry = &rootmenu;
 		conf(&rootmenu);
-		input_mode = ask_silent;
+		input_mode = silentoldconfig;
 		/* fall through */
-	case dont_ask:
-	case dont_ask_dont_tell:
-	case ask_silent:
+	case nonint_oldconfig:
+	case loose_nonint_oldconfig:
+	case silentoldconfig:
 		/* Update until a loop caused no more changes */
 		do {
 			conf_cnt = 0;
 			check_conf(&rootmenu);
 		} while (conf_cnt &&
-			 (input_mode != dont_ask &&
-			  input_mode != dont_ask_dont_tell));
+			 (input_mode != nonint_oldconfig &&
+			  input_mode != loose_nonint_oldconfig));
 		break;
 	}
 
@@ -638,7 +627,7 @@ int main(int ac, char **av)
 			fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
 			return 1;
 		}
-	} else if (!unset_variables || input_mode != dont_ask) {
+	} else if (!unset_variables || input_mode != nonint_oldconfig) {
 		if (conf_write(NULL)) {
 			fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
 			exit(1);
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH] kconfig: rename loose_nonint_oldconfig => oldnoconfig
  2010-07-31 21:29 [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
  2010-07-31 21:31 ` [PATCH] kconfig: use long options in conf Sam Ravnborg
@ 2010-07-31 21:31 ` Sam Ravnborg
  2010-07-31 21:31 ` [PATCH] kconfig: change nonint_oldconfig to listnewconfig Sam Ravnborg
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:31 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Sam Ravnborg, Aristeu Rozanski

Rename target to something that fall more in line
with the other kconfig targets.

oldnoconfig shall read as:

- read the old configuration and set all new options to no

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Aristeu Rozanski <aris@redhat.com>
---
 scripts/kconfig/Makefile |    7 +++----
 scripts/kconfig/conf.c   |   14 +++++++-------
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index b712bdb..0e3c670 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -100,9 +100,9 @@ PHONY += allnoconfig allyesconfig allmodconfig randconfig
 allnoconfig allyesconfig allmodconfig randconfig: $(obj)/conf
 	$< --$@ $(Kconfig)
 
-PHONY += nonint_oldconfig loose_nonint_oldconfig defconfig
+PHONY += nonint_oldconfig oldnoconfig defconfig
 
-nonint_oldconfig loose_nonint_oldconfig: $(obj)/conf
+nonint_oldconfig oldnoconfig: $(obj)/conf
 	$< --$@ $(Kconfig)
 
 defconfig: $(obj)/conf
@@ -134,8 +134,7 @@ help:
 	@echo  '  allnoconfig	  - New config where all options are answered with no'
 	@echo  '  nonint_oldconfig - Checks the current configuration and fails if an option is '
 	@echo  '                    not set'
-	@echo  '  loose_nonint_oldconfig - Same as nonint_oldconfig, but updates the config file with '
-	@echo  '                    missing config options as unset'
+	@echo  '  oldnoconfig     - Same as silentoldconfig but set new symbols to n (unset)'
 
 # lxdialog stuff
 check-lxdialog  := $(srctree)/$(src)/lxdialog/check-lxdialog.sh
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 2dec584..1f86fca 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -34,7 +34,7 @@ enum input_mode {
 	randconfig,
 	defconfig,
 	nonint_oldconfig,
-	loose_nonint_oldconfig,
+	oldnoconfig,
 } input_mode = oldaskconfig;
 
 char *defconfig_file;
@@ -367,7 +367,7 @@ static void conf(struct menu *menu)
 		case P_MENU:
 			if ((input_mode == silentoldconfig ||
 			     input_mode == nonint_oldconfig ||
-			     input_mode == loose_nonint_oldconfig) &&
+			     input_mode == oldnoconfig) &&
 			    rootEntry != menu) {
 				check_conf(menu);
 				return;
@@ -427,7 +427,7 @@ static void check_conf(struct menu *menu)
 		if (sym_is_changable(sym) ||
 		    (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
 			if (input_mode == nonint_oldconfig ||
-			    input_mode == loose_nonint_oldconfig) {
+			    input_mode == oldnoconfig) {
 				if (input_mode == nonint_oldconfig &&
 				    sym->name && !sym_is_choice_value(sym)) {
 					if (!unset_variables)
@@ -460,7 +460,7 @@ static struct option long_opts[] = {
 	{"allmodconfig",    no_argument,       NULL, allmodconfig},
 	{"randconfig",      no_argument,       NULL, randconfig},
 	{"nonint_oldconfig",       no_argument, NULL, nonint_oldconfig},
-	{"loose_nonint_oldconfig", no_argument, NULL, loose_nonint_oldconfig},
+	{"oldnoconfig",     no_argument,       NULL, oldnoconfig},
 	{NULL, 0, NULL, 0}
 };
 
@@ -540,7 +540,7 @@ int main(int ac, char **av)
 	case oldaskconfig:
 	case oldconfig:
 	case nonint_oldconfig:
-	case loose_nonint_oldconfig:
+	case oldnoconfig:
 		conf_read(NULL);
 		break;
 	case allnoconfig:
@@ -603,7 +603,7 @@ int main(int ac, char **av)
 		input_mode = silentoldconfig;
 		/* fall through */
 	case nonint_oldconfig:
-	case loose_nonint_oldconfig:
+	case oldnoconfig:
 	case silentoldconfig:
 		/* Update until a loop caused no more changes */
 		do {
@@ -611,7 +611,7 @@ int main(int ac, char **av)
 			check_conf(&rootmenu);
 		} while (conf_cnt &&
 			 (input_mode != nonint_oldconfig &&
-			  input_mode != loose_nonint_oldconfig));
+			  input_mode != oldnoconfig));
 		break;
 	}
 
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH] kconfig: change nonint_oldconfig to listnewconfig
  2010-07-31 21:29 [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
  2010-07-31 21:31 ` [PATCH] kconfig: use long options in conf Sam Ravnborg
  2010-07-31 21:31 ` [PATCH] kconfig: rename loose_nonint_oldconfig => oldnoconfig Sam Ravnborg
@ 2010-07-31 21:31 ` Sam Ravnborg
  2010-07-31 21:31 ` [PATCH] kconfig: save location of config symbols Sam Ravnborg
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:31 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Sam Ravnborg, Aristeu Rozanski

Rename to a name that better match the other kconfig targets.

listnewconfig shall read as:

- list new options compared to current configuration

New options are now written to stdout so one can redirect the output.

Do not exit with an error code if there is new options.

These are feature changes compared to the original
nonint_oldconfig - but as this feature has not yet been in a
released kernel it should not matter.

It is still possible to do:

make listnewconfig
lookup new config options in Kconfig*
edit .config

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Aristeu Rozanski <aris@redhat.com>
---
 scripts/kconfig/Makefile |    7 +++----
 scripts/kconfig/conf.c   |   34 +++++++++++-----------------------
 2 files changed, 14 insertions(+), 27 deletions(-)

diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 0e3c670..2900d11 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -100,9 +100,9 @@ PHONY += allnoconfig allyesconfig allmodconfig randconfig
 allnoconfig allyesconfig allmodconfig randconfig: $(obj)/conf
 	$< --$@ $(Kconfig)
 
-PHONY += nonint_oldconfig oldnoconfig defconfig
+PHONY += listnewconfig oldnoconfig defconfig
 
-nonint_oldconfig oldnoconfig: $(obj)/conf
+listnewconfig oldnoconfig: $(obj)/conf
 	$< --$@ $(Kconfig)
 
 defconfig: $(obj)/conf
@@ -132,8 +132,7 @@ help:
 	@echo  '  allmodconfig	  - New config selecting modules when possible'
 	@echo  '  allyesconfig	  - New config where all options are accepted with yes'
 	@echo  '  allnoconfig	  - New config where all options are answered with no'
-	@echo  '  nonint_oldconfig - Checks the current configuration and fails if an option is '
-	@echo  '                    not set'
+	@echo  '  listnewconfig   - List new options'
 	@echo  '  oldnoconfig     - Same as silentoldconfig but set new symbols to n (unset)'
 
 # lxdialog stuff
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 1f86fca..ff5c914 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -17,10 +17,6 @@
 #define LKC_DIRECT_LINK
 #include "lkc.h"
 
-/* Return codes */
-#define EUNSETOPT	2	/* if -B and -b are used and unset config
-				 * options were found */
-
 static void conf(struct menu *menu);
 static void check_conf(struct menu *menu);
 
@@ -33,7 +29,7 @@ enum input_mode {
 	allmodconfig,
 	randconfig,
 	defconfig,
-	nonint_oldconfig,
+	listnewconfig,
 	oldnoconfig,
 } input_mode = oldaskconfig;
 
@@ -45,7 +41,6 @@ static int sync_kconfig;
 static int conf_cnt;
 static char line[128];
 static struct menu *rootEntry;
-static int unset_variables;
 
 static void print_help(struct menu *menu)
 {
@@ -366,7 +361,7 @@ static void conf(struct menu *menu)
 		switch (prop->type) {
 		case P_MENU:
 			if ((input_mode == silentoldconfig ||
-			     input_mode == nonint_oldconfig ||
+			     input_mode == listnewconfig ||
 			     input_mode == oldnoconfig) &&
 			    rootEntry != menu) {
 				check_conf(menu);
@@ -426,16 +421,9 @@ static void check_conf(struct menu *menu)
 	if (sym && !sym_has_value(sym)) {
 		if (sym_is_changable(sym) ||
 		    (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
-			if (input_mode == nonint_oldconfig ||
-			    input_mode == oldnoconfig) {
-				if (input_mode == nonint_oldconfig &&
-				    sym->name && !sym_is_choice_value(sym)) {
-					if (!unset_variables)
-						fprintf(stderr, "The following"
-						  " variables are not set:\n");
-					fprintf(stderr, "CONFIG_%s\n",
-							sym->name);
-					unset_variables++;
+			if (input_mode == listnewconfig) {
+				if (sym->name && !sym_is_choice_value(sym)) {
+					printf("CONFIG_%s\n", sym->name);
 				}
 			} else {
 				if (!conf_cnt++)
@@ -459,7 +447,7 @@ static struct option long_opts[] = {
 	{"allyesconfig",    no_argument,       NULL, allyesconfig},
 	{"allmodconfig",    no_argument,       NULL, allmodconfig},
 	{"randconfig",      no_argument,       NULL, randconfig},
-	{"nonint_oldconfig",       no_argument, NULL, nonint_oldconfig},
+	{"listnewconfig",   no_argument,       NULL, listnewconfig},
 	{"oldnoconfig",     no_argument,       NULL, oldnoconfig},
 	{NULL, 0, NULL, 0}
 };
@@ -539,7 +527,7 @@ int main(int ac, char **av)
 	case silentoldconfig:
 	case oldaskconfig:
 	case oldconfig:
-	case nonint_oldconfig:
+	case listnewconfig:
 	case oldnoconfig:
 		conf_read(NULL);
 		break;
@@ -602,7 +590,7 @@ int main(int ac, char **av)
 		conf(&rootmenu);
 		input_mode = silentoldconfig;
 		/* fall through */
-	case nonint_oldconfig:
+	case listnewconfig:
 	case oldnoconfig:
 	case silentoldconfig:
 		/* Update until a loop caused no more changes */
@@ -610,7 +598,7 @@ int main(int ac, char **av)
 			conf_cnt = 0;
 			check_conf(&rootmenu);
 		} while (conf_cnt &&
-			 (input_mode != nonint_oldconfig &&
+			 (input_mode != listnewconfig &&
 			  input_mode != oldnoconfig));
 		break;
 	}
@@ -627,11 +615,11 @@ int main(int ac, char **av)
 			fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
 			return 1;
 		}
-	} else if (!unset_variables || input_mode != nonint_oldconfig) {
+	} else if (input_mode != listnewconfig) {
 		if (conf_write(NULL)) {
 			fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
 			exit(1);
 		}
 	}
-	return unset_variables ? EUNSETOPT : 0;
+	return 0;
 }
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH] kconfig: save location of config symbols
  2010-07-31 21:29 [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
                   ` (2 preceding siblings ...)
  2010-07-31 21:31 ` [PATCH] kconfig: change nonint_oldconfig to listnewconfig Sam Ravnborg
@ 2010-07-31 21:31 ` Sam Ravnborg
  2010-07-31 21:31 ` [PATCH] kconfig: print more info when we see a recursive dependency Sam Ravnborg
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:31 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Sam Ravnborg, Roman Zippel

When we add a new config symbol save the file/line
so we later can refer to their location.

The information is saved as a property to a config symbol
because we may have multiple definitions of the same symbol.

This has the side-effect that a symbol always has
at least one property.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Roman Zippel <zippel@linux-m68k.org>
---
 scripts/kconfig/expr.h   |    1 +
 scripts/kconfig/menu.c   |    2 ++
 scripts/kconfig/symbol.c |    2 ++
 3 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index 75a31e4..6ee2e4f 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -132,6 +132,7 @@ enum prop_type {
 	P_SELECT,   /* select BAR */
 	P_RANGE,    /* range 7..100 (for a symbol) */
 	P_ENV,      /* value from environment variable */
+	P_SYMBOL,   /* where a symbol is defined */
 };
 
 struct property {
diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index 1179989..4fb5902 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -58,6 +58,8 @@ void menu_add_entry(struct symbol *sym)
 	*last_entry_ptr = menu;
 	last_entry_ptr = &menu->next;
 	current_entry = menu;
+	if (sym)
+		menu_add_symbol(P_SYMBOL, sym, NULL);
 }
 
 void menu_end_entry(void)
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index c127fa3..9f180ab 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -961,6 +961,8 @@ const char *prop_get_type_name(enum prop_type type)
 		return "select";
 	case P_RANGE:
 		return "range";
+	case P_SYMBOL:
+		return "symbol";
 	case P_UNKNOWN:
 		break;
 	}
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH] kconfig: print more info when we see a recursive dependency
  2010-07-31 21:29 [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
                   ` (3 preceding siblings ...)
  2010-07-31 21:31 ` [PATCH] kconfig: save location of config symbols Sam Ravnborg
@ 2010-07-31 21:31 ` Sam Ravnborg
  2010-07-31 21:31 ` [PATCH] kconfig: add alldefconfig Sam Ravnborg
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:31 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Roman Zippel, Sam Ravnborg

From: Roman Zippel <zippel@linux-m68k.org>

Consider following kconfig file:

config TEST1
	bool "test 1"
	depends on TEST2

config TEST2
	bool "test 2"
	depends on TEST1

Previously kconfig would report:

foo:6:error: found recursive dependency: TEST2 -> TEST1 -> TEST2

With the following patch kconfig reports:
foo:5:error: recursive dependency detected!
foo:5:  symbol TEST2 depends on TEST1
foo:1:  symbol TEST1 depends on TEST2

Note that we now report where the offending symbols are defined.
This can be a great help for complex situations involving
several files.

Patch is originally from Roman Zippel with a few adjustments by Sam.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Roman Zippel <zippel@linux-m68k.org>
---
 scripts/kconfig/symbol.c |  142 +++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 127 insertions(+), 15 deletions(-)

diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 9f180ab..bc1e158 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -783,6 +783,110 @@ struct symbol **sym_re_search(const char *pattern)
 	return sym_arr;
 }
 
+/*
+ * When we check for recursive dependencies we use a stack to save
+ * current state so we can print out relevant info to user.
+ * The entries are located on the call stack so no need to free memory.
+ * Note inser() remove() must always match to properly clear the stack.
+ */
+static struct dep_stack {
+	struct dep_stack *prev, *next;
+	struct symbol *sym;
+	struct property *prop;
+	struct expr *expr;
+} *check_top;
+
+static void dep_stack_insert(struct dep_stack *stack, struct symbol *sym)
+{
+	memset(stack, 0, sizeof(*stack));
+	if (check_top)
+		check_top->next = stack;
+	stack->prev = check_top;
+	stack->sym = sym;
+	check_top = stack;
+}
+
+static void dep_stack_remove(void)
+{
+	check_top = check_top->prev;
+	if (check_top)
+		check_top->next = NULL;
+}
+
+/*
+ * Called when we have detected a recursive dependency.
+ * check_top point to the top of the stact so we use
+ * the ->prev pointer to locate the bottom of the stack.
+ */
+static void sym_check_print_recursive(struct symbol *last_sym)
+{
+	struct dep_stack *stack;
+	struct symbol *sym, *next_sym;
+	struct menu *menu = NULL;
+	struct property *prop;
+	struct dep_stack cv_stack;
+
+	if (sym_is_choice_value(last_sym)) {
+		dep_stack_insert(&cv_stack, last_sym);
+		last_sym = prop_get_symbol(sym_get_choice_prop(last_sym));
+	}
+
+	for (stack = check_top; stack != NULL; stack = stack->prev)
+		if (stack->sym == last_sym)
+			break;
+	if (!stack) {
+		fprintf(stderr, "unexpected recursive dependency error\n");
+		return;
+	}
+
+	for (; stack; stack = stack->next) {
+		sym = stack->sym;
+		next_sym = stack->next ? stack->next->sym : last_sym;
+		prop = stack->prop;
+
+		/* for choice values find the menu entry (used below) */
+		if (sym_is_choice(sym) || sym_is_choice_value(sym)) {
+			for (prop = sym->prop; prop; prop = prop->next) {
+				menu = prop->menu;
+				if (prop->menu)
+					break;
+			}
+		}
+		if (stack->sym == last_sym)
+			fprintf(stderr, "%s:%d:error: recursive dependency detected!\n",
+				prop->file->name, prop->lineno);
+		if (stack->expr) {
+			fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n",
+				prop->file->name, prop->lineno,
+				sym->name ? sym->name : "<choice>",
+				prop_get_type_name(prop->type),
+				next_sym->name ? next_sym->name : "<choice>");
+		} else if (stack->prop) {
+			fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n",
+				prop->file->name, prop->lineno,
+				sym->name ? sym->name : "<choice>",
+				next_sym->name ? next_sym->name : "<choice>");
+		} else if (sym_is_choice(sym)) {
+			fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n",
+				menu->file->name, menu->lineno,
+				sym->name ? sym->name : "<choice>",
+				next_sym->name ? next_sym->name : "<choice>");
+		} else if (sym_is_choice_value(sym)) {
+			fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n",
+				menu->file->name, menu->lineno,
+				sym->name ? sym->name : "<choice>",
+				next_sym->name ? next_sym->name : "<choice>");
+		} else {
+			fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n",
+				prop->file->name, prop->lineno,
+				sym->name ? sym->name : "<choice>",
+				next_sym->name ? next_sym->name : "<choice>");
+		}
+	}
+
+	if (check_top == &cv_stack)
+		dep_stack_remove();
+}
 
 static struct symbol *sym_check_expr_deps(struct expr *e)
 {
@@ -819,24 +923,33 @@ static struct symbol *sym_check_sym_deps(struct symbol *sym)
 {
 	struct symbol *sym2;
 	struct property *prop;
+	struct dep_stack stack;
+
+	dep_stack_insert(&stack, sym);
 
 	sym2 = sym_check_expr_deps(sym->rev_dep.expr);
 	if (sym2)
-		return sym2;
+		goto out;
 
 	for (prop = sym->prop; prop; prop = prop->next) {
 		if (prop->type == P_CHOICE || prop->type == P_SELECT)
 			continue;
+		stack.prop = prop;
 		sym2 = sym_check_expr_deps(prop->visible.expr);
 		if (sym2)
 			break;
 		if (prop->type != P_DEFAULT || sym_is_choice(sym))
 			continue;
+		stack.expr = prop->expr;
 		sym2 = sym_check_expr_deps(prop->expr);
 		if (sym2)
 			break;
+		stack.expr = NULL;
 	}
 
+out:
+	dep_stack_remove();
+
 	return sym2;
 }
 
@@ -845,6 +958,9 @@ static struct symbol *sym_check_choice_deps(struct symbol *choice)
 	struct symbol *sym, *sym2;
 	struct property *prop;
 	struct expr *e;
+	struct dep_stack stack;
+
+	dep_stack_insert(&stack, choice);
 
 	prop = sym_get_choice_prop(choice);
 	expr_list_for_each_sym(prop->expr, e, sym)
@@ -858,10 +974,8 @@ static struct symbol *sym_check_choice_deps(struct symbol *choice)
 
 	expr_list_for_each_sym(prop->expr, e, sym) {
 		sym2 = sym_check_sym_deps(sym);
-		if (sym2) {
-			fprintf(stderr, " -> %s", sym->name);
+		if (sym2)
 			break;
-		}
 	}
 out:
 	expr_list_for_each_sym(prop->expr, e, sym)
@@ -871,6 +985,8 @@ out:
 	    prop_get_symbol(sym_get_choice_prop(sym2)) == choice)
 		sym2 = choice;
 
+	dep_stack_remove();
+
 	return sym2;
 }
 
@@ -880,18 +996,20 @@ struct symbol *sym_check_deps(struct symbol *sym)
 	struct property *prop;
 
 	if (sym->flags & SYMBOL_CHECK) {
-		fprintf(stderr, "%s:%d:error: found recursive dependency: %s",
-		        sym->prop->file->name, sym->prop->lineno,
-			sym->name ? sym->name : "<choice>");
+		sym_check_print_recursive(sym);
 		return sym;
 	}
 	if (sym->flags & SYMBOL_CHECKED)
 		return NULL;
 
 	if (sym_is_choice_value(sym)) {
+		struct dep_stack stack;
+
 		/* for choice groups start the check with main choice symbol */
+		dep_stack_insert(&stack, sym);
 		prop = sym_get_choice_prop(sym);
 		sym2 = sym_check_deps(prop_get_symbol(prop));
+		dep_stack_remove();
 	} else if (sym_is_choice(sym)) {
 		sym2 = sym_check_choice_deps(sym);
 	} else {
@@ -900,14 +1018,8 @@ struct symbol *sym_check_deps(struct symbol *sym)
 		sym->flags &= ~SYMBOL_CHECK;
 	}
 
-	if (sym2) {
-		fprintf(stderr, " -> %s", sym->name ? sym->name : "<choice>");
-		if (sym2 == sym) {
-			fprintf(stderr, "\n");
-			zconfnerrs++;
-			sym2 = NULL;
-		}
-	}
+	if (sym2 && sym2 == sym)
+		sym2 = NULL;
 
 	return sym2;
 }
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH] kconfig: add alldefconfig
  2010-07-31 21:29 [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
                   ` (4 preceding siblings ...)
  2010-07-31 21:31 ` [PATCH] kconfig: print more info when we see a recursive dependency Sam Ravnborg
@ 2010-07-31 21:31 ` Sam Ravnborg
  2010-07-31 21:31 ` [PATCH] kconfig: refactor code in symbol.c Sam Ravnborg
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:31 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Sam Ravnborg

alldefconfig create a configuration with all values set
to their default value (form the Kconfig files).

This may be useful when we try to use more sensible default
values and may also be used in combination with
the minimal defconfigs.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---
 Documentation/kbuild/kconfig.txt |    2 +-
 scripts/kconfig/Makefile         |   13 +++++++------
 scripts/kconfig/conf.c           |    7 +++++++
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/Documentation/kbuild/kconfig.txt b/Documentation/kbuild/kconfig.txt
index b2cb16e..cca46b1 100644
--- a/Documentation/kbuild/kconfig.txt
+++ b/Documentation/kbuild/kconfig.txt
@@ -65,7 +65,7 @@ also use the environment variable KCONFIG_ALLCONFIG as a flag or a
 filename that contains config symbols that the user requires to be
 set to a specific value.  If KCONFIG_ALLCONFIG is used without a
 filename, "make *config" checks for a file named
-"all{yes/mod/no/random}.config" (corresponding to the *config command
+"all{yes/mod/no/def/random}.config" (corresponding to the *config command
 that was used) for symbol values that are to be forced.  If this file
 is not found, it checks for a file named "all.config" to contain forced
 values.
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 2900d11..0bf1fb6 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -95,9 +95,9 @@ update-po-config: $(obj)/kxgettext $(obj)/gconf.glade.h
 	$(Q)rm -f arch/um/Kconfig.arch
 	$(Q)rm -f $(obj)/config.pot
 
-PHONY += allnoconfig allyesconfig allmodconfig randconfig
+PHONY += allnoconfig allyesconfig allmodconfig alldefconfig randconfig
 
-allnoconfig allyesconfig allmodconfig randconfig: $(obj)/conf
+allnoconfig allyesconfig allmodconfig alldefconfig randconfig: $(obj)/conf
 	$< --$@ $(Kconfig)
 
 PHONY += listnewconfig oldnoconfig defconfig
@@ -127,11 +127,12 @@ help:
 	@echo  '  localmodconfig  - Update current config disabling modules not loaded'
 	@echo  '  localyesconfig  - Update current config converting local mods to core'
 	@echo  '  silentoldconfig - Same as oldconfig, but quietly, additionally update deps'
-	@echo  '  randconfig	  - New config with random answer to all options'
-	@echo  '  defconfig	  - New config with default answer to all options'
-	@echo  '  allmodconfig	  - New config selecting modules when possible'
-	@echo  '  allyesconfig	  - New config where all options are accepted with yes'
+	@echo  '  defconfig	  - New config with default from ARCH supplied defconfig'
 	@echo  '  allnoconfig	  - New config where all options are answered with no'
+	@echo  '  allyesconfig	  - New config where all options are accepted with yes'
+	@echo  '  allmodconfig	  - New config selecting modules when possible'
+	@echo  '  alldefconfig    - New config with all symbols set to default'
+	@echo  '  randconfig	  - New config with random answer to all options'
 	@echo  '  listnewconfig   - List new options'
 	@echo  '  oldnoconfig     - Same as silentoldconfig but set new symbols to n (unset)'
 
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index ff5c914..c8bd33c 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -27,6 +27,7 @@ enum input_mode {
 	allnoconfig,
 	allyesconfig,
 	allmodconfig,
+	alldefconfig,
 	randconfig,
 	defconfig,
 	listnewconfig,
@@ -446,6 +447,7 @@ static struct option long_opts[] = {
 	{"allnoconfig",     no_argument,       NULL, allnoconfig},
 	{"allyesconfig",    no_argument,       NULL, allyesconfig},
 	{"allmodconfig",    no_argument,       NULL, allmodconfig},
+	{"alldefconfig",    no_argument,       NULL, alldefconfig},
 	{"randconfig",      no_argument,       NULL, randconfig},
 	{"listnewconfig",   no_argument,       NULL, listnewconfig},
 	{"oldnoconfig",     no_argument,       NULL, oldnoconfig},
@@ -534,6 +536,7 @@ int main(int ac, char **av)
 	case allnoconfig:
 	case allyesconfig:
 	case allmodconfig:
+	case alldefconfig:
 	case randconfig:
 		name = getenv("KCONFIG_ALLCONFIG");
 		if (name && !stat(name, &tmpstat)) {
@@ -544,6 +547,7 @@ int main(int ac, char **av)
 		case allnoconfig:	name = "allno.config"; break;
 		case allyesconfig:	name = "allyes.config"; break;
 		case allmodconfig:	name = "allmod.config"; break;
+		case alldefconfig:	name = "alldef.config"; break;
 		case randconfig:	name = "allrandom.config"; break;
 		default: break;
 		}
@@ -578,6 +582,9 @@ int main(int ac, char **av)
 	case allmodconfig:
 		conf_set_all_new_symbols(def_mod);
 		break;
+	case alldefconfig:
+		conf_set_all_new_symbols(def_default);
+		break;
 	case randconfig:
 		conf_set_all_new_symbols(def_random);
 		break;
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH] kconfig: refactor code in symbol.c
  2010-07-31 21:29 [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
                   ` (5 preceding siblings ...)
  2010-07-31 21:31 ` [PATCH] kconfig: add alldefconfig Sam Ravnborg
@ 2010-07-31 21:31 ` Sam Ravnborg
  2010-07-31 21:31 ` [PATCH] kconfig: code refactoring in confdata.c Sam Ravnborg
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:31 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Sam Ravnborg

Move logic to determine default for a choice to
a separate function.
No functional changes.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---
 scripts/kconfig/lkc.h    |    1 +
 scripts/kconfig/symbol.c |   46 +++++++++++++++++++++++++++++++++-------------
 2 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index ce6549c..755b819 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -126,6 +126,7 @@ void sym_init(void);
 void sym_clear_all_valid(void);
 void sym_set_all_changed(void);
 void sym_set_changed(struct symbol *sym);
+struct symbol *sym_choice_default(struct symbol *sym);
 struct symbol *sym_check_deps(struct symbol *sym);
 struct property *prop_alloc(enum prop_type type, struct symbol *sym);
 struct symbol *prop_get_symbol(struct property *prop);
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index bc1e158..0a013ab 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -226,22 +226,18 @@ static void sym_calc_visibility(struct symbol *sym)
 	}
 }
 
-static struct symbol *sym_calc_choice(struct symbol *sym)
+/*
+ * Find the default symbol for a choice.
+ * First try the default values for the choice symbol
+ * Next locate the first visible choice value
+ * Return NULL if none was found
+ */
+struct symbol *sym_choice_default(struct symbol *sym)
 {
 	struct symbol *def_sym;
 	struct property *prop;
 	struct expr *e;
 
-	/* first calculate all choice values' visibilities */
-	prop = sym_get_choice_prop(sym);
-	expr_list_for_each_sym(prop->expr, e, def_sym)
-		sym_calc_visibility(def_sym);
-
-	/* is the user choice visible? */
-	def_sym = sym->def[S_DEF_USER].val;
-	if (def_sym && def_sym->visible != no)
-		return def_sym;
-
 	/* any of the defaults visible? */
 	for_all_defaults(sym, prop) {
 		prop->visible.tri = expr_calc_value(prop->visible.expr);
@@ -258,11 +254,35 @@ static struct symbol *sym_calc_choice(struct symbol *sym)
 		if (def_sym->visible != no)
 			return def_sym;
 
-	/* no choice? reset tristate value */
-	sym->curr.tri = no;
+	/* failed to locate any defaults */
 	return NULL;
 }
 
+static struct symbol *sym_calc_choice(struct symbol *sym)
+{
+	struct symbol *def_sym;
+	struct property *prop;
+	struct expr *e;
+
+	/* first calculate all choice values' visibilities */
+	prop = sym_get_choice_prop(sym);
+	expr_list_for_each_sym(prop->expr, e, def_sym)
+		sym_calc_visibility(def_sym);
+
+	/* is the user choice visible? */
+	def_sym = sym->def[S_DEF_USER].val;
+	if (def_sym && def_sym->visible != no)
+		return def_sym;
+
+	def_sym = sym_choice_default(sym);
+
+	if (def_sym == NULL)
+		/* no choice? reset tristate value */
+		sym->curr.tri = no;
+
+	return def_sym;
+}
+
 void sym_calc_value(struct symbol *sym)
 {
 	struct symbol_value newval, oldval;
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH] kconfig: code refactoring in confdata.c
  2010-07-31 21:29 [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
                   ` (6 preceding siblings ...)
  2010-07-31 21:31 ` [PATCH] kconfig: refactor code in symbol.c Sam Ravnborg
@ 2010-07-31 21:31 ` Sam Ravnborg
  2010-07-31 21:31 ` [PATCH] kconfig: add savedefconfig Sam Ravnborg
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:31 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Sam Ravnborg

Add a a few local functions to avoid some code duplication
No functional changes.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---
 scripts/kconfig/confdata.c |  137 ++++++++++++++++++++++---------------------
 1 files changed, 70 insertions(+), 67 deletions(-)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 210a49e..d4fd55e 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -396,15 +396,73 @@ int conf_read(const char *name)
 	return 0;
 }
 
+/* Write a S_STRING */
+static void conf_write_string(bool headerfile, const char *name,
+                              const char *str, FILE *out)
+{
+	int l;
+	if (headerfile)
+		fprintf(out, "#define CONFIG_%s \"", name);
+	else
+		fprintf(out, "CONFIG_%s=\"", name);
+
+	while (1) {
+		l = strcspn(str, "\"\\");
+		if (l) {
+			fwrite(str, l, 1, out);
+			str += l;
+		}
+		if (!*str)
+			break;
+		fprintf(out, "\\%c", *str++);
+	}
+	fputs("\"\n", out);
+}
+
+static void conf_write_symbol(struct symbol *sym, enum symbol_type type,
+                              FILE *out, bool write_no)
+{
+	const char *str;
+
+	switch (type) {
+	case S_BOOLEAN:
+	case S_TRISTATE:
+		switch (sym_get_tristate_value(sym)) {
+		case no:
+			if (write_no)
+				fprintf(out, "# CONFIG_%s is not set\n", sym->name);
+			break;
+		case mod:
+			fprintf(out, "CONFIG_%s=m\n", sym->name);
+			break;
+		case yes:
+			fprintf(out, "CONFIG_%s=y\n", sym->name);
+			break;
+		}
+		break;
+	case S_STRING:
+		conf_write_string(false, sym->name, sym_get_string_value(sym), out);
+		break;
+	case S_HEX:
+	case S_INT:
+		str = sym_get_string_value(sym);
+		fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
+		break;
+	case S_OTHER:
+	case S_UNKNOWN:
+		break;
+	}
+}
+
 int conf_write(const char *name)
 {
 	FILE *out;
 	struct symbol *sym;
 	struct menu *menu;
 	const char *basename;
-	char dirname[128], tmpname[128], newname[128];
-	int type, l;
 	const char *str;
+	char dirname[128], tmpname[128], newname[128];
+	enum symbol_type type;
 	time_t now;
 	int use_timestamp = 1;
 	char *env;
@@ -484,50 +542,11 @@ int conf_write(const char *name)
 				if (modules_sym->curr.tri == no)
 					type = S_BOOLEAN;
 			}
-			switch (type) {
-			case S_BOOLEAN:
-			case S_TRISTATE:
-				switch (sym_get_tristate_value(sym)) {
-				case no:
-					fprintf(out, "# CONFIG_%s is not set\n", sym->name);
-					break;
-				case mod:
-					fprintf(out, "CONFIG_%s=m\n", sym->name);
-					break;
-				case yes:
-					fprintf(out, "CONFIG_%s=y\n", sym->name);
-					break;
-				}
-				break;
-			case S_STRING:
-				str = sym_get_string_value(sym);
-				fprintf(out, "CONFIG_%s=\"", sym->name);
-				while (1) {
-					l = strcspn(str, "\"\\");
-					if (l) {
-						fwrite(str, l, 1, out);
-						str += l;
-					}
-					if (!*str)
-						break;
-					fprintf(out, "\\%c", *str++);
-				}
-				fputs("\"\n", out);
-				break;
-			case S_HEX:
-				str = sym_get_string_value(sym);
-				if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) {
-					fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
-					break;
-				}
-			case S_INT:
-				str = sym_get_string_value(sym);
-				fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
-				break;
-			}
+			/* Write config symbol to file */
+			conf_write_symbol(sym, type, out, true);
 		}
 
-	next:
+next:
 		if (menu->list) {
 			menu = menu->list;
 			continue;
@@ -679,7 +698,7 @@ int conf_write_autoconf(void)
 	const char *name;
 	FILE *out, *tristate, *out_h;
 	time_t now;
-	int i, l;
+	int i;
 
 	sym_clear_all_valid();
 
@@ -729,6 +748,11 @@ int conf_write_autoconf(void)
 		sym_calc_value(sym);
 		if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
 			continue;
+
+		/* write symbol to config file */
+		conf_write_symbol(sym, sym->type, out, false);
+
+		/* update autoconf and tristate files */
 		switch (sym->type) {
 		case S_BOOLEAN:
 		case S_TRISTATE:
@@ -736,12 +760,10 @@ int conf_write_autoconf(void)
 			case no:
 				break;
 			case mod:
-				fprintf(out, "CONFIG_%s=m\n", sym->name);
 				fprintf(tristate, "CONFIG_%s=M\n", sym->name);
 				fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name);
 				break;
 			case yes:
-				fprintf(out, "CONFIG_%s=y\n", sym->name);
 				if (sym->type == S_TRISTATE)
 					fprintf(tristate, "CONFIG_%s=Y\n",
 							sym->name);
@@ -750,35 +772,16 @@ int conf_write_autoconf(void)
 			}
 			break;
 		case S_STRING:
-			str = sym_get_string_value(sym);
-			fprintf(out, "CONFIG_%s=\"", sym->name);
-			fprintf(out_h, "#define CONFIG_%s \"", sym->name);
-			while (1) {
-				l = strcspn(str, "\"\\");
-				if (l) {
-					fwrite(str, l, 1, out);
-					fwrite(str, l, 1, out_h);
-					str += l;
-				}
-				if (!*str)
-					break;
-				fprintf(out, "\\%c", *str);
-				fprintf(out_h, "\\%c", *str);
-				str++;
-			}
-			fputs("\"\n", out);
-			fputs("\"\n", out_h);
+			conf_write_string(true, sym->name, sym_get_string_value(sym), out_h);
 			break;
 		case S_HEX:
 			str = sym_get_string_value(sym);
 			if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) {
-				fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
 				fprintf(out_h, "#define CONFIG_%s 0x%s\n", sym->name, str);
 				break;
 			}
 		case S_INT:
 			str = sym_get_string_value(sym);
-			fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
 			fprintf(out_h, "#define CONFIG_%s %s\n", sym->name, str);
 			break;
 		default:
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH] kconfig: add savedefconfig
  2010-07-31 21:29 [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
                   ` (7 preceding siblings ...)
  2010-07-31 21:31 ` [PATCH] kconfig: code refactoring in confdata.c Sam Ravnborg
@ 2010-07-31 21:31 ` Sam Ravnborg
  2010-07-31 21:34 ` [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
  2010-08-03 12:30 ` [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Michal Marek
  10 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:31 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Sam Ravnborg

savedefconfig will save a minimal config to a file
named "defconfig".

The config symbols are saved in the same order as
they appear in the menu structure so it should
be possible to map them to the relevant menus
if desired.

The implementation was tested against several minimal
configs for arm which was created using brute-force.

There was one regression related to default numbers
which had their valid range further limited by another symbol.

Sample:

config FOO
	int "foo"
	default 4

config BAR
	int "bar"
	range 0 FOO

If FOO is set to 3 then BAR cannot take a value higher than 3.
But the current implementation will set BAR equal to 4.

This is seldomly used and the final configuration is OK,
and the fix was non-trivial.
So it was documented in the code and left as is.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---
 scripts/kconfig/Makefile    |    6 +++-
 scripts/kconfig/conf.c      |   14 ++++++++
 scripts/kconfig/confdata.c  |   76 +++++++++++++++++++++++++++++++++++++++++++
 scripts/kconfig/lkc.h       |    1 +
 scripts/kconfig/lkc_proto.h |    1 +
 scripts/kconfig/symbol.c    |   74 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 171 insertions(+), 1 deletions(-)

diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 0bf1fb6..647dd5a 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -100,11 +100,14 @@ PHONY += allnoconfig allyesconfig allmodconfig alldefconfig randconfig
 allnoconfig allyesconfig allmodconfig alldefconfig randconfig: $(obj)/conf
 	$< --$@ $(Kconfig)
 
-PHONY += listnewconfig oldnoconfig defconfig
+PHONY += listnewconfig oldnoconfig savedefconfig defconfig
 
 listnewconfig oldnoconfig: $(obj)/conf
 	$< --$@ $(Kconfig)
 
+savedefconfig: $(obj)/conf
+	$< --$@=defconfig $(Kconfig)
+
 defconfig: $(obj)/conf
 ifeq ($(KBUILD_DEFCONFIG),)
 	$< --defconfig $(Kconfig)
@@ -128,6 +131,7 @@ help:
 	@echo  '  localyesconfig  - Update current config converting local mods to core'
 	@echo  '  silentoldconfig - Same as oldconfig, but quietly, additionally update deps'
 	@echo  '  defconfig	  - New config with default from ARCH supplied defconfig'
+	@echo  '  savedefconfig   - Save current config as ./defconfig (minimal config)'
 	@echo  '  allnoconfig	  - New config where all options are answered with no'
 	@echo  '  allyesconfig	  - New config where all options are accepted with yes'
 	@echo  '  allmodconfig	  - New config selecting modules when possible'
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index c8bd33c..010600e 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -30,6 +30,7 @@ enum input_mode {
 	alldefconfig,
 	randconfig,
 	defconfig,
+	savedefconfig,
 	listnewconfig,
 	oldnoconfig,
 } input_mode = oldaskconfig;
@@ -444,6 +445,7 @@ static struct option long_opts[] = {
 	{"oldconfig",       no_argument,       NULL, oldconfig},
 	{"silentoldconfig", no_argument,       NULL, silentoldconfig},
 	{"defconfig",       optional_argument, NULL, defconfig},
+	{"savedefconfig",   required_argument, NULL, savedefconfig},
 	{"allnoconfig",     no_argument,       NULL, allnoconfig},
 	{"allyesconfig",    no_argument,       NULL, allyesconfig},
 	{"allmodconfig",    no_argument,       NULL, allmodconfig},
@@ -471,6 +473,7 @@ int main(int ac, char **av)
 			sync_kconfig = 1;
 			break;
 		case defconfig:
+		case savedefconfig:
 			defconfig_file = optarg;
 			break;
 		case randconfig:
@@ -526,6 +529,9 @@ int main(int ac, char **av)
 			exit(1);
 		}
 		break;
+	case savedefconfig:
+		conf_read(NULL);
+		break;
 	case silentoldconfig:
 	case oldaskconfig:
 	case oldconfig:
@@ -591,6 +597,8 @@ int main(int ac, char **av)
 	case defconfig:
 		conf_set_all_new_symbols(def_default);
 		break;
+	case savedefconfig:
+		break;
 	case oldconfig:
 	case oldaskconfig:
 		rootEntry = &rootmenu;
@@ -622,6 +630,12 @@ int main(int ac, char **av)
 			fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
 			return 1;
 		}
+	} else if (input_mode == savedefconfig) {
+		if (conf_write_defconfig(defconfig_file)) {
+			fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"),
+			        defconfig_file);
+			return 1;
+		}
 	} else if (input_mode != listnewconfig) {
 		if (conf_write(NULL)) {
 			fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index d4fd55e..8de6f51 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -454,6 +454,82 @@ static void conf_write_symbol(struct symbol *sym, enum symbol_type type,
 	}
 }
 
+/*
+ * Write out a minimal config.
+ * All values that has default values are skipped as this is redundant.
+ */
+int conf_write_defconfig(const char *filename)
+{
+	struct symbol *sym;
+	struct menu *menu;
+	FILE *out;
+
+	out = fopen(filename, "w");
+	if (!out)
+		return 1;
+
+	sym_clear_all_valid();
+
+	/* Traverse all menus to find all relevant symbols */
+	menu = rootmenu.list;
+
+	while (menu != NULL)
+	{
+		sym = menu->sym;
+		if (sym == NULL) {
+			if (!menu_is_visible(menu))
+				goto next_menu;
+		} else if (!sym_is_choice(sym)) {
+			sym_calc_value(sym);
+			if (!(sym->flags & SYMBOL_WRITE))
+				goto next_menu;
+			sym->flags &= ~SYMBOL_WRITE;
+			/* If we cannot change the symbol - skip */
+			if (!sym_is_changable(sym))
+				goto next_menu;
+			/* If symbol equals to default value - skip */
+			if (strcmp(sym_get_string_value(sym), sym_get_string_default(sym)) == 0)
+				goto next_menu;
+
+			/*
+			 * If symbol is a choice value and equals to the
+			 * default for a choice - skip.
+			 * But only if value equal to "y".
+			 */
+			if (sym_is_choice_value(sym)) {
+				struct symbol *cs;
+				struct symbol *ds;
+
+				cs = prop_get_symbol(sym_get_choice_prop(sym));
+				ds = sym_choice_default(cs);
+				if (sym == ds) {
+					if ((sym->type == S_BOOLEAN ||
+					sym->type == S_TRISTATE) &&
+					sym_get_tristate_value(sym) == yes)
+						goto next_menu;
+				}
+			}
+			conf_write_symbol(sym, sym->type, out, true);
+		}
+next_menu:
+		if (menu->list != NULL) {
+			menu = menu->list;
+		}
+		else if (menu->next != NULL) {
+			menu = menu->next;
+		} else {
+			while ((menu = menu->parent)) {
+				if (menu->next != NULL) {
+					menu = menu->next;
+					break;
+				}
+			}
+		}
+	}
+	fclose(out);
+	return 0;
+}
+
 int conf_write(const char *name)
 {
 	FILE *out;
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 755b819..76db065 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -127,6 +127,7 @@ void sym_clear_all_valid(void);
 void sym_set_all_changed(void);
 void sym_set_changed(struct symbol *sym);
 struct symbol *sym_choice_default(struct symbol *sym);
+const char *sym_get_string_default(struct symbol *sym);
 struct symbol *sym_check_deps(struct symbol *sym);
 struct property *prop_alloc(enum prop_type type, struct symbol *sym);
 struct symbol *prop_get_symbol(struct property *prop);
diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h
index 7cadcad..9a948c9 100644
--- a/scripts/kconfig/lkc_proto.h
+++ b/scripts/kconfig/lkc_proto.h
@@ -3,6 +3,7 @@
 P(conf_parse,void,(const char *name));
 P(conf_read,int,(const char *name));
 P(conf_read_simple,int,(const char *name, int));
+P(conf_write_defconfig,int,(const char *name));
 P(conf_write,int,(const char *name));
 P(conf_write_autoconf,int,(void));
 P(conf_get_changed,bool,(void));
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 0a013ab..e95718f 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -661,6 +661,80 @@ bool sym_set_string_value(struct symbol *sym, const char *newval)
 	return true;
 }
 
+/*
+ * Find the default value associated to a symbol.
+ * For tristate symbol handle the modules=n case
+ * in which case "m" becomes "y".
+ * If the symbol does not have any default then fallback
+ * to the fixed default values.
+ */
+const char *sym_get_string_default(struct symbol *sym)
+{
+	struct property *prop;
+	struct symbol *ds;
+	const char *str;
+	tristate val;
+
+	sym_calc_visibility(sym);
+	sym_calc_value(modules_sym);
+	val = symbol_no.curr.tri;
+	str = symbol_empty.curr.val;
+
+	/* If symbol has a default value look it up */
+	prop = sym_get_default_prop(sym);
+	if (prop != NULL) {
+		switch (sym->type) {
+		case S_BOOLEAN:
+		case S_TRISTATE:
+			/* The visibility imay limit the value from yes => mod */
+			val = EXPR_AND(expr_calc_value(prop->expr), prop->visible.tri);
+			break;
+		default:
+			/*
+			 * The following fails to handle the situation
+			 * where a default value is further limited by
+			 * the valid range.
+			 */
+			ds = prop_get_symbol(prop);
+			if (ds != NULL) {
+				sym_calc_value(ds);
+				str = (const char *)ds->curr.val;
+			}
+		}
+	}
+
+	/* Handle select statements */
+	val = EXPR_OR(val, sym->rev_dep.tri);
+
+	/* transpose mod to yes if modules are not enabled */
+	if (val == mod)
+		if (!sym_is_choice_value(sym) && modules_sym->curr.tri == no)
+			val = yes;
+
+	/* transpose mod to yes if type is bool */
+	if (sym->type == S_BOOLEAN && val == mod)
+		val = yes;
+
+	switch (sym->type) {
+	case S_BOOLEAN:
+	case S_TRISTATE:
+		switch (val) {
+		case no: return "n";
+		case mod: return "m";
+		case yes: return "y";
+		}
+	case S_INT:
+	case S_HEX:
+		return str;
+	case S_STRING:
+		return str;
+	case S_OTHER:
+	case S_UNKNOWN:
+		break;
+	}
+	return "";
+}
+
 const char *sym_get_string_value(struct symbol *sym)
 {
 	tristate val;
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more)
  2010-07-31 21:29 [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
                   ` (8 preceding siblings ...)
  2010-07-31 21:31 ` [PATCH] kconfig: add savedefconfig Sam Ravnborg
@ 2010-07-31 21:34 ` Sam Ravnborg
  2010-07-31 21:35   ` [PATCH 1/9] kconfig: use long options in conf Sam Ravnborg
                     ` (8 more replies)
  2010-08-03 12:30 ` [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Michal Marek
  10 siblings, 9 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:34 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild

Resend with numbered patches...

	Sam

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 1/9] kconfig: use long options in conf
  2010-07-31 21:34 ` [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
@ 2010-07-31 21:35   ` Sam Ravnborg
  2010-07-31 21:35   ` [PATCH 2/9] kconfig: rename loose_nonint_oldconfig => oldnoconfig Sam Ravnborg
                     ` (7 subsequent siblings)
  8 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:35 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Sam Ravnborg

The list of options supported by conf is growing
and their abbreviation did not resemble anything usefull.

So drop the single letter options in favour of long options.

The long options are named equal to what we know from
the make target.
The internal implmentation was changed to match this,
resulting in much more readable code.

Support for short options is dropped - no one is supposed
to call this program direct anyway.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---
 scripts/kconfig/Makefile |   70 +++++++++-----------
 scripts/kconfig/conf.c   |  161 +++++++++++++++++++++------------------------
 2 files changed, 105 insertions(+), 126 deletions(-)

diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 0a34335..b712bdb 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -21,17 +21,17 @@ menuconfig: $(obj)/mconf
 	$< $(Kconfig)
 
 config: $(obj)/conf
-	$< $(Kconfig)
+	$< --oldaskconfig $(Kconfig)
 
 nconfig: $(obj)/nconf
 	$< $(Kconfig)
 
 oldconfig: $(obj)/conf
-	$< -o $(Kconfig)
+	$< --$@ $(Kconfig)
 
 silentoldconfig: $(obj)/conf
 	$(Q)mkdir -p include/generated
-	$< -s $(Kconfig)
+	$< --$@ $(Kconfig)
 
 # if no path is given, then use src directory to find file
 ifdef LSMOD
@@ -44,15 +44,15 @@ endif
 localmodconfig: $(obj)/streamline_config.pl $(obj)/conf
 	$(Q)mkdir -p include/generated
 	$(Q)perl $< $(srctree) $(Kconfig) $(LSMOD_F) > .tmp.config
-	$(Q)if [ -f .config ]; then 				\
-			cmp -s .tmp.config .config ||		\
-			(mv -f .config .config.old.1;		\
-			 mv -f .tmp.config .config;		\
-			 $(obj)/conf -s $(Kconfig);		\
-			 mv -f .config.old.1 .config.old)	\
-	else							\
-			mv -f .tmp.config .config;		\
-			$(obj)/conf -s $(Kconfig);		\
+	$(Q)if [ -f .config ]; then					\
+			cmp -s .tmp.config .config ||			\
+			(mv -f .config .config.old.1;			\
+			 mv -f .tmp.config .config;			\
+			 $(obj)/conf --silentoldconfig $(Kconfig);	\
+			 mv -f .config.old.1 .config.old)		\
+	else								\
+			mv -f .tmp.config .config;			\
+			$(obj)/conf --silentoldconfig $(Kconfig);	\
 	fi
 	$(Q)rm -f .tmp.config
 
@@ -60,24 +60,18 @@ localyesconfig: $(obj)/streamline_config.pl $(obj)/conf
 	$(Q)mkdir -p include/generated
 	$(Q)perl $< $(srctree) $(Kconfig) $(LSMOD_F) > .tmp.config
 	$(Q)sed -i s/=m/=y/ .tmp.config
-	$(Q)if [ -f .config ]; then 				\
-			cmp -s .tmp.config .config ||		\
-			(mv -f .config .config.old.1;		\
-			 mv -f .tmp.config .config;		\
-			 $(obj)/conf -s $(Kconfig);		\
-			 mv -f .config.old.1 .config.old)	\
-	else							\
-			mv -f .tmp.config .config;		\
-			$(obj)/conf -s $(Kconfig);		\
+	$(Q)if [ -f .config ]; then					\
+			cmp -s .tmp.config .config ||			\
+			(mv -f .config .config.old.1;			\
+			 mv -f .tmp.config .config;			\
+			 $(obj)/conf --silentoldconfig $(Kconfig);	\
+			 mv -f .config.old.1 .config.old)		\
+	else								\
+			mv -f .tmp.config .config;			\
+			$(obj)/conf --silentoldconfig $(Kconfig);	\
 	fi
 	$(Q)rm -f .tmp.config
 
-nonint_oldconfig: $(obj)/conf
-	$< -b $(Kconfig)
-
-loose_nonint_oldconfig: $(obj)/conf
-	$< -B $(Kconfig)
-
 # Create new linux.pot file
 # Adjust charset to UTF-8 in .po file to accept UTF-8 in Kconfig files
 # The symlink is used to repair a deficiency in arch/um
@@ -101,30 +95,26 @@ update-po-config: $(obj)/kxgettext $(obj)/gconf.glade.h
 	$(Q)rm -f arch/um/Kconfig.arch
 	$(Q)rm -f $(obj)/config.pot
 
-PHONY += randconfig allyesconfig allnoconfig allmodconfig defconfig
-
-randconfig: $(obj)/conf
-	$< -r $(Kconfig)
+PHONY += allnoconfig allyesconfig allmodconfig randconfig
 
-allyesconfig: $(obj)/conf
-	$< -y $(Kconfig)
+allnoconfig allyesconfig allmodconfig randconfig: $(obj)/conf
+	$< --$@ $(Kconfig)
 
-allnoconfig: $(obj)/conf
-	$< -n $(Kconfig)
+PHONY += nonint_oldconfig loose_nonint_oldconfig defconfig
 
-allmodconfig: $(obj)/conf
-	$< -m $(Kconfig)
+nonint_oldconfig loose_nonint_oldconfig: $(obj)/conf
+	$< --$@ $(Kconfig)
 
 defconfig: $(obj)/conf
 ifeq ($(KBUILD_DEFCONFIG),)
-	$< -d $(Kconfig)
+	$< --defconfig $(Kconfig)
 else
 	@echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'"
-	$(Q)$< -D arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
+	$(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
 endif
 
 %_defconfig: $(obj)/conf
-	$(Q)$< -D arch/$(SRCARCH)/configs/$@ $(Kconfig)
+	$(Q)$< --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)
 
 # Help text used by make help
 help:
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index bde01b4..2dec584 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -10,6 +10,7 @@
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
+#include <getopt.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 
@@ -23,18 +24,19 @@
 static void conf(struct menu *menu);
 static void check_conf(struct menu *menu);
 
-enum {
-	ask_all,
-	ask_new,
-	ask_silent,
-	dont_ask,
-	dont_ask_dont_tell,
-	set_default,
-	set_yes,
-	set_mod,
-	set_no,
-	set_random
-} input_mode = ask_all;
+enum input_mode {
+	oldaskconfig,
+	silentoldconfig,
+	oldconfig,
+	allnoconfig,
+	allyesconfig,
+	allmodconfig,
+	randconfig,
+	defconfig,
+	nonint_oldconfig,
+	loose_nonint_oldconfig,
+} input_mode = oldaskconfig;
+
 char *defconfig_file;
 
 static int indent = 1;
@@ -100,14 +102,14 @@ static int conf_askvalue(struct symbol *sym, const char *def)
 	}
 
 	switch (input_mode) {
-	case ask_new:
-	case ask_silent:
+	case oldconfig:
+	case silentoldconfig:
 		if (sym_has_value(sym)) {
 			printf("%s\n", def);
 			return 0;
 		}
 		check_stdin();
-	case ask_all:
+	case oldaskconfig:
 		fflush(stdout);
 		fgets(line, 128, stdin);
 		return 1;
@@ -297,15 +299,15 @@ static int conf_choice(struct menu *menu)
 			printf("?");
 		printf("]: ");
 		switch (input_mode) {
-		case ask_new:
-		case ask_silent:
+		case oldconfig:
+		case silentoldconfig:
 			if (!is_new) {
 				cnt = def;
 				printf("%d\n", cnt);
 				break;
 			}
 			check_stdin();
-		case ask_all:
+		case oldaskconfig:
 			fflush(stdout);
 			fgets(line, 128, stdin);
 			strip(line);
@@ -363,9 +365,9 @@ static void conf(struct menu *menu)
 
 		switch (prop->type) {
 		case P_MENU:
-			if ((input_mode == ask_silent ||
-			     input_mode == dont_ask ||
-			     input_mode == dont_ask_dont_tell) &&
+			if ((input_mode == silentoldconfig ||
+			     input_mode == nonint_oldconfig ||
+			     input_mode == loose_nonint_oldconfig) &&
 			    rootEntry != menu) {
 				check_conf(menu);
 				return;
@@ -424,9 +426,9 @@ static void check_conf(struct menu *menu)
 	if (sym && !sym_has_value(sym)) {
 		if (sym_is_changable(sym) ||
 		    (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
-			if (input_mode == dont_ask ||
-			    input_mode == dont_ask_dont_tell) {
-				if (input_mode == dont_ask &&
+			if (input_mode == nonint_oldconfig ||
+			    input_mode == loose_nonint_oldconfig) {
+				if (input_mode == nonint_oldconfig &&
 				    sym->name && !sym_is_choice_value(sym)) {
 					if (!unset_variables)
 						fprintf(stderr, "The following"
@@ -448,6 +450,20 @@ static void check_conf(struct menu *menu)
 		check_conf(child);
 }
 
+static struct option long_opts[] = {
+	{"oldaskconfig",    no_argument,       NULL, oldaskconfig},
+	{"oldconfig",       no_argument,       NULL, oldconfig},
+	{"silentoldconfig", no_argument,       NULL, silentoldconfig},
+	{"defconfig",       optional_argument, NULL, defconfig},
+	{"allnoconfig",     no_argument,       NULL, allnoconfig},
+	{"allyesconfig",    no_argument,       NULL, allyesconfig},
+	{"allmodconfig",    no_argument,       NULL, allmodconfig},
+	{"randconfig",      no_argument,       NULL, randconfig},
+	{"nonint_oldconfig",       no_argument, NULL, nonint_oldconfig},
+	{"loose_nonint_oldconfig", no_argument, NULL, loose_nonint_oldconfig},
+	{NULL, 0, NULL, 0}
+};
+
 int main(int ac, char **av)
 {
 	int opt;
@@ -458,38 +474,16 @@ int main(int ac, char **av)
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
 
-	while ((opt = getopt(ac, av, "osbBdD:nmyrh")) != -1) {
+	while ((opt = getopt_long_only(ac, av, "", long_opts, NULL)) != -1) {
+		input_mode = (enum input_mode)opt;
 		switch (opt) {
-		case 'o':
-			input_mode = ask_silent;
-			break;
-		case 's':
-			input_mode = ask_silent;
+		case silentoldconfig:
 			sync_kconfig = 1;
 			break;
-		case 'b':
-			input_mode = dont_ask;
-			break;
-		case 'B':
-			input_mode = dont_ask_dont_tell;
-			break;
-		case 'd':
-			input_mode = set_default;
-			break;
-		case 'D':
-			input_mode = set_default;
+		case defconfig:
 			defconfig_file = optarg;
 			break;
-		case 'n':
-			input_mode = set_no;
-			break;
-		case 'm':
-			input_mode = set_mod;
-			break;
-		case 'y':
-			input_mode = set_yes;
-			break;
-		case 'r':
+		case randconfig:
 		{
 			struct timeval now;
 			unsigned int seed;
@@ -502,17 +496,12 @@ int main(int ac, char **av)
 
 			seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
 			srand(seed);
-
-			input_mode = set_random;
 			break;
 		}
-		case 'h':
-			printf(_("See README for usage info\n"));
-			exit(0);
-			break;
-		default:
+		case '?':
 			fprintf(stderr, _("See README for usage info\n"));
 			exit(1);
+			break;
 		}
 	}
 	if (ac == optind) {
@@ -537,7 +526,7 @@ int main(int ac, char **av)
 	}
 
 	switch (input_mode) {
-	case set_default:
+	case defconfig:
 		if (!defconfig_file)
 			defconfig_file = conf_get_default_confname();
 		if (conf_read(defconfig_file)) {
@@ -547,27 +536,27 @@ int main(int ac, char **av)
 			exit(1);
 		}
 		break;
-	case ask_silent:
-	case ask_all:
-	case ask_new:
-	case dont_ask:
-	case dont_ask_dont_tell:
+	case silentoldconfig:
+	case oldaskconfig:
+	case oldconfig:
+	case nonint_oldconfig:
+	case loose_nonint_oldconfig:
 		conf_read(NULL);
 		break;
-	case set_no:
-	case set_mod:
-	case set_yes:
-	case set_random:
+	case allnoconfig:
+	case allyesconfig:
+	case allmodconfig:
+	case randconfig:
 		name = getenv("KCONFIG_ALLCONFIG");
 		if (name && !stat(name, &tmpstat)) {
 			conf_read_simple(name, S_DEF_USER);
 			break;
 		}
 		switch (input_mode) {
-		case set_no:	 name = "allno.config"; break;
-		case set_mod:	 name = "allmod.config"; break;
-		case set_yes:	 name = "allyes.config"; break;
-		case set_random: name = "allrandom.config"; break;
+		case allnoconfig:	name = "allno.config"; break;
+		case allyesconfig:	name = "allyes.config"; break;
+		case allmodconfig:	name = "allmod.config"; break;
+		case randconfig:	name = "allrandom.config"; break;
 		default: break;
 		}
 		if (!stat(name, &tmpstat))
@@ -592,37 +581,37 @@ int main(int ac, char **av)
 	}
 
 	switch (input_mode) {
-	case set_no:
+	case allnoconfig:
 		conf_set_all_new_symbols(def_no);
 		break;
-	case set_yes:
+	case allyesconfig:
 		conf_set_all_new_symbols(def_yes);
 		break;
-	case set_mod:
+	case allmodconfig:
 		conf_set_all_new_symbols(def_mod);
 		break;
-	case set_random:
+	case randconfig:
 		conf_set_all_new_symbols(def_random);
 		break;
-	case set_default:
+	case defconfig:
 		conf_set_all_new_symbols(def_default);
 		break;
-	case ask_new:
-	case ask_all:
+	case oldconfig:
+	case oldaskconfig:
 		rootEntry = &rootmenu;
 		conf(&rootmenu);
-		input_mode = ask_silent;
+		input_mode = silentoldconfig;
 		/* fall through */
-	case dont_ask:
-	case dont_ask_dont_tell:
-	case ask_silent:
+	case nonint_oldconfig:
+	case loose_nonint_oldconfig:
+	case silentoldconfig:
 		/* Update until a loop caused no more changes */
 		do {
 			conf_cnt = 0;
 			check_conf(&rootmenu);
 		} while (conf_cnt &&
-			 (input_mode != dont_ask &&
-			  input_mode != dont_ask_dont_tell));
+			 (input_mode != nonint_oldconfig &&
+			  input_mode != loose_nonint_oldconfig));
 		break;
 	}
 
@@ -638,7 +627,7 @@ int main(int ac, char **av)
 			fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
 			return 1;
 		}
-	} else if (!unset_variables || input_mode != dont_ask) {
+	} else if (!unset_variables || input_mode != nonint_oldconfig) {
 		if (conf_write(NULL)) {
 			fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
 			exit(1);
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 2/9] kconfig: rename loose_nonint_oldconfig => oldnoconfig
  2010-07-31 21:34 ` [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
  2010-07-31 21:35   ` [PATCH 1/9] kconfig: use long options in conf Sam Ravnborg
@ 2010-07-31 21:35   ` Sam Ravnborg
  2010-07-31 21:35   ` [PATCH 3/9] kconfig: change nonint_oldconfig to listnewconfig Sam Ravnborg
                     ` (6 subsequent siblings)
  8 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:35 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Sam Ravnborg, Aristeu Rozanski

Rename target to something that fall more in line
with the other kconfig targets.

oldnoconfig shall read as:

- read the old configuration and set all new options to no

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Aristeu Rozanski <aris@redhat.com>
---
 scripts/kconfig/Makefile |    7 +++----
 scripts/kconfig/conf.c   |   14 +++++++-------
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index b712bdb..0e3c670 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -100,9 +100,9 @@ PHONY += allnoconfig allyesconfig allmodconfig randconfig
 allnoconfig allyesconfig allmodconfig randconfig: $(obj)/conf
 	$< --$@ $(Kconfig)
 
-PHONY += nonint_oldconfig loose_nonint_oldconfig defconfig
+PHONY += nonint_oldconfig oldnoconfig defconfig
 
-nonint_oldconfig loose_nonint_oldconfig: $(obj)/conf
+nonint_oldconfig oldnoconfig: $(obj)/conf
 	$< --$@ $(Kconfig)
 
 defconfig: $(obj)/conf
@@ -134,8 +134,7 @@ help:
 	@echo  '  allnoconfig	  - New config where all options are answered with no'
 	@echo  '  nonint_oldconfig - Checks the current configuration and fails if an option is '
 	@echo  '                    not set'
-	@echo  '  loose_nonint_oldconfig - Same as nonint_oldconfig, but updates the config file with '
-	@echo  '                    missing config options as unset'
+	@echo  '  oldnoconfig     - Same as silentoldconfig but set new symbols to n (unset)'
 
 # lxdialog stuff
 check-lxdialog  := $(srctree)/$(src)/lxdialog/check-lxdialog.sh
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 2dec584..1f86fca 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -34,7 +34,7 @@ enum input_mode {
 	randconfig,
 	defconfig,
 	nonint_oldconfig,
-	loose_nonint_oldconfig,
+	oldnoconfig,
 } input_mode = oldaskconfig;
 
 char *defconfig_file;
@@ -367,7 +367,7 @@ static void conf(struct menu *menu)
 		case P_MENU:
 			if ((input_mode == silentoldconfig ||
 			     input_mode == nonint_oldconfig ||
-			     input_mode == loose_nonint_oldconfig) &&
+			     input_mode == oldnoconfig) &&
 			    rootEntry != menu) {
 				check_conf(menu);
 				return;
@@ -427,7 +427,7 @@ static void check_conf(struct menu *menu)
 		if (sym_is_changable(sym) ||
 		    (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
 			if (input_mode == nonint_oldconfig ||
-			    input_mode == loose_nonint_oldconfig) {
+			    input_mode == oldnoconfig) {
 				if (input_mode == nonint_oldconfig &&
 				    sym->name && !sym_is_choice_value(sym)) {
 					if (!unset_variables)
@@ -460,7 +460,7 @@ static struct option long_opts[] = {
 	{"allmodconfig",    no_argument,       NULL, allmodconfig},
 	{"randconfig",      no_argument,       NULL, randconfig},
 	{"nonint_oldconfig",       no_argument, NULL, nonint_oldconfig},
-	{"loose_nonint_oldconfig", no_argument, NULL, loose_nonint_oldconfig},
+	{"oldnoconfig",     no_argument,       NULL, oldnoconfig},
 	{NULL, 0, NULL, 0}
 };
 
@@ -540,7 +540,7 @@ int main(int ac, char **av)
 	case oldaskconfig:
 	case oldconfig:
 	case nonint_oldconfig:
-	case loose_nonint_oldconfig:
+	case oldnoconfig:
 		conf_read(NULL);
 		break;
 	case allnoconfig:
@@ -603,7 +603,7 @@ int main(int ac, char **av)
 		input_mode = silentoldconfig;
 		/* fall through */
 	case nonint_oldconfig:
-	case loose_nonint_oldconfig:
+	case oldnoconfig:
 	case silentoldconfig:
 		/* Update until a loop caused no more changes */
 		do {
@@ -611,7 +611,7 @@ int main(int ac, char **av)
 			check_conf(&rootmenu);
 		} while (conf_cnt &&
 			 (input_mode != nonint_oldconfig &&
-			  input_mode != loose_nonint_oldconfig));
+			  input_mode != oldnoconfig));
 		break;
 	}
 
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 3/9] kconfig: change nonint_oldconfig to listnewconfig
  2010-07-31 21:34 ` [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
  2010-07-31 21:35   ` [PATCH 1/9] kconfig: use long options in conf Sam Ravnborg
  2010-07-31 21:35   ` [PATCH 2/9] kconfig: rename loose_nonint_oldconfig => oldnoconfig Sam Ravnborg
@ 2010-07-31 21:35   ` Sam Ravnborg
  2010-07-31 21:35   ` [PATCH 4/9] kconfig: save location of config symbols Sam Ravnborg
                     ` (5 subsequent siblings)
  8 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:35 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Sam Ravnborg, Aristeu Rozanski

Rename to a name that better match the other kconfig targets.

listnewconfig shall read as:

- list new options compared to current configuration

New options are now written to stdout so one can redirect the output.

Do not exit with an error code if there is new options.

These are feature changes compared to the original
nonint_oldconfig - but as this feature has not yet been in a
released kernel it should not matter.

It is still possible to do:

make listnewconfig
lookup new config options in Kconfig*
edit .config

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Aristeu Rozanski <aris@redhat.com>
---
 scripts/kconfig/Makefile |    7 +++----
 scripts/kconfig/conf.c   |   34 +++++++++++-----------------------
 2 files changed, 14 insertions(+), 27 deletions(-)

diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 0e3c670..2900d11 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -100,9 +100,9 @@ PHONY += allnoconfig allyesconfig allmodconfig randconfig
 allnoconfig allyesconfig allmodconfig randconfig: $(obj)/conf
 	$< --$@ $(Kconfig)
 
-PHONY += nonint_oldconfig oldnoconfig defconfig
+PHONY += listnewconfig oldnoconfig defconfig
 
-nonint_oldconfig oldnoconfig: $(obj)/conf
+listnewconfig oldnoconfig: $(obj)/conf
 	$< --$@ $(Kconfig)
 
 defconfig: $(obj)/conf
@@ -132,8 +132,7 @@ help:
 	@echo  '  allmodconfig	  - New config selecting modules when possible'
 	@echo  '  allyesconfig	  - New config where all options are accepted with yes'
 	@echo  '  allnoconfig	  - New config where all options are answered with no'
-	@echo  '  nonint_oldconfig - Checks the current configuration and fails if an option is '
-	@echo  '                    not set'
+	@echo  '  listnewconfig   - List new options'
 	@echo  '  oldnoconfig     - Same as silentoldconfig but set new symbols to n (unset)'
 
 # lxdialog stuff
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 1f86fca..ff5c914 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -17,10 +17,6 @@
 #define LKC_DIRECT_LINK
 #include "lkc.h"
 
-/* Return codes */
-#define EUNSETOPT	2	/* if -B and -b are used and unset config
-				 * options were found */
-
 static void conf(struct menu *menu);
 static void check_conf(struct menu *menu);
 
@@ -33,7 +29,7 @@ enum input_mode {
 	allmodconfig,
 	randconfig,
 	defconfig,
-	nonint_oldconfig,
+	listnewconfig,
 	oldnoconfig,
 } input_mode = oldaskconfig;
 
@@ -45,7 +41,6 @@ static int sync_kconfig;
 static int conf_cnt;
 static char line[128];
 static struct menu *rootEntry;
-static int unset_variables;
 
 static void print_help(struct menu *menu)
 {
@@ -366,7 +361,7 @@ static void conf(struct menu *menu)
 		switch (prop->type) {
 		case P_MENU:
 			if ((input_mode == silentoldconfig ||
-			     input_mode == nonint_oldconfig ||
+			     input_mode == listnewconfig ||
 			     input_mode == oldnoconfig) &&
 			    rootEntry != menu) {
 				check_conf(menu);
@@ -426,16 +421,9 @@ static void check_conf(struct menu *menu)
 	if (sym && !sym_has_value(sym)) {
 		if (sym_is_changable(sym) ||
 		    (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
-			if (input_mode == nonint_oldconfig ||
-			    input_mode == oldnoconfig) {
-				if (input_mode == nonint_oldconfig &&
-				    sym->name && !sym_is_choice_value(sym)) {
-					if (!unset_variables)
-						fprintf(stderr, "The following"
-						  " variables are not set:\n");
-					fprintf(stderr, "CONFIG_%s\n",
-							sym->name);
-					unset_variables++;
+			if (input_mode == listnewconfig) {
+				if (sym->name && !sym_is_choice_value(sym)) {
+					printf("CONFIG_%s\n", sym->name);
 				}
 			} else {
 				if (!conf_cnt++)
@@ -459,7 +447,7 @@ static struct option long_opts[] = {
 	{"allyesconfig",    no_argument,       NULL, allyesconfig},
 	{"allmodconfig",    no_argument,       NULL, allmodconfig},
 	{"randconfig",      no_argument,       NULL, randconfig},
-	{"nonint_oldconfig",       no_argument, NULL, nonint_oldconfig},
+	{"listnewconfig",   no_argument,       NULL, listnewconfig},
 	{"oldnoconfig",     no_argument,       NULL, oldnoconfig},
 	{NULL, 0, NULL, 0}
 };
@@ -539,7 +527,7 @@ int main(int ac, char **av)
 	case silentoldconfig:
 	case oldaskconfig:
 	case oldconfig:
-	case nonint_oldconfig:
+	case listnewconfig:
 	case oldnoconfig:
 		conf_read(NULL);
 		break;
@@ -602,7 +590,7 @@ int main(int ac, char **av)
 		conf(&rootmenu);
 		input_mode = silentoldconfig;
 		/* fall through */
-	case nonint_oldconfig:
+	case listnewconfig:
 	case oldnoconfig:
 	case silentoldconfig:
 		/* Update until a loop caused no more changes */
@@ -610,7 +598,7 @@ int main(int ac, char **av)
 			conf_cnt = 0;
 			check_conf(&rootmenu);
 		} while (conf_cnt &&
-			 (input_mode != nonint_oldconfig &&
+			 (input_mode != listnewconfig &&
 			  input_mode != oldnoconfig));
 		break;
 	}
@@ -627,11 +615,11 @@ int main(int ac, char **av)
 			fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
 			return 1;
 		}
-	} else if (!unset_variables || input_mode != nonint_oldconfig) {
+	} else if (input_mode != listnewconfig) {
 		if (conf_write(NULL)) {
 			fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
 			exit(1);
 		}
 	}
-	return unset_variables ? EUNSETOPT : 0;
+	return 0;
 }
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 4/9] kconfig: save location of config symbols
  2010-07-31 21:34 ` [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
                     ` (2 preceding siblings ...)
  2010-07-31 21:35   ` [PATCH 3/9] kconfig: change nonint_oldconfig to listnewconfig Sam Ravnborg
@ 2010-07-31 21:35   ` Sam Ravnborg
  2010-07-31 21:35   ` [PATCH 5/9] kconfig: print more info when we see a recursive dependency Sam Ravnborg
                     ` (4 subsequent siblings)
  8 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:35 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Sam Ravnborg, Roman Zippel

When we add a new config symbol save the file/line
so we later can refer to their location.

The information is saved as a property to a config symbol
because we may have multiple definitions of the same symbol.

This has the side-effect that a symbol always has
at least one property.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Roman Zippel <zippel@linux-m68k.org>
---
 scripts/kconfig/expr.h   |    1 +
 scripts/kconfig/menu.c   |    2 ++
 scripts/kconfig/symbol.c |    2 ++
 3 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index 75a31e4..6ee2e4f 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -132,6 +132,7 @@ enum prop_type {
 	P_SELECT,   /* select BAR */
 	P_RANGE,    /* range 7..100 (for a symbol) */
 	P_ENV,      /* value from environment variable */
+	P_SYMBOL,   /* where a symbol is defined */
 };
 
 struct property {
diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index 1179989..4fb5902 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -58,6 +58,8 @@ void menu_add_entry(struct symbol *sym)
 	*last_entry_ptr = menu;
 	last_entry_ptr = &menu->next;
 	current_entry = menu;
+	if (sym)
+		menu_add_symbol(P_SYMBOL, sym, NULL);
 }
 
 void menu_end_entry(void)
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index c127fa3..9f180ab 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -961,6 +961,8 @@ const char *prop_get_type_name(enum prop_type type)
 		return "select";
 	case P_RANGE:
 		return "range";
+	case P_SYMBOL:
+		return "symbol";
 	case P_UNKNOWN:
 		break;
 	}
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 5/9] kconfig: print more info when we see a recursive dependency
  2010-07-31 21:34 ` [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
                     ` (3 preceding siblings ...)
  2010-07-31 21:35   ` [PATCH 4/9] kconfig: save location of config symbols Sam Ravnborg
@ 2010-07-31 21:35   ` Sam Ravnborg
  2010-07-31 21:35   ` [PATCH 6/9] kconfig: add alldefconfig Sam Ravnborg
                     ` (3 subsequent siblings)
  8 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:35 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Roman Zippel, Sam Ravnborg

From: Roman Zippel <zippel@linux-m68k.org>

Consider following kconfig file:

config TEST1
	bool "test 1"
	depends on TEST2

config TEST2
	bool "test 2"
	depends on TEST1

Previously kconfig would report:

foo:6:error: found recursive dependency: TEST2 -> TEST1 -> TEST2

With the following patch kconfig reports:
foo:5:error: recursive dependency detected!
foo:5:  symbol TEST2 depends on TEST1
foo:1:  symbol TEST1 depends on TEST2

Note that we now report where the offending symbols are defined.
This can be a great help for complex situations involving
several files.

Patch is originally from Roman Zippel with a few adjustments by Sam.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Roman Zippel <zippel@linux-m68k.org>
---
 scripts/kconfig/symbol.c |  142 +++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 127 insertions(+), 15 deletions(-)

diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 9f180ab..bc1e158 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -783,6 +783,110 @@ struct symbol **sym_re_search(const char *pattern)
 	return sym_arr;
 }
 
+/*
+ * When we check for recursive dependencies we use a stack to save
+ * current state so we can print out relevant info to user.
+ * The entries are located on the call stack so no need to free memory.
+ * Note inser() remove() must always match to properly clear the stack.
+ */
+static struct dep_stack {
+	struct dep_stack *prev, *next;
+	struct symbol *sym;
+	struct property *prop;
+	struct expr *expr;
+} *check_top;
+
+static void dep_stack_insert(struct dep_stack *stack, struct symbol *sym)
+{
+	memset(stack, 0, sizeof(*stack));
+	if (check_top)
+		check_top->next = stack;
+	stack->prev = check_top;
+	stack->sym = sym;
+	check_top = stack;
+}
+
+static void dep_stack_remove(void)
+{
+	check_top = check_top->prev;
+	if (check_top)
+		check_top->next = NULL;
+}
+
+/*
+ * Called when we have detected a recursive dependency.
+ * check_top point to the top of the stact so we use
+ * the ->prev pointer to locate the bottom of the stack.
+ */
+static void sym_check_print_recursive(struct symbol *last_sym)
+{
+	struct dep_stack *stack;
+	struct symbol *sym, *next_sym;
+	struct menu *menu = NULL;
+	struct property *prop;
+	struct dep_stack cv_stack;
+
+	if (sym_is_choice_value(last_sym)) {
+		dep_stack_insert(&cv_stack, last_sym);
+		last_sym = prop_get_symbol(sym_get_choice_prop(last_sym));
+	}
+
+	for (stack = check_top; stack != NULL; stack = stack->prev)
+		if (stack->sym == last_sym)
+			break;
+	if (!stack) {
+		fprintf(stderr, "unexpected recursive dependency error\n");
+		return;
+	}
+
+	for (; stack; stack = stack->next) {
+		sym = stack->sym;
+		next_sym = stack->next ? stack->next->sym : last_sym;
+		prop = stack->prop;
+
+		/* for choice values find the menu entry (used below) */
+		if (sym_is_choice(sym) || sym_is_choice_value(sym)) {
+			for (prop = sym->prop; prop; prop = prop->next) {
+				menu = prop->menu;
+				if (prop->menu)
+					break;
+			}
+		}
+		if (stack->sym == last_sym)
+			fprintf(stderr, "%s:%d:error: recursive dependency detected!\n",
+				prop->file->name, prop->lineno);
+		if (stack->expr) {
+			fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n",
+				prop->file->name, prop->lineno,
+				sym->name ? sym->name : "<choice>",
+				prop_get_type_name(prop->type),
+				next_sym->name ? next_sym->name : "<choice>");
+		} else if (stack->prop) {
+			fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n",
+				prop->file->name, prop->lineno,
+				sym->name ? sym->name : "<choice>",
+				next_sym->name ? next_sym->name : "<choice>");
+		} else if (sym_is_choice(sym)) {
+			fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n",
+				menu->file->name, menu->lineno,
+				sym->name ? sym->name : "<choice>",
+				next_sym->name ? next_sym->name : "<choice>");
+		} else if (sym_is_choice_value(sym)) {
+			fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n",
+				menu->file->name, menu->lineno,
+				sym->name ? sym->name : "<choice>",
+				next_sym->name ? next_sym->name : "<choice>");
+		} else {
+			fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n",
+				prop->file->name, prop->lineno,
+				sym->name ? sym->name : "<choice>",
+				next_sym->name ? next_sym->name : "<choice>");
+		}
+	}
+
+	if (check_top == &cv_stack)
+		dep_stack_remove();
+}
 
 static struct symbol *sym_check_expr_deps(struct expr *e)
 {
@@ -819,24 +923,33 @@ static struct symbol *sym_check_sym_deps(struct symbol *sym)
 {
 	struct symbol *sym2;
 	struct property *prop;
+	struct dep_stack stack;
+
+	dep_stack_insert(&stack, sym);
 
 	sym2 = sym_check_expr_deps(sym->rev_dep.expr);
 	if (sym2)
-		return sym2;
+		goto out;
 
 	for (prop = sym->prop; prop; prop = prop->next) {
 		if (prop->type == P_CHOICE || prop->type == P_SELECT)
 			continue;
+		stack.prop = prop;
 		sym2 = sym_check_expr_deps(prop->visible.expr);
 		if (sym2)
 			break;
 		if (prop->type != P_DEFAULT || sym_is_choice(sym))
 			continue;
+		stack.expr = prop->expr;
 		sym2 = sym_check_expr_deps(prop->expr);
 		if (sym2)
 			break;
+		stack.expr = NULL;
 	}
 
+out:
+	dep_stack_remove();
+
 	return sym2;
 }
 
@@ -845,6 +958,9 @@ static struct symbol *sym_check_choice_deps(struct symbol *choice)
 	struct symbol *sym, *sym2;
 	struct property *prop;
 	struct expr *e;
+	struct dep_stack stack;
+
+	dep_stack_insert(&stack, choice);
 
 	prop = sym_get_choice_prop(choice);
 	expr_list_for_each_sym(prop->expr, e, sym)
@@ -858,10 +974,8 @@ static struct symbol *sym_check_choice_deps(struct symbol *choice)
 
 	expr_list_for_each_sym(prop->expr, e, sym) {
 		sym2 = sym_check_sym_deps(sym);
-		if (sym2) {
-			fprintf(stderr, " -> %s", sym->name);
+		if (sym2)
 			break;
-		}
 	}
 out:
 	expr_list_for_each_sym(prop->expr, e, sym)
@@ -871,6 +985,8 @@ out:
 	    prop_get_symbol(sym_get_choice_prop(sym2)) == choice)
 		sym2 = choice;
 
+	dep_stack_remove();
+
 	return sym2;
 }
 
@@ -880,18 +996,20 @@ struct symbol *sym_check_deps(struct symbol *sym)
 	struct property *prop;
 
 	if (sym->flags & SYMBOL_CHECK) {
-		fprintf(stderr, "%s:%d:error: found recursive dependency: %s",
-		        sym->prop->file->name, sym->prop->lineno,
-			sym->name ? sym->name : "<choice>");
+		sym_check_print_recursive(sym);
 		return sym;
 	}
 	if (sym->flags & SYMBOL_CHECKED)
 		return NULL;
 
 	if (sym_is_choice_value(sym)) {
+		struct dep_stack stack;
+
 		/* for choice groups start the check with main choice symbol */
+		dep_stack_insert(&stack, sym);
 		prop = sym_get_choice_prop(sym);
 		sym2 = sym_check_deps(prop_get_symbol(prop));
+		dep_stack_remove();
 	} else if (sym_is_choice(sym)) {
 		sym2 = sym_check_choice_deps(sym);
 	} else {
@@ -900,14 +1018,8 @@ struct symbol *sym_check_deps(struct symbol *sym)
 		sym->flags &= ~SYMBOL_CHECK;
 	}
 
-	if (sym2) {
-		fprintf(stderr, " -> %s", sym->name ? sym->name : "<choice>");
-		if (sym2 == sym) {
-			fprintf(stderr, "\n");
-			zconfnerrs++;
-			sym2 = NULL;
-		}
-	}
+	if (sym2 && sym2 == sym)
+		sym2 = NULL;
 
 	return sym2;
 }
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 6/9] kconfig: add alldefconfig
  2010-07-31 21:34 ` [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
                     ` (4 preceding siblings ...)
  2010-07-31 21:35   ` [PATCH 5/9] kconfig: print more info when we see a recursive dependency Sam Ravnborg
@ 2010-07-31 21:35   ` Sam Ravnborg
  2010-07-31 21:35   ` [PATCH 7/9] kconfig: refactor code in symbol.c Sam Ravnborg
                     ` (2 subsequent siblings)
  8 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:35 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Sam Ravnborg

alldefconfig create a configuration with all values set
to their default value (form the Kconfig files).

This may be useful when we try to use more sensible default
values and may also be used in combination with
the minimal defconfigs.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---
 Documentation/kbuild/kconfig.txt |    2 +-
 scripts/kconfig/Makefile         |   13 +++++++------
 scripts/kconfig/conf.c           |    7 +++++++
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/Documentation/kbuild/kconfig.txt b/Documentation/kbuild/kconfig.txt
index b2cb16e..cca46b1 100644
--- a/Documentation/kbuild/kconfig.txt
+++ b/Documentation/kbuild/kconfig.txt
@@ -65,7 +65,7 @@ also use the environment variable KCONFIG_ALLCONFIG as a flag or a
 filename that contains config symbols that the user requires to be
 set to a specific value.  If KCONFIG_ALLCONFIG is used without a
 filename, "make *config" checks for a file named
-"all{yes/mod/no/random}.config" (corresponding to the *config command
+"all{yes/mod/no/def/random}.config" (corresponding to the *config command
 that was used) for symbol values that are to be forced.  If this file
 is not found, it checks for a file named "all.config" to contain forced
 values.
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 2900d11..0bf1fb6 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -95,9 +95,9 @@ update-po-config: $(obj)/kxgettext $(obj)/gconf.glade.h
 	$(Q)rm -f arch/um/Kconfig.arch
 	$(Q)rm -f $(obj)/config.pot
 
-PHONY += allnoconfig allyesconfig allmodconfig randconfig
+PHONY += allnoconfig allyesconfig allmodconfig alldefconfig randconfig
 
-allnoconfig allyesconfig allmodconfig randconfig: $(obj)/conf
+allnoconfig allyesconfig allmodconfig alldefconfig randconfig: $(obj)/conf
 	$< --$@ $(Kconfig)
 
 PHONY += listnewconfig oldnoconfig defconfig
@@ -127,11 +127,12 @@ help:
 	@echo  '  localmodconfig  - Update current config disabling modules not loaded'
 	@echo  '  localyesconfig  - Update current config converting local mods to core'
 	@echo  '  silentoldconfig - Same as oldconfig, but quietly, additionally update deps'
-	@echo  '  randconfig	  - New config with random answer to all options'
-	@echo  '  defconfig	  - New config with default answer to all options'
-	@echo  '  allmodconfig	  - New config selecting modules when possible'
-	@echo  '  allyesconfig	  - New config where all options are accepted with yes'
+	@echo  '  defconfig	  - New config with default from ARCH supplied defconfig'
 	@echo  '  allnoconfig	  - New config where all options are answered with no'
+	@echo  '  allyesconfig	  - New config where all options are accepted with yes'
+	@echo  '  allmodconfig	  - New config selecting modules when possible'
+	@echo  '  alldefconfig    - New config with all symbols set to default'
+	@echo  '  randconfig	  - New config with random answer to all options'
 	@echo  '  listnewconfig   - List new options'
 	@echo  '  oldnoconfig     - Same as silentoldconfig but set new symbols to n (unset)'
 
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index ff5c914..c8bd33c 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -27,6 +27,7 @@ enum input_mode {
 	allnoconfig,
 	allyesconfig,
 	allmodconfig,
+	alldefconfig,
 	randconfig,
 	defconfig,
 	listnewconfig,
@@ -446,6 +447,7 @@ static struct option long_opts[] = {
 	{"allnoconfig",     no_argument,       NULL, allnoconfig},
 	{"allyesconfig",    no_argument,       NULL, allyesconfig},
 	{"allmodconfig",    no_argument,       NULL, allmodconfig},
+	{"alldefconfig",    no_argument,       NULL, alldefconfig},
 	{"randconfig",      no_argument,       NULL, randconfig},
 	{"listnewconfig",   no_argument,       NULL, listnewconfig},
 	{"oldnoconfig",     no_argument,       NULL, oldnoconfig},
@@ -534,6 +536,7 @@ int main(int ac, char **av)
 	case allnoconfig:
 	case allyesconfig:
 	case allmodconfig:
+	case alldefconfig:
 	case randconfig:
 		name = getenv("KCONFIG_ALLCONFIG");
 		if (name && !stat(name, &tmpstat)) {
@@ -544,6 +547,7 @@ int main(int ac, char **av)
 		case allnoconfig:	name = "allno.config"; break;
 		case allyesconfig:	name = "allyes.config"; break;
 		case allmodconfig:	name = "allmod.config"; break;
+		case alldefconfig:	name = "alldef.config"; break;
 		case randconfig:	name = "allrandom.config"; break;
 		default: break;
 		}
@@ -578,6 +582,9 @@ int main(int ac, char **av)
 	case allmodconfig:
 		conf_set_all_new_symbols(def_mod);
 		break;
+	case alldefconfig:
+		conf_set_all_new_symbols(def_default);
+		break;
 	case randconfig:
 		conf_set_all_new_symbols(def_random);
 		break;
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 7/9] kconfig: refactor code in symbol.c
  2010-07-31 21:34 ` [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
                     ` (5 preceding siblings ...)
  2010-07-31 21:35   ` [PATCH 6/9] kconfig: add alldefconfig Sam Ravnborg
@ 2010-07-31 21:35   ` Sam Ravnborg
  2010-07-31 21:35   ` [PATCH 8/9] kconfig: code refactoring in confdata.c Sam Ravnborg
  2010-07-31 21:35   ` [PATCH 9/9] kconfig: add savedefconfig Sam Ravnborg
  8 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:35 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Sam Ravnborg

Move logic to determine default for a choice to
a separate function.
No functional changes.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---
 scripts/kconfig/lkc.h    |    1 +
 scripts/kconfig/symbol.c |   46 +++++++++++++++++++++++++++++++++-------------
 2 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index ce6549c..755b819 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -126,6 +126,7 @@ void sym_init(void);
 void sym_clear_all_valid(void);
 void sym_set_all_changed(void);
 void sym_set_changed(struct symbol *sym);
+struct symbol *sym_choice_default(struct symbol *sym);
 struct symbol *sym_check_deps(struct symbol *sym);
 struct property *prop_alloc(enum prop_type type, struct symbol *sym);
 struct symbol *prop_get_symbol(struct property *prop);
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index bc1e158..0a013ab 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -226,22 +226,18 @@ static void sym_calc_visibility(struct symbol *sym)
 	}
 }
 
-static struct symbol *sym_calc_choice(struct symbol *sym)
+/*
+ * Find the default symbol for a choice.
+ * First try the default values for the choice symbol
+ * Next locate the first visible choice value
+ * Return NULL if none was found
+ */
+struct symbol *sym_choice_default(struct symbol *sym)
 {
 	struct symbol *def_sym;
 	struct property *prop;
 	struct expr *e;
 
-	/* first calculate all choice values' visibilities */
-	prop = sym_get_choice_prop(sym);
-	expr_list_for_each_sym(prop->expr, e, def_sym)
-		sym_calc_visibility(def_sym);
-
-	/* is the user choice visible? */
-	def_sym = sym->def[S_DEF_USER].val;
-	if (def_sym && def_sym->visible != no)
-		return def_sym;
-
 	/* any of the defaults visible? */
 	for_all_defaults(sym, prop) {
 		prop->visible.tri = expr_calc_value(prop->visible.expr);
@@ -258,11 +254,35 @@ static struct symbol *sym_calc_choice(struct symbol *sym)
 		if (def_sym->visible != no)
 			return def_sym;
 
-	/* no choice? reset tristate value */
-	sym->curr.tri = no;
+	/* failed to locate any defaults */
 	return NULL;
 }
 
+static struct symbol *sym_calc_choice(struct symbol *sym)
+{
+	struct symbol *def_sym;
+	struct property *prop;
+	struct expr *e;
+
+	/* first calculate all choice values' visibilities */
+	prop = sym_get_choice_prop(sym);
+	expr_list_for_each_sym(prop->expr, e, def_sym)
+		sym_calc_visibility(def_sym);
+
+	/* is the user choice visible? */
+	def_sym = sym->def[S_DEF_USER].val;
+	if (def_sym && def_sym->visible != no)
+		return def_sym;
+
+	def_sym = sym_choice_default(sym);
+
+	if (def_sym == NULL)
+		/* no choice? reset tristate value */
+		sym->curr.tri = no;
+
+	return def_sym;
+}
+
 void sym_calc_value(struct symbol *sym)
 {
 	struct symbol_value newval, oldval;
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 8/9] kconfig: code refactoring in confdata.c
  2010-07-31 21:34 ` [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
                     ` (6 preceding siblings ...)
  2010-07-31 21:35   ` [PATCH 7/9] kconfig: refactor code in symbol.c Sam Ravnborg
@ 2010-07-31 21:35   ` Sam Ravnborg
  2010-07-31 21:35   ` [PATCH 9/9] kconfig: add savedefconfig Sam Ravnborg
  8 siblings, 0 replies; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:35 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Sam Ravnborg

Add a a few local functions to avoid some code duplication
No functional changes.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---
 scripts/kconfig/confdata.c |  137 ++++++++++++++++++++++---------------------
 1 files changed, 70 insertions(+), 67 deletions(-)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 210a49e..d4fd55e 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -396,15 +396,73 @@ int conf_read(const char *name)
 	return 0;
 }
 
+/* Write a S_STRING */
+static void conf_write_string(bool headerfile, const char *name,
+                              const char *str, FILE *out)
+{
+	int l;
+	if (headerfile)
+		fprintf(out, "#define CONFIG_%s \"", name);
+	else
+		fprintf(out, "CONFIG_%s=\"", name);
+
+	while (1) {
+		l = strcspn(str, "\"\\");
+		if (l) {
+			fwrite(str, l, 1, out);
+			str += l;
+		}
+		if (!*str)
+			break;
+		fprintf(out, "\\%c", *str++);
+	}
+	fputs("\"\n", out);
+}
+
+static void conf_write_symbol(struct symbol *sym, enum symbol_type type,
+                              FILE *out, bool write_no)
+{
+	const char *str;
+
+	switch (type) {
+	case S_BOOLEAN:
+	case S_TRISTATE:
+		switch (sym_get_tristate_value(sym)) {
+		case no:
+			if (write_no)
+				fprintf(out, "# CONFIG_%s is not set\n", sym->name);
+			break;
+		case mod:
+			fprintf(out, "CONFIG_%s=m\n", sym->name);
+			break;
+		case yes:
+			fprintf(out, "CONFIG_%s=y\n", sym->name);
+			break;
+		}
+		break;
+	case S_STRING:
+		conf_write_string(false, sym->name, sym_get_string_value(sym), out);
+		break;
+	case S_HEX:
+	case S_INT:
+		str = sym_get_string_value(sym);
+		fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
+		break;
+	case S_OTHER:
+	case S_UNKNOWN:
+		break;
+	}
+}
+
 int conf_write(const char *name)
 {
 	FILE *out;
 	struct symbol *sym;
 	struct menu *menu;
 	const char *basename;
-	char dirname[128], tmpname[128], newname[128];
-	int type, l;
 	const char *str;
+	char dirname[128], tmpname[128], newname[128];
+	enum symbol_type type;
 	time_t now;
 	int use_timestamp = 1;
 	char *env;
@@ -484,50 +542,11 @@ int conf_write(const char *name)
 				if (modules_sym->curr.tri == no)
 					type = S_BOOLEAN;
 			}
-			switch (type) {
-			case S_BOOLEAN:
-			case S_TRISTATE:
-				switch (sym_get_tristate_value(sym)) {
-				case no:
-					fprintf(out, "# CONFIG_%s is not set\n", sym->name);
-					break;
-				case mod:
-					fprintf(out, "CONFIG_%s=m\n", sym->name);
-					break;
-				case yes:
-					fprintf(out, "CONFIG_%s=y\n", sym->name);
-					break;
-				}
-				break;
-			case S_STRING:
-				str = sym_get_string_value(sym);
-				fprintf(out, "CONFIG_%s=\"", sym->name);
-				while (1) {
-					l = strcspn(str, "\"\\");
-					if (l) {
-						fwrite(str, l, 1, out);
-						str += l;
-					}
-					if (!*str)
-						break;
-					fprintf(out, "\\%c", *str++);
-				}
-				fputs("\"\n", out);
-				break;
-			case S_HEX:
-				str = sym_get_string_value(sym);
-				if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) {
-					fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
-					break;
-				}
-			case S_INT:
-				str = sym_get_string_value(sym);
-				fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
-				break;
-			}
+			/* Write config symbol to file */
+			conf_write_symbol(sym, type, out, true);
 		}
 
-	next:
+next:
 		if (menu->list) {
 			menu = menu->list;
 			continue;
@@ -679,7 +698,7 @@ int conf_write_autoconf(void)
 	const char *name;
 	FILE *out, *tristate, *out_h;
 	time_t now;
-	int i, l;
+	int i;
 
 	sym_clear_all_valid();
 
@@ -729,6 +748,11 @@ int conf_write_autoconf(void)
 		sym_calc_value(sym);
 		if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
 			continue;
+
+		/* write symbol to config file */
+		conf_write_symbol(sym, sym->type, out, false);
+
+		/* update autoconf and tristate files */
 		switch (sym->type) {
 		case S_BOOLEAN:
 		case S_TRISTATE:
@@ -736,12 +760,10 @@ int conf_write_autoconf(void)
 			case no:
 				break;
 			case mod:
-				fprintf(out, "CONFIG_%s=m\n", sym->name);
 				fprintf(tristate, "CONFIG_%s=M\n", sym->name);
 				fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name);
 				break;
 			case yes:
-				fprintf(out, "CONFIG_%s=y\n", sym->name);
 				if (sym->type == S_TRISTATE)
 					fprintf(tristate, "CONFIG_%s=Y\n",
 							sym->name);
@@ -750,35 +772,16 @@ int conf_write_autoconf(void)
 			}
 			break;
 		case S_STRING:
-			str = sym_get_string_value(sym);
-			fprintf(out, "CONFIG_%s=\"", sym->name);
-			fprintf(out_h, "#define CONFIG_%s \"", sym->name);
-			while (1) {
-				l = strcspn(str, "\"\\");
-				if (l) {
-					fwrite(str, l, 1, out);
-					fwrite(str, l, 1, out_h);
-					str += l;
-				}
-				if (!*str)
-					break;
-				fprintf(out, "\\%c", *str);
-				fprintf(out_h, "\\%c", *str);
-				str++;
-			}
-			fputs("\"\n", out);
-			fputs("\"\n", out_h);
+			conf_write_string(true, sym->name, sym_get_string_value(sym), out_h);
 			break;
 		case S_HEX:
 			str = sym_get_string_value(sym);
 			if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) {
-				fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
 				fprintf(out_h, "#define CONFIG_%s 0x%s\n", sym->name, str);
 				break;
 			}
 		case S_INT:
 			str = sym_get_string_value(sym);
-			fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
 			fprintf(out_h, "#define CONFIG_%s %s\n", sym->name, str);
 			break;
 		default:
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 9/9] kconfig: add savedefconfig
  2010-07-31 21:34 ` [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
                     ` (7 preceding siblings ...)
  2010-07-31 21:35   ` [PATCH 8/9] kconfig: code refactoring in confdata.c Sam Ravnborg
@ 2010-07-31 21:35   ` Sam Ravnborg
  2010-08-02  8:05     ` Uwe Kleine-König
  8 siblings, 1 reply; 22+ messages in thread
From: Sam Ravnborg @ 2010-07-31 21:35 UTC (permalink / raw
  To: Michal Marek, lkml, linux-kbuild; +Cc: Sam Ravnborg

savedefconfig will save a minimal config to a file
named "defconfig".

The config symbols are saved in the same order as
they appear in the menu structure so it should
be possible to map them to the relevant menus
if desired.

The implementation was tested against several minimal
configs for arm which was created using brute-force.

There was one regression related to default numbers
which had their valid range further limited by another symbol.

Sample:

config FOO
	int "foo"
	default 4

config BAR
	int "bar"
	range 0 FOO

If FOO is set to 3 then BAR cannot take a value higher than 3.
But the current implementation will set BAR equal to 4.

This is seldomly used and the final configuration is OK,
and the fix was non-trivial.
So it was documented in the code and left as is.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---
 scripts/kconfig/Makefile    |    6 +++-
 scripts/kconfig/conf.c      |   14 ++++++++
 scripts/kconfig/confdata.c  |   76 +++++++++++++++++++++++++++++++++++++++++++
 scripts/kconfig/lkc.h       |    1 +
 scripts/kconfig/lkc_proto.h |    1 +
 scripts/kconfig/symbol.c    |   74 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 171 insertions(+), 1 deletions(-)

diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 0bf1fb6..647dd5a 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -100,11 +100,14 @@ PHONY += allnoconfig allyesconfig allmodconfig alldefconfig randconfig
 allnoconfig allyesconfig allmodconfig alldefconfig randconfig: $(obj)/conf
 	$< --$@ $(Kconfig)
 
-PHONY += listnewconfig oldnoconfig defconfig
+PHONY += listnewconfig oldnoconfig savedefconfig defconfig
 
 listnewconfig oldnoconfig: $(obj)/conf
 	$< --$@ $(Kconfig)
 
+savedefconfig: $(obj)/conf
+	$< --$@=defconfig $(Kconfig)
+
 defconfig: $(obj)/conf
 ifeq ($(KBUILD_DEFCONFIG),)
 	$< --defconfig $(Kconfig)
@@ -128,6 +131,7 @@ help:
 	@echo  '  localyesconfig  - Update current config converting local mods to core'
 	@echo  '  silentoldconfig - Same as oldconfig, but quietly, additionally update deps'
 	@echo  '  defconfig	  - New config with default from ARCH supplied defconfig'
+	@echo  '  savedefconfig   - Save current config as ./defconfig (minimal config)'
 	@echo  '  allnoconfig	  - New config where all options are answered with no'
 	@echo  '  allyesconfig	  - New config where all options are accepted with yes'
 	@echo  '  allmodconfig	  - New config selecting modules when possible'
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index c8bd33c..010600e 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -30,6 +30,7 @@ enum input_mode {
 	alldefconfig,
 	randconfig,
 	defconfig,
+	savedefconfig,
 	listnewconfig,
 	oldnoconfig,
 } input_mode = oldaskconfig;
@@ -444,6 +445,7 @@ static struct option long_opts[] = {
 	{"oldconfig",       no_argument,       NULL, oldconfig},
 	{"silentoldconfig", no_argument,       NULL, silentoldconfig},
 	{"defconfig",       optional_argument, NULL, defconfig},
+	{"savedefconfig",   required_argument, NULL, savedefconfig},
 	{"allnoconfig",     no_argument,       NULL, allnoconfig},
 	{"allyesconfig",    no_argument,       NULL, allyesconfig},
 	{"allmodconfig",    no_argument,       NULL, allmodconfig},
@@ -471,6 +473,7 @@ int main(int ac, char **av)
 			sync_kconfig = 1;
 			break;
 		case defconfig:
+		case savedefconfig:
 			defconfig_file = optarg;
 			break;
 		case randconfig:
@@ -526,6 +529,9 @@ int main(int ac, char **av)
 			exit(1);
 		}
 		break;
+	case savedefconfig:
+		conf_read(NULL);
+		break;
 	case silentoldconfig:
 	case oldaskconfig:
 	case oldconfig:
@@ -591,6 +597,8 @@ int main(int ac, char **av)
 	case defconfig:
 		conf_set_all_new_symbols(def_default);
 		break;
+	case savedefconfig:
+		break;
 	case oldconfig:
 	case oldaskconfig:
 		rootEntry = &rootmenu;
@@ -622,6 +630,12 @@ int main(int ac, char **av)
 			fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
 			return 1;
 		}
+	} else if (input_mode == savedefconfig) {
+		if (conf_write_defconfig(defconfig_file)) {
+			fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"),
+			        defconfig_file);
+			return 1;
+		}
 	} else if (input_mode != listnewconfig) {
 		if (conf_write(NULL)) {
 			fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index d4fd55e..8de6f51 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -454,6 +454,82 @@ static void conf_write_symbol(struct symbol *sym, enum symbol_type type,
 	}
 }
 
+/*
+ * Write out a minimal config.
+ * All values that has default values are skipped as this is redundant.
+ */
+int conf_write_defconfig(const char *filename)
+{
+	struct symbol *sym;
+	struct menu *menu;
+	FILE *out;
+
+	out = fopen(filename, "w");
+	if (!out)
+		return 1;
+
+	sym_clear_all_valid();
+
+	/* Traverse all menus to find all relevant symbols */
+	menu = rootmenu.list;
+
+	while (menu != NULL)
+	{
+		sym = menu->sym;
+		if (sym == NULL) {
+			if (!menu_is_visible(menu))
+				goto next_menu;
+		} else if (!sym_is_choice(sym)) {
+			sym_calc_value(sym);
+			if (!(sym->flags & SYMBOL_WRITE))
+				goto next_menu;
+			sym->flags &= ~SYMBOL_WRITE;
+			/* If we cannot change the symbol - skip */
+			if (!sym_is_changable(sym))
+				goto next_menu;
+			/* If symbol equals to default value - skip */
+			if (strcmp(sym_get_string_value(sym), sym_get_string_default(sym)) == 0)
+				goto next_menu;
+
+			/*
+			 * If symbol is a choice value and equals to the
+			 * default for a choice - skip.
+			 * But only if value equal to "y".
+			 */
+			if (sym_is_choice_value(sym)) {
+				struct symbol *cs;
+				struct symbol *ds;
+
+				cs = prop_get_symbol(sym_get_choice_prop(sym));
+				ds = sym_choice_default(cs);
+				if (sym == ds) {
+					if ((sym->type == S_BOOLEAN ||
+					sym->type == S_TRISTATE) &&
+					sym_get_tristate_value(sym) == yes)
+						goto next_menu;
+				}
+			}
+			conf_write_symbol(sym, sym->type, out, true);
+		}
+next_menu:
+		if (menu->list != NULL) {
+			menu = menu->list;
+		}
+		else if (menu->next != NULL) {
+			menu = menu->next;
+		} else {
+			while ((menu = menu->parent)) {
+				if (menu->next != NULL) {
+					menu = menu->next;
+					break;
+				}
+			}
+		}
+	}
+	fclose(out);
+	return 0;
+}
+
 int conf_write(const char *name)
 {
 	FILE *out;
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 755b819..76db065 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -127,6 +127,7 @@ void sym_clear_all_valid(void);
 void sym_set_all_changed(void);
 void sym_set_changed(struct symbol *sym);
 struct symbol *sym_choice_default(struct symbol *sym);
+const char *sym_get_string_default(struct symbol *sym);
 struct symbol *sym_check_deps(struct symbol *sym);
 struct property *prop_alloc(enum prop_type type, struct symbol *sym);
 struct symbol *prop_get_symbol(struct property *prop);
diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h
index 7cadcad..9a948c9 100644
--- a/scripts/kconfig/lkc_proto.h
+++ b/scripts/kconfig/lkc_proto.h
@@ -3,6 +3,7 @@
 P(conf_parse,void,(const char *name));
 P(conf_read,int,(const char *name));
 P(conf_read_simple,int,(const char *name, int));
+P(conf_write_defconfig,int,(const char *name));
 P(conf_write,int,(const char *name));
 P(conf_write_autoconf,int,(void));
 P(conf_get_changed,bool,(void));
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 0a013ab..e95718f 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -661,6 +661,80 @@ bool sym_set_string_value(struct symbol *sym, const char *newval)
 	return true;
 }
 
+/*
+ * Find the default value associated to a symbol.
+ * For tristate symbol handle the modules=n case
+ * in which case "m" becomes "y".
+ * If the symbol does not have any default then fallback
+ * to the fixed default values.
+ */
+const char *sym_get_string_default(struct symbol *sym)
+{
+	struct property *prop;
+	struct symbol *ds;
+	const char *str;
+	tristate val;
+
+	sym_calc_visibility(sym);
+	sym_calc_value(modules_sym);
+	val = symbol_no.curr.tri;
+	str = symbol_empty.curr.val;
+
+	/* If symbol has a default value look it up */
+	prop = sym_get_default_prop(sym);
+	if (prop != NULL) {
+		switch (sym->type) {
+		case S_BOOLEAN:
+		case S_TRISTATE:
+			/* The visibility imay limit the value from yes => mod */
+			val = EXPR_AND(expr_calc_value(prop->expr), prop->visible.tri);
+			break;
+		default:
+			/*
+			 * The following fails to handle the situation
+			 * where a default value is further limited by
+			 * the valid range.
+			 */
+			ds = prop_get_symbol(prop);
+			if (ds != NULL) {
+				sym_calc_value(ds);
+				str = (const char *)ds->curr.val;
+			}
+		}
+	}
+
+	/* Handle select statements */
+	val = EXPR_OR(val, sym->rev_dep.tri);
+
+	/* transpose mod to yes if modules are not enabled */
+	if (val == mod)
+		if (!sym_is_choice_value(sym) && modules_sym->curr.tri == no)
+			val = yes;
+
+	/* transpose mod to yes if type is bool */
+	if (sym->type == S_BOOLEAN && val == mod)
+		val = yes;
+
+	switch (sym->type) {
+	case S_BOOLEAN:
+	case S_TRISTATE:
+		switch (val) {
+		case no: return "n";
+		case mod: return "m";
+		case yes: return "y";
+		}
+	case S_INT:
+	case S_HEX:
+		return str;
+	case S_STRING:
+		return str;
+	case S_OTHER:
+	case S_UNKNOWN:
+		break;
+	}
+	return "";
+}
+
 const char *sym_get_string_value(struct symbol *sym)
 {
 	tristate val;
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH 9/9] kconfig: add savedefconfig
  2010-07-31 21:35   ` [PATCH 9/9] kconfig: add savedefconfig Sam Ravnborg
@ 2010-08-02  8:05     ` Uwe Kleine-König
  0 siblings, 0 replies; 22+ messages in thread
From: Uwe Kleine-König @ 2010-08-02  8:05 UTC (permalink / raw
  To: Sam Ravnborg; +Cc: Michal Marek, lkml, linux-kbuild

Hello,

On Sat, Jul 31, 2010 at 11:35:34PM +0200, Sam Ravnborg wrote:
> savedefconfig will save a minimal config to a file
> named "defconfig".
> 
> The config symbols are saved in the same order as
> they appear in the menu structure so it should
> be possible to map them to the relevant menus
> if desired.
> 
> The implementation was tested against several minimal
> configs for arm which was created using brute-force.
s/was/were/ I think.

> There was one regression related to default numbers
> which had their valid range further limited by another symbol.
> 
> Sample:
> 
> config FOO
> 	int "foo"
> 	default 4
> 
> config BAR
> 	int "bar"
> 	range 0 FOO
> 
> If FOO is set to 3 then BAR cannot take a value higher than 3.
> But the current implementation will set BAR equal to 4.
> 
> This is seldomly used and the final configuration is OK,
> and the fix was non-trivial.
> So it was documented in the code and left as is.
> 
> Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Thanks
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more)
  2010-07-31 21:29 [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
                   ` (9 preceding siblings ...)
  2010-07-31 21:34 ` [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
@ 2010-08-03 12:30 ` Michal Marek
  10 siblings, 0 replies; 22+ messages in thread
From: Michal Marek @ 2010-08-03 12:30 UTC (permalink / raw
  To: Sam Ravnborg
  Cc: lkml, linux-kbuild, Uwe Kleine-K?nig, Randy Dunlap, Roman Zippel,
	Aristeu Rozanski

On 31.7.2010 23:29, Sam Ravnborg wrote:
> This is an update of patches previous posted.
> 
> Version 2 have addressed the following feedback:
> - Drop the idea of introducing allrandconfig (Michal, Randy)
> - Do more code refactoring (Michal)
> - Use long options in conf.c (Michal)
> - savedefconfig shall list symbols in same order as in .config (Uwe)
>  
> The major feature is the introduction of "make savedefconfig".
> 
> Make savedefconfig creates a minimal configuration
> as have been discussed recently and which is already
> done for arm and powerpc.
> savedefconfig utilise the knowledge kconfig has to do so
> much faster than the phyton script posted.
> [...]

Applied, thanks.

Michal

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2010-08-03 12:32 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-31 21:29 [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
2010-07-31 21:31 ` [PATCH] kconfig: use long options in conf Sam Ravnborg
2010-07-31 21:31 ` [PATCH] kconfig: rename loose_nonint_oldconfig => oldnoconfig Sam Ravnborg
2010-07-31 21:31 ` [PATCH] kconfig: change nonint_oldconfig to listnewconfig Sam Ravnborg
2010-07-31 21:31 ` [PATCH] kconfig: save location of config symbols Sam Ravnborg
2010-07-31 21:31 ` [PATCH] kconfig: print more info when we see a recursive dependency Sam Ravnborg
2010-07-31 21:31 ` [PATCH] kconfig: add alldefconfig Sam Ravnborg
2010-07-31 21:31 ` [PATCH] kconfig: refactor code in symbol.c Sam Ravnborg
2010-07-31 21:31 ` [PATCH] kconfig: code refactoring in confdata.c Sam Ravnborg
2010-07-31 21:31 ` [PATCH] kconfig: add savedefconfig Sam Ravnborg
2010-07-31 21:34 ` [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Sam Ravnborg
2010-07-31 21:35   ` [PATCH 1/9] kconfig: use long options in conf Sam Ravnborg
2010-07-31 21:35   ` [PATCH 2/9] kconfig: rename loose_nonint_oldconfig => oldnoconfig Sam Ravnborg
2010-07-31 21:35   ` [PATCH 3/9] kconfig: change nonint_oldconfig to listnewconfig Sam Ravnborg
2010-07-31 21:35   ` [PATCH 4/9] kconfig: save location of config symbols Sam Ravnborg
2010-07-31 21:35   ` [PATCH 5/9] kconfig: print more info when we see a recursive dependency Sam Ravnborg
2010-07-31 21:35   ` [PATCH 6/9] kconfig: add alldefconfig Sam Ravnborg
2010-07-31 21:35   ` [PATCH 7/9] kconfig: refactor code in symbol.c Sam Ravnborg
2010-07-31 21:35   ` [PATCH 8/9] kconfig: code refactoring in confdata.c Sam Ravnborg
2010-07-31 21:35   ` [PATCH 9/9] kconfig: add savedefconfig Sam Ravnborg
2010-08-02  8:05     ` Uwe Kleine-König
2010-08-03 12:30 ` [PATCH v2 0/9] kconfig: introduce saveconfig and alldefconfig (+more) Michal Marek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).