-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
65 lines (51 loc) · 1.16 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
SHELL = /bin/bash
.PHONY: all build clean coverage lint test
.DEFAULT_GOAL := lint
# The name of the binary to build
#
ifndef pkg
pkg := $(shell pwd | awk -F/ '{print $$NF}')
endif
# Set the target OS
# Ex: windows, darwin, linux
#
ifndef target_os
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
target_os = linux
endif
ifeq ($(UNAME_S),Darwin)
target_os = darwin
endif
UNAME_P := $(shell uname -p)
ifeq ($(UNAME_P),x86_64)
target_arch = amd64
endif
endif
ifeq ($(target_os),windows)
target_ext = .exe
endif
ifndef target_arch
target_arch = amd64
endif
## Lint, build
all: pretty build
## Build
build: clean
@GOOS=$(target_os) GOARCH=$(target_arch) go build -mod vendor -o ./bin/$(pkg)-$(target_os)
linux:
@GOOS=linux GOARCH=$(target_arch) go build -mod vendor -o ./bin/$(pkg)-linux
windows:
@GOOS=windows GOARCH=$(target_arch) go build -mod vendor -o ./bin/$(pkg)-windows.exe
## Clean binaries
clean:
@rm -rf ./bin
## Lint
lint:
@go fmt ./...
@golangci-lint run
## Some tests depend on built binary, make sure you've built it beforehand.
test:
@go test -v -mod vendor -race ./...
coverage:
@go test -mod vendor -coverprofile=coverage.out ./...