-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Makefile
73 lines (53 loc) · 2.17 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
NAME=cty
# Set the build dir, where built cross-compiled binaries will be output
BUILDDIR := bin
# VERSION defines the project version for the bundle.
VERSION ?= 0.0.1
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# List the GOOS and GOARCH to build
GO_LDFLAGS_STATIC="-s -w $(CTIMEVAR) -extldflags -static"
.DEFAULT_GOAL := help
##@ Build
build: ## Builds a single binary given the current OS
go build -o $(NAME) main.go
binaries: ## Builds binaries for all supported platforms, linux, darwin
CGO_ENABLED=0 gox \
-osarch="linux/amd64 linux/arm darwin/amd64" \
-ldflags=${GO_LDFLAGS_STATIC} \
-output="$(BUILDDIR)/{{.OS}}/{{.Arch}}/$(NAME)" \
-tags="netgo" \
./
bootstrap: ## Installs necessary third party components
go get github.com/mitchellh/gox
##@ Testing
test: ## Runs all tests
go test -count=1 ./...
clean: ## Runs go clean
go clean -i
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
GOLANGCI_LINT_VERSION ?= v1.60.1
golangci-lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT): $(LOCALBIN)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_LINT_VERSION)
lint: golangci-lint ## Run golangci-lint.
$(GOLANGCI_LINT) run
##@ Utilities
help: ## Display this help. Thanks to https://www.thapaliya.com/en/writings/well-documented-makefiles/
ifeq ($(OS),Windows_NT)
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make <target>\n"} /^[a-zA-Z_-]+:.*?##/ { printf " %-40s %s\n", $$1, $$2 } /^##@/ { printf "\n%s\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
else
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-40s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
endif