Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> |
| 3 | * Released under the terms of the GNU GPL v2.0. |
| 4 | */ |
| 5 | |
| 6 | #include <sys/stat.h> |
| 7 | #include <ctype.h> |
Arnaud Lacombe | 94bedec | 2010-08-17 01:40:20 -0400 | [diff] [blame] | 8 | #include <errno.h> |
Roman Zippel | 2e3646e | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 9 | #include <fcntl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
| 13 | #include <time.h> |
| 14 | #include <unistd.h> |
| 15 | |
| 16 | #define LKC_DIRECT_LINK |
| 17 | #include "lkc.h" |
| 18 | |
Roman Zippel | c1a0f5e | 2005-11-08 21:34:54 -0800 | [diff] [blame] | 19 | static void conf_warning(const char *fmt, ...) |
| 20 | __attribute__ ((format (printf, 1, 2))); |
| 21 | |
| 22 | static const char *conf_filename; |
| 23 | static int conf_lineno, conf_warnings, conf_unsaved; |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | const char conf_defname[] = "arch/$ARCH/defconfig"; |
| 26 | |
Roman Zippel | c1a0f5e | 2005-11-08 21:34:54 -0800 | [diff] [blame] | 27 | static void conf_warning(const char *fmt, ...) |
| 28 | { |
| 29 | va_list ap; |
| 30 | va_start(ap, fmt); |
| 31 | fprintf(stderr, "%s:%d:warning: ", conf_filename, conf_lineno); |
| 32 | vfprintf(stderr, fmt, ap); |
| 33 | fprintf(stderr, "\n"); |
| 34 | va_end(ap); |
| 35 | conf_warnings++; |
| 36 | } |
| 37 | |
Roman Zippel | 14cdd3c | 2006-06-08 22:12:51 -0700 | [diff] [blame] | 38 | const char *conf_get_configname(void) |
| 39 | { |
| 40 | char *name = getenv("KCONFIG_CONFIG"); |
| 41 | |
| 42 | return name ? name : ".config"; |
| 43 | } |
| 44 | |
Markus Heidelberg | 12122f6 | 2009-05-18 01:36:54 +0200 | [diff] [blame] | 45 | const char *conf_get_autoconfig_name(void) |
| 46 | { |
| 47 | char *name = getenv("KCONFIG_AUTOCONFIG"); |
| 48 | |
| 49 | return name ? name : "include/config/auto.conf"; |
| 50 | } |
| 51 | |
J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 52 | static char *conf_expand_value(const char *in) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { |
| 54 | struct symbol *sym; |
J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 55 | const char *src; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | static char res_value[SYMBOL_MAXLENGTH]; |
| 57 | char *dst, name[SYMBOL_MAXLENGTH]; |
| 58 | |
| 59 | res_value[0] = 0; |
| 60 | dst = name; |
| 61 | while ((src = strchr(in, '$'))) { |
| 62 | strncat(res_value, in, src - in); |
| 63 | src++; |
| 64 | dst = name; |
| 65 | while (isalnum(*src) || *src == '_') |
| 66 | *dst++ = *src++; |
| 67 | *dst = 0; |
| 68 | sym = sym_lookup(name, 0); |
| 69 | sym_calc_value(sym); |
| 70 | strcat(res_value, sym_get_string_value(sym)); |
| 71 | in = src; |
| 72 | } |
| 73 | strcat(res_value, in); |
| 74 | |
| 75 | return res_value; |
| 76 | } |
| 77 | |
| 78 | char *conf_get_default_confname(void) |
| 79 | { |
| 80 | struct stat buf; |
| 81 | static char fullname[PATH_MAX+1]; |
| 82 | char *env, *name; |
| 83 | |
| 84 | name = conf_expand_value(conf_defname); |
| 85 | env = getenv(SRCTREE); |
| 86 | if (env) { |
| 87 | sprintf(fullname, "%s/%s", env, name); |
| 88 | if (!stat(fullname, &buf)) |
| 89 | return fullname; |
| 90 | } |
| 91 | return name; |
| 92 | } |
| 93 | |
Sam Ravnborg | 9c900a9 | 2007-11-10 20:01:56 +0100 | [diff] [blame] | 94 | static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) |
| 95 | { |
| 96 | char *p2; |
| 97 | |
| 98 | switch (sym->type) { |
| 99 | case S_TRISTATE: |
| 100 | if (p[0] == 'm') { |
| 101 | sym->def[def].tri = mod; |
| 102 | sym->flags |= def_flags; |
| 103 | break; |
| 104 | } |
| 105 | case S_BOOLEAN: |
| 106 | if (p[0] == 'y') { |
| 107 | sym->def[def].tri = yes; |
| 108 | sym->flags |= def_flags; |
| 109 | break; |
| 110 | } |
| 111 | if (p[0] == 'n') { |
| 112 | sym->def[def].tri = no; |
| 113 | sym->flags |= def_flags; |
| 114 | break; |
| 115 | } |
| 116 | conf_warning("symbol value '%s' invalid for %s", p, sym->name); |
| 117 | break; |
| 118 | case S_OTHER: |
| 119 | if (*p != '"') { |
| 120 | for (p2 = p; *p2 && !isspace(*p2); p2++) |
| 121 | ; |
| 122 | sym->type = S_STRING; |
| 123 | goto done; |
| 124 | } |
| 125 | case S_STRING: |
| 126 | if (*p++ != '"') |
| 127 | break; |
| 128 | for (p2 = p; (p2 = strpbrk(p2, "\"\\")); p2++) { |
| 129 | if (*p2 == '"') { |
| 130 | *p2 = 0; |
| 131 | break; |
| 132 | } |
| 133 | memmove(p2, p2 + 1, strlen(p2)); |
| 134 | } |
| 135 | if (!p2) { |
| 136 | conf_warning("invalid string found"); |
| 137 | return 1; |
| 138 | } |
| 139 | case S_INT: |
| 140 | case S_HEX: |
| 141 | done: |
| 142 | if (sym_string_valid(sym, p)) { |
| 143 | sym->def[def].val = strdup(p); |
| 144 | sym->flags |= def_flags; |
| 145 | } else { |
| 146 | conf_warning("symbol value '%s' invalid for %s", p, sym->name); |
| 147 | return 1; |
| 148 | } |
| 149 | break; |
| 150 | default: |
| 151 | ; |
| 152 | } |
| 153 | return 0; |
| 154 | } |
| 155 | |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 156 | int conf_read_simple(const char *name, int def) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
| 158 | FILE *in = NULL; |
| 159 | char line[1024]; |
| 160 | char *p, *p2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | struct symbol *sym; |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 162 | int i, def_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
| 164 | if (name) { |
| 165 | in = zconf_fopen(name); |
| 166 | } else { |
Roman Zippel | face437 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 167 | struct property *prop; |
| 168 | |
Roman Zippel | 14cdd3c | 2006-06-08 22:12:51 -0700 | [diff] [blame] | 169 | name = conf_get_configname(); |
Roman Zippel | ddc97ca | 2006-06-08 22:12:38 -0700 | [diff] [blame] | 170 | in = zconf_fopen(name); |
| 171 | if (in) |
| 172 | goto load; |
Karsten Wiese | bfc1000 | 2006-12-13 00:34:07 -0800 | [diff] [blame] | 173 | sym_add_change_count(1); |
Ulf Magnusson | ac1ffde | 2010-07-27 21:57:43 +0200 | [diff] [blame] | 174 | if (!sym_defconfig_list) { |
| 175 | if (modules_sym) |
| 176 | sym_calc_value(modules_sym); |
Roman Zippel | face437 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 177 | return 1; |
Ulf Magnusson | ac1ffde | 2010-07-27 21:57:43 +0200 | [diff] [blame] | 178 | } |
Roman Zippel | face437 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 179 | |
| 180 | for_all_defaults(sym_defconfig_list, prop) { |
| 181 | if (expr_calc_value(prop->visible.expr) == no || |
| 182 | prop->expr->type != E_SYMBOL) |
| 183 | continue; |
| 184 | name = conf_expand_value(prop->expr->left.sym->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | in = zconf_fopen(name); |
| 186 | if (in) { |
Arnaldo Carvalho de Melo | 3b9fa09 | 2005-05-05 15:09:46 -0700 | [diff] [blame] | 187 | printf(_("#\n" |
Roman Zippel | ddc97ca | 2006-06-08 22:12:38 -0700 | [diff] [blame] | 188 | "# using defaults found in %s\n" |
| 189 | "#\n"), name); |
| 190 | goto load; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | if (!in) |
| 195 | return 1; |
| 196 | |
Roman Zippel | ddc97ca | 2006-06-08 22:12:38 -0700 | [diff] [blame] | 197 | load: |
Roman Zippel | c1a0f5e | 2005-11-08 21:34:54 -0800 | [diff] [blame] | 198 | conf_filename = name; |
| 199 | conf_lineno = 0; |
| 200 | conf_warnings = 0; |
| 201 | conf_unsaved = 0; |
| 202 | |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 203 | def_flags = SYMBOL_DEF << def; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | for_all_symbols(i, sym) { |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 205 | sym->flags |= SYMBOL_CHANGED; |
| 206 | sym->flags &= ~(def_flags|SYMBOL_VALID); |
Roman Zippel | c1a0f5e | 2005-11-08 21:34:54 -0800 | [diff] [blame] | 207 | if (sym_is_choice(sym)) |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 208 | sym->flags |= def_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | switch (sym->type) { |
| 210 | case S_INT: |
| 211 | case S_HEX: |
| 212 | case S_STRING: |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 213 | if (sym->def[def].val) |
| 214 | free(sym->def[def].val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | default: |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 216 | sym->def[def].val = NULL; |
| 217 | sym->def[def].tri = no; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
| 221 | while (fgets(line, sizeof(line), in)) { |
Roman Zippel | c1a0f5e | 2005-11-08 21:34:54 -0800 | [diff] [blame] | 222 | conf_lineno++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | sym = NULL; |
Arnaud Lacombe | 8baefd3 | 2010-08-24 00:14:47 -0400 | [diff] [blame] | 224 | if (line[0] == '#') { |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 225 | if (memcmp(line + 2, CONFIG_, strlen(CONFIG_))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | continue; |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 227 | p = strchr(line + 2 + strlen(CONFIG_), ' '); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | if (!p) |
| 229 | continue; |
| 230 | *p++ = 0; |
| 231 | if (strncmp(p, "is not set", 10)) |
| 232 | continue; |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 233 | if (def == S_DEF_USER) { |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 234 | sym = sym_find(line + 2 + strlen(CONFIG_)); |
zippel@linux-m68k.org | 661b068 | 2008-09-29 05:27:11 +0200 | [diff] [blame] | 235 | if (!sym) { |
| 236 | sym_add_change_count(1); |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 237 | break; |
zippel@linux-m68k.org | 661b068 | 2008-09-29 05:27:11 +0200 | [diff] [blame] | 238 | } |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 239 | } else { |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 240 | sym = sym_lookup(line + 2 + strlen(CONFIG_), 0); |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 241 | if (sym->type == S_UNKNOWN) |
| 242 | sym->type = S_BOOLEAN; |
| 243 | } |
| 244 | if (sym->flags & def_flags) { |
Jan Engelhardt | d84876f | 2008-01-03 23:33:44 +0100 | [diff] [blame] | 245 | conf_warning("override: reassigning to symbol %s", sym->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } |
| 247 | switch (sym->type) { |
| 248 | case S_BOOLEAN: |
| 249 | case S_TRISTATE: |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 250 | sym->def[def].tri = no; |
| 251 | sym->flags |= def_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | break; |
| 253 | default: |
| 254 | ; |
| 255 | } |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 256 | } else if (memcmp(line, CONFIG_, strlen(CONFIG_)) == 0) { |
| 257 | p = strchr(line + strlen(CONFIG_), '='); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | if (!p) |
| 259 | continue; |
| 260 | *p++ = 0; |
| 261 | p2 = strchr(p, '\n'); |
Matthew Wilcox | d3660a8 | 2006-07-13 12:54:07 -0600 | [diff] [blame] | 262 | if (p2) { |
| 263 | *p2-- = 0; |
| 264 | if (*p2 == '\r') |
| 265 | *p2 = 0; |
| 266 | } |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 267 | if (def == S_DEF_USER) { |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 268 | sym = sym_find(line + strlen(CONFIG_)); |
zippel@linux-m68k.org | 661b068 | 2008-09-29 05:27:11 +0200 | [diff] [blame] | 269 | if (!sym) { |
| 270 | sym_add_change_count(1); |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 271 | break; |
zippel@linux-m68k.org | 661b068 | 2008-09-29 05:27:11 +0200 | [diff] [blame] | 272 | } |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 273 | } else { |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 274 | sym = sym_lookup(line + strlen(CONFIG_), 0); |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 275 | if (sym->type == S_UNKNOWN) |
| 276 | sym->type = S_OTHER; |
| 277 | } |
| 278 | if (sym->flags & def_flags) { |
Jan Engelhardt | d84876f | 2008-01-03 23:33:44 +0100 | [diff] [blame] | 279 | conf_warning("override: reassigning to symbol %s", sym->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
Sam Ravnborg | 9c900a9 | 2007-11-10 20:01:56 +0100 | [diff] [blame] | 281 | if (conf_set_sym_val(sym, def, def_flags, p)) |
| 282 | continue; |
Arnaud Lacombe | 8baefd3 | 2010-08-24 00:14:47 -0400 | [diff] [blame] | 283 | } else { |
| 284 | if (line[0] != '\r' && line[0] != '\n') |
| 285 | conf_warning("unexpected data"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | continue; |
| 287 | } |
| 288 | if (sym && sym_is_choice_value(sym)) { |
| 289 | struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym)); |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 290 | switch (sym->def[def].tri) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | case no: |
| 292 | break; |
| 293 | case mod: |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 294 | if (cs->def[def].tri == yes) { |
Roman Zippel | c1a0f5e | 2005-11-08 21:34:54 -0800 | [diff] [blame] | 295 | conf_warning("%s creates inconsistent choice state", sym->name); |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 296 | cs->flags &= ~def_flags; |
Roman Zippel | c1a0f5e | 2005-11-08 21:34:54 -0800 | [diff] [blame] | 297 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | break; |
| 299 | case yes: |
Jan Engelhardt | d84876f | 2008-01-03 23:33:44 +0100 | [diff] [blame] | 300 | if (cs->def[def].tri != no) |
| 301 | conf_warning("override: %s changes choice state", sym->name); |
| 302 | cs->def[def].val = sym; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | break; |
| 304 | } |
Sam Ravnborg | d6ee357 | 2008-01-07 21:09:55 +0100 | [diff] [blame] | 305 | cs->def[def].tri = EXPR_OR(cs->def[def].tri, sym->def[def].tri); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | fclose(in); |
| 309 | |
| 310 | if (modules_sym) |
| 311 | sym_calc_value(modules_sym); |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | int conf_read(const char *name) |
| 316 | { |
Roman Zippel | 7a96292 | 2008-01-14 04:50:23 +0100 | [diff] [blame] | 317 | struct symbol *sym, *choice_sym; |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 318 | struct property *prop; |
| 319 | struct expr *e; |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 320 | int i, flags; |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 321 | |
Karsten Wiese | bfc1000 | 2006-12-13 00:34:07 -0800 | [diff] [blame] | 322 | sym_set_change_count(0); |
Roman Zippel | ddc97ca | 2006-06-08 22:12:38 -0700 | [diff] [blame] | 323 | |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 324 | if (conf_read_simple(name, S_DEF_USER)) |
Roman Zippel | 9038916 | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 325 | return 1; |
| 326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | for_all_symbols(i, sym) { |
| 328 | sym_calc_value(sym); |
Roman Zippel | c1a0f5e | 2005-11-08 21:34:54 -0800 | [diff] [blame] | 329 | if (sym_is_choice(sym) || (sym->flags & SYMBOL_AUTO)) |
| 330 | goto sym_ok; |
| 331 | if (sym_has_value(sym) && (sym->flags & SYMBOL_WRITE)) { |
| 332 | /* check that calculated value agrees with saved value */ |
| 333 | switch (sym->type) { |
| 334 | case S_BOOLEAN: |
| 335 | case S_TRISTATE: |
Roman Zippel | 0c1822e | 2006-06-08 22:12:41 -0700 | [diff] [blame] | 336 | if (sym->def[S_DEF_USER].tri != sym_get_tristate_value(sym)) |
Roman Zippel | c1a0f5e | 2005-11-08 21:34:54 -0800 | [diff] [blame] | 337 | break; |
| 338 | if (!sym_is_choice(sym)) |
| 339 | goto sym_ok; |
| 340 | default: |
Roman Zippel | 0c1822e | 2006-06-08 22:12:41 -0700 | [diff] [blame] | 341 | if (!strcmp(sym->curr.val, sym->def[S_DEF_USER].val)) |
Roman Zippel | c1a0f5e | 2005-11-08 21:34:54 -0800 | [diff] [blame] | 342 | goto sym_ok; |
| 343 | break; |
| 344 | } |
| 345 | } else if (!sym_has_value(sym) && !(sym->flags & SYMBOL_WRITE)) |
| 346 | /* no previous value and not saved */ |
| 347 | goto sym_ok; |
| 348 | conf_unsaved++; |
| 349 | /* maybe print value in verbose mode... */ |
| 350 | sym_ok: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | if (!sym_is_choice(sym)) |
| 352 | continue; |
Roman Zippel | d8982ba | 2007-07-09 11:43:58 -0700 | [diff] [blame] | 353 | /* The choice symbol only has a set value (and thus is not new) |
| 354 | * if all its visible childs have values. |
| 355 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | prop = sym_get_choice_prop(sym); |
Roman Zippel | 669bfad9 | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 357 | flags = sym->flags; |
Roman Zippel | 7a96292 | 2008-01-14 04:50:23 +0100 | [diff] [blame] | 358 | expr_list_for_each_sym(prop->expr, e, choice_sym) |
| 359 | if (choice_sym->visible != no) |
| 360 | flags &= choice_sym->flags; |
Roman Zippel | 002d27b | 2006-07-13 13:22:38 +0200 | [diff] [blame] | 361 | sym->flags &= flags | ~SYMBOL_DEF_USER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Roman Zippel | d8982ba | 2007-07-09 11:43:58 -0700 | [diff] [blame] | 364 | for_all_symbols(i, sym) { |
| 365 | if (sym_has_value(sym) && !sym_is_choice_value(sym)) { |
| 366 | /* Reset values of generates values, so they'll appear |
| 367 | * as new, if they should become visible, but that |
| 368 | * doesn't quite work if the Kconfig and the saved |
| 369 | * configuration disagree. |
| 370 | */ |
| 371 | if (sym->visible == no && !conf_unsaved) |
| 372 | sym->flags &= ~SYMBOL_DEF_USER; |
| 373 | switch (sym->type) { |
| 374 | case S_STRING: |
| 375 | case S_INT: |
| 376 | case S_HEX: |
| 377 | /* Reset a string value if it's out of range */ |
| 378 | if (sym_string_within_range(sym, sym->def[S_DEF_USER].val)) |
| 379 | break; |
| 380 | sym->flags &= ~(SYMBOL_VALID|SYMBOL_DEF_USER); |
| 381 | conf_unsaved++; |
| 382 | break; |
| 383 | default: |
| 384 | break; |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
Karsten Wiese | bfc1000 | 2006-12-13 00:34:07 -0800 | [diff] [blame] | 389 | sym_add_change_count(conf_warnings || conf_unsaved); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | |
Sam Ravnborg | 49192f2 | 2010-07-31 23:35:33 +0200 | [diff] [blame] | 394 | /* Write a S_STRING */ |
| 395 | static void conf_write_string(bool headerfile, const char *name, |
| 396 | const char *str, FILE *out) |
| 397 | { |
| 398 | int l; |
| 399 | if (headerfile) |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 400 | fprintf(out, "#define %s%s \"", CONFIG_, name); |
Sam Ravnborg | 49192f2 | 2010-07-31 23:35:33 +0200 | [diff] [blame] | 401 | else |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 402 | fprintf(out, "%s%s=\"", CONFIG_, name); |
Sam Ravnborg | 49192f2 | 2010-07-31 23:35:33 +0200 | [diff] [blame] | 403 | |
| 404 | while (1) { |
| 405 | l = strcspn(str, "\"\\"); |
| 406 | if (l) { |
Jean Sacren | bf5e327 | 2010-08-04 16:01:02 -0600 | [diff] [blame] | 407 | xfwrite(str, l, 1, out); |
Sam Ravnborg | 49192f2 | 2010-07-31 23:35:33 +0200 | [diff] [blame] | 408 | str += l; |
| 409 | } |
| 410 | if (!*str) |
| 411 | break; |
| 412 | fprintf(out, "\\%c", *str++); |
| 413 | } |
| 414 | fputs("\"\n", out); |
| 415 | } |
| 416 | |
| 417 | static void conf_write_symbol(struct symbol *sym, enum symbol_type type, |
| 418 | FILE *out, bool write_no) |
| 419 | { |
| 420 | const char *str; |
| 421 | |
| 422 | switch (type) { |
| 423 | case S_BOOLEAN: |
| 424 | case S_TRISTATE: |
| 425 | switch (sym_get_tristate_value(sym)) { |
| 426 | case no: |
| 427 | if (write_no) |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 428 | fprintf(out, "# %s%s is not set\n", |
| 429 | CONFIG_, sym->name); |
Sam Ravnborg | 49192f2 | 2010-07-31 23:35:33 +0200 | [diff] [blame] | 430 | break; |
| 431 | case mod: |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 432 | fprintf(out, "%s%s=m\n", CONFIG_, sym->name); |
Sam Ravnborg | 49192f2 | 2010-07-31 23:35:33 +0200 | [diff] [blame] | 433 | break; |
| 434 | case yes: |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 435 | fprintf(out, "%s%s=y\n", CONFIG_, sym->name); |
Sam Ravnborg | 49192f2 | 2010-07-31 23:35:33 +0200 | [diff] [blame] | 436 | break; |
| 437 | } |
| 438 | break; |
| 439 | case S_STRING: |
| 440 | conf_write_string(false, sym->name, sym_get_string_value(sym), out); |
| 441 | break; |
| 442 | case S_HEX: |
| 443 | case S_INT: |
| 444 | str = sym_get_string_value(sym); |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 445 | fprintf(out, "%s%s=%s\n", CONFIG_, sym->name, str); |
Sam Ravnborg | 49192f2 | 2010-07-31 23:35:33 +0200 | [diff] [blame] | 446 | break; |
| 447 | case S_OTHER: |
| 448 | case S_UNKNOWN: |
| 449 | break; |
| 450 | } |
| 451 | } |
| 452 | |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 453 | /* |
| 454 | * Write out a minimal config. |
| 455 | * All values that has default values are skipped as this is redundant. |
| 456 | */ |
| 457 | int conf_write_defconfig(const char *filename) |
| 458 | { |
| 459 | struct symbol *sym; |
| 460 | struct menu *menu; |
| 461 | FILE *out; |
| 462 | |
| 463 | out = fopen(filename, "w"); |
| 464 | if (!out) |
| 465 | return 1; |
| 466 | |
| 467 | sym_clear_all_valid(); |
| 468 | |
| 469 | /* Traverse all menus to find all relevant symbols */ |
| 470 | menu = rootmenu.list; |
| 471 | |
| 472 | while (menu != NULL) |
| 473 | { |
| 474 | sym = menu->sym; |
| 475 | if (sym == NULL) { |
| 476 | if (!menu_is_visible(menu)) |
| 477 | goto next_menu; |
| 478 | } else if (!sym_is_choice(sym)) { |
| 479 | sym_calc_value(sym); |
| 480 | if (!(sym->flags & SYMBOL_WRITE)) |
| 481 | goto next_menu; |
| 482 | sym->flags &= ~SYMBOL_WRITE; |
| 483 | /* If we cannot change the symbol - skip */ |
| 484 | if (!sym_is_changable(sym)) |
| 485 | goto next_menu; |
| 486 | /* If symbol equals to default value - skip */ |
| 487 | if (strcmp(sym_get_string_value(sym), sym_get_string_default(sym)) == 0) |
| 488 | goto next_menu; |
| 489 | |
| 490 | /* |
| 491 | * If symbol is a choice value and equals to the |
| 492 | * default for a choice - skip. |
Sam Ravnborg | 84062dd | 2010-08-14 23:22:16 +0200 | [diff] [blame] | 493 | * But only if value is bool and equal to "y" and |
| 494 | * choice is not "optional". |
| 495 | * (If choice is "optional" then all values can be "n") |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 496 | */ |
| 497 | if (sym_is_choice_value(sym)) { |
| 498 | struct symbol *cs; |
| 499 | struct symbol *ds; |
| 500 | |
| 501 | cs = prop_get_symbol(sym_get_choice_prop(sym)); |
| 502 | ds = sym_choice_default(cs); |
Sam Ravnborg | 84062dd | 2010-08-14 23:22:16 +0200 | [diff] [blame] | 503 | if (!sym_is_optional(cs) && sym == ds) { |
Sam Ravnborg | 801690c | 2010-08-12 09:11:51 +0200 | [diff] [blame] | 504 | if ((sym->type == S_BOOLEAN) && |
| 505 | sym_get_tristate_value(sym) == yes) |
Sam Ravnborg | 7cf3d73 | 2010-07-31 23:35:34 +0200 | [diff] [blame] | 506 | goto next_menu; |
| 507 | } |
| 508 | } |
| 509 | conf_write_symbol(sym, sym->type, out, true); |
| 510 | } |
| 511 | next_menu: |
| 512 | if (menu->list != NULL) { |
| 513 | menu = menu->list; |
| 514 | } |
| 515 | else if (menu->next != NULL) { |
| 516 | menu = menu->next; |
| 517 | } else { |
| 518 | while ((menu = menu->parent)) { |
| 519 | if (menu->next != NULL) { |
| 520 | menu = menu->next; |
| 521 | break; |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | fclose(out); |
| 527 | return 0; |
| 528 | } |
| 529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | int conf_write(const char *name) |
| 531 | { |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 532 | FILE *out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | struct symbol *sym; |
| 534 | struct menu *menu; |
| 535 | const char *basename; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | const char *str; |
Sam Ravnborg | 49192f2 | 2010-07-31 23:35:33 +0200 | [diff] [blame] | 537 | char dirname[128], tmpname[128], newname[128]; |
| 538 | enum symbol_type type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | time_t now; |
| 540 | int use_timestamp = 1; |
| 541 | char *env; |
| 542 | |
| 543 | dirname[0] = 0; |
| 544 | if (name && name[0]) { |
| 545 | struct stat st; |
| 546 | char *slash; |
| 547 | |
| 548 | if (!stat(name, &st) && S_ISDIR(st.st_mode)) { |
| 549 | strcpy(dirname, name); |
| 550 | strcat(dirname, "/"); |
Roman Zippel | 14cdd3c | 2006-06-08 22:12:51 -0700 | [diff] [blame] | 551 | basename = conf_get_configname(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | } else if ((slash = strrchr(name, '/'))) { |
| 553 | int size = slash - name + 1; |
| 554 | memcpy(dirname, name, size); |
| 555 | dirname[size] = 0; |
| 556 | if (slash[1]) |
| 557 | basename = slash + 1; |
| 558 | else |
Roman Zippel | 14cdd3c | 2006-06-08 22:12:51 -0700 | [diff] [blame] | 559 | basename = conf_get_configname(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | } else |
| 561 | basename = name; |
| 562 | } else |
Roman Zippel | 14cdd3c | 2006-06-08 22:12:51 -0700 | [diff] [blame] | 563 | basename = conf_get_configname(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
Roman Zippel | 14cdd3c | 2006-06-08 22:12:51 -0700 | [diff] [blame] | 565 | sprintf(newname, "%s%s", dirname, basename); |
| 566 | env = getenv("KCONFIG_OVERWRITECONFIG"); |
| 567 | if (!env || !*env) { |
| 568 | sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid()); |
| 569 | out = fopen(tmpname, "w"); |
| 570 | } else { |
| 571 | *tmpname = 0; |
| 572 | out = fopen(newname, "w"); |
| 573 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | if (!out) |
| 575 | return 1; |
Roman Zippel | 14cdd3c | 2006-06-08 22:12:51 -0700 | [diff] [blame] | 576 | |
Sam Ravnborg | 2244cbd | 2006-01-16 12:12:12 +0100 | [diff] [blame] | 577 | sym = sym_lookup("KERNELVERSION", 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | sym_calc_value(sym); |
| 579 | time(&now); |
| 580 | env = getenv("KCONFIG_NOTIMESTAMP"); |
| 581 | if (env && *env) |
| 582 | use_timestamp = 0; |
| 583 | |
Arnaldo Carvalho de Melo | 3b9fa09 | 2005-05-05 15:09:46 -0700 | [diff] [blame] | 584 | fprintf(out, _("#\n" |
| 585 | "# Automatically generated make config: don't edit\n" |
| 586 | "# Linux kernel version: %s\n" |
| 587 | "%s%s" |
| 588 | "#\n"), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | sym_get_string_value(sym), |
| 590 | use_timestamp ? "# " : "", |
| 591 | use_timestamp ? ctime(&now) : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
Karsten Wiese | b321429 | 2006-12-13 00:34:06 -0800 | [diff] [blame] | 593 | if (!conf_get_changed()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | sym_clear_all_valid(); |
| 595 | |
| 596 | menu = rootmenu.list; |
| 597 | while (menu) { |
| 598 | sym = menu->sym; |
| 599 | if (!sym) { |
| 600 | if (!menu_is_visible(menu)) |
| 601 | goto next; |
| 602 | str = menu_get_prompt(menu); |
| 603 | fprintf(out, "\n" |
| 604 | "#\n" |
| 605 | "# %s\n" |
| 606 | "#\n", str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } else if (!(sym->flags & SYMBOL_CHOICE)) { |
| 608 | sym_calc_value(sym); |
| 609 | if (!(sym->flags & SYMBOL_WRITE)) |
| 610 | goto next; |
| 611 | sym->flags &= ~SYMBOL_WRITE; |
| 612 | type = sym->type; |
| 613 | if (type == S_TRISTATE) { |
| 614 | sym_calc_value(modules_sym); |
| 615 | if (modules_sym->curr.tri == no) |
| 616 | type = S_BOOLEAN; |
| 617 | } |
Sam Ravnborg | 49192f2 | 2010-07-31 23:35:33 +0200 | [diff] [blame] | 618 | /* Write config symbol to file */ |
| 619 | conf_write_symbol(sym, type, out, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Sam Ravnborg | 49192f2 | 2010-07-31 23:35:33 +0200 | [diff] [blame] | 622 | next: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | if (menu->list) { |
| 624 | menu = menu->list; |
| 625 | continue; |
| 626 | } |
| 627 | if (menu->next) |
| 628 | menu = menu->next; |
| 629 | else while ((menu = menu->parent)) { |
| 630 | if (menu->next) { |
| 631 | menu = menu->next; |
| 632 | break; |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | fclose(out); |
Roman Zippel | 14cdd3c | 2006-06-08 22:12:51 -0700 | [diff] [blame] | 637 | |
| 638 | if (*tmpname) { |
Sam Ravnborg | 9a3d0fe | 2006-10-01 11:48:53 +0200 | [diff] [blame] | 639 | strcat(dirname, basename); |
Roman Zippel | 14cdd3c | 2006-06-08 22:12:51 -0700 | [diff] [blame] | 640 | strcat(dirname, ".old"); |
| 641 | rename(newname, dirname); |
| 642 | if (rename(tmpname, newname)) |
| 643 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
Roman Zippel | ddc97ca | 2006-06-08 22:12:38 -0700 | [diff] [blame] | 646 | printf(_("#\n" |
| 647 | "# configuration written to %s\n" |
Roman Zippel | 14cdd3c | 2006-06-08 22:12:51 -0700 | [diff] [blame] | 648 | "#\n"), newname); |
Roman Zippel | ddc97ca | 2006-06-08 22:12:38 -0700 | [diff] [blame] | 649 | |
Karsten Wiese | bfc1000 | 2006-12-13 00:34:07 -0800 | [diff] [blame] | 650 | sym_set_change_count(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
| 652 | return 0; |
| 653 | } |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 654 | |
Trevor Keith | 4356f48 | 2009-09-18 12:49:23 -0700 | [diff] [blame] | 655 | static int conf_split_config(void) |
Roman Zippel | 2e3646e | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 656 | { |
Markus Heidelberg | 12122f6 | 2009-05-18 01:36:54 +0200 | [diff] [blame] | 657 | const char *name; |
| 658 | char path[128]; |
Roman Zippel | 2e3646e | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 659 | char *s, *d, c; |
| 660 | struct symbol *sym; |
| 661 | struct stat sb; |
| 662 | int res, i, fd; |
| 663 | |
Markus Heidelberg | 12122f6 | 2009-05-18 01:36:54 +0200 | [diff] [blame] | 664 | name = conf_get_autoconfig_name(); |
Roman Zippel | 2e3646e | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 665 | conf_read_simple(name, S_DEF_AUTO); |
| 666 | |
| 667 | if (chdir("include/config")) |
| 668 | return 1; |
| 669 | |
| 670 | res = 0; |
| 671 | for_all_symbols(i, sym) { |
| 672 | sym_calc_value(sym); |
| 673 | if ((sym->flags & SYMBOL_AUTO) || !sym->name) |
| 674 | continue; |
| 675 | if (sym->flags & SYMBOL_WRITE) { |
| 676 | if (sym->flags & SYMBOL_DEF_AUTO) { |
| 677 | /* |
| 678 | * symbol has old and new value, |
| 679 | * so compare them... |
| 680 | */ |
| 681 | switch (sym->type) { |
| 682 | case S_BOOLEAN: |
| 683 | case S_TRISTATE: |
| 684 | if (sym_get_tristate_value(sym) == |
| 685 | sym->def[S_DEF_AUTO].tri) |
| 686 | continue; |
| 687 | break; |
| 688 | case S_STRING: |
| 689 | case S_HEX: |
| 690 | case S_INT: |
| 691 | if (!strcmp(sym_get_string_value(sym), |
| 692 | sym->def[S_DEF_AUTO].val)) |
| 693 | continue; |
| 694 | break; |
| 695 | default: |
| 696 | break; |
| 697 | } |
| 698 | } else { |
| 699 | /* |
| 700 | * If there is no old value, only 'no' (unset) |
| 701 | * is allowed as new value. |
| 702 | */ |
| 703 | switch (sym->type) { |
| 704 | case S_BOOLEAN: |
| 705 | case S_TRISTATE: |
| 706 | if (sym_get_tristate_value(sym) == no) |
| 707 | continue; |
| 708 | break; |
| 709 | default: |
| 710 | break; |
| 711 | } |
| 712 | } |
| 713 | } else if (!(sym->flags & SYMBOL_DEF_AUTO)) |
| 714 | /* There is neither an old nor a new value. */ |
| 715 | continue; |
| 716 | /* else |
| 717 | * There is an old value, but no new value ('no' (unset) |
| 718 | * isn't saved in auto.conf, so the old value is always |
| 719 | * different from 'no'). |
| 720 | */ |
| 721 | |
| 722 | /* Replace all '_' and append ".h" */ |
| 723 | s = sym->name; |
| 724 | d = path; |
| 725 | while ((c = *s++)) { |
| 726 | c = tolower(c); |
| 727 | *d++ = (c == '_') ? '/' : c; |
| 728 | } |
| 729 | strcpy(d, ".h"); |
| 730 | |
| 731 | /* Assume directory path already exists. */ |
| 732 | fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); |
| 733 | if (fd == -1) { |
| 734 | if (errno != ENOENT) { |
| 735 | res = 1; |
| 736 | break; |
| 737 | } |
| 738 | /* |
| 739 | * Create directory components, |
| 740 | * unless they exist already. |
| 741 | */ |
| 742 | d = path; |
| 743 | while ((d = strchr(d, '/'))) { |
| 744 | *d = 0; |
| 745 | if (stat(path, &sb) && mkdir(path, 0755)) { |
| 746 | res = 1; |
| 747 | goto out; |
| 748 | } |
| 749 | *d++ = '/'; |
| 750 | } |
| 751 | /* Try it again. */ |
| 752 | fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); |
| 753 | if (fd == -1) { |
| 754 | res = 1; |
| 755 | break; |
| 756 | } |
| 757 | } |
| 758 | close(fd); |
| 759 | } |
| 760 | out: |
| 761 | if (chdir("../..")) |
| 762 | return 1; |
| 763 | |
| 764 | return res; |
| 765 | } |
| 766 | |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 767 | int conf_write_autoconf(void) |
| 768 | { |
| 769 | struct symbol *sym; |
| 770 | const char *str; |
Markus Heidelberg | 12122f6 | 2009-05-18 01:36:54 +0200 | [diff] [blame] | 771 | const char *name; |
Michal Marek | bc081dd | 2009-12-07 16:38:33 +0100 | [diff] [blame] | 772 | FILE *out, *tristate, *out_h; |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 773 | time_t now; |
Sam Ravnborg | 49192f2 | 2010-07-31 23:35:33 +0200 | [diff] [blame] | 774 | int i; |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 775 | |
Roman Zippel | 2e3646e | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 776 | sym_clear_all_valid(); |
| 777 | |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 778 | file_write_dep("include/config/auto.conf.cmd"); |
| 779 | |
Roman Zippel | 2e3646e | 2006-06-08 22:12:42 -0700 | [diff] [blame] | 780 | if (conf_split_config()) |
| 781 | return 1; |
| 782 | |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 783 | out = fopen(".tmpconfig", "w"); |
| 784 | if (!out) |
| 785 | return 1; |
| 786 | |
Michal Marek | bc081dd | 2009-12-07 16:38:33 +0100 | [diff] [blame] | 787 | tristate = fopen(".tmpconfig_tristate", "w"); |
| 788 | if (!tristate) { |
| 789 | fclose(out); |
| 790 | return 1; |
| 791 | } |
| 792 | |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 793 | out_h = fopen(".tmpconfig.h", "w"); |
| 794 | if (!out_h) { |
| 795 | fclose(out); |
Michal Marek | bc081dd | 2009-12-07 16:38:33 +0100 | [diff] [blame] | 796 | fclose(tristate); |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 797 | return 1; |
| 798 | } |
| 799 | |
| 800 | sym = sym_lookup("KERNELVERSION", 0); |
| 801 | sym_calc_value(sym); |
| 802 | time(&now); |
| 803 | fprintf(out, "#\n" |
| 804 | "# Automatically generated make config: don't edit\n" |
| 805 | "# Linux kernel version: %s\n" |
| 806 | "# %s" |
| 807 | "#\n", |
| 808 | sym_get_string_value(sym), ctime(&now)); |
Michal Marek | bc081dd | 2009-12-07 16:38:33 +0100 | [diff] [blame] | 809 | fprintf(tristate, "#\n" |
| 810 | "# Automatically generated - do not edit\n" |
| 811 | "\n"); |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 812 | fprintf(out_h, "/*\n" |
| 813 | " * Automatically generated C config: don't edit\n" |
| 814 | " * Linux kernel version: %s\n" |
| 815 | " * %s" |
| 816 | " */\n" |
| 817 | "#define AUTOCONF_INCLUDED\n", |
| 818 | sym_get_string_value(sym), ctime(&now)); |
| 819 | |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 820 | for_all_symbols(i, sym) { |
| 821 | sym_calc_value(sym); |
| 822 | if (!(sym->flags & SYMBOL_WRITE) || !sym->name) |
| 823 | continue; |
Sam Ravnborg | 49192f2 | 2010-07-31 23:35:33 +0200 | [diff] [blame] | 824 | |
| 825 | /* write symbol to config file */ |
| 826 | conf_write_symbol(sym, sym->type, out, false); |
| 827 | |
| 828 | /* update autoconf and tristate files */ |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 829 | switch (sym->type) { |
| 830 | case S_BOOLEAN: |
| 831 | case S_TRISTATE: |
| 832 | switch (sym_get_tristate_value(sym)) { |
| 833 | case no: |
| 834 | break; |
| 835 | case mod: |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 836 | fprintf(tristate, "%s%s=M\n", |
| 837 | CONFIG_, sym->name); |
| 838 | fprintf(out_h, "#define %s%s_MODULE 1\n", |
| 839 | CONFIG_, sym->name); |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 840 | break; |
| 841 | case yes: |
Michal Marek | bc081dd | 2009-12-07 16:38:33 +0100 | [diff] [blame] | 842 | if (sym->type == S_TRISTATE) |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 843 | fprintf(tristate,"%s%s=Y\n", |
| 844 | CONFIG_, sym->name); |
| 845 | fprintf(out_h, "#define %s%s 1\n", |
| 846 | CONFIG_, sym->name); |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 847 | break; |
| 848 | } |
| 849 | break; |
| 850 | case S_STRING: |
Sam Ravnborg | 49192f2 | 2010-07-31 23:35:33 +0200 | [diff] [blame] | 851 | conf_write_string(true, sym->name, sym_get_string_value(sym), out_h); |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 852 | break; |
| 853 | case S_HEX: |
| 854 | str = sym_get_string_value(sym); |
| 855 | if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) { |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 856 | fprintf(out_h, "#define %s%s 0x%s\n", |
| 857 | CONFIG_, sym->name, str); |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 858 | break; |
| 859 | } |
| 860 | case S_INT: |
| 861 | str = sym_get_string_value(sym); |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame^] | 862 | fprintf(out_h, "#define %s%s %s\n", |
| 863 | CONFIG_, sym->name, str); |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 864 | break; |
| 865 | default: |
| 866 | break; |
| 867 | } |
| 868 | } |
| 869 | fclose(out); |
Michal Marek | bc081dd | 2009-12-07 16:38:33 +0100 | [diff] [blame] | 870 | fclose(tristate); |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 871 | fclose(out_h); |
| 872 | |
| 873 | name = getenv("KCONFIG_AUTOHEADER"); |
| 874 | if (!name) |
Sam Ravnborg | 264a268 | 2009-10-18 00:49:24 +0200 | [diff] [blame] | 875 | name = "include/generated/autoconf.h"; |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 876 | if (rename(".tmpconfig.h", name)) |
| 877 | return 1; |
Michal Marek | bc081dd | 2009-12-07 16:38:33 +0100 | [diff] [blame] | 878 | name = getenv("KCONFIG_TRISTATE"); |
| 879 | if (!name) |
| 880 | name = "include/config/tristate.conf"; |
| 881 | if (rename(".tmpconfig_tristate", name)) |
| 882 | return 1; |
Markus Heidelberg | 12122f6 | 2009-05-18 01:36:54 +0200 | [diff] [blame] | 883 | name = conf_get_autoconfig_name(); |
Roman Zippel | c955cca | 2006-06-08 22:12:39 -0700 | [diff] [blame] | 884 | /* |
| 885 | * This must be the last step, kbuild has a dependency on auto.conf |
| 886 | * and this marks the successful completion of the previous steps. |
| 887 | */ |
| 888 | if (rename(".tmpconfig", name)) |
| 889 | return 1; |
| 890 | |
| 891 | return 0; |
| 892 | } |
Karsten Wiese | b321429 | 2006-12-13 00:34:06 -0800 | [diff] [blame] | 893 | |
Karsten Wiese | bfc1000 | 2006-12-13 00:34:07 -0800 | [diff] [blame] | 894 | static int sym_change_count; |
Karsten Wiese | 3b354c5 | 2006-12-13 00:34:08 -0800 | [diff] [blame] | 895 | static void (*conf_changed_callback)(void); |
Karsten Wiese | bfc1000 | 2006-12-13 00:34:07 -0800 | [diff] [blame] | 896 | |
| 897 | void sym_set_change_count(int count) |
| 898 | { |
Karsten Wiese | 3b354c5 | 2006-12-13 00:34:08 -0800 | [diff] [blame] | 899 | int _sym_change_count = sym_change_count; |
Karsten Wiese | bfc1000 | 2006-12-13 00:34:07 -0800 | [diff] [blame] | 900 | sym_change_count = count; |
Karsten Wiese | 3b354c5 | 2006-12-13 00:34:08 -0800 | [diff] [blame] | 901 | if (conf_changed_callback && |
| 902 | (bool)_sym_change_count != (bool)count) |
| 903 | conf_changed_callback(); |
Karsten Wiese | bfc1000 | 2006-12-13 00:34:07 -0800 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | void sym_add_change_count(int count) |
| 907 | { |
Karsten Wiese | 3b354c5 | 2006-12-13 00:34:08 -0800 | [diff] [blame] | 908 | sym_set_change_count(count + sym_change_count); |
Karsten Wiese | bfc1000 | 2006-12-13 00:34:07 -0800 | [diff] [blame] | 909 | } |
| 910 | |
Karsten Wiese | b321429 | 2006-12-13 00:34:06 -0800 | [diff] [blame] | 911 | bool conf_get_changed(void) |
| 912 | { |
| 913 | return sym_change_count; |
| 914 | } |
Karsten Wiese | 3b354c5 | 2006-12-13 00:34:08 -0800 | [diff] [blame] | 915 | |
| 916 | void conf_set_changed_callback(void (*fn)(void)) |
| 917 | { |
| 918 | conf_changed_callback = fn; |
| 919 | } |
Roman Zippel | dc7862e | 2008-05-06 04:55:55 +0200 | [diff] [blame] | 920 | |
Sam Ravnborg | a64b44e | 2010-08-12 09:11:52 +0200 | [diff] [blame] | 921 | static void randomize_choice_values(struct symbol *csym) |
| 922 | { |
| 923 | struct property *prop; |
| 924 | struct symbol *sym; |
| 925 | struct expr *e; |
| 926 | int cnt, def; |
| 927 | |
| 928 | /* |
| 929 | * If choice is mod then we may have more items slected |
| 930 | * and if no then no-one. |
| 931 | * In both cases stop. |
| 932 | */ |
| 933 | if (csym->curr.tri != yes) |
| 934 | return; |
| 935 | |
| 936 | prop = sym_get_choice_prop(csym); |
| 937 | |
| 938 | /* count entries in choice block */ |
| 939 | cnt = 0; |
| 940 | expr_list_for_each_sym(prop->expr, e, sym) |
| 941 | cnt++; |
| 942 | |
| 943 | /* |
| 944 | * find a random value and set it to yes, |
| 945 | * set the rest to no so we have only one set |
| 946 | */ |
| 947 | def = (rand() % cnt); |
| 948 | |
| 949 | cnt = 0; |
| 950 | expr_list_for_each_sym(prop->expr, e, sym) { |
| 951 | if (def == cnt++) { |
| 952 | sym->def[S_DEF_USER].tri = yes; |
| 953 | csym->def[S_DEF_USER].val = sym; |
| 954 | } |
| 955 | else { |
| 956 | sym->def[S_DEF_USER].tri = no; |
| 957 | } |
| 958 | } |
| 959 | csym->flags |= SYMBOL_DEF_USER; |
| 960 | /* clear VALID to get value calculated */ |
| 961 | csym->flags &= ~(SYMBOL_VALID); |
| 962 | } |
| 963 | |
| 964 | static void set_all_choice_values(struct symbol *csym) |
| 965 | { |
| 966 | struct property *prop; |
| 967 | struct symbol *sym; |
| 968 | struct expr *e; |
| 969 | |
| 970 | prop = sym_get_choice_prop(csym); |
| 971 | |
| 972 | /* |
| 973 | * Set all non-assinged choice values to no |
| 974 | */ |
| 975 | expr_list_for_each_sym(prop->expr, e, sym) { |
| 976 | if (!sym_has_value(sym)) |
| 977 | sym->def[S_DEF_USER].tri = no; |
| 978 | } |
| 979 | csym->flags |= SYMBOL_DEF_USER; |
| 980 | /* clear VALID to get value calculated */ |
| 981 | csym->flags &= ~(SYMBOL_VALID); |
| 982 | } |
Roman Zippel | dc7862e | 2008-05-06 04:55:55 +0200 | [diff] [blame] | 983 | |
| 984 | void conf_set_all_new_symbols(enum conf_def_mode mode) |
| 985 | { |
| 986 | struct symbol *sym, *csym; |
Sam Ravnborg | a64b44e | 2010-08-12 09:11:52 +0200 | [diff] [blame] | 987 | int i, cnt; |
Roman Zippel | dc7862e | 2008-05-06 04:55:55 +0200 | [diff] [blame] | 988 | |
| 989 | for_all_symbols(i, sym) { |
| 990 | if (sym_has_value(sym)) |
| 991 | continue; |
| 992 | switch (sym_get_type(sym)) { |
| 993 | case S_BOOLEAN: |
| 994 | case S_TRISTATE: |
| 995 | switch (mode) { |
| 996 | case def_yes: |
| 997 | sym->def[S_DEF_USER].tri = yes; |
| 998 | break; |
| 999 | case def_mod: |
| 1000 | sym->def[S_DEF_USER].tri = mod; |
| 1001 | break; |
| 1002 | case def_no: |
| 1003 | sym->def[S_DEF_USER].tri = no; |
| 1004 | break; |
| 1005 | case def_random: |
Peter Korsgaard | 1244b41 | 2010-07-22 14:24:57 +0200 | [diff] [blame] | 1006 | cnt = sym_get_type(sym) == S_TRISTATE ? 3 : 2; |
| 1007 | sym->def[S_DEF_USER].tri = (tristate)(rand() % cnt); |
Roman Zippel | dc7862e | 2008-05-06 04:55:55 +0200 | [diff] [blame] | 1008 | break; |
| 1009 | default: |
| 1010 | continue; |
| 1011 | } |
Sam Ravnborg | 184832c | 2009-03-15 11:05:12 +0100 | [diff] [blame] | 1012 | if (!(sym_is_choice(sym) && mode == def_random)) |
Roman Zippel | dc7862e | 2008-05-06 04:55:55 +0200 | [diff] [blame] | 1013 | sym->flags |= SYMBOL_DEF_USER; |
| 1014 | break; |
| 1015 | default: |
| 1016 | break; |
| 1017 | } |
| 1018 | |
| 1019 | } |
| 1020 | |
Al Viro | ce97e13 | 2008-10-26 05:12:34 +0000 | [diff] [blame] | 1021 | sym_clear_all_valid(); |
Roman Zippel | dc7862e | 2008-05-06 04:55:55 +0200 | [diff] [blame] | 1022 | |
Sam Ravnborg | 184832c | 2009-03-15 11:05:12 +0100 | [diff] [blame] | 1023 | /* |
| 1024 | * We have different type of choice blocks. |
| 1025 | * If curr.tri equal to mod then we can select several |
| 1026 | * choice symbols in one block. |
| 1027 | * In this case we do nothing. |
| 1028 | * If curr.tri equal yes then only one symbol can be |
| 1029 | * selected in a choice block and we set it to yes, |
| 1030 | * and the rest to no. |
| 1031 | */ |
Roman Zippel | dc7862e | 2008-05-06 04:55:55 +0200 | [diff] [blame] | 1032 | for_all_symbols(i, csym) { |
| 1033 | if (sym_has_value(csym) || !sym_is_choice(csym)) |
| 1034 | continue; |
| 1035 | |
| 1036 | sym_calc_value(csym); |
Sam Ravnborg | a64b44e | 2010-08-12 09:11:52 +0200 | [diff] [blame] | 1037 | if (mode == def_random) |
| 1038 | randomize_choice_values(csym); |
| 1039 | else |
| 1040 | set_all_choice_values(csym); |
Roman Zippel | dc7862e | 2008-05-06 04:55:55 +0200 | [diff] [blame] | 1041 | } |
| 1042 | } |