The following patch expands config(8) slightly to be able to say
"make reconfig" from the build directory.

Yeah, it's sugar, but it got tiresome having to change directories
all the time.

I've put the reconfig target at end, where I'm sure it can't be the
first target.

An alternative approach would be to add an extra keyword for
"boilerplate" stuff that would always be emitted by config, but I
don't see the point of the extra knob in that particular case.

Index: config.h
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.sbin/config/config.h,v
retrieving revision 1.25
diff -u -p -r1.25 config.h
--- config.h    5 Dec 2012 23:20:26 -0000       1.25
+++ config.h    28 Oct 2013 07:44:56 -0000
@@ -339,6 +339,10 @@ void       defoption(const char *name);
 int    devbase_has_instances(struct devbase *, int);
 int    deva_has_instances(struct deva *, int);
 void   setupdirs(void);
+int    pflag;
+char   *sflag;
+char   *bflag;
+char   *startdir;
 
 /* mkheaders.c */
 int    mkheaders(void);
Index: main.c
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.sbin/config/main.c,v
retrieving revision 1.44
diff -u -p -r1.44 main.c
--- main.c      22 Jun 2012 22:02:29 -0000      1.44
+++ main.c      28 Oct 2013 07:47:13 -0000
@@ -93,15 +93,24 @@ usage(void)
        exit(1);
 }
 
+int pflag = 0;
+char *sflag = NULL;
+char *bflag = NULL;
+char *startdir;
+
 int
 main(int argc, char *argv[])
 {
        char *p;
        const char *last_component;
        char *outfile = NULL;
-       int pflag, ch, eflag, uflag, fflag;
+       int ch, eflag, uflag, fflag;
+       char dirbuffer[PATH_MAX];
 
        pflag = eflag = uflag = fflag = 0;
+       startdir = getcwd(dirbuffer, sizeof dirbuffer);
+       if (startdir == NULL)
+               warn("Can't getcwd, no make reconfig");
        while ((ch = getopt(argc, argv, "egpfb:s:o:u")) != -1) {
                switch (ch) {
 
@@ -148,10 +157,12 @@ main(int argc, char *argv[])
                        break;
 
                case 'b':
+                       bflag = optarg;
                        builddir = optarg;
                        break;
 
                case 's':
+                       sflag = optarg;
                        srcdir = optarg;
                        break;
 
Index: mkmakefile.c
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.sbin/config/mkmakefile.c,v
retrieving revision 1.37
diff -u -p -r1.37 mkmakefile.c
--- mkmakefile.c        17 Sep 2012 17:36:13 -0000      1.37
+++ mkmakefile.c        28 Oct 2013 07:47:03 -0000
@@ -60,6 +60,7 @@
 static const char *srcpath(struct files *);
 
 static int emitdefs(FILE *);
+static int emitreconfig(FILE *);
 static int emitfiles(FILE *, int);
 
 static int emitobjs(FILE *);
@@ -120,6 +121,10 @@ mkmakefile(void)
                if ((*fn)(ofp))
                        goto wrerror;
        }
+       if (startdir != NULL) {
+               if (emitreconfig(ofp) != 0)
+                       goto wrerror;
+       }
        if (ferror(ifp)) {
                (void)fprintf(stderr,
                    "config: error reading %s (at line %d): %s\n",
@@ -271,6 +276,33 @@ emitdefs(FILE *fp)
        for (nv = mkoptions; nv != NULL; nv = nv->nv_next)
                if (fprintf(fp, "%s=%s\n", nv->nv_name, nv->nv_str) < 0)
                        return (1);
+       return (0);
+}
+
+static int
+emitreconfig(FILE *fp)
+{
+       if (fputs("\n"
+           ".PHONY: reconfig\n"
+           "reconfig:\n", fp) < 0)
+               return (1);
+       if (fprintf(fp, "\tcd %s && config ", startdir) < 0)
+               return (1);
+       if (pflag) {
+               if (fputs("-p ", fp) < 0)
+                       return (1);
+       }
+       if (sflag) {
+               if (fprintf(fp, "-s %s ", sflag) < 0)
+                       return (1);
+       }
+       if (bflag) {
+               if (fprintf(fp, "-b %s ", bflag) < 0)
+                       return (1);
+       }
+       /* other options */
+       if (fprintf(fp, "%s\n", conffile) < 0)
+               return (1);
        return (0);
 }
 

Reply via email to