Makefile 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. GOHOSTOS:=$(shell go env GOHOSTOS)
  2. GOPATH:=$(shell go env GOPATH)
  3. VERSION=$(shell git describe --tags --always)
  4. ifeq ($(GOHOSTOS), windows)
  5. #the `find.exe` is different from `find` in bash/shell.
  6. #to see https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/find.
  7. #changed to use git-bash.exe to run find cli or other cli friendly, caused of every developer has a Git.
  8. #Git_Bash= $(subst cmd\,bin\bash.exe,$(dir $(shell where git)))
  9. Git_Bash=$(subst \,/,$(subst cmd\,bin\bash.exe,$(dir $(shell where git))))
  10. INTERNAL_PROTO_FILES=$(shell $(Git_Bash) -c "find internal -name *.proto")
  11. API_PROTO_FILES=$(shell $(Git_Bash) -c "find api -name *.proto")
  12. else
  13. INTERNAL_PROTO_FILES=$(shell find internal -name *.proto)
  14. API_PROTO_FILES=$(shell find api -name *.proto)
  15. endif
  16. .PHONY: init
  17. # init env
  18. init:
  19. go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
  20. go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
  21. go install github.com/go-kratos/kratos/cmd/kratos/v2@latest
  22. go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest
  23. go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest
  24. go install github.com/google/wire/cmd/wire@latest
  25. .PHONY: config
  26. # generate internal proto
  27. config:
  28. protoc --proto_path=./internal \
  29. --proto_path=./third_party \
  30. --go_out=paths=source_relative:./internal \
  31. $(INTERNAL_PROTO_FILES)
  32. .PHONY: api
  33. # generate api proto
  34. api:
  35. protoc --proto_path=./api \
  36. --proto_path=./third_party \
  37. --go_out=paths=source_relative:./api \
  38. --go-http_out=paths=source_relative:./api \
  39. --go-grpc_out=paths=source_relative:./api \
  40. --openapi_out=fq_schema_naming=true,default_response=false:. \
  41. $(API_PROTO_FILES)
  42. .PHONY: build
  43. # build
  44. build:
  45. mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./...
  46. .PHONY: generate
  47. # generate
  48. generate:
  49. go generate ./...
  50. go mod tidy
  51. .PHONY: all
  52. # generate all
  53. all:
  54. make api;
  55. make config;
  56. make generate;
  57. # show help
  58. help:
  59. @echo ''
  60. @echo 'Usage:'
  61. @echo ' make [target]'
  62. @echo ''
  63. @echo 'Targets:'
  64. @awk '/^[a-zA-Z\-\_0-9]+:/ { \
  65. helpMessage = match(lastLine, /^# (.*)/); \
  66. if (helpMessage) { \
  67. helpCommand = substr($$1, 0, index($$1, ":")); \
  68. helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
  69. printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
  70. } \
  71. } \
  72. { lastLine = $$0 }' $(MAKEFILE_LIST)
  73. .DEFAULT_GOAL := help