kconfig: Locate files relative to $srctree
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 [email protected] 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;
scripts/kconfig/zconf.l +25 -2
@@ -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);
scripts/kconfig/Makefile +4 -1
@@ -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
scripts/kconfig/confdata.c +10 -3
@@ -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 5const 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)
scripts/kconfig/expr.h +2 -0
@@ -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 };
Hi,
Review
Quoted 10 lines · Sam Ravnborg
const char *conf_confnames[] = {
(quoted diff) +2
-1".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
kconfig/confdata.c +15 -3
@@ -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 chachar *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
kconfig/lkc.h +3 -1
@@ -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
kconfig/zconf.l +28 -2
@@ -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);
Quoted 8 lines · Roman Zippel
Quoted 8 lines
const char *conf_confnames[] = {
(quoted diff) +2
-1".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 */
Quoted 8 lines
Quoted 2 lines
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.
Signature · 2 lines
Russell King ([email protected]) The developer of ARM Linux http://www.arm.linux.org.uk/personal/aboutme.html
Hi,
Quoted 5 lines
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
Hi Roman.
Quoted 3 lines · Roman Zippel
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