Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 6 | #include <sys/mman.h> |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 7 | #include <sys/stat.h> |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 8 | #include <sys/types.h> |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 9 | #include <ctype.h> |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 10 | #include <errno.h> |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 11 | #include <fcntl.h> |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 12 | #include <limits.h> |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 13 | #include <stdarg.h> |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 14 | #include <stdbool.h> |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 15 | #include <stdio.h> |
| 16 | #include <stdlib.h> |
| 17 | #include <string.h> |
| 18 | #include <time.h> |
| 19 | #include <unistd.h> |
| 20 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 21 | #include "lkc.h" |
| 22 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 23 | /* return true if 'path' exists, false otherwise */ |
| 24 | static bool is_present(const char *path) |
| 25 | { |
| 26 | struct stat st; |
| 27 | |
| 28 | return !stat(path, &st); |
| 29 | } |
| 30 | |
| 31 | /* return true if 'path' exists and it is a directory, false otherwise */ |
| 32 | static bool is_dir(const char *path) |
| 33 | { |
| 34 | struct stat st; |
| 35 | |
| 36 | if (stat(path, &st)) |
| 37 | return false; |
| 38 | |
| 39 | return S_ISDIR(st.st_mode); |
| 40 | } |
| 41 | |
| 42 | /* return true if the given two files are the same, false otherwise */ |
| 43 | static bool is_same(const char *file1, const char *file2) |
| 44 | { |
| 45 | int fd1, fd2; |
| 46 | struct stat st1, st2; |
| 47 | void *map1, *map2; |
| 48 | bool ret = false; |
| 49 | |
| 50 | fd1 = open(file1, O_RDONLY); |
| 51 | if (fd1 < 0) |
| 52 | return ret; |
| 53 | |
| 54 | fd2 = open(file2, O_RDONLY); |
| 55 | if (fd2 < 0) |
| 56 | goto close1; |
| 57 | |
| 58 | ret = fstat(fd1, &st1); |
| 59 | if (ret) |
| 60 | goto close2; |
| 61 | ret = fstat(fd2, &st2); |
| 62 | if (ret) |
| 63 | goto close2; |
| 64 | |
| 65 | if (st1.st_size != st2.st_size) |
| 66 | goto close2; |
| 67 | |
| 68 | map1 = mmap(NULL, st1.st_size, PROT_READ, MAP_PRIVATE, fd1, 0); |
| 69 | if (map1 == MAP_FAILED) |
| 70 | goto close2; |
| 71 | |
| 72 | map2 = mmap(NULL, st2.st_size, PROT_READ, MAP_PRIVATE, fd2, 0); |
| 73 | if (map2 == MAP_FAILED) |
| 74 | goto close2; |
| 75 | |
| 76 | if (bcmp(map1, map2, st1.st_size)) |
| 77 | goto close2; |
| 78 | |
| 79 | ret = true; |
| 80 | close2: |
| 81 | close(fd2); |
| 82 | close1: |
| 83 | close(fd1); |
| 84 | |
| 85 | return ret; |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * Create the parent directory of the given path. |
| 90 | * |
| 91 | * For example, if 'include/config/auto.conf' is given, create 'include/config'. |
| 92 | */ |
| 93 | static int make_parent_dir(const char *path) |
| 94 | { |
| 95 | char tmp[PATH_MAX + 1]; |
| 96 | char *p; |
| 97 | |
| 98 | strncpy(tmp, path, sizeof(tmp)); |
| 99 | tmp[sizeof(tmp) - 1] = 0; |
| 100 | |
| 101 | /* Remove the base name. Just return if nothing is left */ |
| 102 | p = strrchr(tmp, '/'); |
| 103 | if (!p) |
| 104 | return 0; |
| 105 | *(p + 1) = 0; |
| 106 | |
| 107 | /* Just in case it is an absolute path */ |
| 108 | p = tmp; |
| 109 | while (*p == '/') |
| 110 | p++; |
| 111 | |
| 112 | while ((p = strchr(p, '/'))) { |
| 113 | *p = 0; |
| 114 | |
| 115 | /* skip if the directory exists */ |
| 116 | if (!is_dir(tmp) && mkdir(tmp, 0755)) |
| 117 | return -1; |
| 118 | |
| 119 | *p = '/'; |
| 120 | while (*p == '/') |
| 121 | p++; |
| 122 | } |
| 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | static char depfile_path[PATH_MAX]; |
| 128 | static size_t depfile_prefix_len; |
| 129 | |
| 130 | /* touch depfile for symbol 'name' */ |
| 131 | static int conf_touch_dep(const char *name) |
| 132 | { |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 133 | int fd; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 134 | |
| 135 | /* check overflow: prefix + name + '\0' must fit in buffer. */ |
| 136 | if (depfile_prefix_len + strlen(name) + 1 > sizeof(depfile_path)) |
| 137 | return -1; |
| 138 | |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 139 | strcpy(depfile_path + depfile_prefix_len, name); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 140 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 141 | fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644); |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 142 | if (fd == -1) |
| 143 | return -1; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 144 | close(fd); |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 149 | static void conf_warning(const char *fmt, ...) |
| 150 | __attribute__ ((format (printf, 1, 2))); |
| 151 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 152 | static void conf_message(const char *fmt, ...) |
| 153 | __attribute__ ((format (printf, 1, 2))); |
| 154 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 155 | static const char *conf_filename; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 156 | static int conf_lineno, conf_warnings; |
zbao | 2f3fd26 | 2015-09-26 06:20:53 -0400 | [diff] [blame] | 157 | |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 158 | #ifdef __MINGW32__ |
| 159 | #define mkdir(_n,_p) mkdir((_n)) |
| 160 | #endif |
| 161 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 162 | static void conf_warning(const char *fmt, ...) |
| 163 | { |
| 164 | va_list ap; |
| 165 | va_start(ap, fmt); |
| 166 | fprintf(stderr, "%s:%d:warning: ", conf_filename, conf_lineno); |
| 167 | vfprintf(stderr, fmt, ap); |
| 168 | fprintf(stderr, "\n"); |
| 169 | va_end(ap); |
| 170 | conf_warnings++; |
| 171 | } |
| 172 | |
Martin Roth | 00cbc7f | 2016-09-21 14:27:26 -0600 | [diff] [blame] | 173 | static void conf_notice(const char *fmt, ...) |
| 174 | { |
| 175 | va_list ap; |
| 176 | va_start(ap, fmt); |
| 177 | fprintf(stderr, "%s:%d:notice: ", conf_filename, conf_lineno); |
| 178 | vfprintf(stderr, fmt, ap); |
| 179 | fprintf(stderr, "\n"); |
| 180 | va_end(ap); |
| 181 | } |
| 182 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 183 | static void conf_default_message_callback(const char *s) |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 184 | { |
| 185 | printf("#\n# "); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 186 | printf("%s", s); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 187 | printf("\n#\n"); |
| 188 | } |
| 189 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 190 | static void (*conf_message_callback)(const char *s) = |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 191 | conf_default_message_callback; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 192 | void conf_set_message_callback(void (*fn)(const char *s)) |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 193 | { |
| 194 | conf_message_callback = fn; |
| 195 | } |
| 196 | |
| 197 | static void conf_message(const char *fmt, ...) |
| 198 | { |
| 199 | va_list ap; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 200 | char buf[4096]; |
| 201 | |
| 202 | if (!conf_message_callback) |
| 203 | return; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 204 | |
| 205 | va_start(ap, fmt); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 206 | |
| 207 | vsnprintf(buf, sizeof(buf), fmt, ap); |
| 208 | conf_message_callback(buf); |
Stefan Reinauer | cce6662 | 2015-04-06 01:14:21 +0200 | [diff] [blame] | 209 | va_end(ap); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 212 | const char *conf_get_configname(void) |
| 213 | { |
| 214 | char *name = getenv("KCONFIG_CONFIG"); |
| 215 | |
| 216 | return name ? name : ".config"; |
| 217 | } |
| 218 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 219 | static const char *conf_get_autoconfig_name(void) |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 220 | { |
| 221 | char *name = getenv("KCONFIG_AUTOCONFIG"); |
| 222 | |
| 223 | return name ? name : "include/config/auto.conf"; |
| 224 | } |
| 225 | |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 226 | static const char *conf_get_autoheader_name(void) |
| 227 | { |
| 228 | char *name = getenv("KCONFIG_AUTOHEADER"); |
| 229 | |
| 230 | return name ? name : "include/generated/autoconf.h"; |
| 231 | } |
| 232 | |
Martin Roth | 35e09ec | 2022-11-13 15:20:57 -0700 | [diff] [blame] | 233 | static const char *conf_get_autobase_name(void) |
| 234 | { |
| 235 | char *name = getenv("KCONFIG_SPLITCONFIG"); |
| 236 | |
| 237 | return name ? name : "include/config/"; |
| 238 | } |
| 239 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 240 | static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) |
| 241 | { |
| 242 | char *p2; |
| 243 | |
| 244 | switch (sym->type) { |
| 245 | case S_TRISTATE: |
| 246 | if (p[0] == 'm') { |
| 247 | sym->def[def].tri = mod; |
| 248 | sym->flags |= def_flags; |
| 249 | break; |
| 250 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 251 | /* fall through */ |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 252 | case S_BOOLEAN: |
| 253 | if (p[0] == 'y') { |
| 254 | sym->def[def].tri = yes; |
| 255 | sym->flags |= def_flags; |
| 256 | break; |
| 257 | } |
| 258 | if (p[0] == 'n') { |
| 259 | sym->def[def].tri = no; |
| 260 | sym->flags |= def_flags; |
| 261 | break; |
| 262 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 263 | if (def != S_DEF_AUTO) |
| 264 | conf_warning("symbol value '%s' invalid for %s", |
| 265 | p, sym->name); |
| 266 | return 1; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 267 | case S_STRING: |
Patrick Georgi | 7eb03cb | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 268 | /* No escaping for S_DEF_AUTO (include/config/auto.conf) */ |
| 269 | if (def != S_DEF_AUTO) { |
| 270 | if (*p++ != '"') |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 271 | break; |
Patrick Georgi | 7eb03cb | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 272 | for (p2 = p; (p2 = strpbrk(p2, "\"\\")); p2++) { |
| 273 | if (*p2 == '"') { |
| 274 | *p2 = 0; |
| 275 | break; |
| 276 | } |
| 277 | memmove(p2, p2 + 1, strlen(p2)); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 278 | } |
Patrick Georgi | 7eb03cb | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 279 | if (!p2) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 280 | conf_warning("invalid string found"); |
Patrick Georgi | 7eb03cb | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 281 | return 1; |
| 282 | } |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 283 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 284 | /* fall through */ |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 285 | case S_INT: |
| 286 | case S_HEX: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 287 | if (sym_string_valid(sym, p)) { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 288 | sym->def[def].val = xstrdup(p); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 289 | sym->flags |= def_flags; |
| 290 | } else { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 291 | if (def != S_DEF_AUTO) |
| 292 | conf_warning("symbol value '%s' invalid for %s", |
| 293 | p, sym->name); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 294 | return 1; |
| 295 | } |
| 296 | break; |
| 297 | default: |
| 298 | ; |
| 299 | } |
| 300 | return 0; |
| 301 | } |
| 302 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 303 | #define LINE_GROWTH 16 |
| 304 | static int add_byte(int c, char **lineptr, size_t slen, size_t *n) |
| 305 | { |
| 306 | char *nline; |
| 307 | size_t new_size = slen + 1; |
| 308 | if (new_size > *n) { |
| 309 | new_size += LINE_GROWTH - 1; |
| 310 | new_size *= 2; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 311 | nline = xrealloc(*lineptr, new_size); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 312 | if (!nline) |
| 313 | return -1; |
| 314 | |
| 315 | *lineptr = nline; |
| 316 | *n = new_size; |
| 317 | } |
| 318 | |
| 319 | (*lineptr)[slen] = c; |
| 320 | |
| 321 | return 0; |
| 322 | } |
| 323 | |
| 324 | static ssize_t compat_getline(char **lineptr, size_t *n, FILE *stream) |
| 325 | { |
| 326 | char *line = *lineptr; |
| 327 | size_t slen = 0; |
| 328 | |
| 329 | for (;;) { |
| 330 | int c = getc(stream); |
| 331 | |
| 332 | switch (c) { |
| 333 | case '\n': |
| 334 | if (add_byte(c, &line, slen, n) < 0) |
| 335 | goto e_out; |
| 336 | slen++; |
| 337 | /* fall through */ |
| 338 | case EOF: |
| 339 | if (add_byte('\0', &line, slen, n) < 0) |
| 340 | goto e_out; |
| 341 | *lineptr = line; |
| 342 | if (slen == 0) |
| 343 | return -1; |
| 344 | return slen; |
| 345 | default: |
| 346 | if (add_byte(c, &line, slen, n) < 0) |
| 347 | goto e_out; |
| 348 | slen++; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | e_out: |
| 353 | line[slen-1] = '\0'; |
| 354 | *lineptr = line; |
| 355 | return -1; |
| 356 | } |
| 357 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 358 | int conf_read_simple(const char *name, int def) |
| 359 | { |
| 360 | FILE *in = NULL; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 361 | char *line = NULL; |
| 362 | size_t line_asize = 0; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 363 | char *p, *p2; |
| 364 | struct symbol *sym; |
| 365 | int i, def_flags; |
| 366 | |
| 367 | if (name) { |
| 368 | in = zconf_fopen(name); |
| 369 | } else { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 370 | char *env; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 371 | |
| 372 | name = conf_get_configname(); |
| 373 | in = zconf_fopen(name); |
| 374 | if (in) |
| 375 | goto load; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 376 | conf_set_changed(true); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 377 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 378 | env = getenv("KCONFIG_DEFCONFIG_LIST"); |
| 379 | if (!env) |
| 380 | return 1; |
| 381 | |
| 382 | while (1) { |
| 383 | bool is_last; |
| 384 | |
| 385 | while (isspace(*env)) |
| 386 | env++; |
| 387 | |
| 388 | if (!*env) |
| 389 | break; |
| 390 | |
| 391 | p = env; |
| 392 | while (*p && !isspace(*p)) |
| 393 | p++; |
| 394 | |
| 395 | is_last = (*p == '\0'); |
| 396 | |
| 397 | *p = '\0'; |
| 398 | |
| 399 | in = zconf_fopen(env); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 400 | if (in) { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 401 | conf_message("using defaults found in %s", |
| 402 | env); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 403 | goto load; |
| 404 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 405 | |
| 406 | if (is_last) |
| 407 | break; |
| 408 | |
| 409 | env = p + 1; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | if (!in) |
| 413 | return 1; |
| 414 | |
| 415 | load: |
| 416 | conf_filename = name; |
| 417 | conf_lineno = 0; |
| 418 | conf_warnings = 0; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 419 | |
| 420 | def_flags = SYMBOL_DEF << def; |
| 421 | for_all_symbols(i, sym) { |
| 422 | sym->flags |= SYMBOL_CHANGED; |
| 423 | sym->flags &= ~(def_flags|SYMBOL_VALID); |
| 424 | if (sym_is_choice(sym)) |
| 425 | sym->flags |= def_flags; |
| 426 | switch (sym->type) { |
| 427 | case S_INT: |
| 428 | case S_HEX: |
| 429 | case S_STRING: |
| 430 | if (sym->def[def].val) |
| 431 | free(sym->def[def].val); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 432 | /* fall through */ |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 433 | default: |
| 434 | sym->def[def].val = NULL; |
| 435 | sym->def[def].tri = no; |
| 436 | } |
| 437 | } |
| 438 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 439 | while (compat_getline(&line, &line_asize, in) != -1) { |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 440 | conf_lineno++; |
| 441 | sym = NULL; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 442 | if (line[0] == '#') { |
| 443 | if (memcmp(line + 2, CONFIG_, strlen(CONFIG_))) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 444 | continue; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 445 | p = strchr(line + 2 + strlen(CONFIG_), ' '); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 446 | if (!p) |
| 447 | continue; |
| 448 | *p++ = 0; |
| 449 | if (strncmp(p, "is not set", 10)) |
| 450 | continue; |
| 451 | if (def == S_DEF_USER) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 452 | sym = sym_find(line + 2 + strlen(CONFIG_)); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 453 | if (!sym) { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 454 | conf_message( |
| 455 | "ignoring nonexistent symbol %s", |
| 456 | line + 2 + strlen(CONFIG_)); |
| 457 | conf_set_changed(true); |
| 458 | continue; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 459 | } |
| 460 | } else { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 461 | sym = sym_lookup(line + 2 + strlen(CONFIG_), 0); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 462 | if (sym->type == S_UNKNOWN) |
| 463 | sym->type = S_BOOLEAN; |
| 464 | } |
| 465 | if (sym->flags & def_flags) { |
Martin Roth | 00cbc7f | 2016-09-21 14:27:26 -0600 | [diff] [blame] | 466 | conf_notice("override: reassigning to symbol %s", sym->name); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 467 | } |
| 468 | switch (sym->type) { |
| 469 | case S_BOOLEAN: |
| 470 | case S_TRISTATE: |
| 471 | sym->def[def].tri = no; |
| 472 | sym->flags |= def_flags; |
| 473 | break; |
| 474 | default: |
| 475 | ; |
| 476 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 477 | } else if (memcmp(line, CONFIG_, strlen(CONFIG_)) == 0) { |
| 478 | p = strchr(line + strlen(CONFIG_), '='); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 479 | if (!p) |
| 480 | continue; |
| 481 | *p++ = 0; |
| 482 | p2 = strchr(p, '\n'); |
| 483 | if (p2) { |
| 484 | *p2-- = 0; |
| 485 | if (*p2 == '\r') |
| 486 | *p2 = 0; |
| 487 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 488 | |
| 489 | sym = sym_find(line + strlen(CONFIG_)); |
| 490 | if (!sym) { |
| 491 | if (def == S_DEF_AUTO) |
| 492 | /* |
| 493 | * Reading from include/config/auto.conf |
| 494 | * If CONFIG_FOO previously existed in |
| 495 | * auto.conf but it is missing now, |
| 496 | * include/config/FOO must be touched. |
| 497 | */ |
| 498 | conf_touch_dep(line + strlen(CONFIG_)); |
| 499 | else |
| 500 | conf_set_changed(true); |
| 501 | continue; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 502 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 503 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 504 | if (sym->flags & def_flags) { |
Martin Roth | 00cbc7f | 2016-09-21 14:27:26 -0600 | [diff] [blame] | 505 | conf_notice("override: reassigning to symbol %s", sym->name); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 506 | } |
| 507 | if (conf_set_sym_val(sym, def, def_flags, p)) |
| 508 | continue; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 509 | } else { |
| 510 | if (line[0] != '\r' && line[0] != '\n') |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 511 | conf_warning("unexpected data: %.*s", |
| 512 | (int)strcspn(line, "\r\n"), line); |
| 513 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 514 | continue; |
| 515 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 516 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 517 | if (sym && sym_is_choice_value(sym)) { |
| 518 | struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym)); |
| 519 | switch (sym->def[def].tri) { |
| 520 | case no: |
| 521 | break; |
| 522 | case mod: |
| 523 | if (cs->def[def].tri == yes) { |
| 524 | conf_warning("%s creates inconsistent choice state", sym->name); |
| 525 | cs->flags &= ~def_flags; |
| 526 | } |
| 527 | break; |
| 528 | case yes: |
| 529 | if (cs->def[def].tri != no) |
Martin Roth | 00cbc7f | 2016-09-21 14:27:26 -0600 | [diff] [blame] | 530 | conf_notice("override: %s changes choice state", sym->name); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 531 | cs->def[def].val = sym; |
| 532 | break; |
| 533 | } |
| 534 | cs->def[def].tri = EXPR_OR(cs->def[def].tri, sym->def[def].tri); |
| 535 | } |
| 536 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 537 | free(line); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 538 | fclose(in); |
| 539 | |
Stefan Reinauer | 57a3131 | 2015-08-20 11:19:34 -0700 | [diff] [blame] | 540 | kconfig_warnings += conf_warnings; |
Stefan Reinauer | f534203 | 2015-07-17 17:26:48 -0700 | [diff] [blame] | 541 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | int conf_read(const char *name) |
| 546 | { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 547 | struct symbol *sym; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 548 | int conf_unsaved = 0; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 549 | int i; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 550 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 551 | conf_set_changed(false); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 552 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 553 | if (conf_read_simple(name, S_DEF_USER)) { |
| 554 | sym_calc_value(modules_sym); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 555 | return 1; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | sym_calc_value(modules_sym); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 559 | |
| 560 | for_all_symbols(i, sym) { |
| 561 | sym_calc_value(sym); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 562 | if (sym_is_choice(sym) || (sym->flags & SYMBOL_NO_WRITE)) |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 563 | continue; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 564 | if (sym_has_value(sym) && (sym->flags & SYMBOL_WRITE)) { |
| 565 | /* check that calculated value agrees with saved value */ |
| 566 | switch (sym->type) { |
| 567 | case S_BOOLEAN: |
| 568 | case S_TRISTATE: |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 569 | if (sym->def[S_DEF_USER].tri == sym_get_tristate_value(sym)) |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 570 | continue; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 571 | break; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 572 | default: |
| 573 | if (!strcmp(sym->curr.val, sym->def[S_DEF_USER].val)) |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 574 | continue; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 575 | break; |
| 576 | } |
| 577 | } else if (!sym_has_value(sym) && !(sym->flags & SYMBOL_WRITE)) |
| 578 | /* no previous value and not saved */ |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 579 | continue; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 580 | conf_unsaved++; |
| 581 | /* maybe print value in verbose mode... */ |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | for_all_symbols(i, sym) { |
| 585 | if (sym_has_value(sym) && !sym_is_choice_value(sym)) { |
| 586 | /* Reset values of generates values, so they'll appear |
| 587 | * as new, if they should become visible, but that |
| 588 | * doesn't quite work if the Kconfig and the saved |
| 589 | * configuration disagree. |
| 590 | */ |
| 591 | if (sym->visible == no && !conf_unsaved) |
| 592 | sym->flags &= ~SYMBOL_DEF_USER; |
| 593 | switch (sym->type) { |
| 594 | case S_STRING: |
| 595 | case S_INT: |
| 596 | case S_HEX: |
| 597 | /* Reset a string value if it's out of range */ |
| 598 | if (sym_string_within_range(sym, sym->def[S_DEF_USER].val)) |
| 599 | break; |
| 600 | sym->flags &= ~(SYMBOL_VALID|SYMBOL_DEF_USER); |
| 601 | conf_unsaved++; |
| 602 | break; |
| 603 | default: |
| 604 | break; |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 609 | if (conf_warnings || conf_unsaved) |
| 610 | conf_set_changed(true); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 611 | |
| 612 | return 0; |
| 613 | } |
| 614 | |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 615 | struct comment_style { |
| 616 | const char *decoration; |
| 617 | const char *prefix; |
| 618 | const char *postfix; |
| 619 | }; |
| 620 | |
| 621 | static const struct comment_style comment_style_pound = { |
| 622 | .decoration = "#", |
| 623 | .prefix = "#", |
| 624 | .postfix = "#", |
| 625 | }; |
| 626 | |
| 627 | static const struct comment_style comment_style_c = { |
| 628 | .decoration = " *", |
| 629 | .prefix = "/*", |
| 630 | .postfix = " */", |
| 631 | }; |
| 632 | |
| 633 | static void conf_write_heading(FILE *fp, const struct comment_style *cs) |
| 634 | { |
| 635 | fprintf(fp, "%s\n", cs->prefix); |
| 636 | |
| 637 | fprintf(fp, "%s Automatically generated file; DO NOT EDIT.\n", |
| 638 | cs->decoration); |
| 639 | |
| 640 | fprintf(fp, "%s %s\n", cs->decoration, rootmenu.prompt->text); |
| 641 | |
| 642 | fprintf(fp, "%s\n", cs->postfix); |
| 643 | } |
| 644 | |
| 645 | /* The returned pointer must be freed on the caller side */ |
| 646 | static char *escape_string_value(const char *in) |
| 647 | { |
| 648 | const char *p; |
| 649 | char *out; |
| 650 | size_t len; |
| 651 | |
| 652 | len = strlen(in) + strlen("\"\"") + 1; |
| 653 | |
| 654 | p = in; |
| 655 | while (1) { |
| 656 | p += strcspn(p, "\"\\"); |
| 657 | |
| 658 | if (p[0] == '\0') |
| 659 | break; |
| 660 | |
| 661 | len++; |
| 662 | p++; |
| 663 | } |
| 664 | |
| 665 | out = xmalloc(len); |
| 666 | out[0] = '\0'; |
| 667 | |
| 668 | strcat(out, "\""); |
| 669 | |
| 670 | p = in; |
| 671 | while (1) { |
| 672 | len = strcspn(p, "\"\\"); |
| 673 | strncat(out, p, len); |
| 674 | p += len; |
| 675 | |
| 676 | if (p[0] == '\0') |
| 677 | break; |
| 678 | |
| 679 | strcat(out, "\\"); |
| 680 | strncat(out, p++, 1); |
| 681 | } |
| 682 | |
| 683 | strcat(out, "\""); |
| 684 | |
| 685 | return out; |
| 686 | } |
| 687 | |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 688 | enum output_n { OUTPUT_N, OUTPUT_N_AS_UNSET, OUTPUT_N_NONE }; |
| 689 | |
| 690 | static void __print_symbol(FILE *fp, struct symbol *sym, enum output_n output_n, |
| 691 | bool escape_string) |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 692 | { |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 693 | const char *val; |
| 694 | char *escaped = NULL; |
| 695 | |
| 696 | if (sym->type == S_UNKNOWN) |
| 697 | return; |
| 698 | |
| 699 | val = sym_get_string_value(sym); |
| 700 | |
| 701 | if ((sym->type == S_BOOLEAN || sym->type == S_TRISTATE) && |
| 702 | output_n != OUTPUT_N && *val == 'n') { |
| 703 | if (output_n == OUTPUT_N_AS_UNSET) |
| 704 | fprintf(fp, "# %s%s is not set\n", CONFIG_, sym->name); |
| 705 | return; |
| 706 | } |
| 707 | |
| 708 | if (sym->type == S_STRING && escape_string) { |
| 709 | escaped = escape_string_value(val); |
| 710 | val = escaped; |
| 711 | } |
| 712 | |
| 713 | fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, val); |
| 714 | |
| 715 | free(escaped); |
| 716 | } |
| 717 | |
| 718 | static void print_symbol_for_dotconfig(FILE *fp, struct symbol *sym) |
| 719 | { |
| 720 | __print_symbol(fp, sym, OUTPUT_N_AS_UNSET, true); |
| 721 | } |
| 722 | |
| 723 | static void print_symbol_for_autoconf(FILE *fp, struct symbol *sym) |
| 724 | { |
| 725 | int print_negatives = getenv("KCONFIG_NEGATIVES") != NULL; |
| 726 | enum output_n out = OUTPUT_N_NONE; |
| 727 | if (print_negatives) { |
| 728 | out = OUTPUT_N; |
| 729 | } |
Patrick Georgi | 7eb03cb | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 730 | __print_symbol(fp, sym, out, false); |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | void print_symbol_for_listconfig(struct symbol *sym) |
| 734 | { |
| 735 | __print_symbol(stdout, sym, OUTPUT_N, true); |
| 736 | } |
| 737 | |
| 738 | static void print_symbol_for_c(FILE *fp, struct symbol *sym) |
| 739 | { |
| 740 | const char *val; |
| 741 | const char *sym_suffix = ""; |
| 742 | const char *val_prefix = ""; |
| 743 | char *escaped = NULL; |
| 744 | |
| 745 | if (sym->type == S_UNKNOWN) |
| 746 | return; |
| 747 | |
| 748 | val = sym_get_string_value(sym); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 749 | |
| 750 | switch (sym->type) { |
| 751 | case S_BOOLEAN: |
| 752 | case S_TRISTATE: |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 753 | switch (*val) { |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 754 | case 'n': |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 755 | if (getenv("KCONFIG_NEGATIVES") != NULL) { |
| 756 | val = "0"; |
| 757 | break; |
| 758 | } |
| 759 | return; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 760 | case 'm': |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 761 | sym_suffix = "_MODULE"; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 762 | /* fall through */ |
| 763 | default: |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 764 | val = "1"; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 765 | } |
| 766 | break; |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 767 | case S_HEX: |
| 768 | if (val[0] != '0' || (val[1] != 'x' && val[1] != 'X')) |
| 769 | val_prefix = "0x"; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 770 | /* fall through */ |
| 771 | case S_INT: |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 772 | if (val[0] == '\0') { |
| 773 | val = "0"; |
| 774 | val_prefix = ""; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 775 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 776 | break; |
| 777 | case S_STRING: |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 778 | escaped = escape_string_value(val); |
| 779 | val = escaped; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 780 | default: |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 781 | break; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 782 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 783 | |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 784 | fprintf(fp, "#define %s%s%s %s%s\n", CONFIG_, sym->name, sym_suffix, |
| 785 | val_prefix, val); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 786 | |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 787 | free(escaped); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | /* |
| 791 | * Write out a minimal config. |
| 792 | * All values that has default values are skipped as this is redundant. |
| 793 | */ |
| 794 | int conf_write_defconfig(const char *filename) |
| 795 | { |
| 796 | struct symbol *sym; |
| 797 | struct menu *menu; |
| 798 | FILE *out; |
| 799 | |
| 800 | out = fopen(filename, "w"); |
| 801 | if (!out) |
| 802 | return 1; |
| 803 | |
| 804 | sym_clear_all_valid(); |
| 805 | |
| 806 | /* Traverse all menus to find all relevant symbols */ |
| 807 | menu = rootmenu.list; |
| 808 | |
| 809 | while (menu != NULL) |
| 810 | { |
| 811 | sym = menu->sym; |
| 812 | if (sym == NULL) { |
| 813 | if (!menu_is_visible(menu)) |
| 814 | goto next_menu; |
| 815 | } else if (!sym_is_choice(sym)) { |
| 816 | sym_calc_value(sym); |
| 817 | if (!(sym->flags & SYMBOL_WRITE)) |
| 818 | goto next_menu; |
| 819 | sym->flags &= ~SYMBOL_WRITE; |
| 820 | /* If we cannot change the symbol - skip */ |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 821 | if (!sym_is_changeable(sym)) |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 822 | goto next_menu; |
| 823 | /* If symbol equals to default value - skip */ |
| 824 | if (strcmp(sym_get_string_value(sym), sym_get_string_default(sym)) == 0) |
| 825 | goto next_menu; |
| 826 | |
| 827 | /* |
| 828 | * If symbol is a choice value and equals to the |
| 829 | * default for a choice - skip. |
| 830 | * But only if value is bool and equal to "y" and |
| 831 | * choice is not "optional". |
| 832 | * (If choice is "optional" then all values can be "n") |
| 833 | */ |
| 834 | if (sym_is_choice_value(sym)) { |
| 835 | struct symbol *cs; |
| 836 | struct symbol *ds; |
| 837 | |
| 838 | cs = prop_get_symbol(sym_get_choice_prop(sym)); |
| 839 | ds = sym_choice_default(cs); |
| 840 | if (!sym_is_optional(cs) && sym == ds) { |
| 841 | if ((sym->type == S_BOOLEAN) && |
| 842 | sym_get_tristate_value(sym) == yes) |
| 843 | goto next_menu; |
| 844 | } |
| 845 | } |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 846 | print_symbol_for_dotconfig(out, sym); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 847 | } |
| 848 | next_menu: |
| 849 | if (menu->list != NULL) { |
| 850 | menu = menu->list; |
| 851 | } |
| 852 | else if (menu->next != NULL) { |
| 853 | menu = menu->next; |
| 854 | } else { |
| 855 | while ((menu = menu->parent)) { |
| 856 | if (menu->next != NULL) { |
| 857 | menu = menu->next; |
| 858 | break; |
| 859 | } |
| 860 | } |
| 861 | } |
| 862 | } |
| 863 | fclose(out); |
| 864 | return 0; |
| 865 | } |
| 866 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 867 | int conf_write(const char *name) |
| 868 | { |
| 869 | FILE *out; |
| 870 | struct symbol *sym; |
| 871 | struct menu *menu; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 872 | const char *str; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 873 | char tmpname[PATH_MAX + 1], oldname[PATH_MAX + 1]; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 874 | char *env; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 875 | int i; |
| 876 | bool need_newline = false; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 877 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 878 | if (!name) |
Raul E Rangel | d2f90a0 | 2019-07-25 16:00:50 -0600 | [diff] [blame] | 879 | name = conf_get_configname(); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 880 | |
| 881 | if (!*name) { |
| 882 | fprintf(stderr, "config name is empty\n"); |
| 883 | return -1; |
Raul E Rangel | d2f90a0 | 2019-07-25 16:00:50 -0600 | [diff] [blame] | 884 | } |
| 885 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 886 | if (is_dir(name)) { |
| 887 | fprintf(stderr, "%s: Is a directory\n", name); |
| 888 | return -1; |
Raul E Rangel | d2f90a0 | 2019-07-25 16:00:50 -0600 | [diff] [blame] | 889 | } |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 890 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 891 | if (make_parent_dir(name)) |
| 892 | return -1; |
| 893 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 894 | env = getenv("KCONFIG_OVERWRITECONFIG"); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 895 | if (env && *env) { |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 896 | *tmpname = 0; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 897 | out = fopen(name, "w"); |
| 898 | } else { |
| 899 | snprintf(tmpname, sizeof(tmpname), "%s.%d.tmp", |
| 900 | name, (int)getpid()); |
| 901 | out = fopen(tmpname, "w"); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 902 | } |
| 903 | if (!out) |
| 904 | return 1; |
| 905 | |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 906 | conf_write_heading(out, &comment_style_pound); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 907 | |
| 908 | if (!conf_get_changed()) |
| 909 | sym_clear_all_valid(); |
| 910 | |
| 911 | menu = rootmenu.list; |
| 912 | while (menu) { |
| 913 | sym = menu->sym; |
| 914 | if (!sym) { |
| 915 | if (!menu_is_visible(menu)) |
| 916 | goto next; |
| 917 | str = menu_get_prompt(menu); |
| 918 | fprintf(out, "\n" |
| 919 | "#\n" |
| 920 | "# %s\n" |
| 921 | "#\n", str); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 922 | need_newline = false; |
| 923 | } else if (!(sym->flags & SYMBOL_CHOICE) && |
| 924 | !(sym->flags & SYMBOL_WRITTEN)) { |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 925 | sym_calc_value(sym); |
| 926 | if (!(sym->flags & SYMBOL_WRITE)) |
| 927 | goto next; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 928 | if (need_newline) { |
| 929 | fprintf(out, "\n"); |
| 930 | need_newline = false; |
| 931 | } |
| 932 | sym->flags |= SYMBOL_WRITTEN; |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 933 | print_symbol_for_dotconfig(out, sym); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 934 | } |
| 935 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 936 | next: |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 937 | if (menu->list) { |
| 938 | menu = menu->list; |
| 939 | continue; |
| 940 | } |
Patrick Georgi | 5526be2 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 941 | |
| 942 | end_check: |
| 943 | if (!menu->sym && menu_is_visible(menu) && menu != &rootmenu && |
| 944 | menu->prompt->type == P_MENU) { |
| 945 | fprintf(out, "# end of %s\n", menu_get_prompt(menu)); |
| 946 | need_newline = true; |
| 947 | } |
| 948 | |
| 949 | if (menu->next) { |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 950 | menu = menu->next; |
Patrick Georgi | 5526be2 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 951 | } else { |
| 952 | menu = menu->parent; |
| 953 | if (menu) |
| 954 | goto end_check; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 955 | } |
| 956 | } |
| 957 | fclose(out); |
| 958 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 959 | for_all_symbols(i, sym) |
| 960 | sym->flags &= ~SYMBOL_WRITTEN; |
| 961 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 962 | if (*tmpname) { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 963 | if (is_same(name, tmpname)) { |
| 964 | conf_message("No change to %s", name); |
| 965 | unlink(tmpname); |
| 966 | conf_set_changed(false); |
| 967 | return 0; |
| 968 | } |
| 969 | |
| 970 | snprintf(oldname, sizeof(oldname), "%s.old", name); |
| 971 | rename(name, oldname); |
| 972 | if (rename(tmpname, name)) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 973 | return 1; |
| 974 | } |
| 975 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 976 | conf_message("configuration written to %s", name); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 977 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 978 | conf_set_changed(false); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 979 | |
| 980 | return 0; |
| 981 | } |
| 982 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 983 | /* write a dependency file as used by kbuild to track dependencies */ |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 984 | static int conf_write_autoconf_cmd(const char *autoconf_name) |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 985 | { |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 986 | char name[PATH_MAX], tmp[PATH_MAX]; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 987 | struct file *file; |
| 988 | FILE *out; |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 989 | int ret; |
| 990 | |
| 991 | ret = snprintf(name, sizeof(name), "%s.cmd", autoconf_name); |
| 992 | if (ret >= sizeof(name)) /* check truncation */ |
| 993 | return -1; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 994 | |
| 995 | if (make_parent_dir(name)) |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 996 | return -1; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 997 | |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 998 | ret = snprintf(tmp, sizeof(tmp), "%s.cmd.tmp", autoconf_name); |
| 999 | if (ret >= sizeof(tmp)) /* check truncation */ |
| 1000 | return -1; |
| 1001 | |
| 1002 | out = fopen(tmp, "w"); |
| 1003 | if (!out) { |
| 1004 | perror("fopen"); |
| 1005 | return -1; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1006 | } |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1007 | |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1008 | fprintf(out, "deps_config := \\\n"); |
| 1009 | for (file = file_list; file; file = file->next) |
| 1010 | fprintf(out, "\t%s \\\n", file->name); |
| 1011 | |
| 1012 | fprintf(out, "\n%s: $(deps_config)\n\n", autoconf_name); |
| 1013 | |
| 1014 | env_write_dep(out, autoconf_name); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1015 | |
| 1016 | fprintf(out, "\n$(deps_config): ;\n"); |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1017 | |
Patrick Georgi | 5526be2 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1018 | fflush(out); |
Patrick Georgi | 7eb03cb | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1019 | ret = ferror(out); /* error check for all fprintf() calls */ |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1020 | fclose(out); |
Patrick Georgi | 7eb03cb | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1021 | if (ret) |
| 1022 | return -1; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1023 | |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1024 | if (rename(tmp, name)) { |
| 1025 | perror("rename"); |
| 1026 | return -1; |
| 1027 | } |
| 1028 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1029 | return 0; |
| 1030 | } |
| 1031 | |
| 1032 | static int conf_touch_deps(void) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1033 | { |
Martin Roth | 35e09ec | 2022-11-13 15:20:57 -0700 | [diff] [blame] | 1034 | const char *name; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1035 | struct symbol *sym; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1036 | int res, i; |
| 1037 | |
Martin Roth | 35e09ec | 2022-11-13 15:20:57 -0700 | [diff] [blame] | 1038 | strcpy(depfile_path, conf_get_autobase_name()); |
| 1039 | depfile_prefix_len = strlen(depfile_path); |
| 1040 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1041 | name = conf_get_autoconfig_name(); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1042 | conf_read_simple(name, S_DEF_AUTO); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1043 | sym_calc_value(modules_sym); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1044 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1045 | for_all_symbols(i, sym) { |
| 1046 | sym_calc_value(sym); |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1047 | if ((sym->flags & SYMBOL_NO_WRITE) || !sym->name) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1048 | continue; |
| 1049 | if (sym->flags & SYMBOL_WRITE) { |
| 1050 | if (sym->flags & SYMBOL_DEF_AUTO) { |
| 1051 | /* |
| 1052 | * symbol has old and new value, |
| 1053 | * so compare them... |
| 1054 | */ |
| 1055 | switch (sym->type) { |
| 1056 | case S_BOOLEAN: |
| 1057 | case S_TRISTATE: |
| 1058 | if (sym_get_tristate_value(sym) == |
| 1059 | sym->def[S_DEF_AUTO].tri) |
| 1060 | continue; |
| 1061 | break; |
| 1062 | case S_STRING: |
| 1063 | case S_HEX: |
| 1064 | case S_INT: |
| 1065 | if (!strcmp(sym_get_string_value(sym), |
| 1066 | sym->def[S_DEF_AUTO].val)) |
| 1067 | continue; |
| 1068 | break; |
| 1069 | default: |
| 1070 | break; |
| 1071 | } |
| 1072 | } else { |
| 1073 | /* |
| 1074 | * If there is no old value, only 'no' (unset) |
| 1075 | * is allowed as new value. |
| 1076 | */ |
| 1077 | switch (sym->type) { |
| 1078 | case S_BOOLEAN: |
| 1079 | case S_TRISTATE: |
| 1080 | if (sym_get_tristate_value(sym) == no) |
| 1081 | continue; |
| 1082 | break; |
| 1083 | default: |
| 1084 | break; |
| 1085 | } |
| 1086 | } |
| 1087 | } else if (!(sym->flags & SYMBOL_DEF_AUTO)) |
| 1088 | /* There is neither an old nor a new value. */ |
| 1089 | continue; |
| 1090 | /* else |
| 1091 | * There is an old value, but no new value ('no' (unset) |
| 1092 | * isn't saved in auto.conf, so the old value is always |
| 1093 | * different from 'no'). |
| 1094 | */ |
| 1095 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1096 | res = conf_touch_dep(sym->name); |
| 1097 | if (res) |
| 1098 | return res; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1099 | } |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1100 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1101 | return 0; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1104 | static int __conf_write_autoconf(const char *filename, |
| 1105 | void (*print_symbol)(FILE *, struct symbol *), |
| 1106 | const struct comment_style *comment_style) |
| 1107 | { |
| 1108 | char tmp[PATH_MAX]; |
| 1109 | FILE *file; |
| 1110 | struct symbol *sym; |
| 1111 | int ret, i; |
| 1112 | |
| 1113 | if (make_parent_dir(filename)) |
| 1114 | return -1; |
| 1115 | |
| 1116 | ret = snprintf(tmp, sizeof(tmp), "%s.tmp", filename); |
| 1117 | if (ret >= sizeof(tmp)) /* check truncation */ |
| 1118 | return -1; |
| 1119 | |
| 1120 | file = fopen(tmp, "w"); |
| 1121 | if (!file) { |
| 1122 | perror("fopen"); |
| 1123 | return -1; |
| 1124 | } |
| 1125 | |
| 1126 | conf_write_heading(file, comment_style); |
| 1127 | |
| 1128 | int print_negatives = getenv("KCONFIG_NEGATIVES") != NULL; |
| 1129 | for_all_symbols(i, sym) |
| 1130 | if (((sym->flags & SYMBOL_WRITE) || (print_negatives && sym->type != S_STRING)) && sym->name) |
| 1131 | print_symbol(file, sym); |
| 1132 | |
Patrick Georgi | 5526be2 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1133 | fflush(file); |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1134 | /* check possible errors in conf_write_heading() and print_symbol() */ |
Patrick Georgi | 7eb03cb | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1135 | ret = ferror(file); |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1136 | fclose(file); |
Patrick Georgi | 7eb03cb | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1137 | if (ret) |
| 1138 | return -1; |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1139 | |
| 1140 | if (rename(tmp, filename)) { |
| 1141 | perror("rename"); |
| 1142 | return -1; |
| 1143 | } |
| 1144 | |
| 1145 | return 0; |
| 1146 | } |
| 1147 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1148 | int conf_write_autoconf(int overwrite) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1149 | { |
| 1150 | struct symbol *sym; |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1151 | const char *autoconf_name = conf_get_autoconfig_name(); |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1152 | int ret, i; |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1153 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1154 | if (!overwrite && is_present(autoconf_name)) |
| 1155 | return 0; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1156 | |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1157 | ret = conf_write_autoconf_cmd(autoconf_name); |
| 1158 | if (ret) |
| 1159 | return -1; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1160 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1161 | if (conf_touch_deps()) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1162 | return 1; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1163 | |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1164 | for_all_symbols(i, sym) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1165 | sym_calc_value(sym); |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1166 | |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1167 | ret = __conf_write_autoconf(conf_get_autoheader_name(), |
| 1168 | print_symbol_for_c, |
| 1169 | &comment_style_c); |
| 1170 | if (ret) |
| 1171 | return ret; |
Raul E Rangel | 7b2dedd | 2019-07-25 15:49:52 -0600 | [diff] [blame] | 1172 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1173 | /* |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1174 | * Create include/config/auto.conf. This must be the last step because |
| 1175 | * Kbuild has a dependency on auto.conf and this marks the successful |
| 1176 | * completion of the previous steps. |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1177 | */ |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 1178 | ret = __conf_write_autoconf(conf_get_autoconfig_name(), |
| 1179 | print_symbol_for_autoconf, |
| 1180 | &comment_style_pound); |
| 1181 | if (ret) |
| 1182 | return ret; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1183 | |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1184 | return 0; |
| 1185 | } |
| 1186 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1187 | static bool conf_changed; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1188 | static void (*conf_changed_callback)(void); |
| 1189 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1190 | void conf_set_changed(bool val) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1191 | { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1192 | if (conf_changed_callback && conf_changed != val) |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1193 | conf_changed_callback(); |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1194 | |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1195 | conf_changed = val; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | bool conf_get_changed(void) |
| 1199 | { |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1200 | return conf_changed; |
Patrick Georgi | 0588d19 | 2009-08-12 15:00:51 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | void conf_set_changed_callback(void (*fn)(void)) |
| 1204 | { |
| 1205 | conf_changed_callback = fn; |
| 1206 | } |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1207 | |
Patrick Georgi | d520840 | 2014-04-11 20:24:06 +0200 | [diff] [blame] | 1208 | void set_all_choice_values(struct symbol *csym) |
| 1209 | { |
| 1210 | struct property *prop; |
| 1211 | struct symbol *sym; |
| 1212 | struct expr *e; |
| 1213 | |
| 1214 | prop = sym_get_choice_prop(csym); |
| 1215 | |
| 1216 | /* |
| 1217 | * Set all non-assinged choice values to no |
| 1218 | */ |
| 1219 | expr_list_for_each_sym(prop->expr, e, sym) { |
| 1220 | if (!sym_has_value(sym)) |
| 1221 | sym->def[S_DEF_USER].tri = no; |
| 1222 | } |
| 1223 | csym->flags |= SYMBOL_DEF_USER; |
| 1224 | /* clear VALID to get value calculated */ |
| 1225 | csym->flags &= ~(SYMBOL_VALID | SYMBOL_NEED_SET_CHOICE_VALUES); |
| 1226 | } |