From 8c363688ac173d34c865b8271ade8c845b67fa24 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 24 Sep 2018 21:34:35 +0200 Subject: Makefile: Only run `xcodebuild` when there are changes Previously, Make would always run `xcodebuild`. I couldn't figure out why, but after some looking around and experimenting, it looked to be due to the `$(RUST_LIB)` prerequisite. Putting it in the order-only dependencies list seems to fix the never-up-to-date problem. Also use `:=` instead of `=` when defining `SOURCE_FILES`. During my research, I came across this recommendation: > always use := not = for shell (and wildcard, for that matter) for > performance reasons. From MadScientist (https://stackoverflow.com/users/939557/madscientist) on Stack Overflow: https://stackoverflow.com/questions/26694249/makefiles-using-wildcard-vs-find-for-specifying-source-files/26694693#26694693 Move the `DomeKey` debug product executable path into a variable and use it as a target to clarify the build target and also allow us to substitute the variable in the `run` task. Now finally, `make run` won't re-build the project if no changes have been made, it'll just run the executable. --- Makefile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 1a1f35c..687d70a 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -SOURCE_FILES = $(shell find DomeKey lib \ +SOURCE_FILES := $(shell find DomeKey lib \ -type f \ -name '*.h' \ -or -name '*.m' \ @@ -7,9 +7,13 @@ SOURCE_FILES = $(shell find DomeKey lib \ RUST_DIR := lib/dome-key-map RUST_LIB := target/debug/libdome_key_map.a +DEBUG_PRODUCT := ~/Library/Developer/Xcode/DerivedData/DomeKey-*/Build/Products/Debug/DomeKey + .PHONY: build -build: $(SOURCE_FILES) $(RUST_LIB) +build: $(DEBUG_PRODUCT) + +$(DEBUG_PRODUCT): $(SOURCE_FILES) | $(RUST_LIB) xcodebuild -scheme DomeKey -configuration Debug $(RUST_LIB): @@ -17,4 +21,4 @@ $(RUST_LIB): .PHONY: run run: build - ~/Library/Developer/Xcode/DerivedData/DomeKey-*/Build/Products/Debug/DomeKey + $(DEBUG_PRODUCT) -- cgit v1.2.3