2 * Copyright (c) 1995 Peter Wemm
3 * Copyright (c) 1980, 1993
4 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 4. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 static char sccsid[] = "@(#)mkheaders.c 8.1 (Berkeley) 6/6/93";
35 static const char rcsid[] =
40 * Make all the .h files for the optional entries
47 #include <sys/param.h>
55 } users = { 8, 2, 512 };
57 static char *lower(char *);
58 static void read_options(void);
59 static void do_option(char *);
60 static char *tooption(char *);
70 /* Fake the cpu types as options. */
71 SLIST_FOREACH(cp, &cputype, cpu_next) {
72 op = (struct opt *)calloc(1, sizeof(*op));
74 err(EXIT_FAILURE, "calloc");
75 op->op_name = ns(cp->cpu_name);
76 SLIST_INSERT_HEAD(&opt, op, op_next);
80 /* fprintf(stderr, "maxusers not specified; will auto-size\n"); */
81 } else if (maxusers < users.u_min) {
82 fprintf(stderr, "minimum of %d maxusers assumed\n",
84 maxusers = users.u_min;
85 } else if (maxusers > users.u_max)
86 fprintf(stderr, "warning: maxusers > %d (%d)\n",
87 users.u_max, maxusers);
89 /* Fake MAXUSERS as an option. */
90 op = (struct opt *)calloc(1, sizeof(*op));
92 err(EXIT_FAILURE, "calloc");
93 op->op_name = ns("MAXUSERS");
94 snprintf(buf, sizeof(buf), "%d", maxusers);
95 op->op_value = ns(buf);
96 SLIST_INSERT_HEAD(&opt, op, op_next);
100 /* Fake the value of MACHINE_ARCH as an option if necessary */
101 SLIST_FOREACH(ol, &otab, o_next) {
102 if (strcasecmp(ol->o_name, machinearch) != 0)
105 op = (struct opt *)calloc(1, sizeof(*op));
107 err(EXIT_FAILURE, "calloc");
108 op->op_name = ns(ol->o_name);
109 SLIST_INSERT_HEAD(&opt, op, op_next);
113 SLIST_FOREACH(op, &opt, op_next) {
114 SLIST_FOREACH(ol, &otab, o_next) {
115 if (eq(op->op_name, ol->o_name) &&
116 (ol->o_flags & OL_ALIAS)) {
117 fprintf(stderr, "Mapping option %s to %s.\n",
118 op->op_name, ol->o_file);
119 op->op_name = ol->o_file;
124 SLIST_FOREACH(ol, &otab, o_next)
125 do_option(ol->o_name);
126 SLIST_FOREACH(op, &opt, op_next) {
127 if (!op->op_ownfile && strncmp(op->op_name, "DEV_", 4)) {
128 fprintf(stderr, "%s: unknown option \"%s\"\n",
129 PREFIX, op->op_name);
136 * Generate an <options>.h file
140 do_option(char *name)
143 const char *basefile;
146 struct opt_head op_head;
153 file = tooption(name);
155 * Check to see if the option was specified..
158 SLIST_FOREACH(op, &opt, op_next) {
159 if (eq(name, op->op_name)) {
161 value = op->op_value;
164 if (oldvalue != NULL && !eq(value, oldvalue))
166 "%s: option \"%s\" redefined from %s to %s\n",
167 PREFIX, op->op_name, oldvalue,
174 inf = fopen(file, "r");
176 outf = fopen(file, "w");
180 /* was the option in the config file? */
182 fprintf(outf, "#define %s %s\n", name, value);
183 } /* else empty file */
189 SLIST_FOREACH(ol, &otab, o_next)
190 if (eq(name, ol->o_name)) {
191 basefile = ol->o_file;
195 SLIST_INIT(&op_head);
202 /* get the #define */
203 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
205 /* get the option name */
206 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
209 /* get the option value */
210 if ((cp = get_word(inf)) == 0 || cp == (char *)EOF)
213 invalue = ns(cp); /* malloced */
219 SLIST_FOREACH(ol, &otab, o_next)
220 if (eq(inw, ol->o_name))
222 if (!eq(inw, name) && !ol) {
224 "WARNING: unknown option `%s' removed from %s\n",
227 } else if (ol != NULL && !eq(basefile, ol->o_file)) {
229 "WARNING: option `%s' moved from %s to %s\n",
230 inw, basefile, ol->o_file);
233 op = (struct opt *) calloc(1, sizeof *op);
235 err(EXIT_FAILURE, "calloc");
237 op->op_value = invalue;
238 SLIST_INSERT_HEAD(&op_head, op, op_next);
243 if (cp == (char *)EOF)
247 if (!tidy && ((value == NULL && oldvalue == NULL) ||
248 (value && oldvalue && eq(value, oldvalue)))) {
249 while (!SLIST_EMPTY(&op_head)) {
250 op = SLIST_FIRST(&op_head);
251 SLIST_REMOVE_HEAD(&op_head, op_next);
259 if (value && !seen) {
260 /* New option appears */
261 op = (struct opt *) calloc(1, sizeof *op);
263 err(EXIT_FAILURE, "calloc");
264 op->op_name = ns(name);
265 op->op_value = value ? ns(value) : NULL;
266 SLIST_INSERT_HEAD(&op_head, op, op_next);
269 outf = fopen(file, "w");
272 while (!SLIST_EMPTY(&op_head)) {
273 op = SLIST_FIRST(&op_head);
274 /* was the option in the config file? */
276 fprintf(outf, "#define %s %s\n",
277 op->op_name, op->op_value);
279 SLIST_REMOVE_HEAD(&op_head, op_next);
288 * Find the filename to store the option spec into.
293 static char hbuf[MAXPATHLEN];
294 char nbuf[MAXPATHLEN];
297 /* "cannot happen"? the otab list should be complete.. */
298 (void)strlcpy(nbuf, "options.h", sizeof(nbuf));
300 SLIST_FOREACH(po, &otab, o_next) {
301 if (eq(po->o_name, name)) {
302 strlcpy(nbuf, po->o_file, sizeof(nbuf));
307 (void)strlcpy(hbuf, path(nbuf), sizeof(hbuf));
313 check_duplicate(const char *fname, const char *this)
317 SLIST_FOREACH(po, &otab, o_next) {
318 if (eq(po->o_name, this)) {
319 fprintf(stderr, "%s: Duplicate option %s.\n",
327 insert_option(const char *fname, char *this, char *val)
331 check_duplicate(fname, this);
332 po = (struct opt_list *) calloc(1, sizeof *po);
334 err(EXIT_FAILURE, "calloc");
338 SLIST_INSERT_HEAD(&otab, po, o_next);
342 update_option(const char *this, char *val, int flags)
346 SLIST_FOREACH(po, &otab, o_next) {
347 if (eq(po->o_name, this)) {
355 * Option not found, but that's OK, we just ignore it since it
356 * may be for another arch.
362 read_option_file(const char *fname, int flags)
365 char *wd, *this, *val;
366 char genopt[MAXPATHLEN];
368 fp = fopen(fname, "r");
371 while ((wd = get_word(fp)) != (char *)EOF) {
375 while (((wd = get_word(fp)) != (char *)EOF) && wd)
381 if (val == (char *)EOF)
385 fprintf(stderr, "%s: compat file requires two"
386 " words per line at %s\n", fname, this);
390 (void)snprintf(genopt, sizeof(genopt), "opt_%s.h",
397 insert_option(fname, this, val);
399 update_option(this, val, flags);
406 * read the options and options.<machine> files
411 char fname[MAXPATHLEN];
414 read_option_file("../../conf/options", 0);
415 (void)snprintf(fname, sizeof fname, "../../conf/options.%s",
417 if (!read_option_file(fname, 0)) {
418 (void)snprintf(fname, sizeof fname, "options.%s", machinename);
419 read_option_file(fname, 0);
421 read_option_file("../../conf/options-compat", OL_ALIAS);
431 *str = tolower(*str);