From b8f194db951584d15a28769028bf6ed03b68c53f Mon Sep 17 00:00:00 2001 From: niklas Date: Sun, 3 Mar 1996 12:32:57 +0000 Subject: [PATCH] From NetBSD: Fix problems with the way init.o is built: * Prevent gratuitous rebuilds when nothing has changed. * Make sure it is rebuilt if a .h file is updated. --- bin/sh/Makefile | 15 ++++----- bin/sh/mkinit.c | 83 ++++++------------------------------------------- 2 files changed, 15 insertions(+), 83 deletions(-) diff --git a/bin/sh/Makefile b/bin/sh/Makefile index 07df49d324e..d84a34cabf4 100644 --- a/bin/sh/Makefile +++ b/bin/sh/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.22 1995/10/22 00:15:02 christos Exp $ +# $NetBSD: Makefile,v 1.23 1996/02/18 12:29:18 mycroft Exp $ # @(#)Makefile 8.4 (Berkeley) 5/5/95 PROG= sh @@ -6,15 +6,16 @@ SRCS= alias.c builtins.c cd.c echo.c error.c eval.c exec.c expand.c \ histedit.c input.c jobs.c mail.c main.c memalloc.c miscbltin.c \ mystring.c nodes.c options.c parser.c redir.c show.c syntax.c \ trap.c output.c var.c -OBJS+= init.o arith.o arith_lex.o +OBJS+= arith.o arith_lex.o init.o LDADD+= -ll -ledit -ltermcap DPADD+= ${LIBL} ${LIBEDIT} ${LIBTERMCAP} LFLAGS= -8 # 8-bit lex scanner for arithmetic CFLAGS+=-DSHELL -I. -I${.CURDIR} .PATH: ${.CURDIR}/bltin ${.CURDIR}/../../usr.bin/printf CLEANFILES+=\ - builtins.c builtins.h init.c mkinit mknodes mksyntax \ - nodes.c nodes.h printf.o syntax.c syntax.h token.def y.tab.h + arith.c arith_lex.c builtins.c builtins.h init.c mkinit mknodes \ + mksyntax nodes.c nodes.h printf.o syntax.c syntax.h token.def \ + y.tab.c y.tab.h .depend parser.o: token.def @@ -25,7 +26,7 @@ builtins.h builtins.c: ${.CURDIR}/mkbuiltins ${.CURDIR}/builtins.def cd ${.CURDIR}; sh mkbuiltins ${.OBJDIR} init.c: mkinit ${SRCS} - ./mkinit '${CC} -c ${CFLAGS} init.c' ${.ALLSRC:S/^mkinit$//} + ./mkinit ${.ALLSRC:S/^mkinit$//} mkinit: ${.CURDIR}/mkinit.c ${CC} ${CFLAGS} ${.CURDIR}/mkinit.c -o $@ @@ -42,8 +43,4 @@ syntax.c syntax.h: mksyntax mksyntax: ${.CURDIR}/mksyntax.c ${.CURDIR}/parser.h ${CC} ${CFLAGS} ${.CURDIR}/mksyntax.c -o $@ -arith_lex.o: arith.o - -${OBJS}: init.c - .include diff --git a/bin/sh/mkinit.c b/bin/sh/mkinit.c index 78bdd8206d4..b2bfbc02d98 100644 --- a/bin/sh/mkinit.c +++ b/bin/sh/mkinit.c @@ -1,4 +1,4 @@ -/* $NetBSD: mkinit.c,v 1.13 1995/05/11 21:29:34 christos Exp $ */ +/* $NetBSD: mkinit.c,v 1.14 1996/02/18 12:29:21 mycroft Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -46,7 +46,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mkinit.c 8.2 (Berkeley) 5/4/95"; #else -static char rcsid[] = "$NetBSD: mkinit.c,v 1.13 1995/05/11 21:29:34 christos Exp $"; +static char rcsid[] = "$NetBSD: mkinit.c,v 1.14 1996/02/18 12:29:21 mycroft Exp $"; #endif #endif /* not lint */ @@ -55,10 +55,9 @@ static char rcsid[] = "$NetBSD: mkinit.c,v 1.13 1995/05/11 21:29:34 christos Exp * special events and combines this code into one file. This (allegedly) * improves the structure of the program since there is no need for * anyone outside of a module to know that that module performs special - * operations on particular events. The command is executed iff init.c - * is actually changed. + * operations on particular events. * - * Usage: mkinit command sourcefile... + * Usage: mkinit sourcefile... */ @@ -73,13 +72,11 @@ static char rcsid[] = "$NetBSD: mkinit.c,v 1.13 1995/05/11 21:29:34 christos Exp /* * OUTFILE is the name of the output file. Output is initially written - * to the file OUTTEMP, which is then moved to OUTFILE if OUTTEMP and - * OUTFILE are different. + * to the file OUTTEMP, which is then moved to OUTFILE. */ #define OUTFILE "init.c" #define OUTTEMP "init.c.new" -#define OUTOBJ "init.o" /* @@ -113,7 +110,7 @@ struct event { char *name; /* name of event (e.g. INIT) */ char *routine; /* name of routine called on event */ char *comment; /* comment describing routine */ - struct text code; /* code for handling event */ + struct text code; /* code for handling event */ }; @@ -163,8 +160,6 @@ void doevent __P((struct event *, FILE *, char *)); void doinclude __P((char *)); void dodecl __P((char *, FILE *)); void output __P((void)); -int file_changed __P((void)); -int touch __P((char *)); void addstr __P((char *, struct text *)); void addchar __P((int, struct text *)); void writetext __P((struct text *, FILE *)); @@ -182,27 +177,13 @@ main(argc, argv) { char **ap; - if (argc < 2) - error("Usage: mkinit command file..."); header_files[0] = "\"shell.h\""; header_files[1] = "\"mystring.h\""; - for (ap = argv + 2 ; *ap ; ap++) + for (ap = argv + 1 ; *ap ; ap++) readfile(*ap); output(); - if (file_changed()) { - unlink(OUTFILE); - link(OUTTEMP, OUTFILE); - unlink(OUTTEMP); - } else { - unlink(OUTTEMP); - if (touch(OUTOBJ)) - exit(0); /* no compilation necessary */ - } - printf("%s\n", argv[1]); - execl("/bin/sh", "sh", "-c", argv[1], (char *)0); - error("Can't exec shell"); - - exit(1); + rename(OUTTEMP, OUTFILE); + exit(0); } @@ -419,52 +400,6 @@ output() { } -/* - * Return true if the new output file is different from the old one. - */ - -int -file_changed() -{ - register FILE *f1, *f2; - register int c; - - if ((f1 = fopen(OUTFILE, "r")) == NULL - || (f2 = fopen(OUTTEMP, "r")) == NULL) - return 1; - while ((c = getc(f1)) == getc(f2)) { - if (c == EOF) - return 0; - } - return 1; -} - - -/* - * Touch a file. Returns 0 on failure, 1 on success. - */ - -int -touch(file) - char *file; -{ - int fd; - char c; - - if ((fd = open(file, O_RDWR)) < 0) - return 0; - if (read(fd, &c, 1) != 1) { - close(fd); - return 0; - } - lseek(fd, (off_t)0, 0); - write(fd, &c, 1); - close(fd); - return 1; -} - - - /* * A text structure is simply a block of text that is kept in memory. * Addstr appends a string to the text struct, and addchar appends a single -- 2.20.1