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 static void conf_warning(const char *fmt
, ...)
18 __attribute__ ((format (printf
, 1, 2)));
20 static const char *conf_filename
;
21 static int conf_lineno
, conf_warnings
, conf_unsaved
;
23 const char conf_def_filename
[] = ".config";
25 const char conf_defname
[] = "scripts/config/defconfig";
27 const char *conf_confnames
[] = {
33 static void conf_warning(const char *fmt
, ...)
37 fprintf(stderr
, "%s:%d:warning: ", conf_filename
, conf_lineno
);
38 vfprintf(stderr
, fmt
, ap
);
39 fprintf(stderr
, "\n");
44 static char *conf_expand_value(const char *in
)
48 static char res_value
[SYMBOL_MAXLENGTH
];
49 char *dst
, name
[SYMBOL_MAXLENGTH
];
53 while ((src
= strchr(in
, '$'))) {
54 strncat(res_value
, in
, src
- in
);
57 while (isalnum(*src
) || *src
== '_')
60 sym
= sym_lookup(name
, 0);
62 strcat(res_value
, sym_get_string_value(sym
));
65 strcat(res_value
, in
);
70 char *conf_get_default_confname(void)
73 static char fullname
[PATH_MAX
+1];
76 name
= conf_expand_value(conf_defname
);
77 env
= getenv(SRCTREE
);
79 sprintf(fullname
, "%s/%s", env
, name
);
80 if (!stat(fullname
, &buf
))
86 int conf_read_simple(const char *name
)
95 in
= zconf_fopen(name
);
97 const char **names
= conf_confnames
;
98 while ((name
= *names
++)) {
99 name
= conf_expand_value(name
);
100 in
= zconf_fopen(name
);
103 "# using defaults found in %s\n"
112 conf_filename
= name
;
117 for_all_symbols(i
, sym
) {
118 sym
->flags
|= SYMBOL_NEW
| SYMBOL_CHANGED
;
119 if (sym_is_choice(sym
))
120 sym
->flags
&= ~SYMBOL_NEW
;
121 sym
->flags
&= ~SYMBOL_VALID
;
129 sym
->user
.val
= NULL
;
134 while (fgets(line
, sizeof(line
), in
)) {
139 if (memcmp(line
+ 2, "CONFIG_", 7))
141 p
= strchr(line
+ 9, ' ');
145 if (strncmp(p
, "is not set", 10))
147 sym
= sym_find(line
+ 9);
149 conf_warning("trying to assign nonexistent symbol %s", line
+ 9);
151 } else if (!(sym
->flags
& SYMBOL_NEW
)) {
152 conf_warning("trying to reassign symbol %s", sym
->name
);
159 sym
->flags
&= ~SYMBOL_NEW
;
166 if (memcmp(line
, "CONFIG_", 7)) {
167 conf_warning("unexpected data");
170 p
= strchr(line
+ 7, '=');
174 p2
= strchr(p
, '\n');
177 sym
= sym_find(line
+ 7);
179 conf_warning("trying to assign nonexistent symbol %s", line
+ 7);
181 } else if (!(sym
->flags
& SYMBOL_NEW
)) {
182 conf_warning("trying to reassign symbol %s", sym
->name
);
189 sym
->flags
&= ~SYMBOL_NEW
;
195 sym
->flags
&= ~SYMBOL_NEW
;
200 sym
->flags
&= ~SYMBOL_NEW
;
203 conf_warning("symbol value '%s' invalid for %s", p
, sym
->name
);
208 for (p2
= p
; (p2
= strpbrk(p2
, "\"\\")); p2
++) {
213 memmove(p2
, p2
+ 1, strlen(p2
));
216 conf_warning("invalid string found");
221 if (sym_string_valid(sym
, p
)) {
222 sym
->user
.val
= strdup(p
);
223 sym
->flags
&= ~SYMBOL_NEW
;
225 conf_warning("symbol value '%s' invalid for %s", p
, sym
->name
);
236 conf_warning("unexpected data");
239 if (sym
&& sym_is_choice_value(sym
)) {
240 struct symbol
*cs
= prop_get_symbol(sym_get_choice_prop(sym
));
241 switch (sym
->user
.tri
) {
245 if (cs
->user
.tri
== yes
) {
246 conf_warning("%s creates inconsistent choice state", sym
->name
);
247 cs
->flags
|= SYMBOL_NEW
;
251 if (cs
->user
.tri
!= no
) {
252 conf_warning("%s creates inconsistent choice state", sym
->name
);
253 cs
->flags
|= SYMBOL_NEW
;
258 cs
->user
.tri
= E_OR(cs
->user
.tri
, sym
->user
.tri
);
264 sym_calc_value(modules_sym
);
268 int conf_read(const char *name
)
271 struct property
*prop
;
275 if (conf_read_simple(name
))
278 for_all_symbols(i
, sym
) {
280 if (sym_is_choice(sym
) || (sym
->flags
& SYMBOL_AUTO
))
282 if (sym_has_value(sym
) && (sym
->flags
& SYMBOL_WRITE
)) {
283 /* check that calculated value agrees with saved value */
287 if (sym
->user
.tri
!= sym_get_tristate_value(sym
))
289 if (!sym_is_choice(sym
))
292 if (!strcmp(sym
->curr
.val
, sym
->user
.val
))
296 } else if (!sym_has_value(sym
) && !(sym
->flags
& SYMBOL_WRITE
))
297 /* no previous value and not saved */
300 /* maybe print value in verbose mode... */
302 if (sym_has_value(sym
) && !sym_is_choice_value(sym
)) {
303 if (sym
->visible
== no
)
304 sym
->flags
|= SYMBOL_NEW
;
309 if (!sym_string_within_range(sym
, sym
->user
.val
)) {
310 sym
->flags
|= SYMBOL_NEW
;
311 sym
->flags
&= ~SYMBOL_VALID
;
317 if (!sym_is_choice(sym
))
319 prop
= sym_get_choice_prop(sym
);
320 for (e
= prop
->expr
; e
; e
= e
->left
.expr
)
321 if (e
->right
.sym
->visible
!= no
)
322 sym
->flags
|= e
->right
.sym
->flags
& SYMBOL_NEW
;
325 sym_change_count
= conf_warnings
&& conf_unsaved
;
330 int conf_write(const char *name
)
335 const char *basename
;
336 char dirname
[128], tmpname
[128], newname
[128];
340 int use_timestamp
= 1;
344 if (name
&& name
[0]) {
348 if (!stat(name
, &st
) && S_ISDIR(st
.st_mode
)) {
349 strcpy(dirname
, name
);
350 strcat(dirname
, "/");
351 basename
= conf_def_filename
;
352 } else if ((slash
= strrchr(name
, '/'))) {
353 int size
= slash
- name
+ 1;
354 memcpy(dirname
, name
, size
);
357 basename
= slash
+ 1;
359 basename
= conf_def_filename
;
363 basename
= conf_def_filename
;
365 sprintf(newname
, "%s.tmpconfig.%d", dirname
, (int)getpid());
366 out
= fopen(newname
, "w");
371 out_h
= fopen(".tmpconfig.h", "w");
375 sym
= sym_lookup("OPENWRTVERSION", 0);
378 env
= getenv("KCONFIG_NOTIMESTAMP");
383 "# Automatically generated make config: don't edit\n"
384 "# OpenWrt version: %s\n"
387 sym_get_string_value(sym
),
388 use_timestamp
? "# " : "",
389 use_timestamp
? ctime(&now
) : "");
391 fprintf(out_h
, "/*\n"
392 " * Automatically generated C config: don't edit\n"
393 " * OpenWrt version: %s\n"
396 "#define AUTOCONF_INCLUDED\n",
397 sym_get_string_value(sym
),
398 use_timestamp
? " * " : "",
399 use_timestamp
? ctime(&now
) : "");
401 if (!sym_change_count
)
402 sym_clear_all_valid();
404 menu
= rootmenu
.list
;
408 if (!menu_is_visible(menu
))
410 str
= menu_get_prompt(menu
);
420 } else if (!(sym
->flags
& SYMBOL_CHOICE
)) {
422 if (!(sym
->flags
& SYMBOL_WRITE
))
424 sym
->flags
&= ~SYMBOL_WRITE
;
426 if (type
== S_TRISTATE
) {
427 sym_calc_value(modules_sym
);
428 /* tristate always enabled */
430 if (modules_sym
->curr
.tri
== no
)
437 switch (sym_get_tristate_value(sym
)) {
439 fprintf(out
, "# CONFIG_%s is not set\n", sym
->name
);
441 fprintf(out_h
, "#undef CONFIG_%s\n", sym
->name
);
444 fprintf(out
, "CONFIG_%s=m\n", sym
->name
);
446 fprintf(out_h
, "#define CONFIG_%s_MODULE 1\n", sym
->name
);
449 fprintf(out
, "CONFIG_%s=y\n", sym
->name
);
451 fprintf(out_h
, "#define CONFIG_%s 1\n", sym
->name
);
457 str
= sym_get_string_value(sym
);
458 fprintf(out
, "CONFIG_%s=\"", sym
->name
);
460 fprintf(out_h
, "#define CONFIG_%s \"", sym
->name
);
462 l
= strcspn(str
, "\"\\");
464 fwrite(str
, l
, 1, out
);
466 fwrite(str
, l
, 1, out_h
);
469 while (*str
== '\\' || *str
== '"') {
470 fprintf(out
, "\\%c", *str
);
472 fprintf(out_h
, "\\%c", *str
);
478 fputs("\"\n", out_h
);
481 str
= sym_get_string_value(sym
);
482 if (str
[0] != '0' || (str
[1] != 'x' && str
[1] != 'X')) {
483 fprintf(out
, "CONFIG_%s=%s\n", sym
->name
, str
);
485 fprintf(out_h
, "#define CONFIG_%s 0x%s\n", sym
->name
, str
);
489 str
= sym_get_string_value(sym
);
490 fprintf(out
, "CONFIG_%s=%s\n", sym
->name
, str
);
492 fprintf(out_h
, "#define CONFIG_%s %s\n", sym
->name
, str
);
504 else while ((menu
= menu
->parent
)) {
514 rename(".tmpconfig.h", "include/linux/autoconf.h");
515 file_write_dep(NULL
);
517 if (!name
|| basename
!= conf_def_filename
) {
519 name
= conf_def_filename
;
520 sprintf(tmpname
, "%s.old", name
);
521 rename(name
, tmpname
);
523 sprintf(tmpname
, "%s%s", dirname
, basename
);
524 if (rename(newname
, tmpname
))
527 sym_change_count
= 0;
This page took 0.079477 seconds and 5 git commands to generate.