Makefile 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 apis -name *.proto")
  12. else
  13. INTERNAL_PROTO_FILES=$(shell find internal -name *.proto)
  14. API_PROTO_FILES=$(shell find apis -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-errors/v2@latest
  23. go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest
  24. go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest
  25. go install github.com/google/wire/cmd/wire@latest
  26. go install entgo.io/ent/cmd/ent@latest
  27. .PHONY: config
  28. # generate internal proto
  29. config:
  30. protoc --proto_path=./internal \
  31. --proto_path=./third_party \
  32. --go_out=paths=source_relative:./internal \
  33. $(INTERNAL_PROTO_FILES)
  34. .PHONY: api
  35. # generate apis proto
  36. api:
  37. protoc --proto_path=./apis \
  38. --proto_path=./third_party \
  39. --go_out=paths=source_relative:./apis \
  40. --go-http_out=paths=source_relative:./apis \
  41. --go-grpc_out=paths=source_relative:./apis \
  42. --openapi_out=fq_schema_naming=true,default_response=false:. \
  43. $(API_PROTO_FILES)
  44. .PHONY: validate
  45. # generate validate proto
  46. validate:
  47. protoc --proto_path=. \
  48. --proto_path=./third_party \
  49. --go_out=paths=source_relative:. \
  50. --validate_out=paths=source_relative,lang=go:. \
  51. $(API_PROTO_FILES)
  52. .PHONY: build
  53. # build
  54. build:
  55. mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./...
  56. .PHONY: errors
  57. # generate errors
  58. errors:
  59. protoc --proto_path=. \
  60. --proto_path=./third_party \
  61. --go_out=paths=source_relative:. \
  62. --go-errors_out=paths=source_relative:. \
  63. $(API_PROTO_FILES)
  64. .PHONY: generate
  65. # generate
  66. generate:
  67. go mod tidy
  68. go get github.com/google/wire/cmd/wire@latest
  69. go generate ./...
  70. .PHONY: all
  71. # generate all
  72. all:
  73. make api;
  74. make validate;
  75. make errors;
  76. #make config;
  77. make generate;
  78. # show help
  79. help:
  80. @echo ''
  81. @echo 'Usage:'
  82. @echo ' make [target]'
  83. @echo ''
  84. @echo 'Targets:'
  85. @awk '/^[a-zA-Z\-\_0-9]+:/ { \
  86. helpMessage = match(lastLine, /^# (.*)/); \
  87. if (helpMessage) { \
  88. helpCommand = substr($$1, 0, index($$1, ":")); \
  89. helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
  90. printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
  91. } \
  92. } \
  93. { lastLine = $$0 }' $(MAKEFILE_LIST)
  94. .DEFAULT_GOAL := help