mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFD] kconfig - introduce cond-source
@ 2005-07-30 22:01 Sam Ravnborg
  2005-07-31  0:50 ` Roman Zippel
  0 siblings, 1 reply; 3+ messages in thread
From: Sam Ravnborg @ 2005-07-30 22:01 UTC (permalink / raw)
  To: Roman Zippel, kbuild-devel, linux-kernel

Hi Roman.

In a couple of cases I have had the need to include a Kconfig file only
if present.
The current 'source' directive works as one would expect. It bails out
if the file is missing.

Examples where I have missed cond-source:
- klibc work
- external modules

	Sam

Patch below implement a cond-source.


diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -39,6 +39,7 @@ void zconf_starthelp(void);
 FILE *zconf_fopen(const char *name);
 void zconf_initscan(const char *name);
 void zconf_nextfile(const char *name);
+void zconf_try_nextfile(const char *name);
 int zconf_lineno(void);
 char *zconf_curname(void);
 
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -91,6 +91,7 @@ n	[A-Za-z0-9_]
 	"mainmenu"		BEGIN(PARAM); return T_MAINMENU;
 	"menu"			BEGIN(PARAM); return T_MENU;
 	"endmenu"		BEGIN(PARAM); return T_ENDMENU;
+	"cond-source"		BEGIN(PARAM); return T_CONDSOURCE;
 	"source"		BEGIN(PARAM); return T_SOURCE;
 	"choice"		BEGIN(PARAM); return T_CHOICE;
 	"endchoice"		BEGIN(PARAM); return T_ENDCHOICE;
@@ -299,18 +300,14 @@ void zconf_initscan(const char *name)
 	current_file->flags = FILE_BUSY;
 }
 
-void zconf_nextfile(const char *name)
+static void zconf_switch_buffer(const char *name, FILE *filp)
 {
 	struct file *file = file_lookup(name);
 	struct buffer *buf = malloc(sizeof(*buf));
 	memset(buf, 0, sizeof(*buf));
 
 	current_buf->state = YY_CURRENT_BUFFER;
-	yyin = zconf_fopen(name);
-	if (!yyin) {
-		printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name);
-		exit(1);
-	}
+	yyin = filp;
 	yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
 	buf->parent = current_buf;
 	current_buf = buf;
@@ -329,6 +326,27 @@ void zconf_nextfile(const char *name)
 	current_file = file;
 }
 
+void zconf_nextfile(const char *name)
+{
+	FILE *filp;
+
+	filp = zconf_fopen(name);
+	if (!filp) {
+		printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name);
+		exit(1);
+	}
+	zconf_switch_buffer(name, filp);
+}
+
+void zconf_try_nextfile(const char *name)
+{
+	FILE *filp;
+
+	filp = zconf_fopen(name);
+	if (filp)
+		zconf_switch_buffer(name, filp);
+}
+
 static struct buffer *zconf_endfile(void)
 {
 	struct buffer *parent;

diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -44,6 +44,7 @@ static struct menu *current_menu, *curre
 %token T_MENU
 %token T_ENDMENU
 %token T_SOURCE
+%token T_CONDSOURCE
 %token T_CHOICE
 %token T_ENDCHOICE
 %token T_COMMENT
@@ -378,15 +379,22 @@ menu_block:
 
 source: T_SOURCE prompt T_EOL
 {
-	$$ = $2;
 	printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
+	zconf_nextfile($2);
 };
 
-source_stmt: source
+condsource: T_CONDSOURCE prompt T_EOL
 {
-	zconf_nextfile($1);
+	printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
+	zconf_try_nextfile($2);
 };
 
+source_stmt:
+	  source
+	| condsource
+	/* empty */
+;
+
 /* comment entry */
 
 comment: T_COMMENT prompt T_EOL

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

* Re: [RFD] kconfig - introduce cond-source
  2005-07-30 22:01 [RFD] kconfig - introduce cond-source Sam Ravnborg
@ 2005-07-31  0:50 ` Roman Zippel
  2005-07-31  8:45   ` Sam Ravnborg
  0 siblings, 1 reply; 3+ messages in thread
From: Roman Zippel @ 2005-07-31  0:50 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: kbuild-devel, linux-kernel

Hi,

On Sun, 31 Jul 2005, Sam Ravnborg wrote:

> In a couple of cases I have had the need to include a Kconfig file only
> if present.
> The current 'source' directive works as one would expect. It bails out
> if the file is missing.

I don't really like it, it's an open invitation to abuse.
I'd rather like to see the user first, which might need it.

bye, Roman

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

* Re: [RFD] kconfig - introduce cond-source
  2005-07-31  0:50 ` Roman Zippel
@ 2005-07-31  8:45   ` Sam Ravnborg
  0 siblings, 0 replies; 3+ messages in thread
From: Sam Ravnborg @ 2005-07-31  8:45 UTC (permalink / raw)
  To: Roman Zippel; +Cc: kbuild-devel, linux-kernel

On Sun, Jul 31, 2005 at 02:50:03AM +0200, Roman Zippel wrote:
> Hi,
> 
> On Sun, 31 Jul 2005, Sam Ravnborg wrote:
> 
> > In a couple of cases I have had the need to include a Kconfig file only
> > if present.
> > The current 'source' directive works as one would expect. It bails out
> > if the file is missing.
> 
> I don't really like it, it's an open invitation to abuse.
> I'd rather like to see the user first, which might need it.
Understood.
I will save this until I have a very good example where I need it.

	Sam

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

end of thread, other threads:[~2005-07-31  8:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-30 22:01 [RFD] kconfig - introduce cond-source Sam Ravnborg
2005-07-31  0:50 ` Roman Zippel
2005-07-31  8:45   ` Sam Ravnborg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®