Add `source' and `build' directives, and corresponding options, per discussion

on tech-kern.  (See man page.)  Implementation by Greg Hudson.
Also, remove special case for i386 in vector handling, although this code isn't
actually used any more.
This commit is contained in:
mycroft 1996-08-31 20:58:16 +00:00
parent 42c80a3779
commit ab6ebadde6
10 changed files with 230 additions and 156 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: config.8,v 1.9 1996/03/17 06:29:19 cgd Exp $
.\" $NetBSD: config.8,v 1.10 1996/08/31 20:58:16 mycroft Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -41,33 +41,25 @@
.Nd build kernel compilation directories
.Sh SYNOPSIS
.Nm config
.Op Fl b Ar builddir
.Op Fl s Ar srcdir
.Op Fl p
.Ar system-name
.Op Ar config-file
.Sh DESCRIPTION
.Pp
This is the new version of the
.Nm Config
creates a kernel build directory from the file
.Ar config-file ,
which describes the system to configure.
.Pp
There are several different ways to run the
.Nm config
program.
.\"It understands the more modern autoconfiguration scheme
.\"used on the SPARC and i386 platforms.
.\"The old version of config is still used with the
.\"HP300, DECstation, and derivative platforms.
.\"Only the version of
.\".Nm config
.\"applicable to the architecture that you are running
.\"will be installed on your machine.
.Pp
.Nm Config
builds a set of configuration files from the file
.Ar system-name ,
which describes
the system to configure.
.Pp
.Nm Config
should run from the
program. The traditional way is to run
.Nm config
from the
.Pa conf
subdirectory of the top-level machine-specific directory
of the system source (usually
subdirectory of the machine-specific directory of the system source
(usually
.Pa /sys/arch/MACHINE/conf ,
where
.Pa MACHINE
@ -75,24 +67,53 @@ is one of
.Pa vax ,
.Pa tahoe ,
.Pa hp300 ,
and so forth).
and so forth), and to specify as the
.Ar config-file
the name of a file located in that directory.
.Nm config
will by default create files in the directory
.Pa ../compile/SYSTEMNAME ,
where
.Pa SYSTEMNAME
is the last path component of
.Ar config-file .
.Nm Config
assumes the directory
.Pa ../compile
exists; it places all output files in a subdirectory there,
creating the subdirectory if necessary.
The subdirectory name is taken from the
.Ar system-name ;
thus, configuring with
.Dq Li config PICKLE
will use the directory
.Pa ../compile/PICKLE .
will assume that the top-level kernel source directory is located four
directories above the build directory.
.Pp
Another way is to create the build directory yourself, place the
configuration file in the build directory with the name
.Pa CONFIG ,
and run
.Nm config
from within the build directory without specifying a
.Ar config-file .
.Nm Config
will then by default create files in the current directory. If you
run
.Nm config
this way, you must specify the location of the top-level kernel source
directory using the
.Fl s
option or by using the
.Dq Li source
directive at the beginning of the system configuration file.
.Pp
Finally, you can specify the build directory for
.Nm config
and run it from anywhere. You can specify a build directory with the
.Fl b
option or by using the
.Dq Li build
directive at the beginning of the system configuration file. You must
specify the location of the top-level kernel source directory if you
specify a build directory.
.Pp
If the
.Fl p
option is supplied,
.Pa .PROF
is appended to the compilation directory name, and
is appended to the default compilation directory name, and
.Nm config
acts as if the lines
.Dq Li makeoptions PROF="-pg"

View File

