Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/config Add two new options, -U and -D, that can be u...



details:   https://anonhg.NetBSD.org/src/rev/253b4b241f37
branches:  trunk
changeset: 329083:253b4b241f37
user:      martin <martin%NetBSD.org@localhost>
date:      Mon May 05 19:08:13 2014 +0000

description:
Add two new options, -U and -D, that can be used to define "makeoptions"
on the config command line. While there, rename the undocumented (internal)
parser debug option from -D to -d.
Discussed on tech-toolchain.

diffstat:

 usr.bin/config/config.1 |  15 ++++++++-
 usr.bin/config/defs.h   |   4 +-
 usr.bin/config/main.c   |  85 ++++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 97 insertions(+), 7 deletions(-)

diffs (223 lines):

diff -r 6cb8ba17b427 -r 253b4b241f37 usr.bin/config/config.1
--- a/usr.bin/config/config.1   Mon May 05 19:06:29 2014 +0000
+++ b/usr.bin/config/config.1   Mon May 05 19:08:13 2014 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: config.1,v 1.13 2012/08/30 12:42:41 wiz Exp $
+.\"    $NetBSD: config.1,v 1.14 2014/05/05 19:08:13 martin Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -40,6 +40,8 @@
 .Op Fl Ppv
 .Op Fl b Ar builddir
 .Op Fl s Ar srcdir
+.Op Fl D Ar var=value
+.Op Fl U Ar value
 .Op Ar config-file
 .Nm
 .Fl x
@@ -109,6 +111,11 @@
 .Ar builddir
 as the kernel build directory, instead of computing and creating one
 automatically.
+.It Fl D Ar var=value
+Define a makeoptions variable to the given value.
+This is equivalent to appending a 
+.Li makeoptions var=value
+line to the config file.
 .It Fl L
 Generate a lint configuration.
 See section
@@ -131,6 +138,12 @@
 when it is used in combination with the
 .Fl L
 flag.
+.It Fl U Ar var
+Undefine the makeoption
+.Ar var .
+This is equivalent to appending the line
+.Li no makeoptions var
+to the config file.
 .It Fl v
 Increase verbosity by enabling some more warnings.
 .It Fl x
diff -r 6cb8ba17b427 -r 253b4b241f37 usr.bin/config/defs.h
--- a/usr.bin/config/defs.h     Mon May 05 19:06:29 2014 +0000
+++ b/usr.bin/config/defs.h     Mon May 05 19:08:13 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.44 2012/06/08 08:56:45 martin Exp $ */
+/*     $NetBSD: defs.h,v 1.45 2014/05/05 19:08:13 martin Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -107,7 +107,7 @@
  * 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         20100430
+#define CONFIG_VERSION         20140502
 #define CONFIG_MINVERSION      0
 
 /*
diff -r 6cb8ba17b427 -r 253b4b241f37 usr.bin/config/main.c
--- a/usr.bin/config/main.c     Mon May 05 19:06:29 2014 +0000
+++ b/usr.bin/config/main.c     Mon May 05 19:08:13 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.51 2013/11/01 21:39:13 christos Exp $       */
+/*     $NetBSD: main.c,v 1.52 2014/05/05 19:08:13 martin Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -86,6 +86,7 @@
 int    vflag;                          /* verbose output */
 int    Pflag;                          /* pack locators */
 int    Lflag;                          /* lint config generation */
+int    handling_cmdlineopts;           /* currently processing -D/-U options */
 
 int    yyparse(void);
 
@@ -100,6 +101,7 @@
 static struct nvlist **nextappmkopt;
 static struct nvlist **nextcndmkopt;
 static struct nvlist **nextfsopt;
+static struct nvlist *cmdlinedefs, *cmdlineundefs;
 
 static void    usage(void) __dead;
 static void    dependopts(void);
@@ -119,6 +121,9 @@
 static int     devbase_has_dead_instances(const char *, void *, void *);
 static int     devbase_has_any_instance(struct devbase *, int, int, int);
 static int     check_dead_devi(const char *, void *, void *);
+static void    add_makeopt(const char *);
+static void    remove_makeopt(const char *);
+static void    handle_cmdline_makeoptions(void);
 static void    kill_orphans(void);
 static void    do_kill_orphans(struct devbase *, struct attr *,
     struct devbase *, int);
@@ -155,11 +160,11 @@
 
        pflag = 0;
        xflag = 0;
-       while ((ch = getopt(argc, argv, "DLPgpvb:s:x")) != -1) {
+       while ((ch = getopt(argc, argv, "D:LPU:dgpvb:s:x")) != -1) {
                switch (ch) {
 
 #ifndef MAKE_BOOTSTRAP
-               case 'D':
+               case 'd':
                        yydebug = 1;
                        break;
 #endif
@@ -179,7 +184,7 @@
                         * do that for you, but you really should just
                         * put them in the config file.
                         */
-                       warnx("-g is obsolete (use makeoptions DEBUG=\"-g\")");
+                       warnx("-g is obsolete (use -D DEBUG=\"-g\")");
                        usage();
                        /*NOTREACHED*/
 
@@ -213,6 +218,14 @@
                        xflag = 1;
                        break;
 
+               case 'D':
+                       add_makeopt(optarg);
+                       break;
+
+               case 'U':
+                       remove_makeopt(optarg);
+                       break;
+
                case '?':
                default:
                        usage();
@@ -386,6 +399,11 @@
                unlink(cname);
 
        /*
+        * Handle command line overrides
+        */
+       handle_cmdline_makeoptions();
+
+       /*
         * Detect and properly ignore orphaned devices
         */
        kill_orphans();
@@ -469,6 +487,7 @@
 usage(void)
 {
        (void)fprintf(stderr, "Usage: %s [-Ppv] [-s srcdir] [-b builddir] "
+           "[-D var=value] [-U var] "
            "[config-file]\n\t%s -x [kernel-file]\n"
            "\t%s -L [-v] [-s srcdir] [config-file]\n", 
            getprogname(), getprogname(), getprogname());
@@ -1071,6 +1090,11 @@
        struct nvlist *nv;
        
        if (ht_remove(ht, name)) {
+               /*
+                * -U command line option removals are always silent
+                */
+               if (handling_cmdlineopts)
+                       return 0;
                cfgerror("%s `%s' is not defined", type, name);
                return (1);
        }
@@ -1770,3 +1794,56 @@
 {
        ht_enumerate(devroottab, kill_orphans_cb, NULL);
 }
+
+static void
+add_makeopt(const char *opt)
+{
+       struct nvlist *p;
+       char *buf = estrdup(opt);
+       char *eq = strchr(buf, '=');
+
+       if (!eq)
+               errx(EXIT_FAILURE, "-D %s is not in var=value format", opt);
+
+       *eq = 0;
+       p = newnv(estrdup(buf), estrdup(eq+1), NULL, 0, NULL);
+       free(buf);
+       p->nv_next = cmdlinedefs;
+       cmdlinedefs = p;
+}
+
+static void
+remove_makeopt(const char *opt)
+{
+       struct nvlist *p;
+
+       p = newnv(estrdup(opt), NULL, NULL, 0, NULL);
+       p->nv_next = cmdlineundefs;
+       cmdlineundefs = p;
+}
+
+static void
+handle_cmdline_makeoptions(void)
+{
+       struct nvlist *p, *n;
+
+       handling_cmdlineopts = 1;
+       for (p = cmdlineundefs; p; p = n) {
+               n = p->nv_next;
+               delmkoption(intern(p->nv_name));
+               free(__UNCONST(p->nv_name));
+               nvfree(p);
+       }
+       for (p = cmdlinedefs; p; p = n) {
+               const char *name = intern(p->nv_name);
+
+               n = p->nv_next;
+               delmkoption(name);
+               addmkoption(name, intern(p->nv_str));
+               free(__UNCONST(p->nv_name));
+               free(__UNCONST(p->nv_str));
+
+               nvfree(p);
+       }
+       handling_cmdlineopts = 0;
+}



Home | Main Index | Thread Index | Old Index