-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmakefile
53 lines (41 loc) · 1.77 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
# All targets.
.PHONY: lint test build publish clean help
# Current version of the project.
VersionMain ?= 0.1.1
# Target binaries. You can build multiple binaries for a single project.
TARGETS := wiki
PLAT_FROM := linux darwin windows
# Project main package location (can be multiple ones).
CMD_DIR := .
# Project output directory.
OUTPUT_DIR := ./output
# Git commit sha.
COMMIT := $(shell git rev-parse --short HEAD)
# Build Date
BUILD_DATE=$(shelldate +%FT%T%z)
# Version File
VERSION_FILE=main
lint: ## use golint to do lint
golint ./...
test: ## test
go test -cover ./...
build: ## build local binary for targets on
@for target in $(TARGETS); do \
go build -o $(OUTPUT_DIR)/$${target} \
-ldflags "-s -w -X $(VERSION_FILE).Version=$(VersionMain)-$(COMMIT)" \
$(CMD_DIR)/.; \
done
build-all: # build cross for targets
@for plat in $(PLAT_FROM); do \
for target in $(TARGETS); do \
CGO_ENABLED=0 GOOS=$${plat} GOARCH=amd64 go build -o $(OUTPUT_DIR)/$${target}_$${plat}_amd64 \
-ldflags "-s -w -X $(VERSION_FILE).Version=$(VersionMain)-$(COMMIT)" \
$(CMD_DIR)/.; \
done \
done
.PHONY: clean
clean: # clean bin files
-rm -vrf ${OUTPUT_DIR}
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'