Add support for generating "option headers". These allow options to

be included in object dependencies.  config(8) is told to generate
a header for a particular option with the new "defopt" keyword, used
in the files.* system description files.  Options that are placed in
header files are not given -D... cpp flags.

This approach allows options to be turned into headers incrementally,
rather than all at once, and allows for non-header options, as well.
This commit is contained in:
thorpej 1997-02-02 21:12:30 +00:00
parent 8a0d2c8cb0
commit e14a0d029f
6 changed files with 116 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: config.h,v 1.29 1997/01/31 03:12:30 thorpej Exp $ */
/* $NetBSD: config.h,v 1.30 1997/02/02 21:12:30 thorpej Exp $ */
/*
* Copyright (c) 1992, 1993
@ -275,13 +275,16 @@ int maxmaxusers; /* default "maxusers" parameter */
int maxusers; /* configuration's "maxusers" parameter */
int maxpartitions; /* configuration's "maxpartitions" parameter */
struct nvlist *options; /* options */
struct nvlist *defoptions; /* "defopt"'d options */
struct nvlist *fsoptions; /* filesystems */
struct nvlist *mkoptions; /* makeoptions */
struct hashtab *devbasetab; /* devbase lookup */
struct hashtab *devatab; /* devbase attachment lookup */
struct hashtab *selecttab; /* selects things that are "optional foo" */
struct hashtab *needcnttab; /* retains names marked "needs-count" */
struct hashtab *opttab; /* table of configured options */
struct hashtab *fsopttab; /* table of configured file systems */
struct hashtab *defopttab; /* options that have been "defopt"'d */
struct devbase *allbases; /* list of all devbase structures */
struct deva *alldevas; /* list of all devbase attachment structures */
@ -324,6 +327,7 @@ const char *intern __P((const char *));
void addoption __P((const char *name, const char *value));
void addfsoption __P((const char *name));
void addmkoption __P((const char *name, const char *value));
void defoption __P((const char *name));
int devbase_has_instances __P((struct devbase *, int));
int deva_has_instances __P((struct deva *, int));
void setupdirs __P((void));

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: gram.y,v 1.13 1997/01/31 03:12:32 thorpej Exp $ */
/* $NetBSD: gram.y,v 1.14 1997/02/02 21:12:32 thorpej Exp $ */
/*
* Copyright (c) 1992, 1993
@ -99,8 +99,8 @@ static void check_maxpart __P((void));
int val;
}
%token AND AT ATTACH BUILD COMPILE_WITH CONFIG DEFINE DEVICE DUMPS ENDFILE
%token XFILE FILE_SYSTEM FLAGS INCLUDE XMACHINE MAJOR MAKEOPTIONS
%token AND AT ATTACH BUILD COMPILE_WITH CONFIG DEFINE DEFOPT DEVICE DUMPS
%token ENDFILE XFILE FILE_SYSTEM FLAGS INCLUDE XMACHINE MAJOR MAKEOPTIONS
%token MAXUSERS MAXPARTITIONS MINOR ON OPTIONS PSEUDO_DEVICE ROOT SOURCE
%token SWAP TYPE WITH NEEDS_COUNT NEEDS_FLAG
%token <val> NUMBER
@ -220,6 +220,7 @@ one_def:
file |
include |
DEFINE WORD interface_opt { (void)defattr($2, $3); } |
DEFOPT WORD { defoption($2); } |
DEVICE devbase interface_opt attrs_opt
{ defdev($2, 0, $3, $4); } |
ATTACH devbase AT atlist devattach_opt attrs_opt

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.21 1997/01/31 03:12:32 thorpej Exp $ */
/* $NetBSD: main.c,v 1.22 1997/02/02 21:12:33 thorpej Exp $ */
/*
* Copyright (c) 1992, 1993
@ -67,9 +67,9 @@ int yyparse __P((void));
extern char *optarg;
extern int optind;
static struct hashtab *opttab;
static struct hashtab *mkopttab;
static struct nvlist **nextopt;
static struct nvlist **nextdefopt;
static struct nvlist **nextmkopt;
static struct nvlist **nextfsopt;
@ -164,9 +164,11 @@ usage:
opttab = ht_new();
mkopttab = ht_new();
fsopttab = ht_new();
defopttab = ht_new();
nextopt = &options;
nextmkopt = &mkoptions;
nextfsopt = &fsoptions;
nextdefopt = &defoptions;
/*
* Handle profiling (must do this before we try to create any
@ -281,6 +283,38 @@ stop()
exit(1);
}
/*
* Define a standard option, for which a header file will be generated.
*/
void
defoption(name)
const char *name;
{
register const char *n;
register char *p, c;
char low[500];
/*
* Convert to lower case. The header file name will be
* in lower case, so we store the lower case version in
* the hash table to detect option name collisions. The
* original string will be stored in the nvlist for use
* in the header file.
*/
for (n = name, p = low; (c = *n) != '\0'; n++)
*p++ = isupper(c) ? tolower(c) : c;
*p = 0;
n = intern(low);
(void)do_option(defopttab, &nextdefopt, n, name, "defopt");
/*
* Insert a verbatum copy of the option name, as well,
* to speed lookups when creating the Makefile.
*/
(void)ht_insert(defopttab, name, (void *)name);
}
/*
* Add an option from "options FOO". Note that this selects things that
* are "optional foo".

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkheaders.c,v 1.11 1996/08/31 20:58:22 mycroft Exp $ */
/* $NetBSD: mkheaders.c,v 1.12 1997/02/02 21:12:34 thorpej Exp $ */
/*
* Copyright (c) 1992, 1993
@ -53,6 +53,7 @@
#include "config.h"
static int emitcnt __P((struct nvlist *));
static int emitopt __P((struct nvlist *));
static int err __P((const char *, char *, FILE *));
static char *cntname __P((const char *));
@ -63,6 +64,7 @@ int
mkheaders()
{
register struct files *fi;
register struct nvlist *nv;
for (fi = allfiles; fi != NULL; fi = fi->fi_next) {
if (fi->fi_flags & FI_HIDDEN)
@ -71,6 +73,11 @@ mkheaders()
emitcnt(fi->fi_optf))
return (1);
}
for (nv = defoptions; nv != NULL; nv = nv->nv_next)
if (emitopt(nv))
return (1);
return (0);
}
@ -118,6 +125,64 @@ writeit:
return (0);
}
static int
emitopt(nv)
struct nvlist *nv;
{
struct nvlist *option;
char new_contents[BUFSIZ], buf[BUFSIZ];
char fname[BUFSIZ], *p, c;
const char *n;
int nlines;
FILE *fp;
/*
* Generate the new contents of the file.
*/
p = new_contents;
if ((option = ht_lookup(opttab, nv->nv_str)) == NULL)
p += sprintf(p, "/* option `%s' not defined */\n",
nv->nv_str);
else {
p += sprintf(p, "#define\t%s", option->nv_name);
if (option->nv_str != NULL)
p += sprintf(p, "\t%s", option->nv_str);
p += sprintf(p, "\n");
}
/*
* Compare the new file to the old.
*/
sprintf(fname, "opt_%s.h", nv->nv_name);
if ((fp = fopen(fname, "r")) == NULL)
goto writeit;
nlines = 0;
while (fgets(buf, sizeof(buf), fp) != NULL) {
if (++nlines != 1 ||
strcmp(buf, new_contents) != 0)
goto writeit;
}
if (ferror(fp))
return (err("read", fname, fp));
(void)fclose(fp);
if (nlines == 1)
return (0);
writeit:
/*
* They're different, or the file doesn't exist.
*/
if ((fp = fopen(fname, "w")) == NULL) {
(void)fprintf(stderr, "config: cannot write %s: %s\n",
fname, strerror(errno));
return (1);
}
if (fprintf(fp, "%s", new_contents) < 0)
return (err("writ", fname, fp));
if (fclose(fp))
return (err("writ", fname, fp));
return (0);
}
static int
err(what, fname, fp)
const char *what;
@ -129,7 +194,6 @@ err(what, fname, fp)
what, fname, strerror(errno));
if (fp)
(void)fclose(fp);
free(fname);
return (1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkmakefile.c,v 1.33 1997/01/31 03:12:33 thorpej Exp $ */
/* $NetBSD: mkmakefile.c,v 1.34 1997/02/02 21:12:36 thorpej Exp $ */
/*
* Copyright (c) 1992, 1993
@ -184,6 +184,8 @@ emitdefs(fp)
return (1);
sp = "";
for (nv = options; nv != NULL; nv = nv->nv_next) {
if (ht_lookup(defopttab, nv->nv_name) != NULL)
continue;
if (fprintf(fp, "%s-D%s", sp, nv->nv_name) < 0)
return 1;
if (nv->nv_str)

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: scan.l,v 1.12 1997/01/31 03:12:36 thorpej Exp $ */
/* $NetBSD: scan.l,v 1.13 1997/02/02 21:12:37 thorpej Exp $ */
/*
* Copyright (c) 1992, 1993
@ -89,6 +89,7 @@ build return BUILD;
compile-with return COMPILE_WITH;
config return CONFIG;
define return DEFINE;
defopt return DEFOPT;
device return DEVICE;
dumps return DUMPS;
file return XFILE;