-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
81 lines (69 loc) · 1.9 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
define VERSION_CMD =
eval ' \
define=""; \
version=`git describe --abbrev=0 --tags | tr -d "[a-z]"` ; \
[ -z "$$version" ] && version="unknown"; \
commit=`git rev-parse --verify HEAD`; \
tagname=`git show-ref --tags | grep $$commit`; \
if [ -n "$$tagname" ]; then \
define=`echo $$tagname | awk -F "/" "{print \\$$NF}" | tr -d "[a-z]"`; \
else \
define=`printf "$$version-%.12s" $$commit`; \
fi; \
tainted=`git ls-files -m | wc -l` ; \
if [ "$$tainted" -gt 0 ]; then \
define="$${define}-tainted"; \
fi; \
echo "$$define" \
'
endef
EXTRA_BUILD_TARGET=
VERSION?=$(shell $(VERSION_CMD))
GO?=go
BUILD_ID:=$(shell echo 0x$$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \n'))
VERBOSE_FLAGS?=
VERBOSE?=false
ifeq ($(VERBOSE), true)
VERBOSE_FLAGS+=-v
endif
GO_MONOLITH_GITHUB:=github.com/sergeyglazyrindev/go-monolith
GO_MONOLITH_GITHUB_VERSION:=$(GO_MONOLITH_GITHUB)/version.Version=${VERSION}
BUILD_TAGS?=$(TAGS)
include .mk/check.mk
include .mk/dist.mk
include .mk/proto.mk
include .mk/static.mk
include .mk/tests.mk
define GOCOMPILE
CGO_CFLAGS_ALLOW='.*' CGO_LDFLAGS_ALLOW='.*' $(GO) $1 \
-ldflags="${LDFLAGS} -B $(BUILD_ID) -X $(GO_MONOLITH_GITHUB_VERSION)" \
${GOFLAGS} -tags="${BUILD_TAGS}" ${VERBOSE_FLAGS} -o /go-monolith/go-monolith \
cmd/go-monolith/main.go
endef
.PHONY: .build
.build:
$(call GOCOMPILE,build)
.PHONY: build
build: gopath moddownload .build
.PHONY: .install
.install:
$(call GOCOMPILE,install)
.PHONY: gomonolith.clean
gomonolith.clean:
go clean -i $(GOMONOLITH_GITHUB)
.PHONY: moddownload
moddownload:
ifneq ($(OFFLINE), true)
go mod download
endif
.PHONY: genlocalfiles
genlocalfiles: $(EXTRA_BUILD_TARGET)
# .proto
.PHONY: touchlocalfiles
touchlocalfiles: .proto.touch
.PHONY: clean
clean: gomonolith.clean .proto.clean \
go clean -i >/dev/null 2>&1 || true
.PHONY: docker
docker:
docker build . -t $(DOCKER_IMAGE):$(DOCKER_TAG)