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