This repository has been archived by the owner on Jan 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
143 lines (114 loc) · 3.34 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#
# Makefile
#
# The kickoff point for all project management commands.
#
GOCC := go
# Program version
VERSION := $(shell git describe --always --tags)
# Binary name for bintray
BIN_NAME=templr
# Project owner for bintray
OWNER=gesquive
# Project name for bintray
PROJECT_NAME=templr
# Project url used for builds
# examples: github.com, bitbucket.org
REPO_HOST_URL=github.com
# Grab the current commit
GIT_COMMIT=$(shell git rev-parse HEAD)
# Check if there are uncommited changes
GIT_DIRTY=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true)
# Use a local vendor directory for any dependencies; comment this out to
# use the global GOPATH instead
# GOPATH=$(PWD)
INSTALL_PATH=$(GOPATH)/src/${REPO_HOST_URL}/${OWNER}/${PROJECT_NAME}
LOCAL_BIN=bin
GOTEMP:=$(shell mktemp -d)
export PATH := ${LOCAL_BIN}:${PATH}
default: test build
.PHONY: help
help:
@echo 'Management commands for $(PROJECT_NAME):'
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: build
build: gox ## Compile the project
@echo "building ${OWNER} ${BIN_NAME} ${VERSION}"
@echo "GOPATH=${GOPATH}"
gox -verbose \
-ldflags "-X main.version=${VERSION} -X main.dirty=${GIT_DIRTY}" \
-os="linux" \
-arch="amd64" \
-output="${BIN_NAME}" .
.PHONY: install
install: build ## Install the binary
install -d ${DESTDIR}/usr/local/bin/
install -m 755 ./${BIN_NAME} ${DESTDIR}/usr/local/bin/${BIN_NAME}
.PHONY: deps
deps: glide ## Download project dependencies
glide install
.PHONY: test
test: ## Run golang tests
${GOCC} test ./...
.PHONY: bench
bench: ## Run golang benchmarks
${GOCC} test -benchmem -bench=. ./...
.PHONY: clean
clean: ## Clean the directory tree
${GOCC} clean
rm -f ./${BIN_NAME}.test
rm -f ./${BIN_NAME}
rm -rf ./${LOCAL_BIN}
rm -rf ./dist
.PHONY: build-dist
build-dist: gox
gox -verbose \
-ldflags "-X main.version=${VERSION} -X main.dirty=${GIT_DIRTY}" \
-os="linux" \
-arch="amd64 386" \
-output="dist/{{.OS}}-{{.Arch}}/{{.Dir}}" .
.PHONY: package-dist
package-dist: gop
gop --delete \
--os="linux" \
--arch="amd64 386" \
--archive="tar.gz" \
--files="LICENSE README.md pkg" \
--input="dist/{{.OS}}-{{.Arch}}/{{.Dir}}" \
--output="dist/{{.Dir}}-${VERSION}-{{.OS}}-{{.Arch}}.{{.Archive}}" .
.PHONY: dist
dist: build-dist package-dist ## Cross compile and package the full distribution
.PHONY: fmt
fmt: ## Reformat the source tree with gofmt
find . -name '*.go' -not -path './.vendor/*' -exec gofmt -w=true {} ';'
.PHONY: link
link: $(INSTALL_PATH) ## Symlink this project into the GOPATH
$(INSTALL_PATH):
@mkdir -p `dirname $(INSTALL_PATH)`
@ln -s $(PWD) $(INSTALL_PATH) >/dev/null 2>&1
${LOCAL_BIN}:
@mkdir -p ${LOCAL_BIN}
.PHONY: glide
glide: bin/glide
bin/glide: ${LOCAL_BIN}
@echo "Installing glide"
@export GOPATH=${GOTEMP} && ${GOCC} get -u github.com/Masterminds/glide
@cp ${GOTEMP}/bin/glide ${LOCAL_BIN}
@glide --version
@rm -rf ${GOTEMP}
.PHONY: gox
gox: bin/gox
bin/gox: ${LOCAL_BIN}
@echo "Installing gox"
@GOPATH=${GOTEMP} ${GOCC} get -u github.com/mitchellh/gox
@cp ${GOTEMP}/bin/gox ${LOCAL_BIN}/gox
@rm -rf ${GOTEMP}
.PHONY: gop
gop: bin/gop
bin/gop: ${LOCAL_BIN}
@echo "Installing gop"
@export GOPATH=${GOTEMP} && ${GOCC} get -u github.com/gesquive/gop
@cp ${GOTEMP}/bin/gop ${LOCAL_BIN}
@gop --version
@rm -rf ${GOTEMP}