|
|
1.1 root 1: #ifndef lint
2: static char sccsid[] = "@(#)mkmakefile.c 1.30 (Berkeley) 8/11/83";
3: #endif
4:
5: /*
6: * Build the makefile for the system, from
7: * the information in the files files and the
8: * additional files for the machine being compiled to.
9: */
10:
11: #include <stdio.h>
12: #include <ctype.h>
13: #include "y.tab.h"
14: #include "config.h"
15:
16: #define next_word(fp, wd) \
17: { register char *word = get_word(fp); \
18: if (word == (char *)EOF) \
19: return; \
20: else \
21: wd = word; \
22: }
23:
24: static struct file_list *fcur;
25: char *tail();
26:
27: /*
28: * Lookup a file, by make.
29: */
30: struct file_list *
31: fl_lookup(file)
32: register char *file;
33: {
34: register struct file_list *fp;
35:
36: for (fp = ftab ; fp != 0; fp = fp->f_next) {
37: if (eq(fp->f_fn, file))
38: return (fp);
39: }
40: return (0);
41: }
42:
43: /*
44: * Lookup a file, by final component name.
45: */
46: struct file_list *
47: fltail_lookup(file)
48: register char *file;
49: {
50: register struct file_list *fp;
51:
52: for (fp = ftab ; fp != 0; fp = fp->f_next) {
53: if (eq(tail(fp->f_fn), tail(file)))
54: return (fp);
55: }
56: return (0);
57: }
58:
59: /*
60: * Make a new file list entry
61: */
62: struct file_list *
63: new_fent()
64: {
65: register struct file_list *fp;
66:
67: fp = (struct file_list *) malloc(sizeof *fp);
68: fp->f_needs = 0;
69: fp->f_next = 0;
70: fp->f_flags = 0;
71: fp->f_type = 0;
72: if (fcur == 0)
73: fcur = ftab = fp;
74: else
75: fcur->f_next = fp;
76: fcur = fp;
77: return (fp);
78: }
79:
80: char *COPTS;
81:
82: /*
83: * Build the makefile from the skeleton
84: */
85: makefile()
86: {
87: FILE *ifp, *ofp;
88: char line[BUFSIZ];
89: struct opt *op;
90:
91: read_files();
92: strcpy(line, "../conf/makefile.");
93: (void) strcat(line, machinename);
94: ifp = fopen(line, "r");
95: if (ifp == 0) {
96: perror(line);
97: exit(1);
98: }
99: ofp = fopen(path("makefile"), "w");
100: if (ofp == 0) {
101: perror(path("makefile"));
102: exit(1);
103: }
104: fprintf(ofp, "IDENT=-D%s", raise(ident));
105: if (profiling)
106: fprintf(ofp, " -DGPROF");
107: if (cputype == 0) {
108: printf("cpu type must be specified\n");
109: exit(1);
110: }
111: { struct cputype *cp;
112: for (cp = cputype; cp; cp = cp->cpu_next)
113: fprintf(ofp, " -D%s", cp->cpu_name);
114: }
115: for (op = opt; op; op = op->op_next)
116: if (op->op_value)
117: fprintf(ofp, " -D%s=\"%s\"", op->op_name, op->op_value);
118: else
119: fprintf(ofp, " -D%s", op->op_name);
120: fprintf(ofp, "\n");
121: if (hadtz == 0)
122: printf("timezone not specified; gmt assumed\n");
123: #ifdef tahoe
124: if (maxusers == 0) {
125: printf("maxusers not specified; 4 assumed\n");
126: maxusers = 4;
127: } else if (maxusers < 2) {
128: printf("minimum of 2 maxusers assumed\n");
129: maxusers = 2;
130: } else if (maxusers > 128) {
131: printf("maxusers truncated to 128\n");
132: maxusers = 128;
133: }
134: #endif
135: #ifdef vax
136: if (maxusers == 0) {
137: printf("maxusers not specified; 24 assumed\n");
138: maxusers = 24;
139: } else if (maxusers < 8) {
140: printf("minimum of 8 maxusers assumed\n");
141: maxusers = 8;
142: } else if (maxusers > 128) {
143: printf("maxusers truncated to 128\n");
144: maxusers = 128;
145: }
146: #endif
147: #ifdef sun
148: if (maxusers == 0) {
149: printf("maxusers not specified; 8 assumed\n");
150: maxusers = 8;
151: } else if (maxusers < 2) {
152: printf("minimum of 2 maxusers assumed\n");
153: maxusers = 2;
154: } else if (maxusers > 32) {
155: printf("maxusers truncated to 32\n");
156: maxusers = 32;
157: }
158: #endif
159: fprintf(ofp, "PARAM=-DHZ=%d -DTIMEZONE=%d -DDST=%d -DMAXUSERS=%d\n",
160: hz,timezone, dst, maxusers);
161: while (fgets(line, BUFSIZ, ifp) != 0) {
162: if (*line == '%')
163: goto percent;
164: if (profiling && strncmp(line, "COPTS=", 6) == 0) {
165: register char *cp;
166:
167: fprintf(ofp,
168: "GPROF.EX=/usr/src/lib/libc/%s/csu/gmon.ex\n",
169: machinename);
170: cp = index(line, '\n');
171: if (cp)
172: *cp = 0;
173: cp = line + 6;
174: while (*cp && (*cp == ' ' || *cp == '\t'))
175: cp++;
176: COPTS = malloc((unsigned)(strlen(cp) + 1));
177: if (COPTS == 0) {
178: printf("config: out of memory\n");
179: exit(1);
180: }
181: strcpy(COPTS, cp);
182: fprintf(ofp, "%s -pg\n", line);
183: continue;
184: }
185: fprintf(ofp, "%s", line);
186: continue;
187: percent:
188: if (eq(line, "%OBJS\n"))
189: do_objs(ofp);
190: else if (eq(line, "%CFILES\n"))
191: do_cfiles(ofp);
192: else if (eq(line, "%RULES\n"))
193: do_rules(ofp);
194: else if (eq(line, "%LOAD\n"))
195: do_load(ofp);
196: else
197: fprintf(stderr,
198: "Unknown %% construct in generic makefile: %s",
199: line);
200: }
201: (void) fclose(ifp);
202: (void) fclose(ofp);
203: }
204:
205: /*
206: * Read in the information about files used in making the system.
207: * Store it in the ftab linked list.
208: */
209: read_files()
210: {
211: FILE *fp;
212: register struct file_list *tp;
213: register struct device *dp;
214: char *wd, *this, *needs, *devorprof;
215: char fname[32];
216: int nreqs, first = 1, configdep;
217:
218: ftab = 0;
219: (void) strcpy(fname, "files");
220: openit:
221: fp = fopen(fname, "r");
222: if (fp == 0) {
223: perror(fname);
224: exit(1);
225: }
226: next:
227: /*
228: * filename [ standard | optional ] [ config-dependent ]
229: * [ dev* | profiling-routine ] [ device-driver]
230: */
231: wd = get_word(fp);
232: if (wd == (char *)EOF) {
233: (void) fclose(fp);
234: if (first == 1) {
1.1.1.2 ! root 235: tp=new_fent();
! 236: tp->f_type = FILESPT;
1.1 root 237: (void) sprintf(fname, "files.%s", machinename);
238: first++;
239: goto openit;
240: }
241: if (first == 2) {
242: (void) sprintf(fname, "files.%s", raise(ident));
243: first++;
244: fp = fopen(fname, "r");
245: if (fp != 0)
246: goto next;
247: }
248: return;
249: }
250: if (wd == 0)
251: goto next;
252: this = ns(wd);
253: next_word(fp, wd);
254: if (wd == 0) {
255: printf("%s: No type for %s.\n",
256: fname, this);
257: exit(1);
258: }
259: if (fl_lookup(this)) {
260: printf("%s: Duplicate file %s.\n",
261: fname, this);
262: exit(1);
263: }
264: tp = 0;
265: if (first == 3 && (tp = fltail_lookup(this)) != 0)
266: printf("%s: Local file %s overrides %s.\n",
267: fname, this, tp->f_fn);
268: nreqs = 0;
269: devorprof = "";
270: configdep = 0;
271: needs = 0;
272: if (eq(wd, "standard"))
273: goto checkdev;
274: if (!eq(wd, "optional")) {
275: printf("%s: %s must be optional or standard\n", fname, this);
276: exit(1);
277: }
278: nextopt:
279: next_word(fp, wd);
280: if (wd == 0)
281: goto doneopt;
282: if (eq(wd, "config-dependent")) {
283: configdep++;
284: goto nextopt;
285: }
286: devorprof = wd;
287: if (eq(wd, "device-driver") || eq(wd, "profiling-routine")) {
288: next_word(fp, wd);
289: goto save;
290: }
291: nreqs++;
292: if (needs == 0)
293: needs = ns(wd);
294: for (dp = dtab; dp != 0; dp = dp->d_next)
295: if (eq(dp->d_name, wd))
296: goto nextopt;
297: while ((wd = get_word(fp)) != 0)
298: ;
299: if (tp == 0)
300: tp = new_fent();
301: tp->f_fn = this;
302: tp->f_type = INVISIBLE;
303: tp->f_needs = needs;
304: goto next;
305:
306: doneopt:
307: if (nreqs == 0) {
308: printf("%s: what is %s optional on?\n",
309: fname, this);
310: exit(1);
311: }
312:
313: checkdev:
314: if (wd) {
315: next_word(fp, wd);
316: if (wd) {
317: if (eq(wd, "config-dependent")) {
318: configdep++;
319: goto checkdev;
320: }
321: devorprof = wd;
322: next_word(fp, wd);
323: }
324: }
325:
326: save:
327: if (wd) {
328: printf("%s: syntax error describing %s\n",
329: fname, this);
330: exit(1);
331: }
332: if (eq(devorprof, "profiling-routine") && profiling == 0)
333: goto next;
334: if (tp == 0)
335: tp = new_fent();
336: tp->f_fn = this;
337: if (eq(devorprof, "device-driver"))
338: tp->f_type = DRIVER;
339: else if (eq(devorprof, "profiling-routine"))
340: tp->f_type = PROFILING;
341: else
342: tp->f_type = NORMAL;
343: tp->f_flags = 0;
344: if (configdep)
345: tp->f_flags |= CONFIGDEP;
346: tp->f_needs = needs;
347: goto next;
348: }
349:
350: do_objs(fp)
351: FILE *fp;
352: {
353: register struct file_list *tp, *fl;
354: register int lpos, len;
355: register char *cp, och, *sp;
356: char swapname[32];
357:
358: fprintf(fp, "OBJS=");
359: lpos = 6;
360: for (tp = ftab; tp != 0; tp = tp->f_next) {
1.1.1.2 ! root 361: if (tp->f_type == FILESPT){
! 362: fprintf(fp,"\nMOBJS=");
! 363: lpos = 6;
! 364: goto cont;
! 365: }
1.1 root 366: if (tp->f_type == INVISIBLE)
367: continue;
368: sp = tail(tp->f_fn);
369: for (fl = conf_list; fl; fl = fl->f_next) {
370: if (fl->f_type != SWAPSPEC)
371: continue;
372: sprintf(swapname, "swap%s.c", fl->f_fn);
373: if (eq(sp, swapname))
374: goto cont;
375: }
376: cp = sp + (len = strlen(sp)) - 1;
377: och = *cp;
378: *cp = 'o';
379: if (len + lpos > 72) {
380: lpos = 8;
381: fprintf(fp, "\\\n\t");
382: }
383: fprintf(fp, "%s ", sp);
384: lpos += len + 1;
385: *cp = och;
386: cont:
387: ;
388: }
389: if (lpos != 8)
390: putc('\n', fp);
391: }
392:
393: do_cfiles(fp)
394: FILE *fp;
395: {
396: register struct file_list *tp;
397: register int lpos, len;
398:
399: fprintf(fp, "CFILES=");
400: lpos = 8;
401: for (tp = ftab; tp != 0; tp = tp->f_next) {
1.1.1.2 ! root 402: if (tp->f_type == FILESPT){
! 403: fprintf(fp,"\nMCFILES=");
! 404: lpos = 8;
! 405: goto cont1;
! 406: }
1.1 root 407: if (tp->f_type == INVISIBLE)
408: continue;
409: if (tp->f_fn[strlen(tp->f_fn)-1] != 'c')
410: continue;
411: if ((len = 3 + strlen(tp->f_fn)) + lpos > 72) {
412: lpos = 8;
413: fprintf(fp, "\\\n\t");
414: }
415: fprintf(fp, "../%s ", tp->f_fn);
416: lpos += len + 1;
1.1.1.2 ! root 417: cont1:
! 418: ;
1.1 root 419: }
420: if (lpos != 8)
421: putc('\n', fp);
422: }
423:
424: char *
425: tail(fn)
426: char *fn;
427: {
428: register char *cp;
429:
430: cp = rindex(fn, '/');
431: if (cp == 0)
432: return (fn);
433: return (cp+1);
434: }
435:
436: /*
437: * Create the makerules for each file
438: * which is part of the system.
439: * Devices are processed with the special c2 option -i
440: * which avoids any problem areas with i/o addressing
441: * (e.g. for the VAX); assembler files are processed by as.
442: */
443: do_rules(f)
444: FILE *f;
445: {
446: register char *cp, *np, och, *tp;
447: register struct file_list *ftp;
448: char *extras;
449:
450: for (ftp = ftab; ftp != 0; ftp = ftp->f_next) {
1.1.1.2 ! root 451: if (ftp->f_type == FILESPT)
! 452: continue;
1.1 root 453: if (ftp->f_type == INVISIBLE)
454: continue;
455: cp = (np = ftp->f_fn) + strlen(ftp->f_fn) - 1;
456: och = *cp;
457: *cp = '\0';
458: fprintf(f, "%so: ../%s%c\n", tail(np), np, och);
459: tp = tail(np);
460: if (och == 's') {
461: fprintf(f, "\t${AS} -o %so ../%ss\n\n", tp, np);
462: continue;
463: }
464: if (och == 'x') {
465: fprintf(f, "\t/lib/cpp ../%sx | ${AS} -o %so\n", np, tp);
466: fprintf(f, "\t${LD} -x -r %so \n", tp);
467: fprintf(f, "\tmv a.out %so \n\n", tp);
468: continue;
469: }
470: if (ftp->f_flags & CONFIGDEP)
471: extras = "${PARAM} ";
472: else
473: extras = "";
474: switch (ftp->f_type) {
475:
476: case NORMAL:
477: switch (machine) {
478:
479: case MACHINE_VAX:
480: fprintf(f, "\t${CC} -I. -c -S ${COPTS} %s../%sc\n",
481: extras, np);
482: fprintf(f, "\t${C2} %ss | sed -f ../%s/asm.sed |",
483: tp, machinename);
484: fprintf(f, " ${AS} -o %so\n", tp);
485: fprintf(f, "\trm -f %ss\n\n", tp);
486: break;
487:
488: case MACHINE_SUN:
489: case MACHINE_TAHOE:
490: fprintf(f, "\t${CC} -I. -c -O ${COPTS} %s../%sc\n\n",
491: extras, np);
492: break;
493: }
494: break;
495:
496: case DRIVER:
497: switch (machine) {
498:
499: case MACHINE_VAX:
500: fprintf(f, "\t${CC} -I. -c -S ${COPTS} %s../%sc\n",
501: extras, np);
502: fprintf(f,"\t${C2} -i %ss | sed -f ../%s/asm.sed |",
503: tp, machinename);
504: fprintf(f, " ${AS} -o %so\n", tp);
505: fprintf(f, "\trm -f %ss\n\n", tp);
506: break;
507:
508: case MACHINE_SUN:
509: case MACHINE_TAHOE:
510: fprintf(f, "\t${CC} -I. -c -O ${COPTS} %s../%sc\n\n",
511: extras, np);
512: }
513: break;
514:
515: case PROFILING:
516: if (!profiling)
517: continue;
518: if (COPTS == 0) {
519: fprintf(stderr,
520: "config: COPTS undefined in generic makefile");
521: COPTS = "";
522: }
523: switch (machine) {
524:
525: case MACHINE_VAX:
526: fprintf(f, "\t${CC} -I. -c -S %s %s../%sc\n",
527: COPTS, extras, np);
528: fprintf(f, "\tex - %ss < ${GPROF.EX}\n", tp);
529: fprintf(f,
530: "\tsed -f ../vax/asm.sed %ss | ${AS} -o %so\n",
531: tp, tp);
532: fprintf(f, "\trm -f %ss\n\n", tp);
533: break;
534:
535: case MACHINE_TAHOE:
536: fprintf(f, "\t${CC} -I. -c -S %s %s../%sc\n",
537: COPTS, extras, np);
538: fprintf(f, "\tex - %ss < ${GPROF.EX}\n", tp);
539: fprintf(f, "\trm -f %ss\n\n", tp);
540: break;
541:
542: case MACHINE_SUN:
543: fprintf(stderr,
544: "config: don't know how to profile kernel on sun\n");
545: break;
546: }
547: break;
548:
549: default:
550: printf("Don't know rules for %s\n", np);
551: break;
552: }
553: *cp = och;
554: }
555: }
556:
557: /*
558: * Create the load strings
559: */
560: do_load(f)
561: register FILE *f;
562: {
563: register struct file_list *fl;
564: int first = 1;
565: struct file_list *do_systemspec();
566:
567: fl = conf_list;
568: while (fl) {
569: if (fl->f_type != SYSTEMSPEC) {
570: fl = fl->f_next;
571: continue;
572: }
573: fl = do_systemspec(f, fl, first);
574: if (first)
575: first = 0;
576: }
577: fprintf(f, "all:");
578: for (fl = conf_list; fl != 0; fl = fl->f_next)
579: if (fl->f_type == SYSTEMSPEC)
580: fprintf(f, " %s", fl->f_needs);
581: fprintf(f, "\n");
582: }
583:
584: struct file_list *
585: do_systemspec(f, fl, first)
586: FILE *f;
587: register struct file_list *fl;
588: int first;
589: {
590:
1.1.1.2 ! root 591: fprintf(f, "%s: makefile locore.o ${OBJS} ${MOBJS} param.o", fl->f_needs);
1.1 root 592: fprintf(f, " ioconf.o swap%s.o sys5_name.o ${LIBSYS}\n", fl->f_fn);
593: fprintf(f, "\t@echo loading %s\n\t@rm -f %s\n",
594: fl->f_needs, fl->f_needs);
595: if (first) {
596: fprintf(f, "\t@sh ../conf/newvers.sh\n");
597: fprintf(f, "\t@${CC} $(CFLAGS) -c vers.c\n");
598: }
599: switch (machine) {
600:
601: case MACHINE_TAHOE:
602: fprintf(f, "\t@${LD} -n -o %s -e start -x -T C0000800 ",
603: fl->f_needs);
604: break;
605:
606: case MACHINE_VAX:
607: fprintf(f, "\t@${LD} -n -o %s -e start -x -T 80000000 ",
608: fl->f_needs);
609: break;
610:
611: case MACHINE_SUN:
612: fprintf(f, "\t@${LD} -o %s -e start -x -T 4000 ",
613: fl->f_needs);
614: break;
615: }
1.1.1.2 ! root 616: fprintf(f, "locore.o ${OBJS} ${MOBJS} vers.o ioconf.o param.o ");
1.1 root 617: fprintf(f, "swap%s.o sys5_name.o ${LIBSYS}\n", fl->f_fn);
618: fprintf(f, "\t@echo rearranging symbols\n");
619: if ( machine == MACHINE_TAHOE)
620: fprintf(f, "\t@-symorder ../%s/symbols.sort %s\n",
621: "machine", fl->f_needs);
622: else
623: fprintf(f, "\t@-symorder ../%s/symbols.sort %s\n",
624: machinename, fl->f_needs);
625: fprintf(f, "\t@size %s\n", fl->f_needs);
626: fprintf(f, "\t@chmod 755 %s\n\n", fl->f_needs);
627: do_swapspec(f, fl->f_fn);
628: for (fl = fl->f_next; fl->f_type == SWAPSPEC; fl = fl->f_next)
629: ;
630: return (fl);
631: }
632:
633: do_swapspec(f, name)
634: FILE *f;
635: register char *name;
636: {
637:
638: if (!eq(name, "generic")) {
639: fprintf(f, "swap%s.o: swap%s.c\n", name, name);
640: fprintf(f, "\t${CC} -I. -c -O ${COPTS} swap%s.c\n\n", name);
641: return;
642: }
643: fprintf(f, "swapgeneric.o: ../%s/swapgeneric.c\n", machinename);
644: switch (machine) {
645:
646: case MACHINE_VAX:
647: fprintf(f, "\t${CC} -I. -c -S ${COPTS} ");
648: fprintf(f, "../%s/swapgeneric.c\n", machinename);
649: fprintf(f, "\t${C2} swapgeneric.s | sed -f ../%s/asm.sed",
650: machinename);
651: fprintf(f, " | ${AS} -o swapgeneric.o\n");
652: fprintf(f, "\trm -f swapgeneric.s\n\n");
653: break;
654:
655: case MACHINE_TAHOE:
656: case MACHINE_SUN:
657: fprintf(f, "\t${CC} -I. -c -O ${COPTS} ");
658: fprintf(f, "../%s/swapgeneric.c\n\n", machinename);
659: break;
660: }
661: }
662:
663: char *
664: raise(str)
665: register char *str;
666: {
667: register char *cp = str;
668:
669: while (*str) {
670: if (islower(*str))
671: *str = toupper(*str);
672: str++;
673: }
674: return (cp);
675: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.