2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
14 #define LKC_DIRECT_LINK
17 const char conf_def_filename
[] = ".config";
19 const char conf_defname
[] = "arch/$ARCH/defconfig";
21 const char *conf_confnames
[] = {
23 "/lib/modules/$UNAME_RELEASE/.config",
25 "/boot/config-$UNAME_RELEASE",
30 static char *conf_expand_value(const char *in
)
34 static char res_value
[SYMBOL_MAXLENGTH
];
35 char *dst
, name
[SYMBOL_MAXLENGTH
];
39 while ((src
= strchr(in
, '$'))) {
40 strncat(res_value
, in
, src
- in
);
43 while (isalnum(*src
) || *src
== '_')
46 sym
= sym_lookup(name
, 0);
48 strcat(res_value
, sym_get_string_value(sym
));
51 strcat(res_value
, in
);
56 char *conf_get_default_confname(void)
59 static char fullname
[PATH_MAX
+1];
62 name
= conf_expand_value(conf_defname
);
63 env
= getenv(SRCTREE
);
65 sprintf(fullname
, "%s/%s", env
, name
);
66 if (!stat(fullname
, &buf
))
72 int conf_read(const char *name
)
79 struct property
*prop
;
84 in
= zconf_fopen(name
);
86 const char **names
= conf_confnames
;
87 while ((name
= *names
++)) {
88 name
= conf_expand_value(name
);
89 in
= zconf_fopen(name
);
92 "# using defaults found in %s\n"
102 for_all_symbols(i
, sym
) {
103 sym
->flags
|= SYMBOL_NEW
| SYMBOL_CHANGED
;
104 sym
->flags
&= ~SYMBOL_VALID
;
112 sym
->user
.val
= NULL
;
117 while (fgets(line
, sizeof(line
), in
)) {
122 if (memcmp(line
+ 2, "CONFIG_", 7))
124 p
= strchr(line
+ 9, ' ');
128 if (strncmp(p
, "is not set", 10))
130 sym
= sym_find(line
+ 9);
132 fprintf(stderr
, "%s:%d: trying to assign nonexistent symbol %s\n", name
, lineno
, line
+ 9);
139 sym
->flags
&= ~SYMBOL_NEW
;
146 if (memcmp(line
, "CONFIG_", 7))
148 p
= strchr(line
+ 7, '=');
152 p2
= strchr(p
, '\n');
155 sym
= sym_find(line
+ 7);
157 fprintf(stderr
, "%s:%d: trying to assign nonexistent symbol %s\n", name
, lineno
, line
+ 7);
164 sym
->flags
&= ~SYMBOL_NEW
;
170 sym
->flags
&= ~SYMBOL_NEW
;
175 sym
->flags
&= ~SYMBOL_NEW
;
182 for (p2
= p
; (p2
= strpbrk(p2
, "\"\\")); p2
++) {
187 memmove(p2
, p2
+ 1, strlen(p2
));
190 fprintf(stderr
, "%s:%d: invalid string found\n", name
, lineno
);
195 if (sym_string_valid(sym
, p
)) {
196 sym
->user
.val
= strdup(p
);
197 sym
->flags
&= ~SYMBOL_NEW
;
199 fprintf(stderr
, "%s:%d: symbol value '%s' invalid for %s\n", name
, lineno
, p
, sym
->name
);
212 if (sym
&& sym_is_choice_value(sym
)) {
213 struct symbol
*cs
= prop_get_symbol(sym_get_choice_prop(sym
));
214 switch (sym
->user
.tri
) {
218 if (cs
->user
.tri
== yes
)
222 if (cs
->user
.tri
!= no
)
227 cs
->user
.tri
= E_OR(cs
->user
.tri
, sym
->user
.tri
);
228 cs
->flags
&= ~SYMBOL_NEW
;
234 sym_calc_value(modules_sym
);
235 for_all_symbols(i
, sym
) {
237 if (sym_has_value(sym
) && !sym_is_choice_value(sym
)) {
238 if (sym
->visible
== no
)
239 sym
->flags
|= SYMBOL_NEW
;
244 if (!sym_string_within_range(sym
, sym
->user
.val
))
245 sym
->flags
|= SYMBOL_NEW
;
250 if (!sym_is_choice(sym
))
252 prop
= sym_get_choice_prop(sym
);
253 for (e
= prop
->expr
; e
; e
= e
->left
.expr
)
254 if (e
->right
.sym
->visible
!= no
)
255 sym
->flags
|= e
->right
.sym
->flags
& SYMBOL_NEW
;
258 sym_change_count
= 1;
263 int conf_write(const char *name
)
268 const char *basename
;
269 char dirname
[128], tmpname
[128], newname
[128];
273 int use_timestamp
= 1;
277 if (name
&& name
[0]) {
281 if (!stat(name
, &st
) && S_ISDIR(st
.st_mode
)) {
282 strcpy(dirname
, name
);
283 strcat(dirname
, "/");
284 basename
= conf_def_filename
;
285 } else if ((slash
= strrchr(name
, '/'))) {
286 int size
= slash
- name
+ 1;
287 memcpy(dirname
, name
, size
);
290 basename
= slash
+ 1;
292 basename
= conf_def_filename
;
296 basename
= conf_def_filename
;
298 sprintf(newname
, "%s.tmpconfig.%d", dirname
, (int)getpid());
299 out
= fopen(newname
, "w");
304 out_h
= fopen(".tmpconfig.h", "w");
308 sym
= sym_lookup("KERNELRELEASE", 0);
311 env
= getenv("KCONFIG_NOTIMESTAMP");
316 "# Automatically generated make config: don't edit\n"
317 "# Linux kernel version: %s\n"
320 sym_get_string_value(sym
),
321 use_timestamp
? "# " : "",
322 use_timestamp
? ctime(&now
) : "");
324 fprintf(out_h
, "/*\n"
325 " * Automatically generated C config: don't edit\n"
326 " * Linux kernel version: %s\n"
329 "#define AUTOCONF_INCLUDED\n",
330 sym_get_string_value(sym
),
331 use_timestamp
? " * " : "",
332 use_timestamp
? ctime(&now
) : "");
334 if (!sym_change_count
)
335 sym_clear_all_valid();
337 menu
= rootmenu
.list
;
341 if (!menu_is_visible(menu
))
343 str
= menu_get_prompt(menu
);
353 } else if (!(sym
->flags
& SYMBOL_CHOICE
)) {
355 if (!(sym
->flags
& SYMBOL_WRITE
))
357 sym
->flags
&= ~SYMBOL_WRITE
;
359 if (type
== S_TRISTATE
) {
360 sym_calc_value(modules_sym
);
361 if (modules_sym
->curr
.tri
== no
)
367 switch (sym_get_tristate_value(sym
)) {
369 fprintf(out
, "# CONFIG_%s is not set\n", sym
->name
);
371 fprintf(out_h
, "#undef CONFIG_%s\n", sym
->name
);
374 fprintf(out
, "CONFIG_%s=m\n", sym
->name
);
376 fprintf(out_h
, "#define CONFIG_%s_MODULE 1\n", sym
->name
);
379 fprintf(out
, "CONFIG_%s=y\n", sym
->name
);
381 fprintf(out_h
, "#define CONFIG_%s 1\n", sym
->name
);
387 str
= sym_get_string_value(sym
);
388 fprintf(out
, "CONFIG_%s=\"", sym
->name
);
390 fprintf(out_h
, "#define CONFIG_%s \"", sym
->name
);
392 l
= strcspn(str
, "\"\\");
394 fwrite(str
, l
, 1, out
);
396 fwrite(str
, l
, 1, out_h
);
399 while (*str
== '\\' || *str
== '"') {
400 fprintf(out
, "\\%c", *str
);
402 fprintf(out_h
, "\\%c", *str
);
408 fputs("\"\n", out_h
);
411 str
= sym_get_string_value(sym
);
412 if (str
[0] != '0' || (str
[1] != 'x' && str
[1] != 'X')) {
413 fprintf(out
, "CONFIG_%s=%s\n", sym
->name
, str
);
415 fprintf(out_h
, "#define CONFIG_%s 0x%s\n", sym
->name
, str
);
419 str
= sym_get_string_value(sym
);
420 fprintf(out
, "CONFIG_%s=%s\n", sym
->name
, str
);
422 fprintf(out_h
, "#define CONFIG_%s %s\n", sym
->name
, str
);
434 else while ((menu
= menu
->parent
)) {
444 rename(".tmpconfig.h", "include/linux/autoconf.h");
445 file_write_dep(NULL
);
447 if (!name
|| basename
!= conf_def_filename
) {
449 name
= conf_def_filename
;
450 sprintf(tmpname
, "%s.old", name
);
451 rename(name
, tmpname
);
453 sprintf(tmpname
, "%s%s", dirname
, basename
);
454 if (rename(newname
, tmpname
))
457 sym_change_count
= 0;