diff options
author | Paul Mundt <lethal@linux-sh.org> | 2011-01-13 01:06:28 -0500 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2011-01-13 01:06:28 -0500 |
commit | f43dc23d5ea91fca257be02138a255f02d98e806 (patch) | |
tree | b29722f6e965316e90ac97abf79923ced250dc21 /scripts/basic | |
parent | f8e53553f452dcbf67cb89c8cba63a1cd6eb4cc0 (diff) | |
parent | 4162cf64973df51fc885825bc9ca4d055891c49f (diff) |
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux-2.6 into common/serial-rework
Conflicts:
arch/sh/kernel/cpu/sh2/setup-sh7619.c
arch/sh/kernel/cpu/sh2a/setup-mxg.c
arch/sh/kernel/cpu/sh2a/setup-sh7201.c
arch/sh/kernel/cpu/sh2a/setup-sh7203.c
arch/sh/kernel/cpu/sh2a/setup-sh7206.c
arch/sh/kernel/cpu/sh3/setup-sh7705.c
arch/sh/kernel/cpu/sh3/setup-sh770x.c
arch/sh/kernel/cpu/sh3/setup-sh7710.c
arch/sh/kernel/cpu/sh3/setup-sh7720.c
arch/sh/kernel/cpu/sh4/setup-sh4-202.c
arch/sh/kernel/cpu/sh4/setup-sh7750.c
arch/sh/kernel/cpu/sh4/setup-sh7760.c
arch/sh/kernel/cpu/sh4a/setup-sh7343.c
arch/sh/kernel/cpu/sh4a/setup-sh7366.c
arch/sh/kernel/cpu/sh4a/setup-sh7722.c
arch/sh/kernel/cpu/sh4a/setup-sh7723.c
arch/sh/kernel/cpu/sh4a/setup-sh7724.c
arch/sh/kernel/cpu/sh4a/setup-sh7763.c
arch/sh/kernel/cpu/sh4a/setup-sh7770.c
arch/sh/kernel/cpu/sh4a/setup-sh7780.c
arch/sh/kernel/cpu/sh4a/setup-sh7785.c
arch/sh/kernel/cpu/sh4a/setup-sh7786.c
arch/sh/kernel/cpu/sh4a/setup-shx3.c
arch/sh/kernel/cpu/sh5/setup-sh5.c
drivers/serial/sh-sci.c
drivers/serial/sh-sci.h
include/linux/serial_sci.h
Diffstat (limited to 'scripts/basic')
-rw-r--r-- | scripts/basic/Makefile | 2 | ||||
-rw-r--r-- | scripts/basic/docproc.c | 166 | ||||
-rw-r--r-- | scripts/basic/fixdep.c | 145 | ||||
-rw-r--r-- | scripts/basic/hash.c | 64 |
4 files changed, 229 insertions, 148 deletions
diff --git a/scripts/basic/Makefile b/scripts/basic/Makefile index 09559951df12..4c324a1f1e0e 100644 --- a/scripts/basic/Makefile +++ b/scripts/basic/Makefile | |||
@@ -9,7 +9,7 @@ | |||
9 | # fixdep: Used to generate dependency information during build process | 9 | # fixdep: Used to generate dependency information during build process |
10 | # docproc: Used in Documentation/DocBook | 10 | # docproc: Used in Documentation/DocBook |
11 | 11 | ||
12 | hostprogs-y := fixdep docproc hash | 12 | hostprogs-y := fixdep docproc |
13 | always := $(hostprogs-y) | 13 | always := $(hostprogs-y) |
14 | 14 | ||
15 | # fixdep is needed to compile other host programs | 15 | # fixdep is needed to compile other host programs |
diff --git a/scripts/basic/docproc.c b/scripts/basic/docproc.c index 99ca7a698687..98dec87974d0 100644 --- a/scripts/basic/docproc.c +++ b/scripts/basic/docproc.c | |||
@@ -34,12 +34,14 @@ | |||
34 | * | 34 | * |
35 | */ | 35 | */ |
36 | 36 | ||
37 | #define _GNU_SOURCE | ||
37 | #include <stdio.h> | 38 | #include <stdio.h> |
38 | #include <stdlib.h> | 39 | #include <stdlib.h> |
39 | #include <string.h> | 40 | #include <string.h> |
40 | #include <ctype.h> | 41 | #include <ctype.h> |
41 | #include <unistd.h> | 42 | #include <unistd.h> |
42 | #include <limits.h> | 43 | #include <limits.h> |
44 | #include <errno.h> | ||
43 | #include <sys/types.h> | 45 | #include <sys/types.h> |
44 | #include <sys/wait.h> | 46 | #include <sys/wait.h> |
45 | 47 | ||
@@ -54,6 +56,7 @@ typedef void FILEONLY(char * file); | |||
54 | FILEONLY *internalfunctions; | 56 | FILEONLY *internalfunctions; |
55 | FILEONLY *externalfunctions; | 57 | FILEONLY *externalfunctions; |
56 | FILEONLY *symbolsonly; | 58 | FILEONLY *symbolsonly; |
59 | FILEONLY *findall; | ||
57 | 60 | ||
58 | typedef void FILELINE(char * file, char * line); | 61 | typedef void FILELINE(char * file, char * line); |
59 | FILELINE * singlefunctions; | 62 | FILELINE * singlefunctions; |
@@ -65,13 +68,31 @@ FILELINE * docsection; | |||
65 | #define KERNELDOCPATH "scripts/" | 68 | #define KERNELDOCPATH "scripts/" |
66 | #define KERNELDOC "kernel-doc" | 69 | #define KERNELDOC "kernel-doc" |
67 | #define DOCBOOK "-docbook" | 70 | #define DOCBOOK "-docbook" |
71 | #define LIST "-list" | ||
68 | #define FUNCTION "-function" | 72 | #define FUNCTION "-function" |
69 | #define NOFUNCTION "-nofunction" | 73 | #define NOFUNCTION "-nofunction" |
70 | #define NODOCSECTIONS "-no-doc-sections" | 74 | #define NODOCSECTIONS "-no-doc-sections" |
71 | 75 | ||
72 | static char *srctree, *kernsrctree; | 76 | static char *srctree, *kernsrctree; |
73 | 77 | ||
74 | void usage (void) | 78 | static char **all_list = NULL; |
79 | static int all_list_len = 0; | ||
80 | |||
81 | static void consume_symbol(const char *sym) | ||
82 | { | ||
83 | int i; | ||
84 | |||
85 | for (i = 0; i < all_list_len; i++) { | ||
86 | if (!all_list[i]) | ||
87 | continue; | ||
88 | if (strcmp(sym, all_list[i])) | ||
89 | continue; | ||
90 | all_list[i] = NULL; | ||
91 | break; | ||
92 | } | ||
93 | } | ||
94 | |||
95 | static void usage (void) | ||
75 | { | 96 | { |
76 | fprintf(stderr, "Usage: docproc {doc|depend} file\n"); | 97 | fprintf(stderr, "Usage: docproc {doc|depend} file\n"); |
77 | fprintf(stderr, "Input is read from file.tmpl. Output is sent to stdout\n"); | 98 | fprintf(stderr, "Input is read from file.tmpl. Output is sent to stdout\n"); |
@@ -84,7 +105,7 @@ void usage (void) | |||
84 | /* | 105 | /* |
85 | * Execute kernel-doc with parameters given in svec | 106 | * Execute kernel-doc with parameters given in svec |
86 | */ | 107 | */ |
87 | void exec_kernel_doc(char **svec) | 108 | static void exec_kernel_doc(char **svec) |
88 | { | 109 | { |
89 | pid_t pid; | 110 | pid_t pid; |
90 | int ret; | 111 | int ret; |
@@ -129,7 +150,7 @@ struct symfile | |||
129 | struct symfile symfilelist[MAXFILES]; | 150 | struct symfile symfilelist[MAXFILES]; |
130 | int symfilecnt = 0; | 151 | int symfilecnt = 0; |
131 | 152 | ||
132 | void add_new_symbol(struct symfile *sym, char * symname) | 153 | static void add_new_symbol(struct symfile *sym, char * symname) |
133 | { | 154 | { |
134 | sym->symbollist = | 155 | sym->symbollist = |
135 | realloc(sym->symbollist, (sym->symbolcnt + 1) * sizeof(char *)); | 156 | realloc(sym->symbollist, (sym->symbolcnt + 1) * sizeof(char *)); |
@@ -137,14 +158,14 @@ void add_new_symbol(struct symfile *sym, char * symname) | |||
137 | } | 158 | } |
138 | 159 | ||
139 | /* Add a filename to the list */ | 160 | /* Add a filename to the list */ |
140 | struct symfile * add_new_file(char * filename) | 161 | static struct symfile * add_new_file(char * filename) |
141 | { | 162 | { |
142 | symfilelist[symfilecnt++].filename = strdup(filename); | 163 | symfilelist[symfilecnt++].filename = strdup(filename); |
143 | return &symfilelist[symfilecnt - 1]; | 164 | return &symfilelist[symfilecnt - 1]; |
144 | } | 165 | } |
145 | 166 | ||
146 | /* Check if file already are present in the list */ | 167 | /* Check if file already are present in the list */ |
147 | struct symfile * filename_exist(char * filename) | 168 | static struct symfile * filename_exist(char * filename) |
148 | { | 169 | { |
149 | int i; | 170 | int i; |
150 | for (i=0; i < symfilecnt; i++) | 171 | for (i=0; i < symfilecnt; i++) |
@@ -157,20 +178,20 @@ struct symfile * filename_exist(char * filename) | |||
157 | * List all files referenced within the template file. | 178 | * List all files referenced within the template file. |
158 | * Files are separated by tabs. | 179 | * Files are separated by tabs. |
159 | */ | 180 | */ |
160 | void adddep(char * file) { printf("\t%s", file); } | 181 | static void adddep(char * file) { printf("\t%s", file); } |
161 | void adddep2(char * file, char * line) { line = line; adddep(file); } | 182 | static void adddep2(char * file, char * line) { line = line; adddep(file); } |
162 | void noaction(char * line) { line = line; } | 183 | static void noaction(char * line) { line = line; } |
163 | void noaction2(char * file, char * line) { file = file; line = line; } | 184 | static void noaction2(char * file, char * line) { file = file; line = line; } |
164 | 185 | ||
165 | /* Echo the line without further action */ | 186 | /* Echo the line without further action */ |
166 | void printline(char * line) { printf("%s", line); } | 187 | static void printline(char * line) { printf("%s", line); } |
167 | 188 | ||
168 | /* | 189 | /* |
169 | * Find all symbols in filename that are exported with EXPORT_SYMBOL & | 190 | * Find all symbols in filename that are exported with EXPORT_SYMBOL & |
170 | * EXPORT_SYMBOL_GPL (& EXPORT_SYMBOL_GPL_FUTURE implicitly). | 191 | * EXPORT_SYMBOL_GPL (& EXPORT_SYMBOL_GPL_FUTURE implicitly). |
171 | * All symbols located are stored in symfilelist. | 192 | * All symbols located are stored in symfilelist. |
172 | */ | 193 | */ |
173 | void find_export_symbols(char * filename) | 194 | static void find_export_symbols(char * filename) |
174 | { | 195 | { |
175 | FILE * fp; | 196 | FILE * fp; |
176 | struct symfile *sym; | 197 | struct symfile *sym; |
@@ -227,7 +248,7 @@ void find_export_symbols(char * filename) | |||
227 | * intfunc uses -nofunction | 248 | * intfunc uses -nofunction |
228 | * extfunc uses -function | 249 | * extfunc uses -function |
229 | */ | 250 | */ |
230 | void docfunctions(char * filename, char * type) | 251 | static void docfunctions(char * filename, char * type) |
231 | { | 252 | { |
232 | int i,j; | 253 | int i,j; |
233 | int symcnt = 0; | 254 | int symcnt = 0; |
@@ -248,6 +269,7 @@ void docfunctions(char * filename, char * type) | |||
248 | struct symfile * sym = &symfilelist[i]; | 269 | struct symfile * sym = &symfilelist[i]; |
249 | for (j=0; j < sym->symbolcnt; j++) { | 270 | for (j=0; j < sym->symbolcnt; j++) { |
250 | vec[idx++] = type; | 271 | vec[idx++] = type; |
272 | consume_symbol(sym->symbollist[j].name); | ||
251 | vec[idx++] = sym->symbollist[j].name; | 273 | vec[idx++] = sym->symbollist[j].name; |
252 | } | 274 | } |
253 | } | 275 | } |
@@ -258,15 +280,15 @@ void docfunctions(char * filename, char * type) | |||
258 | fflush(stdout); | 280 | fflush(stdout); |
259 | free(vec); | 281 | free(vec); |
260 | } | 282 | } |
261 | void intfunc(char * filename) { docfunctions(filename, NOFUNCTION); } | 283 | static void intfunc(char * filename) { docfunctions(filename, NOFUNCTION); } |
262 | void extfunc(char * filename) { docfunctions(filename, FUNCTION); } | 284 | static void extfunc(char * filename) { docfunctions(filename, FUNCTION); } |
263 | 285 | ||
264 | /* | 286 | /* |
265 | * Document specific function(s) in a file. | 287 | * Document specific function(s) in a file. |
266 | * Call kernel-doc with the following parameters: | 288 | * Call kernel-doc with the following parameters: |
267 | * kernel-doc -docbook -function function1 [-function function2] | 289 | * kernel-doc -docbook -function function1 [-function function2] |
268 | */ | 290 | */ |
269 | void singfunc(char * filename, char * line) | 291 | static void singfunc(char * filename, char * line) |
270 | { | 292 | { |
271 | char *vec[200]; /* Enough for specific functions */ | 293 | char *vec[200]; /* Enough for specific functions */ |
272 | int i, idx = 0; | 294 | int i, idx = 0; |
@@ -287,6 +309,11 @@ void singfunc(char * filename, char * line) | |||
287 | vec[idx++] = &line[i]; | 309 | vec[idx++] = &line[i]; |
288 | } | 310 | } |
289 | } | 311 | } |
312 | for (i = 0; i < idx; i++) { | ||
313 | if (strcmp(vec[i], FUNCTION)) | ||
314 | continue; | ||
315 | consume_symbol(vec[i + 1]); | ||
316 | } | ||
290 | vec[idx++] = filename; | 317 | vec[idx++] = filename; |
291 | vec[idx] = NULL; | 318 | vec[idx] = NULL; |
292 | exec_kernel_doc(vec); | 319 | exec_kernel_doc(vec); |
@@ -297,7 +324,7 @@ void singfunc(char * filename, char * line) | |||
297 | * Call kernel-doc with the following parameters: | 324 | * Call kernel-doc with the following parameters: |
298 | * kernel-doc -docbook -function "doc section" filename | 325 | * kernel-doc -docbook -function "doc section" filename |
299 | */ | 326 | */ |
300 | void docsect(char *filename, char *line) | 327 | static void docsect(char *filename, char *line) |
301 | { | 328 | { |
302 | char *vec[6]; /* kerneldoc -docbook -function "section" file NULL */ | 329 | char *vec[6]; /* kerneldoc -docbook -function "section" file NULL */ |
303 | char *s; | 330 | char *s; |
@@ -306,6 +333,13 @@ void docsect(char *filename, char *line) | |||
306 | if (*s == '\n') | 333 | if (*s == '\n') |
307 | *s = '\0'; | 334 | *s = '\0'; |
308 | 335 | ||
336 | if (asprintf(&s, "DOC: %s", line) < 0) { | ||
337 | perror("asprintf"); | ||
338 | exit(1); | ||
339 | } | ||
340 | consume_symbol(s); | ||
341 | free(s); | ||
342 | |||
309 | vec[0] = KERNELDOC; | 343 | vec[0] = KERNELDOC; |
310 | vec[1] = DOCBOOK; | 344 | vec[1] = DOCBOOK; |
311 | vec[2] = FUNCTION; | 345 | vec[2] = FUNCTION; |
@@ -315,6 +349,84 @@ void docsect(char *filename, char *line) | |||
315 | exec_kernel_doc(vec); | 349 | exec_kernel_doc(vec); |
316 | } | 350 | } |
317 | 351 | ||
352 | static void find_all_symbols(char *filename) | ||
353 | { | ||
354 | char *vec[4]; /* kerneldoc -list file NULL */ | ||
355 | pid_t pid; | ||
356 | int ret, i, count, start; | ||
357 | char real_filename[PATH_MAX + 1]; | ||
358 | int pipefd[2]; | ||
359 | char *data, *str; | ||
360 | size_t data_len = 0; | ||
361 | |||
362 | vec[0] = KERNELDOC; | ||
363 | vec[1] = LIST; | ||
364 | vec[2] = filename; | ||
365 | vec[3] = NULL; | ||
366 | |||
367 | if (pipe(pipefd)) { | ||
368 | perror("pipe"); | ||
369 | exit(1); | ||
370 | } | ||
371 | |||
372 | switch (pid=fork()) { | ||
373 | case -1: | ||
374 | perror("fork"); | ||
375 | exit(1); | ||
376 | case 0: | ||
377 | close(pipefd[0]); | ||
378 | dup2(pipefd[1], 1); | ||
379 | memset(real_filename, 0, sizeof(real_filename)); | ||
380 | strncat(real_filename, kernsrctree, PATH_MAX); | ||
381 | strncat(real_filename, "/" KERNELDOCPATH KERNELDOC, | ||
382 | PATH_MAX - strlen(real_filename)); | ||
383 | execvp(real_filename, vec); | ||
384 | fprintf(stderr, "exec "); | ||
385 | perror(real_filename); | ||
386 | exit(1); | ||
387 | default: | ||
388 | close(pipefd[1]); | ||
389 | data = malloc(4096); | ||
390 | do { | ||
391 | while ((ret = read(pipefd[0], | ||
392 | data + data_len, | ||
393 | 4096)) > 0) { | ||
394 | data_len += ret; | ||
395 | data = realloc(data, data_len + 4096); | ||
396 | } | ||
397 | } while (ret == -EAGAIN); | ||
398 | if (ret != 0) { | ||
399 | perror("read"); | ||
400 | exit(1); | ||
401 | } | ||
402 | waitpid(pid, &ret ,0); | ||
403 | } | ||
404 | if (WIFEXITED(ret)) | ||
405 | exitstatus |= WEXITSTATUS(ret); | ||
406 | else | ||
407 | exitstatus = 0xff; | ||
408 | |||
409 | count = 0; | ||
410 | /* poor man's strtok, but with counting */ | ||
411 | for (i = 0; i < data_len; i++) { | ||
412 | if (data[i] == '\n') { | ||
413 | count++; | ||
414 | data[i] = '\0'; | ||
415 | } | ||
416 | } | ||
417 | start = all_list_len; | ||
418 | all_list_len += count; | ||
419 | all_list = realloc(all_list, sizeof(char *) * all_list_len); | ||
420 | str = data; | ||
421 | for (i = 0; i < data_len && start != all_list_len; i++) { | ||
422 | if (data[i] == '\0') { | ||
423 | all_list[start] = str; | ||
424 | str = data + i + 1; | ||
425 | start++; | ||
426 | } | ||
427 | } | ||
428 | } | ||
429 | |||
318 | /* | 430 | /* |
319 | * Parse file, calling action specific functions for: | 431 | * Parse file, calling action specific functions for: |
320 | * 1) Lines containing !E | 432 | * 1) Lines containing !E |
@@ -322,9 +434,10 @@ void docsect(char *filename, char *line) | |||
322 | * 3) Lines containing !D | 434 | * 3) Lines containing !D |
323 | * 4) Lines containing !F | 435 | * 4) Lines containing !F |
324 | * 5) Lines containing !P | 436 | * 5) Lines containing !P |
325 | * 6) Default lines - lines not matching the above | 437 | * 6) Lines containing !C |
438 | * 7) Default lines - lines not matching the above | ||
326 | */ | 439 | */ |
327 | void parse_file(FILE *infile) | 440 | static void parse_file(FILE *infile) |
328 | { | 441 | { |
329 | char line[MAXLINESZ]; | 442 | char line[MAXLINESZ]; |
330 | char * s; | 443 | char * s; |
@@ -365,6 +478,12 @@ void parse_file(FILE *infile) | |||
365 | s++; | 478 | s++; |
366 | docsection(line + 2, s); | 479 | docsection(line + 2, s); |
367 | break; | 480 | break; |
481 | case 'C': | ||
482 | while (*s && !isspace(*s)) s++; | ||
483 | *s = '\0'; | ||
484 | if (findall) | ||
485 | findall(line+2); | ||
486 | break; | ||
368 | default: | 487 | default: |
369 | defaultline(line); | 488 | defaultline(line); |
370 | } | 489 | } |
@@ -380,6 +499,7 @@ void parse_file(FILE *infile) | |||
380 | int main(int argc, char *argv[]) | 499 | int main(int argc, char *argv[]) |
381 | { | 500 | { |
382 | FILE * infile; | 501 | FILE * infile; |
502 | int i; | ||
383 | 503 | ||
384 | srctree = getenv("SRCTREE"); | 504 | srctree = getenv("SRCTREE"); |
385 | if (!srctree) | 505 | if (!srctree) |
@@ -415,6 +535,7 @@ int main(int argc, char *argv[]) | |||
415 | symbolsonly = find_export_symbols; | 535 | symbolsonly = find_export_symbols; |
416 | singlefunctions = noaction2; | 536 | singlefunctions = noaction2; |
417 | docsection = noaction2; | 537 | docsection = noaction2; |
538 | findall = find_all_symbols; | ||
418 | parse_file(infile); | 539 | parse_file(infile); |
419 | 540 | ||
420 | /* Rewind to start from beginning of file again */ | 541 | /* Rewind to start from beginning of file again */ |
@@ -425,8 +546,16 @@ int main(int argc, char *argv[]) | |||
425 | symbolsonly = printline; | 546 | symbolsonly = printline; |
426 | singlefunctions = singfunc; | 547 | singlefunctions = singfunc; |
427 | docsection = docsect; | 548 | docsection = docsect; |
549 | findall = NULL; | ||
428 | 550 | ||
429 | parse_file(infile); | 551 | parse_file(infile); |
552 | |||
553 | for (i = 0; i < all_list_len; i++) { | ||
554 | if (!all_list[i]) | ||
555 | continue; | ||
556 | fprintf(stderr, "Warning: didn't use docs for %s\n", | ||
557 | all_list[i]); | ||
558 | } | ||
430 | } | 559 | } |
431 | else if (strcmp("depend", argv[1]) == 0) | 560 | else if (strcmp("depend", argv[1]) == 0) |
432 | { | 561 | { |
@@ -439,6 +568,7 @@ int main(int argc, char *argv[]) | |||
439 | symbolsonly = adddep; | 568 | symbolsonly = adddep; |
440 | singlefunctions = adddep2; | 569 | singlefunctions = adddep2; |
441 | docsection = adddep2; | 570 | docsection = adddep2; |
571 | findall = adddep; | ||
442 | parse_file(infile); | 572 | parse_file(infile); |
443 | printf("\n"); | 573 | printf("\n"); |
444 | } | 574 | } |
diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 72c15205bb2b..c9a16abacab4 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c | |||
@@ -16,16 +16,15 @@ | |||
16 | * tells make when to remake a file. | 16 | * tells make when to remake a file. |
17 | * | 17 | * |
18 | * To use this list as-is however has the drawback that virtually | 18 | * To use this list as-is however has the drawback that virtually |
19 | * every file in the kernel includes <linux/config.h> which then again | 19 | * every file in the kernel includes autoconf.h. |
20 | * includes <linux/autoconf.h> | ||
21 | * | 20 | * |
22 | * If the user re-runs make *config, linux/autoconf.h will be | 21 | * If the user re-runs make *config, autoconf.h will be |
23 | * regenerated. make notices that and will rebuild every file which | 22 | * regenerated. make notices that and will rebuild every file which |
24 | * includes autoconf.h, i.e. basically all files. This is extremely | 23 | * includes autoconf.h, i.e. basically all files. This is extremely |
25 | * annoying if the user just changed CONFIG_HIS_DRIVER from n to m. | 24 | * annoying if the user just changed CONFIG_HIS_DRIVER from n to m. |
26 | * | 25 | * |
27 | * So we play the same trick that "mkdep" played before. We replace | 26 | * So we play the same trick that "mkdep" played before. We replace |
28 | * the dependency on linux/autoconf.h by a dependency on every config | 27 | * the dependency on autoconf.h by a dependency on every config |
29 | * option which is mentioned in any of the listed prequisites. | 28 | * option which is mentioned in any of the listed prequisites. |
30 | * | 29 | * |
31 | * kconfig populates a tree in include/config/ with an empty file | 30 | * kconfig populates a tree in include/config/ with an empty file |
@@ -74,7 +73,7 @@ | |||
74 | * cmd_<target> = <cmdline> | 73 | * cmd_<target> = <cmdline> |
75 | * | 74 | * |
76 | * and then basically copies the .<target>.d file to stdout, in the | 75 | * and then basically copies the .<target>.d file to stdout, in the |
77 | * process filtering out the dependency on linux/autoconf.h and adding | 76 | * process filtering out the dependency on autoconf.h and adding |
78 | * dependencies on include/config/my/option.h for every | 77 | * dependencies on include/config/my/option.h for every |
79 | * CONFIG_MY_OPTION encountered in any of the prequisites. | 78 | * CONFIG_MY_OPTION encountered in any of the prequisites. |
80 | * | 79 | * |
@@ -125,8 +124,7 @@ char *target; | |||
125 | char *depfile; | 124 | char *depfile; |
126 | char *cmdline; | 125 | char *cmdline; |
127 | 126 | ||
128 | void usage(void) | 127 | static void usage(void) |
129 | |||
130 | { | 128 | { |
131 | fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n"); | 129 | fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n"); |
132 | exit(1); | 130 | exit(1); |
@@ -135,43 +133,41 @@ void usage(void) | |||
135 | /* | 133 | /* |
136 | * Print out the commandline prefixed with cmd_<target filename> := | 134 | * Print out the commandline prefixed with cmd_<target filename> := |
137 | */ | 135 | */ |
138 | void print_cmdline(void) | 136 | static void print_cmdline(void) |
139 | { | 137 | { |
140 | printf("cmd_%s := %s\n\n", target, cmdline); | 138 | printf("cmd_%s := %s\n\n", target, cmdline); |
141 | } | 139 | } |
142 | 140 | ||
143 | char * str_config = NULL; | 141 | struct item { |
144 | int size_config = 0; | 142 | struct item *next; |
145 | int len_config = 0; | 143 | unsigned int len; |
144 | unsigned int hash; | ||
145 | char name[0]; | ||
146 | }; | ||
146 | 147 | ||
147 | /* | 148 | #define HASHSZ 256 |
148 | * Grow the configuration string to a desired length. | 149 | static struct item *hashtab[HASHSZ]; |
149 | * Usually the first growth is plenty. | ||
150 | */ | ||
151 | void grow_config(int len) | ||
152 | { | ||
153 | while (len_config + len > size_config) { | ||
154 | if (size_config == 0) | ||
155 | size_config = 2048; | ||
156 | str_config = realloc(str_config, size_config *= 2); | ||
157 | if (str_config == NULL) | ||
158 | { perror("fixdep:malloc"); exit(1); } | ||
159 | } | ||
160 | } | ||
161 | 150 | ||
151 | static unsigned int strhash(const char *str, unsigned int sz) | ||
152 | { | ||
153 | /* fnv32 hash */ | ||
154 | unsigned int i, hash = 2166136261U; | ||
162 | 155 | ||
156 | for (i = 0; i < sz; i++) | ||
157 | hash = (hash ^ str[i]) * 0x01000193; | ||
158 | return hash; | ||
159 | } | ||
163 | 160 | ||
164 | /* | 161 | /* |
165 | * Lookup a value in the configuration string. | 162 | * Lookup a value in the configuration string. |
166 | */ | 163 | */ |
167 | int is_defined_config(const char * name, int len) | 164 | static int is_defined_config(const char *name, int len, unsigned int hash) |
168 | { | 165 | { |
169 | const char * pconfig; | 166 | struct item *aux; |
170 | const char * plast = str_config + len_config - len; | 167 | |
171 | for ( pconfig = str_config + 1; pconfig < plast; pconfig++ ) { | 168 | for (aux = hashtab[hash % HASHSZ]; aux; aux = aux->next) { |
172 | if (pconfig[ -1] == '\n' | 169 | if (aux->hash == hash && aux->len == len && |
173 | && pconfig[len] == '\n' | 170 | memcmp(aux->name, name, len) == 0) |
174 | && !memcmp(pconfig, name, len)) | ||
175 | return 1; | 171 | return 1; |
176 | } | 172 | } |
177 | return 0; | 173 | return 0; |
@@ -180,54 +176,69 @@ int is_defined_config(const char * name, int len) | |||
180 | /* | 176 | /* |
181 | * Add a new value to the configuration string. | 177 | * Add a new value to the configuration string. |
182 | */ | 178 | */ |
183 | void define_config(const char * name, int len) | 179 | static void define_config(const char *name, int len, unsigned int hash) |
184 | { | 180 | { |
185 | grow_config(len + 1); | 181 | struct item *aux = malloc(sizeof(*aux) + len); |
186 | 182 | ||
187 | memcpy(str_config+len_config, name, len); | 183 | if (!aux) { |
188 | len_config += len; | 184 | perror("fixdep:malloc"); |
189 | 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; | ||
190 | } | 192 | } |
191 | 193 | ||
192 | /* | 194 | /* |
193 | * Clear the set of configuration strings. | 195 | * Clear the set of configuration strings. |
194 | */ | 196 | */ |
195 | void clear_config(void) | 197 | static void clear_config(void) |
196 | { | 198 | { |
197 | len_config = 0; | 199 | struct item *aux, *next; |
198 | 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 | } | ||
199 | } | 209 | } |
200 | 210 | ||
201 | /* | 211 | /* |
202 | * Record the use of a CONFIG_* word. | 212 | * Record the use of a CONFIG_* word. |
203 | */ | 213 | */ |
204 | void use_config(char *m, int slen) | 214 | static void use_config(const char *m, int slen) |
205 | { | 215 | { |
206 | char s[PATH_MAX]; | 216 | unsigned int hash = strhash(m, slen); |
207 | char *p; | 217 | int c, i; |
208 | 218 | ||
209 | if (is_defined_config(m, slen)) | 219 | if (is_defined_config(m, slen, hash)) |
210 | return; | 220 | return; |
211 | 221 | ||
212 | define_config(m, slen); | 222 | define_config(m, slen, hash); |
213 | 223 | ||
214 | memcpy(s, m, slen); s[slen] = 0; | 224 | printf(" $(wildcard include/config/"); |
215 | 225 | for (i = 0; i < slen; i++) { | |
216 | for (p = s; p < s + slen; p++) { | 226 | c = m[i]; |
217 | if (*p == '_') | 227 | if (c == '_') |
218 | *p = '/'; | 228 | c = '/'; |
219 | else | 229 | else |
220 | *p = tolower((int)*p); | 230 | c = tolower(c); |
231 | putchar(c); | ||
221 | } | 232 | } |
222 | printf(" $(wildcard include/config/%s.h) \\\n", s); | 233 | printf(".h) \\\n"); |
223 | } | 234 | } |
224 | 235 | ||
225 | void parse_config_file(char *map, size_t len) | 236 | static void parse_config_file(const char *map, size_t len) |
226 | { | 237 | { |
227 | int *end = (int *) (map + len); | 238 | const int *end = (const int *) (map + len); |
228 | /* start at +1, so that p can never be < map */ | 239 | /* start at +1, so that p can never be < map */ |
229 | int *m = (int *) map + 1; | 240 | const int *m = (const int *) map + 1; |
230 | char *p, *q; | 241 | const char *p, *q; |
231 | 242 | ||
232 | for (; m < end; m++) { | 243 | for (; m < end; m++) { |
233 | if (*m == INT_CONF) { p = (char *) m ; goto conf; } | 244 | if (*m == INT_CONF) { p = (char *) m ; goto conf; } |
@@ -256,7 +267,7 @@ void parse_config_file(char *map, size_t len) | |||
256 | } | 267 | } |
257 | 268 | ||
258 | /* test is s ends in sub */ | 269 | /* test is s ends in sub */ |
259 | int strrcmp(char *s, char *sub) | 270 | static int strrcmp(char *s, char *sub) |
260 | { | 271 | { |
261 | int slen = strlen(s); | 272 | int slen = strlen(s); |
262 | int sublen = strlen(sub); | 273 | int sublen = strlen(sub); |
@@ -267,7 +278,7 @@ int strrcmp(char *s, char *sub) | |||
267 | return memcmp(s + slen - sublen, sub, sublen); | 278 | return memcmp(s + slen - sublen, sub, sublen); |
268 | } | 279 | } |
269 | 280 | ||
270 | void do_config_file(char *filename) | 281 | static void do_config_file(const char *filename) |
271 | { | 282 | { |
272 | struct stat st; | 283 | struct stat st; |
273 | int fd; | 284 | int fd; |
@@ -275,7 +286,7 @@ void do_config_file(char *filename) | |||
275 | 286 | ||
276 | fd = open(filename, O_RDONLY); | 287 | fd = open(filename, O_RDONLY); |
277 | if (fd < 0) { | 288 | if (fd < 0) { |
278 | fprintf(stderr, "fixdep: "); | 289 | fprintf(stderr, "fixdep: error opening config file: "); |
279 | perror(filename); | 290 | perror(filename); |
280 | exit(2); | 291 | exit(2); |
281 | } | 292 | } |
@@ -298,7 +309,7 @@ void do_config_file(char *filename) | |||
298 | close(fd); | 309 | close(fd); |
299 | } | 310 | } |
300 | 311 | ||
301 | void parse_dep_file(void *map, size_t len) | 312 | static void parse_dep_file(void *map, size_t len) |
302 | { | 313 | { |
303 | char *m = map; | 314 | char *m = map; |
304 | char *end = m + len; | 315 | char *end = m + len; |
@@ -326,7 +337,7 @@ void parse_dep_file(void *map, size_t len) | |||
326 | p++; | 337 | p++; |
327 | } | 338 | } |
328 | memcpy(s, m, p-m); s[p-m] = 0; | 339 | memcpy(s, m, p-m); s[p-m] = 0; |
329 | if (strrcmp(s, "include/linux/autoconf.h") && | 340 | if (strrcmp(s, "include/generated/autoconf.h") && |
330 | strrcmp(s, "arch/um/include/uml-config.h") && | 341 | strrcmp(s, "arch/um/include/uml-config.h") && |
331 | strrcmp(s, ".ver")) { | 342 | strrcmp(s, ".ver")) { |
332 | printf(" %s \\\n", s); | 343 | printf(" %s \\\n", s); |
@@ -338,7 +349,7 @@ void parse_dep_file(void *map, size_t len) | |||
338 | printf("$(deps_%s):\n", target); | 349 | printf("$(deps_%s):\n", target); |
339 | } | 350 | } |
340 | 351 | ||
341 | void print_deps(void) | 352 | static void print_deps(void) |
342 | { | 353 | { |
343 | struct stat st; | 354 | struct stat st; |
344 | int fd; | 355 | int fd; |
@@ -346,11 +357,15 @@ void print_deps(void) | |||
346 | 357 | ||
347 | fd = open(depfile, O_RDONLY); | 358 | fd = open(depfile, O_RDONLY); |
348 | if (fd < 0) { | 359 | if (fd < 0) { |
349 | fprintf(stderr, "fixdep: "); | 360 | fprintf(stderr, "fixdep: error opening depfile: "); |
350 | perror(depfile); | 361 | perror(depfile); |
351 | exit(2); | 362 | exit(2); |
352 | } | 363 | } |
353 | fstat(fd, &st); | 364 | if (fstat(fd, &st) < 0) { |
365 | fprintf(stderr, "fixdep: error fstat'ing depfile: "); | ||
366 | perror(depfile); | ||
367 | exit(2); | ||
368 | } | ||
354 | if (st.st_size == 0) { | 369 | if (st.st_size == 0) { |
355 | fprintf(stderr,"fixdep: %s is empty\n",depfile); | 370 | fprintf(stderr,"fixdep: %s is empty\n",depfile); |
356 | close(fd); | 371 | close(fd); |
@@ -370,7 +385,7 @@ void print_deps(void) | |||
370 | close(fd); | 385 | close(fd); |
371 | } | 386 | } |
372 | 387 | ||
373 | void traps(void) | 388 | static void traps(void) |
374 | { | 389 | { |
375 | static char test[] __attribute__((aligned(sizeof(int)))) = "CONF"; | 390 | static char test[] __attribute__((aligned(sizeof(int)))) = "CONF"; |
376 | int *p = (int *)test; | 391 | int *p = (int *)test; |
diff --git a/scripts/basic/hash.c b/scripts/basic/hash.c deleted file mode 100644 index 3299ad7fc8c0..000000000000 --- a/scripts/basic/hash.c +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2008 Red Hat, Inc., Jason Baron <jbaron@redhat.com> | ||
3 | * | ||
4 | */ | ||
5 | |||
6 | #include <stdio.h> | ||
7 | #include <stdlib.h> | ||
8 | #include <string.h> | ||
9 | |||
10 | #define DYNAMIC_DEBUG_HASH_BITS 6 | ||
11 | |||
12 | static const char *program; | ||
13 | |||
14 | static void usage(void) | ||
15 | { | ||
16 | printf("Usage: %s <djb2|r5> <modname>\n", program); | ||
17 | exit(1); | ||
18 | } | ||
19 | |||
20 | /* djb2 hashing algorithm by Dan Bernstein. From: | ||
21 | * http://www.cse.yorku.ca/~oz/hash.html | ||
22 | */ | ||
23 | |||
24 | unsigned int djb2_hash(char *str) | ||
25 | { | ||
26 | unsigned long hash = 5381; | ||
27 | int c; | ||
28 | |||
29 | c = *str; | ||
30 | while (c) { | ||
31 | hash = ((hash << 5) + hash) + c; | ||
32 | c = *++str; | ||
33 | } | ||
34 | return (unsigned int)(hash & ((1 << DYNAMIC_DEBUG_HASH_BITS) - 1)); | ||
35 | } | ||
36 | |||
37 | unsigned int r5_hash(char *str) | ||
38 | { | ||
39 | unsigned long hash = 0; | ||
40 | int c; | ||
41 | |||
42 | c = *str; | ||
43 | while (c) { | ||
44 | hash = (hash + (c << 4) + (c >> 4)) * 11; | ||
45 | c = *++str; | ||
46 | } | ||
47 | return (unsigned int)(hash & ((1 << DYNAMIC_DEBUG_HASH_BITS) - 1)); | ||
48 | } | ||
49 | |||
50 | int main(int argc, char *argv[]) | ||
51 | { | ||
52 | program = argv[0]; | ||
53 | |||
54 | if (argc != 3) | ||
55 | usage(); | ||
56 | if (!strcmp(argv[1], "djb2")) | ||
57 | printf("%d\n", djb2_hash(argv[2])); | ||
58 | else if (!strcmp(argv[1], "r5")) | ||
59 | printf("%d\n", r5_hash(argv[2])); | ||
60 | else | ||
61 | usage(); | ||
62 | exit(0); | ||
63 | } | ||
64 | |||