Module Name: src Committed By: uebayasi Date: Fri Sep 4 10:16:35 UTC 2015
Modified Files: src/usr.bin/config: defs.h files.c mkmakefile.c scan.l Log Message: Sort files in ${ALLFILES} in the order of parsing of `files.*'. config(1) reads the first `files.${MACHINE}' when it encounters `machine'. Then it includes common `files.${MACHINE_SUBARCH}', `files.${MACHINE_ARCH}', and MI `sys/conf/files' at last. This change makes the first "file" in `files.${MACHINE}' appear first in ${ALLFILES}. To generate a diff of this commit: cvs rdiff -u -r1.92 -r1.93 src/usr.bin/config/defs.h cvs rdiff -u -r1.32 -r1.33 src/usr.bin/config/files.c cvs rdiff -u -r1.67 -r1.68 src/usr.bin/config/mkmakefile.c cvs rdiff -u -r1.24 -r1.25 src/usr.bin/config/scan.l Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/config/defs.h diff -u src/usr.bin/config/defs.h:1.92 src/usr.bin/config/defs.h:1.93 --- src/usr.bin/config/defs.h:1.92 Fri Sep 4 06:10:47 2015 +++ src/usr.bin/config/defs.h Fri Sep 4 10:16:35 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: defs.h,v 1.92 2015/09/04 06:10:47 uebayasi Exp $ */ +/* $NetBSD: defs.h,v 1.93 2015/09/04 10:16:35 uebayasi Exp $ */ /* * Copyright (c) 1992, 1993 @@ -353,6 +353,7 @@ struct files { struct nvlist *fi_optf; /* flattened version of above, if needed */ const char *fi_mkrule; /* special make rule, if any */ struct attr *fi_attr; /* owner attr */ + int fi_order; /* score of order in ${ALLFILES} */ TAILQ_ENTRY(files) fi_anext; /* next file in attr */ }; @@ -362,6 +363,9 @@ struct files { #define FI_NEEDSFLAG 0x04 /* needs-flag */ #define FI_HIDDEN 0x08 /* obscured by other(s), base names overlap */ +extern size_t nselfiles; +extern struct files **selfiles; + /* * Condition expressions. */ @@ -613,6 +617,7 @@ u_short currentline(void); int firstfile(const char *); void package(const char *); int include(const char *, int, int, int); +extern int includedepth; /* sem.c, other than for yacc actions */ void initsem(void); Index: src/usr.bin/config/files.c diff -u src/usr.bin/config/files.c:1.32 src/usr.bin/config/files.c:1.33 --- src/usr.bin/config/files.c:1.32 Fri Sep 4 06:01:40 2015 +++ src/usr.bin/config/files.c Fri Sep 4 10:16:35 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: files.c,v 1.32 2015/09/04 06:01:40 uebayasi Exp $ */ +/* $NetBSD: files.c,v 1.33 2015/09/04 10:16:35 uebayasi Exp $ */ /* * Copyright (c) 1992, 1993 @@ -45,7 +45,7 @@ #endif #include <sys/cdefs.h> -__RCSID("$NetBSD: files.c,v 1.32 2015/09/04 06:01:40 uebayasi Exp $"); +__RCSID("$NetBSD: files.c,v 1.33 2015/09/04 10:16:35 uebayasi Exp $"); #include <sys/param.h> #include <errno.h> @@ -57,6 +57,10 @@ __RCSID("$NetBSD: files.c,v 1.32 2015/09 extern const char *yyfile; +int nallfiles; +size_t nselfiles; +struct files **selfiles; + /* * 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 @@ -181,6 +185,7 @@ addfile(const char *path, struct condexp fi->fi_optf = NULL; fi->fi_mkrule = rule; fi->fi_attr = NULL; + fi->fi_order = (int)nallfiles + (includedepth << 16); switch (fi->fi_suffix) { case 'c': TAILQ_INSERT_TAIL(&allcfiles, fi, fi_snext); @@ -202,6 +207,8 @@ addfile(const char *path, struct condexp "unknown suffix"); break; } + CFGDBG(3, "file added `%s' at order score %d", fi->fi_path, fi->fi_order); + nallfiles++; return; bad: if (optx != NULL) { @@ -263,6 +270,21 @@ checkaux(const char *name, void *context return (0); } +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; +} + /* * We have finished reading everything. Tack the files down: calculate * selection and counts as needed. Check that the object files built @@ -277,6 +299,9 @@ fixfiles(void) struct config *cf; char swapname[100]; + /* Place these files at last. */ + int onallfiles = nallfiles; + nallfiles = 1 << 30; addfile("devsw.c", NULL, 0, NULL); addfile("ioconf.c", NULL, 0, NULL); @@ -285,6 +310,7 @@ fixfiles(void) cf->cf_name); addfile(intern(swapname), NULL, 0, NULL); } + nallfiles = onallfiles; err = 0; TAILQ_FOREACH(fi, &allfiles, fi_next) { @@ -334,6 +360,7 @@ fixfiles(void) } } fi->fi_flags |= FI_SEL; + nselfiles++; CFGDBG(3, "file selected `%s'", fi->fi_path); /* Add other files to the default "netbsd" attribute. */ @@ -343,6 +370,16 @@ fixfiles(void) CFGDBG(3, "file `%s' belongs to attr `%s'", fi->fi_path, fi->fi_attr->a_name); } + + /* Order files. */ + selfiles = malloc(nselfiles * sizeof(fi)); + int i = 0; + TAILQ_FOREACH(fi, &allfiles, fi_next) { + if ((fi->fi_flags & FI_SEL) == 0) + continue; + selfiles[i++] = fi; + } + qsort(selfiles, nselfiles, (unsigned)sizeof(fi), cmpfiles); return (err); } Index: src/usr.bin/config/mkmakefile.c diff -u src/usr.bin/config/mkmakefile.c:1.67 src/usr.bin/config/mkmakefile.c:1.68 --- src/usr.bin/config/mkmakefile.c:1.67 Fri Sep 4 06:10:47 2015 +++ src/usr.bin/config/mkmakefile.c Fri Sep 4 10:16:35 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: mkmakefile.c,v 1.67 2015/09/04 06:10:47 uebayasi Exp $ */ +/* $NetBSD: mkmakefile.c,v 1.68 2015/09/04 10:16:35 uebayasi Exp $ */ /* * Copyright (c) 1992, 1993 @@ -45,7 +45,7 @@ #endif #include <sys/cdefs.h> -__RCSID("$NetBSD: mkmakefile.c,v 1.67 2015/09/04 06:10:47 uebayasi Exp $"); +__RCSID("$NetBSD: mkmakefile.c,v 1.68 2015/09/04 10:16:35 uebayasi Exp $"); #include <sys/param.h> #include <ctype.h> @@ -470,13 +470,13 @@ emitallfiles(FILE *fp) { struct files *fi; static int called; + int i; int found = 0; if (called++ != 0) return; - TAILQ_FOREACH(fi, &allfiles, fi_next) { - if ((fi->fi_flags & FI_SEL) == 0) - continue; + for (i = 0; i < (int)nselfiles; i++) { + fi = selfiles[i]; if (found++ == 0) fprintf(fp, "ALLFILES= \\\n"); putc('\t', fp); @@ -493,18 +493,18 @@ static void emitrules(FILE *fp) { struct files *fi; + int i; int found = 0; - TAILQ_FOREACH(fi, &allfiles, fi_next) { - if ((fi->fi_flags & FI_SEL) == 0) - continue; + for (i = 0; i < (int)nselfiles; i++) { + fi = selfiles[i]; if (fi->fi_mkrule == NULL) continue; fprintf(fp, "%s.o: ", fi->fi_base); emitfile(fp, fi); putc('\n', fp); fprintf(fp, "\t%s\n\n", fi->fi_mkrule); - found = 1; + found++; } if (found == 0) fprintf(fp, "#%%RULES\n"); Index: src/usr.bin/config/scan.l diff -u src/usr.bin/config/scan.l:1.24 src/usr.bin/config/scan.l:1.25 --- src/usr.bin/config/scan.l:1.24 Tue Sep 1 13:42:48 2015 +++ src/usr.bin/config/scan.l Fri Sep 4 10:16:35 2015 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: scan.l,v 1.24 2015/09/01 13:42:48 uebayasi Exp $ */ +/* $NetBSD: scan.l,v 1.25 2015/09/04 10:16:35 uebayasi Exp $ */ /* * Copyright (c) 1992, 1993 @@ -42,7 +42,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: scan.l,v 1.24 2015/09/01 13:42:48 uebayasi Exp $"); +__RCSID("$NetBSD: scan.l,v 1.25 2015/09/04 10:16:35 uebayasi Exp $"); #include <sys/param.h> #include <errno.h> @@ -476,6 +476,8 @@ package(const char *fname) free(fname2); } +int includedepth; + /* * Open the named file for inclusion at the current point. Returns 0 on * success (file opened and previous state pushed), nonzero on failure @@ -537,6 +539,7 @@ include(const char *fname, int ateof, in yyfile = intern(s); yyline = 1; free(s); + includedepth++; return (0); } @@ -599,6 +602,8 @@ endinclude(void) interesting = in->in_interesting; free(in); + includedepth--; + return (ateof); }