summaryrefslogtreecommitdiffstats
path: root/usr.sbin/config
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1995-12-11 10:52:34 +0000
committerpeter <peter@FreeBSD.org>1995-12-11 10:52:34 +0000
commit7a7fb14fa9b36f5a77f0861c85e6bb995aa6b757 (patch)
treeef03c70fe9e388e67ab0c2e18b675681568a8009 /usr.sbin/config
parentd7af2f0a80cee1f5b4fa606c79490ec68445ee7b (diff)
downloadFreeBSD-src-7a7fb14fa9b36f5a77f0861c85e6bb995aa6b757.zip
FreeBSD-src-7a7fb14fa9b36f5a77f0861c85e6bb995aa6b757.tar.gz
Implement support for conf/options and i386/conf/options.i386
Note that this code is dormant unless the options files exist. Also, parsing of quoted options in the config files is improved. What this allows, is all the options in LINT to be specified to be configured as #defines in a file rather than on the CC command line at kernel build time. This means that 'make depend' will catch dependencies on actual *options*, meaning that you can run 'config' and 'make depend' in complete safety WITHOUT removing the compile directory each time. Unfortunately, this requires a pass over the source to get the individual files to #include the new .h files that would be generated by config. This has a small compile time penalty (appears up to about 2% slower) from a "fresh" build. Of course, you should not be needing to do complete rebuilds very often once this was completed, so it would be an overall win for most people. Since this code is dormant and we've got a lot of other things happening on the kernel tree at the moment (prototypes, devfs, static declarations etc) I am not planning on doing any changes to activate this feature just yet.
Diffstat (limited to 'usr.sbin/config')
-rw-r--r--usr.sbin/config/Makefile2
-rw-r--r--usr.sbin/config/config.h9
-rw-r--r--usr.sbin/config/config.y24
-rw-r--r--usr.sbin/config/lang.l8
-rw-r--r--usr.sbin/config/main.c5
-rw-r--r--usr.sbin/config/mkheaders.c6
-rw-r--r--usr.sbin/config/mkmakefile.c30
-rw-r--r--usr.sbin/config/mkoptions.c316
-rw-r--r--usr.sbin/config/mkswapconf.c1
9 files changed, 393 insertions, 8 deletions
diff --git a/usr.sbin/config/Makefile b/usr.sbin/config/Makefile
index 36e3d17..55f213e 100644
--- a/usr.sbin/config/Makefile
+++ b/usr.sbin/config/Makefile
@@ -3,7 +3,7 @@
PROG= config
CFLAGS+=-I. -I${.CURDIR}
SRCS= config.c main.c lang.c mkioconf.c mkmakefile.c mkglue.c mkheaders.c \
- mkswapconf.c
+ mkoptions.c mkswapconf.c
MAN8= config.8
DPADD= ${LIBL}
LDADD= -ll
diff --git a/usr.sbin/config/config.h b/usr.sbin/config/config.h
index c906e2b..41e492f 100644
--- a/usr.sbin/config/config.h
+++ b/usr.sbin/config/config.h
@@ -174,9 +174,16 @@ struct cputype {
struct opt {
char *op_name;
char *op_value;
+ int op_ownfile; /* true = own file, false = makefile */
struct opt *op_next;
} *opt, *mkopt;
+struct opt_list {
+ char *o_name;
+ char *o_file;
+ struct opt_list *o_next;
+} *otab;
+
char *ident;
char *ns();
char *tc();
@@ -216,4 +223,6 @@ int debugging;
int maxusers;
u_int loadaddress;
+extern int old_config_present; /* Old config/build directory still there */
+
#define eq(a,b) (!strcmp(a,b))
diff --git a/usr.sbin/config/config.y b/usr.sbin/config/config.y
index c161952..78d8bf4 100644
--- a/usr.sbin/config/config.y
+++ b/usr.sbin/config/config.y
@@ -9,6 +9,7 @@
%token ANY
%token ARGS
%token AT
+%token AUTO
%token BIO
%token BUS
%token COMMA
@@ -37,6 +38,7 @@
%token MINUS
%token NET
%token NEXUS
+%token NONE
%token ON
%token OPTIONS
%token MAKEOPTIONS
@@ -118,6 +120,7 @@
#include <ctype.h>
#include <stdio.h>
#include <err.h>
+#include <string.h>
struct device cur;
struct device *curp = 0;
@@ -183,6 +186,7 @@ Config_spec:
= {
struct cputype *cp =
(struct cputype *)malloc(sizeof (struct cputype));
+ memset(cp, 0, sizeof(*cp));
cp->cpu_name = ns($2);
cp->cpu_next = cputype;
cputype = cp;
@@ -389,15 +393,23 @@ Option:
Save_id
= {
struct opt *op = (struct opt *)malloc(sizeof (struct opt));
+ char *s;
+ memset(op, 0, sizeof(*op));
op->op_name = ns($1);
op->op_next = opt;
op->op_value = 0;
opt = op;
+ if (s = strchr(op->op_name, '=')) {
+ /* AARGH!!!! Old-style bogon */
+ *s = '\0';
+ op->op_value = ns(s + 1);
+ }
free(temp_id);
} |
Save_id EQUALS Opt_value
= {
struct opt *op = (struct opt *)malloc(sizeof (struct opt));
+ memset(op, 0, sizeof(*op));
op->op_name = ns($1);
op->op_next = opt;
op->op_value = ns($3);
@@ -432,7 +444,9 @@ Mkoption:
Save_id EQUALS Opt_value
= {
struct opt *op = (struct opt *)malloc(sizeof (struct opt));
+ memset(op, 0, sizeof(*op));
op->op_name = ns($1);
+ op->op_ownfile = 0; /* for now */
op->op_next = mkopt;
op->op_value = ns($3);
mkopt = op;
@@ -607,6 +621,10 @@ Info:
= { cur.d_port = ns($2); } |
PORT NUMBER
= { cur.d_portn = $2; } |
+ PORT AUTO
+ = { cur.d_portn = -1; } |
+ PORT NONE
+ = { cur.d_portn = -2; } |
TTY
= { cur.d_mask = "tty"; } |
BIO
@@ -630,11 +648,13 @@ Id_list:
Save_id
= {
struct idlst *a = (struct idlst *)malloc(sizeof(struct idlst));
+ memset(a, 0, sizeof(*a));
a->id = $1; a->id_next = 0; $$ = a;
} |
Save_id Id_list =
{
struct idlst *a = (struct idlst *)malloc(sizeof(struct idlst));
+ memset(a, 0, sizeof(*a));
a->id = $1; a->id_next = $2; $$ = a;
};
@@ -670,6 +690,7 @@ newdev(dp)
register struct device *np;
np = (struct device *) malloc(sizeof *np);
+ memset(np, 0, sizeof(*np));
*np = *dp;
np->d_next = 0;
if (curp == 0)
@@ -688,6 +709,7 @@ mkconf(sysname)
register struct file_list *fl, **flp;
fl = (struct file_list *) malloc(sizeof *fl);
+ memset(fl, 0, sizeof(*fl));
fl->f_type = SYSTEMSPEC;
fl->f_needs = sysname;
fl->f_rootdev = NODEV;
@@ -705,6 +727,7 @@ newflist(ftype)
u_char ftype;
{
struct file_list *fl = (struct file_list *)malloc(sizeof (*fl));
+ memset(fl, 0, sizeof(*fl));
fl->f_type = ftype;
fl->f_next = 0;
@@ -763,6 +786,7 @@ mkcomp(dp)
char buf[80];
fl = (struct file_list *) malloc(sizeof *fl);
+ memset(fl, 0, sizeof(*fl));
fl->f_type = COMPDEVICE;
fl->f_compinfo = dp->d_unit;
fl->f_fn = ns(dp->d_name);
diff --git a/usr.sbin/config/lang.l b/usr.sbin/config/lang.l
index 84fdf70..3d80f5d 100644
--- a/usr.sbin/config/lang.l
+++ b/usr.sbin/config/lang.l
@@ -52,6 +52,7 @@ struct kt {
{ "and", AND },
{ "args", ARGS },
{ "at", AT },
+ { "auto", AUTO },
#if MACHINE_I386
{ "bio", BIO },
{ "bus", BUS },
@@ -86,6 +87,7 @@ struct kt {
{ "net", NET },
#endif MACHINE_I386
{ "nexus", NEXUS },
+ { "none", NONE },
{ "on", ON },
{ "options", OPTIONS },
#if MACHINE_I386
@@ -126,6 +128,12 @@ WORD [A-Za-z_][-A-Za-z_]*
tprintf("(%s) ", yytext);
return i;
}
+\\\"[^"]+\\\" {
+ yytext[strlen(yytext)-2] = '"';
+ yytext[strlen(yytext)-1] = '\0';
+ yylval.str = strdup(yytext + 1);
+ return ID;
+ }
\"[^"]+\" {
yytext[strlen(yytext)-1] = '\0';
yylval.str = strdup(yytext + 1);
diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c
index 98d9bf7..3369504 100644
--- a/usr.sbin/config/main.c
+++ b/usr.sbin/config/main.c
@@ -59,6 +59,7 @@ static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
static char *PREFIX;
static int no_config_clobber = FALSE;
+int old_config_present;
/*
* Config builds a set of files for building a UNIX
@@ -135,6 +136,9 @@ usage: fputs("usage: config [-gpn] sysname\n", stderr);
}
}
#endif
+ else
+ old_config_present++;
+
loadaddress = -1;
dtab = NULL;
confp = &conf_list;
@@ -188,6 +192,7 @@ usage: fputs("usage: config [-gpn] sysname\n", stderr);
(void) sprintf(xxx, "../../%s/include", machinename);
(void) symlink(xxx, path("machine"));
}
+ options(); /* make options .h files */
makefile(); /* build Makefile */
headers(); /* make a lot of .h files */
swapconf(); /* swap config files */
diff --git a/usr.sbin/config/mkheaders.c b/usr.sbin/config/mkheaders.c
index 7929987..bfa5692 100644
--- a/usr.sbin/config/mkheaders.c
+++ b/usr.sbin/config/mkheaders.c
@@ -140,7 +140,7 @@ do_header(dev, hname, count)
break;
fl = (struct file_list *) malloc(sizeof *fl);
bzero(fl, sizeof(*fl));
- fl->f_fn = inw;
+ fl->f_fn = inw; /* malloced */
fl->f_type = inc;
fl->f_next = fl_head;
fl_head = fl;
@@ -149,6 +149,7 @@ do_header(dev, hname, count)
if (count == oldcount) {
for (fl = fl_head; fl != NULL; fl = tflp) {
tflp = fl->f_next;
+ free(fl->f_fn);
free(fl);
}
return;
@@ -156,7 +157,7 @@ do_header(dev, hname, count)
if (oldcount == -1) {
fl = (struct file_list *) malloc(sizeof *fl);
bzero(fl, sizeof(*fl));
- fl->f_fn = name;
+ fl->f_fn = ns(name); /* malloced */
fl->f_type = count;
fl->f_next = fl_head;
fl_head = fl;
@@ -170,6 +171,7 @@ do_header(dev, hname, count)
fprintf(outf,
"#define %s %u\n", fl->f_fn, count ? fl->f_type : 0);
tflp = fl->f_next;
+ free(fl->f_fn);
free(fl);
}
(void) fclose(outf);
diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c
index 1a347e8..8f6ca3a 100644
--- a/usr.sbin/config/mkmakefile.c
+++ b/usr.sbin/config/mkmakefile.c
@@ -63,6 +63,7 @@ static char sccsid[] = "@(#)mkmakefile.c 8.1 (Berkeley) 6/6/93";
static struct file_list *fcur;
char *tail();
+extern int old_config_present;
/*
* Lookup a file, by name.
@@ -139,6 +140,7 @@ makefile()
char line[BUFSIZ];
struct opt *op;
struct users *up;
+ int warn_make_clean = 0;
read_files();
strcpy(line, "Makefile.");
@@ -157,19 +159,27 @@ makefile()
fprintf(ofp, "IDENT=");
if (profiling)
fprintf(ofp, " -DGPROF");
+
if (cputype == 0) {
printf("cpu type must be specified\n");
exit(1);
}
+#if 0
+ /* XXX: moved to cputype.h */
{ struct cputype *cp;
for (cp = cputype; cp; cp = cp->cpu_next)
fprintf(ofp, " -D%s", cp->cpu_name);
}
- for (op = opt; op; op = op->op_next)
- if (op->op_value)
- fprintf(ofp, " -D%s=\"%s\"", op->op_name, op->op_value);
- else
- fprintf(ofp, " -D%s", op->op_name);
+#endif
+ for (op = opt; op; op = op->op_next) {
+ if (!op->op_ownfile) {
+ warn_make_clean++;
+ if (op->op_value)
+ fprintf(ofp, " -D%s=%s", op->op_name, op->op_value);
+ else
+ fprintf(ofp, " -D%s", op->op_name);
+ }
+ }
fprintf(ofp, "\n");
if ((unsigned)machine > NUSERS) {
printf("maxusers config info isn't present, using vax\n");
@@ -220,6 +230,15 @@ makefile()
}
(void) fclose(ifp);
(void) fclose(ofp);
+#ifdef notyet
+ if (warn_make_clean) {
+ printf("WARNING: Unknown options used (not in ../../conf/options or ./options.%s).\n", machinename);
+ if (old_config_present) {
+ printf("It is VERY important that you do a ``make clean'' before recompiling!\n");
+ }
+ }
+ printf("Don't forget to do a ``make depend''\n");
+#endif
}
/*
@@ -395,6 +414,7 @@ nextparam:
}
if (std) {
dp = (struct device *) malloc(sizeof *dp);
+ bzero(dp, sizeof *dp);
init_dev(dp);
dp->d_name = ns(wd);
dp->d_type = PSEUDO_DEVICE;
diff --git a/usr.sbin/config/mkoptions.c b/usr.sbin/config/mkoptions.c
new file mode 100644
index 0000000..f722d93
--- /dev/null
+++ b/usr.sbin/config/mkoptions.c
@@ -0,0 +1,316 @@
+/*
+ * Copyright (c) 1995 Peter Wemm
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)mkheaders.c 8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
+
+/*
+ * Make all the .h files for the optional entries
+ */
+
+#include <stdio.h>
+#include <ctype.h>
+#include "config.h"
+#include "y.tab.h"
+
+options()
+{
+ struct opt_list *ol;
+
+ /* fake the cpu types as options */
+ /* Please forgive me for this hack.. :-) */
+ struct opt *op;
+ struct cputype *cp;
+
+ for (cp = cputype; cp; cp = cp->cpu_next) {
+ struct opt *op = (struct opt *)malloc(sizeof (struct opt));
+ memset(op, 0, sizeof(*op));
+ op->op_name = cp->cpu_name;
+ op->op_value = 0;
+ op->op_next = opt;
+ opt = op;
+ }
+
+ read_options();
+ for (ol = otab; ol != 0; ol = ol->o_next)
+ do_option(ol->o_name);
+}
+
+/*
+ * Generate an <options>.h file
+ */
+
+do_option(name)
+ char *name;
+{
+ char *file, *inw, *tooption();
+ struct opt *op, *op_head, *topp;
+ FILE *inf, *outf;
+ char *value;
+ char *oldvalue;
+ int seen;
+
+ file = tooption(name);
+
+ /*
+ * Check to see if the option was specified..
+ */
+ value = NULL;
+ for (op = opt; op; op = op->op_next) {
+ if (eq(name, op->op_name)) {
+ value = op->op_value;
+ if (!value)
+ value = ns("1");
+ op->op_ownfile++;
+ }
+ }
+
+ inf = fopen(file, "r");
+ if (inf == 0) {
+ outf = fopen(file, "w");
+ if (outf == 0) {
+ perror(file);
+ exit(1);
+ }
+
+ /* was the option in the config file? */
+ if (value) {
+ fprintf(outf, "#define %s %s\n", name, value);
+ } /* else empty file */
+
+ (void) fclose(outf);
+ return;
+ }
+ oldvalue = NULL;
+ op_head = NULL;
+ seen = 0;
+ for (;;) {
+ char *cp;
+ char *invalue;
+
+ /* get the #define */
+ if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
+ break;
+ /* get the option name */
+ if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
+ break;
+ inw = ns(inw);
+ cp = get_word(inf);
+ if (cp == 0 || cp == (char *)EOF)
+ break;
+ /* option value */
+ invalue = ns(cp); /* malloced */
+ if (eq(inw, name)) {
+ oldvalue = invalue;
+ invalue = value;
+ seen++;
+ }
+ op = (struct opt *) malloc(sizeof *op);
+ bzero(op, sizeof(*op));
+ op->op_name = inw;
+ op->op_value = invalue;
+ op->op_next = op_head;
+ op_head = op;
+
+ /* EOL? */
+ cp = get_word(inf);
+ if (cp == (char *)EOF)
+ break;
+ }
+ (void) fclose(inf);
+ if ((value == NULL && oldvalue == NULL) ||
+ (value && oldvalue && eq(value,oldvalue))) {
+ for (op = op_head; op != NULL; op = topp) {
+ topp = op->op_next;
+ free(op->op_name);
+ free(op->op_value);
+ free(op);
+ }
+ return;
+ }
+
+ if (value && !seen) {
+ /* New option appears */
+ op = (struct opt *) malloc(sizeof *op);
+ bzero(op, sizeof(*op));
+ op->op_name = ns(name);
+ op->op_value = value ? ns(value) : NULL;
+ op->op_next = op_head;
+ op_head = op;
+ }
+
+ outf = fopen(file, "w");
+ if (outf == 0) {
+ perror(file);
+ exit(1);
+ }
+ for (op = op_head; op != NULL; op = topp) {
+ /* was the option in the config file? */
+ if (op->op_value) {
+ fprintf(outf, "#define %s %s\n",
+ op->op_name, op->op_value);
+ }
+ topp = op->op_next;
+ free(op->op_name);
+ free(op->op_value);
+ free(op);
+ }
+ (void) fclose(outf);
+}
+
+/*
+ * Find the filename to store the option spec into.
+ */
+char *
+tooption(name)
+ char *name;
+{
+ static char hbuf[80];
+ char nbuf[80];
+ struct opt_list *po;
+
+ /* "cannot happen"? the otab list should be complete.. */
+ (void) strcpy(nbuf, "options.h");
+
+ for (po = otab ; po != 0; po = po->o_next) {
+ if (eq(po->o_name, name)) {
+ strcpy(nbuf, po->o_file);
+ break;
+ }
+ }
+
+ (void) strcpy(hbuf, path(nbuf));
+ return (hbuf);
+}
+
+/*
+ * read the options and options.<machine> files
+ */
+read_options()
+{
+ FILE *fp;
+ char fname[32];
+ char *wd, *this, *val;
+ struct opt_list *po;
+ int first = 1;
+ char genopt[80];
+ char *lower();
+
+ otab = 0;
+ (void) strcpy(fname, "../../conf/options");
+openit:
+ fp = fopen(fname, "r");
+ if (fp == 0) {
+ return;
+ }
+ if(ident == NULL) {
+ printf("no ident line specified\n");
+ exit(1);
+ }
+next:
+ wd = get_word(fp);
+ if (wd == (char *)EOF) {
+ (void) fclose(fp);
+ if (first == 1) {
+ (void) sprintf(fname, "options.%s", machinename);
+ first++;
+ goto openit;
+ }
+ if (first == 2) {
+ (void) sprintf(fname, "options.%s", raise(ident));
+ first++;
+ fp = fopen(fname, "r");
+ if (fp != 0)
+ goto next;
+ }
+ return;
+ }
+ if (wd == 0)
+ goto next;
+ /*************************************************\
+ * If it's a comment ignore to the end of the line *
+ \*************************************************/
+ if(wd[0] == '#')
+ {
+ while( ((wd = get_word(fp)) != (char *)EOF) && wd)
+ ;
+ goto next;
+ }
+ this = ns(wd);
+ val = get_word(fp);
+ if (val == (char *)EOF)
+ return;
+ if (val == 0) {
+ char *s = ns(this);
+ (void) strcpy(genopt, "opt_");
+ (void) strcat(genopt, lower(s));
+ (void) strcat(genopt, ".h");
+ val = genopt;
+ free(s);
+ }
+ val = ns(val);
+
+ for (po = otab ; po != 0; po = po->o_next) {
+ if (eq(po->o_name, this)) {
+ printf("%s: Duplicate option %s.\n",
+ fname, this);
+ exit(1);
+ }
+ }
+
+ po = (struct opt_list *) malloc(sizeof *po);
+ bzero(po, sizeof(*po));
+ po->o_name = this;
+ po->o_file = val;
+ po->o_next = otab;
+ otab = po;
+
+ goto next;
+}
+
+char *
+lower(str)
+ register char *str;
+{
+ register char *cp = str;
+
+ while (*str) {
+ if (isupper(*str))
+ *str = tolower(*str);
+ str++;
+ }
+ return (cp);
+}
+
diff --git a/usr.sbin/config/mkswapconf.c b/usr.sbin/config/mkswapconf.c
index 9722d9c..39d964b 100644
--- a/usr.sbin/config/mkswapconf.c
+++ b/usr.sbin/config/mkswapconf.c
@@ -245,6 +245,7 @@ initdevtable()
if (sscanf(linebuf, "%s\t%d\n", buf, &maj) == 2) {
*dp = (struct devdescription *)malloc(sizeof (**dp));
+ memset(*dp, 0, sizeof(**dp));
(*dp)->dev_name = ns(buf);
(*dp)->dev_major = maj;
dp = &(*dp)->dev_next;
OpenPOWER on IntegriCloud