- Allow substition of options values in the generated Makefile using the

syntax %OPTION%.
- Make it possible to specify a syntax version information in the Makefile.
- Bump version to 20090214.
This commit is contained in:
cube 2009-02-15 01:39:54 +00:00
parent f0bb687386
commit 016c56ea2f
2 changed files with 63 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: defs.h,v 1.27 2009/01/20 18:20:48 drochner Exp $ */
/* $NetBSD: defs.h,v 1.28 2009/02/15 01:39:54 cube Exp $ */
/*
* Copyright (c) 1992, 1993
@ -104,7 +104,7 @@ extern const char *progname;
* The next two lines define the current version of the config(1) binary,
* and the minimum version of the configuration files it supports.
*/
#define CONFIG_VERSION 20081219
#define CONFIG_VERSION 20090214
#define CONFIG_MINVERSION 0
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkmakefile.c,v 1.7 2008/07/16 11:45:56 kent Exp $ */
/* $NetBSD: mkmakefile.c,v 1.8 2009/02/15 01:39:54 cube Exp $ */
/*
* Copyright (c) 1992, 1993
@ -74,6 +74,7 @@ static void emitrules(FILE *);
static void emitload(FILE *);
static void emitincludes(FILE *);
static void emitappmkoptions(FILE *);
static void emitsubs(FILE *, const char *, const char *, int);
int
mkmakefile(void)
@ -113,7 +114,7 @@ mkmakefile(void)
lineno = 0;
while (fgets(line, sizeof(line), ifp) != NULL) {
lineno++;
if (line[0] != '%') {
if (version < 20090214 && line[0] != '%') {
fputs(line, ofp);
continue;
}
@ -131,9 +132,20 @@ mkmakefile(void)
fn = emitincludes;
else if (strcmp(line, "%MAKEOPTIONSAPPEND\n") == 0)
fn = emitappmkoptions;
else {
cfgxerror(ifname, lineno,
"unknown %% construct ignored: %s", line);
else if (strncmp(line, "%VERSION ", sizeof("%VERSION ")-1) == 0) {
int newvers;
if (sscanf(line, "%%VERSION %d\n", &newvers) != 1) {
cfgxerror(ifname, lineno, "syntax error for "
"%%VERSION");
} else
setversion(newvers);
continue;
} else {
if (version < 20090214)
cfgxerror(ifname, lineno,
"unknown %% construct ignored: %s", line);
else
emitsubs(ofp, line, ifname, lineno);
continue;
}
(*fn)(ofp);
@ -174,6 +186,50 @@ mkmakefile(void)
return (1);
}
static void
emitsubs(FILE *fp, const char *line, const char *file, int lineno)
{
char *nextpct, *optname;
struct nvlist *option;
while (*line != '\0') {
if (*line != '%') {
fputc(*line++, fp);
continue;
}
line++;
nextpct = strchr(line, '%');
if (nextpct == NULL) {
cfgxerror(file, lineno, "unbalanced %% or "
"unknown construct");
return;
}
*nextpct = '\0';
if (*line == '\0')
fputc('%', fp);
else {
optname = intern(line);
if (!DEFINED_OPTION(optname)) {
cfgxerror(file, lineno, "unknown option %s",
optname);
return;
}
if ((option = ht_lookup(opttab, optname)) == NULL)
option = ht_lookup(fsopttab, optname);
if (option != NULL)
fputs(option->nv_str ? option->nv_str : "1",
fp);
/* Otherwise it's not a selected option and we don't
* output anything. */
}
line = nextpct+1;
}
}
/*
* Return (possibly in a static buffer) the name of the `source' for a
* file. If we have `options source', or if the file is marked `always