mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sam Ravnborg <sam@ravnborg.org>
To: Roman Zippel <zippel@linux-m68k.org>,
	kbuild-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org
Subject: [RFD] kconfig - introduce cond-source
Date: Sun, 31 Jul 2005 00:01:00 +0200	[thread overview]
Message-ID: <20050730220100.GA3240@mars.ravnborg.org> (raw)

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

             reply	other threads:[~2005-07-30 21:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-30 22:01 Sam Ravnborg [this message]
2005-07-31  0:50 ` Roman Zippel
2005-07-31  8:45   ` Sam Ravnborg

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=20050730220100.GA3240@mars.ravnborg.org \
    --to=sam@ravnborg.org \
    --cc=kbuild-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®