Commit | Line | Data |
---|---|---|
8d9792eb | 1 | /* mkmakefile.c 1.23 82/12/18 */ |
28061b3f | 2 | |
01d17851 | 3 | /* |
28061b3f BJ |
4 | * Build the makefile for the system, from |
5 | * the information in the files files and the | |
6 | * additional files for the machine being compiled to. | |
01d17851 MT |
7 | */ |
8 | ||
9 | #include <stdio.h> | |
d5429061 | 10 | #include <ctype.h> |
01d17851 MT |
11 | #include "y.tab.h" |
12 | #include "config.h" | |
13 | ||
28061b3f BJ |
14 | #define next_word(fp, wd) \ |
15 | { register char *word = get_word(fp); \ | |
22d68ad0 BJ |
16 | if (word == (char *)EOF) \ |
17 | return; \ | |
28061b3f BJ |
18 | else \ |
19 | wd = word; \ | |
20 | } | |
01d17851 | 21 | |
28061b3f | 22 | static struct file_list *fcur; |
01d17851 MT |
23 | |
24 | /* | |
28061b3f | 25 | * Lookup a file, by make. |
01d17851 | 26 | */ |
28061b3f BJ |
27 | struct file_list * |
28 | fl_lookup(file) | |
29 | register char *file; | |
01d17851 | 30 | { |
28061b3f BJ |
31 | register struct file_list *fp; |
32 | ||
22d68ad0 | 33 | for (fp = ftab ; fp != 0; fp = fp->f_next) { |
28061b3f BJ |
34 | if (eq(fp->f_fn, file)) |
35 | return (fp); | |
36 | } | |
37 | return (0); | |
01d17851 MT |
38 | } |
39 | ||
40 | /* | |
28061b3f | 41 | * Make a new file list entry |
01d17851 | 42 | */ |
28061b3f BJ |
43 | struct file_list * |
44 | new_fent() | |
01d17851 | 45 | { |
28061b3f BJ |
46 | register struct file_list *fp; |
47 | ||
48 | fp = (struct file_list *) malloc(sizeof *fp); | |
22d68ad0 BJ |
49 | fp->f_needs = 0; |
50 | fp->f_next = 0; | |
51 | if (fcur == 0) | |
28061b3f BJ |
52 | fcur = ftab = fp; |
53 | else | |
54 | fcur->f_next = fp; | |
55 | fcur = fp; | |
56 | return (fp); | |
01d17851 MT |
57 | } |
58 | ||
28061b3f BJ |
59 | char *COPTS; |
60 | ||
01d17851 | 61 | /* |
28061b3f | 62 | * Build the makefile from the skeleton |
01d17851 | 63 | */ |
01d17851 MT |
64 | makefile() |
65 | { | |
28061b3f BJ |
66 | FILE *ifp, *ofp; |
67 | char line[BUFSIZ]; | |
68 | struct opt *op; | |
69 | ||
70 | read_files(); | |
71 | strcpy(line, "../conf/makefile."); | |
22d68ad0 | 72 | (void) strcat(line, machinename); |
28061b3f | 73 | ifp = fopen(line, "r"); |
22d68ad0 | 74 | if (ifp == 0) { |
28061b3f BJ |
75 | perror(line); |
76 | exit(1); | |
77 | } | |
78 | ofp = fopen(path("makefile"), "w"); | |
22d68ad0 | 79 | if (ofp == 0) { |
28061b3f BJ |
80 | perror(path("makefile")); |
81 | exit(1); | |
82 | } | |
83 | fprintf(ofp, "IDENT=-D%s", raise(ident)); | |
84 | if (profiling) | |
85 | fprintf(ofp, " -DGPROF"); | |
86 | if (cputype == 0) { | |
87 | printf("cpu type must be specified\n"); | |
88 | exit(1); | |
89 | } | |
90 | { struct cputype *cp; | |
91 | for (cp = cputype; cp; cp = cp->cpu_next) | |
92 | fprintf(ofp, " -D%s", cp->cpu_name); | |
93 | } | |
94 | for (op = opt; op; op = op->op_next) | |
95 | if (op->op_value) | |
96 | fprintf(ofp, " -D%s=\"%s\"", op->op_name, op->op_value); | |
97 | else | |
98 | fprintf(ofp, " -D%s", op->op_name); | |
99 | fprintf(ofp, "\n"); | |
100 | if (hadtz == 0) | |
101 | printf("timezone not specified; gmt assumed\n"); | |
102 | if (maxusers == 0) { | |
103 | printf("maxusers not specified; 24 assumed\n"); | |
104 | maxusers = 24; | |
105 | } else if (maxusers < 8) { | |
106 | printf("minimum of 8 maxusers assumed\n"); | |
107 | maxusers = 8; | |
108 | } else if (maxusers > 128) { | |
109 | printf("maxusers truncated to 128\n"); | |
110 | maxusers = 128; | |
111 | } | |
112 | fprintf(ofp, "PARAM=-DTIMEZONE=%d -DDST=%d -DMAXUSERS=%d\n", | |
113 | timezone, dst, maxusers); | |
22d68ad0 | 114 | while (fgets(line, BUFSIZ, ifp) != 0) { |
28061b3f BJ |
115 | if (*line == '%') |
116 | goto percent; | |
117 | if (profiling && strncmp(line, "COPTS=", 6) == 0) { | |
118 | register char *cp; | |
119 | ||
8d9792eb | 120 | fprintf(ofp, "CRT0.EX=/usr/src/lib/libc/csu/crt0.ex\n"); |
28061b3f BJ |
121 | cp = index(line, '\n'); |
122 | if (cp) | |
123 | *cp = 0; | |
124 | cp = line + 6; | |
125 | while (*cp && (*cp == ' ' || *cp == '\t')) | |
126 | cp++; | |
22d68ad0 | 127 | COPTS = malloc((unsigned)(strlen(cp) + 1)); |
28061b3f | 128 | if (COPTS == 0) { |
f2db9eb7 | 129 | printf("config: out of memory\n"); |
28061b3f BJ |
130 | exit(1); |
131 | } | |
132 | strcpy(COPTS, cp); | |
133 | fprintf(ofp, "%s -pg\n", line); | |
134 | continue; | |
8486638c | 135 | } |
28061b3f | 136 | fprintf(ofp, "%s", line); |
8486638c | 137 | continue; |
28061b3f BJ |
138 | percent: |
139 | if (eq(line, "%OBJS\n")) | |
140 | do_objs(ofp); | |
141 | else if (eq(line, "%CFILES\n")) | |
142 | do_cfiles(ofp); | |
143 | else if (eq(line, "%RULES\n")) | |
144 | do_rules(ofp); | |
145 | else if (eq(line, "%LOAD\n")) | |
146 | do_load(ofp); | |
147 | else | |
148 | fprintf(stderr, | |
149 | "Unknown %% construct in generic makefile: %s", | |
150 | line); | |
01d17851 | 151 | } |
73845e07 SL |
152 | (void) fclose(ifp); |
153 | (void) fclose(ofp); | |
01d17851 MT |
154 | } |
155 | ||
156 | /* | |
28061b3f BJ |
157 | * Read in the information about files used in making the system. |
158 | * Store it in the ftab linked list. | |
01d17851 | 159 | */ |
01d17851 MT |
160 | read_files() |
161 | { | |
28061b3f BJ |
162 | FILE *fp; |
163 | register struct file_list *tp; | |
164 | register struct device *dp; | |
165 | char *wd, *this, *needs, *devorprof; | |
166 | char fname[32]; | |
167 | int nreqs; | |
168 | int first = 1; | |
169 | ||
22d68ad0 BJ |
170 | ftab = 0; |
171 | (void) strcpy(fname, "files"); | |
28061b3f BJ |
172 | openit: |
173 | fp = fopen(fname, "r"); | |
22d68ad0 | 174 | if (fp == 0) { |
73845e07 | 175 | perror(fname); |
28061b3f BJ |
176 | exit(1); |
177 | } | |
178 | next: | |
179 | /* filename [ standard | optional dev* ] [ device-driver ] */ | |
180 | wd = get_word(fp); | |
22d68ad0 BJ |
181 | if (wd == (char *)EOF) { |
182 | (void) fclose(fp); | |
28061b3f | 183 | if (first) { |
22d68ad0 | 184 | (void) sprintf(fname, "files.%s", machinename); |
28061b3f BJ |
185 | first = 0; |
186 | goto openit; | |
187 | } | |
188 | return; | |
189 | } | |
22d68ad0 | 190 | if (wd == 0) |
28061b3f | 191 | goto next; |
01d17851 | 192 | this = ns(wd); |
01d17851 | 193 | next_word(fp, wd); |
22d68ad0 | 194 | if (wd == 0) { |
f2db9eb7 | 195 | printf("%s: No type for %s.\n", |
28061b3f BJ |
196 | fname, this); |
197 | exit(1); | |
01d17851 | 198 | } |
28061b3f | 199 | if (fl_lookup(this)) { |
f2db9eb7 | 200 | printf("%s: Duplicate file %s.\n", |
28061b3f BJ |
201 | fname, this); |
202 | exit(1); | |
203 | } | |
204 | nreqs = 0; | |
205 | devorprof = ""; | |
206 | needs = 0; | |
207 | if (eq(wd, "standard")) | |
208 | goto checkdev; | |
209 | if (!eq(wd, "optional")) { | |
73845e07 | 210 | printf("%s: %s must be optional or standard\n", |
28061b3f BJ |
211 | fname, this); |
212 | exit(1); | |
213 | } | |
214 | nextopt: | |
215 | next_word(fp, wd); | |
22d68ad0 | 216 | if (wd == 0) |
28061b3f BJ |
217 | goto doneopt; |
218 | devorprof = wd; | |
73845e07 SL |
219 | if (eq(wd, "device-driver") || eq(wd, "profiling-routine")) { |
220 | next_word(fp, wd); | |
28061b3f | 221 | goto save; |
73845e07 | 222 | } |
28061b3f BJ |
223 | nreqs++; |
224 | if (needs == 0) | |
225 | needs = ns(wd); | |
22d68ad0 | 226 | for (dp = dtab; dp != 0; dp = dp->d_next) |
28061b3f BJ |
227 | if (eq(dp->d_name, wd)) |
228 | goto nextopt; | |
22d68ad0 | 229 | while ((wd = get_word(fp)) != 0) |
28061b3f BJ |
230 | ; |
231 | tp = new_fent(); | |
01d17851 | 232 | tp->f_fn = this; |
28061b3f BJ |
233 | tp->f_type = INVISIBLE; |
234 | tp->f_needs = needs; | |
235 | goto next; | |
236 | doneopt: | |
237 | if (nreqs == 0) { | |
f2db9eb7 | 238 | printf("%s: what is %s optional on?\n", |
28061b3f BJ |
239 | fname, this); |
240 | exit(1); | |
241 | } | |
242 | checkdev: | |
243 | if (wd) { | |
2fcca161 | 244 | next_word(fp, wd); |
22d68ad0 | 245 | if (wd != 0) { |
28061b3f BJ |
246 | devorprof = wd; |
247 | next_word(fp, wd); | |
2fcca161 | 248 | } |
01d17851 | 249 | } |
28061b3f | 250 | save: |
22d68ad0 | 251 | if (wd != 0) { |
f2db9eb7 | 252 | printf("%s: syntax error describing %s\n", |
28061b3f BJ |
253 | fname, this); |
254 | exit(1); | |
2fcca161 | 255 | } |
73845e07 SL |
256 | if (eq(devorprof, "profiling-routine") && profiling == 0) |
257 | goto next; | |
28061b3f BJ |
258 | tp = new_fent(); |
259 | tp->f_fn = this; | |
260 | if (eq(devorprof, "device-driver")) | |
261 | tp->f_type = DEVICE; | |
262 | else if (eq(devorprof, "profiling-routine")) | |
263 | tp->f_type = PROFILING; | |
264 | else | |
265 | tp->f_type = NORMAL; | |
266 | tp->f_needs = needs; | |
267 | goto next; | |
01d17851 MT |
268 | } |
269 | ||
01d17851 | 270 | do_objs(fp) |
28061b3f | 271 | FILE *fp; |
01d17851 | 272 | { |
28061b3f BJ |
273 | register struct file_list *tp; |
274 | register int lpos, len; | |
275 | register char *cp, och, *sp; | |
276 | char *tail(); | |
277 | ||
278 | fprintf(fp, "OBJS="); | |
279 | lpos = 6; | |
22d68ad0 | 280 | for (tp = ftab; tp != 0; tp = tp->f_next) { |
28061b3f BJ |
281 | if (tp->f_type == INVISIBLE) |
282 | continue; | |
283 | sp = tail(tp->f_fn); | |
284 | cp = sp + (len = strlen(sp)) - 1; | |
285 | och = *cp; | |
286 | *cp = 'o'; | |
287 | if (len + lpos > 72) { | |
288 | lpos = 8; | |
289 | fprintf(fp, "\\\n\t"); | |
290 | } | |
291 | fprintf(fp, "%s ", sp); | |
292 | lpos += len + 1; | |
293 | *cp = och; | |
01d17851 | 294 | } |
28061b3f BJ |
295 | if (lpos != 8) |
296 | putc('\n', fp); | |
01d17851 MT |
297 | } |
298 | ||
01d17851 | 299 | do_cfiles(fp) |
28061b3f | 300 | FILE *fp; |
01d17851 | 301 | { |
28061b3f BJ |
302 | register struct file_list *tp; |
303 | register int lpos, len; | |
304 | ||
305 | fprintf(fp, "CFILES="); | |
306 | lpos = 8; | |
22d68ad0 | 307 | for (tp = ftab; tp != 0; tp = tp->f_next) { |
28061b3f BJ |
308 | if (tp->f_type == INVISIBLE) |
309 | continue; | |
310 | if (tp->f_fn[strlen(tp->f_fn)-1] != 'c') | |
311 | continue; | |
312 | if ((len = 3 + strlen(tp->f_fn)) + lpos > 72) { | |
313 | lpos = 8; | |
314 | fprintf(fp, "\\\n\t"); | |
315 | } | |
316 | fprintf(fp, "../%s ", tp->f_fn); | |
317 | lpos += len + 1; | |
01d17851 | 318 | } |
28061b3f BJ |
319 | if (lpos != 8) |
320 | putc('\n', fp); | |
01d17851 MT |
321 | } |
322 | ||
28061b3f BJ |
323 | char * |
324 | tail(fn) | |
325 | char *fn; | |
01d17851 | 326 | { |
28061b3f | 327 | register char *cp; |
01d17851 | 328 | |
28061b3f BJ |
329 | cp = rindex(fn, '/'); |
330 | return (cp+1); | |
01d17851 MT |
331 | } |
332 | ||
333 | /* | |
28061b3f BJ |
334 | * Create the makerules for each file |
335 | * which is part of the system. | |
336 | * Devices are processed with the special c2 option -i | |
337 | * which avoids any problem areas with i/o addressing | |
338 | * (e.g. for the VAX); assembler files are processed by as. | |
01d17851 | 339 | */ |
01d17851 | 340 | do_rules(f) |
28061b3f | 341 | FILE *f; |
01d17851 | 342 | { |
28061b3f BJ |
343 | register char *cp, *np, och, *tp; |
344 | register struct file_list *ftp; | |
01d17851 | 345 | |
22d68ad0 | 346 | for (ftp = ftab; ftp != 0; ftp = ftp->f_next) { |
01d17851 | 347 | if (ftp->f_type == INVISIBLE) |
28061b3f | 348 | continue; |
01d17851 MT |
349 | cp = (np = ftp->f_fn) + strlen(ftp->f_fn) - 1; |
350 | och = *cp; | |
351 | *cp = '\0'; | |
352 | fprintf(f, "%so: ../%s%c\n", tail(np), np, och); | |
353 | tp = tail(np); | |
28061b3f BJ |
354 | if (och == 's') { |
355 | fprintf(f, "\t${AS} -o %so ../%ss\n\n", tp, np); | |
356 | continue; | |
01d17851 | 357 | } |
28061b3f BJ |
358 | switch (ftp->f_type) { |
359 | ||
360 | case NORMAL: | |
361 | switch (machine) { | |
362 | ||
363 | case MACHINE_VAX: | |
364 | fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../%sc\n", np); | |
365 | fprintf(f, "\t${C2} %ss | sed -f ../%s/asm.sed |", | |
366 | tp, machinename); | |
367 | fprintf(f, " ${AS} -o %so\n", tp); | |
368 | fprintf(f, "\trm -f %ss\n\n", tp); | |
369 | break; | |
370 | ||
371 | case MACHINE_SUN: | |
372 | fprintf(f, "\t${CC} -I. -c -O ${COPTS} ../%sc\n\n", np); | |
373 | break; | |
374 | } | |
375 | break; | |
376 | ||
377 | case DEVICE: | |
378 | switch (machine) { | |
379 | ||
380 | case MACHINE_VAX: | |
381 | fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../%sc\n", np); | |
382 | fprintf(f,"\t${C2} -i %ss | sed -f ../%s/asm.sed |", | |
383 | tp, machinename); | |
384 | fprintf(f, " ${AS} -o %so\n", tp); | |
385 | fprintf(f, "\trm -f %ss\n\n", tp); | |
386 | break; | |
387 | ||
388 | case MACHINE_SUN: | |
389 | fprintf(f, "\t${CC} -I. -c -O ${COPTS} ../%sc\n\n", np); | |
390 | } | |
391 | break; | |
392 | ||
393 | case PROFILING: | |
8486638c SL |
394 | if (!profiling) |
395 | continue; | |
396 | if (COPTS == 0) { | |
397 | fprintf(stderr, | |
28061b3f | 398 | "config: COPTS undefined in generic makefile"); |
8486638c SL |
399 | COPTS = ""; |
400 | } | |
28061b3f BJ |
401 | switch (machine) { |
402 | ||
403 | case MACHINE_VAX: | |
404 | fprintf(f, "\t${CC} -I. -c -S %s ../%sc\n", COPTS, np); | |
405 | fprintf(f, "\tex - %ss < ${CRT0.EX}\n", tp); | |
406 | fprintf(f, | |
73845e07 | 407 | "\t/lib/cpp %ss | sed -f ../vax/asm.sed | ${AS} -o %so\n", |
28061b3f BJ |
408 | tp, tp); |
409 | fprintf(f, "\trm -f %ss\n\n", tp); | |
410 | break; | |
411 | ||
412 | case MACHINE_SUN: | |
413 | fprintf(stderr, | |
414 | "config: don't know how to profile kernel on sun\n"); | |
415 | break; | |
416 | } | |
73845e07 | 417 | break; |
28061b3f BJ |
418 | |
419 | default: | |
f2db9eb7 | 420 | printf("Don't know rules for %s", np); |
28061b3f BJ |
421 | break; |
422 | } | |
01d17851 | 423 | *cp = och; |
28061b3f | 424 | } |
01d17851 MT |
425 | } |
426 | ||
427 | /* | |
428 | * Create the load strings | |
429 | */ | |
01d17851 | 430 | do_load(f) |
28061b3f | 431 | register FILE *f; |
01d17851 | 432 | { |
28061b3f | 433 | register struct file_list *fl; |
821eeaae | 434 | int first = 1; |
28061b3f | 435 | |
22d68ad0 | 436 | for (fl = conf_list; fl != 0; fl = fl->f_next) { |
28061b3f BJ |
437 | fprintf(f, "%s: makefile locore.o ${OBJS} param.o", |
438 | fl->f_needs); | |
439 | fprintf(f, " ioconf.o swap%s.o\n", fl->f_fn); | |
440 | fprintf(f, "\t@echo loading %s\n\t@rm -f %s\n", | |
441 | fl->f_needs, fl->f_needs); | |
442 | if (first) { | |
443 | first = 0; | |
444 | fprintf(f, "\t@sh ../conf/newvers.sh\n"); | |
445 | fprintf(f, "\t@${CC} $(CFLAGS) -c vers.c\n"); | |
446 | } | |
447 | switch (machine) { | |
448 | ||
449 | case MACHINE_VAX: | |
450 | fprintf(f, "\t@${LD} -n -o %s -e start -x -T 80000000 ", | |
451 | fl->f_needs); | |
452 | fprintf(f, "locore.o ${OBJS} vers.o ioconf.o param.o "); | |
453 | fprintf(f, "swap%s.o\n", fl->f_fn); | |
454 | break; | |
455 | ||
456 | case MACHINE_SUN: | |
457 | fprintf(f, "\t@${LD} -o %s -e start -x -T 4000 ", | |
458 | fl->f_needs); | |
459 | fprintf(f, "locore.o ${OBJS} vers.o ioconf.o param.o "); | |
460 | fprintf(f, "swap%s.o\n", fl->f_fn); | |
461 | break; | |
462 | } | |
463 | fprintf(f, "\t@echo rearranging symbols\n"); | |
464 | fprintf(f, "\t@-symorder ../%s/symbols.sort %s\n", | |
465 | machinename, fl->f_needs); | |
466 | fprintf(f, "\t@size %s\n", fl->f_needs); | |
467 | fprintf(f, "\t@chmod 755 %s\n\n", fl->f_needs); | |
190b5698 | 468 | } |
22d68ad0 | 469 | for (fl = conf_list; fl != 0; fl = fl->f_next) { |
28061b3f BJ |
470 | fprintf(f, "swap%s.o: ../%s/swap%s.c\n", |
471 | fl->f_fn, machinename, fl->f_fn); | |
472 | switch (machine) { | |
473 | ||
474 | case MACHINE_VAX: | |
475 | fprintf(f, "\t${CC} -I. -c -S ${COPTS}"); | |
476 | fprintf(f, " ../%s/swap%s.c\n", machinename, fl->f_fn); | |
477 | fprintf(f, "\t${C2} swap%s.s | sed -f ../%s/asm.sed", | |
478 | fl->f_fn, machinename); | |
479 | fprintf(f, " | ${AS} -o swap%s.o\n", | |
480 | fl->f_fn); | |
481 | fprintf(f, "\trm -f swap%s.s\n\n", fl->f_fn); | |
482 | break; | |
483 | ||
484 | case MACHINE_SUN: | |
485 | fprintf(f, "\t${CC} -I. -c -O ${COPTS} "); | |
486 | fprintf(f, "../%s/swap%s.c\n\n", machinename, fl->f_fn); | |
487 | break; | |
488 | } | |
489 | } | |
490 | fprintf(f, "all:"); | |
22d68ad0 | 491 | for (fl = conf_list; fl != 0; fl = fl->f_next) |
28061b3f BJ |
492 | fprintf(f, " %s", fl->f_needs); |
493 | fprintf(f, "\n"); | |
01d17851 | 494 | } |
d5429061 | 495 | |
22d68ad0 | 496 | char * |
d5429061 | 497 | raise(str) |
28061b3f | 498 | register char *str; |
d5429061 | 499 | { |
28061b3f BJ |
500 | register char *cp = str; |
501 | ||
502 | while (*str) { | |
503 | if (islower(*str)) | |
504 | *str = toupper(*str); | |
505 | str++; | |
506 | } | |
507 | return (cp); | |
d5429061 | 508 | } |