-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
77 lines (67 loc) · 1.98 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
PROJECT := github.com/wolveix/xbox-dvr
GO := $(shell which go 2>/dev/null)
GOFIELDALIGNMENT := $(shell which fieldalignment 2>/dev/null)
GOFUMPT := $(shell which gofumpt 2>/dev/null)
GOLINTER := $(shell which golangci-lint 2>/dev/null)
GONILAWAY := $(shell which nilaway 2>/dev/null)
GO_BENCH_FLAGS := -short -bench=. -benchmem
GO_BENCH := $(GO) test $(GO_BENCH_FLAGS)
GO_BUILD := CGO_ENABLED=0 $(GO) build -ldflags "-s -w" -trimpath
GO_FORMAT := $(GOFUMPT) -w
GO_OPTIMIZE := $(GOFIELDALIGNMENT) -fix
GO_TEST := $(GO) test -v -short
GO_TIDY := $(GO) mod tidy
TARGETS := bin/xdvr
all: check-dependencies prepare optimize $(TARGETS) clean
dev: prepare $(TARGETS)
bin/%: $(shell find . -name "*.go" -type f)
@echo "Building $@..."
@if [ "$(MAKECMDGOALS)" != "dev" ]; then \
cd build && $(GO_BUILD) -o ../$@ $(PROJECT)/cmd/$*; \
else \
$(GO_BUILD) -o $@ $(PROJECT)/cmd/$*; \
fi
check-dependencies:
@echo "Checking dependencies..."
@if [ -z "${GO}" ]; then \
echo "Cannot find 'go' in your $$PATH"; \
exit 1; \
fi
@if [ -z "${GOFIELDALIGNMENT}" ]; then \
echo "Cannot find 'fieldalignment' in your $$PATH"; \
exit 1; \
fi
clean:
@echo "Cleaning temporary build directory..."
@rm -rf build
format:
@if [ -z "${GOFUMPT}" ]; then \
echo "Cannot find 'gofumpt' in your $$PATH"; \
exit 1; \
fi
@echo "Formatting code..."
@$(GO_FORMAT) $(PWD)
lint:
@if [ -z "${GOLINTER}" ]; then \
echo "Cannot find 'golangci-lint' in your $$PATH"; \
exit 1; \
fi
@echo "Running linter..."
@$(GOLINTER) run ./...
nil:
@if [ -z "${GONILAWAY}" ]; then \
echo "Cannot find 'nilaway' in your $$PATH"; \
exit 1; \
fi
@echo "Running nilaway..."
@$(GONILAWAY) ./...
optimize:
@echo "Creating temporary build directory..."
@cp -r cmd go.* ./build/
@echo "Optimizing struct field alignment..."
@cd build && $(GO_OPTIMIZE) ./... > /dev/null 2>&1 || true
prepare:
@echo "Cleaning previous builds..."
@rm -rf bin build
@mkdir -p bin build
@$(GO_TIDY)