123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- GOHOSTOS:=$(shell go env GOHOSTOS)
- GOPATH:=$(shell go env GOPATH)
- VERSION=$(shell git describe --tags --always)
- 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 cmd\,bin\bash.exe,$(dir $(shell where git)))
- Git_Bash=$(subst \,/,$(subst cmd\,bin\bash.exe,$(dir $(shell where git))))
- INTERNAL_PROTO_FILES=$(shell $(Git_Bash) -c "find internal -name *.proto")
- API_PROTO_FILES=$(shell $(Git_Bash) -c "find apis -name *.proto")
- else
- INTERNAL_PROTO_FILES=$(shell find internal -name *.proto)
- API_PROTO_FILES=$(shell find apis -name *.proto)
- endif
- .PHONY: init
- # init env
- init:
- go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
- go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
- go install github.com/go-kratos/kratos/cmd/kratos/v2@latest
- go install github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2@latest
- go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest
- go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest
- go install github.com/google/wire/cmd/wire@latest
- go install entgo.io/ent/cmd/ent@latest
- .PHONY: config
- # generate internal proto
- config:
- protoc --proto_path=./internal \
- --proto_path=./third_party \
- --go_out=paths=source_relative:./internal \
- $(INTERNAL_PROTO_FILES)
- .PHONY: api
- # generate apis proto
- api:
- protoc --proto_path=./apis \
- --proto_path=./third_party \
- --go_out=paths=source_relative:./apis \
- --go-http_out=paths=source_relative:./apis \
- --go-grpc_out=paths=source_relative:./apis \
- --openapi_out=fq_schema_naming=true,default_response=false:. \
- $(API_PROTO_FILES)
- .PHONY: validate
- # generate validate proto
- validate:
- protoc --proto_path=. \
- --proto_path=./third_party \
- --go_out=paths=source_relative:. \
- --validate_out=paths=source_relative,lang=go:. \
- $(API_PROTO_FILES)
- .PHONY: build
- # build
- build:
- mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./...
- .PHONY: errors
- # generate errors
- errors:
- protoc --proto_path=. \
- --proto_path=./third_party \
- --go_out=paths=source_relative:. \
- --go-errors_out=paths=source_relative:. \
- $(API_PROTO_FILES)
- .PHONY: generate
- # generate
- generate:
- go mod tidy
- go get github.com/google/wire/cmd/wire@latest
- go generate ./...
- .PHONY: all
- # generate all
- all:
- make api;
- make validate;
- make errors;
- #make config;
- make generate;
- # 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
|