Skip to content

Commit 104daea

Browse files
committed
kconfig: reference environment variables directly and remove 'option env='
To get access to environment variables, Kconfig needs to define a symbol using "option env=" syntax. It is tedious to add a symbol entry for each environment variable given that we need to define much more such as 'CC', 'AS', 'srctree' etc. to evaluate the compiler capability in Kconfig. Adding '$' for symbol references is grammatically inconsistent. Looking at the code, the symbols prefixed with 'S' are expanded by: - conf_expand_value() This is used to expand 'arch/$ARCH/defconfig' and 'defconfig_list' - sym_expand_string_value() This is used to expand strings in 'source' and 'mainmenu' All of them are fixed values independent of user configuration. So, they can be changed into the direct expansion instead of symbols. This change makes the code much cleaner. The bounce symbols 'SRCARCH', 'ARCH', 'SUBARCH', 'KERNELVERSION' are gone. sym_init() hard-coding 'UNAME_RELEASE' is also gone. 'UNAME_RELEASE' should be replaced with an environment variable. ARCH_DEFCONFIG is a normal symbol, so it should be simply referenced without '$' prefix. The new syntax is addicted by Make. The variable reference needs parentheses, like $(FOO), but you can omit them for single-letter variables, like $F. Yet, in Makefiles, people tend to use the parenthetical form for consistency / clarification. At this moment, only the environment variable is supported, but I will extend the concept of 'variable' later on. The variables are expanded in the lexer so we can simplify the token handling on the parser side. For example, the following code works. [Example code] config MY_TOOLCHAIN_LIST string default "My tools: CC=$(CC), AS=$(AS), CPP=$(CPP)" [Result] $ make -s alldefconfig && tail -n 1 .config CONFIG_MY_TOOLCHAIN_LIST="My tools: CC=gcc, AS=as, CPP=gcc -E" Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Kees Cook <[email protected]>
1 parent f1089c9 commit 104daea

19 files changed

+343
-154
lines changed

Documentation/kbuild/kconfig-language.txt

-8
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,6 @@ applicable everywhere (see syntax).
198198
enables the third modular state for all config symbols.
199199
At most one symbol may have the "modules" option set.
200200

201-
- "env"=<value>
202-
This imports the environment variable into Kconfig. It behaves like
203-
a default, except that the value comes from the environment, this
204-
also means that the behaviour when mixing it with normal defaults is
205-
undefined at this point. The symbol is currently not exported back
206-
to the build environment (if this is desired, it can be done via
207-
another symbol).
208-
209201
- "allnoconfig_y"
210202
This declares the symbol as one that should have the value y when
211203
using "allnoconfig". Used for symbols that hide other symbols.

Kconfig

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
# For a description of the syntax of this configuration file,
44
# see Documentation/kbuild/kconfig-language.txt.
55
#
6-
mainmenu "Linux/$ARCH $KERNELVERSION Kernel Configuration"
6+
mainmenu "Linux/$(ARCH) $(KERNELVERSION) Kernel Configuration"
77

8-
config SRCARCH
9-
string
10-
option env="SRCARCH"
11-
12-
source "arch/$SRCARCH/Kconfig"
8+
source "arch/$(SRCARCH)/Kconfig"

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ include scripts/Kbuild.include
284284
# Read KERNELRELEASE from include/config/kernel.release (if it exists)
285285
KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
286286
KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
287-
export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
287+
UNAME_RELEASE := $(shell uname --release)
288+
export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION UNAME_RELEASE
288289

289290
# SUBARCH tells the usermode build what the underlying arch is. That is set
290291
# first, and if a usermode build is happening, the "ARCH=um" on the command

arch/sh/Kconfig

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ config SUPERH
5858
<http://www.linux-sh.org/>.
5959

6060
config SUPERH32
61-
def_bool ARCH = "sh"
61+
def_bool "$(ARCH)" = "sh"
6262
select HAVE_KPROBES
6363
select HAVE_KRETPROBES
6464
select HAVE_IOREMAP_PROT if MMU && !X2TLB
@@ -77,7 +77,7 @@ config SUPERH32
7777
select HAVE_CC_STACKPROTECTOR
7878

