-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
143 lines (121 loc) · 4.33 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
# @author Hans-Peter Schadler <hps@abyle.org>
# Initial concept for Makefile stolen from https://github.com/yyyar/gobetween/tree/master/dist (thanks!)
#
.PHONY: update clean build build-all test authors dist vendor build-container-latest \
build-container-tagged build-container-gitcommit release-container release-container-gitcommit
NAME := redseligg
BINARIES := botterinstance bottercontrol botter
VERSION := $(shell cat VERSION)
COMPTIME := $(shell date -Is)
LDFLAGS := -X main.version=${VERSION} -X main.compTime=${COMPTIME}
SRCPATH := .
DOCKERBASETAG := torlenor/redseligg
CURRENTGITCOMMIT := $(shell git log -1 --format=%h)
CURRENTGITUNTRACKED := $(shell git diff-index --quiet HEAD -- || echo "_untracked")
ENVFLAGS :=
default: build
clean:
@echo Cleaning up...
@rm bin/* -rf
@rm dist/* -rf
@echo Done.
build:
@echo Building...
@mkdir -p ./bin
@for cmd in ${BINARIES}; \
do \
echo "\t$${cmd}" ;\
${ENVFLAGS} go build -o ./bin/$${cmd} -ldflags '${LDFLAGS}' ./cmd/$${cmd}/ ;\
done
@echo Done.
race:
@echo Building...
mkdir -p ./bin
@for cmd in ${BINARIES}; \
do \
echo "\t$${cmd}" ;\
${ENVFLAGS} go build -o ./bin/$${cmd} -ldflags '${LDFLAGS}' -race ./cmd/$${cmd}/ ;\
done
@echo Done.
build-static:
@echo Building...
mkdir -p ./bin
@for cmd in ${BINARIES}; \
do \
echo "\t$${cmd}" ;\
CGO_ENABLED=1 ${ENVFLAGS} go build -o ./bin/$${cmd} -ldflags '-s -w --extldflags "-static" ${LDFLAGS}' ./cmd/$${cmd}/ ;\
done
@echo Done.
test:
@echo "Running unit tests"
@${ENVFLAGS} go test -covermode=count -coverprofile=coverage.out ./...
test-verbose:
@echo "Running unit tests"
@${ENVFLAGS} go test -v -covermode=count -coverprofile=coverage.out ./...
install: build
install -d ${DESTDIR}/usr/local/bin/
@for cmd in ${BINARIES}; \
do \
echo "\t$${cmd}" ;\
install -m 755 ./bin/$${cmd} ${DESTDIR}/usr/local/bin/$${cmd} ;\
done
uninstall:
@for cmd in ${BINARIES}; \
do \
echo "\t$${cmd}" ;\
rm -f ${DESTDIR}/usr/local/bin/$${cmd} ;\
done
deps:
${ENVFLAGS} go get -v ./...
clean-dist:
rm -rf ./dist/${VERSION}
dist:
@# For linux 386 when building on linux amd64 you'll need 'libc6-dev-i386' package
@echo Building dist
# we need this for Windows
GOOS=windows GOARCH=386 ${ENVFLAGS} go get -v github.com/konsorten/go-windows-terminal-sequences
@# os arch cgo ext
@for arch in "linux 386 1 " "linux amd64 1 " \
"windows 386 0 .exe " "windows amd64 0 .exe " \
"darwin 386 0 " "darwin amd64 0 "; \
do \
set -- $$arch ; \
echo "******************* $$1_$$2 ********************" ;\
distpath="./dist/${VERSION}/$$1_$$2" ;\
mkdir -p $$distpath ; \
for cmd in ${BINARIES}; \
do \
echo "\t$${cmd}" ;\
CGO_ENABLED=$$3 GOOS=$$1 GOARCH=$$2 ${ENVFLAGS} go build -o $$distpath/$${cmd}$$4 -ldflags '-s -w --extldflags "-static" ${LDFLAGS}' ./cmd/$${cmd}/ ;\
done ;\
cp "README.md" "LICENSE" "CHANGELOG.md" "AUTHORS" $$distpath ;\
cp "cfg/bots.toml" $$distpath/bots.toml ;\
if [ "$$1" = "linux" ]; then \
cd $$distpath && tar -zcvf ../../${NAME}_${VERSION}_$$1_$$2.tar.gz * && cd - ;\
else \
cd $$distpath && zip -r ../../${NAME}_${VERSION}_$$1_$$2.zip . && cd - ;\
fi \
done
build-container-latest: build-static
@echo Building docker image ${DOCKERBASETAG}:latest
docker build -t ${DOCKERBASETAG}:latest .
build-container-tagged: build-static
@echo Building docker image ${DOCKERBASETAG}:${VERSION}
docker build -t ${DOCKERBASETAG}:${VERSION} .
build-container-gitcommit: build-static
@echo Building docker image ${DOCKERBASETAG}:${VERSION}-${CURRENTGITCOMMIT}${CURRENTGITUNTRACKED}
docker build -t ${DOCKERBASETAG}:${VERSION}-${CURRENTGITCOMMIT}${CURRENTGITUNTRACKED} .
release-container: build-container-tagged
@echo Pushing docker image ${DOCKERBASETAG}:${VERSION}
docker tag ${DOCKERBASETAG}:${VERSION} ${DOCKERBASETAG}:latest
docker push ${DOCKERBASETAG}:${VERSION}
release-container-tagged: build-container-tagged
@echo Pushing docker image ${DOCKERBASETAG}:${VERSION}
docker push ${DOCKERBASETAG}:${VERSION}
docker tag ${DOCKERBASETAG}:${VERSION} ${DOCKERBASETAG}:latest
docker push ${DOCKERBASETAG}:latest
release-container-gitcommit: build-container-gitcommit
@echo Pushing docker image ${DOCKERBASETAG}:${VERSION}-${CURRENTGITCOMMIT}${CURRENTGITUNTRACKED}
docker push ${DOCKERBASETAG}:${VERSION}-${CURRENTGITCOMMIT}${CURRENTGITUNTRACKED}