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