summaryrefslogtreecommitdiff
path: root/support/kconfig/patches/14-support-out-of-tree-config.patch
blob: 9fa6384d315d7dac6ac31a4c4cbfa06cf14d470f (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
---
 conf.c     |    1 
 confdata.c |   62 ++++++++++++++++++++++++++++++++++++++++++++++---------------
 util.c     |   16 +++++++++++++--
 3 files changed, 61 insertions(+), 18 deletions(-)

Index: config/conf.c
===================================================================
--- config.orig/conf.c
+++ config/conf.c
@@ -503,7 +503,6 @@
 	}
 	name = av[optind];
 	conf_parse(name);
-	//zconfdump(stdout);
 	if (sync_kconfig) {
 		name = conf_get_configname();
 		if (stat(name, &tmpstat)) {
Index: config/confdata.c
===================================================================
--- config.orig/confdata.c
+++ config/confdata.c
@@ -71,9 +71,7 @@
 
 const char *conf_get_autoconfig_name(void)
 {
-	char *name = getenv("KCONFIG_AUTOCONFIG");
-
-	return name ? name : "include/config/auto.conf";
+	return getenv("KCONFIG_AUTOCONFIG");
 }
 
 static char *conf_expand_value(const char *in)
@@ -565,6 +563,9 @@
 	int use_timestamp = 1;
 	char *env;
 
+	if (!name)
+		name = conf_get_configname();
+
 	dirname[0] = 0;
 	if (name && name[0]) {
 		struct stat st;
@@ -671,6 +672,7 @@
 {
 	const char *name;
 	char path[PATH_MAX+1];
+	char *opwd, *dir, *_name;
 	char *s, *d, c;
 	struct symbol *sym;
 	struct stat sb;
@@ -679,8 +681,20 @@
 	name = conf_get_autoconfig_name();
 	conf_read_simple(name, S_DEF_AUTO);
 
-	if (chdir("include/config"))
-		return 1;
+	opwd = malloc(256);
+	_name = strdup(name);
+	if (opwd == NULL || _name == NULL)
+ 		return 1;
+	opwd = getcwd(opwd, 256);
+	dir = dirname(_name);
+	if (dir == NULL) {
+		res = 1;
+		goto err;
+	}
+	if (chdir(dir)) {
+		res = 1;
+		goto err;
+	}
 
 	res = 0;
 	for_all_symbols(i, sym) {
@@ -773,9 +787,11 @@
 		close(fd);
 	}
 out:
-	if (chdir("../.."))
-		return 1;
-
+	if (chdir(opwd))
+		res = 1;
+err:
+	free(opwd);
+	free(_name);
 	return res;
 }
 
@@ -787,25 +803,38 @@
 	FILE *out, *tristate, *out_h;
 	time_t now;
 	int i;
+	char dir[PATH_MAX+1], buf[PATH_MAX+1];
+	char *s;
+
+	strcpy(dir, conf_get_configname());
+	s = strrchr(dir, '/');
+	if (s)
+		s[1] = 0;
+	else
+		dir[0] = 0;
 
 	sym_clear_all_valid();
 
-	file_write_dep("include/config/auto.conf.cmd");
+	sprintf(buf, "%s.config.cmd", dir);
+	file_write_dep(buf);
 
 	if (conf_split_config())
 		return 1;
 
-	out = fopen(".tmpconfig", "w");
+	sprintf(buf, "%s.tmpconfig", dir);
+	out = fopen(buf, "w");
 	if (!out)
 		return 1;
 
-	tristate = fopen(".tmpconfig_tristate", "w");
+	sprintf(buf, "%s.tmpconfig_tristate", dir);
+	tristate = fopen(buf, "w");
 	if (!tristate) {
 		fclose(out);
 		return 1;
 	}
 
-	out_h = fopen(".tmpconfig.h", "w");
+	sprintf(buf, "%s.tmpconfig.h", dir);
+	out_h = fopen(buf, "w");
 	if (!out_h) {
 		fclose(out);
 		fclose(tristate);
@@ -885,19 +914,22 @@
 	name = getenv("KCONFIG_AUTOHEADER");
 	if (!name)
 		name = "include/generated/autoconf.h";
-	if (rename(".tmpconfig.h", name))
+	sprintf(buf, "%s.tmpconfig.h", dir);
+	if (rename(buf, name))
 		return 1;
 	name = getenv("KCONFIG_TRISTATE");
 	if (!name)
 		name = "include/config/tristate.conf";
-	if (rename(".tmpconfig_tristate", name))
+	sprintf(buf, "%s.tmpconfig_tristate", dir);
+	if (rename(buf, name))
 		return 1;
 	name = conf_get_autoconfig_name();
 	/*
 	 * This must be the last step, kbuild has a dependency on auto.conf
 	 * and this marks the successful completion of the previous steps.
 	 */
-	if (rename(".tmpconfig", name))
+	sprintf(buf, "%s.tmpconfig", dir);
+	if (rename(buf, name))
 		return 1;
 
 	return 0;
Index: config/util.c
===================================================================
--- config.orig/util.c
+++ config/util.c
@@ -147,6 +147,8 @@
 /* write a dependency file as used by kbuild to track dependencies */
 int file_write_dep(const char *name)
 {
+	char *str;
+	char buf[PATH_MAX+1], buf2[PATH_MAX+1], dir[PATH_MAX+1];
 	struct symbol *sym, *env_sym;
 	struct expr *e;
 	struct file *file;
@@ -154,7 +156,16 @@
 
 	if (!name)
 		name = ".kconfig.d";
-	out = fopen("..config.tmp", "w");
+
+	strcpy(dir, conf_get_configname());
+	str = strrchr(dir, '/');
+	if (str)
+		str[1] = 0;
+	else
+		dir[0] = 0;
+
+	sprintf(buf, "%s..config.tmp", dir);
+	out = fopen(buf, "w");
 	if (!out)
 		return 1;
 	fprintf(out, "deps_config := \\\n");
@@ -185,7 +196,8 @@
 
 	fprintf(out, "\n$(deps_config): ;\n");
 	fclose(out);
-	rename("..config.tmp", name);
+	sprintf(buf2, "%s%s", dir, name);
+	rename(buf, buf2);
 	return write_make_deps(NULL);
 }