|
|
1.1 root 1: /*
2: * mkmakefile.c 1.10 81/05/18
3: * Functions in this file build the makefile from the files list
4: * and the information in the config table
5: */
6:
7: #include <stdio.h>
8: #include <ctype.h>
9: #include "y.tab.h"
10: #include "config.h"
11:
12: char *mkfile = "makefile";
13:
14: #define next_word(fp, wd)\
15: { register char *word = get_word(fp);\
16: if (word == WEOF) return EOF; \
17: else wd = word; }
18:
19: static struct file_list *fcur;
20:
21: /*
22: * fl_lookup
23: * look up a file name
24: */
25:
26: struct file_list *fl_lookup(file)
27: register char *file;
28: {
29: register struct file_list *fp;
30:
31: for (fp = ftab ; fp != NULL; fp = fp->f_next)
32: {
33: if (eq(fp->f_fn, file))
34: return fp;
35: }
36: return NULL;
37: }
38:
39: /*
40: * new_fent
41: * Make a new file list entry
42: */
43:
44: struct file_list *new_fent()
45: {
46: register struct file_list *fp;
47:
48: fp = (struct file_list *) malloc(sizeof *fp);
49: fp->f_needs = NULL;
50: fp->f_next = NULL;
51: if (fcur == NULL)
52: fcur = ftab = fp;
53: else
54: fcur->f_next = fp;
55: fcur = fp;
56: return fp;
57: }
58:
59: /*
60: * makefile:
61: * Build the makefile from the skeleton
62: */
63:
64: makefile()
65: {
66: FILE *ifp, *ofp;
67: char line[BUFSIZ];
68: struct cputype *cp;
69: struct opt *op;
70: char *raise();
71:
72: read_files(); /* Read in the "files" file */
73: ifp = fopen(GLOBAL(mkfile), "r");
74: if (ifp == NULL) {
75: perror(GLOBAL("makefile"));
76: exit(1);
77: }
78: ofp = fopen(LOCAL("makefile"), "w");
79: if (ofp == NULL) {
80: perror(LOCAL("makefile"));
81: exit(1);
82: }
83: fprintf(ofp, "IDENT=-D%s", raise(ident));
84: if (cputype == NULL) {
85: printf("cpu type must be specified\n");
86: exit(1);
87: }
88: for (cp = cputype; cp; cp = cp->cpu_next)
89: fprintf(ofp, " -D%s", cp->cpu_name);
90: for (op = opt; op; op = op->op_next)
91: fprintf(ofp, " -D%s", op->op_name);
92: fprintf(ofp, "\n");
93: if (hz == 0) {
94: #ifdef notdef
95: printf("hz not specified; 50hz assumed\n");
96: #endif
97: hz = 60;
98: }
99: if (hadtz == 0)
100: printf("timezone not specified; gmt assumed\n");
101: if (maxusers == 0) {
102: printf("maxusers not specified; 24 assumed\n");
103: maxusers = 24;
104: } else if (maxusers < 8) {
105: printf("minimum of 8 maxusers assumed\n");
106: maxusers = 8;
107: } else if (maxusers > 128) {
108: printf("maxusers truncated to 128\n");
109: maxusers = 128;
110: }
111: fprintf(ofp, "PARAM=-DHZ=%d -DTIMEZONE=%d -DDST=%d -DMAXUSERS=%d\n",
112: hz, timezone, dst, maxusers);
113: while(fgets(line, BUFSIZ, ifp) != NULL)
114: {
115: if (*line != '%')
116: {
117: fprintf(ofp, "%s", line);
118: continue;
119: }
120: else if (eq(line, "%OBJS\n"))
121: do_objs(ofp);
122: else if (eq(line, "%CFILES\n"))
123: do_cfiles(ofp);
124: else if (eq(line, "%RULES\n"))
125: do_rules(ofp);
126: else if (eq(line, "%LOAD\n"))
127: do_load(ofp);
128: else
129: fprintf(stderr, "Unknown %% construct in generic makefile: %s", line);
130: }
131: fclose(ifp);
132: fclose(ofp);
133: }
134:
135: /*
136: * files:
137: * Read in the "files" file.
138: * Store it in the ftab linked list
139: */
140:
141: read_files()
142: {
143:
144: ftab = NULL;
145: read_files_file(GLOBAL("files"), TRUE);
146: read_files_file(LOCAL("files"), FALSE);
147: }
148:
149: read_files_file(filename, must_exist)
150: char *filename;
151: {
152: FILE *fp;
153: register struct file_list *tp;
154: register struct device *dp;
155: register char *wd, *this;
156: int type;
157:
158: fp = fopen(filename, "r");
159: if (fp == NULL) {
160: if (must_exist) {
161: perror(filename);
162: exit(1);
163: } else
164: return;
165: }
166: while((wd = get_word(fp)) != WEOF)
167: {
168: if (wd == NULL)
169: continue;
170: this = ns(wd);
171: /*
172: * Read standard/optional
173: */
174: next_word(fp, wd);
175: if (wd == NULL)
176: {
177: fprintf(stderr, "Huh, no type for %s in files.\n", this);
178: exit(10);
179: }
180: if ((tp = fl_lookup(wd)) == NULL)
181: tp = new_fent();
182: else
183: free(tp->f_fn);
184: tp->f_fn = this;
185: type = 0;
186: if (eq(wd, "optional"))
187: {
188: next_word(fp, wd);
189: if (wd == NULL)
190: {
191: fprintf(stderr, "Needed a dev for optional(%s)\n", this);
192: exit(11);
193: }
194: tp->f_needs = ns(wd);
195: for (dp = dtab ; dp != NULL; dp = dp->d_next)
196: {
197: if (eq(dp->d_name, wd))
198: break;
199: }
200: if (dp == NULL)
201: type = INVISIBLE;
202: }
203: next_word(fp, wd);
204: if (type == 0 && wd != NULL)
205: type = DEVICE;
206: else if (type == 0)
207: type = NORMAL;
208: tp->f_type = type;
209: }
210: fclose(fp);
211: }
212:
213: /*
214: * do_objs
215: * Spew forth the OBJS definition
216: */
217:
218: do_objs(fp)
219: FILE *fp;
220: {
221: register struct file_list *tp;
222: register int lpos, len;
223: register char *cp, och, *sp;
224: char *tail();
225:
226: fprintf(fp, "OBJS=");
227: lpos = 6;
228: for (tp = ftab; tp != NULL; tp = tp->f_next)
229: {
230: if (tp->f_type == INVISIBLE)
231: continue;
232: sp = tail(tp->f_fn);
233: cp = sp + (len = strlen(sp)) - 1;
234: och = *cp;
235: *cp = 'o';
236: if (len + lpos > 72)
237: {
238: lpos = 8;
239: fprintf(fp, "\\\n\t");
240: }
241: fprintf(fp, "%s ", sp);
242: lpos += len + 1;
243: *cp = och;
244: }
245: if (lpos != 8)
246: putc('\n', fp);
247: }
248:
249: /*
250: * do_cfiles
251: * Spew forth the CFILES definition
252: */
253:
254: do_cfiles(fp)
255: FILE *fp;
256: {
257: register struct file_list *tp;
258: register int lpos, len;
259:
260: fprintf(fp, "CFILES=");
261: lpos = 8;
262: for (tp = ftab; tp != NULL; tp = tp->f_next)
263: {
264: if (tp->f_type == INVISIBLE)
265: continue;
266: if (tp->f_fn[strlen(tp->f_fn)-1] != 'c')
267: continue;
268: if ((len = 3 + strlen(tp->f_fn)) + lpos > 72)
269: {
270: lpos = 8;
271: fprintf(fp, "\\\n\t");
272: }
273: fprintf(fp, "../%s ", tp->f_fn);
274: lpos += len + 1;
275: }
276: if (lpos != 8)
277: putc('\n', fp);
278: }
279:
280: /*
281: * tail:
282: * Return tail end of a filename
283: */
284:
285: char *tail(fn)
286: char *fn;
287: {
288: register char *cp;
289: char *strrchr();
290:
291: cp = strrchr(fn, '/');
292: return cp+1;
293: }
294:
295: /*
296: * do_rules:
297: * Spit out the rules for making each file
298: */
299:
300: do_rules(f)
301: FILE *f;
302: {
303: register char *cp, *np, och, *tp;
304: register struct file_list *ftp;
305:
306: for (ftp = ftab; ftp != NULL; ftp = ftp->f_next)
307: {
308: if (ftp->f_type == INVISIBLE)
309: continue;
310: cp = (np = ftp->f_fn) + strlen(ftp->f_fn) - 1;
311: och = *cp;
312: *cp = '\0';
313: fprintf(f, "%so: ../%s%c\n", tail(np), np, och);
314: tp = tail(np);
315: if (och == 's')
316: fprintf(f, "\t${AS} -o %so ../%ss\n\n", tp, np);
317: else if (ftp->f_type == NORMAL)
318: {
319: fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../%sc\n", np);
320: fprintf(f, "\t${C2} %ss | sed -f ../sys/asm.sed | ${AS} -o %so\n",
321: tp, tp);
322: fprintf(f, "\trm -f %ss\n\n", tp);
323: }
324: else if (ftp->f_type == DEVICE)
325: {
326: fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../%sc\n", np);
327: fprintf(f,"\t${C2} -i %ss | sed -f ../sys/asm.sed | ${AS} -o %so\n",
328: tp, tp);
329: fprintf(f, "\trm -f %ss\n\n", tp);
330: }
331: else
332: fprintf(stderr, "Don't know rules for %s", np);
333: *cp = och;
334: }
335: }
336:
337: /*
338: * Create the load strings
339: */
340:
341: do_load(f)
342: register FILE *f;
343: {
344: register struct file_list *fl;
345: register bool first = TRUE;
346:
347: for (fl = conf_list; fl != NULL; fl = fl->f_next)
348: {
349: fprintf(f, "%s: makefile locore.o ${OBJS} ${EMULO} ioconf.o conf.o param.o swap%s.o\n",
350: fl->f_needs, fl->f_fn);
351: fprintf(f, "\t@echo loading %s\n\t@rm -f %s\n",
352: fl->f_needs, fl->f_needs);
353: if (first)
354: {
355: first = FALSE;
356: fprintf(f, "\t@sh ../conf/newvers.sh\n");
357: fprintf(f, "\t@cc $(CFLAGS) -c vers.c\n");
358: }
359: fprintf(f,
360: "\t@ld -n -o %s -e start -x -T 80000000 locore.o ${OBJS} ${EMULO} vers.o ioconf.o conf.o param.o swap%s.o\n",
361: fl->f_needs, fl->f_fn);
362: fprintf(f, "\t@size %s\n", fl->f_needs);
363: fprintf(f, "\t@chmod 755 %s\n\n", fl->f_needs);
364: }
365: for (fl = conf_list; fl != NULL; fl = fl->f_next)
366: {
367: fprintf(f, "swap%s.o: ../dev/swap%s.c\n", fl->f_fn, fl->f_fn);
368: fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../dev/swap%s.c\n", fl->f_fn);
369: fprintf(f,
370: "\t${C2} swap%s.s | sed -f ../sys/asm.sed | ${AS} -o swap%s.o\n",
371: fl->f_fn, fl->f_fn);
372: fprintf(f, "\trm -f swap%s.s\n\n", fl->f_fn);
373: }
374: fprintf(f, "all:");
375: for (fl = conf_list; fl != NULL; fl = fl->f_next)
376: fprintf(f, " %s", fl->f_needs);
377: putc('\n', f);
378: }
379:
380: char *
381: raise(str)
382: register char *str;
383: {
384: register char *cp = str;
385:
386: while(*str)
387: {
388: if (islower(*str))
389: *str = toupper(*str);
390: str++;
391: }
392: return cp;
393: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.