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 /* printf("maxusers not specified; will auto-size\n"); */
81 } else if (maxusers < users.u_min) {
82 printf("minimum of %d maxusers assumed\n", users.u_min);
83 maxusers = users.u_min;
84 } else if (maxusers > users.u_max)
85 printf("warning: maxusers > %d (%d)\n", users.u_max, maxusers);
87 /* Fake MAXUSERS as an option. */
88 op = (struct opt *)calloc(1, sizeof(*op));
90 err(EXIT_FAILURE, "calloc");
91 op->op_name = ns("MAXUSERS");
92 snprintf(buf, sizeof(buf), "%d", maxusers);
93 op->op_value = ns(buf);
94 SLIST_INSERT_HEAD(&opt, op, op_next);
98 /* Fake the value of MACHINE_ARCH as an option if necessary */
99 SLIST_FOREACH(ol, &otab, o_next) {
100 if (strcasecmp(ol->o_name, machinearch) != 0)
103 op = (struct opt *)calloc(1, sizeof(*op));
105 err(EXIT_FAILURE, "calloc");
106 op->op_name = ns(ol->o_name);
107 SLIST_INSERT_HEAD(&opt, op, op_next);
111 SLIST_FOREACH(op, &opt, op_next) {
112 SLIST_FOREACH(ol, &otab, o_next) {
113 if (eq(op->op_name, ol->o_name) &&
114 (ol->o_flags & OL_ALIAS)) {
115 printf("Mapping option %s to %s.\n",
116 op->op_name, ol->o_file);
117 op->op_name = ol->o_file;
122 SLIST_FOREACH(ol, &otab, o_next)
123 do_option(ol->o_name);
124 SLIST_FOREACH(op, &opt, op_next) {
125 if (!op->op_ownfile && strncmp(op->op_name, "DEV_", 4)) {
126 printf("%s: unknown option \"%s\"\n",
127 PREFIX, op->op_name);
134 * Generate an <options>.h file
138 do_option(char *name)
141 const char *basefile;
144 struct opt_head op_head;
151 file = tooption(name);
153 * Check to see if the option was specified..
156 SLIST_FOREACH(op, &opt, op_next) {
157 if (eq(name, op->op_name)) {
159 value = op->op_value;
162 if (oldvalue != NULL && !eq(value, oldvalue))
164 "%s: option \"%s\" redefined from %s to %s\n",
165 PREFIX, op->op_name, oldvalue,
172 inf = fopen(file, "r");
174 outf = fopen(file, "w");
178 /* was the option in the config file? */
180 fprintf(outf, "#define %s %s\n", name, value);
181 } /* else empty file */
187 SLIST_FOREACH(ol, &otab, o_next)
188 if (eq(name, ol->o_name)) {
189 basefile = ol->o_file;
193 SLIST_INIT(&op_head);
200 /* get the #define */
201 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
203 /* get the option name */
204 if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
207 /* get the option value */
208 if ((cp = get_word(inf)) == 0 || cp == (char *)EOF)
211 invalue = ns(cp); /* malloced */
217 SLIST_FOREACH(ol, &otab, o_next)
218 if (eq(inw, ol->o_name))
220 if (!eq(inw, name) && !ol) {
221 printf("WARNING: unknown option `%s' removed from %s\n",
224 } else if (ol != NULL && !eq(basefile, ol->o_file)) {
225 printf("WARNING: option `%s' moved from %s to %s\n",
226 inw, basefile, ol->o_file);
229 op = (struct opt *) calloc(1, sizeof *op);
231 err(EXIT_FAILURE, "calloc");
233 op->op_value = invalue;
234 SLIST_INSERT_HEAD(&op_head, op, op_next);
239 if (cp == (char *)EOF)
243 if (!tidy && ((value == NULL && oldvalue == NULL) ||
244 (value && oldvalue && eq(value, oldvalue)))) {
245 while (!SLIST_EMPTY(&op_head)) {
246 op = SLIST_FIRST(&op_head);
247 SLIST_REMOVE_HEAD(&op_head, op_next);
255 if (value && !seen) {
256 /* New option appears */
257 op = (struct opt *) calloc(1, sizeof *op);
259 err(EXIT_FAILURE, "calloc");
260 op->op_name = ns(name);
261 op->op_value = value ? ns(value) : NULL;
262 SLIST_INSERT_HEAD(&op_head, op, op_next);
265 outf = fopen(file, "w");
268 while (!SLIST_EMPTY(&op_head)) {
269 op = SLIST_FIRST(&op_head);
270 /* was the option in the config file? */
272 fprintf(outf, "#define %s %s\n",
273 op->op_name, op->op_value);
275 SLIST_REMOVE_HEAD(&op_head, op_next);
284 * Find the filename to store the option spec into.
289 static char hbuf[MAXPATHLEN];
290 char nbuf[MAXPATHLEN];
293 /* "cannot happen"? the otab list should be complete.. */
294 (void)strlcpy(nbuf, "options.h", sizeof(nbuf));
296 SLIST_FOREACH(po, &otab, o_next) {
297 if (eq(po->o_name, name)) {
298 strlcpy(nbuf, po->o_file, sizeof(nbuf));
303 (void)strlcpy(hbuf, path(nbuf), sizeof(hbuf));
309 check_duplicate(const char *fname, const char *this)
313 SLIST_FOREACH(po, &otab, o_next) {
314 if (eq(po->o_name, this)) {
315 printf("%s: Duplicate option %s.\n",
323 insert_option(const char *fname, char *this, char *val)
327 check_duplicate(fname, this);
328 po = (struct opt_list *) calloc(1, sizeof *po);
330 err(EXIT_FAILURE, "calloc");
334 SLIST_INSERT_HEAD(&otab, po, o_next);
338 update_option(const char *this, char *val, int flags)
342 SLIST_FOREACH(po, &otab, o_next) {
343 if (eq(po->o_name, this)) {
350 printf("Compat option %s not listed in options file.\n", this);
355 read_option_file(const char *fname, int flags)
358 char *wd, *this, *val;
359 char genopt[MAXPATHLEN];
361 fp = fopen(fname, "r");
364 while ((wd = get_word(fp)) != (char *)EOF) {
368 while (((wd = get_word(fp)) != (char *)EOF) && wd)
374 if (val == (char *)EOF)
378 printf("%s: compat file requires two words "
379 "per line at %s\n", fname, this);
383 (void)snprintf(genopt, sizeof(genopt), "opt_%s.h",
390 insert_option(fname, this, val);
392 update_option(this, val, flags);
399 * read the options and options.<machine> files
404 char fname[MAXPATHLEN];
407 read_option_file("../../conf/options", 0);
408 (void)snprintf(fname, sizeof fname, "../../conf/options.%s",
410 if (!read_option_file(fname, 0)) {
411 (void)snprintf(fname, sizeof fname, "options.%s", machinename);
412 read_option_file(fname, 0);
414 read_option_file("../../conf/options-compat", OL_ALIAS);
424 *str = tolower(*str);