diff --git a/usr.bin/config/defs.h b/usr.bin/config/defs.h index 4a63e582ab9b..5b4a4d236de2 100644 --- a/usr.bin/config/defs.h +++ b/usr.bin/config/defs.h @@ -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); diff --git a/usr.bin/config/files.c b/usr.bin/config/files.c index 1c704276b464..e494201de41f 100644 --- a/usr.bin/config/files.c +++ b/usr.bin/config/files.c @@ -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 -__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 #include @@ -57,6 +57,10 @@ __RCSID("$NetBSD: files.c,v 1.32 2015/09/04 06:01:40 uebayasi Exp $"); 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 condexpr *optx, u_char flags, const char *rule) 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 condexpr *optx, u_char flags, const char *rule) "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); } diff --git a/usr.bin/config/mkmakefile.c b/usr.bin/config/mkmakefile.c index 1b6e3f19f792..d848ef15ad42 100644 --- a/usr.bin/config/mkmakefile.c +++ b/usr.bin/config/mkmakefile.c @@ -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 -__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 #include @@ -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"); diff --git a/usr.bin/config/scan.l b/usr.bin/config/scan.l index a5afcea67d09..1c4209fe8499 100644 --- a/usr.bin/config/scan.l +++ b/usr.bin/config/scan.l @@ -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 -__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 #include @@ -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, int conditional, int direct) 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); }