Debian Codegraph @

example/Makefile

raw
1 # Copyright The containerd Authors.
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6
7 # http://www.apache.org/licenses/LICENSE-2.0
8
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 GO_CMD := go
16 GO_BUILD := $(GO_CMD) build
17
18 PROTO_SOURCES := $(shell find . -name '*.proto' | grep -v /vendor/)
19 PROTO_GOFILES := $(patsubst %.proto,%.pb.go,$(PROTO_SOURCES)) \
20 $(patsubst %.proto,%_ttrpc.pb.go,$(PROTO_SOURCES))
21 PROTO_INCLUDE := -I$(PWD):/usr/local/include:/usr/include
22 PROTO_OPTIONS := --proto_path=. $(PROTO_INCLUDE) \
23 --go_opt=paths=source_relative --go_out=. \
24 --go-ttrpc_opt=paths=source_relative --go-ttrpc_out=.
25 PROTO_COMPILE := PATH=$(PATH):$(shell go env GOPATH)/bin; protoc $(PROTO_OPTIONS)
26
27 INSTALL_PROTOC := https://github.com/containerd/containerd/blob/main/script/setup/install-protobuf
28 PROTOC_DEPS := google.golang.org/protobuf/cmd/[email protected]
29 TTRPC_PLUGIN := github.com/containerd/ttrpc/cmd/protoc-gen-go-ttrpc@74421d10189e8c118870d294c9f7f62db2d33ec1
30 WGET := wget
31
32 BINARIES := example-client example-server
33
34 ifneq ($(V),1)
35 Q := @
36 endif
37
38
39 #
40 # top-level targets
41 #
42
43 all: build ## build example
44
45 build: $(BINARIES)
46
47 clean:
48 $(Q)rm -f $(BINARIES)
49
50 protos: $(PROTO_GOFILES) ## generate example API ttrpc bindings
51
52 #
53 # binary compilation targets
54 #
55
56 example-client: $(wildcard api/*.go config/*.go client/*.go) ## build example client
57 $(Q)echo "Building $@..."; \
58 $(GO_BUILD) -o $@ ./client
59
60 example-server: $(wildcard api/*.go config/*.go server/*.go) ## build example-server
61 $(Q)echo "Building $@..."; \
62 $(GO_BUILD) -o $@ ./server
63
64 #
65 # proto generation targets
66 #
67
68 %.pb.go: %.proto
69 $(Q)echo "Generating $@..."; \
70 $(PROTO_COMPILE) $<
71
72 #
73 # targets for installing dependencies
74 #
75
76 install-protoc install-protobuf: ## install protobuf compiler
77 $(Q)$(WGET) $(INSTALL_PROTOC) && chmod a+x install-protobuf && ./install-protobuf
78
79 install-protoc-dependencies: ## install protobuf compiler dependencies
80 $(Q)$(GO_INSTALL) -mod=mod $(PROTOC_DEPS)
81
82 install-ttrpc-plugin: ## install protobuf compiler ttrcp plugin
83 $(Q)$(GO_INSTALL) -mod=mod $(TTRPC_PLUGIN)
84
85 help: ## this help
86 @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort