-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
76 lines (63 loc) · 1.76 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
GOPATH?=$(HOME)/go
FIRST_GOPATH:=$(firstword $(subst :, ,$(GOPATH)))
# Build available information.
GIT_HASH:=$(shell git log --format="%h" -n 1 2> /dev/null)
GIT_BRANCH:=$(shell git branch 2> /dev/null | grep '*' | cut -f2 -d' ')
APP_VERSION:="$(GIT_BRANCH)-$(GIT_HASH)"
# LAUNCHRPKG is used to set launchr version.
LAUNCHRPKG:=github.com/launchrctl/launchr
DEBUG?=0
ifeq ($(DEBUG), 1)
LDFLAGS_EXTRA=
BUILD_OPTS=-gcflags "all=-N -l"
else
LDFLAGS_EXTRA=-s -w
BUILD_OPTS=-trimpath
endif
BUILD_ENVPARMS:=CGO_ENABLED=0
GOBIN:=$(FIRST_GOPATH)/bin
LOCAL_BIN:=$(CURDIR)/bin
# Linter config.
GOLANGCI_BIN:=$(LOCAL_BIN)/golangci-lint
GOLANGCI_TAG:=1.61.0
.PHONY: all
all: deps test build
# Install go dependencies
.PHONY: deps
deps:
$(info Installing go dependencies...)
go mod download
# Run all tests
.PHONY: test
test:
$(info Running tests...)
go test ./...
# Build launchr
.PHONY: build
build:
$(info Building launchr...)
# Application related information available on build time.
$(eval LDFLAGS:=-X '$(LAUNCHRPKG).name=launchr' -X '$(LAUNCHRPKG).version=$(APP_VERSION)' $(LDFLAGS_EXTRA))
$(eval BIN?=$(LOCAL_BIN)/launchr)
go generate ./...
$(BUILD_ENVPARMS) go build -ldflags "$(LDFLAGS)" $(BUILD_OPTS) -o $(BIN) ./cmd/launchr
# Install launchr
.PHONY: install
install: all
install:
$(info Installing launchr to GOPATH...)
cp $(LOCAL_BIN)/launchr $(GOBIN)/launchr
# Install and run linters
.PHONY: lint
lint: .install-lint .lint
# Install golangci-lint binary
.PHONY: .install-lint
.install-lint:
ifeq ($(wildcard $(GOLANGCI_BIN)),)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCAL_BIN) v$(GOLANGCI_TAG)
endif
# Runs linters
.PHONY: .lint
.lint:
$(info Running lint...)
$(GOLANGCI_BIN) run --fix ./...