-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
51 lines (37 loc) · 1.46 KB
/
Makefile
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
40
41
42
43
44
45
46
47
48
49
50
51
.PHONY: toolchain clean distclean
# Edit: go module path to this package: https://go.dev/ref/mod#glos-module-path
GO_PACKAGE := github.com/rmorison/protobuf-toolchain-template
# Edit: Add .proto files here
PROTO_FILES := proto/helloworld/helloworld.proto
# Edit: protoc build arch from releases page: https://github.com/protocolbuffers/protobuf/releases/
PROTOC_ARCH := $(if $(PROTOC_ARCH),$(PROTOC_ARCH),linux-x86_64)
# Derived: protoc built files
PROTOC_GO_FILES := $(PROTO_FILES:.proto=.pb.go) $(PROTO_FILES:.proto=_grpc.pb.go)
.SECONDARY: $(PROTOC_GO_FILES)
# Protocol compiler toolchain
PROTOC_BIN := toolchain/bin
PROTOC := $(PROTOC_BIN)/protoc
export PATH := $(shell pwd)/$(PROTOC_BIN):$(PATH)
# Build .pb.go from .proto
%.pb.go %_grpc.pb.go: %.proto $(PROTOC)
$(PROTOC) $< \
--go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative
# Build go program from main.go
%/main: %/main.go go.mod $(PROTOC_GO_FILES)
go mod tidy
go build -o $@ $<
all: greeter_client/main greeter_server/main
greeter_client/main: greeter_client/main.go
greeter_server/main: greeter_server/main.go
go.mod:
go mod init $(GO_PACKAGE)
toolchain: $(PROTOC)
$(PROTOC):
make -C toolchain GO_PACKAGE=$(GO_PACKAGE) PROTOC_ARCH=$(PROTOC_ARCH)
clean:
rm -f $(PROTOC_GO_FILES) greeter_client/main greeter_server/main
make -C toolchain clean
distclean:
rm -f $(PROTOC_GO_FILES) greeter_client/main greeter_server/main go.mod go.sum
make -C toolchain distclean