-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
88 lines (67 loc) · 1.93 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
NAME := wpdump
REVISION := $(shell git rev-parse --short HEAD)
##
# options
##
GOARCH := amd64
LDFLAGS := -X 'main.Name=$(NAME)' \
-X 'main.Revision=$(REVISION)'
ifeq ($(DEBUG), 1)
BUILD_OPTIONS := -gcflags=all="-N -l" -tags DEBUG -ldflags="$(LDFLAGS)"
BUILD_MODE := debug
else
BUILD_OPTIONS := -ldflags="-s -w $(LDFLAGS)"
BUILD_MODE := release
endif
DOCKER_GO := docker run -it -v "$(PWD):/go" -e GOPATH= -e GOOS=$$GOOS -e GOARCH=$$GOARCH golang:latest go
GO_SRCS := $(shell find . -type f -name '*.go')
##
# build
##
all: linux darwin windows
linux: target/$(BUILD_MODE)/$(NAME)-linux-$(GOARCH)
darwin: target/$(BUILD_MODE)/$(NAME)-darwin-$(GOARCH)
windows: target/$(BUILD_MODE)/$(NAME)-windows-$(GOARCH).exe
##
# artifact
##
target/$(BUILD_MODE)/$(NAME)-linux-$(GOARCH): $(GO_SRCS)
GOOS=linux; \
GOARCH=$(GOARCH); \
$(DOCKER_GO) build $(BUILD_OPTIONS) -o target/$(BUILD_MODE)/$(NAME)-linux-$(GOARCH)
target/$(BUILD_MODE)/$(NAME)-darwin-$(GOARCH): $(GO_SRCS)
GOOS=darwin; \
GOARCH=$(GOARCH); \
$(DOCKER_GO) build $(BUILD_OPTIONS) -o target/$(BUILD_MODE)/$(NAME)-darwin-$(GOARCH)
target/$(BUILD_MODE)/$(NAME)-windows-$(GOARCH).exe: $(GO_SRCS)
GOOS=windows; \
GOARCH=$(GOARCH); \
$(DOCKER_GO) build $(BUILD_OPTIONS) -o target/$(BUILD_MODE)/$(NAME)-windows-$(GOARCH).exe
clean:
-rm -rf target/*
##
# check
##
check:
@echo [tool fix]
@go tool fix -diff .
@echo
@echo [fmt]
@go fmt ./...
@echo
@echo [gofumpt]
@go install mvdan.cc/gofumpt@latest
@gofumpt -l -w .
@echo
@echo [golangci-lint]
@docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:v1.45.0 golangci-lint run --enable-all --disable 'wsl,scopelint,golint,interfacer,lll,varnamelen,ireturn,cyclop,maligned,exhaustivestruct,paralleltest,wrapcheck,gosec,gomnd,forbidigo,testpackage,gochecknoglobals'
@echo
@echo [mod tidy]
@go mod tidy
@echo
@echo [mod verify]
@go mod verify
@echo
@echo [test]
@go test ./...
.PHONY: all linux darwin windows clean