forked from moncho/dry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
75 lines (59 loc) · 2.57 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Set an output prefix, which is the local directory if not specified
PREFIX?=$(shell pwd)
# Populate version variables
# Add to compile time flags
PKG := github.com/moncho/dry
VERSION := $(shell cat APPVERSION)
GITCOMMIT := $(shell git rev-parse --short HEAD)
GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no)
OS := $(shell uname)
ifneq ($(GITUNTRACKEDCHANGES),)
GITCOMMIT := $(GITCOMMIT)-dirty
endif
CTIMEVAR=-X $(PKG)/version.GITCOMMIT=$(GITCOMMIT) -X $(PKG)/version.VERSION=$(VERSION)
GO_LDFLAGS=-ldflags "-w $(CTIMEVAR)"
GO_LDFLAGS_STATIC=-ldflags "-w $(CTIMEVAR) -extldflags -static"
GOOSES = darwin freebsd linux windows
GOARCHS = amd64 386 arm
print-%: ; @echo $*=$($*)
run: ## Runs dry
vgo run ./main.go
vendor: ## Runs dep ensure
dep ensure
# TODO remove once https://github.com/golang/dep/issues/433 is resolved
# Workaround for OSX sed behaving differently
case "${OS}" in \
Darwin) find vendor -type f -name "*.go" -print0 | xargs -0 sed -i '' 's/Sirupsen\/logrus/sirupsen\/logrus/g' ;;\
*) find vendor -type f -name "*.go" -print0 | xargs -0 sed -i 's/Sirupsen\/logrus/sirupsen\/logrus/g' ;;\
esac ;\
touch $@
build: ## Builds dry
vgo build .
install: ## Installs dry
vgo install $(PKG)
test: ## Run tests
vgo test $(shell go list ./... | grep -v /vendor/ | grep -v mock)
benchmark: ## Run benchmarks
vgo test -bench $(shell go list ./... | grep -v /vendor/ | grep -v mock)
define buildpretty
$(if $(and $(filter-out darwin_arm,$(1)_$(2)), $(filter-out windows_arm,$(1)_$(2)), $(filter-out windows_386,$(1)_$(2))), \
mkdir -p ${PREFIX}/cross/$(1)/$(2);
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build -o ${PREFIX}/cross/$(1)/$(2)/dry -a ${GO_LDFLAGS_STATIC} .;
)
endef
cross: *.go VERSION ## Cross compiles dry
$(foreach GOARCH,$(GOARCHS),$(foreach GOOS,$(GOOSES),$(call buildpretty,$(GOOS),$(GOARCH))))
define buildrelease
$(if $(and $(filter-out darwin_arm,$(1)_$(2)), $(filter-out windows_arm,$(1)_$(2)), $(filter-out windows_386,$(1)_$(2))), \
mkdir -p ${PREFIX}/cross/$(1)/$(2);
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build -o ${PREFIX}/cross/dry-$(1)-$(2) -a ${GO_LDFLAGS_STATIC} .;
)
endef
release: *.go VERSION ## Prepares a dry release
$(foreach GOARCH,$(GOARCHS),$(foreach GOOS,$(GOOSES),$(call buildrelease,$(GOOS),$(GOARCH))))
clean:
rm -rf ${PREFIX}/cross
.PHONY: help vendor
# Magic as explained here: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help: ## Shows help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'