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