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 (MAJOR_VERS(versreq) != MAJOR_VERS(CONFIGVERS) ||
157 versreq > CONFIGVERS) {
158 fprintf(stderr, "ERROR: version of config(8) does not match kernel!\n");
159 fprintf(stderr, "config version = %d, ", CONFIGVERS);
160 fprintf(stderr, "version required = %d\n\n", versreq);
161 fprintf(stderr, "Make sure that /usr/src/usr.sbin/config is in sync\n");
162 fprintf(stderr, "with your /usr/src/sys and install a new config binary\n");
163 fprintf(stderr, "before trying this again.\n\n");
164 fprintf(stderr, "If running the new config fails check your config\n");
165 fprintf(stderr, "file against the GENERIC or LINT config files for\n");
166 fprintf(stderr, "changes in config syntax, or option/device naming\n");
167 fprintf(stderr, "conventions\n\n");
172 "Unknown %% construct in generic makefile: %s",
177 moveifchanged(path("Makefile.new"), path("Makefile"));
181 * Build hints.c from the skeleton
191 ifp = fopen(hints, "r");
197 ofp = fopen(path("hints.c.new"), "w");
199 err(1, "%s", path("hints.c.new"));
200 fprintf(ofp, "#include <sys/types.h>\n");
201 fprintf(ofp, "#include <sys/systm.h>\n");
203 fprintf(ofp, "int hintmode = %d;\n", hintmode);
204 fprintf(ofp, "char static_hints[] = {\n");
206 while (fgets(line, BUFSIZ, ifp) != 0) {
207 /* zap trailing CR and/or LF */
208 while ((s = rindex(line, '\n')) != NULL)
210 while ((s = rindex(line, '\r')) != NULL)
212 /* remove # comments */
213 s = index(line, '#');
216 /* remove any whitespace and " characters */
219 if (*s == ' ' || *s == '\t' || *s == '"') {
233 fprintf(ofp, "\"%s\\0\"\n", line);
236 fprintf(ofp, "\"\\0\"\n};\n");
240 moveifchanged(path("hints.c.new"), path("hints.c"));
244 * Build env.c from the skeleton
254 ifp = fopen(env, "r");
260 ofp = fopen(path("env.c.new"), "w");
262 err(1, "%s", path("env.c.new"));
263 fprintf(ofp, "#include <sys/types.h>\n");
264 fprintf(ofp, "#include <sys/systm.h>\n");
266 fprintf(ofp, "int envmode = %d;\n", envmode);
267 fprintf(ofp, "char static_env[] = {\n");
269 while (fgets(line, BUFSIZ, ifp) != 0) {
270 /* zap trailing CR and/or LF */
271 while ((s = rindex(line, '\n')) != NULL)
273 while ((s = rindex(line, '\r')) != NULL)
275 /* remove # comments */
276 s = index(line, '#');
279 /* remove any whitespace and " characters */
282 if (*s == ' ' || *s == '\t' || *s == '"') {
296 fprintf(ofp, "\"%s\\0\"\n", line);
299 fprintf(ofp, "\"\\0\"\n};\n");
303 moveifchanged(path("env.c.new"), path("env.c"));
307 read_file(char *fname)
310 struct file_list *tp;
313 char *wd, *this, *compilewith, *depends, *clean, *warning;
314 int compile, match, nreqs, std, filetype,
315 imp_rule, no_obj, before_depend, mandatory, nowerror;
317 fp = fopen(fname, "r");
322 * filename [ standard | mandatory | optional ]
323 * [ dev* [ | dev* ... ] | profiling-routine ] [ no-obj ]
324 * [ compile-with "compile rule" [no-implicit-rule] ]
325 * [ dependency "dependency-list"] [ before-depend ]
326 * [ clean "file-list"] [ warning "text warning" ]
329 if (wd == (char *)EOF) {
337 while (((wd = get_word(fp)) != (char *)EOF) && wd)
344 printf("%s: No type for %s.\n",
348 tp = fl_lookup(this);
362 if (eq(wd, "standard")) {
365 * If an entry is marked "mandatory", config will abort if it's
366 * not called by a configuration line in the config file. Apart
367 * from this, the device is handled like one marked "optional".
369 } else if (eq(wd, "mandatory")) {
371 } else if (!eq(wd, "optional")) {
372 printf("%s: %s must be optional, mandatory or standard\n",
380 if (compile && tp == NULL)
386 printf("%s: syntax error describing %s\n",
395 if (eq(wd, "no-obj")) {
399 if (eq(wd, "no-implicit-rule")) {
400 if (compilewith == 0) {
401 printf("%s: alternate rule required when "
402 "\"no-implicit-rule\" is specified.\n",
408 if (eq(wd, "before-depend")) {
412 if (eq(wd, "dependency")) {
413 next_quoted_word(fp, wd);
415 printf("%s: %s missing compile command string.\n",
422 if (eq(wd, "clean")) {
423 next_quoted_word(fp, wd);
425 printf("%s: %s missing clean file list.\n",
432 if (eq(wd, "compile-with")) {
433 next_quoted_word(fp, wd);
435 printf("%s: %s missing compile command string.\n",
439 compilewith = ns(wd);
442 if (eq(wd, "warning")) {
443 next_quoted_word(fp, wd);
445 printf("%s: %s missing warning text string.\n",
453 if (eq(wd, "local")) {
457 if (eq(wd, "no-depend")) {
461 if (eq(wd, "profiling-routine")) {
462 filetype = PROFILING;
465 if (eq(wd, "nowerror")) {
469 STAILQ_FOREACH(dp, &dtab, d_next)
470 if (eq(dp->d_name, wd)) {
471 dp->d_done |= DEVDONE;
475 printf("%s: mandatory device \"%s\" not found\n",
480 printf("standard entry %s has a device keyword - %s!\n",
484 SLIST_FOREACH(op, &opt, op_next)
485 if (op->op_value == 0 && opteq(op->op_name, wd))
491 if (std == 0 && nreqs == 0) {
492 printf("%s: what is %s optional on?\n",
498 printf("%s: syntax error describing %s\n",
502 if (filetype == PROFILING && profiling == 0)
506 tp->f_type = filetype;
508 tp->f_flags |= NO_IMPLCT_RULE;
510 tp->f_flags |= NO_OBJ;
512 tp->f_flags |= BEFORE_DEPEND;
514 tp->f_flags |= NOWERROR;
515 tp->f_compilewith = compilewith;
516 tp->f_depends = depends;
518 tp->f_warn = warning;
523 * Read in the information about files used in making the system.
524 * Store it in the ftab linked list.
529 char fname[MAXPATHLEN];
530 struct files_name *nl, *tnl;
532 (void) snprintf(fname, sizeof(fname), "../../conf/files");
534 (void) snprintf(fname, sizeof(fname),
535 "../../conf/files.%s", machinename);
537 for (nl = STAILQ_FIRST(&fntab); nl != NULL; nl = tnl) {
538 read_file(nl->f_name);
539 tnl = STAILQ_NEXT(nl, f_next);
546 opteq(const char *cp, const char *dp)
550 for (; ; cp++, dp++) {
552 c = isupper(*cp) ? tolower(*cp) : *cp;
553 d = isupper(*dp) ? tolower(*dp) : *dp;
563 do_before_depend(FILE *fp)
565 struct file_list *tp;
568 fputs("BEFORE_DEPEND=", fp);
570 STAILQ_FOREACH(tp, &ftab, f_next)
571 if (tp->f_flags & BEFORE_DEPEND) {
572 len = strlen(tp->f_fn);
573 if ((len = 3 + len) + lpos > 72) {
577 if (tp->f_flags & NO_IMPLCT_RULE)
578 fprintf(fp, "%s ", tp->f_fn);
580 fprintf(fp, "$S/%s ", tp->f_fn);
590 struct file_list *tp;
594 fprintf(fp, "OBJS=");
596 STAILQ_FOREACH(tp, &ftab, f_next) {
597 if (tp->f_flags & NO_OBJ)
600 cp = sp + (len = strlen(sp)) - 1;
603 if (len + lpos > 72) {
605 fprintf(fp, "\\\n\t");
607 fprintf(fp, "%s ", sp);
616 do_xxfiles(char *tag, FILE *fp)
618 struct file_list *tp;
622 if (tag[strlen(tag) - 1] == '\n')
623 tag[strlen(tag) - 1] = '\0';
630 fprintf(fp, "%sFILES=", SUFF);
632 STAILQ_FOREACH(tp, &ftab, f_next)
633 if (tp->f_type != NODEPEND) {
634 len = strlen(tp->f_fn);
635 if (tp->f_fn[len - slen - 1] != '.')
637 if (strcasecmp(&tp->f_fn[len - slen], suff) != 0)
639 if ((len = 3 + len) + lpos > 72) {
643 if (tp->f_type != LOCAL)
644 fprintf(fp, "$S/%s ", tp->f_fn);
646 fprintf(fp, "%s ", tp->f_fn);
658 cp = rindex(fn, '/');
665 * Create the makerules for each file
666 * which is part of the system.
671 char *cp, *np, och, *tp;
672 struct file_list *ftp;
675 STAILQ_FOREACH(ftp, &ftab, f_next) {
677 printf("WARNING: %s\n", ftp->f_warn);
678 cp = (np = ftp->f_fn) + strlen(ftp->f_fn) - 1;
680 if (ftp->f_flags & NO_IMPLCT_RULE) {
682 fprintf(f, "%s: %s\n", np, ftp->f_depends);
684 fprintf(f, "%s: \n", np);
689 fprintf(f, "%so:\n\t-cp $S/%so .\n\n",
693 if (ftp->f_depends) {
694 fprintf(f, "%sln: $S/%s%c %s\n", tail(np),
695 np, och, ftp->f_depends);
696 fprintf(f, "\t${NORMAL_LINT}\n\n");
697 fprintf(f, "%so: $S/%s%c %s\n", tail(np),
698 np, och, ftp->f_depends);
701 fprintf(f, "%sln: $S/%s%c\n", tail(np),
703 fprintf(f, "\t${NORMAL_LINT}\n\n");
704 fprintf(f, "%so: $S/%s%c\n", tail(np),
709 compilewith = ftp->f_compilewith;
710 if (compilewith == 0) {
711 const char *ftype = NULL;
712 static char cmd[128];
714 switch (ftp->f_type) {
727 printf("config: don't know rules for %s\n", np);
730 snprintf(cmd, sizeof(cmd), "${%s_%c%s}", ftype,
732 ftp->f_flags & NOWERROR ? "_NOWERROR" : "");
736 fprintf(f, "\t%s\n\n", compilewith);
743 struct file_list *tp;
748 STAILQ_FOREACH(tp, &ftab, f_next)
750 len = strlen(tp->f_clean);
751 if (len + lpos > 72) {
755 fprintf(fp, "%s ", tp->f_clean);
769 *str = toupper(*str);