From ae33177603d06467243af099036541e2d1649f64 Mon Sep 17 00:00:00 2001 From: KokaKiwi Date: Wed, 23 Oct 2013 17:09:40 +0200 Subject: [PATCH 1/2] Improved Makefile --- Makefile | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 72ba3831c..0d8533fee 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,41 @@ +RUSTC ?= rustc + +RUSTCFLAGS := + +EXES := false printenv true yes cat whoami +EXES_PATHS := $(addprefix build/,$(EXES)) +TESTS := cat + +command = sh -c '$(1)' + +define EXE_BUILD +build/$(1): $(1)/$(1).rs + $(call command,$(RUSTC) $(RUSTCFLAGS) -o build/$(1) $(1)/$(1).rs) +endef + +define TEST_BUILD +test_$(1): tmp/$(1)_test + $(call command,tmp/$(1)_test) + +tmp/$(1)_test: $(1)/test.rs + $(RUSTC) $(RUSTCFLAGS) -o tmp/$(1)_test $(1)/test.rs +endef + +all: build $(EXES_PATHS) + +test: tmp $(addprefix test_,$(TESTS)) + rm -rf tmp + +clean: + rm -rf build tmp + build: - rm -rf build mkdir build - # run through the shell since make acting up on windows - sh -c 'rustc --out-dir build/ false/false.rs' - sh -c 'rustc --out-dir build/ printenv/printenv.rs' - sh -c 'rustc --out-dir build/ true/true.rs' - sh -c 'rustc --out-dir build/ yes/yes.rs' - sh -c 'rustc --out-dir build/ cat/cat.rs' - sh -c 'rustc --out-dir build/ whoami/whoami.rs' -test: - rm -rf tmp +tmp: mkdir tmp - sh -c 'rustc -o tmp/cat_test cat/test.rs' - sh -c 'tmp/cat_test' - rm -rf tmp -.PHONY: build +$(foreach exe,$(EXES),$(eval $(call EXE_BUILD,$(exe)))) +$(foreach test,$(TESTS),$(eval $(call TEST_BUILD,$(test)))) + +.PHONY: all test clean From 0daed114a7abf5937976bae50679e0a8df2c14a1 Mon Sep 17 00:00:00 2001 From: KokaKiwi Date: Wed, 23 Oct 2013 17:21:23 +0200 Subject: [PATCH 2/2] Just modify variables order in Makefile (more readable) --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0d8533fee..3d83dc911 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,10 @@ RUSTC ?= rustc RUSTCFLAGS := EXES := false printenv true yes cat whoami -EXES_PATHS := $(addprefix build/,$(EXES)) TESTS := cat +EXES_PATHS := $(addprefix build/,$(EXES)) + command = sh -c '$(1)' define EXE_BUILD