From 35ae145926959146adce3d19ec844c2584a05ee4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 19 Apr 2017 06:19:52 -0700 Subject: Makefile: detect when y.tab.h doesn't change. When we touch the parser.y file, yacc regenerates y.tab.h. Then everything which depends on that is rebuilt. However, this is not necessary if the parser.y change doesn't actually modify the contents of y.tab.h. A build system based on file hashes wouldn't have this problem, but make works strictly with modification timestamps. * Makefile (y.tab.c): Preserve the old y.tab.h, if it exists, as y.tab.h.old. Then if the new y.tab.h is exactly the same according to cmp, restore the old y.tab.h in its place. (clean): Remove y.tab.h.old. --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 7bf1d3db..b1b2db11 100644 --- a/Makefile +++ b/Makefile @@ -239,11 +239,15 @@ y.tab.h: y.tab.c y.tab.c: $(top_srcdir)parser.y $(call ABBREV,YACC) + $(V)if [ -e y.tab.h ]; then mv y.tab.h y.tab.h.old ; fi $(V)rm -f y.tab.c $(V)if $(TXR_YACC) -v -d $< ; then \ chmod a-w y.tab.c ; \ sed -e '/yyparse/d' < y.tab.h > y.tab.h.tmp && \ mv y.tab.h.tmp y.tab.h ; \ + if cmp -s y.tab.h y.tab.h.old ; then \ + mv y.tab.h.old y.tab.h ; \ + fi ; \ else \ rm y.tab.c ; \ false ; \ @@ -285,6 +289,7 @@ rebuild: clean repatch $(PROG) clean: conftest.clean tests.clean rm -f $(PROG)$(EXE) $(PROG)-dbg$(EXE) y.tab.c lex.yy.c y.tab.h y.output + rm -f y.tab.h.old rm -f $(PROG)-win$(EXE) $(PROG)-win-dbg$(EXE) rm -rf opt dbg $(EXTRA_OBJS-y) -- cgit v1.2.3