xref: /OK3568_Linux_fs/buildroot/support/kconfig/patches/14-support-out-of-tree-config.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1---
2 conf.c     |    1
3 confdata.c |   62 ++++++++++++++++++++++++++++++++++++++++++++++---------------
4 util.c     |   16 +++++++++++++--
5 3 files changed, 61 insertions(+), 18 deletions(-)
6
7Index: kconfig/conf.c
8===================================================================
9--- kconfig.orig/conf.c
10+++ kconfig/conf.c
11@@ -565,7 +565,6 @@ int main(int ac, char **av)
12 	}
13 	name = av[optind];
14 	conf_parse(name);
15-	//zconfdump(stdout);
16 	if (sync_kconfig) {
17 		name = conf_get_configname();
18 		if (stat(name, &tmpstat)) {
19Index: kconfig/confdata.c
20===================================================================
21--- kconfig.orig/confdata.c
22+++ kconfig/confdata.c
23@@ -13,6 +13,7 @@
24 #include <string.h>
25 #include <time.h>
26 #include <unistd.h>
27+#include <libgen.h>
28
29 #include "lkc.h"
30
31@@ -76,9 +77,7 @@ const char *conf_get_configname(void)
32
33 const char *conf_get_autoconfig_name(void)
34 {
35-	char *name = getenv("KCONFIG_AUTOCONFIG");
36-
37-	return name ? name : "include/config/auto.conf";
38+	return getenv("KCONFIG_AUTOCONFIG");
39 }
40
41 static char *conf_expand_value(const char *in)
42@@ -748,6 +747,9 @@ int conf_write(const char *name)
43 	char dirname[PATH_MAX+1], tmpname[PATH_MAX+1], newname[PATH_MAX+1];
44 	char *env;
45
46+	if (!name)
47+		name = conf_get_configname();
48+
49 	dirname[0] = 0;
50 	if (name && name[0]) {
51 		struct stat st;
52@@ -842,6 +844,7 @@ static int conf_split_config(void)
53 {
54 	const char *name;
55 	char path[PATH_MAX+1];
56+	char *opwd, *dir, *_name;
57 	char *s, *d, c;
58 	struct symbol *sym;
59 	struct stat sb;
60@@ -851,8 +854,20 @@ static int conf_split_config(void)
61 	conf_read_simple(name, S_DEF_AUTO);
62 	sym_calc_value(modules_sym);
63
64-	if (chdir("include/config"))
65-		return 1;
66+	opwd = malloc(256);
67+	_name = strdup(name);
68+	if (opwd == NULL || _name == NULL)
69+ 		return 1;
70+	opwd = getcwd(opwd, 256);
71+	dir = dirname(_name);
72+	if (dir == NULL) {
73+		res = 1;
74+		goto err;
75+	}
76+	if (chdir(dir)) {
77+		res = 1;
78+		goto err;
79+	}
80
81 	res = 0;
82 	for_all_symbols(i, sym) {
83@@ -945,9 +960,11 @@ static int conf_split_config(void)
84 		close(fd);
85 	}
86 out:
87-	if (chdir("../.."))
88-		return 1;
89-
90+	if (chdir(opwd))
91+		res = 1;
92+err:
93+	free(opwd);
94+	free(_name);
95 	return res;
96 }
97
98@@ -957,25 +974,38 @@ int conf_write_autoconf(void)
99 	const char *name;
100 	FILE *out, *tristate, *out_h;
101 	int i;
102+	char dir[PATH_MAX+1], buf[PATH_MAX+1];
103+	char *s;
104+
105+	strcpy(dir, conf_get_configname());
106+	s = strrchr(dir, '/');
107+	if (s)
108+		s[1] = 0;
109+	else
110+		dir[0] = 0;
111
112 	sym_clear_all_valid();
113
114-	file_write_dep("include/config/auto.conf.cmd");
115+	sprintf(buf, "%s.config.cmd", dir);
116+	file_write_dep(buf);
117
118 	if (conf_split_config())
119 		return 1;
120
121-	out = fopen(".tmpconfig", "w");
122+	sprintf(buf, "%s.tmpconfig", dir);
123+	out = fopen(buf, "w");
124 	if (!out)
125 		return 1;
126
127-	tristate = fopen(".tmpconfig_tristate", "w");
128+	sprintf(buf, "%s.tmpconfig_tristate", dir);
129+	tristate = fopen(buf, "w");
130 	if (!tristate) {
131 		fclose(out);
132 		return 1;
133 	}
134
135-	out_h = fopen(".tmpconfig.h", "w");
136+	sprintf(buf, "%s.tmpconfig.h", dir);
137+	out_h = fopen(buf, "w");
138 	if (!out_h) {
139 		fclose(out);
140 		fclose(tristate);
141@@ -1007,19 +1037,22 @@ int conf_write_autoconf(void)
142 	name = getenv("KCONFIG_AUTOHEADER");
143 	if (!name)
144 		name = "include/generated/autoconf.h";
145-	if (rename(".tmpconfig.h", name))
146+	sprintf(buf, "%s.tmpconfig.h", dir);
147+	if (rename(buf, name))
148 		return 1;
149 	name = getenv("KCONFIG_TRISTATE");
150 	if (!name)
151 		name = "include/config/tristate.conf";
152-	if (rename(".tmpconfig_tristate", name))
153+	sprintf(buf, "%s.tmpconfig_tristate", dir);
154+	if (rename(buf, name))
155 		return 1;
156 	name = conf_get_autoconfig_name();
157 	/*
158 	 * This must be the last step, kbuild has a dependency on auto.conf
159 	 * and this marks the successful completion of the previous steps.
160 	 */
161-	if (rename(".tmpconfig", name))
162+	sprintf(buf, "%s.tmpconfig", dir);
163+	if (rename(buf, name))
164 		return 1;
165
166 	return 0;
167Index: kconfig/util.c
168===================================================================
169--- kconfig.orig/util.c
170+++ kconfig/util.c
171@@ -34,6 +34,8 @@ struct file *file_lookup(const char *nam
172 /* write a dependency file as used by kbuild to track dependencies */
173 int file_write_dep(const char *name)
174 {
175+	char *str;
176+	char buf[PATH_MAX+1], buf2[PATH_MAX+1], dir[PATH_MAX+1];
177 	struct symbol *sym, *env_sym;
178 	struct expr *e;
179 	struct file *file;
180@@ -41,7 +43,16 @@ int file_write_dep(const char *name)
181
182 	if (!name)
183 		name = ".kconfig.d";
184-	out = fopen("..config.tmp", "w");
185+
186+	strcpy(dir, conf_get_configname());
187+	str = strrchr(dir, '/');
188+	if (str)
189+		str[1] = 0;
190+	else
191+		dir[0] = 0;
192+
193+	sprintf(buf, "%s..config.tmp", dir);
194+	out = fopen(buf, "w");
195 	if (!out)
196 		return 1;
197 	fprintf(out, "deps_config := \\\n");
198@@ -72,7 +83,8 @@ int file_write_dep(const char *name)
199
200 	fprintf(out, "\n$(deps_config): ;\n");
201 	fclose(out);
202-	rename("..config.tmp", name);
203+	sprintf(buf2, "%s%s", dir, name);
204+	rename(buf, buf2);
205 	return 0;
206 }
207
208