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