public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
From: Sam Ravnborg <sam@ravnborg.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kbuild <linux-kbuild@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Roman Zippel <zippel@linux-m68k.org>,
	Jeremy Fitzhardinge <jeremy@goop.org>
Subject: Re: [RFC PATCH] kconfig: introduce KCONFIG_* symbols for .c files
Date: Sat, 24 May 2008 22:24:27 +0200	[thread overview]
Message-ID: <20080524202427.GA879@uranus.ravnborg.org> (raw)
In-Reply-To: <20080524125316.4b969936.akpm@linux-foundation.org>

On Sat, May 24, 2008 at 12:53:16PM -0700, Andrew Morton wrote:
> On Sat, 24 May 2008 21:25:40 +0200 Sam Ravnborg <sam@ravnborg.org> wrote:
> 
> > We have many places in the kernel that looks like
> > the following:
> > 
> > #ifdef CONFIG_FOO
> > 	...
> > #endif
> > 
> > Which has the disadvantage that the code denoted '...'
> > are not even built if CONFIG_FOO is not selected in
> > the current configuration.
> > 
> > We know that gcc do simple code-elimination for
> > conditionals which is always true/false and
> > thus the above code could be turned into:
> > 
> > 	if (CONFIG_FOO)
> > 		...
> > 
> > One line smaller and we follow the normal flow in the program.
> > The code is always build but we do not waste space as gcc will
> > do proper code-elimination for us.
> > 
> > Today this is not possible because kconfig will only
> > define CONFIG_FOO if selected and FOO is not a module.
> > 
> > The following patch implement a new set of defines in
> > the KCONFIG_* namespace.
> > 
> > For a tristate symbol the following are defined:
> > 
> > FOO not selected: 
> > #define KCONFIG_FOO        0
> > #define KCONFIG_FOO_MODULE 0
> > 
> > FOO is built-in ('y')
> > #define KCONFIG_FOO        1
> > #define KCONFIG_FOO_MODULE 0
> > 
> > FOO is a module ('m'):
> > #define KCONFIG_FOO        1
> > #define KCONFIG_FOO_MODULE 1
> > 
> > In other words KCONFIG_FOO will say if the
> > symbol is selected and KCONFIG_FOO_MODULE
> > will say if it is a module.
> > 
> > With the above included we can now do:
> > 
> > 	if (KCONFIG_FOO)
> > 		...
> > 
> > This is not a replacement for the CONFIG_*
> > defines but a pleasant supplement.
> > Using KCONFIG_FOO will also give us a nice
> > error message the day that FOO is no longer part
> > of the configuration.
> 
> It could help to get us out of the occasional sticky situation, but it
> does seem a bit risky.  What happens with Kconfig variables which are
> just not known about at all with some .configs?
> 
> Silly example, one could add
> 
> 	if (KCONFIG_DVB_VES1820)
> 
> to kernel/sched.c and that would work happily until someone sets DVB=n,
> in which case I assume KCONFIG_DVB_VES1820 doesn't get defined
> anywhere?
It would have helped if I had applied the correct patch...
All boolean and tristate symbols in the konfiguration have
their symbols defined as KCONFIG_* no matter their values.
So KCONFIG_DVB_VES1820 would get defined.

Correct patch below.

	Sam

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index ee5fe94..247ea30 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -666,6 +666,43 @@ out:
 	return res;
 }
 
+static void write_tristate_config(FILE *m, FILE *h, struct symbol *sym)
+{
+	switch (sym_get_tristate_value(sym)) {
+	case mod:
+		fprintf(m, "CONFIG_%s=m\n", sym->name);
+		fprintf(h, "#define CONFIG_%s_MODULE 1\n", sym->name);
+		break;
+	case yes:
+		fprintf(m, "CONFIG_%s=y\n", sym->name);
+		fprintf(h, "#define CONFIG_%s 1\n", sym->name);
+		break;
+	case no:
+		break;
+	}
+}
+
+static void write_tristate_kconfig(FILE *f, struct symbol *sym)
+{
+	switch (sym_get_tristate_value(sym)) {
+	case mod:
+		fprintf(f, "#define KCONFIG_%s 1\n", sym->name);
+		if (sym->type == S_TRISTATE)
+			fprintf(f, "#define KCONFIG_%s_MODULE 1\n", sym->name);
+		break;
+	case yes:
+		fprintf(f, "#define KCONFIG_%s 1\n", sym->name);
+		if (sym->type == S_TRISTATE)
+			fprintf(f, "#define KCONFIG_%s_MODULE 0\n", sym->name);
+		break;
+	case no:
+		fprintf(f, "#define KCONFIG_%s 0\n", sym->name);
+		if (sym->type == S_TRISTATE)
+			fprintf(f, "#define KCONFIG_%s_MODULE 0\n", sym->name);
+		break;
+	}
+}
+
 int conf_write_autoconf(void)
 {
 	struct symbol *sym;
@@ -716,18 +753,7 @@ int conf_write_autoconf(void)
 		switch (sym->type) {
 		case S_BOOLEAN:
 		case S_TRISTATE:
-			switch (sym_get_tristate_value(sym)) {
-			case no:
-				break;
-			case mod:
-				fprintf(out, "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);
-				fprintf(out_h, "#define CONFIG_%s 1\n", sym->name);
-				break;
-			}
+			write_tristate_config(out, out_h, sym);
 			break;
 		case S_STRING:
 			str = sym_get_string_value(sym);
@@ -765,6 +791,19 @@ int conf_write_autoconf(void)
 			break;
 		}
 	}
+	for_all_symbols(i, sym) {
+		sym_calc_value(sym);
+		if (!sym->name)
+			continue;
+		switch (sym->type) {
+		case S_BOOLEAN:
+		case S_TRISTATE:
+			write_tristate_kconfig(out_h, sym);
+			break;
+		default:
+			break;
+		}
+	}
 	fclose(out);
 	fclose(out_h);
 

  parent reply	other threads:[~2008-05-24 20:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-24 19:25 [RFC PATCH] kconfig: introduce KCONFIG_* symbols for .c files Sam Ravnborg
2008-05-24 19:53 ` Andrew Morton
2008-05-24 20:14   ` Jeremy Fitzhardinge
2008-05-24 20:46     ` Sam Ravnborg
2008-05-24 20:56       ` Jeremy Fitzhardinge
2008-05-24 21:03         ` Sam Ravnborg
2008-05-24 20:24   ` Sam Ravnborg [this message]
2008-05-24 20:48     ` Andrew Morton
2008-05-24 21:00       ` Sam Ravnborg
2008-05-24 20:05 ` Adrian Bunk
2008-05-24 20:44   ` Sam Ravnborg
2008-05-24 20:57     ` Adrian Bunk
2008-05-24 20:20 ` Linus Torvalds
2008-05-24 20:37   ` [PATCH] x86: use defconfig as last resort Sam Ravnborg
2008-05-25  1:30     ` Linus Torvalds
2008-05-25  6:15       ` Sam Ravnborg
2008-05-25  6:22       ` Sam Ravnborg
2008-05-24 20:48 ` [RFC PATCH] kconfig: introduce KCONFIG_* symbols for .c files Jeremy Fitzhardinge
2008-05-24 20:58   ` Jeremy Fitzhardinge
2008-05-24 21:03     ` Adrian Bunk
2008-05-24 21:13       ` Jeremy Fitzhardinge
2008-05-24 21:26 ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080524202427.GA879@uranus.ravnborg.org \
    --to=sam@ravnborg.org \
    --cc=akpm@linux-foundation.org \
    --cc=jeremy@goop.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=zippel@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox