Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/config Add a mechanism to specify prefixes that are...



details:   https://anonhg.NetBSD.org/src/rev/7b78f1fe8ead
branches:  trunk
changeset: 474512:7b78f1fe8ead
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Jul 09 06:44:58 1999 +0000

description:
Add a mechanism to specify prefixes that are transparently prepended
to file specifications.  The prefixes are arranged in a stack, and
nest, so that file, object, and include specifications are normalized,
and all end up relative to the kernel compile directory.

For example, in the kernel config file:

# Pull in config fragments for kernel crypto
prefix ../crypto-us/sys                         # push it
cinclude "conf/files.crypto-us"                 # include it if it's there
prefix                                          # pop it

and in files.crypto-us:

file netinet6/esp_core.c                ipsec & ipsec_esp
file netinet6/esp_output.c              ipsec & ipsec_esp
file netinet6/esp_input.c               ipsec & ipsec_esp

...generates the following in the kernel Makefile:

        $S/../crypto-us/sys/netinet6/esp_core.c \
        $S/../crypto-us/sys/netinet6/esp_output.c \
        $S/../crypto-us/sys/netinet6/esp_input.c \

By placing this all in the kernel config file, all the magic involved in
reaching into non-standard kernel source directories is placed into a file
that the user is expected to edit anyway, and reasonable examples (and
sane defaults, for typical source checkouts) can be provided.

diffstat:

 usr.sbin/config/config.h     |  20 +++++++++++-
 usr.sbin/config/files.c      |   4 +-
 usr.sbin/config/gram.y       |  10 ++++-
 usr.sbin/config/main.c       |   4 +-
 usr.sbin/config/mkheaders.c  |   6 +-
 usr.sbin/config/mkmakefile.c |  46 ++++++++++++++++++++++------
 usr.sbin/config/scan.l       |   5 +-
 usr.sbin/config/util.c       |  72 ++++++++++++++++++++++++++++++++++++++++++-
 8 files changed, 141 insertions(+), 26 deletions(-)

diffs (truncated from 379 to 300 lines):

diff -r 69dc93af2625 -r 7b78f1fe8ead usr.sbin/config/config.h
--- a/usr.sbin/config/config.h  Fri Jul 09 03:05:49 1999 +0000
+++ b/usr.sbin/config/config.h  Fri Jul 09 06:44:58 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: config.h,v 1.43 1999/07/07 00:02:09 thorpej Exp $      */
+/*     $NetBSD: config.h,v 1.44 1999/07/09 06:44:58 thorpej Exp $      */
 
 /*
  * Copyright (c) 1992, 1993
@@ -255,6 +255,7 @@
        const char *fi_path;    /* full file path */
        const char *fi_tail;    /* name, i.e., strrchr(fi_path, '/') + 1 */
        const char *fi_base;    /* tail minus ".c" (or whatever) */
+       const char *fi_prefix;  /* any file prefix */
        struct  nvlist *fi_optx;/* options expression */
        struct  nvlist *fi_optf;/* flattened version of above, if needed */
        const char *fi_mkrule;  /* special make rule, if any */
@@ -276,6 +277,7 @@
        u_char  oi_flags;       /* as below */
        char    oi_lastc;       /* last char from path */
        const char *oi_path;    /* full object path */
+       const char *oi_prefix;  /* any file prefix */
        struct  nvlist *oi_optx;/* options expression */
        struct  nvlist *oi_optf;/* flattened version of above, if needed */
 };
@@ -289,6 +291,15 @@
 #define        FX_OR           3       /* OR expr (lhs in nv_ptr, rhs in nv_next) */
 
 /*
+ * File/object prefixes.  These are arranged in a stack, and affect
+ * the behavior of the source path.
+ */
+struct prefix {
+       struct prefix *pf_next; /* next prefix in stack */
+       const char *pf_prefix;  /* the actual prefix */
+};
+
+/*
  * Hash tables look up name=value pairs.  The pointer value of the name
  * is assumed to be constant forever; this can be arranged by interning
  * the name.  (This is fairly convenient since our lexer does this for
@@ -334,7 +345,9 @@
 int    npseudo;                /* number of pseudo's */
 
 struct files *allfiles;        /* list of all kernel source files */
-struct objects *allobjects;    /* list of all kernel object and library files */
+struct objects *allobjects;    /* list of all kernel object and library
+                                  files */
+struct prefix *prefixes;       /* prefix stack */
 
 struct devi **packed;          /* arrayified table for packed devi's */
 int    npacked;                /* size of packed table, <= ndevi */
@@ -417,6 +430,9 @@
 /* util.c */
 void   *emalloc __P((size_t));
 void   *erealloc __P((void *, size_t));
+char   *estrdup __P((const char *));
+void   prefix_push __P((const char *));
+void   prefix_pop __P((void));
 char   *sourcepath __P((const char *));
 void   warn __P((const char *, ...));                  /* immediate warns */
 void   error __P((const char *, ...));                 /* immediate errs */
diff -r 69dc93af2625 -r 7b78f1fe8ead usr.sbin/config/files.c
--- a/usr.sbin/config/files.c   Fri Jul 09 03:05:49 1999 +0000
+++ b/usr.sbin/config/files.c   Fri Jul 09 06:44:58 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: files.c,v 1.9 1997/10/18 07:59:06 lukem Exp $  */
+/*     $NetBSD: files.c,v 1.10 1999/07/09 06:44:58 thorpej Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -146,6 +146,7 @@
        fi->fi_path = path;
        fi->fi_tail = tail;
        fi->fi_base = intern(base);
+       fi->fi_prefix = (prefixes != NULL) ? prefixes->pf_prefix : NULL;
        fi->fi_optx = optx;
        fi->fi_optf = NULL;
        fi->fi_mkrule = rule;
@@ -182,6 +183,7 @@
        oi->oi_srcline = currentline();
        oi->oi_flags = flags;
        oi->oi_path = path;
+       oi->oi_prefix = (prefixes != NULL) ? prefixes->pf_prefix : NULL;
        oi->oi_optx = optx;
        oi->oi_optf = NULL;
        *nextobject = oi;
diff -r 69dc93af2625 -r 7b78f1fe8ead usr.sbin/config/gram.y
--- a/usr.sbin/config/gram.y    Fri Jul 09 03:05:49 1999 +0000
+++ b/usr.sbin/config/gram.y    Fri Jul 09 06:44:58 1999 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: gram.y,v 1.26 1999/07/07 00:02:09 thorpej Exp $        */
+/*     $NetBSD: gram.y,v 1.27 1999/07/09 06:44:58 thorpej Exp $        */
 
 /*
  * Copyright (c) 1992, 1993
@@ -104,8 +104,8 @@
 %token AND AT ATTACH BUILD CINCLUDE COMPILE_WITH CONFIG DEFFS DEFINE DEFOPT 
 %token DEFPARAM DEFFLAG DEFPSEUDO DEVICE DEVCLASS DUMPS ENDFILE XFILE XOBJECT
 %token FILE_SYSTEM FLAGS INCLUDE XMACHINE MAJOR MAKEOPTIONS
-%token MAXUSERS MAXPARTITIONS MINOR ON OPTIONS PSEUDO_DEVICE ROOT SOURCE
-%token TYPE WITH NEEDS_COUNT NEEDS_FLAG
+%token MAXUSERS MAXPARTITIONS MINOR ON OPTIONS PREFIX PSEUDO_DEVICE ROOT
+%token SOURCE TYPE WITH NEEDS_COUNT NEEDS_FLAG
 %token <val> NUMBER
 %token <str> PATHNAME WORD EMPTY
 
@@ -225,6 +225,9 @@
        INCLUDE WORD                    { (void) include($2, 0, 0); } |
        CINCLUDE WORD                   { (void) include($2, 0, 1); };
 
+prefix:
+       PREFIX PATHNAME                 { prefix_push($2); } |
+       PREFIX                          { prefix_pop(); };
 
 /*
  * The machine definitions grammar.
@@ -242,6 +245,7 @@
        file |
        object |
        include |
+       prefix |
        DEVCLASS WORD                   { (void)defattr($2, NULL, 1); } |
        DEFFS fsoptfile_opt deffses     { deffilesystem($2, $3); } |
        DEFINE WORD interface_opt       { (void)defattr($2, $3, 0); } |
diff -r 69dc93af2625 -r 7b78f1fe8ead usr.sbin/config/main.c
--- a/usr.sbin/config/main.c    Fri Jul 09 03:05:49 1999 +0000
+++ b/usr.sbin/config/main.c    Fri Jul 09 06:44:58 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.39 1999/04/02 06:36:30 gwr Exp $    */
+/*     $NetBSD: main.c,v 1.40 1999/07/09 06:44:58 thorpej Exp $        */
 
 /*
  * Copyright (c) 1992, 1993
@@ -339,7 +339,7 @@
                p = sourcepath(buf);
                q = machinearch;
        } else {
-               p = strdup("machine");
+               p = estrdup("machine");
                q = machine;
        }
        (void)unlink(q);
diff -r 69dc93af2625 -r 7b78f1fe8ead usr.sbin/config/mkheaders.c
--- a/usr.sbin/config/mkheaders.c       Fri Jul 09 03:05:49 1999 +0000
+++ b/usr.sbin/config/mkheaders.c       Fri Jul 09 06:44:58 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkheaders.c,v 1.22 1999/01/21 13:10:09 pk Exp $        */
+/*     $NetBSD: mkheaders.c,v 1.23 1999/07/09 06:44:59 thorpej Exp $   */
 
 /*
  * Copyright (c) 1992, 1993
@@ -213,7 +213,7 @@
                         * usable defines, so ignore it.
                         */
                        return 0;
