aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/basic
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /scripts/basic
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'scripts/basic')
-rw-r--r--scripts/basic/.gitignore2
-rw-r--r--scripts/basic/Makefile3
-rw-r--r--scripts/basic/docproc.c580
-rw-r--r--scripts/basic/fixdep.c140
-rw-r--r--scripts/basic/hash.c64
5 files changed, 88 insertions, 701 deletions
diff --git a/scripts/basic/.gitignore b/scripts/basic/.gitignore
index bf8b199ec598..a776371a3502 100644
--- a/scripts/basic/.gitignore
+++ b/scripts/basic/.gitignore
@@ -1,3 +1 @@
1hash
2fixdep fixdep
3docproc
diff --git a/scripts/basic/Makefile b/scripts/basic/Makefile
index 09559951df12..4fcef87bb875 100644
--- a/scripts/basic/Makefile
+++ b/scripts/basic/Makefile
@@ -7,9 +7,8 @@
7# .config is included by main Makefile. 7# .config is included by main Makefile.
8# --------------------------------------------------------------------------- 8# ---------------------------------------------------------------------------
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
11 10
12hostprogs-y := fixdep docproc hash 11hostprogs-y := fixdep
13always := $(hostprogs-y) 12always := $(hostprogs-y)
14 13
15# fixdep is needed to compile other host programs 14# fixdep is needed to compile other host programs
diff --git a/scripts/basic/docproc.c b/scripts/basic/docproc.c
deleted file mode 100644
index fc3b18d844af..000000000000
--- a/scripts/basic/docproc.c
+++ /dev/null
@@ -1,580 +0,0 @@
1/*
2 * docproc is a simple preprocessor for the template files
3 * used as placeholders for the kernel internal documentation.
4 * docproc is used for documentation-frontend and
5 * dependency-generator.
6 * The two usages have in common that they require
7 * some knowledge of the .tmpl syntax, therefore they
8 * are kept together.
9 *
10 * documentation-frontend
11 * Scans the template file and call kernel-doc for
12 * all occurrences of ![EIF]file
13 * Beforehand each referenced file is scanned for
14 * any symbols that are exported via these macros:
15 * EXPORT_SYMBOL(), EXPORT_SYMBOL_GPL(), &
16 * EXPORT_SYMBOL_GPL_FUTURE()
17 * This is used to create proper -function and
18 * -nofunction arguments in calls to kernel-doc.
19 * Usage: docproc doc file.tmpl
20 *
21 * dependency-generator:
22 * Scans the template file and list all files
23 * referenced in a format recognized by make.
24 * Usage: docproc depend file.tmpl
25 * Writes dependency information to stdout
26 * in the following format:
27 * file.tmpl src.c src2.c
28 * The filenames are obtained from the following constructs:
29 * !Efilename
30 * !Ifilename
31 * !Dfilename
32 * !Ffilename
33 * !Pfilename
34 *
35 */
36
37#define _GNU_SOURCE
38#include <stdio.h>
39#include <stdlib.h>
40#include <string.h>
41#include <ctype.h>
42#include <unistd.h>
43#include <limits.h>
44#include <errno.h>
45#include <sys/types.h>
46#include <sys/wait.h>
47
48/* exitstatus is used to keep track of any failing calls to kernel-doc,
49 * but execution continues. */
50int exitstatus = 0;
51
52typedef void DFL(char *);
53DFL *defaultline;
54
55typedef void FILEONLY(char * file);
56FILEONLY *internalfunctions;
57FILEONLY *externalfunctions;
58FILEONLY *symbolsonly;
59FILEONLY *findall;
60
61typedef void FILELINE(char * file, char * line);
62FILELINE * singlefunctions;
63FILELINE * entity_system;
64FILELINE * docsection;
65
66#define MAXLINESZ 2048
67#define MAXFILES 250
68#define KERNELDOCPATH "scripts/"
69#define KERNELDOC "kernel-doc"
70#define DOCBOOK "-docbook"
71#define LIST "-list"
72#define FUNCTION "-function"
73#define NOFUNCTION "-nofunction"
74#define NODOCSECTIONS "-no-doc-sections"
75
76static char *srctree, *kernsrctree;
77
78static char **all_list = NULL;
79static int all_list_len = 0;
80
81static 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
95static void usage (void)
96{
97 fprintf(stderr, "Usage: docproc {doc|depend} file\n");
98 fprintf(stderr, "Input is read from file.tmpl. Output is sent to stdout\n");
99 fprintf(stderr, "doc: frontend when generating kernel documentation\n");
100 fprintf(stderr, "depend: generate list of files referenced within file\n");
101 fprintf(stderr, "Environment variable SRCTREE: absolute path to sources.\n");
102 fprintf(stderr, " KBUILD_SRC: absolute path to kernel source tree.\n");
103}
104
105/*
106 * Execute kernel-doc with parameters given in svec
107 */
108static void exec_kernel_doc(char **svec)
109{
110 pid_t pid;
111 int ret;
112 char real_filename[PATH_MAX + 1];
113 /* Make sure output generated so far are flushed */
114 fflush(stdout);
115 switch (pid=fork()) {
116 case -1:
117 perror("fork");
118 exit(1);
119 case 0:
120 memset(real_filename, 0, sizeof(real_filename));
121 strncat(real_filename, kernsrctree, PATH_MAX);
122 strncat(real_filename, "/" KERNELDOCPATH KERNELDOC,
123 PATH_MAX - strlen(real_filename));
124 execvp(real_filename, svec);
125 fprintf(stderr, "exec ");
126 perror(real_filename);
127 exit(1);
128 default:
129 waitpid(pid, &ret ,0);
130 }
131 if (WIFEXITED(ret))
132 exitstatus |= WEXITSTATUS(ret);
133 else
134 exitstatus = 0xff;
135}
136
137/* Types used to create list of all exported symbols in a number of files */
138struct symbols
139{
140 char *name;
141};
142
143struct symfile
144{
145 char *filename;
146 struct symbols *symbollist;
147 int symbolcnt;
148};
149
150struct symfile symfilelist[MAXFILES];
151int symfilecnt = 0;
152
153static void add_new_symbol(struct symfile *sym, char * symname)
154{
155 sym->symbollist =
156 realloc(sym->symbollist, (sym->symbolcnt + 1) * sizeof(char *));
157 sym->symbollist[sym->symbolcnt++].name = strdup(symname);
158}
159
160/* Add a filename to the list */
161static struct symfile * add_new_file(char * filename)
162{
163 symfilelist[symfilecnt++].filename = strdup(filename);
164 return &symfilelist[symfilecnt - 1];
165}
166
167/* Check if file already are present in the list */
168static struct symfile * filename_exist(char * filename)
169{
170 int i;
171 for (i=0; i < symfilecnt; i++)
172 if (strcmp(symfilelist[i].filename, filename) == 0)
173 return &symfilelist[i];
174 return NULL;
175}
176
177/*
178 * List all files referenced within the template file.
179 * Files are separated by tabs.
180 */
181static void adddep(char * file) { printf("\t%s", file); }
182static void adddep2(char * file, char * line) { line = line; adddep(file); }
183static void noaction(char * line) { line = line; }
184static void noaction2(char * file, char * line) { file = file; line = line; }
185
186/* Echo the line without further action */
187static void printline(char * line) { printf("%s", line); }
188
189/*
190 * Find all symbols in filename that are exported with EXPORT_SYMBOL &
191 * EXPORT_SYMBOL_GPL (& EXPORT_SYMBOL_GPL_FUTURE implicitly).
192 * All symbols located are stored in symfilelist.
193 */
194static void find_export_symbols(char * filename)
195{
196 FILE * fp;
197 struct symfile *sym;
198 char line[MAXLINESZ];
199 if (filename_exist(filename) == NULL) {
200 char real_filename[PATH_MAX + 1];
201 memset(real_filename, 0, sizeof(real_filename));
202 strncat(real_filename, srctree, PATH_MAX);
203 strncat(real_filename, "/", PATH_MAX - strlen(real_filename));
204 strncat(real_filename, filename,
205 PATH_MAX - strlen(real_filename));
206 sym = add_new_file(filename);
207 fp = fopen(real_filename, "r");
208 if (fp == NULL)
209 {
210 fprintf(stderr, "docproc: ");
211 perror(real_filename);
212 exit(1);
213 }
214 while (fgets(line, MAXLINESZ, fp)) {
215 char *p;
216 char *e;
217 if (((p = strstr(line, "EXPORT_SYMBOL_GPL")) != NULL) ||
218 ((p = strstr(line, "EXPORT_SYMBOL")) != NULL)) {
219 /* Skip EXPORT_SYMBOL{_GPL} */
220 while (isalnum(*p) || *p == '_')
221 p++;
222 /* Remove parentheses & additional whitespace */
223 while (isspace(*p))
224 p++;
225 if (*p != '(')
226 continue; /* Syntax error? */
227 else
228 p++;
229 while (isspace(*p))
230 p++;
231 e = p;
232 while (isalnum(*e) || *e == '_')
233 e++;
234 *e = '\0';
235 add_new_symbol(sym, p);
236 }
237 }
238 fclose(fp);
239 }
240}
241
242/*
243 * Document all external or internal functions in a file.
244 * Call kernel-doc with following parameters:
245 * kernel-doc -docbook -nofunction function_name1 filename
246 * Function names are obtained from all the src files
247 * by find_export_symbols.
248 * intfunc uses -nofunction
249 * extfunc uses -function
250 */
251static void docfunctions(char * filename, char * type)
252{
253 int i,j;
254 int symcnt = 0;
255 int idx = 0;
256 char **vec;
257
258 for (i=0; i <= symfilecnt; i++)
259 symcnt += symfilelist[i].symbolcnt;
260 vec = malloc((2 + 2 * symcnt + 3) * sizeof(char *));
261 if (vec == NULL) {
262 perror("docproc: ");
263 exit(1);
264 }
265 vec[idx++] = KERNELDOC;
266 vec[idx++] = DOCBOOK;
267 vec[idx++] = NODOCSECTIONS;
268 for (i=0; i < symfilecnt; i++) {
269 struct symfile * sym = &symfilelist[i];
270 for (j=0; j < sym->symbolcnt; j++) {
271 vec[idx++] = type;
272 consume_symbol(sym->symbollist[j].name);
273 vec[idx++] = sym->symbollist[j].name;
274 }
275 }
276 vec[idx++] = filename;
277 vec[idx] = NULL;
278 printf("<!-- %s -->\n", filename);
279 exec_kernel_doc(vec);
280 fflush(stdout);
281 free(vec);
282}
283static void intfunc(char * filename) { docfunctions(filename, NOFUNCTION); }
284static void extfunc(char * filename) { docfunctions(filename, FUNCTION); }
285
286/*
287 * Document specific function(s) in a file.
288 * Call kernel-doc with the following parameters:
289 * kernel-doc -docbook -function function1 [-function function2]
290 */
291static void singfunc(char * filename, char * line)
292{
293 char *vec[200]; /* Enough for specific functions */
294 int i, idx = 0;
295 int startofsym = 1;
296 vec[idx++] = KERNELDOC;
297 vec[idx++] = DOCBOOK;
298
299 /* Split line up in individual parameters preceded by FUNCTION */
300 for (i=0; line[i]; i++) {
301 if (isspace(line[i])) {
302 line[i] = '\0';
303 startofsym = 1;
304 continue;
305 }
306 if (startofsym) {
307 startofsym = 0;
308 vec[idx++] = FUNCTION;
309 vec[idx++] = &line[i];
310 }
311 }
312 for (i = 0; i < idx; i++) {
313 if (strcmp(vec[i], FUNCTION))
314 continue;
315 consume_symbol(vec[i + 1]);
316 }
317 vec[idx++] = filename;
318 vec[idx] = NULL;
319 exec_kernel_doc(vec);
320}
321
322/*
323 * Insert specific documentation section from a file.
324 * Call kernel-doc with the following parameters:
325 * kernel-doc -docbook -function "doc section" filename
326 */
327static void docsect(char *filename, char *line)
328{
329 char *vec[6]; /* kerneldoc -docbook -function "section" file NULL */
330 char *s;
331
332 for (s = line; *s; s++)
333 if (*s == '\n')
334 *s = '\0';
335
336 asprintf(&s, "DOC: %s", line);
337 consume_symbol(s);
338 free(s);
339
340 vec[0] = KERNELDOC;
341 vec[1] = DOCBOOK;
342 vec[2] = FUNCTION;
343 vec[3] = line;
344 vec[4] = filename;
345 vec[5] = NULL;
346 exec_kernel_doc(vec);
347}
348
349static void find_all_symbols(char *filename)
350{
351 char *vec[4]; /* kerneldoc -list file NULL */
352 pid_t pid;
353 int ret, i, count, start;
354 char real_filename[PATH_MAX + 1];
355 int pipefd[2];
356 char *data, *str;
357 size_t data_len = 0;
358
359 vec[0] = KERNELDOC;
360 vec[1] = LIST;
361 vec[2] = filename;
362 vec[3] = NULL;
363
364 if (pipe(pipefd)) {
365 perror("pipe");
366 exit(1);
367 }
368
369 switch (pid=fork()) {
370 case -1:
371 perror("fork");
372 exit(1);
373 case 0:
374 close(pipefd[0]);
375 dup2(pipefd[1], 1);
376 memset(real_filename, 0, sizeof(real_filename));
377 strncat(real_filename, kernsrctree, PATH_MAX);
378 strncat(real_filename, "/" KERNELDOCPATH KERNELDOC,
379 PATH_MAX - strlen(real_filename));
380 execvp(real_filename, vec);
381 fprintf(stderr, "exec ");
382 perror(real_filename);
383 exit(1);
384 default:
385 close(pipefd[1]);
386 data = malloc(4096);
387 do {
388 while ((ret = read(pipefd[0],
389 data + data_len,
390 4096)) > 0) {
391 data_len += ret;
392 data = realloc(data, data_len + 4096);
393 }
394 } while (ret == -EAGAIN);
395 if (ret != 0) {
396 perror("read");
397 exit(1);
398 }
399 waitpid(pid, &ret ,0);
400 }
401 if (WIFEXITED(ret))
402 exitstatus |= WEXITSTATUS(ret);
403 else
404 exitstatus = 0xff;
405
406 count = 0;
407 /* poor man's strtok, but with counting */
408 for (i = 0; i < data_len; i++) {
409 if (data[i] == '\n') {
410 count++;
411 data[i] = '\0';
412 }
413 }
414 start = all_list_len;
415 all_list_len += count;
416 all_list = realloc(all_list, sizeof(char *) * all_list_len);
417 str = data;
418 for (i = 0; i < data_len && start != all_list_len; i++) {
419 if (data[i] == '\0') {
420 all_list[start] = str;
421 str = data + i + 1;
422 start++;
423 }
424 }
425}
426
427/*
428 * Parse file, calling action specific functions for:
429 * 1) Lines containing !E
430 * 2) Lines containing !I
431 * 3) Lines containing !D
432 * 4) Lines containing !F
433 * 5) Lines containing !P
434 * 6) Lines containing !C
435 * 7) Default lines - lines not matching the above
436 */
437static void parse_file(FILE *infile)
438{
439 char line[MAXLINESZ];
440 char * s;
441 while (fgets(line, MAXLINESZ, infile)) {
442 if (line[0] == '!') {
443 s = line + 2;
444 switch (line[1]) {
445 case 'E':
446 while (*s && !isspace(*s)) s++;
447 *s = '\0';
448 externalfunctions(line+2);
449 break;
450 case 'I':
451 while (*s && !isspace(*s)) s++;
452 *s = '\0';
453 internalfunctions(line+2);
454 break;
455 case 'D':
456 while (*s && !isspace(*s)) s++;
457 *s = '\0';
458 symbolsonly(line+2);
459 break;
460 case 'F':
461 /* filename */
462 while (*s && !isspace(*s)) s++;
463 *s++ = '\0';
464 /* function names */
465 while (isspace(*s))
466 s++;
467 singlefunctions(line +2, s);
468 break;
469 case 'P':
470 /* filename */
471 while (*s && !isspace(*s)) s++;
472 *s++ = '\0';
473 /* DOC: section name */
474 while (isspace(*s))
475 s++;
476 docsection(line + 2, s);
477 break;
478 case 'C':
479 while (*s && !isspace(*s)) s++;
480 *s = '\0';
481 if (findall)
482 findall(line+2);
483 break;
484 default:
485 defaultline(line);
486 }
487 }
488 else {
489 defaultline(line);
490 }
491 }
492 fflush(stdout);
493}
494
495
496int main(int argc, char *argv[])
497{
498 FILE * infile;
499 int i;
500
501 srctree = getenv("SRCTREE");
502 if (!srctree)
503 srctree = getcwd(NULL, 0);
504 kernsrctree = getenv("KBUILD_SRC");
505 if (!kernsrctree || !*kernsrctree)
506 kernsrctree = srctree;
507 if (argc != 3) {
508 usage();
509 exit(1);
510 }
511 /* Open file, exit on error */
512 infile = fopen(argv[2], "r");
513 if (infile == NULL) {
514 fprintf(stderr, "docproc: ");
515 perror(argv[2]);
516 exit(2);
517 }
518
519 if (strcmp("doc", argv[1]) == 0)
520 {
521 /* Need to do this in two passes.
522 * First pass is used to collect all symbols exported
523 * in the various files;
524 * Second pass generate the documentation.
525 * This is required because some functions are declared
526 * and exported in different files :-((
527 */
528 /* Collect symbols */
529 defaultline = noaction;
530 internalfunctions = find_export_symbols;
531 externalfunctions = find_export_symbols;
532 symbolsonly = find_export_symbols;
533 singlefunctions = noaction2;
534 docsection = noaction2;
535 findall = find_all_symbols;
536 parse_file(infile);
537
538 /* Rewind to start from beginning of file again */
539 fseek(infile, 0, SEEK_SET);
540 defaultline = printline;
541 internalfunctions = intfunc;
542 externalfunctions = extfunc;
543 symbolsonly = printline;
544 singlefunctions = singfunc;
545 docsection = docsect;
546 findall = NULL;
547
548 parse_file(infile);
549
550 for (i = 0; i < all_list_len; i++) {
551 if (!all_list[i])
552 continue;
553 fprintf(stderr, "Warning: didn't use docs for %s\n",
554 all_list[i]);
555 }
556 }
557 else if (strcmp("depend", argv[1]) == 0)
558 {
559 /* Create first part of dependency chain
560 * file.tmpl */
561 printf("%s\t", argv[2]);
562 defaultline = noaction;
563 internalfunctions = adddep;
564 externalfunctions = adddep;
565 symbolsonly = adddep;
566 singlefunctions = adddep2;
567 docsection = adddep2;
568 findall = adddep;
569 parse_file(infile);
570 printf("\n");
571 }
572 else
573 {
574 fprintf(stderr, "Unknown option: %s\n", argv[1]);
575 exit(1);
576 }
577 fclose(infile);
578 fflush(stdout);
579 return exitstatus;
580}
diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index ea26b23de082..291228e25984 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
141char * str_config = NULL; 141struct item {
142int size_config = 0; 142 struct item *next;
143int 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. 149static struct item *hashtab[HASHSZ];
147 * Usually the first growth is plenty.
148 */
149static 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
151static 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 */
165static int is_defined_config(const char * name, int len) 164static 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 */
181static void define_config(const char * name, int len) 179static 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 */
193static void clear_config(void) 197static 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 */
202static void use_config(char *m, int slen) 214static 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
223static void parse_config_file(char *map, size_t len) 236static 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
268static void do_config_file(char *filename) 281static 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 }
@@ -296,12 +309,18 @@ static void do_config_file(char *filename)
296 close(fd); 309 close(fd);
297} 310}
298 311
312/*
313 * Important: The below generated source_foo.o and deps_foo.o variable
314 * assignments are parsed not only by make, but also by the rather simple
315 * parser in scripts/mod/sumversion.c.
316 */
299static void parse_dep_file(void *map, size_t len) 317static void parse_dep_file(void *map, size_t len)
300{ 318{
301 char *m = map; 319 char *m = map;
302 char *end = m + len; 320 char *end = m + len;
303 char *p; 321 char *p;
304 char s[PATH_MAX]; 322 char s[PATH_MAX];
323 int first;
305 324
306 p = strchr(m, ':'); 325 p = strchr(m, ':');
307 if (!p) { 326 if (!p) {
@@ -309,11 +328,11 @@ static void parse_dep_file(void *map, size_t len)
309 exit(1); 328 exit(1);
310 } 329 }
311 memcpy(s, m, p-m); s[p-m] = 0; 330 memcpy(s, m, p-m); s[p-m] = 0;
312 printf("deps_%s := \\\n", target);
313 m = p+1; 331 m = p+1;
314 332
315 clear_config(); 333 clear_config();
316 334
335 first = 1;
317 while (m < end) { 336 while (m < end) {
318 while (m < end && (*m == ' ' || *m == '\\' || *m == '\n')) 337 while (m < end && (*m == ' ' || *m == '\\' || *m == '\n'))
319 m++; 338 m++;
@@ -327,9 +346,20 @@ static void parse_dep_file(void *map, size_t len)
327 if (strrcmp(s, "include/generated/autoconf.h") && 346 if (strrcmp(s, "include/generated/autoconf.h") &&
328 strrcmp(s, "arch/um/include/uml-config.h") && 347 strrcmp(s, "arch/um/include/uml-config.h") &&
329 strrcmp(s, ".ver")) { 348 strrcmp(s, ".ver")) {
330 printf(" %s \\\n", s); 349 /*
350 * Do not list the source file as dependency, so that
351 * kbuild is not confused if a .c file is rewritten
352 * into .S or vice versa. Storing it in source_* is
353 * needed for modpost to compute srcversions.
354 */
355 if (first) {
356 printf("source_%s := %s\n\n", target, s);
357 printf("deps_%s := \\\n", target);
358 } else
359 printf(" %s \\\n", s);
331 do_config_file(s); 360 do_config_file(s);
332 } 361 }
362 first = 0;
333 m = p + 1; 363 m = p + 1;
334 } 364 }
335 printf("\n%s: $(deps_%s)\n\n", target, target); 365 printf("\n%s: $(deps_%s)\n\n", target, target);
@@ -344,11 +374,15 @@ static void print_deps(void)
344 374
345 fd = open(depfile, O_RDONLY); 375 fd = open(depfile, O_RDONLY);
346 if (fd < 0) { 376 if (fd < 0) {
347 fprintf(stderr, "fixdep: "); 377 fprintf(stderr, "fixdep: error opening depfile: ");
348 perror(depfile); 378 perror(depfile);
349 exit(2); 379 exit(2);
350 } 380 }
351 fstat(fd, &st); 381 if (fstat(fd, &st) < 0) {
382 fprintf(stderr, "fixdep: error fstat'ing depfile: ");
383 perror(depfile);
384 exit(2);
385 }
352 if (st.st_size == 0) { 386 if (st.st_size == 0) {
353 fprintf(stderr,"fixdep: %s is empty\n",depfile); 387 fprintf(stderr,"fixdep: %s is empty\n",depfile);
354 close(fd); 388 close(fd);
diff --git a/scripts/basic/hash.c b/scripts/basic/hash.c
deleted file mode 100644
index 2ef5d3f666b8..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
12static const char *program;
13
14static 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
24static 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
37static 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
50int 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