2 * Copyright (c) 1993, 19801990
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 static char sccsid[] = "@(#)mkmakefile.c 8.1 (Berkeley) 6/6/93";
34 static const char rcsid[] =
39 * Build the makefile for the system, from
40 * the information in the files files and the
41 * additional files for the machine being compiled to.
48 #include <sys/param.h>
51 #include "configvers.h"
53 #define next_word(fp, wd) \
54 { char *word = get_word(fp); \
55 if (word == (char *)EOF) \
60 #define next_quoted_word(fp, wd) \
61 { char *word = get_quoted_word(fp); \
62 if (word == (char *)EOF) \
68 static char *tail(char *);
69 static void do_clean(FILE *);
70 static void do_rules(FILE *);
71 static void do_xxfiles(char *, FILE *);
72 static void do_objs(FILE *);
73 static void do_before_depend(FILE *);
74 static int opteq(const char *, const char *);
75 static void read_files(void);
78 * Lookup a file, by name.
80 static struct file_list *
85 STAILQ_FOREACH(fp, &ftab, f_next) {
86 if (eq(fp->f_fn, file))
93 * Make a new file list entry
95 static struct file_list *
100 fp = (struct file_list *) malloc(sizeof *fp);
101 bzero(fp, sizeof *fp);
102 STAILQ_INSERT_TAIL(&ftab, fp, f_next);
107 * Build the makefile from the skeleton
118 snprintf(line, sizeof(line), "../../conf/Makefile.%s", machinename);
119 ifp = fopen(line, "r");
121 snprintf(line, sizeof(line), "Makefile.%s", machinename);
122 ifp = fopen(line, "r");
127 ofp = fopen(path("Makefile.new"), "w");
129 err(1, "%s", path("Makefile.new"));
130 fprintf(ofp, "KERN_IDENT=%s\n", ident);
131 SLIST_FOREACH(op, &mkopt, op_next)
132 fprintf(ofp, "%s=%s\n", op->op_name, op->op_value);
134 fprintf(ofp, "DEBUG=-g\n");
136 fprintf(ofp, "PROFLEVEL=%d\n", profiling);
138 fprintf(ofp,"S=%s\n", srcdir);
139 while (fgets(line, BUFSIZ, ifp) != 0) {
141 fprintf(ofp, "%s", line);
144 if (eq(line, "%BEFORE_DEPEND\n"))
145 do_before_depend(ofp);
146 else if (eq(line, "%OBJS\n"))
148 else if (strncmp(line, "%FILES.", 7) == 0)
149 do_xxfiles(line, ofp);
150 else if (eq(line, "%RULES\n"))
152 else if (eq(line, "%CLEAN\n"))
154 else if (strncmp(line, "%VERSREQ=", sizeof("%VERSREQ=") - 1) == 0) {
155 versreq = atoi(line + sizeof("%VERSREQ=") - 1);
156 if (versreq != CONFIGVERS) {
157 fprintf(stderr, "ERROR: version of config(8) does not match kernel!\n");
158 fprintf(stderr, "config version = %d, ", CONFIGVERS);
159 fprintf(stderr, "version required = %d\n\n", versreq);
160 fprintf(stderr, "Make sure that /usr/src/usr.sbin/config is in sync\n");
161 fprintf(stderr, "with your /usr/src/sys and install a new config binary\n");
162 fprintf(stderr, "before trying this again.\n\n");
163 fprintf(stderr, "If running the new config fails check your config\n");
164 fprintf(stderr, "file against the GENERIC or LINT config files for\n");
165 fprintf(stderr, "changes in config syntax, or option/device naming\n");
166 fprintf(stderr, "conventions\n\n");
171 "Unknown %% construct in generic makefile: %s",
176 moveifchanged(path("Makefile.new"), path("Makefile"));
180 * Build hints.c from the skeleton
190 ifp = fopen(hints, "r");
196 ofp = fopen(path("hints.c.new"), "w");
198 err(1, "%s", path("hints.c.new"));
199 fprintf(ofp, "#include <sys/types.h>\n");
200 fprintf(ofp, "#include <sys/systm.h>\n");
202 fprintf(ofp, "int hintmode = %d;\n", hintmode);
203 fprintf(ofp, "char static_hints[] = {\n");
205 while (fgets(line, BUFSIZ, ifp) != 0) {
206 /* zap trailing CR and/or LF */
207 while ((s = rindex(line, '\n')) != NULL)
209 while ((s = rindex(line, '\r')) != NULL)
211 /* remove # comments */
212 s = index(line, '#');
215 /* remove any whitespace and " characters */
218 if (*s == ' ' || *s == '\t' || *s == '"') {
232 fprintf(ofp, "\"%s\\0\"\n", line);
235 fprintf(ofp, "\"\\0\"\n};\n");
239 moveifchanged(path("hints.c.new"), path("hints.c"));
243 * Build env.c from the skeleton
253 ifp = fopen(env, "r");
259 ofp = fopen(path("env.c.new"), "w");
261 err(1, "%s", path("env.c.new"));
262 fprintf(ofp, "#include <sys/types.h>\n");
263 fprintf(ofp, "#include <sys/systm.h>\n");
265 fprintf(ofp, "int envmode = %d;\n", envmode);
266 fprintf(ofp, "char static_env[] = {\n");
268 while (fgets(line, BUFSIZ, ifp) != 0) {
269 /* zap trailing CR and/or LF */
270 while ((s = rindex(line, '\n')) != NULL)
272 while ((s = rindex(line, '\r')) != NULL)
274 /* remove # comments */
275 s = index(line, '#');
278 /* remove any whitespace and " characters */
281 if (*s == ' ' || *s == '\t' || *s == '"') {
295 fprintf(ofp, "\"%s\\0\"\n", line);
298 fprintf(ofp, "\"\\0\"\n};\n");
302 moveifchanged(path("env.c.new"), path("env.c"));
306 read_file(char *fname)
309 struct file_list *tp;
312 char *wd, *this, *compilewith, *depends, *clean, *warning;
313 int compile, match, nreqs, devfound, std, filetype,
314 imp_rule, no_obj, before_depend, mandatory, nowerror;
316 fp = fopen(fname, "r");
321 * filename [ standard | mandatory | optional ]
322 * [ dev* [ | dev* ... ] | profiling-routine ] [ no-obj ]
323 * [ compile-with "compile rule" [no-implicit-rule] ]
324 * [ dependency "dependency-list"] [ before-depend ]
325 * [ clean "file-list"] [ warning "text warning" ]
328 if (wd == (char *)EOF) {
336 while (((wd = get_word(fp)) != (char *)EOF) && wd)
343 printf("%s: No type for %s.\n",
347 tp = fl_lookup(this);
361 if (eq(wd, "standard")) {
364 * If an entry is marked "mandatory", config will abort if it's
365 * not called by a configuration line in the config file. Apart
366 * from this, the device is handled like one marked "optional".
368 } else if (eq(wd, "mandatory")) {
370 } else if (!eq(wd, "optional")) {
371 printf("%s: %s must be optional, mandatory or standard\n",
379 if (compile && tp == NULL)
385 printf("%s: syntax error describing %s\n",
394 if (eq(wd, "no-obj")) {
398 if (eq(wd, "no-implicit-rule")) {
399 if (compilewith == 0) {
400 printf("%s: alternate rule required when "
401 "\"no-implicit-rule\" is specified.\n",
407 if (eq(wd, "before-depend")) {
411 if (eq(wd, "dependency")) {
412 next_quoted_word(fp, wd);
414 printf("%s: %s missing compile command string.\n",
421 if (eq(wd, "clean")) {
422 next_quoted_word(fp, wd);
424 printf("%s: %s missing clean file list.\n",
431 if (eq(wd, "compile-with")) {
432 next_quoted_word(fp, wd);
434 printf("%s: %s missing compile command string.\n",
438 compilewith = ns(wd);
441 if (eq(wd, "warning")) {
442 next_quoted_word(fp, wd);
444 printf("%s: %s missing warning text string.\n",
452 if (eq(wd, "local")) {
456 if (eq(wd, "no-depend")) {
460 if (eq(wd, "profiling-routine")) {
461 filetype = PROFILING;
464 if (eq(wd, "nowerror")) {
468 devfound = 0; /* XXX duplicate device entries */
469 STAILQ_FOREACH(dp, &dtab, d_next)
470 if (eq(dp->d_name, wd)) {
471 dp->d_done |= DEVDONE;
477 printf("%s: mandatory device \"%s\" not found\n",
482 printf("standard entry %s has a device keyword - %s!\n",
486 SLIST_FOREACH(op, &opt, op_next)
487 if (op->op_value == 0 && opteq(op->op_name, wd))
493 if (std == 0 && nreqs == 0) {
494 printf("%s: what is %s optional on?\n",
500 printf("%s: syntax error describing %s\n",
504 if (filetype == PROFILING && profiling == 0)
508 tp->f_type = filetype;
510 tp->f_flags |= NO_IMPLCT_RULE;
512 tp->f_flags |= NO_OBJ;
514 tp->f_flags |= BEFORE_DEPEND;
516 tp->f_flags |= NOWERROR;
517 tp->f_compilewith = compilewith;
518 tp->f_depends = depends;
520 tp->f_warn = warning;
525 * Read in the information about files used in making the system.
526 * Store it in the ftab linked list.
531 char fname[MAXPATHLEN];
532 struct files_name *nl, *tnl;
534 (void) snprintf(fname, sizeof(fname), "../../conf/files");
536 (void) snprintf(fname, sizeof(fname),
537 "../../conf/files.%s", machinename);
539 for (nl = STAILQ_FIRST(&fntab); nl != NULL; nl = tnl) {
540 read_file(nl->f_name);
541 tnl = STAILQ_NEXT(nl, f_next);
548 opteq(const char *cp, const char *dp)
552 for (; ; cp++, dp++) {
554 c = isupper(*cp) ? tolower(*cp) : *cp;
555 d = isupper(*dp) ? tolower(*dp) : *dp;
565 do_before_depend(FILE *fp)
567 struct file_list *tp;
570 fputs("BEFORE_DEPEND=", fp);
572 STAILQ_FOREACH(tp, &ftab, f_next)
573 if (tp->f_flags & BEFORE_DEPEND) {
574 len = strlen(tp->f_fn);
575 if ((len = 3 + len) + lpos > 72) {
579 if (tp->f_flags & NO_IMPLCT_RULE)
580 fprintf(fp, "%s ", tp->f_fn);
582 fprintf(fp, "$S/%s ", tp->f_fn);
592 struct file_list *tp;
596 fprintf(fp, "OBJS=");
598 STAILQ_FOREACH(tp, &ftab, f_next) {
599 if (tp->f_flags & NO_OBJ)
602 cp = sp + (len = strlen(sp)) - 1;
605 if (len + lpos > 72) {
607 fprintf(fp, "\\\n\t");
609 fprintf(fp, "%s ", sp);
618 do_xxfiles(char *tag, FILE *fp)
620 struct file_list *tp;
624 if (tag[strlen(tag) - 1] == '\n')
625 tag[strlen(tag) - 1] = '\0';
632 fprintf(fp, "%sFILES=", SUFF);
634 STAILQ_FOREACH(tp, &ftab, f_next)
635 if (tp->f_type != NODEPEND) {
636 len = strlen(tp->f_fn);
637 if (tp->f_fn[len - slen - 1] != '.')
639 if (strcasecmp(&tp->f_fn[len - slen], suff) != 0)
641 if ((len = 3 + len) + lpos > 72) {
645 if (tp->f_type != LOCAL)
646 fprintf(fp, "$S/%s ", tp->f_fn);
648 fprintf(fp, "%s ", tp->f_fn);
660 cp = rindex(fn, '/');
667 * Create the makerules for each file
668 * which is part of the system.
673 char *cp, *np, och, *tp;
674 struct file_list *ftp;
677 STAILQ_FOREACH(ftp, &ftab, f_next) {
679 printf("WARNING: %s\n", ftp->f_warn);
680 cp = (np = ftp->f_fn) + strlen(ftp->f_fn) - 1;
682 if (ftp->f_flags & NO_IMPLCT_RULE) {
684 fprintf(f, "%s: %s\n", np, ftp->f_depends);
686 fprintf(f, "%s: \n", np);
691 fprintf(f, "%so:\n\t-cp $S/%so .\n\n",
695 if (ftp->f_depends) {
696 fprintf(f, "%sln: $S/%s%c %s\n", tail(np),
697 np, och, ftp->f_depends);
698 fprintf(f, "\t${NORMAL_LINT}\n\n");
699 fprintf(f, "%so: $S/%s%c %s\n", tail(np),
700 np, och, ftp->f_depends);
703 fprintf(f, "%sln: $S/%s%c\n", tail(np),
705 fprintf(f, "\t${NORMAL_LINT}\n\n");
706 fprintf(f, "%so: $S/%s%c\n", tail(np),
711 compilewith = ftp->f_compilewith;
712 if (compilewith == 0) {
713 const char *ftype = NULL;
714 static char cmd[128];
716 switch (ftp->f_type) {
729 printf("config: don't know rules for %s\n", np);
732 snprintf(cmd, sizeof(cmd), "${%s_%c%s}", ftype,
734 ftp->f_flags & NOWERROR ? "_NOWERROR" : "");
738 fprintf(f, "\t%s\n\n", compilewith);
745 struct file_list *tp;
750 STAILQ_FOREACH(tp, &ftab, f_next)
752 len = strlen(tp->f_clean);
753 if (len + lpos > 72) {
757 fprintf(fp, "%s ", tp->f_clean);
771 *str = toupper(*str);