From 03210956277ac967ac95acee043246b84a7a5694 Mon Sep 17 00:00:00 2001 From: espie Date: Tue, 29 Oct 2013 15:37:56 +0000 Subject: emit an extra "config" convenience target that allows one to rerun config without changing directories. Lots of inputs by deraadt@, who wanted it to work for movable relative directories. --- usr.sbin/config/config.h | 6 +++++- usr.sbin/config/main.c | 20 ++++++++++++++++++-- usr.sbin/config/mkmakefile.c | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 4 deletions(-) (limited to 'usr.sbin/config') diff --git a/usr.sbin/config/config.h b/usr.sbin/config/config.h index 9c3ac277322..49d2b373141 100644 --- a/usr.sbin/config/config.h +++ b/usr.sbin/config/config.h @@ -1,4 +1,4 @@ -/* $OpenBSD: config.h,v 1.25 2012/12/05 23:20:26 deraadt Exp $ */ +/* $OpenBSD: config.h,v 1.26 2013/10/29 15:37:56 espie Exp $ */ /* $NetBSD: config.h,v 1.30 1997/02/02 21:12:30 thorpej Exp $ */ /* @@ -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); diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c index 531c2438915..e1926c7b984 100644 --- a/usr.sbin/config/main.c +++ b/usr.sbin/config/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.44 2012/06/22 22:02:29 guenther Exp $ */ +/* $OpenBSD: main.c,v 1.45 2013/10/29 15:37:56 espie Exp $ */ /* $NetBSD: main.c,v 1.22 1997/02/02 21:12:33 thorpej Exp $ */ /* @@ -93,13 +93,19 @@ 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; while ((ch = getopt(argc, argv, "egpfb:s:o:u")) != -1) { @@ -148,10 +154,12 @@ main(int argc, char *argv[]) break; case 'b': + bflag = optarg; builddir = optarg; break; case 's': + sflag = optarg; srcdir = optarg; break; @@ -163,7 +171,15 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; if (argc > 1 || (eflag && argv[0] == NULL)) + usage(); + if (bflag) { + startdir = getcwd(dirbuffer, sizeof dirbuffer); + if (startdir == NULL) + warn("Use of -b and can't getcwd, no make config"); + } else { + startdir = "../../conf"; + } if (eflag) { #ifdef MAKE_BOOTSTRAP diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c index 1e1d90d8489..9af4dfbba0e 100644 --- a/usr.sbin/config/mkmakefile.c +++ b/usr.sbin/config/mkmakefile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkmakefile.c,v 1.37 2012/09/17 17:36:13 espie Exp $ */ +/* $OpenBSD: mkmakefile.c,v 1.38 2013/10/29 15:37:56 espie Exp $ */ /* $NetBSD: mkmakefile.c,v 1.34 1997/02/02 21:12:36 thorpej Exp $ */ /* @@ -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", @@ -274,6 +279,33 @@ emitdefs(FILE *fp) return (0); } +static int +emitreconfig(FILE *fp) +{ + if (fputs("\n" + ".PHONY: config\n" + "config:\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); +} + static int emitobjs(FILE *fp) { -- cgit v1.2.3-59-g8ed1b