From 160abf9684ceb2d80c40139a982915fa007e58df Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 15 Sep 2016 21:56:16 -0700 Subject: [PATCH 1/2] Makefile: Add a pattern rule for oci-* commands Make it easy to (re)build a single command without building all of them. Using main.go as the only prerequisite cuts some corners, but prerequisites for this are hard ;). With this commit, you can touch main.go to force a rebuild. If that ends up being too awkward, we can make these .PHONY targets. Signed-off-by: W. Trevor King --- Makefile | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 73116f7..b67cf09 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,10 @@ export GO15VENDOREXPERIMENT COMMIT=$(shell git rev-parse HEAD 2> /dev/null || true) EPOCH_TEST_COMMIT ?= v0.2.0 +TOOLS := \ + oci-create-runtime-bundle \ + oci-image-validate \ + oci-unpack default: help @@ -20,10 +24,10 @@ check-license: @echo "checking license headers" @./.tool/check-license -tools: - go build -ldflags "-X main.gitCommit=${COMMIT}" ./cmd/oci-create-runtime-bundle - go build -ldflags "-X main.gitCommit=${COMMIT}" ./cmd/oci-unpack - go build -ldflags "-X main.gitCommit=${COMMIT}" ./cmd/oci-image-validate +tools: $(TOOLS) + +oci-%: cmd/oci-%/main.go + go build -ldflags "-X main.gitCommit=${COMMIT}" ./cmd/$@ lint: @echo "checking lint" @@ -69,10 +73,7 @@ install.tools: .install.gitvalidation .install.glide .install.glide-vc .install. gometalinter --install --update clean: - rm -rf *~ $(OUTPUT_DIRNAME) - rm -f oci-create-runtime-bundle - rm -f oci-unpack - rm -f oci-image-validate + rm -rf *~ $(OUTPUT_DIRNAME) $(TOOLS) .PHONY: \ tools \ From 2d06368186ec4ba216c8afbe6ec59b8d9ad88981 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 22 Sep 2016 10:10:15 -0700 Subject: [PATCH 2/2] Makefile: Always rebuild oci-* tools The previous commit only rebuilt them when the associated main.go was newer, which avoided some unnecessary rebuilds. Unfortunately, it also avoids rebuilding when another Go dependency changed, which could bite users that expected 'make tools' to give them fresh copies of the tools even if they only touched a dependency package. I'm fine either way, but Antonio prefers always rebuilding [1], so this commit adds it. I've switched the old pattern rule to a static pattern rule [2], because Make was treating the non-static pattern rules as implicit rules and .PHONY causes implicit rules to be skipped [3]. [1]: https://github.com/opencontainers/image-tools/pull/28#issuecomment-248958814 [2]: https://www.gnu.org/software/make/manual/html_node/Static-Usage.html [3]: https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html Signed-off-by: W. Trevor King --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b67cf09..f0f35f7 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ check-license: tools: $(TOOLS) -oci-%: cmd/oci-%/main.go +$(TOOLS): oci-%: go build -ldflags "-X main.gitCommit=${COMMIT}" ./cmd/$@ lint: @@ -77,6 +77,7 @@ clean: .PHONY: \ tools \ + $(TOOLS) \ check-license \ clean \ lint \