Browse Source

tools/Makefile: avoid rebuilding over and over

H. Peter Anvin 3 years ago
parent
commit
776ec1c1d2
2 changed files with 26 additions and 9 deletions
  1. 1 0
      .gitignore
  2. 25 9
      tools/Makefile

+ 1 - 0
.gitignore

@@ -24,6 +24,7 @@ greybox_tmp/
 *.eqn
 *.log
 *.deps
+*.stamp
 *.build/
 fpga/output_files/*.htm
 fpga/output_files/*.htm_files/

+ 25 - 9
tools/Makefile

@@ -28,35 +28,51 @@ _tail = $(wordlist 2,$(words $(1)),$(1))
 _strip_flags = $(if $(1),$(call _strip_flags,$(call _tail,$(1)),$(subst $(word 1,$(1)),,$(2))),$(2))
 strip_flags  = $(if $(findstring -,$(word 1,$(2))),$(2),$(call _strip_flags,$(1),$(word 1,$(2))) $(call _tail,$(2)))
 
-RMAKE = $(MAKE) MAKEFLAGS='$(call strip_flags,r R,$(MAKEFLAGS))'
+RMAKE = +$(MAKE) MAKEFLAGS='$(call strip_flags,r R,$(MAKEFLAGS))'
 
 riscv_configargs := target_configargs='--enable-lite-exit --disable-newlib-register-fini'
 
-all: gnu.riscv.build gnu.z80.build
+all: gnu
 
 clean:
-	rm -rf *.build *~ *.bak \#* .\#*
+	rm -rf *.build *~ *.bak \#* .\#* *.deps *.stamp
 
 spotless: clean
 	rm -rf gnu
 
-.PHONY: src
-src:
-	[ ! -f ../../.gitmodules ] || \
-		git submodule update --init --recursive
+.PHONY: gnu.src
+gnu.src:
+	if [ -f ../../.gitmodules ] && \
+	   git submodule status --recursive | grep -q '^[+-]'; then \
+		git submodule update --init --recursive ; \
+		rm -rf gnu gnu.*.stamp ; \
+	fi
+
+.PHONY: gnu
+gnu:
+	$(MAKE) gnu.src
+	$(MAKE) gnu.bin
+
+.PHONY: gnu.bin
+gnu.bin: gnu.riscv.build.stamp gnu.z80.build.stamp
 
 # Note: the riscv-gnu-toolchain repo has bugs when building in
 # parallel, so spoon feed it a sequence to avoid dependency problems.
+%.build.stamp:
+	$(MAKE) $*.build
+
 .PHONY: gnu.riscv.build
-gnu.riscv.build: src
+gnu.riscv.build:
 	mkdir -p $@
 	cd $@ && $(riscv_configargs) ../$(tooldir)/configure $(riscv_config)
 	$(RMAKE) -C $@ $(riscv_configargs) build-binutils
 	$(RMAKE) -C $@ $(riscv_configargs) newlib
+	: >$@.stamp
 
 .PHONY: gnu.z80.build
-gnu.z80.build: src
+gnu.z80.build:
 	mkdir -p $@
 	cd $@ && ../$(binutils)/configure $(z80_config)
 	$(RMAKE) -C $@
 	$(RMAKE) -C $@ install
+	: >$@.stamp