2015-09-05 00:32:54 +03:00
|
|
|
/* $NetBSD: files.c,v 1.35 2015/09/04 21:32:54 uebayasi Exp $ */
|
1996-03-03 20:21:25 +03:00
|
|
|
|
1996-03-17 09:29:19 +03:00
|
|
|
/*
|
1995-04-28 10:54:58 +04:00
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the Computer Systems Engineering group
|
|
|
|
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
|
|
|
* contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Lawrence Berkeley Laboratories.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 15:25:11 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1995-04-28 10:54:58 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* from: @(#)files.c 8.1 (Berkeley) 6/6/93
|
|
|
|
*/
|
|
|
|
|
2004-06-21 02:20:14 +04:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "nbtool_config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-10-29 20:14:50 +03:00
|
|
|
#include <sys/cdefs.h>
|
2015-09-05 00:32:54 +03:00
|
|
|
__RCSID("$NetBSD: files.c,v 1.35 2015/09/04 21:32:54 uebayasi Exp $");
|
2014-10-29 20:14:50 +03:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
#include <sys/param.h>
|
2015-09-04 18:50:48 +03:00
|
|
|
#include <assert.h>
|
1995-04-28 10:54:58 +04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2006-08-26 22:17:13 +04:00
|
|
|
#include <util.h>
|
2002-01-29 13:20:28 +03:00
|
|
|
#include "defs.h"
|
1995-04-28 10:54:58 +04:00
|
|
|
|
|
|
|
extern const char *yyfile;
|
|
|
|
|
2015-09-04 13:16:35 +03:00
|
|
|
int nallfiles;
|
|
|
|
size_t nselfiles;
|
|
|
|
struct files **selfiles;
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
/*
|
|
|
|
* We check that each full path name is unique. File base names
|
|
|
|
* should generally also be unique, e.g., having both a net/xx.c and
|
|
|
|
* a kern/xx.c (or, worse, a net/xx.c and a new/xx.c++) is probably
|
|
|
|
* wrong, but is permitted under some conditions.
|
|
|
|
*/
|
|
|
|
static struct hashtab *basetab; /* file base names */
|
|
|
|
static struct hashtab *pathtab; /* full path names */
|
|
|
|
|
|
|
|
static struct files **unchecked;
|
|
|
|
|
2014-10-09 14:29:36 +04:00
|
|
|
static void addfiletoattr(const char *, struct files *);
|
2000-10-02 23:48:34 +04:00
|
|
|
static int checkaux(const char *, void *);
|
|
|
|
static int fixcount(const char *, void *);
|
|
|
|
static int fixfsel(const char *, void *);
|
|
|
|
static int fixsel(const char *, void *);
|
1996-03-17 16:18:15 +03:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
void
|
2000-10-02 23:48:34 +04:00
|
|
|
initfiles(void)
|
1995-04-28 10:54:58 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
basetab = ht_new();
|
|
|
|
pathtab = ht_new();
|
2002-06-05 14:56:17 +04:00
|
|
|
TAILQ_INIT(&allfiles);
|
2015-09-01 14:22:59 +03:00
|
|
|
TAILQ_INIT(&allcfiles);
|
|
|
|
TAILQ_INIT(&allsfiles);
|
|
|
|
TAILQ_INIT(&allofiles);
|
2002-06-05 14:56:17 +04:00
|
|
|
unchecked = &TAILQ_FIRST(&allfiles);
|
1995-04-28 10:54:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-08-29 05:54:07 +03:00
|
|
|
addfile(const char *path, struct condexpr *optx, u_char flags, const char *rule)
|
1995-04-28 10:54:58 +04:00
|
|
|
{
|
2000-06-09 09:06:12 +04:00
|
|
|
struct files *fi;
|
1996-03-17 16:18:15 +03:00
|
|
|
const char *dotp, *tail;
|
1995-04-28 10:54:58 +04:00
|
|
|
size_t baselen;
|
2015-09-01 15:46:20 +03:00
|
|
|
size_t dirlen;
|
1995-04-28 10:54:58 +04:00
|
|
|
int needc, needf;
|
1996-03-17 16:18:15 +03:00
|
|
|
char base[200];
|
2015-09-01 15:46:20 +03:00
|
|
|
char dir[MAXPATHLEN];
|
1995-04-28 10:54:58 +04:00
|
|
|
|
|
|
|
/* check various errors */
|
|
|
|
needc = flags & FI_NEEDSCOUNT;
|
|
|
|
needf = flags & FI_NEEDSFLAG;
|
|
|
|
if (needc && needf) {
|
2007-01-14 02:47:36 +03:00
|
|
|
cfgerror("cannot mix needs-count and needs-flag");
|
1995-04-28 10:54:58 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
1996-03-17 16:18:15 +03:00
|
|
|
if (optx == NULL && (needc || needf)) {
|
2007-01-14 02:47:36 +03:00
|
|
|
cfgerror("nothing to %s for %s", needc ? "count" : "flag",
|
|
|
|
path);
|
1995-04-28 10:54:58 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
2015-08-28 11:56:39 +03:00
|
|
|
if (*path == '/') {
|
|
|
|
cfgerror("path must be relative");
|
|
|
|
goto bad;
|
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
|
|
|
|
/* find last part of pathname, and same without trailing suffix */
|
1996-11-08 01:59:39 +03:00
|
|
|
tail = strrchr(path, '/');
|
2015-09-01 15:46:20 +03:00
|
|
|
if (tail == NULL) {
|
|
|
|
dirlen = 0;
|
1995-04-28 10:54:58 +04:00
|
|
|
tail = path;
|
2015-09-01 15:46:20 +03:00
|
|
|
} else {
|
|
|
|
dirlen = (size_t)(tail - path);
|
1995-04-28 10:54:58 +04:00
|
|
|
tail++;
|
2015-09-01 15:46:20 +03:00
|
|
|
}
|
|
|
|
memcpy(dir, path, dirlen);
|
|
|
|
dir[dirlen] = '\0';
|
|
|
|
|
1996-11-08 01:59:39 +03:00
|
|
|
dotp = strrchr(tail, '.');
|
1995-04-28 10:54:58 +04:00
|
|
|
if (dotp == NULL || dotp[1] == 0 ||
|
2014-10-29 20:14:50 +03:00
|
|
|
(baselen = (size_t)(dotp - tail)) >= sizeof(base)) {
|
2007-01-14 02:47:36 +03:00
|
|
|
cfgerror("invalid pathname `%s'", path);
|
1995-04-28 10:54:58 +04:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1996-03-17 16:18:15 +03:00
|
|
|
* Commit this file to memory. We will decide later whether it
|
|
|
|
* will be used after all.
|
1995-04-28 10:54:58 +04:00
|
|
|
*/
|
2003-11-25 00:44:37 +03:00
|
|
|
fi = ecalloc(1, sizeof *fi);
|
1996-03-17 16:18:15 +03:00
|
|
|
if (ht_insert(pathtab, path, fi)) {
|
2000-06-09 09:06:12 +04:00
|
|
|
free(fi);
|
|
|
|
if ((fi = ht_lookup(pathtab, path)) == NULL)
|
1996-03-17 16:18:15 +03:00
|
|
|
panic("addfile: ht_lookup(%s)", path);
|
2015-08-29 05:54:07 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If it's a duplicate entry, it is must specify a make
|
|
|
|
* rule, and only a make rule, and must come from
|
|
|
|
* a different source file than the original entry.
|
|
|
|
* If it does otherwise, it is disallowed. This allows
|
|
|
|
* machine-dependent files to override the compilation
|
|
|
|
* options for specific files.
|
|
|
|
*/
|
|
|
|
if (rule != NULL && optx == NULL && flags == 0 &&
|
|
|
|
yyfile != fi->fi_srcfile) {
|
|
|
|
fi->fi_mkrule = rule;
|
|
|
|
return;
|
|
|
|
}
|
2007-01-14 02:47:36 +03:00
|
|
|
cfgerror("duplicate file %s", path);
|
|
|
|
cfgxerror(fi->fi_srcfile, fi->fi_srcline,
|
2000-06-09 09:06:12 +04:00
|
|
|
"here is the original definition");
|
|
|
|
goto bad;
|
1996-03-17 16:18:15 +03:00
|
|
|
}
|
|
|
|
memcpy(base, tail, baselen);
|
2015-09-01 15:46:20 +03:00
|
|
|
base[baselen] = '\0';
|
1995-04-28 10:54:58 +04:00
|
|
|
fi->fi_srcfile = yyfile;
|
|
|
|
fi->fi_srcline = currentline();
|
|
|
|
fi->fi_flags = flags;
|
|
|
|
fi->fi_path = path;
|
|
|
|
fi->fi_tail = tail;
|
1996-03-17 16:18:15 +03:00
|
|
|
fi->fi_base = intern(base);
|
2015-09-01 15:46:20 +03:00
|
|
|
fi->fi_dir = intern(dir);
|
2002-06-05 14:56:17 +04:00
|
|
|
fi->fi_prefix = SLIST_EMPTY(&prefixes) ? NULL :
|
|
|
|
SLIST_FIRST(&prefixes)->pf_prefix;
|
2015-09-01 16:42:48 +03:00
|
|
|
fi->fi_buildprefix = SLIST_EMPTY(&buildprefixes) ? NULL :
|
|
|
|
SLIST_FIRST(&buildprefixes)->pf_prefix;
|
2014-11-17 03:53:15 +03:00
|
|
|
fi->fi_len = strlen(path);
|
|
|
|
fi->fi_suffix = path[fi->fi_len - 1];
|
1996-03-17 16:18:15 +03:00
|
|
|
fi->fi_optx = optx;
|
|
|
|
fi->fi_optf = NULL;
|
2015-08-29 05:54:07 +03:00
|
|
|
fi->fi_mkrule = rule;
|
2014-10-09 14:29:36 +04:00
|
|
|
fi->fi_attr = NULL;
|
2015-09-04 13:16:35 +03:00
|
|
|
fi->fi_order = (int)nallfiles + (includedepth << 16);
|
2015-09-01 14:22:59 +03:00
|
|
|
switch (fi->fi_suffix) {
|
|
|
|
case 'c':
|
|
|
|
TAILQ_INSERT_TAIL(&allcfiles, fi, fi_snext);
|
|
|
|
TAILQ_INSERT_TAIL(&allfiles, fi, fi_next);
|
|
|
|
break;
|
|
|
|
case 'S':
|
2015-09-01 15:10:56 +03:00
|
|
|
fi->fi_suffix = 's';
|
|
|
|
/* FALLTHRU */
|
2015-09-01 14:22:59 +03:00
|
|
|
case 's':
|
|
|
|
TAILQ_INSERT_TAIL(&allsfiles, fi, fi_snext);
|
|
|
|
TAILQ_INSERT_TAIL(&allfiles, fi, fi_next);
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
TAILQ_INSERT_TAIL(&allofiles, fi, fi_snext);
|
2015-09-04 04:24:01 +03:00
|
|
|
TAILQ_INSERT_TAIL(&allfiles, fi, fi_next);
|
2015-09-01 15:10:56 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cfgxerror(fi->fi_srcfile, fi->fi_srcline,
|
|
|
|
"unknown suffix");
|
2015-09-01 14:22:59 +03:00
|
|
|
break;
|
|
|
|
}
|
2015-09-04 13:16:35 +03:00
|
|
|
CFGDBG(3, "file added `%s' at order score %d", fi->fi_path, fi->fi_order);
|
|
|
|
nallfiles++;
|
1995-04-28 10:54:58 +04:00
|
|
|
return;
|
2002-06-05 14:56:17 +04:00
|
|
|
bad:
|
2014-05-21 09:25:34 +04:00
|
|
|
if (optx != NULL) {
|
|
|
|
condexpr_destroy(optx);
|
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
}
|
|
|
|
|
2014-10-09 14:29:36 +04:00
|
|
|
static void
|
|
|
|
addfiletoattr(const char *name, struct files *fi)
|
|
|
|
{
|
|
|
|
struct attr *a;
|
|
|
|
|
|
|
|
a = ht_lookup(attrtab, name);
|
2014-10-09 19:25:26 +04:00
|
|
|
if (a == NULL) {
|
|
|
|
CFGDBG(1, "attr `%s' not found", name);
|
|
|
|
} else {
|
2014-10-09 14:29:36 +04:00
|
|
|
fi->fi_attr = a;
|
2014-10-09 19:25:26 +04:00
|
|
|
TAILQ_INSERT_TAIL(&a->a_files, fi, fi_anext);
|
2014-10-09 14:29:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
/*
|
|
|
|
* We have finished reading some "files" file, either ../../conf/files
|
|
|
|
* or ./files.$machine. Make sure that everything that is flagged as
|
|
|
|
* needing a count is reasonable. (This prevents ../../conf/files from
|
|
|
|
* depending on some machine-specific device.)
|
|
|
|
*/
|
|
|
|
void
|
2000-10-02 23:48:34 +04:00
|
|
|
checkfiles(void)
|
1995-04-28 10:54:58 +04:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct files *fi, *last;
|
1995-04-28 10:54:58 +04:00
|
|
|
|
|
|
|
last = NULL;
|
2002-06-05 14:56:17 +04:00
|
|
|
for (fi = *unchecked; fi != NULL;
|
|
|
|
last = fi, fi = TAILQ_NEXT(fi, fi_next)) {
|
1996-03-17 16:18:15 +03:00
|
|
|
if ((fi->fi_flags & FI_NEEDSCOUNT) != 0)
|
|
|
|
(void)expr_eval(fi->fi_optx, checkaux, fi);
|
2002-06-05 14:56:17 +04:00
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
if (last != NULL)
|
2002-06-05 14:56:17 +04:00
|
|
|
unchecked = &TAILQ_NEXT(last, fi_next);
|
1995-04-28 10:54:58 +04:00
|
|
|
}
|
|
|
|
|
1996-03-17 16:18:15 +03:00
|
|
|
/*
|
|
|
|
* Auxiliary function for checkfiles, called from expr_eval.
|
|
|
|
* We are not actually interested in the expression's value.
|
|
|
|
*/
|
|
|
|
static int
|
2000-10-02 23:48:34 +04:00
|
|
|
checkaux(const char *name, void *context)
|
1996-03-17 16:18:15 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct files *fi = context;
|
1996-03-17 16:18:15 +03:00
|
|
|
|
|
|
|
if (ht_lookup(devbasetab, name) == NULL) {
|
2007-01-14 02:47:36 +03:00
|
|
|
cfgxerror(fi->fi_srcfile, fi->fi_srcline,
|
1996-03-17 16:18:15 +03:00
|
|
|
"`%s' is not a countable device",
|
|
|
|
name);
|
|
|
|
/* keep fixfiles() from complaining again */
|
|
|
|
fi->fi_flags |= FI_HIDDEN;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2015-09-04 13:16:35 +03:00
|
|
|
static int
|
|
|
|
cmpfiles(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const struct files * const *fia = a, * const *fib = b;
|
|
|
|
int sa = (*fia)->fi_order;
|
|
|
|
int sb = (*fib)->fi_order;
|
|
|
|
|
|
|
|
if (sa < sb)
|
|
|
|
return -1;
|
|
|
|
else if (sa > sb)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
/*
|
|
|
|
* We have finished reading everything. Tack the files down: calculate
|
1996-03-17 16:18:15 +03:00
|
|
|
* selection and counts as needed. Check that the object files built
|
|
|
|
* from the selected sources do not collide.
|
1995-04-28 10:54:58 +04:00
|
|
|
*/
|
|
|
|
int
|
2000-10-02 23:48:34 +04:00
|
|
|
fixfiles(void)
|
1995-04-28 10:54:58 +04:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct files *fi, *ofi;
|
1996-03-17 16:18:15 +03:00
|
|
|
struct nvlist *flathead, **flatp;
|
|
|
|
int err, sel;
|
2015-09-04 08:13:32 +03:00
|
|
|
struct config *cf;
|
|
|
|
char swapname[100];
|
1995-04-28 10:54:58 +04:00
|
|
|
|
2015-09-04 13:16:35 +03:00
|
|
|
/* Place these files at last. */
|
|
|
|
int onallfiles = nallfiles;
|
|
|
|
nallfiles = 1 << 30;
|
2015-09-03 17:23:52 +03:00
|
|
|
addfile("devsw.c", NULL, 0, NULL);
|
|
|
|
addfile("ioconf.c", NULL, 0, NULL);
|
|
|
|
|
2015-09-04 08:13:32 +03:00
|
|
|
TAILQ_FOREACH(cf, &allcf, cf_next) {
|
|
|
|
(void)snprintf(swapname, sizeof(swapname), "swap%s.c",
|
|
|
|
cf->cf_name);
|
|
|
|
addfile(intern(swapname), NULL, 0, NULL);
|
|
|
|
}
|
2015-09-04 13:16:35 +03:00
|
|
|
nallfiles = onallfiles;
|
2015-09-01 19:01:23 +03:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
err = 0;
|
2002-06-05 14:56:17 +04:00
|
|
|
TAILQ_FOREACH(fi, &allfiles, fi_next) {
|
2005-11-07 06:26:20 +03:00
|
|
|
|
1996-03-17 16:18:15 +03:00
|
|
|
/* Skip files that generated counted-device complaints. */
|
1995-04-28 10:54:58 +04:00
|
|
|
if (fi->fi_flags & FI_HIDDEN)
|
|
|
|
continue;
|
1997-10-10 14:27:53 +04:00
|
|
|
|
2014-10-09 23:27:04 +04:00
|
|
|
if (fi->fi_optx != NULL) {
|
2014-10-09 14:29:36 +04:00
|
|
|
if (fi->fi_optx->cx_type == CX_ATOM) {
|
|
|
|
addfiletoattr(fi->fi_optx->cx_u.atom, fi);
|
|
|
|
}
|
1996-03-17 16:18:15 +03:00
|
|
|
flathead = NULL;
|
|
|
|
flatp = &flathead;
|
|
|
|
sel = expr_eval(fi->fi_optx,
|
|
|
|
fi->fi_flags & FI_NEEDSCOUNT ? fixcount :
|
|
|
|
fi->fi_flags & FI_NEEDSFLAG ? fixfsel :
|
|
|
|
fixsel,
|
|
|
|
&flatp);
|
|
|
|
fi->fi_optf = flathead;
|
|
|
|
if (!sel)
|
|
|
|
continue;
|
1995-04-28 10:54:58 +04:00
|
|
|
}
|
1996-03-17 16:18:15 +03:00
|
|
|
|
|
|
|
/* We like this file. Make sure it generates a unique .o. */
|
|
|
|
if (ht_insert(basetab, fi->fi_base, fi)) {
|
|
|
|
if ((ofi = ht_lookup(basetab, fi->fi_base)) == NULL)
|
|
|
|
panic("fixfiles ht_lookup(%s)", fi->fi_base);
|
|
|
|
/*
|
|
|
|
* If the new file comes from a different source,
|
|
|
|
* allow the new one to override the old one.
|
|
|
|
*/
|
2000-06-09 09:06:12 +04:00
|
|
|
if (fi->fi_path != ofi->fi_path) {
|
1996-03-17 16:18:15 +03:00
|
|
|
if (ht_replace(basetab, fi->fi_base, fi) != 1)
|
|
|
|
panic("fixfiles ht_replace(%s)",
|
|
|
|
fi->fi_base);
|
2014-10-29 20:14:50 +03:00
|
|
|
ofi->fi_flags &= (u_char)~FI_SEL;
|
1996-03-17 16:18:15 +03:00
|
|
|
ofi->fi_flags |= FI_HIDDEN;
|
|
|
|
} else {
|
2007-01-14 02:47:36 +03:00
|
|
|
cfgxerror(fi->fi_srcfile, fi->fi_srcline,
|
1996-03-17 16:18:15 +03:00
|
|
|
"object file collision on %s.o, from %s",
|
|
|
|
fi->fi_base, fi->fi_path);
|
2007-01-14 02:47:36 +03:00
|
|
|
cfgxerror(ofi->fi_srcfile, ofi->fi_srcline,
|
1996-03-17 16:18:15 +03:00
|
|
|
"here is the previous file: %s",
|
|
|
|
ofi->fi_path);
|
|
|
|
err = 1;
|
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
}
|
1996-03-17 16:18:15 +03:00
|
|
|
fi->fi_flags |= FI_SEL;
|
2015-09-04 13:16:35 +03:00
|
|
|
nselfiles++;
|
2014-10-09 19:25:26 +04:00
|
|
|
CFGDBG(3, "file selected `%s'", fi->fi_path);
|
|
|
|
|
|
|
|
/* Add other files to the default "netbsd" attribute. */
|
|
|
|
if (fi->fi_attr == NULL) {
|
|
|
|
addfiletoattr(allattr.a_name, fi);
|
|
|
|
}
|
|
|
|
CFGDBG(3, "file `%s' belongs to attr `%s'", fi->fi_path,
|
|
|
|
fi->fi_attr->a_name);
|
1995-04-28 10:54:58 +04:00
|
|
|
}
|
2015-09-04 13:16:35 +03:00
|
|
|
|
|
|
|
/* Order files. */
|
|
|
|
selfiles = malloc(nselfiles * sizeof(fi));
|
2015-09-05 00:32:54 +03:00
|
|
|
unsigned i = 0;
|
2015-09-04 13:16:35 +03:00
|
|
|
TAILQ_FOREACH(fi, &allfiles, fi_next) {
|
|
|
|
if ((fi->fi_flags & FI_SEL) == 0)
|
|
|
|
continue;
|
|
|
|
selfiles[i++] = fi;
|
|
|
|
}
|
2015-09-04 18:50:48 +03:00
|
|
|
assert(i <= nselfiles);
|
|
|
|
nselfiles = i;
|
2015-09-04 13:16:35 +03:00
|
|
|
qsort(selfiles, nselfiles, (unsigned)sizeof(fi), cmpfiles);
|
1995-04-28 10:54:58 +04:00
|
|
|
return (err);
|
|
|
|
}
|
1996-03-17 16:18:15 +03:00
|
|
|
|
1997-10-10 14:27:53 +04:00
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
/*
|
|
|
|
* We have finished reading everything. Tack the devsws down: calculate
|
|
|
|
* selection.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
fixdevsw(void)
|
|
|
|
{
|
2006-12-26 03:07:18 +03:00
|
|
|
int error;
|
2002-09-06 17:18:43 +04:00
|
|
|
struct devm *dm, *res;
|
2003-01-23 18:03:44 +03:00
|
|
|
struct hashtab *fixdevmtab;
|
2002-09-06 17:18:43 +04:00
|
|
|
char mstr[16];
|
|
|
|
|
2006-12-26 03:07:18 +03:00
|
|
|
error = 0;
|
2002-09-06 17:18:43 +04:00
|
|
|
fixdevmtab = ht_new();
|
|
|
|
|
|
|
|
TAILQ_FOREACH(dm, &alldevms, dm_next) {
|
|
|
|
res = ht_lookup(fixdevmtab, intern(dm->dm_name));
|
|
|
|
if (res != NULL) {
|
|
|
|
if (res->dm_cmajor != dm->dm_cmajor ||
|
2003-01-23 17:55:39 +03:00
|
|
|
res->dm_bmajor != dm->dm_bmajor) {
|
2007-01-14 02:47:36 +03:00
|
|
|
cfgxerror(res->dm_srcfile, res->dm_srcline,
|
2007-12-01 02:19:18 +03:00
|
|
|
"device-major '%s' "
|
|
|
|
"block %d, char %d redefined"
|
|
|
|
" at %s:%d as block %d, char %d",
|
|
|
|
res->dm_name,
|
|
|
|
res->dm_bmajor, res->dm_cmajor,
|
|
|
|
dm->dm_srcfile, dm->dm_srcline,
|
|
|
|
dm->dm_bmajor, dm->dm_cmajor);
|
2003-01-23 17:57:40 +03:00
|
|
|
} else {
|
2007-12-01 02:19:18 +03:00
|
|
|
cfgxerror(res->dm_srcfile, res->dm_srcline,
|
|
|
|
"device-major '%s' "
|
|
|
|
"(block %d, char %d) duplicated"
|
|
|
|
" at %s:%d",
|
|
|
|
dm->dm_name, dm->dm_bmajor,
|
|
|
|
dm->dm_cmajor,
|
|
|
|
dm->dm_srcfile, dm->dm_srcline);
|
2002-09-06 17:18:43 +04:00
|
|
|
}
|
2007-12-01 02:19:18 +03:00
|
|
|
error = 1;
|
|
|
|
goto out;
|
2003-01-23 18:05:45 +03:00
|
|
|
}
|
|
|
|
if (ht_insert(fixdevmtab, intern(dm->dm_name), dm)) {
|
|
|
|
panic("fixdevsw: %s char %d block %d",
|
|
|
|
dm->dm_name, dm->dm_cmajor, dm->dm_bmajor);
|
2002-09-06 17:18:43 +04:00
|
|
|
}
|
|
|
|
|
2003-01-23 18:01:54 +03:00
|
|
|
if (dm->dm_opts != NULL &&
|
|
|
|
!expr_eval(dm->dm_opts, fixsel, NULL))
|
|
|
|
continue;
|
|
|
|
|
2009-01-20 21:20:47 +03:00
|
|
|
if (dm->dm_cmajor != NODEVMAJOR) {
|
2003-01-23 18:05:45 +03:00
|
|
|
if (ht_lookup(cdevmtab, intern(dm->dm_name)) != NULL) {
|
2007-01-14 02:47:36 +03:00
|
|
|
cfgxerror(dm->dm_srcfile, dm->dm_srcline,
|
2003-01-23 18:05:45 +03:00
|
|
|
"device-major of character device '%s' "
|
|
|
|
"is already defined", dm->dm_name);
|
2006-12-26 03:07:18 +03:00
|
|
|
error = 1;
|
2006-09-27 23:05:46 +04:00
|
|
|
goto out;
|
2003-01-23 18:05:45 +03:00
|
|
|
}
|
|
|
|
(void)snprintf(mstr, sizeof(mstr), "%d", dm->dm_cmajor);
|
|
|
|
if (ht_lookup(cdevmtab, intern(mstr)) != NULL) {
|
2007-01-14 02:47:36 +03:00
|
|
|
cfgxerror(dm->dm_srcfile, dm->dm_srcline,
|
2003-01-23 18:05:45 +03:00
|
|
|
"device-major of character major '%d' "
|
|
|
|
"is already defined", dm->dm_cmajor);
|
2006-12-26 03:07:18 +03:00
|
|
|
error = 1;
|
2006-09-27 23:05:46 +04:00
|
|
|
goto out;
|
2003-01-23 18:05:45 +03:00
|
|
|
}
|
|
|
|
if (ht_insert(cdevmtab, intern(dm->dm_name), dm) ||
|
|
|
|
ht_insert(cdevmtab, intern(mstr), dm)) {
|
|
|
|
panic("fixdevsw: %s character major %d",
|
|
|
|
dm->dm_name, dm->dm_cmajor);
|
|
|
|
}
|
2002-09-06 17:18:43 +04:00
|
|
|
}
|
2009-01-20 21:20:47 +03:00
|
|
|
if (dm->dm_bmajor != NODEVMAJOR) {
|
2002-09-06 17:18:43 +04:00
|
|
|
if (ht_lookup(bdevmtab, intern(dm->dm_name)) != NULL) {
|
2007-01-14 02:47:36 +03:00
|
|
|
cfgxerror(dm->dm_srcfile, dm->dm_srcline,
|
2002-09-06 17:18:43 +04:00
|
|
|
"device-major of block device '%s' "
|
|
|
|
"is already defined", dm->dm_name);
|
2006-12-26 03:07:18 +03:00
|
|
|
error = 1;
|
2006-09-27 23:05:46 +04:00
|
|
|
goto out;
|
2002-09-06 17:18:43 +04:00
|
|
|
}
|
|
|
|
(void)snprintf(mstr, sizeof(mstr), "%d", dm->dm_bmajor);
|
|
|
|
if (ht_lookup(bdevmtab, intern(mstr)) != NULL) {
|
2007-01-14 02:47:36 +03:00
|
|
|
cfgxerror(dm->dm_srcfile, dm->dm_srcline,
|
2002-09-06 17:18:43 +04:00
|
|
|
"device-major of block major '%d' "
|
|
|
|
"is already defined", dm->dm_bmajor);
|
2006-12-26 03:07:18 +03:00
|
|
|
error = 1;
|
2006-09-27 23:05:46 +04:00
|
|
|
goto out;
|
2002-09-06 17:18:43 +04:00
|
|
|
}
|
|
|
|
if (ht_insert(bdevmtab, intern(dm->dm_name), dm) ||
|
|
|
|
ht_insert(bdevmtab, intern(mstr), dm)) {
|
|
|
|
panic("fixdevsw: %s block major %d",
|
|
|
|
dm->dm_name, dm->dm_bmajor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-27 23:05:46 +04:00
|
|
|
out:
|
|
|
|
ht_free(fixdevmtab);
|
2006-12-26 03:07:18 +03:00
|
|
|
return (error);
|
2002-09-06 17:18:43 +04:00
|
|
|
}
|
|
|
|
|
1996-03-17 16:18:15 +03:00
|
|
|
/*
|
|
|
|
* Called when evaluating a needs-count expression. Make sure the
|
|
|
|
* atom is a countable device. The expression succeeds iff there
|
|
|
|
* is at least one of them (note that while `xx*' will not always
|
|
|
|
* set xx's d_umax > 0, you cannot mix '*' and needs-count). The
|
|
|
|
* mkheaders() routine wants a flattened, in-order list of the
|
|
|
|
* atoms for `#define name value' lines, so we build that as we
|
|
|
|
* are called to eval each atom.
|
|
|
|
*/
|
|
|
|
static int
|
2000-10-02 23:48:34 +04:00
|
|
|
fixcount(const char *name, void *context)
|
1996-03-17 16:18:15 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct nvlist ***p = context;
|
|
|
|
struct devbase *dev;
|
|
|
|
struct nvlist *nv;
|
1996-03-17 16:18:15 +03:00
|
|
|
|
|
|
|
dev = ht_lookup(devbasetab, name);
|
|
|
|
if (dev == NULL) /* cannot occur here; we checked earlier */
|
|
|
|
panic("fixcount(%s)", name);
|
|
|
|
nv = newnv(name, NULL, NULL, dev->d_umax, NULL);
|
|
|
|
**p = nv;
|
|
|
|
*p = &nv->nv_next;
|
|
|
|
(void)ht_insert(needcnttab, name, nv);
|
|
|
|
return (dev->d_umax != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called from fixfiles when eval'ing a selection expression for a
|
|
|
|
* file that will generate a .h with flags. We will need the flat list.
|
|
|
|
*/
|
|
|
|
static int
|
2000-10-02 23:48:34 +04:00
|
|
|
fixfsel(const char *name, void *context)
|
1996-03-17 16:18:15 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct nvlist ***p = context;
|
|
|
|
struct nvlist *nv;
|
|
|
|
int sel;
|
1996-03-17 16:18:15 +03:00
|
|
|
|
|
|
|
sel = ht_lookup(selecttab, name) != NULL;
|
|
|
|
nv = newnv(name, NULL, NULL, sel, NULL);
|
|
|
|
**p = nv;
|
|
|
|
*p = &nv->nv_next;
|
|
|
|
return (sel);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* As for fixfsel above, but we do not need the flat list.
|
|
|
|
*/
|
|
|
|
static int
|
2007-01-14 02:47:36 +03:00
|
|
|
/*ARGSUSED*/
|
2000-10-02 23:48:34 +04:00
|
|
|
fixsel(const char *name, void *context)
|
1996-03-17 16:18:15 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
return (ht_lookup(selecttab, name) != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Eval an expression tree. Calls the given function on each node,
|
|
|
|
* passing it the given context & the name; return value is &/|/! of
|
|
|
|
* results of evaluating atoms.
|
|
|
|
*
|
|
|
|
* No short circuiting ever occurs. fn must return 0 or 1 (otherwise
|
|
|
|
* our mixing of C's bitwise & boolean here may give surprises).
|
|
|
|
*/
|
2009-03-13 21:24:41 +03:00
|
|
|
int
|
2012-03-11 12:21:53 +04:00
|
|
|
expr_eval(struct condexpr *expr, int (*fn)(const char *, void *), void *ctx)
|
1996-03-17 16:18:15 +03:00
|
|
|
{
|
|
|
|
int lhs, rhs;
|
|
|
|
|
2012-03-11 12:21:53 +04:00
|
|
|
switch (expr->cx_type) {
|
1996-03-17 16:18:15 +03:00
|
|
|
|
2012-03-11 12:21:53 +04:00
|
|
|
case CX_ATOM:
|
|
|
|
return ((*fn)(expr->cx_atom, ctx));
|
1996-03-17 16:18:15 +03:00
|
|
|
|
2012-03-11 12:21:53 +04:00
|
|
|
case CX_NOT:
|
|
|
|
return (!expr_eval(expr->cx_not, fn, ctx));
|
1996-03-17 16:18:15 +03:00
|
|
|
|
2012-03-11 12:21:53 +04:00
|
|
|
case CX_AND:
|
|
|
|
lhs = expr_eval(expr->cx_and.left, fn, ctx);
|
|
|
|
rhs = expr_eval(expr->cx_and.right, fn, ctx);
|
1996-03-17 16:18:15 +03:00
|
|
|
return (lhs & rhs);
|
|
|
|
|
2012-03-11 12:21:53 +04:00
|
|
|
case CX_OR:
|
|
|
|
lhs = expr_eval(expr->cx_or.left, fn, ctx);
|
|
|
|
rhs = expr_eval(expr->cx_or.right, fn, ctx);
|
1996-03-17 16:18:15 +03:00
|
|
|
return (lhs | rhs);
|
|
|
|
}
|
2012-03-11 12:21:53 +04:00
|
|
|
panic("invalid condexpr type %d", (int)expr->cx_type);
|
1996-03-17 16:18:15 +03:00
|
|
|
/* NOTREACHED */
|
1997-10-18 11:58:56 +04:00
|
|
|
return (0);
|
1996-03-17 16:18:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
/*
|
|
|
|
* Print expression tree.
|
|
|
|
*/
|
|
|
|
void
|
2000-10-02 23:48:34 +04:00
|
|
|
prexpr(struct nvlist *expr)
|
1996-03-17 16:18:15 +03:00
|
|
|
{
|
|
|
|
static void pr0();
|
|
|
|
|
|
|
|
printf("expr =");
|
|
|
|
pr0(expr);
|
|
|
|
printf("\n");
|
|
|
|
(void)fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
pr0(struct nvlist *e)
|
1996-03-17 16:18:15 +03:00
|
|
|
{
|
|
|
|
|
2008-12-28 04:23:46 +03:00
|
|
|
switch (e->nv_num) {
|
1996-03-17 16:18:15 +03:00
|
|
|
case FX_ATOM:
|
|
|
|
printf(" %s", e->nv_name);
|
|
|
|
return;
|
|
|
|
case FX_NOT:
|
|
|
|
printf(" (!");
|
|
|
|
break;
|
|
|
|
case FX_AND:
|
|
|
|
printf(" (&");
|
|
|
|
break;
|
|
|
|
case FX_OR:
|
|
|
|
printf(" (|");
|
|
|
|
break;
|
|
|
|
default:
|
2008-12-28 04:23:46 +03:00
|
|
|
printf(" (?%lld?", e->nv_num);
|
1996-03-17 16:18:15 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (e->nv_ptr)
|
|
|
|
pr0(e->nv_ptr);
|
|
|
|
pr0(e->nv_next);
|
|
|
|
printf(")");
|
|
|
|
}
|
|
|
|
#endif
|