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