* kconfig: Locate files relative to $srctree
@ 2002-11-23 22:07 Sam Ravnborg
2002-11-24 1:56 ` Roman Zippel
0 siblings, 1 reply; 5+ messages in thread
From: Sam Ravnborg @ 2002-11-23 22:07 UTC (permalink / raw)
To: Roman Zippel; +Cc: linux-kernel
Hi Roman
This patch to kconfig teach it to try locating inputfiles
relative to $srctree as a second choice.
The purpose of this patch is to make support for separate
src/obj dir simpler, in other words to avoid symlinking Kconfig
and defconfig files.
With the current implementation I decided to try normal path
first, and second the path with $srctree prefixed.
Some codepaths could be simpler if we decide always to
prefix with $srctree.
I considered adding a command line option, but then changes
were required in all frontends.
Therefore I decided to build-in knowledge of $srctree instead.
When/if we you acknowledge this I would like you to push to Linus.
Comments appreciated.
Sam
The cset includes _shipped files, which I deleted on purpose.
It includes the following changes:
Makefile | 5 ++++-
confdata.c | 13 ++++++++++---
expr.h | 2 ++
symbol.c | 7 +++++++
zconf.l | 27 +++++++++++++++++++++++++--
5 files changed, 48 insertions(+), 6 deletions(-)
To try it out uncomment LKC_GENPARSER in Makefile.
Complete bk cset will shortly be available for pulling at:
http://linux-sam.bkbits.net/sepobjdir
# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.857 -> 1.858
# scripts/kconfig/symbol.c 1.2 -> 1.3
# scripts/kconfig/zconf.tab.c_shipped 1.2 -> 1.3
# scripts/kconfig/expr.h 1.2 -> 1.3
# scripts/kconfig/zconf.l 1.3 -> 1.4
# scripts/kconfig/lex.zconf.c_shipped 1.3 -> 1.4
# scripts/kconfig/zconf.tab.h_shipped 1.2 -> 1.3
# scripts/kconfig/confdata.c 1.3 -> 1.4
# scripts/kconfig/Makefile 1.2 -> 1.3
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/11/23 sam@mars.ravnborg.org 1.858
# kconfig: Try to locate files in $srctree
#
# In order to support separate src/obj dir, try locating
# files in tree pointed out by $srctree as second alternative
# --------------------------------------------
#
diff -Nru a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
--- a/scripts/kconfig/symbol.c Sat Nov 23 22:53:43 2002
+++ b/scripts/kconfig/symbol.c Sat Nov 23 22:53:43 2002
@@ -75,6 +75,13 @@
if (p)
sym_add_default(sym, p);
+ sym = sym_lookup(SRCTREE, 0);
+ sym->type = S_STRING;
+ sym->flags |= SYMBOL_AUTO;
+ p = getenv(SRCTREE);
+ if (p)
+ sym_add_default(sym, p);
+
sym = sym_lookup("UNAME_RELEASE", 0);
sym->type = S_STRING;
sym->flags |= SYMBOL_AUTO;
diff -Nru a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
--- a/scripts/kconfig/zconf.l Sat Nov 23 22:53:43 2002
+++ b/scripts/kconfig/zconf.l Sat Nov 23 22:53:43 2002
@@ -249,9 +249,32 @@
BEGIN(INITIAL);
}
+/*
+ Try to open specified file with following names:
+ ./name
+ $(srctree)/name
+ The latter is used when srctree is separate from objtree
+ when compiling the kernel.
+ Return NULL if file is not found.
+*/
+static FILE *zconf_fopen(const char *name)
+{
+ static char fullname[SYMBOL_MAXLENGTH];
+ static char *p;
+ FILE *f = fopen(name, "r");
+ if (f)
+ return f;
+ p = getenv(SRCTREE);
+ if (p) {
+ sprintf(fullname, "%s/%s", p, name);
+ return fopen(fullname, "r");
+ }
+ return NULL;
+}
+
void zconf_initscan(const char *name)
{
- yyin = fopen(name, "r");
+ yyin = zconf_fopen(name);
if (!yyin) {
printf("can't find file %s\n", name);
exit(1);
@@ -272,7 +295,7 @@
memset(buf, 0, sizeof(*buf));
current_buf->state = YY_CURRENT_BUFFER;
- yyin = fopen(name, "r");
+ yyin = zconf_fopen(name);
if (!yyin) {
printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name);
exit(1);
diff -Nru a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
--- a/scripts/kconfig/Makefile Sat Nov 23 22:53:43 2002
+++ b/scripts/kconfig/Makefile Sat Nov 23 22:53:43 2002
@@ -77,12 +77,15 @@
ifdef LKC_GENPARSER
$(obj)/zconf.tab.c: $(obj)/zconf.y
-$(obj)/zconf.tab.h: $(obj)/zconf.tab.c
+$(obj)/zconf.tab.h: $(obj)/zconf.y
%.tab.c: %.y
bison -t -d -v -b $* -p $(notdir $*) $<
+ cp $@ $@_shipped
+ cp $(@:.c=.h) $(@:.c=.h)_shipped
lex.%.c: %.l
flex -P$(notdir $*) -o$@ $<
+ cp $@ $@_shipped
endif
diff -Nru a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
--- a/scripts/kconfig/confdata.c Sat Nov 23 22:53:43 2002
+++ b/scripts/kconfig/confdata.c Sat Nov 23 22:53:43 2002
@@ -7,6 +7,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
#include <unistd.h>
#define LKC_DIRECT_LINK
@@ -14,14 +15,16 @@
const char conf_def_filename[] = ".config";
-const char conf_defname[] = "arch/$ARCH/defconfig";
+#define DEFNAME 4
+#define DEFALTNAME 5
const char *conf_confnames[] = {
".config",
"/lib/modules/$UNAME_RELEASE/.config",
"/etc/kernel-config",
"/boot/config-$UNAME_RELEASE",
- conf_defname,
+ "arch/$ARCH/defconfig", /* index DEFNAME */
+ "$" SRCTREE "/arch/$ARCH/defconfig", /* index DEFALTNAME */
NULL,
};
@@ -53,7 +56,11 @@
char *conf_get_default_confname(void)
{
- return conf_expand_value(conf_defname);
+ struct stat buf;
+ char * name = conf_expand_value(conf_confnames[DEFNAME]);
+ if (!stat(name, &buf))
+ return name;
+ return conf_expand_value(conf_confnames[DEFALTNAME]);
}
int conf_read(const char *name)
diff -Nru a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
--- a/scripts/kconfig/expr.h Sat Nov 23 22:53:43 2002
+++ b/scripts/kconfig/expr.h Sat Nov 23 22:53:43 2002
@@ -127,6 +127,8 @@
#define SYMBOL_HASHSIZE 257
#define SYMBOL_HASHMASK 0xff
+#define SRCTREE "srctree"
+
enum prop_type {
P_UNKNOWN, P_PROMPT, P_COMMENT, P_MENU, P_ROOTMENU, P_DEFAULT, P_CHOICE
};
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: kconfig: Locate files relative to $srctree
2002-11-23 22:07 kconfig: Locate files relative to $srctree Sam Ravnborg
@ 2002-11-24 1:56 ` Roman Zippel
2002-11-24 13:37 ` Russell King
2002-11-26 19:29 ` Sam Ravnborg
0 siblings, 2 replies; 5+ messages in thread
From: Roman Zippel @ 2002-11-24 1:56 UTC (permalink / raw)
To: Sam Ravnborg; +Cc: linux-kernel
Hi,
On Sat, 23 Nov 2002, Sam Ravnborg wrote:
> const char *conf_confnames[] = {
> ".config",
> "/lib/modules/$UNAME_RELEASE/.config",
> "/etc/kernel-config",
> "/boot/config-$UNAME_RELEASE",
> - conf_defname,
> + "arch/$ARCH/defconfig", /* index DEFNAME */
> + "$" SRCTREE "/arch/$ARCH/defconfig", /* index DEFALTNAME */
> NULL,
> };
This is not good. At some point I maybe want to make these configurable.
I changed the patch to always use zconf_fopen(), which will try the
alternative prefix for relative paths.
I couldn't test this very much as you forgot the kbuild script. :)
Anyway, below is an alternative version.
bye, Roman
Index: scripts/kconfig/confdata.c
===================================================================
RCS file: /usr/src/cvsroot/linux-2.5/scripts/kconfig/confdata.c,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 confdata.c
--- scripts/kconfig/confdata.c 11 Nov 2002 19:06:27 -0000 1.1.1.2
+++ scripts/kconfig/confdata.c 24 Nov 2002 00:31:28 -0000
@@ -3,6 +3,7 @@
* Released under the terms of the GNU GPL v2.0.
*/
+#include <sys/stat.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
@@ -53,7 +54,18 @@ static char *conf_expand_value(const cha
char *conf_get_default_confname(void)
{
- return conf_expand_value(conf_defname);
+ struct stat buf;
+ static char fullname[PATH_MAX+1];
+ char *env, *name;
+
+ name = conf_expand_value(conf_defname);
+ env = getenv(SRCTREE);
+ if (env) {
+ sprintf(fullname, "%s/%s", env, name);
+ if (!stat(fullname, &buf))
+ return fullname;
+ }
+ return name;
}
int conf_read(const char *name)
@@ -68,12 +80,12 @@ int conf_read(const char *name)
int i;
if (name) {
- in = fopen(name, "r");
+ in = zconf_fopen(name);
} else {
const char **names = conf_confnames;
while ((name = *names++)) {
name = conf_expand_value(name);
- in = fopen(name, "r");
+ in = zconf_fopen(name);
if (in) {
printf("#\n"
"# using defaults found in %s\n"
Index: scripts/kconfig/lkc.h
===================================================================
RCS file: /usr/src/cvsroot/linux-2.5/scripts/kconfig/lkc.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 lkc.h
--- scripts/kconfig/lkc.h 31 Oct 2002 13:29:12 -0000 1.1.1.1
+++ scripts/kconfig/lkc.h 24 Nov 2002 00:31:28 -0000
@@ -21,12 +21,14 @@ extern "C" {
#include "lkc_proto.h"
#undef P
-void symbol_end(char *help);
+#define SRCTREE "srctree"
+
int zconfparse(void);
void zconfdump(FILE *out);
extern int zconfdebug;
void zconf_starthelp(void);
+FILE *zconf_fopen(const char *name);
void zconf_initscan(const char *name);
void zconf_nextfile(const char *name);
int zconf_lineno(void);
Index: scripts/kconfig/zconf.l
===================================================================
RCS file: /usr/src/cvsroot/linux-2.5/scripts/kconfig/zconf.l,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 zconf.l
--- scripts/kconfig/zconf.l 11 Nov 2002 19:06:28 -0000 1.1.1.2
+++ scripts/kconfig/zconf.l 24 Nov 2002 00:31:28 -0000
@@ -7,6 +7,7 @@
* Released under the terms of the GNU GPL v2.0.
*/
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -249,9 +251,34 @@ static void zconf_endhelp(void)
BEGIN(INITIAL);
}
+
+/*
+ * Try to open specified file with following names:
+ * ./name
+ * $(srctree)/name
+ * The latter is used when srctree is separate from objtree
+ * when compiling the kernel.
+ * Return NULL if file is not found.
+ */
+FILE *zconf_fopen(const char *name)
+{
+ char *env, fullname[PATH_MAX+1];
+ FILE *f;
+
+ f = fopen(name, "r");
+ if (!f && name[0] != '/') {
+ env = getenv(SRCTREE);
+ if (env) {
+ sprintf(fullname, "%s/%s", env, name);
+ f = fopen(fullname, "r");
+ }
+ }
+ return f;
+}
+
void zconf_initscan(const char *name)
{
- yyin = fopen(name, "r");
+ yyin = zconf_fopen(name);
if (!yyin) {
printf("can't find file %s\n", name);
exit(1);
@@ -272,7 +299,7 @@ void zconf_nextfile(const char *name)
memset(buf, 0, sizeof(*buf));
current_buf->state = YY_CURRENT_BUFFER;
- yyin = fopen(name, "r");
+ yyin = zconf_fopen(name);
if (!yyin) {
printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name);
exit(1);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: kconfig: Locate files relative to $srctree
2002-11-24 1:56 ` Roman Zippel
@ 2002-11-24 13:37 ` Russell King
2002-11-24 14:23 ` Roman Zippel
2002-11-26 19:29 ` Sam Ravnborg
1 sibling, 1 reply; 5+ messages in thread
From: Russell King @ 2002-11-24 13:37 UTC (permalink / raw)
To: Roman Zippel; +Cc: Sam Ravnborg, linux-kernel
On Sun, Nov 24, 2002 at 02:56:22AM +0100, Roman Zippel wrote:
> > const char *conf_confnames[] = {
> > ".config",
> > "/lib/modules/$UNAME_RELEASE/.config",
> > "/etc/kernel-config",
> > "/boot/config-$UNAME_RELEASE",
> > - conf_defname,
> > + "arch/$ARCH/defconfig", /* index DEFNAME */
> > + "$" SRCTREE "/arch/$ARCH/defconfig", /* index DEFALTNAME */
> > NULL,
> > };
>
> This is not good. At some point I maybe want to make these configurable.
> I changed the patch to always use zconf_fopen(), which will try the
> alternative prefix for relative paths.
> I couldn't test this very much as you forgot the kbuild script. :)
> Anyway, below is an alternative version.
One thing that does slightly annoy me with the new config tools is the
handling of the default configuration when you're cross-building. In
this circumstance, looking for the running kernel configuration seems
wrong; it definitely isn't going to be the configuration you want to
start from.
--
Russell King (rmk@arm.linux.org.uk) The developer of ARM Linux
http://www.arm.linux.org.uk/personal/aboutme.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: kconfig: Locate files relative to $srctree
2002-11-24 13:37 ` Russell King
@ 2002-11-24 14:23 ` Roman Zippel
0 siblings, 0 replies; 5+ messages in thread
From: Roman Zippel @ 2002-11-24 14:23 UTC (permalink / raw)
To: Russell King; +Cc: Sam Ravnborg, linux-kernel
Hi,
> One thing that does slightly annoy me with the new config tools is the
> handling of the default configuration when you're cross-building. In
> this circumstance, looking for the running kernel configuration seems
> wrong; it definitely isn't going to be the configuration you want to
> start from.
That didn't really came with the new tools, I took the list from the old
Configure.
Anyway, this is another reason I'd like to make this configurable, as
different archs might want to have different paths here.
bye, Roman
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: kconfig: Locate files relative to $srctree
2002-11-24 1:56 ` Roman Zippel
2002-11-24 13:37 ` Russell King
@ 2002-11-26 19:29 ` Sam Ravnborg
1 sibling, 0 replies; 5+ messages in thread
From: Sam Ravnborg @ 2002-11-26 19:29 UTC (permalink / raw)
To: Roman Zippel; +Cc: Sam Ravnborg, linux-kernel
Hi Roman.
On Sun, Nov 24, 2002 at 02:56:22AM +0100, Roman Zippel wrote:
> This is not good. At some point I maybe want to make these configurable.
> I changed the patch to always use zconf_fopen(), which will try the
> alternative prefix for relative paths.
Sorry for the late feedback, been busy...
I have to say that I like your version better than mine, and it's
actually less intrusive. Thanks for looking into this.
I have tested this patch with objdir in same dir as src, and in
separate dir.
Everything works as usual.
I would be glad if you push this to Linus.
Sam
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-11-26 19:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-23 22:07 kconfig: Locate files relative to $srctree Sam Ravnborg
2002-11-24 1:56 ` Roman Zippel
2002-11-24 13:37 ` Russell King
2002-11-24 14:23 ` Roman Zippel
2002-11-26 19:29 ` Sam Ravnborg
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.