In `-S' mode, generate *.c files under conf/ subdirectory. Register generated

.c files to the `files' list internally.
This commit is contained in:
uebayasi 2015-09-02 05:09:25 +00:00
parent d9bb176d5f
commit dccd2cf552
7 changed files with 65 additions and 30 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: defs.h,v 1.83 2015/09/01 16:01:23 uebayasi Exp $ */
/* $NetBSD: defs.h,v 1.84 2015/09/02 05:09:25 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@ -433,6 +433,8 @@ struct nvlist *machinesubarches;
const char *ioconfname; /* ioconf name, mutually exclusive to machine */
const char *srcdir; /* path to source directory (rel. to build) */
const char *builddir; /* path to build directory */
int builddirfd; /* dir fd of builddir */
int buildconfdirfd; /* dir fd of builddir/conf */
const char *defbuilddir; /* default build directory */
const char *ident; /* kernel "ident"ification string */
int errors; /* counts calls to error() */

View File

@ -1,4 +1,4 @@
/* $NetBSD: files.c,v 1.26 2015/09/01 16:01:23 uebayasi Exp $ */
/* $NetBSD: files.c,v 1.27 2015/09/02 05:09:25 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@ -45,7 +45,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: files.c,v 1.26 2015/09/01 16:01:23 uebayasi Exp $");
__RCSID("$NetBSD: files.c,v 1.27 2015/09/02 05:09:25 uebayasi Exp $");
#include <sys/param.h>
#include <errno.h>
@ -278,13 +278,15 @@ fixfiles(void)
struct config *cf;
char swapname[100];
addfile("devsw.c", NULL, 0, NULL);
addfile("ioconf.c", NULL, 0, NULL);
buildprefix_push("conf");
addfile("conf/devsw.c", NULL, 0, NULL);
addfile("conf/ioconf.c", NULL, 0, NULL);
TAILQ_FOREACH(cf, &allcf, cf_next) {
(void)snprintf(swapname, sizeof(swapname), "swap%s.c",
(void)snprintf(swapname, sizeof(swapname), "conf/swap%s.c",
cf->cf_name);
addfile(intern(swapname), NULL, 0, NULL);
}
buildprefix_pop();
}
err = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.84 2015/09/01 16:01:23 uebayasi Exp $ */
/* $NetBSD: main.c,v 1.85 2015/09/02 05:09:25 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@ -45,7 +45,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: main.c,v 1.84 2015/09/01 16:01:23 uebayasi Exp $");
__RCSID("$NetBSD: main.c,v 1.85 2015/09/02 05:09:25 uebayasi Exp $");
#ifndef MAKE_BOOTSTRAP
#include <sys/cdefs.h>
@ -100,6 +100,8 @@ extern int yydebug;
#endif
int dflag;
static const char *buildconfdir = ".";
static struct dlhash *obsopttab;
static struct hashtab *mkopttab;
static struct nvlist **nextopt;
@ -522,11 +524,15 @@ main(int argc, char **argv)
/*
* Ready to go. Build all the various files.
*/
if (mksubdirs() || mksymlinks() || mkmakefile() || mkheaders() || mkswap() ||
if ((Sflag && mksubdirs()) || mksymlinks() || mkmakefile() || mkheaders() || mkswap() ||
mkioconf() || (do_devsw ? mkdevsw() : 0) || mkident() || errors)
stop();
(void)printf("Build directory is %s\n", builddir);
(void)printf("Don't forget to run \"make depend\"\n");
close(buildconfdirfd);
close(builddirfd);
return 0;
}
@ -650,9 +656,6 @@ mksubdirs(void)
const char *prefix, *sep;
char buf[MAXPATHLEN];
if (!Sflag)
return 0;
TAILQ_FOREACH(fi, &allfiles, fi_next) {
if ((fi->fi_flags & FI_SEL) == 0)
continue;
@ -672,6 +675,8 @@ mksubdirs(void)
mksubdir(buf);
}
buildconfdir = "conf";
return 0;
}
@ -689,6 +694,9 @@ mksymlinks(void)
p = buf;
if ((buildconfdirfd = open(buildconfdir, O_RDONLY)) == -1)
errx(EXIT_FAILURE, "cannot opens %s", buildconfdir);
snprintf(buf, sizeof(buf), "%s/arch/%s/include", srcdir, machine);
ret = recreate(p, "machine");
ret = recreate(p, machine);
@ -1464,6 +1472,8 @@ setupdirs(void)
errx(EXIT_FAILURE, "cannot create %s", builddir);
} else if (!S_ISDIR(st.st_mode))
errx(EXIT_FAILURE, "%s is not a directory", builddir);
if ((builddirfd = open(builddir, O_RDONLY)) == -1)
errx(EXIT_FAILURE, "cannot opens %s", builddir);
if (chdir(builddir) == -1)
err(EXIT_FAILURE, "cannot change to %s", builddir);
if (stat(srcdir, &st) == -1)

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkdevsw.c,v 1.12 2014/11/10 21:13:04 christos Exp $ */
/* $NetBSD: mkdevsw.c,v 1.13 2015/09/02 05:09:25 uebayasi Exp $ */
/*
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -34,7 +34,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: mkdevsw.c,v 1.12 2014/11/10 21:13:04 christos Exp $");
__RCSID("$NetBSD: mkdevsw.c,v 1.13 2015/09/02 05:09:25 uebayasi Exp $");
#include <stdio.h>
#include <string.h>
@ -53,9 +53,10 @@ mkdevsw(void)
{
FILE *fp;
fchdir(buildconfdirfd);
if ((fp = fopen("devsw.c.tmp", "w")) == NULL) {
warn("cannot create devsw.c");
return (1);
goto err;
}
emitheader(fp);
@ -67,17 +68,21 @@ mkdevsw(void)
if (ferror(fp)) {
warn("error writing devsw.c");
fclose(fp);
return 1;
goto err;
}
(void)fclose(fp);
if (moveifchanged("devsw.c.tmp", "devsw.c") != 0) {
warn("error renaming devsw.c");
return (1);
goto err;
}
fchdir(builddirfd);
return (0);
err:
fchdir(builddirfd);
return (1);
}
static void

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkheaders.c,v 1.27 2015/08/20 09:44:24 christos Exp $ */
/* $NetBSD: mkheaders.c,v 1.28 2015/09/02 05:09:25 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@ -45,7 +45,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: mkheaders.c,v 1.27 2015/08/20 09:44:24 christos Exp $");
__RCSID("$NetBSD: mkheaders.c,v 1.28 2015/09/02 05:09:25 uebayasi Exp $");
#include <sys/param.h>
#include <ctype.h>
@ -392,6 +392,7 @@ emitioconfh(void)
struct devi *i;
tfname = "tmp_ioconf.h";
fchdir(buildconfdirfd);
if ((tfp = fopen(tfname, "w")) == NULL)
return (herr("open", tfname, NULL));
@ -415,7 +416,11 @@ emitioconfh(void)
if (fclose(tfp) == EOF)
return (herr("clos", tfname, NULL));
return (moveifchanged(tfname, "ioconf.h"));
if (moveifchanged(tfname, "ioconf.h") != 0)
return (herr("mvif", tfname, NULL));
fchdir(builddirfd);
return 0;
}
/*
@ -528,6 +533,7 @@ herr(const char *what, const char *fname, FILE *fp)
warn("error %sing %s", what, fname);
if (fp)
(void)fclose(fp);
fchdir(builddirfd);
return (1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkioconf.c,v 1.30 2015/08/28 03:55:15 uebayasi Exp $ */
/* $NetBSD: mkioconf.c,v 1.31 2015/09/02 05:09:25 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@ -45,7 +45,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: mkioconf.c,v 1.30 2015/08/28 03:55:15 uebayasi Exp $");
__RCSID("$NetBSD: mkioconf.c,v 1.31 2015/09/02 05:09:25 uebayasi Exp $");
#include <sys/param.h>
#include <err.h>
@ -87,9 +87,10 @@ mkioconf(void)
FILE *fp;
qsort(packed, npacked, sizeof *packed, cforder);
fchdir(buildconfdirfd);
if ((fp = fopen("ioconf.c.tmp", "w")) == NULL) {
warn("cannot write ioconf.c");
return (1);
goto err;
}
fprintf(fp, "#include \"ioconf.h\"\n");
@ -116,15 +117,20 @@ mkioconf(void)
#if 0
(void)unlink("ioconf.c.tmp");
#endif
return (1);
goto err;
}
(void)fclose(fp);
if (moveifchanged("ioconf.c.tmp", "ioconf.c") != 0) {
warn("error renaming ioconf.c");
return (1);
goto err;
}
fchdir(builddirfd);
return (0);
err:
fchdir(builddirfd);
return (1);
}
static int

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkswap.c,v 1.8 2014/10/29 17:14:50 christos Exp $ */
/* $NetBSD: mkswap.c,v 1.9 2015/09/02 05:09:25 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@ -45,7 +45,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: mkswap.c,v 1.8 2014/10/29 17:14:50 christos Exp $");
__RCSID("$NetBSD: mkswap.c,v 1.9 2015/09/02 05:09:25 uebayasi Exp $");
#include <sys/param.h>
#include <errno.h>
@ -97,9 +97,10 @@ mkoneswap(struct config *cf)
(void)snprintf(fname, sizeof(fname), "swap%s.c", cf->cf_name);
(void)snprintf(tname, sizeof(tname), "swap%s.c.tmp", cf->cf_name);
fchdir(buildconfdirfd);
if ((fp = fopen(tname, "w")) == NULL) {
warn("cannot open %s", fname);
return (1);
goto err;
}
autogen_comment(fp, fname);
@ -149,8 +150,9 @@ mkoneswap(struct config *cf)
}
if (moveifchanged(tname, fname) != 0) {
warn("error renaming %s", fname);
return (1);
goto err;
}
fchdir(builddirfd);
return (0);
wrerror:
@ -160,5 +162,7 @@ mkoneswap(struct config *cf)
#if 0
(void)unlink(fname);
#endif
err:
fchdir(builddirfd);
return (1);
}