Commit | Line | Data |
---|---|---|
01d17851 MT |
1 | /* |
2 | * mkmakefile.c 1.1 81/02/24 | |
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 "y.tab.h" | |
9 | #include "config.h" | |
10 | ||
11 | #define next_word(fp, wd)\ | |
12 | { register char *word = get_word(fp);\ | |
13 | if (word == EOF) return EOF; \ | |
14 | else wd = word; } | |
15 | ||
16 | static struct file_list *fcur; | |
17 | ||
18 | /* | |
19 | * fl_lookup | |
20 | * look up a file name | |
21 | */ | |
22 | ||
23 | struct file_list *fl_lookup(file) | |
24 | register char *file; | |
25 | { | |
26 | register struct file_list *fp; | |
27 | ||
28 | for (fp = ftab ; fp != NULL; fp = fp->f_next) | |
29 | { | |
30 | if (eq(fp->f_fn, file)) | |
31 | return fp; | |
32 | } | |
33 | return NULL; | |
34 | } | |
35 | ||
36 | /* | |
37 | * new_fent | |
38 | * Make a new file list entry | |
39 | */ | |
40 | ||
41 | struct file_list *new_fent() | |
42 | { | |
43 | register struct file_list *fp; | |
44 | ||
45 | fp = (struct file_list *) malloc(sizeof *fp); | |
46 | fp->f_needs = fp->f_next = NULL; | |
47 | if (fcur == NULL) | |
48 | fcur = ftab = fp; | |
49 | else | |
50 | fcur->f_next = fp; | |
51 | fcur = fp; | |
52 | return fp; | |
53 | } | |
54 | ||
55 | /* | |
56 | * makefile: | |
57 | * Build the makefile from the skeleton | |
58 | */ | |
59 | ||
60 | makefile() | |
61 | { | |
62 | FILE *ifp, *ofp; | |
63 | char line[80]; | |
64 | ||
65 | read_files(); /* Read in the "files" file */ | |
66 | ifp = fopen(path(makefile), "r"); | |
67 | ofp = fopen(path(Makefile), "w"); | |
68 | while(fgets(line, 80, ifp) != NULL) | |
69 | { | |
70 | if (*line != '%') | |
71 | { | |
72 | fprintf(ofp, "%s", line); | |
73 | continue; | |
74 | } | |
75 | else if (eq(line, "%OBJS\n")) | |
76 | do_objs(ofp); | |
77 | else if (eq(line, "%CFILES\n")) | |
78 | do_cfiles(ofp); | |
79 | else if (eq(line, "%RULES\n")) | |
80 | do_rules(ofp); | |
81 | else if (eq(line, "%LOAD\n")) | |
82 | do_load(ofp); | |
83 | else | |
84 | fprintf(stderr, "Unknown %% thingy in generic makefile %s", line); | |
85 | } | |
86 | fclose(ifp); | |
87 | fclose(ofp); | |
88 | } | |
89 | ||
90 | /* | |
91 | * files: | |
92 | * Read in the "files" file. | |
93 | * Store it in the ftab linked list | |
94 | */ | |
95 | ||
96 | read_files() | |
97 | { | |
98 | FILE *fp; | |
99 | register struct file_list *tp; | |
100 | register struct device *dp; | |
101 | register char *wd, *this; | |
102 | int type; | |
103 | ||
104 | fp = fopen(path(files), "r"); | |
105 | ||
106 | ftab = NULL; | |
107 | while((wd = get_word(fp)) != EOF) | |
108 | { | |
109 | if (wd == NULL) | |
110 | continue; | |
111 | this = ns(wd); | |
112 | /* | |
113 | * Read standard/optional | |
114 | */ | |
115 | next_word(fp, wd); | |
116 | if (wd == NULL) | |
117 | { | |
118 | fprintf(stderr, "Huh, no type for %s in files.\n", this); | |
119 | exit(10); | |
120 | } | |
121 | if ((tp = fl_lookup(wd)) == NULL) | |
122 | tp = new_fent(); | |
123 | else | |
124 | free(tp->f_fn); | |
125 | tp->f_fn = this; | |
126 | type = 0; | |
127 | if (eq(wd, "optional")) | |
128 | { | |
129 | next_word(fp, wd); | |
130 | if (wd == NULL) | |
131 | { | |
132 | fprintf(stderr, "Needed a dev for optional(%s)\n", this); | |
133 | exit(11); | |
134 | } | |
135 | tp->f_needs = ns(wd); | |
136 | for (dp = dtab ; dp != NULL; dp = dp->d_next) | |
137 | { | |
138 | if (eq(dp->d_name, wd)) | |
139 | break; | |
140 | } | |
141 | if (dp == NULL) | |
142 | type = INVISIBLE; | |
143 | } | |
144 | next_word(fp, wd); | |
145 | if (type == 0 && wd != NULL) | |
146 | type = DEVICE; | |
147 | else if (type == 0) | |
148 | type = NORMAL; | |
149 | tp->f_type = type; | |
150 | } | |
151 | fclose(fp); | |
152 | } | |
153 | ||
154 | /* | |
155 | * do_objs | |
156 | * Spew forth the OBJS definition | |
157 | */ | |
158 | ||
159 | do_objs(fp) | |
160 | FILE *fp; | |
161 | { | |
162 | register struct file_list *tp; | |
163 | register int lpos, len; | |
164 | register char *cp, och; | |
165 | ||
166 | fprintf(fp, "OBJS="); | |
167 | lpos = 6; | |
168 | for (tp = ftab; tp != NULL; tp = tp->f_next) | |
169 | { | |
170 | if (tp->f_type == INVISIBLE) | |
171 | continue; | |
172 | cp = tp->f_fn + (len = strlen(tp->f_fn)) - 1; | |
173 | och = *cp; | |
174 | *cp = 'o'; | |
175 | if (len + lpos > 72) | |
176 | { | |
177 | lpos = 8; | |
178 | fprintf(fp, "\\\n\t"); | |
179 | } | |
180 | fprintf(fp, "%s ", tp->f_fn); | |
181 | lpos += len + 1; | |
182 | *cp = och; | |
183 | } | |
184 | if (lpos != 8) | |
185 | putc('\n', fp); | |
186 | } | |
187 | ||
188 | /* | |
189 | * do_cfiles | |
190 | * Spew forth the CFILES definition | |
191 | */ | |
192 | ||
193 | do_cfiles(fp) | |
194 | FILE *fp; | |
195 | { | |
196 | register struct file_list *tp; | |
197 | register int lpos, len; | |
198 | ||
199 | fprintf(fp, "CFILES="); | |
200 | lpos = 8; | |
201 | for (tp = ftab; tp != NULL; tp = tp->f_next) | |
202 | { | |
203 | if (tp->f_type == INVISIBLE) | |
204 | continue; | |
205 | if ((len = strlen(tp->f_fn)) + lpos > 72) | |
206 | { | |
207 | lpos = 8; | |
208 | fprintf(fp, "\\\n\t"); | |
209 | } | |
210 | fprintf(fp, "%s ", tp->f_fn); | |
211 | lpos += len + 1; | |
212 | } | |
213 | if (lpos != 8) | |
214 | putc('\n', fp); | |
215 | } | |
216 | ||
217 | /* | |
218 | * tail: | |
219 | * Return tail end of a filename | |
220 | */ | |
221 | ||
222 | char *tail(fn) | |
223 | char *fn; | |
224 | { | |
225 | register char *cp; | |
226 | ||
227 | cp = rindex(fn, '/'); | |
228 | return cp+1; | |
229 | } | |
230 | ||
231 | /* | |
232 | * do_rules: | |
233 | * Spit out the rules for making each file | |
234 | */ | |
235 | ||
236 | do_rules(f) | |
237 | FILE *f; | |
238 | { | |
239 | register char *cp, *np, och, *tp; | |
240 | register struct file_list *ftp; | |
241 | ||
242 | for (ftp = ftab; ftp != NULL; ftp = ftp->f_next) | |
243 | { | |
244 | if (ftp->f_type == INVISIBLE) | |
245 | continue; | |
246 | cp = (np = ftp->f_fn) + strlen(ftp->f_fn) - 1; | |
247 | och = *cp; | |
248 | *cp = '\0'; | |
249 | fprintf(f, "%so: ../%s%c\n", tail(np), np, och); | |
250 | tp = tail(np); | |
251 | if (och == 's') | |
252 | fprintf(f, "\t${AS} -o %so ../%ss\n\n", tp, np); | |
253 | else if (ftp->f_type == NORMAL) | |
254 | { | |
255 | fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../%sc\n", np); | |
256 | fprintf(f, "\t${C2} %ss | sed -f ../sys/asm.sed | ${AS} -o %so\n", | |
257 | tp, tp); | |
258 | fprintf(f, "\trm -f %ss\n\n", tp); | |
259 | } | |
260 | else if (ftp->f_type == DEVICE) | |
261 | { | |
262 | fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../%sc\n", np); | |
263 | fprintf(f,"\t${C2} -i %ss | sed -f ../sys/asm.sed | ${AS} -o %so\n", | |
264 | tp, tp); | |
265 | fprintf(f, "\trm -f %ss\n\n", tp); | |
266 | } | |
267 | else | |
268 | fprintf(stderr, "Don't know rules for %s", np); | |
269 | *cp = och; | |
270 | } | |
271 | } | |
272 | ||
273 | /* | |
274 | * Create the load strings | |
275 | */ | |
276 | ||
277 | do_load(f) | |
278 | register FILE *f; | |
279 | { | |
280 | register struct file_list *fl; | |
281 | ||
282 | fprintf(f, "all:"); | |
283 | for (fl = conf_list; fl != NULL; fl = fl->f_next) | |
284 | fprintf(f, " %s", fl->f_needs); | |
285 | putc('\n', f); | |
286 | for (fl = conf_list; fl != NULL; fl = fl->f_next) | |
287 | { | |
288 | fprintf(f, "\n%s: makefile locore.o ${OBJS} swap%s.o\n", | |
289 | fl->f_needs, fl->f_fn); | |
290 | fprintf(f, "\t@echo loading %s\n\t@rm -f %s\n\t", | |
291 | fl->f_needs, fl->f_needs); | |
292 | fprintf(f, | |
293 | "@ld -n -o %s -e start -x -T 80000000 locore.o ${OBJS} swap%s.o\n", | |
294 | fl->f_needs, fl->f_fn); | |
295 | fprintf(f, "\t@echo rearranging symbols\n"); | |
296 | fprintf(f, "\t@-symorder ../conf/symbols.sort %s\n", fl->f_needs); | |
297 | fprintf(f, "\t@size %s\n", fl->f_needs); | |
298 | fprintf(f, "\t@chmod 755 %s\n", fl->f_needs); | |
299 | } | |
300 | for (fl = conf_list; fl != NULL; fl = fl->f_next) | |
301 | { | |
302 | fprintf(f, "\nswap%s.o: ../conf/swap%s.c\n", fl->f_fn, fl->f_fn); | |
303 | fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../conf/swap%s.c\n", fl->f_fn); | |
304 | fprintf(f, | |
305 | "\t${C2} swap%s.s | sed -f ../sys/asm.sed | ${AS} -o swap%s.o\n", | |
306 | fl->f_fn, fl->f_fn); | |
307 | fprintf(f, "\trm -f swap%s.s\n", fl->f_fn); | |
308 | } | |
309 | } |