Permalink
Browse files

Makefile: Add implicit header and make-variable dependencies.

  • Loading branch information...
1 parent da77eda commit 55a85e321222de12a28dec6d016f560ea800e9e1 @nelhage committed Jun 26, 2012
Showing with 45 additions and 6 deletions.
  1. +2 −0 .gitignore
  2. +11 −6 Makefile
  3. +32 −0 Makefile.lib
View
@@ -1,3 +1,5 @@
*.o
bemu
instructions.h
+.*.d
+.config
View
@@ -6,28 +6,30 @@ SRCS=bemu.cpp bcpu.cpp bdecode.cpp bt.cpp bclock.cpp bconsole.cpp
ASMSRCS=bt_helper.S
OBJECTS=$(SRCS:.cpp=.o) $(ASMSRCS:.S=.o)
GEN_H=instructions.h
-HEADERS=$(SRCS:.cpp=.h) $(GEN_H) x86.h
+DEPFILES=$(SRCS:%.cpp=.%.d)
BEMU=bemu
UASM=uasm/uasm
TESTS=sancheck litmus bench1 bench2 bench3 bench4 supervisor align qsort timer trap jmptab
TESTS_BIN=$(TESTS:%=tests/%.bin)
-all: $(BEMU) $(TESTS_BIN)
+all: $(BEMU) $(TESTS_BIN) $(DEPFILES)
$(BEMU): $(OBJECTS)
- $(CXX) -o $@ $(LDFLAGS) $^
+ $(CXX) -o $@ $(LDFLAGS) $(filter-out .config/%,$^)
$(UASM): CXXFLAGS += -w
$(UASM):
uasm: $(UASM)
+$(OBJECTS): instructions.h .config/CXX .config/CPPFLAGS .config/CXXFLAGS
+$(BEMU): .config/LDFLAGS
+$(ASMSRCS:.S=.o): .config/ASFLAGS
+
instructions.h: insts.pl
perl $< -cxx > $@
-$(OBJECTS): $(HEADERS)
-
clean:
rm -f $(OBJECTS) $(BEMU)
rm -f tests/*.bin tests/*.map tests/*.sym
@@ -46,7 +48,7 @@ run-timer: BEMUOPTS += -o clock
test: $(TESTS_BIN) $(UASM) $(BEMU)
./run-tests.sh
-TAGS: $(SRCS) $(ASMSRCS) $(HEADERS)
+TAGS: $(SRCS) $(ASMSRCS)
etags $^
tags: TAGS
@@ -55,3 +57,6 @@ check-syntax:
$(CC) $(CCFLAGS) -Wall -Wextra -fsyntax-only $(CHK_SOURCES)
.phony: CLEAN tags check-syntax uasm
+
+include Makefile.lib
+-include $(DEPFILES)
View
@@ -0,0 +1,32 @@
+comma:=,
+
+.%.d: %.cc .config/CXX .config/CPPFLAGS .config/CXXFLAGS
+ @set -e; rm -f $@; \
+ $(CXX) -M $(CPPFLAGS) $(CXXFLAGS) $< > $@.$$$$; \
+ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
+ rm -f $@.$$$$
+
+.%.d: %.cpp .config/CXX .config/CPPFLAGS .config/CXXFLAGS
+ @set -e; rm -f $@; \
+ $(CXX) -M $(CPPFLAGS) $(CXXFLAGS) $< > $@.$$$$; \
+ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
+ rm -f $@.$$$$
+
+.%.d: %.c .config/CC .config/CPPFLAGS .config/CFLAGS
+ @set -e; rm -f $@; \
+ $(CC) -M $(CPPFLAGS) $(CFLAGS) $< > $@.$$$$; \
+ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
+ rm -f $@.$$$$
+
+.config:
+ @mkdir -p $@
+
+.config/%.tmp: .config FORCE
+ @echo $(call $*) > $@
+
+.config/%: .config/%.tmp
+ @cmp -s $< $@ || cp -f $< $@
+ @rm $<
+
+.PHONY: FORCE
+.PRECIOUS: .config/%

0 comments on commit 55a85e3

Please sign in to comment.