Module Name: src Committed By: thorpej Date: Thu Jan 18 04:41:38 UTC 2024
Modified Files: src/usr.bin/config: config.5 defs.h gram.y main.c mkmakefile.c scan.l util.c Log Message: With config(1) as it exists today, a kernel Makefile is able to implement logic on kernel options so long as those options are not defflag'd or defparam'd. This works because such options are automatally added to the IDENT var in the kernel Makefile as a preprocessor define, and the Makefile can then do an operation like: .if !empty(IDENT:M-DSOMECOOLCPUOPTION) CFLAGS+= -mcpu=somecoolcpu .endif Unfortunately, this precludes making it possible to generate a compile-time dependency on SOMECOOLCPUOPTION, or having SOMECOOLCPUOPTION imply another kernel config option using the normal config(1) option dependency function. Fix this by introducing a new option description keyword: mkflagvar. This keyword marks an already defflag'd option as wanting a kernel Makefile var defined if that option is selected in the kernel config file. So: defflag opt_coolcpu.h SOMECOOLCPUOPTION ANOTHERCOOLCPUOPTION mkflagvar SOMECOOLCPUOPTION ANOTHERCOOLCPUOPTION will cause: KERNEL_OPT_SOMECOOLCPUOPTION="1" KERNEL_OPT_ANOTHERCOOLCPUOPTION="1" ...to be emitted into the kernel Makefile if those options are, in fact, selected with "options ..." in the kernel config file, thus allowing for a compile-time dependency on the option to be generated in addition to Makefile logic, which now looks like: .if !empty(KERNEL_OPT_SOMECOOLCPUOPTION) CFLAGS+= -mcpu=somecoolcpu .endif To generate a diff of this commit: cvs rdiff -u -r1.47 -r1.48 src/usr.bin/config/config.5 cvs rdiff -u -r1.106 -r1.107 src/usr.bin/config/defs.h cvs rdiff -u -r1.56 -r1.57 src/usr.bin/config/gram.y cvs rdiff -u -r1.100 -r1.101 src/usr.bin/config/main.c cvs rdiff -u -r1.71 -r1.72 src/usr.bin/config/mkmakefile.c cvs rdiff -u -r1.34 -r1.35 src/usr.bin/config/scan.l cvs rdiff -u -r1.21 -r1.22 src/usr.bin/config/util.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/config/config.5 diff -u src/usr.bin/config/config.5:1.47 src/usr.bin/config/config.5:1.48 --- src/usr.bin/config/config.5:1.47 Mon Oct 4 14:35:20 2021 +++ src/usr.bin/config/config.5 Thu Jan 18 04:41:37 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: config.5,v 1.47 2021/10/04 14:35:20 andvar Exp $ +.\" $NetBSD: config.5,v 1.48 2024/01/18 04:41:37 thorpej Exp $ .\" .\" Copyright (c) 2006, 2007 The NetBSD Foundation. .\" All rights reserved. @@ -24,7 +24,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd July 19, 2016 +.Dd January 17, 2024 .Dt CONFIG 5 .Os .Sh NAME @@ -459,6 +459,24 @@ The optional argument should match the original definition of the option. .\" .Pp +.It Ic mkflagvar \ + Ar option ... +Specifes that an option previously defined with +.Ic defflag +should have a variable created in the kernel Makefile if the option +is selection with an +.Ic options +statement. +No variable is created if the option is not selected. +The Makefile variable will have the name +.Li KERNEL_OPT_ Ns Aq Ar option +and, because options defined with +.Ic defflag +are boolean, +the variable will have the value +.Dq 1 . +.\" +.Pp .It Ic define \ Ar attribute \ Oo Ic \&{ Ar locators Ic \&} Oc \ Index: src/usr.bin/config/defs.h diff -u src/usr.bin/config/defs.h:1.106 src/usr.bin/config/defs.h:1.107 --- src/usr.bin/config/defs.h:1.106 Fri Apr 3 19:53:41 2020 +++ src/usr.bin/config/defs.h Thu Jan 18 04:41:37 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: defs.h,v 1.106 2020/04/03 19:53:41 joerg Exp $ */ +/* $NetBSD: defs.h,v 1.107 2024/01/18 04:41:37 thorpej Exp $ */ /* * Copyright (c) 1992, 1993 @@ -151,6 +151,7 @@ struct defoptlist { const char *dl_value; const char *dl_lintvalue; int dl_obsolete; + int dl_mkvar; struct nvlist *dl_depends; struct where dl_where; }; @@ -591,10 +592,12 @@ void delfsoption(const char *, int); void delmkoption(const char *, int); int devbase_has_instances(struct devbase *, int); struct where *find_declared_option(const char *); +struct defoptlist *find_declared_option_option(const char *name); int deva_has_instances(struct deva *, int); void setupdirs(void); void fixmaxusers(void); void fixmkoption(void); +void mkflagvar(struct defoptlist *); const char *strtolower(const char *); /* tests on option types */ Index: src/usr.bin/config/gram.y diff -u src/usr.bin/config/gram.y:1.56 src/usr.bin/config/gram.y:1.57 --- src/usr.bin/config/gram.y:1.56 Sun Jul 26 22:40:52 2020 +++ src/usr.bin/config/gram.y Thu Jan 18 04:41:37 2024 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: gram.y,v 1.56 2020/07/26 22:40:52 uwe Exp $ */ +/* $NetBSD: gram.y,v 1.57 2024/01/18 04:41:37 thorpej Exp $ */ /* * Copyright (c) 1992, 1993 @@ -42,7 +42,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: gram.y,v 1.56 2020/07/26 22:40:52 uwe Exp $"); +__RCSID("$NetBSD: gram.y,v 1.57 2024/01/18 04:41:37 thorpej Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -179,6 +179,7 @@ static struct loclist *namelocvals(const %token IDENT IOCONF %token LINKZERO %token XMACHINE MAJOR MAKEOPTIONS MAXUSERS MAXPARTITIONS MINOR +%token MKFLAGVAR %token NEEDS_COUNT NEEDS_FLAG NO CNO %token XOBJECT OBSOLETE ON OPTIONS %token PACKAGE PLUSEQ PREFIX BUILDPREFIX PSEUDO_DEVICE PSEUDO_ROOT @@ -334,6 +335,7 @@ definition: | define_attribute | define_option | define_flag + | define_flag_mkvar | define_obsolete_flag | define_param | define_obsolete_param @@ -402,6 +404,10 @@ define_flag: { defflag($2, $3, $4, 0); } ; +define_flag_mkvar: + MKFLAGVAR defopts + { mkflagvar($2); } + define_obsolete_flag: OBSOLETE DEFFLAG optfile_opt defopts { defflag($3, $4, NULL, 1); } Index: src/usr.bin/config/main.c diff -u src/usr.bin/config/main.c:1.100 src/usr.bin/config/main.c:1.101 --- src/usr.bin/config/main.c:1.100 Fri Apr 3 19:53:41 2020 +++ src/usr.bin/config/main.c Thu Jan 18 04:41:37 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.100 2020/04/03 19:53:41 joerg Exp $ */ +/* $NetBSD: main.c,v 1.101 2024/01/18 04:41:37 thorpej Exp $ */ /* * Copyright (c) 1992, 1993 @@ -45,7 +45,7 @@ #endif #include <sys/cdefs.h> -__RCSID("$NetBSD: main.c,v 1.100 2020/04/03 19:53:41 joerg Exp $"); +__RCSID("$NetBSD: main.c,v 1.101 2024/01/18 04:41:37 thorpej Exp $"); #ifndef MAKE_BOOTSTRAP #include <sys/cdefs.h> @@ -210,7 +210,6 @@ static int kill_orphans_cb(const char *, static int cfcrosscheck(struct config *, const char *, struct nvlist *); static void defopt(struct dlhash *ht, const char *fname, struct defoptlist *opts, struct nvlist *deps, int obs); -static struct defoptlist *find_declared_option_option(const char *name); static struct nvlist *find_declared_fs_option(const char *name); #define LOGCONFIG_LARGE "INCLUDE_CONFIG_FILE" @@ -922,7 +921,7 @@ badfilename(const char *fname) * This used to be one function (find_declared_option) before options * and filesystems became different types. */ -static struct defoptlist * +struct defoptlist * find_declared_option_option(const char *name) { struct defoptlist *option; @@ -1065,6 +1064,27 @@ defopt(struct dlhash *ht, const char *fn } /* + * Specify that a defined option should have a Makefile variable created. + */ +static void +mkoptvar(struct dlhash *ht, struct defoptlist *opts) +{ + struct defoptlist *dl, *defined_dl; + + for (dl = opts; dl != NULL; dl = dl->dl_next) { + defined_dl = dlhash_lookup(ht, dl->dl_name); + if (defined_dl == NULL) { + cfgerror("option `%s' not defined" + " at %s:%hu", dl->dl_name, dl->dl_where.w_srcfile, + dl->dl_where.w_srcline); + continue; + } + defined_dl->dl_mkvar = 1; + } + defoptlist_destroy(dl); +} + +/* * Define one or more standard options. If an option file name is specified, * place all options in one file with the specified name. Otherwise, create * an option file for each option. @@ -1099,6 +1119,16 @@ defflag(const char *fname, struct defopt defopt(defflagtab, fname, opts, deps, obs); } +/* + * Specify that a defined flag option should have a Makefile variable + * created. + */ +void +mkflagvar(struct defoptlist *opts) +{ + + mkoptvar(defflagtab, opts); +} /* * Add an option from "options FOO". Note that this selects things that Index: src/usr.bin/config/mkmakefile.c diff -u src/usr.bin/config/mkmakefile.c:1.71 src/usr.bin/config/mkmakefile.c:1.72 --- src/usr.bin/config/mkmakefile.c:1.71 Mon Aug 27 05:35:00 2018 +++ src/usr.bin/config/mkmakefile.c Thu Jan 18 04:41:37 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: mkmakefile.c,v 1.71 2018/08/27 05:35:00 riastradh Exp $ */ +/* $NetBSD: mkmakefile.c,v 1.72 2024/01/18 04:41:37 thorpej Exp $ */ /* * Copyright (c) 1992, 1993 @@ -45,7 +45,7 @@ #endif #include <sys/cdefs.h> -__RCSID("$NetBSD: mkmakefile.c,v 1.71 2018/08/27 05:35:00 riastradh Exp $"); +__RCSID("$NetBSD: mkmakefile.c,v 1.72 2024/01/18 04:41:37 thorpej Exp $"); #include <sys/param.h> #include <ctype.h> @@ -275,6 +275,7 @@ emitsubs(FILE *fp, const char *line, con static void emitdefs(FILE *fp) { + struct defoptlist *dl; struct nvlist *nv; fprintf(fp, "KERNEL_BUILD=%s\n", conffile); @@ -308,6 +309,22 @@ emitdefs(FILE *fp) } for (nv = mkoptions; nv != NULL; nv = nv->nv_next) emitmkoption(fp, "=", nv); + + /* + * Go through the options again and emit Makefile variables + * for those specified to get one. + */ + for (nv = options; nv != NULL; nv = nv->nv_next) { + + dl = find_declared_option_option(nv->nv_name); + if (dl != NULL && dl->dl_mkvar) { + const char *s = nv->nv_str; + if (s == NULL) { + s = "1"; + } + fprintf(fp, "KERNEL_OPT_%s=\"%s\"\n", nv->nv_name, s); + } + } } static void Index: src/usr.bin/config/scan.l diff -u src/usr.bin/config/scan.l:1.34 src/usr.bin/config/scan.l:1.35 --- src/usr.bin/config/scan.l:1.34 Fri Sep 10 21:52:17 2021 +++ src/usr.bin/config/scan.l Thu Jan 18 04:41:37 2024 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: scan.l,v 1.34 2021/09/10 21:52:17 rillig Exp $ */ +/* $NetBSD: scan.l,v 1.35 2024/01/18 04:41:37 thorpej Exp $ */ /* * Copyright (c) 1992, 1993 @@ -42,7 +42,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: scan.l,v 1.34 2021/09/10 21:52:17 rillig Exp $"); +__RCSID("$NetBSD: scan.l,v 1.35 2024/01/18 04:41:37 thorpej Exp $"); #include <sys/param.h> #include <errno.h> @@ -164,6 +164,7 @@ linkzero return LINKZERO; machine return XMACHINE; major return MAJOR; makeoptions return MAKEOPTIONS; +mkflagvar return MKFLAGVAR; maxpartitions return MAXPARTITIONS; maxusers return MAXUSERS; minor return MINOR; Index: src/usr.bin/config/util.c diff -u src/usr.bin/config/util.c:1.21 src/usr.bin/config/util.c:1.22 --- src/usr.bin/config/util.c:1.21 Sat Mar 7 19:26:13 2020 +++ src/usr.bin/config/util.c Thu Jan 18 04:41:38 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.21 2020/03/07 19:26:13 christos Exp $ */ +/* $NetBSD: util.c,v 1.22 2024/01/18 04:41:38 thorpej Exp $ */ /* * Copyright (c) 1992, 1993 @@ -45,7 +45,7 @@ #endif #include <sys/cdefs.h> -__RCSID("$NetBSD: util.c,v 1.21 2020/03/07 19:26:13 christos Exp $"); +__RCSID("$NetBSD: util.c,v 1.22 2024/01/18 04:41:38 thorpej Exp $"); #include <sys/types.h> #include <assert.h> @@ -258,6 +258,7 @@ defoptlist_create(const char *name, cons dl->dl_value = val; dl->dl_lintvalue = lintval; dl->dl_obsolete = 0; + dl->dl_mkvar = 0; dl->dl_depends = NULL; dl->dl_where.w_srcfile = yyfile; dl->dl_where.w_srcline = currentline();