19 static void conf_warning(
const char *
fmt, ...)
22 static
void conf_message(
const char *fmt, ...)
25 static
const char *conf_filename;
26 static
int conf_lineno, conf_warnings, conf_unsaved;
30 static
void conf_warning(
const char *fmt, ...)
34 fprintf(stderr,
"%s:%d:warning: ", conf_filename, conf_lineno);
41 static void conf_default_message_callback(
const char *
fmt,
va_list ap)
48 static void (*conf_message_callback) (
const char *
fmt,
va_list ap) =
49 conf_default_message_callback;
52 conf_message_callback =
fn;
55 static void conf_message(
const char *
fmt, ...)
60 if (conf_message_callback)
61 conf_message_callback(fmt, ap);
66 char *
name = getenv(
"KCONFIG_CONFIG");
68 return name ? name :
".config";
73 char *
name = getenv(
"KCONFIG_AUTOCONFIG");
75 return name ? name :
"include/config/auto.conf";
78 static char *conf_expand_value(
const char *
in)
87 while ((src =
strchr(in,
'$'))) {
88 strncat(res_value, in, src - in);
91 while (
isalnum(*src) || *src ==
'_')
113 sprintf(fullname,
"%s/%s", env, name);
114 if (!
stat(fullname, &buf))
120 static int conf_set_sym_val(
struct symbol *sym,
int def,
int def_flags,
char *
p)
128 sym->
flags |= def_flags;
135 sym->
flags |= def_flags;
139 sym->
def[def].tri =
no;
140 sym->
flags |= def_flags;
143 conf_warning(
"symbol value '%s' invalid for %s", p, sym->
name);
147 for (p2 = p; *p2 && !
isspace(*p2); p2++)
156 for (p2 = p; (p2 =
strpbrk(p2,
"\"\\")); p2++) {
164 conf_warning(
"invalid string found");
172 sym->
def[def].val = strdup(p);
173 sym->
flags |= def_flags;
175 conf_warning(
"symbol value '%s' invalid for %s", p, sym->
name);
185 #define LINE_GROWTH 16
186 static int add_byte(
int c,
char **lineptr,
size_t slen,
size_t *
n)
189 size_t new_size = slen + 1;
193 nline = realloc(*lineptr, new_size);
201 (*lineptr)[slen] =
c;
206 static ssize_t compat_getline(
char **lineptr,
size_t *
n, FILE *stream)
208 char *
line = *lineptr;
212 int c = getc(stream);
216 if (add_byte(c, &line, slen, n) < 0)
221 if (add_byte(
'\0', &line, slen, n) < 0)
228 if (add_byte(c, &line, slen, n) < 0)
244 size_t line_asize = 0;
269 name = conf_expand_value(prop->
expr->left.sym->name);
272 conf_message(
_(
"using defaults found in %s"),
282 conf_filename =
name;
291 if (sym_is_choice(sym))
292 sym->
flags |= def_flags;
297 if (sym->
def[def].val)
302 sym->
def[def].tri =
no;
306 while (compat_getline(&line, &line_asize, in) != -1) {
309 if (line[0] ==
'#') {
316 if (
strncmp(p,
"is not set", 10))
329 if (sym->
flags & def_flags) {
330 conf_warning(
"override: reassigning to symbol %s", sym->
name);
335 sym->
def[def].tri =
no;
336 sym->
flags |= def_flags;
363 if (sym->
flags & def_flags) {
364 conf_warning(
"override: reassigning to symbol %s", sym->
name);
366 if (conf_set_sym_val(sym, def, def_flags, p))
369 if (line[0] !=
'\r' && line[0] !=
'\n')
370 conf_warning(
"unexpected data");
374 if (sym && sym_is_choice_value(sym)) {
376 switch (sym->
def[def].tri) {
380 if (cs->
def[def].tri ==
yes) {
381 conf_warning(
"%s creates inconsistent choice state", sym->
name);
382 cs->
flags &= ~def_flags;
386 if (cs->
def[def].tri !=
no)
387 conf_warning(
"override: %s changes choice state", sym->
name);
423 if (!sym_is_choice(sym))
439 if (sym_has_value(sym) && !sym_is_choice_value(sym)) {
477 kconfig_print_symbol(FILE *
fp,
struct symbol *sym,
const char *
value,
void *
arg)
484 bool skip_unset = (arg !=
NULL);
487 fprintf(fp,
"# %s%s is not set\n",
500 kconfig_print_comment(FILE *fp,
const char *value,
void *arg)
502 const char *p =
value;
510 xfwrite(p, l, 1, fp);
521 .print_symbol = kconfig_print_symbol,
522 .print_comment = kconfig_print_comment,
531 header_print_symbol(FILE *fp,
struct symbol *sym,
const char *value,
void *arg)
537 const char *suffix =
"";
546 fprintf(fp,
"#define %s%s%s 1\n",
554 if (value[0] !=
'0' || (value[1] !=
'x' && value[1] !=
'X'))
556 fprintf(fp,
"#define %s%s %s%s\n",
562 fprintf(fp,
"#define %s%s %s\n",
572 header_print_comment(FILE *fp,
const char *value,
void *arg)
574 const char *p =
value;
583 xfwrite(p, l, 1, fp);
595 .print_symbol = header_print_symbol,
596 .print_comment = header_print_comment,
605 tristate_print_symbol(FILE *fp,
struct symbol *sym,
const char *value,
void *arg)
614 .print_symbol = tristate_print_symbol,
615 .print_comment = kconfig_print_comment,
618 static void conf_write_symbol(FILE *fp,
struct symbol *sym,
640 conf_write_heading(FILE *fp,
struct conf_printer *printer,
void *printer_arg)
646 "Automatically generated file; DO NOT EDIT.\n"
663 out = fopen(filename,
"w");
678 }
else if (!sym_is_choice(sym)) {
697 if (sym_is_choice_value(sym)) {
703 if (!sym_is_optional(cs) && sym == ds) {
705 sym_get_tristate_value(sym) ==
yes)
709 conf_write_symbol(out, sym, &kconfig_printer_cb,
NULL);
718 while ((menu = menu->
parent)) {
735 const char *basename;
741 if (name && name[0]) {
749 }
else if ((slash =
strrchr(name,
'/'))) {
750 int size = slash - name + 1;
751 memcpy(dirname, name, size);
754 basename = slash + 1;
762 sprintf(newname,
"%s%s", dirname, basename);
763 env = getenv(
"KCONFIG_OVERWRITECONFIG");
765 sprintf(tmpname,
"%s.tmpconfig.%d", dirname, (
int)getpid());
766 out = fopen(tmpname,
"w");
769 out = fopen(newname,
"w");
774 conf_write_heading(out, &kconfig_printer_cb,
NULL);
796 conf_write_symbol(out, sym, &kconfig_printer_cb,
NULL);
806 else while ((menu = menu->
parent)) {
816 strcat(dirname, basename);
818 rename(newname, dirname);
819 if (rename(tmpname, newname))
823 conf_message(
_(
"configuration written to %s"), newname);
830 static int conf_split_config(
void)
842 if (chdir(
"include/config"))
859 if (sym_get_tristate_value(sym) ==
881 if (sym_get_tristate_value(sym) ==
no)
902 *d++ = (c ==
'_') ?
'/' : c;
918 while ((d =
strchr(d,
'/'))) {
920 if (
stat(path, &
sb) && mkdir(path, 0755)) {
953 if (conf_split_config())
956 out = fopen(
".tmpconfig",
"w");
960 tristate = fopen(
".tmpconfig_tristate",
"w");
966 out_h = fopen(
".tmpconfig.h",
"w");
973 conf_write_heading(out, &kconfig_printer_cb,
NULL);
975 conf_write_heading(tristate, &tristate_printer_cb,
NULL);
977 conf_write_heading(out_h, &header_printer_cb,
NULL);
985 conf_write_symbol(out, sym, &kconfig_printer_cb, (
void *)1);
987 conf_write_symbol(tristate, sym, &tristate_printer_cb, (
void *)1);
989 conf_write_symbol(out_h, sym, &header_printer_cb,
NULL);
995 name = getenv(
"KCONFIG_AUTOHEADER");
997 name =
"include/generated/autoconf.h";
998 if (rename(
".tmpconfig.h", name))
1000 name = getenv(
"KCONFIG_TRISTATE");
1002 name =
"include/config/tristate.conf";
1003 if (rename(
".tmpconfig_tristate", name))
1010 if (rename(
".tmpconfig", name))
1016 static int sym_change_count;
1017 static void (*conf_changed_callback)(
void);
1021 int _sym_change_count = sym_change_count;
1022 sym_change_count =
count;
1023 if (conf_changed_callback &&
1024 (
bool)_sym_change_count != (
bool)count)
1025 conf_changed_callback();
1035 return sym_change_count;
1040 conf_changed_callback =
fn;
1043 static void randomize_choice_values(
struct symbol *csym)
1069 def = (rand() % cnt);
1086 static void set_all_choice_values(
struct symbol *csym)
1098 if (!sym_has_value(sym))
1108 struct symbol *sym, *csym;
1112 if (sym_has_value(sym))
1134 if (!(sym_is_choice(sym) && mode ==
def_random))
1155 if (sym_has_value(csym) || !sym_is_choice(csym))
1160 randomize_choice_values(csym);
1162 set_all_choice_values(csym);