Makefile · 2666 bytes Raw Blame History
1 # ZephyrFS Protocol Buffer Makefile
2
3 # Directories
4 PROTO_DIR = protobuff
5 GEN_DIR = generated
6 RUST_OUT = $(GEN_DIR)/rust
7 GO_OUT = $(GEN_DIR)/go
8 TS_OUT = $(GEN_DIR)/typescript
9
10 # Proto files
11 PROTO_FILES = $(wildcard $(PROTO_DIR)/*.proto)
12
13 # Tools
14 PROTOC = protoc
15 RUST_PLUGIN = --rust_out=$(RUST_OUT) --rust-grpc_out=$(RUST_OUT)
16 GO_PLUGIN = --go_out=$(GO_OUT) --go-grpc_out=$(GO_OUT)
17 TS_PLUGIN = --ts_out=$(TS_OUT) --grpc-web_out=import_style=typescript,mode=grpcweb:$(TS_OUT)
18
19 .PHONY: all clean rust go typescript setup
20
21 all: setup rust go typescript
22
23 setup:
24 @mkdir -p $(RUST_OUT) $(GO_OUT) $(TS_OUT)
25
26 rust: setup
27 @echo "Generating Rust code from protobuf files..."
28 @for proto in $(PROTO_FILES); do \
29 $(PROTOC) --proto_path=$(PROTO_DIR) $(RUST_PLUGIN) $$proto; \
30 done
31 @echo "Rust protobuf generation complete"
32
33 go: setup
34 @echo "Generating Go code from protobuf files..."
35 @for proto in $(PROTO_FILES); do \
36 $(PROTOC) --proto_path=$(PROTO_DIR) $(GO_PLUGIN) $$proto; \
37 done
38 @echo "Go protobuf generation complete"
39
40 typescript: setup
41 @echo "Generating TypeScript code from protobuf files..."
42 @for proto in $(PROTO_FILES); do \
43 $(PROTOC) --proto_path=$(PROTO_DIR) $(TS_PLUGIN) $$proto; \
44 done
45 @echo "TypeScript protobuf generation complete"
46
47 clean:
48 @echo "Cleaning generated files..."
49 @rm -rf $(GEN_DIR)
50 @echo "Clean complete"
51
52 install-deps:
53 @echo "Installing protobuf compiler dependencies..."
54 # Install protoc (platform-specific)
55 @if command -v apt-get >/dev/null 2>&1; then \
56 sudo apt-get update && sudo apt-get install -y protobuf-compiler; \
57 elif command -v brew >/dev/null 2>&1; then \
58 brew install protobuf; \
59 elif command -v pacman >/dev/null 2>&1; then \
60 sudo pacman -S protobuf; \
61 else \
62 echo "Please install protobuf compiler manually"; \
63 exit 1; \
64 fi
65 # Install Rust protobuf plugins
66 @cargo install protobuf-codegen protoc-gen-rust grpc-compiler
67 # Install Go protobuf plugins
68 @go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
69 @go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
70 # Install TypeScript protobuf plugins
71 @npm install -g protoc-gen-ts protoc-gen-grpc-web
72
73 validate:
74 @echo "Validating protobuf files..."
75 @for proto in $(PROTO_FILES); do \
76 echo "Validating $$proto..."; \
77 $(PROTOC) --proto_path=$(PROTO_DIR) --descriptor_set_out=/dev/null $$proto || exit 1; \
78 done
79 @echo "All protobuf files are valid"
80
81 docs:
82 @echo "Generating protocol documentation..."
83 @mkdir -p docs/generated
84 @$(PROTOC) --proto_path=$(PROTO_DIR) --doc_out=docs/generated --doc_opt=html,index.html $(PROTO_FILES)
85 @echo "Documentation generated in docs/generated/"
86
87 .PHONY: install-deps validate docs