-               locdup = strdup(name);
+               locdup = estrdup(name);
                for (cp = locdup; *cp; cp++)
                        if (islower(*cp))
                                *cp = toupper(*cp);
@@ -228,7 +228,7 @@
                                 * usable defines, so ignore it.
                                 */
                                continue;
-                       namedup = strdup(nv->nv_name);
+                       namedup = estrdup(nv->nv_name);
                        for (cp = namedup; *cp; cp++)
                                if (islower(*cp))
                                        *cp = toupper(*cp);
diff -r 69dc93af2625 -r 7b78f1fe8ead usr.sbin/config/mkmakefile.c
--- a/usr.sbin/config/mkmakefile.c      Fri Jul 09 03:05:49 1999 +0000
+++ b/usr.sbin/config/mkmakefile.c      Fri Jul 09 06:44:58 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkmakefile.c,v 1.39 1999/05/23 19:30:30 mycroft Exp $  */
+/*     $NetBSD: mkmakefile.c,v 1.40 1999/07/09 06:44:59 thorpej Exp $  */
 
 /*
  * Copyright (c) 1992, 1993
@@ -247,17 +247,30 @@
                if ((oi->oi_flags & OI_SEL) == 0)
                        continue;
                len = strlen(oi->oi_path);
-               if (*oi->oi_path != '/')
-                       len += 3;
+               if (*oi->oi_path != '/') {
+                       len += 3;       /* "$S/" */
+                       if (oi->oi_prefix != NULL)
+                               len += strlen(oi->oi_prefix) + 1;
+               }
                if (lpos + len > 72) {
                        if (fputs(" \\\n", fp) < 0)
                                return (1);
                        sp = '\t';
                        lpos = 7;
                }
