generated from aide-family/moon-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
128 lines (115 loc) · 4.38 KB
/
Makefile
File metadata and controls
128 lines (115 loc) · 4.38 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
GOHOSTOS:=$(shell go env GOHOSTOS)
VERSION=$(shell git describe --tags --always)
BUILD_TIME=$(shell date '+%Y-%m-%dT%H:%M:%SZ')
AUTHOR=$(shell git log -1 --format='%an')
AUTHOR_EMAIL=$(shell git log -1 --format='%ae')
REPO=$(shell git config remote.origin.url)
ifeq ($(GOHOSTOS), windows)
#the `find.exe` is different from `find` in bash/shell.
#to see https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/find.
#changed to use git-bash.exe to run find cli or other cli friendly, caused of every developer has a Git.
Git_Bash=$(subst \,/,$(subst cmd\,bin\bash.exe,$(dir $(shell where git))))
API_PROTO_FILES=$(shell $(Git_Bash) -c "find pkg/magicbox/proto/marksman -name *.proto")
# Use mkdir -p equivalent for Windows
MKDIR=mkdir
RM=del /f /q
else
API_PROTO_FILES=$(shell find pkg/magicbox/proto/marksman -name *.proto)
MKDIR=mkdir -p
RM=rm -f
endif
.PHONY: init
# initialize the marksman environment
init:
@echo "Initializing marksman environment"
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.3
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2@latest
go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest
go install github.com/google/wire/cmd/wire@latest
go install github.com/aide-family/stringer@v1.1.3
go install github.com/protoc-gen/i18n-gen@latest
go install golang.org/x/tools/gopls@latest
go install github.com/go-kratos/kratos/cmd/kratos/v2@latest
.PHONY: conf
# generate the conf files
conf:
@echo "Generating conf files"
protoc --proto_path=./internal/conf \
--proto_path=./pkg/magicbox/proto/third_party \
--proto_path=./pkg/magicbox/proto \
--go_out=paths=source_relative:./internal/conf \
--experimental_allow_proto3_optional \
./internal/conf/*.proto
.PHONY: api
# generate the api files
api:
@echo "Generating api files"
protoc --proto_path=./pkg/magicbox/proto \
--proto_path=./pkg/magicbox/proto/third_party \
--go_out=. --go_opt=module=github.com/aide-family/marksman \
--go-http_out=. --go-http_opt=module=github.com/aide-family/marksman \
--go-grpc_out=. --go-grpc_opt=module=github.com/aide-family/marksman \
--openapi_out=fq_schema_naming=true,default_response=false:./internal/server/swagger \
--experimental_allow_proto3_optional \
$(API_PROTO_FILES)
.PHONY: wire
# generate the wire files
wire:
@echo "Generating wire files"
wire ./...
.PHONY: all
# generate all files
all:
@git log -1 --format='%B' > description.txt
git submodule update --init --recursive
git submodule update --remote --recursive
make api conf wire
.PHONY: build
# build the marksman binary
build: all
@echo "Building marksman"
@echo "VERSION: $(VERSION)"
@echo "BUILD_TIME: $(BUILD_TIME)"
@echo "AUTHOR: $(AUTHOR)"
@echo "AUTHOR_EMAIL: $(AUTHOR_EMAIL)"
@git log -1 --format='%B' > description.txt
go build -ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME) -X main.Author=$(AUTHOR) -X main.Email=$(AUTHOR_EMAIL) -X main.Repo=$(REPO)" -o bin/marksman main.go
.PHONY: build-exe
# build the marksman binary for windows
build-exe: all
@echo "Building marksman"
@echo "VERSION: $(VERSION)"
@echo "BUILD_TIME: $(BUILD_TIME)"
@echo "AUTHOR: $(AUTHOR)"
@echo "AUTHOR_EMAIL: $(AUTHOR_EMAIL)"
@git log -1 --format='%B' > description.txt
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME) -X main.Author=$(AUTHOR) -X main.Email=$(AUTHOR_EMAIL) -X main.Repo=$(REPO)" -o bin/marksman.exe main.go
.PHONY: dev
# run the marksman binary in development mode
dev:
@echo "Running marksman in development mode"
go run . run all --log-level=DEBUG
.PHONY: migrate-sqlite
# run the tests
migrate-sqlite:
@echo "Migrating sqlite database"
go test -v -run 'TestGenerate|TestMigrateSQLite' ./internal/data/impl/do
# show help
help:
@echo ''
@echo 'Usage:'
@echo ' make [target]'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help