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
;
233 if (cs
->user
.tri
!= no
) {
234 conf_warning("%s creates inconsistent choice state", sym
->name
);
235 cs
->flags
|= SYMBOL_NEW
;
240 cs
->user
.tri
= E_OR(cs
->user
.tri
, sym
->user
.tri
);
248 int conf_read_simple(const char *name
, int load_config
)
251 FILE *defaults
= NULL
;
254 char *home_dir
= getenv("HOME");
255 char *default_config_path
= NULL
;
258 default_config_path
= malloc(strlen(home_dir
) + sizeof(LOCAL_BUILD_SETTINGS
) + 1);
259 sprintf(default_config_path
, "%s%s", home_dir
, LOCAL_BUILD_SETTINGS
);
260 defaults
= zconf_fopen(default_config_path
);
262 printf("# using buildsystem predefines from %s\n", default_config_path
);
263 free(default_config_path
);
268 in
= zconf_fopen(name
);
270 const char **names
= conf_confnames
;
271 while ((name
= *names
++)) {
272 name
= conf_expand_value(name
);
273 in
= zconf_fopen(name
);
276 "# using defaults found in %s\n"
284 if (!in
&& !defaults
)
287 conf_filename
= name
;
292 for_all_symbols(i
, sym
) {
293 sym
->flags
|= SYMBOL_NEW
| SYMBOL_CHANGED
;
294 if (sym_is_choice(sym
))
295 sym
->flags
&= ~SYMBOL_NEW
;
296 sym
->flags
&= ~SYMBOL_VALID
;
304 sym
->user
.val
= NULL
;
310 conf_read_file(defaults
, sym
);
313 conf_read_file(in
, sym
);
316 sym_calc_value(modules_sym
);
321 int conf_read(const char *name
)
324 struct property
*prop
;
328 if (conf_read_simple(name
, 1))
331 for_all_symbols(i
, sym
) {
333 if (sym_is_choice(sym
) || (sym
->flags
& SYMBOL_AUTO
))
335 if (sym_has_value(sym
) && (sym
->flags
& SYMBOL_WRITE
)) {
336 /* check that calculated value agrees with saved value */
340 if (sym
->user
.tri
!= sym_get_tristate_value(sym
))
342 if (!sym_is_choice(sym
))
345 if (!strcmp(sym
->curr
.val
, sym
->user
.val
))
349 } else if (!sym_has_value(sym
) && !(sym
->flags
& SYMBOL_WRITE
))
350 /* no previous value and not saved */
353 /* maybe print value in verbose mode... */
355 if (sym_has_value(sym
) && !sym_is_choice_value(sym
)) {
356 if (sym
->visible
== no
)
357 sym
->flags
|= SYMBOL_NEW
;
362 if (!sym_string_within_range(sym
, sym
->user
.val
)) {
363 sym
->flags
|= SYMBOL_NEW
;
364 sym
->flags
&= ~SYMBOL_VALID
;
370 if (!sym_is_choice(sym
))
372 prop
= sym_get_choice_prop(sym
);
373 for (e
= prop
->expr
; e
; e
= e
->left
.expr
)
374 if (e
->right
.sym
->visible
!= no
)
375 sym
->flags
|= e
->right
.sym
->flags
& SYMBOL_NEW
;
378 sym_change_count
= conf_warnings
&& conf_unsaved
;
383 int conf_write(const char *name
)
388 const char *basename
;
389 char dirname
[128], tmpname
[128], newname
[128];
393 int use_timestamp
= 1;
397 if (name
&& name
[0]) {
401 if (!stat(name
, &st
) && S_ISDIR(st
.st_mode
)) {
402 strcpy(dirname
, name
);
403 strcat(dirname
, "/");
404 basename
= conf_def_filename
;
405 } else if ((slash
= strrchr(name
, '/'))) {
406 int size
= slash
- name
+ 1;
407 memcpy(dirname
, name
, size
);
410 basename
= slash
+ 1;
412 basename
= conf_def_filename
;
416 basename
= conf_def_filename
;
418 sprintf(newname
, "%s.tmpconfig.%d", dirname
, (int)getpid());
419 out
= fopen(newname
, "w");
422 sym
= sym_lookup("OPENWRTVERSION", 0);
425 env
= getenv("KCONFIG_NOTIMESTAMP");
430 "# Automatically generated make config: don't edit\n"
431 "# OpenWrt version: %s\n"
434 sym_get_string_value(sym
),
435 use_timestamp
? "# " : "",
436 use_timestamp
? ctime(&now
) : "");
438 if (!sym_change_count
)
439 sym_clear_all_valid();
441 menu
= rootmenu
.list
;
445 if (!menu_is_visible(menu
))
447 str
= menu_get_prompt(menu
);
452 } else if (!(sym
->flags
& SYMBOL_CHOICE
)) {
454 if (!(sym
->flags
& SYMBOL_WRITE
))
456 sym
->flags
&= ~SYMBOL_WRITE
;
458 if (type
== S_TRISTATE
) {
459 sym_calc_value(modules_sym
);
460 /* tristate always enabled */
462 if (modules_sym
->curr
.tri
== no
)
469 switch (sym_get_tristate_value(sym
)) {
471 fprintf(out
, "# CONFIG_%s is not set\n", sym
->name
);
474 fprintf(out
, "CONFIG_%s=m\n", sym
->name
);
477 fprintf(out
, "CONFIG_%s=y\n", sym
->name
);
483 str
= sym_get_string_value(sym
);
484 fprintf(out
, "CONFIG_%s=\"", sym
->name
);
486 l
= strcspn(str
, "\"\\");
488 fwrite(str
, l
, 1, out
);
491 while (*str
== '\\' || *str
== '"') {
492 fprintf(out
, "\\%c", *str
);
499 str
= sym_get_string_value(sym
);
500 if (str
[0] != '0' || (str
[1] != 'x' && str
[1] != 'X')) {
501 fprintf(out
, "CONFIG_%s=%s\n", sym
->name
, str
);
505 str
= sym_get_string_value(sym
);
506 fprintf(out
, "CONFIG_%s=%s\n", sym
->name
, str
);
518 else while ((menu
= menu
->parent
)) {
526 if (!name
|| basename
!= conf_def_filename
) {
528 name
= conf_def_filename
;
529 sprintf(tmpname
, "%s.old", name
);
530 rename(name
, tmpname
);
532 sprintf(tmpname
, "%s%s", dirname
, basename
);
533 if (rename(newname
, tmpname
))
536 sym_change_count
= 0;
This page took 0.07155 seconds and 5 git commands to generate.