Makefile 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 apis 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 mod tidy
  50. go get github.com/google/wire/cmd/wire@latest
  51. go generate ./...
  52. .PHONY: entc
  53. # entc
  54. entc:
  55. go run entgo.io/ent/cmd/ent generate ./internal/data/ent/schema
  56. .PHONY: all
  57. # generate all
  58. all:
  59. #make apis;
  60. make config;
  61. make entc;
  62. make generate;
  63. # show help
  64. help:
  65. @echo ''
  66. @echo 'Usage:'
  67. @echo ' make [target]'
  68. @echo ''
  69. @echo 'Targets:'
  70. @awk '/^[a-zA-Z\-\_0-9]+:/ { \
  71. helpMessage = match(lastLine, /^# (.*)/); \
  72. if (helpMessage) { \
  73. helpCommand = substr($$1, 0, index($$1, ":")); \
  74. helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
  75. printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
  76. } \
  77. } \
  78. { lastLine = $$0 }' $(MAKEFILE_LIST)
  79. .DEFAULT_GOAL := help