mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-29 04:21:26 +01:00
Make a little more effort to avoid touching certain generated files if
they were not changed. This makes 'make depend' more useful.
This commit is contained in:
parent
b90ef46a2f
commit
5b70a95cd8
@ -192,6 +192,7 @@ char *get_word();
|
||||
char *get_quoted_word();
|
||||
char *path();
|
||||
char *raise();
|
||||
void moveifchanged();
|
||||
|
||||
int do_trace;
|
||||
|
||||
|
@ -44,8 +44,11 @@ static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <sysexits.h>
|
||||
#include "y.tab.h"
|
||||
#include "config.h"
|
||||
|
||||
@ -328,3 +331,65 @@ path(file)
|
||||
}
|
||||
return (cp);
|
||||
}
|
||||
|
||||
/*
|
||||
* moveifchanged --
|
||||
* compare two files; rename if changed.
|
||||
*/
|
||||
void
|
||||
moveifchanged(const char *from_name, const char *to_name)
|
||||
{
|
||||
char *p, *q;
|
||||
int changed;
|
||||
size_t tsize;
|
||||
struct stat from_sb, to_sb;
|
||||
int from_fd, to_fd;
|
||||
|
||||
changed = 0;
|
||||
|
||||
if ((from_fd = open(from_name, O_RDONLY)) < 0)
|
||||
err(EX_OSERR, "moveifchanged open(%s)", from_name);
|
||||
|
||||
if ((to_fd = open(to_name, O_RDONLY)) < 0)
|
||||
changed++;
|
||||
|
||||
if (!changed && fstat(from_fd, &from_sb) < 0)
|
||||
err(EX_OSERR, "moveifchanged fstat(%s)", from_name);
|
||||
|
||||
if (!changed && fstat(to_fd, &to_sb) < 0)
|
||||
err(EX_OSERR, "moveifchanged fstat(%s)", to_name);
|
||||
|
||||
if (!changed && from_sb.st_size != to_sb.st_size)
|
||||
changed++;
|
||||
|
||||
tsize = (size_t)from_sb.st_size;
|
||||
|
||||
if (!changed) {
|
||||
p = mmap(NULL, tsize, PROT_READ, 0, from_fd, (off_t)0);
|
||||
if ((long)p == -1)
|
||||
err(EX_OSERR, "mmap %s", from_name);
|
||||
q = mmap(NULL, tsize, PROT_READ, 0, to_fd, (off_t)0);
|
||||
if ((long)q == -1)
|
||||
err(EX_OSERR, "mmap %s", to_name);
|
||||
|
||||
changed = memcmp(p, q, tsize);
|
||||
munmap(p, tsize);
|
||||
munmap(q, tsize);
|
||||
}
|
||||
if (changed) {
|
||||
if (rename(from_name, to_name) < 0)
|
||||
err(EX_OSERR, "rename(%s, %s)", from_name, to_name);
|
||||
} else {
|
||||
if (unlink(from_name) < 0)
|
||||
err(EX_OSERR, "unlink(%s, %s)", from_name);
|
||||
}
|
||||
|
||||
#ifdef DIAG
|
||||
if (changed)
|
||||
printf("CHANGED! rename (%s, %s)\n", from_name, to_name);
|
||||
else
|
||||
printf("SAME! unlink (%s)\n", from_name);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -346,9 +346,9 @@ vector()
|
||||
int dev_id;
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen(path("vector.h"), "w");
|
||||
fp = fopen(path("vector.h.new"), "w");
|
||||
if (fp == NULL) {
|
||||
perror(path("vector.h"));
|
||||
perror(path("vector.h.new"));
|
||||
exit(1);
|
||||
}
|
||||
fprintf(fp, "/*\n");
|
||||
@ -367,6 +367,7 @@ vector()
|
||||
fprintf(fp, "\"\n\n");
|
||||
fprintf(fp, "#define\tNR_DEVICES\t%d\n", dev_id);
|
||||
(void) fclose(fp);
|
||||
moveifchanged(path("vector.h.new"), path("vector.h"));
|
||||
}
|
||||
|
||||
vector_devtab(fp, table, dev_idp)
|
||||
|
@ -608,9 +608,9 @@ i386_ioconf()
|
||||
static char *old_d_name;
|
||||
static char old_shandler[32 + 1];
|
||||
|
||||
fp = fopen(path("ioconf.c"), "w");
|
||||
fp = fopen(path("ioconf.c.new"), "w");
|
||||
if (fp == 0) {
|
||||
perror(path("ioconf.c"));
|
||||
perror(path("ioconf.c.new"));
|
||||
exit(1);
|
||||
}
|
||||
fprintf(fp, "/*\n");
|
||||
@ -622,9 +622,9 @@ i386_ioconf()
|
||||
fprintf(fp, "#include \"ioconf.h\"\n");
|
||||
fprintf(fp, "\n");
|
||||
fprintf(fp, "#define C (caddr_t)\n");
|
||||
fp1 = fopen(path("ioconf.h"), "w");
|
||||
fp1 = fopen(path("ioconf.h.new"), "w");
|
||||
if (fp1 == 0) {
|
||||
perror(path("ioconf.h"));
|
||||
perror(path("ioconf.h.new"));
|
||||
exit(1);
|
||||
}
|
||||
fprintf(fp1, "/*\n");
|
||||
@ -701,6 +701,8 @@ i386_ioconf()
|
||||
fprintf(fp1, "\n");
|
||||
fprintf(fp1, "#endif /* IOCONF_H */\n");
|
||||
(void) fclose(fp1);
|
||||
moveifchanged(path("ioconf.c.new"), path("ioconf.c"));
|
||||
moveifchanged(path("ioconf.h.new"), path("ioconf.h"));
|
||||
}
|
||||
|
||||
isa_biotab(fp, table)
|
||||
|
@ -150,9 +150,9 @@ makefile()
|
||||
perror(line);
|
||||
exit(1);
|
||||
}
|
||||
ofp = fopen(path("Makefile"), "w");
|
||||
ofp = fopen(path("Makefile.new"), "w");
|
||||
if (ofp == 0) {
|
||||
perror(path("Makefile"));
|
||||
perror(path("Makefile.new"));
|
||||
exit(1);
|
||||
}
|
||||
fprintf(ofp, "KERN_IDENT=%s\n", raise(ident));
|
||||
@ -234,6 +234,7 @@ makefile()
|
||||
}
|
||||
(void) fclose(ifp);
|
||||
(void) fclose(ofp);
|
||||
moveifchanged(path("Makefile.new"), path("Makefile"));
|
||||
#ifdef notyet
|
||||
if (warn_make_clean) {
|
||||
printf("WARNING: Unknown options used (not in ../../conf/options or ./options.%s).\n", machinename);
|
||||
|
@ -66,6 +66,7 @@ do_swap(fl)
|
||||
register struct file_list *fl;
|
||||
{
|
||||
FILE *fp;
|
||||
char newswapname[80];
|
||||
char swapname[80];
|
||||
register struct file_list *swap;
|
||||
dev_t dev;
|
||||
@ -75,9 +76,10 @@ do_swap(fl)
|
||||
return (fl->f_next);
|
||||
}
|
||||
(void) sprintf(swapname, "swap%s.c", fl->f_fn);
|
||||
fp = fopen(path(swapname), "w");
|
||||
(void) sprintf(newswapname, "swap%s.c.new", fl->f_fn);
|
||||
fp = fopen(path(newswapname), "w");
|
||||
if (fp == 0) {
|
||||
perror(path(swapname));
|
||||
perror(path(newswapname));
|
||||
exit(1);
|
||||
}
|
||||
fprintf(fp, "#include <sys/param.h>\n");
|
||||
@ -90,7 +92,7 @@ do_swap(fl)
|
||||
*/
|
||||
swap = fl->f_next;
|
||||
if (swap == 0 || swap->f_type != SWAPSPEC) {
|
||||
(void) unlink(path(swapname));
|
||||
(void) unlink(path(newswapname));
|
||||
fclose(fp);
|
||||
return (swap);
|
||||
}
|
||||
@ -107,6 +109,7 @@ do_swap(fl)
|
||||
fprintf(fp, "\n");
|
||||
fprintf(fp, "void\nsetconf()\n{\n}\n");
|
||||
fclose(fp);
|
||||
moveifchanged(path(newswapname), path(swapname));
|
||||
return (swap);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user