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 #define LOCAL_BUILD_SETTINGS "/.openwrt/defconfig"
19 static void conf_warning(const char *fmt
, ...)
20 __attribute__ ((format (printf
, 1, 2)));
22 static const char *conf_filename
;
23 static int conf_lineno
, conf_warnings
, conf_unsaved
;
25 const char conf_def_filename
[] = ".config";
27 const char conf_defname
[] = "scripts/config/defconfig";
29 const char *conf_confnames
[] = {
35 static void conf_warning(const char *fmt
, ...)
39 fprintf(stderr
, "%s:%d:warning: ", conf_filename
, conf_lineno
);
40 vfprintf(stderr
, fmt
, ap
);
41 fprintf(stderr
, "\n");
46 static char *conf_expand_value(const char *in
)
50 static char res_value
[SYMBOL_MAXLENGTH
];
51 char *dst
, name
[SYMBOL_MAXLENGTH
];
55 while ((src
= strchr(in
, '$'))) {
56 strncat(res_value
, in
, src
- in
);
59 while (isalnum(*src
) || *src
== '_')
62 sym
= sym_lookup(name
, 0);
64 strcat(res_value
, sym_get_string_value(sym
));
67 strcat(res_value
, in
);
72 char *conf_get_default_confname(void)
75 static char fullname
[PATH_MAX
+1];
78 name
= conf_expand_value(conf_defname
);
79 env
= getenv(SRCTREE
);
81 sprintf(fullname
, "%s/%s", env
, name
);
82 if (!stat(fullname
, &buf
))
93 for_all_symbols(i
, sym
) {
94 sym
->flags
|= SYMBOL_NEW
| SYMBOL_CHANGED
;
95 if (sym_is_choice(sym
))
96 sym
->flags
&= ~SYMBOL_NEW
;
97 sym
->flags
&= ~SYMBOL_VALID
;
105 sym
->user
.val
= NULL
;
109 conf_read_simple(NULL
, 0);
112 int conf_read_file(FILE *in
, struct symbol
*sym
){
116 while (fgets(line
, sizeof(line
), in
)) {
121 if (memcmp(line
+ 2, "CONFIG_", 7))
123 p
= strchr(line
+ 9, ' ');
127 if (strncmp(p
, "is not set", 10))
129 sym
= sym_find(line
+ 9);
131 //conf_warning("trying to assign nonexistent symbol %s", line + 9);
133 } /*else if (!(sym->flags & SYMBOL_NEW)) {
134 //conf_warning("trying to reassign symbol %s", sym->name);
141 sym
->flags
&= ~SYMBOL_NEW
;
148 if (memcmp(line
, "CONFIG_", 7)) {
149 conf_warning("unexpected data");
152 p
= strchr(line
+ 7, '=');
156 p2
= strchr(p
, '\n');
159 sym
= sym_find(line
+ 7);
161 //conf_warning("trying to assign nonexistent symbol %s", line + 7);
163 } /*else if (!(sym->flags & SYMBOL_NEW)) {
164 conf_warning("trying to reassign symbol %s", sym->name);
171 sym
->flags
&= ~SYMBOL_NEW
;
177 sym
->flags
&= ~SYMBOL_NEW
;
182 sym
->flags
&= ~SYMBOL_NEW
;
185 conf_warning("symbol value '%s' invalid for %s", p
, sym
->name
);
190 for (p2
= p
; (p2
= strpbrk(p2
, "\"\\")); p2
++) {
195 memmove(p2
, p2
+ 1, strlen(p2
));
198 conf_warning("invalid string found");
203 if (sym_string_valid(sym
, p
)) {
204 sym
->user
.val
= strdup(p
);
205 sym
->flags
&= ~SYMBOL_NEW
;
207 conf_warning("symbol value '%s' invalid for %s", p
, sym
->name
);
218 conf_warning("unexpected data");
221 if (sym
&& sym_is_choice_value(sym
)) {
222 struct symbol
*cs
= prop_get_symbol(sym_get_choice_prop(sym
));
223 switch (sym
->user
.tri
) {
227 if (cs
->user
.tri
== yes
) {
228 conf_warning("%s creates inconsistent choice state", sym
->name
);
229 cs
->flags
|= SYMBOL_NEW
;
236 cs
->user
.tri
= E_OR(cs
->user
.tri
, sym
->user
.tri
);
244 int conf_read_simple(const char *name
, int load_config
)
247 FILE *defaults
= NULL
;
250 char *home_dir
= getenv("HOME");
251 char *default_config_path
= NULL
;
254 default_config_path
= malloc(strlen(home_dir
) + sizeof(LOCAL_BUILD_SETTINGS
) + 1);
255 sprintf(default_config_path
, "%s%s", home_dir
, LOCAL_BUILD_SETTINGS
);
256 defaults
= zconf_fopen(default_config_path
);
258 printf("# using buildsystem predefines from %s\n", default_config_path
);
259 free(default_config_path
);
264 in
= zconf_fopen(name
);
266 const char **names
= conf_confnames
;
267 while ((name
= *names
++)) {
268 name
= conf_expand_value(name
);
269 in
= zconf_fopen(name
);
272 "# using defaults found in %s\n"
280 if (!in
&& !defaults
)
283 conf_filename
= name
;
288 for_all_symbols(i
, sym
) {
289 sym
->flags
|= SYMBOL_NEW
| SYMBOL_CHANGED
;
290 if (sym_is_choice(sym
))
291 sym
->flags
&= ~SYMBOL_NEW
;
292 sym
->flags
&= ~SYMBOL_VALID
;
300 sym
->user
.val
= NULL
;
306 conf_read_file(defaults
, sym
);
309 conf_read_file(in
, sym
);
312 sym_calc_value(modules_sym
);
317 int conf_read(const char *name
)
320 struct property
*prop
;
324 if (conf_read_simple(name
, 1))
327 for_all_symbols(i
, sym
) {
329 if (sym_is_choice(sym
) || (sym
->flags
& SYMBOL_AUTO
))
331 if (sym_has_value(sym
) && (sym
->flags
& SYMBOL_WRITE
)) {
332 /* check that calculated value agrees with saved value */
336 if (sym
->user
.tri
!= sym_get_tristate_value(sym
))
338 if (!sym_is_choice(sym
))
341 if (!strcmp(sym
->curr
.val
, sym
->user
.val
))
345 } else if (!sym_has_value(sym
) && !(sym
->flags
& SYMBOL_WRITE
))
346 /* no previous value and not saved */
349 /* maybe print value in verbose mode... */
351 if (sym_has_value(sym
) && !sym_is_choice_value(sym
)) {
352 if (sym
->visible
== no
)
353 sym
->flags
|= SYMBOL_NEW
;
358 if (!sym_string_within_range(sym
, sym
->user
.val
)) {
359 sym
->flags
|= SYMBOL_NEW
;
360 sym
->flags
&= ~SYMBOL_VALID
;
366 if (!sym_is_choice(sym
))
368 prop
= sym_get_choice_prop(sym
);
369 for (e
= prop
->expr
; e
; e
= e
->left
.expr
)
370 if (e
->right
.sym
->visible
!= no
)
371 sym
->flags
|= e
->right
.sym
->flags
& SYMBOL_NEW
;
374 sym_change_count
= conf_warnings
&& conf_unsaved
;
379 int conf_write(const char *name
)
384 const char *basename
;
385 char dirname
[128], tmpname
[128], newname
[128];
389 int use_timestamp
= 1;
393 if (name
&& name
[0]) {
397 if (!stat(name
, &st
) && S_ISDIR(st
.st_mode
)) {
398 strcpy(dirname
, name
);
399 strcat(dirname
, "/");
400 basename
= conf_def_filename
;
401 } else if ((slash
= strrchr(name
, '/'))) {
402 int size
= slash
- name
+ 1;
403 memcpy(dirname
, name
, size
);
406 basename
= slash
+ 1;
408 basename
= conf_def_filename
;
412 basename
= conf_def_filename
;
414 sprintf(newname
, "%s.tmpconfig.%d", dirname
, (int)getpid());
415 out
= fopen(newname
, "w");
418 sym
= sym_lookup("OPENWRTVERSION", 0);
421 env
= getenv("KCONFIG_NOTIMESTAMP");
426 "# Automatically generated make config: don't edit\n"
427 "# OpenWrt version: %s\n"
430 sym_get_string_value(sym
),
431 use_timestamp
? "# " : "",
432 use_timestamp
? ctime(&now
) : "");
434 if (!sym_change_count
)
435 sym_clear_all_valid();
437 menu
= rootmenu
.list
;
441 if (!menu_is_visible(menu
))
443 str
= menu_get_prompt(menu
);
448 } else if (!(sym
->flags
& SYMBOL_CHOICE
)) {
450 if (!(sym
->flags
& SYMBOL_WRITE
))
452 sym
->flags
&= ~SYMBOL_WRITE
;
454 if (type
== S_TRISTATE
) {
455 sym_calc_value(modules_sym
);
456 /* tristate always enabled */
458 if (modules_sym
->curr
.tri
== no
)
465 switch (sym_get_tristate_value(sym
)) {
467 fprintf(out
, "# CONFIG_%s is not set\n", sym
->name
);
470 fprintf(out
, "CONFIG_%s=m\n", sym
->name
);
473 fprintf(out
, "CONFIG_%s=y\n", sym
->name
);
479 str
= sym_get_string_value(sym
);
480 fprintf(out
, "CONFIG_%s=\"", sym
->name
);
482 l
= strcspn(str
, "\"\\");
484 fwrite(str
, l
, 1, out
);
487 while (*str
== '\\' || *str
== '"') {
488 fprintf(out
, "\\%c", *str
);
495 str
= sym_get_string_value(sym
);
496 if (str
[0] != '0' || (str
[1] != 'x' && str
[1] != 'X')) {
497 fprintf(out
, "CONFIG_%s=%s\n", sym
->name
, str
);
501 str
= sym_get_string_value(sym
);
502 fprintf(out
, "CONFIG_%s=%s\n", sym
->name
, str
);
514 else while ((menu
= menu
->parent
)) {
522 if (!name
|| basename
!= conf_def_filename
) {
524 name
= conf_def_filename
;
525 sprintf(tmpname
, "%s.old", name
);
526 rename(name
, tmpname
);
528 sprintf(tmpname
, "%s%s", dirname
, basename
);
529 if (rename(newname
, tmpname
))
532 sym_change_count
= 0;
This page took 0.06985 seconds and 5 git commands to generate.