-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.proto
More file actions
39 lines (32 loc) · 1.09 KB
/
Copy pathMakefile.proto
File metadata and controls
39 lines (32 loc) · 1.09 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
PROTOC := protoc
PROTOC_GEN_GO := $(shell which protoc-gen-go)
PROTOC_GEN_GO_GRPC := $(shell which protoc-gen-go-grpc)
PROTO_DIR := proto
OUT_DIR := $(PROTO_DIR)/listwatcher
PROTO_PATHS := $(PROTO_DIR)
.PHONY: all build clean check install
all: check install build
check:
@command -v $(PROTOC) >/dev/null 2>&1 || { echo "Error: protoc is not installed."; exit 1; }
install:
@if [ -z "$(PROTOC_GEN_GO)" ]; then \
echo "Installing protoc-gen-go..."; \
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest; \
else \
echo "protoc-gen-go is already installed."; \
fi
@if [ -z "$(PROTOC_GEN_GO_GRPC)" ]; then \
echo "Installing protoc-gen-go-grpc..."; \
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest; \
else \
echo "protoc-gen-go-grpc is already installed."; \
fi
build:
@mkdir -p $(OUT_DIR)
$(PROTOC) \
--proto_path=$(PROTO_PATHS) \
--go_out=$(OUT_DIR) --go_opt=paths=source_relative \
--go-grpc_out=$(OUT_DIR) --go-grpc_opt=paths=source_relative \
$(PROTO_DIR)/*.proto
clean:
find $(OUT_DIR) -type f \( -name "*.pb.go" -o -name "*_grpc.pb.go" \) -delete