summaryrefslogtreecommitdiffstats
path: root/util/kconfig/patches/0009-util-kconfig-Allow-emitting-false-booleans-into-kconfig-output.patch
blob: 7e005e5f9d5eda4d8c2a2aef6ddb55e84cf81fe9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
commit ab0cc6067d5a00182e89fbec82b942eb3d803204
Author: Patrick Georgi <pgeorgi@google.com>
Date:   Fri Nov 22 22:08:15 2019 +0100

    util/kconfig: Allow emitting false booleans into kconfig output

    This is controlled by an environment variable so the same tool is
    useful in different contexts.

    Change-Id: I9e62b05e45709f1539e455e2eed37308609be15e
    Signed-off-by: Patrick Georgi <pgeorgi@google.com>

Index: kconfig/confdata.c
===================================================================
--- kconfig.orig/confdata.c
+++ kconfig/confdata.c
@@ -687,6 +687,9 @@ header_print_symbol(FILE *fp, struct sym
 
 		switch (*value) {
 		case 'n':
+			if (getenv("KCONFIG_NEGATIVES") != NULL)
+				fprintf(fp, "#define %s%s%s 0\n",
+				    CONFIG_, sym->name, suffix);
 			break;
 		case 'm':
 			suffix = "_MODULE";
@@ -702,14 +705,28 @@ header_print_symbol(FILE *fp, struct sym
 
 		if (value[0] != '0' || (value[1] != 'x' && value[1] != 'X'))
 			prefix = "0x";
+		if (value[0] == '\0') {
+			/*
+			 * prefix is reset to remain closer to the older
+			 * coreboot patch. No need to keep this once kconfig
+			 * is fully upreved
+			 */
+			prefix = "";
+			value = "0";
+		}
 		fprintf(fp, "#define %s%s %s%s\n",
 		    CONFIG_, sym->name, prefix, value);
 		break;
 	}
 	case S_STRING:
+		if (value[0] == '\0')
+			break;
+		if (!(sym->flags & SYMBOL_WRITE))
+			break;
+		/* fall through */
 	case S_INT:
 		fprintf(fp, "#define %s%s %s\n",
-		    CONFIG_, sym->name, value);
+		    CONFIG_, sym->name, value[0]?value:"0");
 		break;
 	default:
 		break;
@@ -1080,6 +1097,7 @@ int conf_write_autoconf(int overwrite)
 	const char *autoconf_name = conf_get_autoconfig_name();
 	FILE *out, *out_h;
 	int i;
+	int print_negatives = getenv("KCONFIG_NEGATIVES") != NULL;
 
 	if (!overwrite && is_present(autoconf_name))
 		return 0;
@@ -1104,11 +1122,13 @@ int conf_write_autoconf(int overwrite)
 
 	for_all_symbols(i, sym) {
 		sym_calc_value(sym);
-		if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
+		if (!(sym->flags & SYMBOL_WRITE) && !print_negatives)
+			continue;
+		if (!sym->name)
 			continue;
 
 		/* write symbols to auto.conf and autoconf.h */
-		conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1);
+		conf_write_symbol(out, sym, &kconfig_printer_cb, print_negatives?NULL:(void *)1);
 		conf_write_symbol(out_h, sym, &header_printer_cb, NULL);
 	}
 	fclose(out);
Index: kconfig/symbol.c
===================================================================
--- kconfig.orig/symbol.c
+++ kconfig/symbol.c
@@ -757,7 +757,7 @@ const char *sym_get_string_default(struc
 		}
 	case S_INT:
 	case S_HEX:
-		return str;
+		return "0";
 	case S_STRING:
 		return str;
 	case S_UNKNOWN: