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.
This commit is contained in:
Peter Wemm 2001-01-29 09:34:43 +00:00
parent f5fccbbcb4
commit e3701bdd59
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=71784

View File

@ -55,6 +55,7 @@ static const char rcsid[] =
#include <stdio.h>
#include <sysexits.h>
#include <unistd.h>
#include <dirent.h>
#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);
}