-
Notifications
You must be signed in to change notification settings - Fork 3
/
makefile
88 lines (72 loc) · 2.24 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
# Having these will allow CI scripts to build for many OS's and ARCH's
OS := $(or ${OS},${OS},linux)
ARCH := $(or ${ARCH},${ARCH},amd64)
# Path to lint tool
GOLINTER ?= golangci-lint
GOFORMATTER ?= gofmt
# Determine binary file name
BIN_NAME := vidx2pidx
PROG := build/$(BIN_NAME)
ifneq (,$(findstring windows,$(OS)))
PROG=build/$(BIN_NAME).exe
endif
SOURCES := $(wildcard *.go)
all:
@echo Pick one of:
@echo $$ make $(PROG)
@echo $$ make run
@echo $$ make clean
@echo $$ make config
@echo $$ make release
@echo
@echo Build for different OS's and ARCH's by defining these variables. Ex:
@echo $$ make OS=windows ARCH=amd64 build/$(BIN_NAME).exe \# build for windows 64bits
@echo $$ make OS=darwin ARCH=amd64 build/$(BIN_NAME) \# build for MacOS 64bits
@echo
@echo Run tests
@echo $$ make test ARGS="<test args>"
@echo
@echo Release a new version of $(BIN_NAME)
@echo $$ make release
@echo
@echo Clean everything
@echo $$ make clean
@echo
@echo Configure local environment
@echo $$ make config
@echo
@echo Generate a report on code-coverage
@echo $$ make coverage-report
$(PROG): $(SOURCES)
@echo Building project
GOOS=$(OS) GOARCH=$(ARCH) go build -ldflags "-X main.version=`git describe 2>/dev/null || echo unknown`" -o $(PROG) ./...
run: $(PROG)
@./$(PROG) $(ARGS) || true
lint:
$(GOLINTER) run --config=.golangci.yml
format:
$(GOFORMATTER) -s -w .
format-check:
$(GOFORMATTER) -d . | tee format-check.out
test ! -s format-check.out
.PHONY: test release config
test:
TESTING=1 go test $(ARGS) ./...
test-all: format-check coverage-check lint
coverage-report:
TESTING=1 go test ./... -coverprofile cover.out
go tool cover -html=cover.out
coverage-check:
TESTING=1 go test ./... $(ARGS) -coverprofile cover.out
tail -n +2 cover.out | grep -v -e " 1$$" | grep -v main.go | tee coverage-check.out
test ! -s coverage-check.out
release: test-all build/vidx2pidx
@./scripts/release
config:
@echo "Configuring local environment"
@go version 2>/dev/null || echo "Need Golang: https://golang.org/doc/install"
@golangci-lint version 2>/dev/null || echo "Need GolangCi-Lint: https://golangci-lint.run/usage/install/#local-installation"
# Install pre-commit hooks
cp scripts/pre-commit .git/hooks/pre-commit
clean:
rm -rf build/*