7979
config SUPERH64
80-
def_bool ARCH = "sh64"
80+
def_bool "$(ARCH)" = "sh64"
8181
select HAVE_EXIT_THREAD
8282
select KALLSYMS
8383

arch/sparc/Kconfig

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
config 64BIT
2-
bool "64-bit kernel" if ARCH = "sparc"
3-
default ARCH = "sparc64"
2+
bool "64-bit kernel" if "$(ARCH)" = "sparc"
3+
default "$(ARCH)" = "sparc64"
44
help
55
SPARC is a family of RISC microprocessors designed and marketed by
66
Sun Microsystems, incorporated. They are very widely found in Sun

arch/um/Kconfig.common

-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ config HZ
5454
int
5555
default 100
5656

57-
config SUBARCH
58-
string
59-
option env="SUBARCH"
60-
6157
config NR_CPUS
6258
int
6359
range 1 1

arch/x86/Kconfig

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# SPDX-License-Identifier: GPL-2.0
22
# Select 32 or 64 bit
33
config 64BIT
4-
bool "64-bit kernel" if ARCH = "x86"
5-
default ARCH != "i386"
4+
bool "64-bit kernel" if "$(ARCH)" = "x86"
5+
default "$(ARCH)" != "i386"
66
---help---
77
Say yes to build a 64-bit kernel - formerly known as x86_64
88
Say no to build a 32-bit kernel - formerly known as i386

arch/x86/um/Kconfig

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
mainmenu "User Mode Linux/$SUBARCH $KERNELVERSION Kernel Configuration"
2+
mainmenu "User Mode Linux/$(SUBARCH) $(KERNELVERSION) Kernel Configuration"
33

44
source "arch/um/Kconfig.common"
55

@@ -16,8 +16,8 @@ config UML_X86
1616
select GENERIC_FIND_FIRST_BIT
1717

1818
config 64BIT
19-
bool "64-bit kernel" if SUBARCH = "x86"
20-
default SUBARCH != "i386"
19+
bool "64-bit kernel" if "$(SUBARCH)" = "x86"
20+
default "$(SUBARCH)" != "i386"
2121

2222
config X86_32
2323
def_bool !64BIT

init/Kconfig

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
config ARCH
2-
string
3-
option env="ARCH"
4-
5-
config KERNELVERSION
6-
string
7-
option env="KERNELVERSION"
8-
91
config DEFCONFIG_LIST
102
string
113
depends on !UML
124
option defconfig_list
13-
default "/lib/modules/$UNAME_RELEASE/.config"
5+
default "/lib/modules/$(UNAME_RELEASE)/.config"
146
default "/etc/kernel-config"
15-
default "/boot/config-$UNAME_RELEASE"
16-
default "$ARCH_DEFCONFIG"
17-
default "arch/$ARCH/defconfig"
7+
default "/boot/config-$(UNAME_RELEASE)"
8+
default ARCH_DEFCONFIG
9+
default "arch/$(ARCH)/defconfig"
1810

1911
config CONSTRUCTORS
2012
bool

scripts/kconfig/confdata.c

+4-29
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void conf_message(const char *fmt, ...)
3030
static const char *conf_filename;
3131
static int conf_lineno, conf_warnings;
3232

33-
const char conf_defname[] = "arch/$ARCH/defconfig";
33+
const char conf_defname[] = "arch/$(ARCH)/defconfig";
3434

3535
static void conf_warning(const char *fmt, ...)
3636
{
@@ -81,39 +81,13 @@ const char *conf_get_autoconfig_name(void)
8181
return name ? name : "include/config/auto.conf";
8282
}
8383