-               if (fprintf(fp, "%c%s%s", sp, *oi->oi_path != '/' ? "$S/" : "",
-                   oi->oi_path) < 0)
-                       return (1);
+               if (*oi->oi_path == '/') {
+                       if (fprintf(fp, "%c%s", sp, oi->oi_path) < 0)
+                               return (1);
+               } else {
+                       if (oi->oi_prefix != NULL) {
+                               if (fprintf(fp, "%c$S/%s/%s", sp, oi->oi_prefix,
+                                   oi->oi_path) < 0)
+                                       return (1);
+                       } else {
+                               if (fprintf(fp, "%c$S/%s", sp, oi->oi_path) < 0)
+                                       return (1);
+                       }
+               }
                lpos += len + 1;
                sp = ' ';
        }
@@ -305,17 +318,30 @@
                len = strlen(fpath);
                if (fpath[len - 1] != suffix)
                        continue;
-               if (*fpath != '/')
+               if (*fpath != '/') {
                        len += 3;       /* "$S/" */
+                       if (fi->fi_prefix != NULL)
+                               len += strlen(fi->fi_prefix) + 1;
+               }
                if (lpos + len > 72) {
                        if (fputs(" \\\n", fp) < 0)
                                return (1);
                        sp = '\t';
                        lpos = 7;
                }
-               if (fprintf(fp, "%c%s%s", sp, *fpath != '/' ? "$S/" : "",
-                   fpath) < 0)
-                       return (1);
+               if (*fi->fi_path == '/') {
+                       if (fprintf(fp, "%c%s", sp, fi->fi_path) < 0)
+                               return (1);
+               } else {
+                       if (fi->fi_prefix != NULL) {
+                               if (fprintf(fp, "%c$S/%s/%s", sp, fi->fi_prefix,
+                                   fi->fi_path) < 0)
+                                       return (1);
+                       } else {
+                               if (fprintf(fp, "%c$S/%s", sp, fi->fi_path) < 0)
+                                       return (1);
+                       }
+               }
                lpos += len + 1;
                sp = ' ';
        }
diff -r 69dc93af2625 -r 7b78f1fe8ead usr.sbin/config/scan.l
--- a/usr.sbin/config/scan.l    Fri Jul 09 03:05:49 1999 +0000
+++ b/usr.sbin/config/scan.l    Fri Jul 09 06:44:58 1999 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: scan.l,v 1.24 1999/07/09 02:37:26 thorpej Exp $        */
+/*     $NetBSD: scan.l,v 1.25 1999/07/09 06:44:59 thorpej Exp $        */
 
 /*
  * Copyright (c) 1992, 1993
@@ -113,6 +113,7 @@
 object         return XOBJECT;
 on             return ON;
 options                return OPTIONS;
+prefix         return PREFIX;
 pseudo-device  return PSEUDO_DEVICE;
 root           return ROOT;
 source         return SOURCE;
@@ -217,7 +218,7 @@
                setupdirs();
        }
 
-       s = (*fname == '/') ? strdup(fname) : sourcepath(fname);
+       s = (*fname == '/') ? estrdup(fname) : sourcepath(fname);
        if ((fp = fopen(s, "r")) == NULL) {
                if (conditional == 0)
                        error("cannot open %s for reading: %s\n", s,
diff -r 69dc93af2625 -r 7b78f1fe8ead usr.sbin/config/util.c
--- a/usr.sbin/config/util.c    Fri Jul 09 03:05:49 1999 +0000
+++ b/usr.sbin/config/util.c    Fri Jul 09 06:44:58 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.7 1998/06/24 11:20:55 jonathan Exp $        */
+/*     $NetBSD: util.c,v 1.8 1999/07/09 06:44:59 thorpej Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -90,6 +90,20 @@
        return (p);
 }
 
+/*
+ * Strdup, with abort on error.
+ */
+char *
+estrdup(p)
+       const char *p;
+{
+       char *cp;
+



Home | Main Index | Thread Index | Old Index