@ -1,4 +1,4 @@
/* $NetBSD: config.h,v 1.24 1996/08/12 00:55:54 mycroft Exp $ */
/* $NetBSD: config.h,v 1.25 1996/08/31 20:58:17 mycroft Exp $ */
/*
* Copyright (c) 1992, 1993
@ -232,9 +232,11 @@ struct files {
struct hashtab;
const char *conffile; /* source file, e.g., "GENERIC.sparc" */
const char *confdirbase; /* basename of compile directory, usu. same */
const char *machine; /* machine type, e.g., "sparc" or "sun3" */
const char *machinearch; /* machine arch, e.g., "sparc" or "m68k" */
const char *srcdir; /* path to source directory (rel. to build) */
const char *builddir; /* path to build directory */
const char *defbuilddir; /* default build directory */
int errors; /* counts calls to error() */
int minmaxusers; /* minimum "maxusers" parameter */
int defmaxusers; /* default "maxusers" parameter */
@ -315,7 +317,7 @@ void initsem __P((void));
/* util.c */
void *emalloc __P((size_t));
void *erealloc __P((void *, size_t));
char *path __P((const char *));
char *sourcepath __P((const char *));
void error __P((const char *, ...)); /* immediate errs */
void xerror __P((const char *, int, const char *, ...)); /* delayed errs */
__dead void panic __P((const char *, ...));

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: gram.y,v 1.7 1996/03/17 13:18:18 cgd Exp $ */
/* $NetBSD: gram.y,v 1.8 1996/08/31 20:58:19 mycroft Exp $ */
/*
* Copyright (c) 1992, 1993
@ -46,11 +46,14 @@
*/
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "config.h"
#include "sem.h"
@ -84,6 +87,7 @@ static int adepth;
#define fx_and(e1, e2) new0(NULL, NULL, e1, FX_AND, e2)
#define fx_or(e1, e2) new0(NULL, NULL, e1, FX_OR, e2)
static void setupdirs __P((void));
static void cleanup __P((void));
static void setmachine __P((const char *, const char *));
static void setmaxpartitions __P((int));
@ -99,9 +103,9 @@ static void setmaxpartitions __P((int));
int val;
}
%token AND AT ATTACH COMPILE_WITH CONFIG DEFINE DEVICE DUMPS ENDFILE
%token AND AT ATTACH BUILD COMPILE_WITH CONFIG DEFINE DEVICE DUMPS ENDFILE
%token XFILE FLAGS INCLUDE XMACHINE MAJOR MAKEOPTIONS MAXUSERS MAXPARTITIONS
%token MINOR ON OPTIONS PSEUDO_DEVICE ROOT SWAP VECTOR WITH
%token MINOR ON OPTIONS PSEUDO_DEVICE ROOT SOURCE SWAP VECTOR WITH
%token <val> FFLAG NUMBER
%token <str> PATHNAME WORD
@ -134,12 +138,24 @@ static void setmaxpartitions __P((int));
* separate grammars, with some shared terminals and nonterminals.
*/
Configuration:
hdrs machine_spec /* "machine foo" from machine descr. */
dirs hdrs machine_spec /* "machine foo" from machine descr. */
dev_defs dev_eof /* ../../conf/devices */
dev_defs dev_eof /* devices.foo */
maxpart_spec dev_defs dev_eof /* ../../conf/devices */
specs; /* rest of machine description */
dirs:
dirspecs = { setupdirs(); };
dirspecs:
dirspecs dir |
/* empty */;
dir:
SOURCE PATHNAME = { if (!srcdir) srcdir = $2; } |
BUILD PATHNAME = { if (!builddir) builddir = $2; } |
'\n';
hdrs:
hdrs hdr |
/* empty */;
@ -194,7 +210,7 @@ rule:
/* empty */ = { $$ = NULL; };
include:
INCLUDE WORD = { (void)include($2, '\n'); };
INCLUDE WORD = { include($2, '\n'); };
/*
* The machine definitions grammar.
@ -400,6 +416,48 @@ yyerror(s)
error("%s", s);
}
/*
* Verify/create builddir if necessary, change to it, and verify srcdir.
*/
static void
setupdirs()
{
struct stat st;
char *prof;
/* srcdir must be specified if builddir is not specified or if
* no configuration filename was specified. */
if ((builddir || strcmp(defbuilddir, ".") == 0) && !srcdir)
stop("source directory must be specified");
if (srcdir == NULL)
srcdir = "../../../..";
if (builddir == NULL)
builddir = defbuilddir;
if (stat(builddir, &st) != 0) {
if (mkdir(builddir, 0777)) {
(void)fprintf(stderr, "config: cannot create %s: %s\n",
builddir, strerror(errno));
exit(2);
}
} else if (!S_ISDIR(st.st_mode)) {
(void)fprintf(stderr, "config: %s is not a directory\n",
builddir);
exit(2);
}
if (chdir(builddir) != 0) {
(void)fprintf(stderr, "config: cannot change to %s\n",
builddir);
exit(2);
}
if (stat(srcdir, &st) != 0 || !S_ISDIR(st.st_mode)) {
(void)fprintf(stderr, "config: %s is not a directory\n",
srcdir);
exit(2);
}
}
/*
* Cleanup procedure after syntax error: release any nvlists
* allocated during parsing the current line.
@ -420,20 +478,24 @@ setmachine(mch, mcharch)
const char *mch;
const char *mcharch;
{
char buf[MAXPATHLEN], archbuf[MAXPATHLEN];
char buf[MAXPATHLEN];
machine = mch;
machinearch = mcharch;
(void)sprintf(buf, "arch/%s/conf/files.%s", machine, machine);
if (include(buf, ENDFILE) != 0)
exit(1);
if (machinearch != NULL)
(void)sprintf(archbuf, "../../%s/conf/files.%s",
(void)sprintf(buf, "arch/%s/conf/files.%s",
machinearch, machinearch);
else
strncpy(archbuf, _PATH_DEVNULL, MAXPATHLEN);
(void)sprintf(buf, "files.%s", machine);
strcpy(buf, _PATH_DEVNULL);
if (include(buf, ENDFILE) != 0)
exit(1);
if (include(buf, ENDFILE) ||
include(archbuf, ENDFILE) ||
include("../../../conf/files", ENDFILE))
if (include("conf/files", ENDFILE) != 0)
exit(1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.17 1996/03/17 11:50:13 cgd Exp $ */
/* $NetBSD: main.c,v 1.18 1996/08/31 20:58:20 mycroft Exp $ */
/*
* Copyright (c) 1992, 1993
@ -52,6 +52,7 @@ static char copyright[] =
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
@ -86,11 +87,11 @@ main(argc, argv)
char **argv;
{
register char *p;
const char *last_component;
int pflag, ch;
struct stat st;
pflag = 0;
while ((ch = getopt(argc, argv, "gp")) != EOF) {
while ((ch = getopt(argc, argv, "gpb:s:")) != EOF) {
switch (ch) {
case 'g':
@ -119,6 +120,14 @@ main(argc, argv)
pflag = 1;
break;
case 'b':
builddir = optarg;
break;
case 's':
srcdir = optarg;
break;
case '?':
default:
goto usage;
@ -127,12 +136,12 @@ main(argc, argv)
argc -= optind;
argv += optind;
if (argc != 1) {
if (argc > 1) {
usage:
(void)fputs("usage: config [-p] sysname\n", stderr);
(void)fputs("usage: config [-p] [-s srcdir] [-b builddir] sysname\n", stderr);
exit(1);
}
conffile = argv[0];
conffile = (argc == 1) ? argv[0] : "CONFIG";
if (firstfile(conffile)) {
(void)fprintf(stderr, "config: cannot read %s: %s\n",
conffile, strerror(errno));
@ -160,31 +169,18 @@ usage:
* Handle profiling (must do this before we try to create any
* files).
*/
last_component = strrchr(conffile, '/');
last_component = (last_component) ? last_component + 1 : conffile;
if (pflag) {
char *s;
s = emalloc(strlen(conffile) + sizeof(".PROF"));
(void)sprintf(s, "%s.PROF", conffile);
confdirbase = s;
p = emalloc(strlen(last_component) + 17);
(void)sprintf(p, "../compile/%s.PROF", last_component);
(void)addmkoption(intern("PROF"), "-pg");
(void)addoption(intern("GPROF"), NULL);
} else
confdirbase = conffile;
/*
* Verify, creating if necessary, the compilation directory.
*/
p = path(NULL);
if (stat(p, &st)) {
if (mkdir(p, 0777)) {
(void)fprintf(stderr, "config: cannot create %s: %s\n",
p, strerror(errno));
exit(2);
}
} else if (!S_ISDIR(st.st_mode)) {
(void)fprintf(stderr, "config: %s is not a directory\n", p);
exit(2);
} else {
p = emalloc(strlen(last_component) + 13);
(void)sprintf(p, "../compile/%s", last_component);
}
defbuilddir = (argc == 0) ? "." : p;
/*
* Parse config file (including machine definitions).
@ -241,29 +237,30 @@ static int
mksymlinks()
{
int ret;
char *p, buf[200];
char *p, buf[MAXPATHLEN];
const char *q;
p = path("machine");
(void)sprintf(buf, "../../include", machine);
(void)unlink(p);
ret = symlink(buf, p);
sprintf(buf, "arch/%s/include", machine);
p = sourcepath(buf);
(void)unlink("machine");
ret = symlink(p, "machine");
if (ret)
(void)fprintf(stderr, "config: symlink(%s -> %s): %s\n",
p, buf, strerror(errno));
free(p);
(void)fprintf(stderr, "config: symlink(machine -> %s): %s\n",
p, strerror(errno));
if (machinearch != NULL) {
p = path(machinearch);
(void)sprintf(buf, "../../../%s/include", machinearch);
sprintf(buf, "arch/%s/include", machinearch);
p = sourcepath(buf);
q = machinearch;
} else {
p = path(machine);
(void)sprintf(buf, "machine");
p = strdup("machine");
q = machine;
}
(void)unlink(p);
ret = symlink(buf, p);
(void)unlink(q);
ret = symlink(p, q);
if (ret)
(void)fprintf(stderr, "config: symlink(%s -> %s): %s\n",
p, buf, strerror(errno));
q, p, strerror(errno));
free(p);
return (ret);

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkheaders.c,v 1.10 1996/03/17 13:18:21 cgd Exp $ */
/* $NetBSD: mkheaders.c,v 1.11 1996/08/31 20:58:22 mycroft Exp $ */
/*
* Copyright (c) 1992, 1993
@ -80,13 +80,12 @@ emitcnt(head)
{
register struct nvlist *nv;
register FILE *fp;
register char *fname;
int cnt;
char nam[100];
char buf[BUFSIZ];
char fname[BUFSIZ];
(void)sprintf(buf, "%s.h", head->nv_name);
fname = path(buf);
(void)sprintf(fname, "%s.h", head->nv_name);
if ((fp = fopen(fname, "r")) == NULL)
goto writeit;
nv = head;

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkioconf.c,v 1.38 1996/03/17 06:29:27 cgd Exp $ */
/* $NetBSD: mkioconf.c,v 1.39 1996/08/31 20:58:23 mycroft Exp $ */
/*
* Copyright (c) 1992, 1993
@ -65,8 +65,6 @@ static int emitroots __P((FILE *));
static int emitvec __P((FILE *));
static char *vecname __P((char *, const char *, int));
static const char *s_i386;
#define SEP(pos, max) (((u_int)(pos) % (max)) == 0 ? "\n\t" : " ")
/*
@ -79,16 +77,12 @@ int
mkioconf()
{
register FILE *fp;
register char *fname;
int v;
s_i386 = intern("i386");
fname = path("ioconf.c");
qsort(packed, npacked, sizeof *packed, cforder);
if ((fp = fopen(fname, "w")) == NULL) {
(void)fprintf(stderr, "config: cannot write %s: %s\n",
fname, strerror(errno));
if ((fp = fopen("ioconf.c", "w")) == NULL) {
(void)fprintf(stderr, "config: cannot write ioconf.c: %s\n",
strerror(errno));
return (1);
}
v = emithdr(fp);
@ -96,15 +90,13 @@ mkioconf()
emitpv(fp) || emitcfdata(fp) || emitroots(fp) || emitpseudo(fp)) {
if (v >= 0)
(void)fprintf(stderr,
"config: error writing %s: %s\n",
fname, strerror(errno));
"config: error writing ioconf.c: %s\n",
strerror(errno));
(void)fclose(fp);
/* (void)unlink(fname); */
free(fname);
/* (void)unlink("ioconf.c"); */
return (1);
}
(void)fclose(fp);
free(fname);
return (0);
}
@ -398,11 +390,6 @@ vecname(buf, name, unit)
int unit;
{
/* @#%* 386 uses a different name format */
if (machine == s_i386) {
(void)sprintf(buf, "V%s%d", name, unit);
return (buf);
}
(void)sprintf(buf, "X%s%d", name, unit);
return (buf);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkmakefile.c,v 1.30 1996/08/12 00:55:55 mycroft Exp $ */
/* $NetBSD: mkmakefile.c,v 1.31 1996/08/31 20:58:25 mycroft Exp $ */
/*
* Copyright (c) 1992, 1993
@ -74,20 +74,21 @@ mkmakefile()
register FILE *ifp, *ofp;
register int lineno;
register int (*fn) __P((FILE *));
register char *ofname;
char line[BUFSIZ], ifname[200];
register char *ifname;
char line[BUFSIZ], buf[200];
(void)sprintf(ifname, "Makefile.%s", machine);
(void)sprintf(buf, "arch/%s/conf/Makefile.%s", machine, machine);
ifname = sourcepath(buf);
if ((ifp = fopen(ifname, "r")) == NULL) {
(void)fprintf(stderr, "config: cannot read %s: %s\n",
ifname, strerror(errno));
free(ifname);
return (1);
}
ofname = path("Makefile");
if ((ofp = fopen(ofname, "w")) == NULL) {
(void)fprintf(stderr, "config: cannot write %s: %s\n",
ofname, strerror(errno));
free(ofname);
if ((ofp = fopen("Makefile", "w")) == NULL) {
(void)fprintf(stderr, "config: cannot write Makefile: %s\n",
strerror(errno));
free(ifname);
return (1);
}
if (emitdefs(ofp) != 0)
@ -123,8 +124,8 @@ mkmakefile()
"config: error reading %s (at line %d): %s\n",
ifname, lineno, strerror(errno));
goto bad;
/* (void)unlink(ofname); */
free(ofname);
/* (void)unlink("Makefile"); */
free(ifname);
return (1);
}
if (fclose(ofp)) {
@ -132,16 +133,16 @@ mkmakefile()
goto wrerror;
}
(void)fclose(ifp);
free(ofname);
free(ifname);
return (0);
wrerror:
(void)fprintf(stderr, "config: error writing %s: %s\n",
ofname, strerror(errno));
(void)fprintf(stderr, "config: error writing Makefile: %s\n",
strerror(errno));
bad:
if (ofp != NULL)
(void)fclose(ofp);
/* (void)unlink(ofname); */
free(ofname);
/* (void)unlink("Makefile"); */
free(ifname);
return (1);
}
@ -194,6 +195,13 @@ emitdefs(fp)
return (1);
if (fprintf(fp, "PARAM=-DMAXUSERS=%d\n", maxusers) < 0)
return (1);
if (*srcdir == '/') {
if (fprintf(fp, "S=\t%s\n", srcdir) < 0)
return (1);
} else {
if (fprintf(fp, "S!=\tcd %s; pwd\n", srcdir) < 0)
return (1);
}
for (nv = mkoptions; nv != NULL; nv = nv->nv_next)
if (fprintf(fp, "%s=%s\n", nv->nv_name, nv->nv_str) < 0)
return (1);

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkswap.c,v 1.4 1996/03/17 20:36:25 christos Exp $ */
/* $NetBSD: mkswap.c,v 1.5 1996/08/31 20:58:27 mycroft Exp $ */
/*
* Copyright (c) 1992, 1993
@ -87,12 +87,10 @@ mkoneswap(cf)
{
register struct nvlist *nv;
register FILE *fp;
register char *fname;
char buf[200];
char fname[200];
char *mountroot;
(void)sprintf(buf, "swap%s.c", cf->cf_name);
fname = path(buf);
(void)sprintf(fname, "swap%s.c", cf->cf_name);
if ((fp = fopen(fname, "w")) == NULL) {
(void)fprintf(stderr, "config: cannot write %s: %s\n",
fname, strerror(errno));
@ -129,7 +127,6 @@ mkoneswap(cf)
fp = NULL;
goto wrerror;
}
free(fname);
return (0);
wrerror:
(void)fprintf(stderr, "config: error writing %s: %s\n",
@ -137,6 +134,5 @@ wrerror:
if (fp != NULL)
(void)fclose(fp);
/* (void)unlink(fname); */
free(fname);
return (1);
}

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: scan.l,v 1.5 1996/08/12 00:55:57 mycroft Exp $ */
/* $NetBSD: scan.l,v 1.6 1996/08/31 20:58:28 mycroft Exp $ */
/*
* Copyright (c) 1992, 1993
@ -87,6 +87,7 @@ WORD [A-Za-z_][-A-Za-z_0-9]*
and { return AND; }
at { return AT; }
attach { return ATTACH; }
build { return BUILD; }
compile-with { return COMPILE_WITH; }
config { return CONFIG; }
define { return DEFINE; }
@ -105,6 +106,7 @@ on { return ON; }
options { return OPTIONS; }
"pseudo-device" { return PSEUDO_DEVICE; }
root { return ROOT; }
source { return SOURCE; }
swap { return SWAP; }
vector { return VECTOR; }
with { return WITH; }
@ -186,10 +188,16 @@ include(fname, ateof)
{
register FILE *fp;
register struct incl *in;
char *s;
if ((fp = fopen(fname, "r")) == NULL) {
error("cannot open %s for reading: %s\n",
fname, strerror(errno));
/* Kludge until files.* files are fixed. */
if (strncmp(fname, "../../../", 9) == 0)
fname += 9;
s = (*fname == '/') ? strdup(fname) : sourcepath(fname);
if ((fp = fopen(s, "r")) == NULL) {
error("cannot open %s for reading: %s\n", s, strerror(errno));
free(s);
return (-1);
}
in = emalloc(sizeof *in);
@ -200,9 +208,10 @@ include(fname, ateof)
in->in_preveof = eoftoken;
incl = in;
yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
yyfile = intern(fname);
yyfile = intern(s);
yyline = 1;
eoftoken = ateof;
free(s);
return (0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.4 1996/03/17 11:50:16 cgd Exp $ */
/* $NetBSD: util.c,v 1.5 1996/08/31 20:58:29 mycroft Exp $ */
/*
* Copyright (c) 1992, 1993
@ -96,23 +96,16 @@ nomem()
}
/*
* Prepend the compilation directory to a file name.
* Prepend the source path to a file name.
*/
char *
path(file)
sourcepath(file)
const char *file;
{
register char *cp;
#define CDIR "../compile/"
if (file == NULL) {
cp = emalloc(sizeof(CDIR) + strlen(confdirbase));
(void)sprintf(cp, "%s%s", CDIR, confdirbase);
} else {
cp = emalloc(sizeof(CDIR) + strlen(confdirbase) + 1 +
strlen(file));
(void)sprintf(cp, "%s%s/%s", CDIR, confdirbase, file);
}
cp = emalloc(strlen(srcdir) + 1 + strlen(file) + 1);
(void)sprintf(cp, "%s/%s", srcdir, file);
return (cp);
}