From 2c6ef92d83b54b2a2a2203ee3860bc46a6c56341 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 29 Jan 2001 09:34:43 +0000 Subject: I confess. This is a truely nasty hack. I am so ashamed! (I think config(8) source does bad things to your brain :-) Clean up likely stray *.h files in the build directory. Eg: if isa.h ceases being generated, zap it. The heuristics to figure out a 'likely' file are pretty revolting. --- usr.sbin/config/main.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c index ed04c8d..520d4fa 100644 --- a/usr.sbin/config/main.c +++ b/usr.sbin/config/main.c @@ -55,6 +55,7 @@ static const char rcsid[] = #include #include #include +#include #include "y.tab.h" #include "config.h" @@ -78,6 +79,7 @@ int profiling; static void configfile(void); static void get_srcdir(void); static void usage(void); +static void cleanheaders(char *, time_t); /* * Config builds a set of files for building a UNIX @@ -90,6 +92,9 @@ main(int argc, char **argv) struct stat buf; int ch, len; char *p; + time_t starttime; + + starttime = time(0); while ((ch = getopt(argc, argv, "d:gp")) != -1) switch (ch) { @@ -171,6 +176,7 @@ main(int argc, char **argv) makefile(); /* build Makefile */ headers(); /* make a lot of .h files */ configfile(); /* put config file into kernel*/ + cleanheaders(p, starttime); printf("Kernel build directory is %s\n", p); exit(0); } @@ -409,3 +415,54 @@ moveifchanged(const char *from_name, const char *to_name) err(EX_OSERR, "unlink(%s)", from_name); } } + +static void +cleanheaders(char *p, time_t starttime) +{ + DIR *dirp; + struct dirent *dp; + struct stat st; + struct file_list *fl; + int i; + + starttime--; + + /* + * Scan the build directory and clean out stuff that looks like + * it might have been a leftover NFOO header, etc. + */ + dirp = opendir(p); + while ((dp = readdir(dirp)) != NULL) { + i = dp->d_namlen - 2; + /* Skip non-headers */ + if (dp->d_name[i] != '.' || dp->d_name[i + 1] != 'h') + continue; + /* Skip stuff that config created or examined in this pass */ + if (stat(path(dp->d_name), &st) == -1) + err(1, "stat(%s)", dp->d_name); + if (st.st_mtime >= starttime || st.st_atime >= starttime || + st.st_ctime >= starttime) + continue; + /* Skip special stuff, eg: bus_if.h, but check opt_*.h */ + if (index(dp->d_name, '_') && + strncmp(dp->d_name, "opt_", 4) != 0) + continue; + /* Some more magic names to skip. Sigh. */ + if (strcmp(dp->d_name, "setdefs.h") == 0 || + strcmp(dp->d_name, "y.tab.h") == 0) + continue; + /* Check if it is a target file */ + for (fl = ftab; fl != NULL; fl = fl->f_next) { + if (strcmp(dp->d_name, fl->f_fn) == 0) { + break; + } + } + if (fl) + continue; + printf("Removing stale header: %s\n", dp->d_name); + unlink(path(dp->d_name)); + } + (void)closedir(dirp); + +} + -- cgit v1.1