mkmakefile.c revision 1.20 1 1.18 uebayasi /* $NetBSD: mkmakefile.c,v 1.20 2014/10/09 17:36:10 uebayasi Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (c) 1992, 1993
5 1.1 thorpej * The Regents of the University of California. All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This software was developed by the Computer Systems Engineering group
8 1.1 thorpej * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 1.1 thorpej * contributed to Berkeley.
10 1.1 thorpej *
11 1.1 thorpej * All advertising materials mentioning features or use of this software
12 1.1 thorpej * must display the following acknowledgement:
13 1.1 thorpej * This product includes software developed by the University of
14 1.1 thorpej * California, Lawrence Berkeley Laboratories.
15 1.1 thorpej *
16 1.1 thorpej * Redistribution and use in source and binary forms, with or without
17 1.1 thorpej * modification, are permitted provided that the following conditions
18 1.1 thorpej * are met:
19 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
20 1.1 thorpej * notice, this list of conditions and the following disclaimer.
21 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
22 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
23 1.1 thorpej * documentation and/or other materials provided with the distribution.
24 1.1 thorpej * 3. Neither the name of the University nor the names of its contributors
25 1.1 thorpej * may be used to endorse or promote products derived from this software
26 1.1 thorpej * without specific prior written permission.
27 1.1 thorpej *
28 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 1.1 thorpej * SUCH DAMAGE.
39 1.1 thorpej *
40 1.1 thorpej * from: @(#)mkmakefile.c 8.1 (Berkeley) 6/6/93
41 1.1 thorpej */
42 1.1 thorpej
43 1.1 thorpej #if HAVE_NBTOOL_CONFIG_H
44 1.1 thorpej #include "nbtool_config.h"
45 1.1 thorpej #endif
46 1.1 thorpej
47 1.1 thorpej #include <sys/param.h>
48 1.1 thorpej #include <ctype.h>
49 1.1 thorpej #include <errno.h>
50 1.1 thorpej #include <stdio.h>
51 1.1 thorpej #include <stdlib.h>
52 1.1 thorpej #include <string.h>
53 1.6 christos #include <err.h>
54 1.1 thorpej #include "defs.h"
55 1.1 thorpej #include "sem.h"
56 1.1 thorpej
57 1.1 thorpej /*
58 1.1 thorpej * Make the Makefile.
59 1.1 thorpej */
60 1.1 thorpej
61 1.1 thorpej static const char *srcpath(struct files *);
62 1.1 thorpej
63 1.1 thorpej static const char *prefix_prologue(const char *);
64 1.2 erh static const char *filetype_prologue(struct filetype *);
65 1.2 erh
66 1.1 thorpej
67 1.5 dsl static void emitdefs(FILE *);
68 1.5 dsl static void emitfiles(FILE *, int, int);
69 1.1 thorpej
70 1.5 dsl static void emitobjs(FILE *);
71 1.18 uebayasi static void emitallkobjs(FILE *);
72 1.18 uebayasi static int emitallkobjscb(const char *, void *, void *);
73 1.18 uebayasi static void emitattrkobjs(FILE *);
74 1.18 uebayasi static int emitattrkobjscb(const char *, void *, void *);
75 1.18 uebayasi static void emitkobjs(FILE *);
76 1.5 dsl static void emitcfiles(FILE *);
77 1.5 dsl static void emitsfiles(FILE *);
78 1.5 dsl static void emitrules(FILE *);
79 1.5 dsl static void emitload(FILE *);
80 1.5 dsl static void emitincludes(FILE *);
81 1.5 dsl static void emitappmkoptions(FILE *);
82 1.8 cube static void emitsubs(FILE *, const char *, const char *, int);
83 1.11 cube static int selectopt(const char *, void *);
84 1.1 thorpej
85 1.18 uebayasi /* Generate Makefile to build things per-attribute *.ko (a.k.a modular build). */
86 1.18 uebayasi int usekobjs = 0; /* XXX */
87 1.18 uebayasi
88 1.1 thorpej int
89 1.1 thorpej mkmakefile(void)
90 1.1 thorpej {
91 1.1 thorpej FILE *ifp, *ofp;
92 1.1 thorpej int lineno;
93 1.5 dsl void (*fn)(FILE *);
94 1.1 thorpej char *ifname;
95 1.1 thorpej char line[BUFSIZ], buf[200];
96 1.1 thorpej
97 1.1 thorpej /* Try a makefile for the port first.
98 1.1 thorpej */
99 1.1 thorpej (void)snprintf(buf, sizeof(buf), "arch/%s/conf/Makefile.%s",
100 1.1 thorpej machine, machine);
101 1.1 thorpej ifname = sourcepath(buf);
102 1.1 thorpej if ((ifp = fopen(ifname, "r")) == NULL) {
103 1.1 thorpej /* Try a makefile for the architecture second.
104 1.1 thorpej */
105 1.1 thorpej (void)snprintf(buf, sizeof(buf), "arch/%s/conf/Makefile.%s",
106 1.1 thorpej machinearch, machinearch);
107 1.4 cube free(ifname);
108 1.1 thorpej ifname = sourcepath(buf);
109 1.4 cube ifp = fopen(ifname, "r");
110 1.1 thorpej }
111 1.4 cube if (ifp == NULL) {
112 1.6 christos warn("cannot read %s", ifname);
113 1.4 cube goto bad2;
114 1.1 thorpej }
115 1.5 dsl
116 1.1 thorpej if ((ofp = fopen("Makefile.tmp", "w")) == NULL) {
117 1.6 christos warn("cannot write Makefile");
118 1.4 cube goto bad1;
119 1.1 thorpej }
120 1.5 dsl
121 1.5 dsl emitdefs(ofp);
122 1.5 dsl
123 1.1 thorpej lineno = 0;
124 1.1 thorpej while (fgets(line, sizeof(line), ifp) != NULL) {
125 1.1 thorpej lineno++;
126 1.10 cube if ((version < 20090214 && line[0] != '%') || line[0] == '#') {
127 1.5 dsl fputs(line, ofp);
128 1.1 thorpej continue;
129 1.1 thorpej }
130 1.1 thorpej if (strcmp(line, "%OBJS\n") == 0)
131 1.19 uebayasi fn = usekobjs ? emitkobjs : emitobjs;
132 1.1 thorpej else if (strcmp(line, "%CFILES\n") == 0)
133 1.1 thorpej fn = emitcfiles;
134 1.1 thorpej else if (strcmp(line, "%SFILES\n") == 0)
135 1.1 thorpej fn = emitsfiles;
136 1.1 thorpej else if (strcmp(line, "%RULES\n") == 0)
137 1.1 thorpej fn = emitrules;
138 1.1 thorpej else if (strcmp(line, "%LOAD\n") == 0)
139 1.1 thorpej fn = emitload;
140 1.1 thorpej else if (strcmp(line, "%INCLUDES\n") == 0)
141 1.1 thorpej fn = emitincludes;
142 1.1 thorpej else if (strcmp(line, "%MAKEOPTIONSAPPEND\n") == 0)
143 1.1 thorpej fn = emitappmkoptions;
144 1.8 cube else if (strncmp(line, "%VERSION ", sizeof("%VERSION ")-1) == 0) {
145 1.8 cube int newvers;
146 1.8 cube if (sscanf(line, "%%VERSION %d\n", &newvers) != 1) {
147 1.8 cube cfgxerror(ifname, lineno, "syntax error for "
148 1.8 cube "%%VERSION");
149 1.8 cube } else
150 1.8 cube setversion(newvers);
151 1.8 cube continue;
152 1.8 cube } else {
153 1.8 cube if (version < 20090214)
154 1.8 cube cfgxerror(ifname, lineno,
155 1.8 cube "unknown %% construct ignored: %s", line);
156 1.8 cube else
157 1.8 cube emitsubs(ofp, line, ifname, lineno);
158 1.1 thorpej continue;
159 1.1 thorpej }
160 1.5 dsl (*fn)(ofp);
161 1.1 thorpej }
162 1.5 dsl
163 1.5 dsl fflush(ofp);
164 1.5 dsl if (ferror(ofp))
165 1.5 dsl goto wrerror;
166 1.5 dsl
167 1.1 thorpej if (ferror(ifp)) {
168 1.6 christos warn("error reading %s (at line %d)", ifname, lineno);
169 1.1 thorpej goto bad;
170 1.1 thorpej }
171 1.5 dsl
172 1.1 thorpej if (fclose(ofp)) {
173 1.1 thorpej ofp = NULL;
174 1.1 thorpej goto wrerror;
175 1.1 thorpej }
176 1.1 thorpej (void)fclose(ifp);
177 1.5 dsl
178 1.1 thorpej if (moveifchanged("Makefile.tmp", "Makefile") != 0) {
179 1.6 christos warn("error renaming Makefile");
180 1.4 cube goto bad2;
181 1.1 thorpej }
182 1.1 thorpej free(ifname);
183 1.1 thorpej return (0);
184 1.4 cube
185 1.1 thorpej wrerror:
186 1.6 christos warn("error writing Makefile");
187 1.1 thorpej bad:
188 1.1 thorpej if (ofp != NULL)
189 1.1 thorpej (void)fclose(ofp);
190 1.4 cube bad1:
191 1.4 cube (void)fclose(ifp);
192 1.1 thorpej /* (void)unlink("Makefile.tmp"); */
193 1.4 cube bad2:
194 1.1 thorpej free(ifname);
195 1.1 thorpej return (1);
196 1.1 thorpej }
197 1.1 thorpej
198 1.8 cube static void
199 1.8 cube emitsubs(FILE *fp, const char *line, const char *file, int lineno)
200 1.8 cube {
201 1.9 enami char *nextpct;
202 1.9 enami const char *optname;
203 1.8 cube struct nvlist *option;
204 1.8 cube
205 1.8 cube while (*line != '\0') {
206 1.8 cube if (*line != '%') {
207 1.8 cube fputc(*line++, fp);
208 1.8 cube continue;
209 1.8 cube }
210 1.8 cube
211 1.8 cube line++;
212 1.8 cube nextpct = strchr(line, '%');
213 1.8 cube if (nextpct == NULL) {
214 1.8 cube cfgxerror(file, lineno, "unbalanced %% or "
215 1.8 cube "unknown construct");
216 1.8 cube return;
217 1.8 cube }
218 1.8 cube *nextpct = '\0';
219 1.8 cube
220 1.8 cube if (*line == '\0')
221 1.8 cube fputc('%', fp);
222 1.8 cube else {
223 1.8 cube optname = intern(line);
224 1.8 cube if (!DEFINED_OPTION(optname)) {
225 1.8 cube cfgxerror(file, lineno, "unknown option %s",
226 1.8 cube optname);
227 1.8 cube return;
228 1.8 cube }
229 1.8 cube
230 1.8 cube if ((option = ht_lookup(opttab, optname)) == NULL)
231 1.8 cube option = ht_lookup(fsopttab, optname);
232 1.8 cube if (option != NULL)
233 1.8 cube fputs(option->nv_str ? option->nv_str : "1",
234 1.8 cube fp);
235 1.8 cube /* Otherwise it's not a selected option and we don't
236 1.8 cube * output anything. */
237 1.8 cube }
238 1.8 cube
239 1.8 cube line = nextpct+1;
240 1.8 cube }
241 1.8 cube }
242 1.8 cube
243 1.1 thorpej /*
244 1.1 thorpej * Return (possibly in a static buffer) the name of the `source' for a
245 1.1 thorpej * file. If we have `options source', or if the file is marked `always
246 1.1 thorpej * source', this is always the path from the `file' line; otherwise we
247 1.1 thorpej * get the .o from the obj-directory.
248 1.1 thorpej */
249 1.1 thorpej static const char *
250 1.1 thorpej srcpath(struct files *fi)
251 1.1 thorpej {
252 1.1 thorpej #if 1
253 1.1 thorpej /* Always have source, don't support object dirs for kernel builds. */
254 1.1 thorpej return (fi->fi_path);
255 1.1 thorpej #else
256 1.1 thorpej static char buf[MAXPATHLEN];
257 1.1 thorpej
258 1.1 thorpej if (have_source || (fi->fi_flags & FI_ALWAYSSRC) != 0)
259 1.1 thorpej return (fi->fi_path);
260 1.1 thorpej if (objpath == NULL) {
261 1.6 christos cfgerror("obj-directory not set");
262 1.1 thorpej return (NULL);
263 1.1 thorpej }
264 1.1 thorpej (void)snprintf(buf, sizeof buf, "%s/%s.o", objpath, fi->fi_base);
265 1.1 thorpej return (buf);
266 1.1 thorpej #endif
267 1.1 thorpej }
268 1.1 thorpej
269 1.1 thorpej static const char *
270 1.2 erh filetype_prologue(struct filetype *fit)
271 1.2 erh {
272 1.2 erh if (fit->fit_flags & FIT_NOPROLOGUE || *fit->fit_path == '/')
273 1.2 erh return ("");
274 1.2 erh else
275 1.2 erh return ("$S/");
276 1.2 erh }
277 1.2 erh
278 1.2 erh static const char *
279 1.1 thorpej prefix_prologue(const char *path)
280 1.1 thorpej {
281 1.1 thorpej if (*path == '/')
282 1.1 thorpej return ("");
283 1.1 thorpej else
284 1.1 thorpej return ("$S/");
285 1.1 thorpej }
286 1.1 thorpej
287 1.5 dsl static void
288 1.1 thorpej emitdefs(FILE *fp)
289 1.1 thorpej {
290 1.1 thorpej struct nvlist *nv;
291 1.13 lukem const char *sp;
292 1.1 thorpej
293 1.5 dsl fprintf(fp, "KERNEL_BUILD=%s\n", conffile);
294 1.5 dsl fputs("IDENT=", fp);
295 1.1 thorpej sp = "";
296 1.1 thorpej for (nv = options; nv != NULL; nv = nv->nv_next) {
297 1.1 thorpej
298 1.1 thorpej /* skip any options output to a header file */
299 1.1 thorpej if (DEFINED_OPTION(nv->nv_name))
300 1.1 thorpej continue;
301 1.5 dsl fprintf(fp, "%s-D%s", sp, nv->nv_name);
302 1.1 thorpej if (nv->nv_str)
303 1.5 dsl fprintf(fp, "=\"%s\"", nv->nv_str);
304 1.1 thorpej sp = " ";
305 1.1 thorpej }
306 1.5 dsl putc('\n', fp);
307 1.5 dsl fprintf(fp, "PARAM=-DMAXUSERS=%d\n", maxusers);
308 1.5 dsl fprintf(fp, "MACHINE=%s\n", machine);
309 1.1 thorpej if (*srcdir == '/' || *srcdir == '.') {
310 1.5 dsl fprintf(fp, "S=\t%s\n", srcdir);
311 1.1 thorpej } else {
312 1.1 thorpej /*
313 1.1 thorpej * libkern and libcompat "Makefile.inc"s want relative S
314 1.1 thorpej * specification to begin with '.'.
315 1.1 thorpej */
316 1.5 dsl fprintf(fp, "S=\t./%s\n", srcdir);
317 1.1 thorpej }
318 1.1 thorpej for (nv = mkoptions; nv != NULL; nv = nv->nv_next)
319 1.5 dsl fprintf(fp, "%s=%s\n", nv->nv_name, nv->nv_str);
320 1.1 thorpej }
321 1.1 thorpej
322 1.5 dsl static void
323 1.1 thorpej emitobjs(FILE *fp)
324 1.1 thorpej {
325 1.1 thorpej struct files *fi;
326 1.1 thorpej struct objects *oi;
327 1.1 thorpej
328 1.20 uebayasi fputs("OBJS= \\\n", fp);
329 1.1 thorpej TAILQ_FOREACH(fi, &allfiles, fi_next) {
330 1.1 thorpej if ((fi->fi_flags & FI_SEL) == 0)
331 1.1 thorpej continue;
332 1.20 uebayasi fprintf(fp, "\t%s.o \\\n", fi->fi_base);
333 1.1 thorpej }
334 1.1 thorpej TAILQ_FOREACH(oi, &allobjects, oi_next) {
335 1.1 thorpej if ((oi->oi_flags & OI_SEL) == 0)
336 1.1 thorpej continue;
337 1.1 thorpej if (*oi->oi_path == '/') {
338 1.20 uebayasi fprintf(fp, "\t%s \\\n", oi->oi_path);
339 1.1 thorpej } else {
340 1.1 thorpej if (oi->oi_prefix != NULL) {
341 1.20 uebayasi fprintf(fp, "\t%s%s/%s \\\n",
342 1.5 dsl prefix_prologue(oi->oi_path),
343 1.5 dsl oi->oi_prefix, oi->oi_path);
344 1.1 thorpej } else {
345 1.20 uebayasi fprintf(fp, "\t%s%s \\\n",
346 1.2 erh filetype_prologue(&oi->oi_fit),
347 1.5 dsl oi->oi_path);
348 1.1 thorpej }
349 1.1 thorpej }
350 1.1 thorpej }
351 1.5 dsl putc('\n', fp);
352 1.1 thorpej }
353 1.1 thorpej
354 1.5 dsl static void
355 1.18 uebayasi emitkobjs(FILE *fp)
356 1.18 uebayasi {
357 1.18 uebayasi emitallkobjs(fp);
358 1.18 uebayasi emitattrkobjs(fp);
359 1.18 uebayasi }
360 1.18 uebayasi
361 1.18 uebayasi static void
362 1.18 uebayasi emitallkobjs(FILE *fp)
363 1.18 uebayasi {
364 1.18 uebayasi
365 1.18 uebayasi fputs("OBJS=", fp);
366 1.18 uebayasi ht_enumerate(attrtab, emitallkobjscb, fp);
367 1.18 uebayasi putc('\n', fp);
368 1.18 uebayasi }
369 1.18 uebayasi
370 1.18 uebayasi static int
371 1.18 uebayasi emitallkobjscb(const char *name, void *v, void *arg)
372 1.18 uebayasi {
373 1.18 uebayasi struct attr *a = v;
374 1.18 uebayasi FILE *fp = arg;
375 1.18 uebayasi
376 1.18 uebayasi if (ht_lookup(selecttab, name) == NULL)
377 1.18 uebayasi return 0;
378 1.18 uebayasi if (TAILQ_EMPTY(&a->a_files))
379 1.18 uebayasi return 0;
380 1.18 uebayasi fprintf(fp, " %s.ko", name);
381 1.18 uebayasi return 0;
382 1.18 uebayasi }
383 1.18 uebayasi
384 1.18 uebayasi static void
385 1.18 uebayasi emitattrkobjs(FILE *fp)
386 1.18 uebayasi {
387 1.18 uebayasi extern struct hashtab *attrtab;
388 1.18 uebayasi
389 1.18 uebayasi ht_enumerate(attrtab, emitattrkobjscb, fp);
390 1.18 uebayasi }
391 1.18 uebayasi
392 1.18 uebayasi static int
393 1.18 uebayasi emitattrkobjscb(const char *name, void *v, void *arg)
394 1.18 uebayasi {
395 1.18 uebayasi struct attr *a = v;
396 1.18 uebayasi struct files *fi;
397 1.18 uebayasi FILE *fp = arg;
398 1.18 uebayasi
399 1.18 uebayasi if (ht_lookup(selecttab, name) == NULL)
400 1.18 uebayasi return 0;
401 1.18 uebayasi if (TAILQ_EMPTY(&a->a_files))
402 1.18 uebayasi return 0;
403 1.18 uebayasi fputc('\n', fp);
404 1.18 uebayasi fprintf(fp, "OBJS.%s=", name);
405 1.18 uebayasi TAILQ_FOREACH(fi, &a->a_files, fi_anext) {
406 1.18 uebayasi fprintf(fp, " %s.o", fi->fi_base);
407 1.18 uebayasi }
408 1.18 uebayasi fputc('\n', fp);
409 1.18 uebayasi fprintf(fp, "%s.ko: ${OBJS.%s}\n", name, name);
410 1.18 uebayasi fprintf(fp, "\t${LINK_O}\n");
411 1.18 uebayasi return 0;
412 1.18 uebayasi }
413 1.18 uebayasi
414 1.18 uebayasi static void
415 1.1 thorpej emitcfiles(FILE *fp)
416 1.1 thorpej {
417 1.1 thorpej
418 1.5 dsl emitfiles(fp, 'c', 0);
419 1.1 thorpej }
420 1.1 thorpej
421 1.5 dsl static void
422 1.1 thorpej emitsfiles(FILE *fp)
423 1.1 thorpej {
424 1.1 thorpej
425 1.5 dsl emitfiles(fp, 's', 'S');
426 1.1 thorpej }
427 1.1 thorpej
428 1.5 dsl static void
429 1.1 thorpej emitfiles(FILE *fp, int suffix, int upper_suffix)
430 1.1 thorpej {
431 1.1 thorpej struct files *fi;
432 1.20 uebayasi int len;
433 1.1 thorpej const char *fpath;
434 1.3 erh struct config *cf;
435 1.3 erh char swapname[100];
436 1.1 thorpej
437 1.20 uebayasi fprintf(fp, "%cFILES= \\\n", toupper(suffix));
438 1.1 thorpej TAILQ_FOREACH(fi, &allfiles, fi_next) {
439 1.1 thorpej if ((fi->fi_flags & FI_SEL) == 0)
440 1.1 thorpej continue;
441 1.5 dsl fpath = srcpath(fi);
442 1.1 thorpej len = strlen(fpath);
443 1.5 dsl if (fpath[len - 1] != suffix && fpath[len - 1] != upper_suffix)
444 1.1 thorpej continue;
445 1.5 dsl if (*fpath != '/') {
446 1.2 erh /* "$S/" */
447 1.2 erh if (fi->fi_prefix != NULL)
448 1.2 erh len += strlen(prefix_prologue(fi->fi_prefix)) +
449 1.2 erh strlen(fi->fi_prefix) + 1;
450 1.2 erh else
451 1.2 erh len += strlen(filetype_prologue(&fi->fi_fit));
452 1.1 thorpej }
453 1.1 thorpej if (*fi->fi_path == '/') {
454 1.20 uebayasi fprintf(fp, "\t%s \\\n", fpath);
455 1.1 thorpej } else {
456 1.1 thorpej if (fi->fi_prefix != NULL) {
457 1.20 uebayasi fprintf(fp, "\t%s%s/%s \\\n",
458 1.5 dsl prefix_prologue(fi->fi_prefix),
459 1.5 dsl fi->fi_prefix, fpath);
460 1.1 thorpej } else {
461 1.20 uebayasi fprintf(fp, "\t%s%s \\\n",
462 1.2 erh filetype_prologue(&fi->fi_fit),
463 1.5 dsl fpath);
464 1.1 thorpej }
465 1.1 thorpej }
466 1.1 thorpej }
467 1.3 erh /*
468 1.3 erh * The allfiles list does not include the configuration-specific
469 1.3 erh * C source files. These files should be eliminated someday, but
470 1.3 erh * for now, we have to add them to ${CFILES} (and only ${CFILES}).
471 1.3 erh */
472 1.3 erh if (suffix == 'c') {
473 1.3 erh TAILQ_FOREACH(cf, &allcf, cf_next) {
474 1.3 erh (void)snprintf(swapname, sizeof(swapname), "swap%s.c",
475 1.3 erh cf->cf_name);
476 1.20 uebayasi fprintf(fp, "\t%s \\\n", swapname);
477 1.3 erh }
478 1.3 erh }
479 1.5 dsl putc('\n', fp);
480 1.1 thorpej }
481 1.1 thorpej
482 1.1 thorpej /*
483 1.1 thorpej * Emit the make-rules.
484 1.1 thorpej */
485 1.5 dsl static void
486 1.1 thorpej emitrules(FILE *fp)
487 1.1 thorpej {
488 1.1 thorpej struct files *fi;
489 1.1 thorpej const char *cp, *fpath;
490 1.1 thorpej int ch;
491 1.1 thorpej
492 1.1 thorpej TAILQ_FOREACH(fi, &allfiles, fi_next) {
493 1.1 thorpej if ((fi->fi_flags & FI_SEL) == 0)
494 1.1 thorpej continue;
495 1.5 dsl fpath = srcpath(fi);
496 1.1 thorpej if (*fpath == '/') {
497 1.5 dsl fprintf(fp, "%s.o: %s\n", fi->fi_base, fpath);
498 1.1 thorpej } else {
499 1.1 thorpej if (fi->fi_prefix != NULL) {
500 1.5 dsl fprintf(fp, "%s.o: %s%s/%s\n", fi->fi_base,
501 1.5 dsl prefix_prologue(fi->fi_prefix),
502 1.5 dsl fi->fi_prefix, fpath);
503 1.1 thorpej } else {
504 1.5 dsl fprintf(fp, "%s.o: %s%s\n",
505 1.2 erh fi->fi_base,
506 1.2 erh filetype_prologue(&fi->fi_fit),
507 1.5 dsl fpath);
508 1.7 kent }
509 1.7 kent }
510 1.7 kent if (fi->fi_mkrule != NULL) {
511 1.7 kent fprintf(fp, "\t%s\n\n", fi->fi_mkrule);
512 1.7 kent } else {
513 1.7 kent fputs("\t${NORMAL_", fp);
514 1.7 kent cp = strrchr(fpath, '.');
515 1.7 kent cp = cp == NULL ? fpath : cp + 1;
516 1.7 kent while ((ch = *cp++) != '\0') {
517 1.7 kent fputc(toupper(ch), fp);
518 1.1 thorpej }
519 1.7 kent fputs("}\n\n", fp);
520 1.1 thorpej }
521 1.1 thorpej }
522 1.1 thorpej }
523 1.1 thorpej
524 1.1 thorpej /*
525 1.1 thorpej * Emit the load commands.
526 1.1 thorpej *
527 1.1 thorpej * This function is not to be called `spurt'.
528 1.1 thorpej */
529 1.5 dsl static void
530 1.1 thorpej emitload(FILE *fp)
531 1.1 thorpej {
532 1.1 thorpej struct config *cf;
533 1.1 thorpej
534 1.5 dsl fputs(".MAIN: all\nall:", fp);
535 1.1 thorpej TAILQ_FOREACH(cf, &allcf, cf_next) {
536 1.5 dsl fprintf(fp, " %s", cf->cf_name);
537 1.15 martin /*
538 1.15 martin * If we generate multiple configs inside the same build directory
539 1.15 martin * with a parallel build, strange things may happen, so sequentialize
540 1.15 martin * them.
541 1.15 martin */
542 1.15 martin if (cf != TAILQ_LAST(&allcf,conftq))
543 1.15 martin fprintf(fp, " .WAIT");
544 1.1 thorpej }
545 1.5 dsl fputs("\n\n", fp);
546 1.1 thorpej TAILQ_FOREACH(cf, &allcf, cf_next) {
547 1.17 joerg fprintf(fp, "KERNELS+=%s\n", cf->cf_name);
548 1.16 joerg fprintf(fp, "%s: ${SYSTEM_DEP} swap%s.o vers.o build_kernel\n",
549 1.17 joerg cf->cf_name, cf->cf_name);
550 1.17 joerg fprintf(fp, "swap%s.o: swap%s.c\n"
551 1.17 joerg "\t${NORMAL_C}\n\n", cf->cf_name, cf->cf_name);
552 1.1 thorpej }
553 1.16 joerg fputs("\n", fp);
554 1.1 thorpej }
555 1.1 thorpej
556 1.1 thorpej /*
557 1.1 thorpej * Emit include headers (for any prefixes encountered)
558 1.1 thorpej */
559 1.5 dsl static void
560 1.1 thorpej emitincludes(FILE *fp)
561 1.1 thorpej {
562 1.1 thorpej struct prefix *pf;
563 1.1 thorpej
564 1.1 thorpej SLIST_FOREACH(pf, &allprefixes, pf_next) {
565 1.5 dsl fprintf(fp, "EXTRA_INCLUDES+=\t-I%s%s\n",
566 1.5 dsl prefix_prologue(pf->pf_prefix), pf->pf_prefix);
567 1.1 thorpej }
568 1.1 thorpej }
569 1.1 thorpej
570 1.1 thorpej /*
571 1.1 thorpej * Emit appending makeoptions.
572 1.1 thorpej */
573 1.5 dsl static void
574 1.1 thorpej emitappmkoptions(FILE *fp)
575 1.1 thorpej {
576 1.1 thorpej struct nvlist *nv;
577 1.14 dholland struct condexpr *cond;
578 1.1 thorpej
579 1.1 thorpej for (nv = appmkoptions; nv != NULL; nv = nv->nv_next)
580 1.5 dsl fprintf(fp, "%s+=%s\n", nv->nv_name, nv->nv_str);
581 1.1 thorpej
582 1.14 dholland for (nv = condmkoptions; nv != NULL; nv = nv->nv_next) {
583 1.14 dholland cond = nv->nv_ptr;
584 1.14 dholland if (expr_eval(cond, selectopt, NULL))
585 1.11 cube fprintf(fp, "%s+=%s\n", nv->nv_name, nv->nv_str);
586 1.14 dholland condexpr_destroy(cond);
587 1.14 dholland nv->nv_ptr = NULL;
588 1.11 cube }
589 1.11 cube }
590 1.11 cube
591 1.11 cube static int
592 1.11 cube /*ARGSUSED*/
593 1.11 cube selectopt(const char *name, void *context)
594 1.11 cube {
595 1.11 cube
596 1.11 cube return (ht_lookup(selecttab, strtolower(name)) != NULL);
597 1.1 thorpej }
598