84-
static char *conf_expand_value(const char *in)
85-
{
86-
struct symbol *sym;
87-
const char *src;
88-
static char res_value[SYMBOL_MAXLENGTH];
89-
char *dst, name[SYMBOL_MAXLENGTH];
90-
91-
res_value[0] = 0;
92-
dst = name;
93-
while ((src = strchr(in, '$'))) {
94-
strncat(res_value, in, src - in);
95-
src++;
96-
dst = name;
97-
while (isalnum(*src) || *src == '_')
98-
*dst++ = *src++;
99-
*dst = 0;
100-
sym = sym_lookup(name, 0);
101-
sym_calc_value(sym);
102-
strcat(res_value, sym_get_string_value(sym));
103-
in = src;
104-
}
105-
strcat(res_value, in);
106-
107-
return res_value;
108-
}
109-
11084
char *conf_get_default_confname(void)
11185
{
11286
struct stat buf;
11387
static char fullname[PATH_MAX+1];
11488
char *env, *name;
11589

116-
name = conf_expand_value(conf_defname);
90+
name = expand_string(conf_defname);
11791
env = getenv(SRCTREE);
11892
if (env) {
11993
sprintf(fullname, "%s/%s", env, name);
@@ -274,7 +248,8 @@ int conf_read_simple(const char *name, int def)
274248
if (expr_calc_value(prop->visible.expr) == no ||
275249
prop->expr->type != E_SYMBOL)
276250
continue;
277-
name = conf_expand_value(prop->expr->left.sym->name);
251+
sym_calc_value(prop->expr->left.sym);
252+
name = sym_get_string_value(prop->expr->left.sym);
278253
in = zconf_fopen(name);
279254
if (in) {
280255
conf_message("using defaults found in %s",

scripts/kconfig/kconf_id.c

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ static struct kconf_id kconf_id_array[] = {
3232
{ "on", T_ON, TF_PARAM },
3333
{ "modules", T_OPT_MODULES, TF_OPTION },
3434
{ "defconfig_list", T_OPT_DEFCONFIG_LIST, TF_OPTION },
35-
{ "env", T_OPT_ENV, TF_OPTION },
3635
{ "allnoconfig_y", T_OPT_ALLNOCONFIG_Y, TF_OPTION },
3736
};
3837

scripts/kconfig/lkc.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ enum conf_def_mode {
4444

4545
#define T_OPT_MODULES 1
4646
#define T_OPT_DEFCONFIG_LIST 2
47-
#define T_OPT_ENV 3
4847
#define T_OPT_ALLNOCONFIG_Y 4
4948

5049
struct kconf_id {
@@ -103,6 +102,7 @@ void *xmalloc(size_t size);
103102
void *xcalloc(size_t nmemb, size_t size);
104103
void *xrealloc(void *p, size_t size);
105104
char *xstrdup(const char *s);
105+
char *xstrndup(const char *s, size_t n);
106106

107107
struct gstr {
108108
size_t len;
@@ -120,9 +120,6 @@ void str_printf(struct gstr *gs, const char *fmt, ...);
120120
const char *str_get(struct gstr *gs);
121121

122122
/* symbol.c */
123-
extern struct expr *sym_env_list;
124-
125-
void sym_init(void);
126123
void sym_clear_all_valid(void);
127124
struct symbol *sym_choice_default(struct symbol *sym);
128125
const char *sym_get_string_default(struct symbol *sym);

scripts/kconfig/lkc_proto.h

+6
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,11 @@ const char * sym_get_string_value(struct symbol *sym);
4949

5050
const char * prop_get_type_name(enum prop_type type);
5151

52+
/* preprocess.c */
53+
void env_write_dep(FILE *f, const char *auto_conf_name);
54+
char *expand_string(const char *in);
55+
char *expand_dollar(const char **str);
56+
char *expand_one_token(const char **str);
57+
5258
/* expr.c */
5359
void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken);

scripts/kconfig/menu.c

-3
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,6 @@ void menu_add_option(int token, char *arg)
214214
zconf_error("trying to redefine defconfig symbol");
215215
sym_defconfig_list->flags |= SYMBOL_AUTO;
216216
break;
217-
case T_OPT_ENV:
218-
prop_add_env(arg);
219-
break;
220217
case T_OPT_ALLNOCONFIG_Y:
221218
current_entry->sym->flags |= SYMBOL_ALLNOCONFIG_Y;
222219
break;

0 commit comments

Comments
 (0)