2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
13 #define LKC_DIRECT_LINK
16 const char conf_def_filename
[] = ".config";
18 const char conf_defname
[] = "sysdeps/linux/defconfig";
20 const char *conf_confnames
[] = {
26 static char *conf_expand_value(const char *in
)
30 static char res_value
[SYMBOL_MAXLENGTH
];
31 char *dst
, name
[SYMBOL_MAXLENGTH
];
35 while ((src
= strchr(in
, '$'))) {
36 strncat(res_value
, in
, src
- in
);
39 while (isalnum(*src
) || *src
== '_')
42 sym
= sym_lookup(name
, 0);
44 strcat(res_value
, sym_get_string_value(sym
));
47 strcat(res_value
, in
);
52 char *conf_get_default_confname(void)
55 static char fullname
[PATH_MAX
+1];
58 name
= conf_expand_value(conf_defname
);
59 env
= getenv(SRCTREE
);
61 sprintf(fullname
, "%s/%s", env
, name
);
62 if (!stat(fullname
, &buf
))
68 int conf_read(const char *name
)
75 struct property
*prop
;
80 in
= zconf_fopen(name
);
82 const char **names
= conf_confnames
;
83 while ((name
= *names
++)) {
84 name
= conf_expand_value(name
);
85 in
= zconf_fopen(name
);
88 "# using defaults found in %s\n"
98 for_all_symbols(i
, sym
) {
99 sym
->flags
|= SYMBOL_NEW
| SYMBOL_CHANGED
;
100 sym
->flags
&= ~SYMBOL_VALID
;
108 sym
->user
.val
= NULL
;
113 while (fgets(line
, sizeof(line
), in
)) {
120 p
= strchr(line
+ 2, ' ');
124 if (strncmp(p
, "is not set", 10))
126 sym
= sym_find(line
+ 2);
128 fprintf(stderr
, "%s:%d: trying to assign nonexistent symbol %s\n", name
, lineno
, line
+ 2);
135 sym
->flags
&= ~SYMBOL_NEW
;
143 p
= strchr(line
, '=');
147 p2
= strchr(p
, '\n');
150 sym
= sym_find(line
);
152 fprintf(stderr
, "%s:%d: trying to assign nonexistent symbol %s\n", name
, lineno
, line
);
159 sym
->flags
&= ~SYMBOL_NEW
;
165 sym
->flags
&= ~SYMBOL_NEW
;
170 sym
->flags
&= ~SYMBOL_NEW
;
177 for (p2
= p
; (p2
= strpbrk(p2
, "\"\\")); p2
++) {
182 memmove(p2
, p2
+ 1, strlen(p2
));
185 fprintf(stderr
, "%s:%d: invalid string found\n", name
, lineno
);
190 if (sym_string_valid(sym
, p
)) {
191 sym
->user
.val
= strdup(p
);
192 sym
->flags
&= ~SYMBOL_NEW
;
194 fprintf(stderr
, "%s:%d: symbol value '%s' invalid for %s\n", name
, lineno
, p
, sym
->name
);
207 if (sym
&& sym_is_choice_value(sym
)) {
208 struct symbol
*cs
= prop_get_symbol(sym_get_choice_prop(sym
));
209 switch (sym
->user
.tri
) {
213 if (cs
->user
.tri
== yes
)
217 if (cs
->user
.tri
!= no
)
222 cs
->user
.tri
= E_OR(cs
->user
.tri
, sym
->user
.tri
);
223 cs
->flags
&= ~SYMBOL_NEW
;
229 sym_calc_value(modules_sym
);
230 for_all_symbols(i
, sym
) {
232 if (sym_has_value(sym
) && !sym_is_choice_value(sym
)) {
233 if (sym
->visible
== no
)
234 sym
->flags
|= SYMBOL_NEW
;
239 if (!sym_string_within_range(sym
, sym
->user
.val
))
240 sym
->flags
|= SYMBOL_NEW
;
245 if (!sym_is_choice(sym
))
247 prop
= sym_get_choice_prop(sym
);
248 for (e
= prop
->expr
; e
; e
= e
->left
.expr
)
249 if (e
->right
.sym
->visible
!= no
)
250 sym
->flags
|= e
->right
.sym
->flags
& SYMBOL_NEW
;
253 sym_change_count
= 1;
258 int conf_write(const char *name
)
263 const char *basename
;
264 char dirname
[128], tmpname
[128], newname
[128];
269 if (name
&& name
[0]) {
273 if (!stat(name
, &st
) && S_ISDIR(st
.st_mode
)) {
274 strcpy(dirname
, name
);
275 strcat(dirname
, "/");
276 basename
= conf_def_filename
;
277 } else if ((slash
= strrchr(name
, '/'))) {
278 int size
= slash
- name
+ 1;
279 memcpy(dirname
, name
, size
);
282 basename
= slash
+ 1;
284 basename
= conf_def_filename
;
288 basename
= conf_def_filename
;
290 sprintf(newname
, "%s.tmpconfig.%d", dirname
, getpid());
291 out
= fopen(newname
, "w");
296 out_h
= fopen(".tmpconfig.h", "w");
301 "# Automatically generated make config: don't edit\n"
304 fprintf(out_h
, "/*\n"
305 " * Automatically generated header file: don't edit\n"
307 "#define AUTOCONF_INCLUDED\n\n"
308 "/* Version Number */\n"
309 "#define BB_VER \"%s\"\n"
310 "#define BB_BT \"%s\"\n",
312 getenv("BUILDTIME"));
313 if (getenv("EXTRA_VERSION"))
314 fprintf(out_h
, "#define BB_EXTRA_VERSION \"%s\"\n",
315 getenv("EXTRA_VERSION"));
316 fprintf(out_h
, "\n");
319 if (!sym_change_count
)
320 sym_clear_all_valid();
322 menu
= rootmenu
.list
;
326 if (!menu_is_visible(menu
))
328 str
= menu_get_prompt(menu
);
338 } else if (!(sym
->flags
& SYMBOL_CHOICE
)) {
340 if (!(sym
->flags
& SYMBOL_WRITE
))
342 sym
->flags
&= ~SYMBOL_WRITE
;
344 if (type
== S_TRISTATE
) {
345 sym_calc_value(modules_sym
);
346 if (modules_sym
->curr
.tri
== no
)
352 switch (sym_get_tristate_value(sym
)) {
354 fprintf(out
, "# %s is not set\n", sym
->name
);
356 fprintf(out_h
, "#undef %s\n", sym
->name
);
359 fprintf(out
, "%s=m\n", sym
->name
);
362 fprintf(out_h
, "#define %s_MODULE 1\n", sym
->name
);
366 fprintf(out
, "%s=y\n", sym
->name
);
368 fprintf(out_h
, "#define %s 1\n", sym
->name
);
374 str
= sym_get_string_value(sym
);
375 fprintf(out
, "%s=\"", sym
->name
);
377 fprintf(out_h
, "#define %s \"", sym
->name
);
379 l
= strcspn(str
, "\"\\");
381 fwrite(str
, l
, 1, out
);
383 fwrite(str
, l
, 1, out_h
);
386 while (*str
== '\\' || *str
== '"') {
387 fprintf(out
, "\\%c", *str
);
389 fprintf(out_h
, "\\%c", *str
);
395 fputs("\"\n", out_h
);
398 str
= sym_get_string_value(sym
);
399 if (str
[0] != '0' || (str
[1] != 'x' && str
[1] != 'X')) {
400 fprintf(out
, "%s=%s\n", sym
->name
, str
);
402 fprintf(out_h
, "#define %s 0x%s\n", sym
->name
, str
);
406 str
= sym_get_string_value(sym
);
407 fprintf(out
, "%s=%s\n", sym
->name
, str
);
409 fprintf(out_h
, "#define %s %s\n", sym
->name
, str
);
421 else while ((menu
= menu
->parent
)) {
431 rename(".tmpconfig.h", "include/config.h");
432 file_write_dep(NULL
);
434 if (!name
|| basename
!= conf_def_filename
) {
436 name
= conf_def_filename
;
437 sprintf(tmpname
, "%s.old", name
);
438 rename(name
, tmpname
);
440 sprintf(tmpname
, "%s%s", dirname
, basename
);
441 if (rename(newname
, tmpname
))
444 sym_change_count
= 0;
This page took 0.05929 seconds and 5 git commands to generate.