diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2018-02-17 19:24:10 -0500 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2018-02-18 17:51:40 -0500 |
| commit | a82d5fe2ef0e4a2bcb15463c35564c603f6e7d9c (patch) | |
| tree | 02c3862532aff57362104420ecbbb6d6e456e873 /Makefile | |
| parent | 9603fda74ca247209f93a742abcf629060e55867 (diff) | |
Refactoring the Makefile
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 67 |
1 files changed, 26 insertions, 41 deletions
@@ -1,3 +1,4 @@ +.DEFAULT_GOAL = build extension = $(patsubst windows,.exe,$(filter windows,$(1))) GO := go PKG_NAME := gomplate @@ -9,17 +10,11 @@ VERSION ?= `git describe --abbrev=0 --tags $(git rev-list --tags --max-count=1) COMMIT_FLAG := -X `go list ./version`.GitCommit=$(COMMIT) VERSION_FLAG := -X `go list ./version`.Version=$(VERSION) -GOOS ?= `go version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\1/'` -GOARCH ?= `go version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\2/'` +GOOS ?= $(shell go version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\1/') +GOARCH ?= $(shell go version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\2/') platforms := linux-amd64 linux-386 linux-arm linux-arm64 darwin-amd64 solaris-amd64 windows-amd64.exe windows-386.exe - -define gocross - GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 \ - $(GO) build \ - -ldflags "-w -s $(COMMIT_FLAG) $(VERSION_FLAG)" \ - -o $(PREFIX)/bin/$(PKG_NAME)_$(1)-$(2)$(call extension,$(1)); -endef +compressed-platforms := linux-amd64-slim linux-arm-slim linux-arm64-slim darwin-amd64-slim windows-amd64-slim.exe define gocross-tool GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 \ @@ -29,11 +24,6 @@ define gocross-tool $(PREFIX)/test/integration/$(3)svc; endef -define compress - upx --lzma $(PREFIX)/bin/$(PKG_NAME)_$(1)-$(2)$(call extension,$(1)) \ - -o $(PREFIX)/bin/$(PKG_NAME)_$(1)-$(2)-slim$(call extension,$(1)) -endef - clean: rm -Rf $(PREFIX)/bin/* rm -f $(PREFIX)/test/integration/gomplate @@ -43,52 +33,45 @@ clean: build-x: $(patsubst %,$(PREFIX)/bin/$(PKG_NAME)_%,$(platforms)) -compress-all: - $(call compress,linux,amd64) - $(call compress,linux,arm) - $(call compress,windows,amd64) +compress-all: $(patsubst %,$(PREFIX)/bin/$(PKG_NAME)_%,$(compressed-platforms)) -compress: build - @upx --lzma $(PREFIX)/bin/$(PKG_NAME)$(call extension,$(GOOS)) \ - -o $(PREFIX)/bin/$(PKG_NAME)-slim$(call extension,$(GOOS)) +$(PREFIX)/bin/$(PKG_NAME)_%-slim: $(PREFIX)/bin/$(PKG_NAME)_% + upx --lzma $< -o $@ -build-release: clean build-x compress-all +$(PREFIX)/bin/$(PKG_NAME)_%-slim.exe: $(PREFIX)/bin/$(PKG_NAME)_%.exe + upx --lzma $< -o $@ -$(PREFIX)/bin/$(PKG_NAME)_%: $(shell find $(PREFIX) -type f -name '*.go' -not -path "$(PREFIX)/test/*") - $(call gocross,$(shell echo $* | sed 's/\([^-]*\)-\([^.]*\).*/\1/'),$(shell echo $* | sed 's/\([^-]*\)-\([^.]*\).*/\2/')) - -$(PREFIX)/bin/mirror_%: $(shell find $(PREFIX)/test/integration/mirrorsvc -type f -name '*.go') - $(call gocross-tool,$(shell echo $* | sed 's/\([^-]*\)-\([^.]*\).*/\1/'),$(shell echo $* | sed 's/\([^-]*\)-\([^.]*\).*/\2/'),mirror) +compress: $(PREFIX)/bin/$(PKG_NAME)_$(GOOS)-$(GOARCH)-slim$(call extension,$(GOOS)) + cp $< $(PREFIX)/bin/$(PKG_NAME)-slim$(call extension,$(GOOS)) -$(PREFIX)/bin/meta_%: $(shell find $(PREFIX)/test/integration/metasvc -type f -name '*.go') - $(call gocross-tool,$(shell echo $* | sed 's/\([^-]*\)-\([^.]*\).*/\1/'),$(shell echo $* | sed 's/\([^-]*\)-\([^.]*\).*/\2/'),meta) - -$(PREFIX)/bin/aws_%: $(shell find $(PREFIX)/test/integration/awssvc -type f -name '*.go') - $(call gocross-tool,$(shell echo $* | sed 's/\([^-]*\)-\([^.]*\).*/\1/'),$(shell echo $* | sed 's/\([^-]*\)-\([^.]*\).*/\2/'),aws) +$(PREFIX)/bin/$(PKG_NAME)_%: $(shell find $(PREFIX) -type f -name '*.go' -not -path "$(PREFIX)/test/*") + GOOS=$(shell echo $* | cut -f1 -d-) GOARCH=$(shell echo $* | cut -f2 -d- | cut -f1 -d.) CGO_ENABLED=0 \ + $(GO) build \ + -ldflags "-w -s $(COMMIT_FLAG) $(VERSION_FLAG)" \ + -o $@ -$(PREFIX)/bin/$(PKG_NAME)$(call extension,$(GOOS)): $(shell find $(PREFIX) -type f -name '*.go' -not -path "$(PREFIX)/test/*") - CGO_ENABLED=0 \ - $(GO) build -ldflags "-w -s $(COMMIT_FLAG) $(VERSION_FLAG)" -o $@ +$(PREFIX)/bin/$(PKG_NAME)$(call extension,$(GOOS)): $(PREFIX)/bin/$(PKG_NAME)_$(GOOS)-$(GOARCH)$(call extension,$(GOOS)) + cp $< $@ -$(PREFIX)/bin/mirror$(call extension,$(GOOS)): $(shell find $(PREFIX)/test/integration/mirrorsvc -type f -name '*.go') +$(PREFIX)/test/integration/mirror$(call extension,$(GOOS)): $(shell find $(PREFIX)/test/integration/mirrorsvc -type f -name '*.go') CGO_ENABLED=0 \ $(GO) build -ldflags "-w -s $(COMMIT_FLAG) $(VERSION_FLAG)" -o $@ $(PREFIX)/test/integration/mirrorsvc -$(PREFIX)/bin/meta$(call extension,$(GOOS)): $(shell find $(PREFIX)/test/integration/metasvc -type f -name '*.go') +$(PREFIX)/test/integration/meta$(call extension,$(GOOS)): $(shell find $(PREFIX)/test/integration/metasvc -type f -name '*.go') CGO_ENABLED=0 \ $(GO) build -ldflags "-w -s $(COMMIT_FLAG) $(VERSION_FLAG)" -o $@ $(PREFIX)/test/integration/metasvc -$(PREFIX)/bin/aws$(call extension,$(GOOS)): $(shell find $(PREFIX)/test/integration/awssvc -type f -name '*.go') +$(PREFIX)/test/integration/aws$(call extension,$(GOOS)): $(shell find $(PREFIX)/test/integration/awssvc -type f -name '*.go') CGO_ENABLED=0 \ $(GO) build -ldflags "-w -s $(COMMIT_FLAG) $(VERSION_FLAG)" -o $@ $(PREFIX)/test/integration/awssvc build: $(PREFIX)/bin/$(PKG_NAME)$(call extension,$(GOOS)) -build-mirror: $(PREFIX)/bin/mirror$(call extension,$(GOOS)) +build-mirror: $(PREFIX)/test/integration/mirror$(call extension,$(GOOS)) -build-meta: $(PREFIX)/bin/meta$(call extension,$(GOOS)) +build-meta: $(PREFIX)/test/integration/meta$(call extension,$(GOOS)) -build-aws: $(PREFIX)/bin/aws$(call extension,$(GOOS)) +build-aws: $(PREFIX)/test/integration/aws$(call extension,$(GOOS)) test: $(GO) test -v -race ./... @@ -130,3 +113,5 @@ lint: endif .PHONY: gen-changelog clean test build-x compress-all build-release build build-integration-image test-integration-docker gen-docs lint +.DELETE_ON_ERROR: +.SECONDARY: |
