2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1995 Peter Wemm
5 * Copyright (c) 1980, 1993
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static char sccsid[] = "@(#)mkheaders.c 8.1 (Berkeley) 6/6/93";
37 static const char rcsid[] =
42 * Make all the .h files for the optional entries
49 #include <sys/param.h>
57 } users = { 8, 2, 512 };
59 static char *lower(char *);
60 static void read_options(void);
61 static void do_option(char *);
62 static char *tooption(char *);
72 /* Fake the cpu types as options. */
73 SLIST_FOREACH(cp, &cputype, cpu_next) {
74 op = (struct opt *)calloc(1, sizeof(*op));
76 err(EXIT_FAILURE, "calloc");
77 op->op_name = ns(cp->cpu_name);
78 SLIST_INSERT_HEAD(&opt, op, op_next);
82 /* fprintf(stderr, "maxusers not specified; will auto-size\n"); */
83 } else if (maxusers < users.u_min) {
84 fprintf(stderr, "minimum of %d maxusers assumed\n",
86 maxusers = users.u_min;
87 } else if (maxusers > users.u_max)
88 fprintf(stderr, "warning: maxusers > %d (%d)\n",
89 users.u_max, maxusers);
91 /* Fake MAXUSERS as an option. */
92 op = (struct opt *)calloc(1, sizeof(*op));
94 err(EXIT_FAILURE, "calloc");
95 op->op_name = ns("MAXUSERS");
96 snprintf(buf, sizeof(buf), "%d", maxusers);
97 op->op_value = ns(buf);
98 SLIST_INSERT_HEAD(&opt, op, op_next);
102 /* Fake the value of MACHINE_ARCH as an option if necessary */
103 SLIST_FOREACH(ol, &otab, o_next) {
104 if (strcasecmp(ol->o_name, machinearch) != 0)
107 op = (struct opt *)calloc(1, sizeof(*op));
109 err(EXIT_FAILURE, "calloc");
110 op->op_name = ns(ol->o_name);
111 SLIST_INSERT_HEAD(&opt, op, op_next);
115 SLIST_FOREACH(op, &opt, op_next) {
116 SLIST_FOREACH(ol, &otab, o_next) {
117 if (eq(op->op_name, ol->o_name) &&
118 (ol->o_flags & OL_ALIAS)) {
119 fprintf(stderr, "Mapping option %s to %s.\n",
120 op->op_name, ol->o_file);
121 op->op_name = ol->o_file;
126 SLIST_FOREACH(ol, &otab, o_next)
127 do_option(ol->o_name);
128 SLIST_FOREACH(op, &opt, op_next) {
129 if (!op->op_ownfile && strncmp(op->op_name, "DEV_", 4)) {
130 fprintf(stderr, "%s: unknown option \"%s\"\n",
131 PREFIX, op->op_name);
138 * Generate an <options>.h file
142 do_option(char *name)
145 const char *basefile;
148 struct opt_head op_head;
155 file = tooption(name);
157 * Check to see if the option was specified..
160 SLIST_FOREACH(op, &opt, op_next) {
161 if (eq(name, op->op_name)) {
163 value = op->op_value;
166 if (oldvalue != NULL && !eq(value, oldvalue))
168 "%s: option \"%s\" redefined from %s to %s\n",
169 PREFIX, op->op_name, oldvalue,
176 inf = fopen(file, "r");
178 outf = fopen(file, "w");
182 /* was the option in the config file? */
184 fprintf(outf, "#define %s %s\n", name, value);
185 } /* else empty file */
191 SLIST_FOREACH(ol, &otab, o_next)
192 if (eq(name, ol->o_name)) {
193 basefile = ol->o_file;
197 SLIST_INIT(&op_head);
204 /* get the #define */
205 if ((inw = get_word(inf)) == NULL || inw == (char *)EOF)
207 /* get the option name */
208 if ((inw = get_word(inf)) == NULL || inw == (char *)EOF)
211 /* get the option value */
212 if ((cp = get_word(inf)) == NULL || cp == (char *)EOF)
215 invalue = ns(cp); /* malloced */
221 SLIST_FOREACH(ol, &otab, o_next)
222 if (eq(inw, ol->o_name))
224 if (!eq(inw, name) && !ol) {
226 "WARNING: unknown option `%s' removed from %s\n",
229 } else if (ol != NULL && !eq(basefile, ol->o_file)) {
231 "WARNING: option `%s' moved from %s to %s\n",
232 inw, basefile, ol->o_file);
235 op = (struct opt *) calloc(1, sizeof *op);
237 err(EXIT_FAILURE, "calloc");
239 op->op_value = invalue;
240 SLIST_INSERT_HEAD(&op_head, op, op_next);
245 if (cp == (char *)EOF)
249 if (!tidy && ((value == NULL && oldvalue == NULL) ||
250 (value && oldvalue && eq(value, oldvalue)))) {
251 while (!SLIST_EMPTY(&op_head)) {
252 op = SLIST_FIRST(&op_head);
253 SLIST_REMOVE_HEAD(&op_head, op_next);
261 if (value && !seen) {
262 /* New option appears */
263 op = (struct opt *) calloc(1, sizeof *op);
265 err(EXIT_FAILURE, "calloc");
266 op->op_name = ns(name);
267 op->op_value = value ? ns(value) : NULL;
268 SLIST_INSERT_HEAD(&op_head, op, op_next);
271 outf = fopen(file, "w");
274 while (!SLIST_EMPTY(&op_head)) {
275 op = SLIST_FIRST(&op_head);
276 /* was the option in the config file? */
278 fprintf(outf, "#define %s %s\n",
279 op->op_name, op->op_value);
281 SLIST_REMOVE_HEAD(&op_head, op_next);
290 * Find the filename to store the option spec into.
295 static char hbuf[MAXPATHLEN];
296 char nbuf[MAXPATHLEN];
299 /* "cannot happen"? the otab list should be complete.. */
300 (void)strlcpy(nbuf, "options.h", sizeof(nbuf));
302 SLIST_FOREACH(po, &otab, o_next) {
303 if (eq(po->o_name, name)) {
304 strlcpy(nbuf, po->o_file, sizeof(nbuf));
309 (void)strlcpy(hbuf, path(nbuf), sizeof(hbuf));
315 check_duplicate(const char *fname, const char *this)
319 SLIST_FOREACH(po, &otab, o_next) {
320 if (eq(po->o_name, this)) {
321 fprintf(stderr, "%s: Duplicate option %s.\n",
329 insert_option(const char *fname, char *this, char *val)
333 check_duplicate(fname, this);
334 po = (struct opt_list *) calloc(1, sizeof *po);
336 err(EXIT_FAILURE, "calloc");
340 SLIST_INSERT_HEAD(&otab, po, o_next);
344 update_option(const char *this, char *val, int flags)
348 SLIST_FOREACH(po, &otab, o_next) {
349 if (eq(po->o_name, this)) {
357 * Option not found, but that's OK, we just ignore it since it
358 * may be for another arch.
364 read_option_file(const char *fname, int flags)
367 char *wd, *this, *val;
368 char genopt[MAXPATHLEN];
370 fp = fopen(fname, "r");
373 while ((wd = get_word(fp)) != (char *)EOF) {
377 while (((wd = get_word(fp)) != (char *)EOF) && wd)
383 if (val == (char *)EOF)
387 fprintf(stderr, "%s: compat file requires two"
388 " words per line at %s\n", fname, this);
392 (void)snprintf(genopt, sizeof(genopt), "opt_%s.h",
399 insert_option(fname, this, val);
401 update_option(this, val, flags);
408 * read the options and options.<machine> files
413 char fname[MAXPATHLEN];
416 read_option_file("../../conf/options", 0);
417 (void)snprintf(fname, sizeof fname, "../../conf/options.%s",
419 if (!read_option_file(fname, 0)) {
420 (void)snprintf(fname, sizeof fname, "options.%s", machinename);
421 read_option_file(fname, 0);
423 read_option_file("../../conf/options-compat", OL_ALIAS);
433 *str = tolower(*str);