-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
40 lines (29 loc) · 1.01 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
SRC := $(shell find . -name '*.go')
BIN := $(subst cmd/,dist/,$(wildcard cmd/*))
BIN_PATH := /usr/local/bin
.PHONY: all clean test run build install upgrade help $(SUBDIR)
all: $(SUBDIR) # default action
@[ -f .git/hooks/pre-commit ] || pre-commit install --install-hooks
@git config commit.template .git-commit-template
clean: $(SUBDIR) # clean-up environment
@find . -name '*.sw[po]' -delete
@rm -f $(BIN)
test: # run test
gofmt -w -s $(SRC)
go test -v ./...
run: # run in the local environment
go run
build: $(BIN) # build the binary/library
install: $(BIN) # install the binary/library on local
install -m755 $(BIN) $(BIN_PATH)/
upgrade: # upgrade all the necessary packages
pre-commit autoupdate
help: # show this message
@printf "Usage: make [OPTION]\n"
@printf "\n"
@perl -nle 'print $$& if m{^[\w-]+:.*?#.*$$}' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?#"} {printf " %-18s %s\n", $$1, $$2}'
dist/%: cmd/%/main.go $(SRC)
@mkdir -p $(@D)
@go mod tidy
go build -ldflags="-s -w" -o $@ $<