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
))
91 for_all_symbols(i
, sym
) {
92 sym
->flags
|= SYMBOL_NEW
| SYMBOL_CHANGED
;
93 if (sym_is_choice(sym
))
94 sym
->flags
&= ~SYMBOL_NEW
;
95 sym
->flags
&= ~SYMBOL_VALID
;
103 sym
->user
.val
= NULL
;
109 int conf_read_simple(const char *name
)
118 in
= zconf_fopen(name
);
120 const char **names
= conf_confnames
;
121 while ((name
= *names
++)) {
122 name
= conf_expand_value(name
);
123 in
= zconf_fopen(name
);
126 "# using defaults found in %s\n"
135 conf_filename
= name
;
140 for_all_symbols(i
, sym
) {
141 sym
->flags
|= SYMBOL_NEW
| SYMBOL_CHANGED
;
142 if (sym_is_choice(sym
))
143 sym
->flags
&= ~SYMBOL_NEW
;
144 sym
->flags
&= ~SYMBOL_VALID
;
152 sym
->user
.val
= NULL
;
157 while (fgets(line
, sizeof(line
), in
)) {
162 if (memcmp(line
+ 2, "CONFIG_", 7))
164 p
= strchr(line
+ 9, ' ');
168 if (strncmp(p
, "is not set", 10))
170 sym
= sym_find(line
+ 9);
172 conf_warning("trying to assign nonexistent symbol %s", line
+ 9);
174 } else if (!(sym
->flags
& SYMBOL_NEW
)) {
175 conf_warning("trying to reassign symbol %s", sym
->name
);
182 sym
->flags
&= ~SYMBOL_NEW
;
189 if (memcmp(line
, "CONFIG_", 7)) {
190 conf_warning("unexpected data");
193 p
= strchr(line
+ 7, '=');
197 p2
= strchr(p
, '\n');
200 sym
= sym_find(line
+ 7);
202 conf_warning("trying to assign nonexistent symbol %s", line
+ 7);
204 } else if (!(sym
->flags
& SYMBOL_NEW
)) {
205 conf_warning("trying to reassign symbol %s", sym
->name
);
212 sym
->flags
&= ~SYMBOL_NEW
;
218 sym
->flags
&= ~SYMBOL_NEW
;
223 sym
->flags
&= ~SYMBOL_NEW
;
226 conf_warning("symbol value '%s' invalid for %s", p
, sym
->name
);
231 for (p2
= p
; (p2
= strpbrk(p2
, "\"\\")); p2
++) {
236 memmove(p2
, p2
+ 1, strlen(p2
));
239 conf_warning("invalid string found");
244 if (sym_string_valid(sym
, p
)) {
245 sym
->user
.val
= strdup(p
);
246 sym
->flags
&= ~SYMBOL_NEW
;
248 conf_warning("symbol value '%s' invalid for %s", p
, sym
->name
);
259 conf_warning("unexpected data");
262 if (sym
&& sym_is_choice_value(sym
)) {
263 struct symbol
*cs
= prop_get_symbol(sym_get_choice_prop(sym
));
264 switch (sym
->user
.tri
) {
268 if (cs
->user
.tri
== yes
) {
269 conf_warning("%s creates inconsistent choice state", sym
->name
);
270 cs
->flags
|= SYMBOL_NEW
;
274 if (cs
->user
.tri
!= no
) {
275 conf_warning("%s creates inconsistent choice state", sym
->name
);
276 cs
->flags
|= SYMBOL_NEW
;
281 cs
->user
.tri
= E_OR(cs
->user
.tri
, sym
->user
.tri
);
287 sym_calc_value(modules_sym
);
291 int conf_read(const char *name
)
294 struct property
*prop
;
298 if (conf_read_simple(name
))
301 for_all_symbols(i
, sym
) {
303 if (sym_is_choice(sym
) || (sym
->flags
& SYMBOL_AUTO
))
305 if (sym_has_value(sym
) && (sym
->flags
& SYMBOL_WRITE
)) {
306 /* check that calculated value agrees with saved value */
310 if (sym
->user
.tri
!= sym_get_tristate_value(sym
))
312 if (!sym_is_choice(sym
))
315 if (!strcmp(sym
->curr
.val
, sym
->user
.val
))
319 } else if (!sym_has_value(sym
) && !(sym
->flags
& SYMBOL_WRITE
))
320 /* no previous value and not saved */
323 /* maybe print value in verbose mode... */
325 if (sym_has_value(sym
) && !sym_is_choice_value(sym
)) {
326 if (sym
->visible
== no
)
327 sym
->flags
|= SYMBOL_NEW
;
332 if (!sym_string_within_range(sym
, sym
->user
.val
)) {
333 sym
->flags
|= SYMBOL_NEW
;
334 sym
->flags
&= ~SYMBOL_VALID
;
340 if (!sym_is_choice(sym
))
342 prop
= sym_get_choice_prop(sym
);
343 for (e
= prop
->expr
; e
; e
= e
->left
.expr
)
344 if (e
->right
.sym
->visible
!= no
)
345 sym
->flags
|= e
->right
.sym
->flags
& SYMBOL_NEW
;
348 sym_change_count
= conf_warnings
&& conf_unsaved
;
353 int conf_write(const char *name
)
358 const char *basename
;
359 char dirname
[128], tmpname
[128], newname
[128];
363 int use_timestamp
= 1;
367 if (name
&& name
[0]) {
371 if (!stat(name
, &st
) && S_ISDIR(st
.st_mode
)) {
372 strcpy(dirname
, name
);
373 strcat(dirname
, "/");
374 basename
= conf_def_filename
;
375 } else if ((slash
= strrchr(name
, '/'))) {
376 int size
= slash
- name
+ 1;
377 memcpy(dirname
, name
, size
);
380 basename
= slash
+ 1;
382 basename
= conf_def_filename
;
386 basename
= conf_def_filename
;
388 sprintf(newname
, "%s.tmpconfig.%d", dirname
, (int)getpid());
389 out
= fopen(newname
, "w");
394 out_h
= fopen(".tmpconfig.h", "w");
398 sym
= sym_lookup("OPENWRTVERSION", 0);
401 env
= getenv("KCONFIG_NOTIMESTAMP");
406 "# Automatically generated make config: don't edit\n"
407 "# OpenWrt version: %s\n"
410 sym_get_string_value(sym
),
411 use_timestamp
? "# " : "",
412 use_timestamp
? ctime(&now
) : "");
414 fprintf(out_h
, "/*\n"
415 " * Automatically generated C config: don't edit\n"
416 " * OpenWrt version: %s\n"
419 "#define AUTOCONF_INCLUDED\n",
420 sym_get_string_value(sym
),
421 use_timestamp
? " * " : "",
422 use_timestamp
? ctime(&now
) : "");
424 if (!sym_change_count
)
425 sym_clear_all_valid();
427 menu
= rootmenu
.list
;
431 if (!menu_is_visible(menu
))
433 str
= menu_get_prompt(menu
);
443 } else if (!(sym
->flags
& SYMBOL_CHOICE
)) {
445 if (!(sym
->flags
& SYMBOL_WRITE
))
447 sym
->flags
&= ~SYMBOL_WRITE
;
449 if (type
== S_TRISTATE
) {
450 sym_calc_value(modules_sym
);
451 /* tristate always enabled */
453 if (modules_sym
->curr
.tri
== no
)
460 switch (sym_get_tristate_value(sym
)) {
462 fprintf(out
, "# CONFIG_%s is not set\n", sym
->name
);
464 fprintf(out_h
, "#undef CONFIG_%s\n", sym
->name
);
467 fprintf(out
, "CONFIG_%s=m\n", sym
->name
);
469 fprintf(out_h
, "#define CONFIG_%s_MODULE 1\n", sym
->name
);
472 fprintf(out
, "CONFIG_%s=y\n", sym
->name
);
474 fprintf(out_h
, "#define CONFIG_%s 1\n", sym
->name
);
480 str
= sym_get_string_value(sym
);
481 fprintf(out
, "CONFIG_%s=\"", sym
->name
);
483 fprintf(out_h
, "#define CONFIG_%s \"", sym
->name
);
485 l
= strcspn(str
, "\"\\");
487 fwrite(str
, l
, 1, out
);
489 fwrite(str
, l
, 1, out_h
);
492 while (*str
== '\\' || *str
== '"') {
493 fprintf(out
, "\\%c", *str
);
495 fprintf(out_h
, "\\%c", *str
);
501 fputs("\"\n", out_h
);
504 str
= sym_get_string_value(sym
);
505 if (str
[0] != '0' || (str
[1] != 'x' && str
[1] != 'X')) {
506 fprintf(out
, "CONFIG_%s=%s\n", sym
->name
, str
);
508 fprintf(out_h
, "#define CONFIG_%s 0x%s\n", sym
->name
, str
);
512 str
= sym_get_string_value(sym
);
513 fprintf(out
, "CONFIG_%s=%s\n", sym
->name
, str
);
515 fprintf(out_h
, "#define CONFIG_%s %s\n", sym
->name
, str
);
527 else while ((menu
= menu
->parent
)) {
537 rename(".tmpconfig.h", "include/linux/autoconf.h");
538 file_write_dep(NULL
);
540 if (!name
|| basename
!= conf_def_filename
) {
542 name
= conf_def_filename
;
543 sprintf(tmpname
, "%s.old", name
);
544 rename(name
, tmpname
);
546 sprintf(tmpname
, "%s%s", dirname
, basename
);
547 if (rename(newname
, tmpname
))
550 sym_change_count
= 0;
This page took 0.070837 seconds and 5 git commands to generate.