package/fbterm: fix download site
[buildroot-gz.git] / support / kconfig / patches / 14-support-out-of-tree-config.patch
blobec3134f94e24d7bd0243b4d739362b3b2a56358c
1 ---
2 conf.c | 1
3 confdata.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++---------------
4 util.c | 16 +++++++++++++--
5 3 files changed, 61 insertions(+), 18 deletions(-)
7 Index: b/conf.c
8 ===================================================================
9 --- a/conf.c
10 +++ b/conf.c
11 @@ -558,7 +558,6 @@
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)) {
19 Index: b/confdata.c
20 ===================================================================
21 --- a/confdata.c
22 +++ b/confdata.c
23 @@ -13,6 +13,7 @@
24 #include <string.h>
25 #include <time.h>
26 #include <unistd.h>
27 +#include <libgen.h>
29 #include "lkc.h"
31 @@ -70,9 +71,7 @@
33 const char *conf_get_autoconfig_name(void)
35 - char *name = getenv("KCONFIG_AUTOCONFIG");
37 - return name ? name : "include/config/auto.conf";
38 + return getenv("KCONFIG_AUTOCONFIG");
41 static char *conf_expand_value(const char *in)
42 @@ -742,6 +741,9 @@
43 char dirname[PATH_MAX+1], tmpname[PATH_MAX+1], newname[PATH_MAX+1];
44 char *env;
46 + if (!name)
47 + name = conf_get_configname();
49 dirname[0] = 0;
50 if (name && name[0]) {
51 struct stat st;
52 @@ -836,6 +838,7 @@
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 @@ -844,8 +847,20 @@
61 name = conf_get_autoconfig_name();
62 conf_read_simple(name, S_DEF_AUTO);
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 + }
81 res = 0;
82 for_all_symbols(i, sym) {
83 @@ -938,9 +953,11 @@
84 close(fd);
86 out:
87 - if (chdir("../.."))
88 - return 1;
90 + if (chdir(opwd))
91 + res = 1;
92 +err:
93 + free(opwd);
94 + free(_name);
95 return res;
98 @@ -950,25 +967,38 @@
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;
105 + strcpy(dir, conf_get_configname());
106 + s = strrchr(dir, '/');
107 + if (s)
108 + s[1] = 0;
109 + else
110 + dir[0] = 0;
112 sym_clear_all_valid();
114 - file_write_dep("include/config/auto.conf.cmd");
115 + sprintf(buf, "%s.config.cmd", dir);
116 + file_write_dep(buf);
118 if (conf_split_config())
119 return 1;
121 - out = fopen(".tmpconfig", "w");
122 + sprintf(buf, "%s.tmpconfig", dir);
123 + out = fopen(buf, "w");
124 if (!out)
125 return 1;
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;
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 @@ -1000,19 +1030,22 @@
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();
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.
161 - if (rename(".tmpconfig", name))
162 + sprintf(buf, "%s.tmpconfig", dir);
163 + if (rename(buf, name))
164 return 1;
166 return 0;
167 Index: b/util.c
168 ===================================================================
169 --- a/util.c
170 +++ b/util.c
171 @@ -34,6 +34,8 @@
172 /* write a dependency file as used by kbuild to track dependencies */
173 int file_write_dep(const char *name)
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 @@
182 if (!name)
183 name = ".kconfig.d";
184 - out = fopen("..config.tmp", "w");
186 + strcpy(dir, conf_get_configname());
187 + str = strrchr(dir, '/');
188 + if (str)
189 + str[1] = 0;
190 + else
191 + dir[0] = 0;
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 @@
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;