-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
105 lines (86 loc) · 2.61 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
# Metadata about this makefile and position
MKFILE_PATH := $(lastword $(MAKEFILE_LIST))
CURRENT_DIR := $(patsubst %/,%,$(dir $(realpath $(MKFILE_PATH))))
# List all our actual files, excluding vendor
GOFILES ?= $(shell go list $(TEST) | grep -v /vendor/)
# Tags specific for building
GOTAGS ?=
TESTARGS ?=
# Number of procs to use
GOMAXPROCS ?= 4
# Get the project metadata
GOVERSION := 1.13.1
PROJECT := github.com/Shuttl-Tech/drone-autoscaler
NAME := $(notdir $(PROJECT))
GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
VERSION := $(shell awk -F\" '/Version/ { print $$2; exit }' "${CURRENT_DIR}/cmd/main.go")
# Current system information
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
# Default os-arch combination to build
XC_OS ?= linux darwin
XC_ARCH ?= amd64
# GPG Signing key (blank by default, means no GPG signing)
#GPG_KEY ?=
# List of ldflags
LD_FLAGS ?= \
-s \
-w \
-extldflags \"-static\"
# List of tests to run
TEST ?= ./...
# Create a cross-compile target for every os-arch pairing. This will generate
# a make target for each os/arch like "make linux/amd64" as well as generate a
# meta target (build) for compiling everything.
define make-xc-target
$1/$2:
@printf "%s%20s %s\n" "-->" "${1}/${2}:" "${PROJECT}"
@docker run \
--interactive \
--rm \
--dns="8.8.8.8" \
--volume="${CURRENT_DIR}:/go/src/${PROJECT}" \
--workdir="/go/src/${PROJECT}" \
"golang:${GOVERSION}" \
env \
CGO_ENABLED="0" \
GOOS="${1}" \
GOARCH="${2}" \
go build \
-a \
-o="_build/${NAME}${3}_${1}_${2}" \
-ldflags "${LD_FLAGS}" \
-tags "${GOTAGS}" \
"${PROJECT}/cmd"
.PHONY: $1/$2
$1:: $1/$2
.PHONY: $1
build:: $1/$2
.PHONY: build
endef
$(foreach goarch,$(XC_ARCH),$(foreach goos,$(XC_OS),$(eval $(call make-xc-target,$(goos),$(goarch),$(if $(findstring windows,$(goos)),.exe,)))))
dist:
@$(MAKE) -f "${MKFILE_PATH}" _cleanup
@$(MAKE) -f "${MKFILE_PATH}" -j4 build
@$(MAKE) -f "${MKFILE_PATH}" _checksum
.PHONY: dist
# _cleanup removes any previous binaries
_cleanup:
@rm -rf "${CURRENT_DIR}/_build/"
# _checksum produces the checksums for the binaries in _build
_checksum:
@cd "${CURRENT_DIR}/_build" && \
shasum --algorithm 256 * > ${CURRENT_DIR}/_build/${NAME}_v${VERSION}_SHA256SUMS && \
cd - &>/dev/null
.PHONY: _checksum
# test runs the test suite with caching disabled
test: fmtcheck
@echo "==> Testing ${NAME}"
@go test -count=1 -v -timeout=300s -tags="${GOTAGS}" ${GOFILES} ${TESTARGS}
.PHONY: test
fmt:
@echo "==> Fixing source code with gofmt..."
gofmt -s -w ./cmd ./cluster ./config ./engine
fmtcheck:
@sh -c "'$(CURDIR)/scripts/fmtcheck.sh'"
.PHONY: fmtcheck