diff options
author | James Morris <jmorris@namei.org> | 2011-03-07 18:55:06 -0500 |
---|---|---|
committer | James Morris <jmorris@namei.org> | 2011-03-07 18:55:06 -0500 |
commit | 1cc26bada9f6807814806db2f0d78792eecdac71 (patch) | |
tree | 5509b5139db04af6c13db0a580c84116a4a54039 /scripts/basic | |
parent | eae61f3c829439f8f9121b5cd48a14be04df451f (diff) | |
parent | 214d93b02c4fe93638ad268613c9702a81ed9192 (diff) |
Merge branch 'master'; commit 'v2.6.38-rc7' into next
Diffstat (limited to 'scripts/basic')
-rw-r--r-- | scripts/basic/fixdep.c | 131 |
1 files changed, 79 insertions, 52 deletions
diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index ea26b23de082..6c94c6ce2925 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c | |||
@@ -138,38 +138,36 @@ static void print_cmdline(void) | |||
138 | printf("cmd_%s := %s\n\n", target, cmdline); | 138 | printf("cmd_%s := %s\n\n", target, cmdline); |
139 | } | 139 | } |
140 | 140 | ||
141 | char * str_config = NULL; | 141 | struct item { |
142 | int size_config = 0; | 142 | struct item *next; |
143 | int len_config = 0; | 143 | unsigned int len; |
144 | unsigned int hash; | ||
145 | char name[0]; | ||
146 | }; | ||
144 | 147 | ||
145 | /* | 148 | #define HASHSZ 256 |
146 | * Grow the configuration string to a desired length. | 149 | static struct item *hashtab[HASHSZ]; |
147 | * Usually the first growth is plenty. | ||
148 | */ | ||
149 | static void grow_config(int len) | ||
150 | { | ||
151 | while (len_config + len > size_config) { | ||
152 | if (size_config == 0) | ||
153 | size_config = 2048; | ||
154 | str_config = realloc(str_config, size_config *= 2); | ||
155 | if (str_config == NULL) | ||
156 | { perror("fixdep:malloc"); exit(1); } | ||
157 | } | ||
158 | } | ||
159 | 150 | ||
151 | static unsigned int strhash(const char *str, unsigned int sz) | ||
152 | { | ||
153 | /* fnv32 hash */ | ||
154 | unsigned int i, hash = 2166136261U; | ||
160 | 155 | ||
156 | for (i = 0; i < sz; i++) | ||
157 | hash = (hash ^ str[i]) * 0x01000193; | ||
158 | return hash; | ||
159 | } | ||
161 | 160 | ||
162 | /* | 161 | /* |
163 | * Lookup a value in the configuration string. | 162 | * Lookup a value in the configuration string. |
164 | */ | 163 | */ |
165 | static int is_defined_config(const char * name, int len) | 164 | static int is_defined_config(const char *name, int len, unsigned int hash) |
166 | { | 165 | { |
167 | const char * pconfig; | 166 | struct item *aux; |
168 | const char * plast = str_config + len_config - len; | 167 | |
169 | for ( pconfig = str_config + 1; pconfig < plast; pconfig++ ) { | 168 | for (aux = hashtab[hash % HASHSZ]; aux; aux = aux->next) { |
170 | if (pconfig[ -1] == '\n' | 169 | if (aux->hash == hash && aux->len == len && |
171 | && pconfig[len] == '\n' | 170 | memcmp(aux->name, name, len) == 0) |
172 | && !memcmp(pconfig, name, len)) | ||
173 | return 1; | 171 | return 1; |
174 | } | 172 | } |
175 | return 0; | 173 | return 0; |
@@ -178,13 +176,19 @@ static int is_defined_config(const char * name, int len) | |||
178 | /* | 176 | /* |
179 | * Add a new value to the configuration string. | 177 | * Add a new value to the configuration string. |
180 | */ | 178 | */ |
181 | static void define_config(const char * name, int len) | 179 | static void define_config(const char *name, int len, unsigned int hash) |
182 | { | 180 | { |
183 | grow_config(len + 1); | 181 | struct item *aux = malloc(sizeof(*aux) + len); |
184 | 182 | ||
185 | memcpy(str_config+len_config, name, len); | 183 | if (!aux) { |
186 | len_config += len; | 184 | perror("fixdep:malloc"); |
187 | str_config[len_config++] = '\n'; | 185 | exit(1); |
186 | } | ||
187 | memcpy(aux->name, name, len); | ||
188 | aux->len = len; | ||
189 | aux->hash = hash; | ||
190 | aux->next = hashtab[hash % HASHSZ]; | ||
191 | hashtab[hash % HASHSZ] = aux; | ||
188 | } | 192 | } |
189 | 193 | ||
190 | /* | 194 | /* |
@@ -192,40 +196,49 @@ static void define_config(const char * name, int len) | |||
192 | */ | 196 | */ |
193 | static void clear_config(void) | 197 | static void clear_config(void) |
194 | { | 198 | { |
195 | len_config = 0; | 199 | struct item *aux, *next; |
196 | define_config("", 0); | 200 | unsigned int i; |
201 | |||
202 | for (i = 0; i < HASHSZ; i++) { | ||
203 | for (aux = hashtab[i]; aux; aux = next) { | ||
204 | next = aux->next; | ||
205 | free(aux); | ||
206 | } | ||
207 | hashtab[i] = NULL; | ||
208 | } | ||
197 | } | 209 | } |
198 | 210 | ||
199 | /* | 211 | /* |
200 | * Record the use of a CONFIG_* word. | 212 | * Record the use of a CONFIG_* word. |
201 | */ | 213 | */ |
202 | static void use_config(char *m, int slen) | 214 | static void use_config(const char *m, int slen) |
203 | { | 215 | { |
204 | char s[PATH_MAX]; | 216 | unsigned int hash = strhash(m, slen); |
205 | char *p; | 217 | int c, i; |
206 | 218 | ||
207 | if (is_defined_config(m, slen)) | 219 | if (is_defined_config(m, slen, hash)) |
208 | return; | 220 | return; |
209 | 221 | ||
210 | define_config(m, slen); | 222 | define_config(m, slen, hash); |
211 | 223 | ||
212 | memcpy(s, m, slen); s[slen] = 0; | 224 | printf(" $(wildcard include/config/"); |
213 | 225 | for (i = 0; i < slen; i++) { | |
214 | for (p = s; p < s + slen; p++) { | 226 | c = m[i]; |
215 | if (*p == '_') | 227 | if (c == '_') |
216 | *p = '/'; | 228 | c = '/'; |
217 | else | 229 | else |
218 | *p = tolower((int)*p); | 230 | c = tolower(c); |
231 | putchar(c); | ||
219 | } | 232 | } |
220 | printf(" $(wildcard include/config/%s.h) \\\n", s); | 233 | printf(".h) \\\n"); |
221 | } | 234 | } |
222 | 235 | ||
223 | static void parse_config_file(char *map, size_t len) | 236 | static void parse_config_file(const char *map, size_t len) |
224 | { | 237 | { |
225 | int *end = (int *) (map + len); | 238 | const int *end = (const int *) (map + len); |
226 | /* start at +1, so that p can never be < map */ | 239 | /* start at +1, so that p can never be < map */ |
227 | int *m = (int *) map + 1; | 240 | const int *m = (const int *) map + 1; |
228 | char *p, *q; | 241 | const char *p, *q; |
229 | 242 | ||
230 | for (; m < end; m++) { | 243 | for (; m < end; m++) { |
231 | if (*m == INT_CONF) { p = (char *) m ; goto conf; } | 244 | if (*m == INT_CONF) { p = (char *) m ; goto conf; } |
@@ -265,7 +278,7 @@ static int strrcmp(char *s, char *sub) | |||
265 | return memcmp(s + slen - sublen, sub, sublen); | 278 | return memcmp(s + slen - sublen, sub, sublen); |
266 | } | 279 | } |
267 | 280 | ||
268 | static void do_config_file(char *filename) | 281 | static void do_config_file(const char *filename) |
269 | { | 282 | { |
270 | struct stat st; | 283 | struct stat st; |
271 | int fd; | 284 | int fd; |
@@ -273,7 +286,7 @@ static void do_config_file(char *filename) | |||
273 | 286 | ||
274 | fd = open(filename, O_RDONLY); | 287 | fd = open(filename, O_RDONLY); |
275 | if (fd < 0) { | 288 | if (fd < 0) { |
276 | fprintf(stderr, "fixdep: "); | 289 | fprintf(stderr, "fixdep: error opening config file: "); |
277 | perror(filename); | 290 | perror(filename); |
278 | exit(2); | 291 | exit(2); |
279 | } | 292 | } |
@@ -302,6 +315,7 @@ static void parse_dep_file(void *map, size_t len) | |||
302 | char *end = m + len; | 315 | char *end = m + len; |
303 | char *p; | 316 | char *p; |
304 | char s[PATH_MAX]; | 317 | char s[PATH_MAX]; |
318 | int first; | ||
305 | 319 | ||
306 | p = strchr(m, ':'); | 320 | p = strchr(m, ':'); |
307 | if (!p) { | 321 | if (!p) { |
@@ -314,6 +328,7 @@ static void parse_dep_file(void *map, size_t len) | |||
314 | 328 | ||
315 | clear_config(); | 329 | clear_config(); |
316 | 330 | ||
331 | first = 1; | ||
317 | while (m < end) { | 332 | while (m < end) { |
318 | while (m < end && (*m == ' ' || *m == '\\' || *m == '\n')) | 333 | while (m < end && (*m == ' ' || *m == '\\' || *m == '\n')) |
319 | m++; | 334 | m++; |
@@ -327,9 +342,17 @@ static void parse_dep_file(void *map, size_t len) | |||
327 | if (strrcmp(s, "include/generated/autoconf.h") && | 342 | if (strrcmp(s, "include/generated/autoconf.h") && |
328 | strrcmp(s, "arch/um/include/uml-config.h") && | 343 | strrcmp(s, "arch/um/include/uml-config.h") && |
329 | strrcmp(s, ".ver")) { | 344 | strrcmp(s, ".ver")) { |
330 | printf(" %s \\\n", s); | 345 | /* |
346 | * Do not output the first dependency (the | ||
347 | * source file), so that kbuild is not confused | ||
348 | * if a .c file is rewritten into .S or vice | ||
349 | * versa. | ||
350 | */ | ||
351 | if (!first) | ||
352 | printf(" %s \\\n", s); | ||
331 | do_config_file(s); | 353 | do_config_file(s); |
332 | } | 354 | } |
355 | first = 0; | ||
333 | m = p + 1; | 356 | m = p + 1; |
334 | } | 357 | } |
335 | printf("\n%s: $(deps_%s)\n\n", target, target); | 358 | printf("\n%s: $(deps_%s)\n\n", target, target); |
@@ -344,11 +367,15 @@ static void print_deps(void) | |||
344 | 367 | ||
345 | fd = open(depfile, O_RDONLY); | 368 | fd = open(depfile, O_RDONLY); |
346 | if (fd < 0) { | 369 | if (fd < 0) { |
347 | fprintf(stderr, "fixdep: "); | 370 | fprintf(stderr, "fixdep: error opening depfile: "); |
348 | perror(depfile); | 371 | perror(depfile); |
349 | exit(2); | 372 | exit(2); |
350 | } | 373 | } |
351 | fstat(fd, &st); | 374 | if (fstat(fd, &st) < 0) { |
375 | fprintf(stderr, "fixdep: error fstat'ing depfile: "); | ||
376 | perror(depfile); | ||
377 | exit(2); | ||
378 | } | ||
352 | if (st.st_size == 0) { | 379 | if (st.st_size == 0) { |
353 | fprintf(stderr,"fixdep: %s is empty\n",depfile); | 380 | fprintf(stderr,"fixdep: %s is empty\n",depfile); |
354 | close(fd); | 381 | close(fd); |