-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
83 lines (66 loc) · 1.95 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
CURRENT_DIR := $(shell pwd)
DIST_DIR := $(CURRENT_DIR)/dist
CLI_NAME := mta
BIN_NAME := mta
CGO_FLAG := 0
HOST_OS := $(shell go env GOOS)
HOST_ARCH := $(shell go env GOARCH)
TARGET_ARCH ?= linux/amd64
TARGET_OS := $(shell echo $(TARGET_ARCH) | cut -d'/' -f1)
TARGET_ARCH_SHORT := $(shell echo $(TARGET_ARCH) | cut -d'/' -f2)
VERSION := $(shell cat ${CURRENT_DIR}/VERSION)
GOPATH ?= $(shell if test -x `which go`; then go env GOPATH; else echo "$(HOME)/go"; fi)
GOCACHE ?= $(HOME)/.cache/go-build
ARGOCD_LINT_GOGC ?= 20
default: build
$(DIST_DIR):
mkdir -p $(DIST_DIR)
.PHONY: cli
cli-local:
GOOS=$(HOST_OS) GOARCH=$(HOST_ARCH) CGO_ENABLED=$(CGO_FLAG) go build -o $(DIST_DIR)/$(CLI_NAME) .
.PHONY: build
build: $(DIST_DIR)
GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH_SHORT) CGO_ENABLED=$(CGO_FLAG) go build -o $(DIST_DIR)/$(CLI_NAME) .
.PHONY: run
run:
go run main.go
.PHONY: lint
lint:
golangci-lint --version
# NOTE: If you get an "Out of Memory" error, try reducing GOGC value
GOGC=$(ARGOCD_LINT_GOGC) GOMAXPROCS=2 golangci-lint run --fix --verbose
.PHONY: test
test:
go test -v ./...
.PHONY: fmt
fmt:
go fmt ./...
.PHONY: tidy
tidy:
go mod tidy
.PHONY: deps
deps:
go list -m -u all
.PHONY: clean
clean:
rm -rf $(DIST_DIR)
.PHONY: release
release:
@echo "Building release version $(VERSION)"
GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH_SHORT) CGO_ENABLED=$(CGO_FLAG) go build -o $(DIST_DIR)/$(CLI_NAME)-$(VERSION) .
.PHONY: help
help:
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@echo " build Compile the project"
@echo " cli-local Build for local system"
@echo " run Run the Go application"
@echo " lint Run golangci-lint"
@echo " test Run unit tests"
@echo " fmt Format the code"
@echo " tidy Clean up go.mod dependencies"
@echo " deps Check for outdated dependencies"
@echo " clean Remove build files"
@echo " release Build a release version"
@echo " help Show this help message"