• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright 2015 gRPC authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17# TODO(jtattermusch): Remove the hack to workaround protobuf bug. See https://github.com/protocolbuffers/protobuf/issues/12439
18# Hack: protobuf currently doesn't declare it's absl dependencies when protobuf.pc pkgconfig file is used.
19PROTOBUF_ABSL_DEPS = absl_absl_check absl_absl_log absl_algorithm absl_base absl_bind_front absl_bits absl_btree absl_cleanup absl_cord absl_core_headers absl_debugging absl_die_if_null absl_dynamic_annotations absl_flags absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_layout absl_log_initialize absl_log_severity absl_memory absl_node_hash_map absl_node_hash_set absl_optional absl_span absl_status absl_statusor absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant
20# TODO(jtattermusch): Remove the hack to workaround protobuf/utf8_range bug. See https://github.com/protocolbuffers/utf8_range/issues/20
21# Hack: utf8_range (which is protobuf's dependency) currently doesn't have a pkgconfig file, so we need to explicitly
22# tweak the list of libraries to link against to fix the build.
23PROTOBUF_UTF8_RANGE_LINK_LIBS = -lutf8_validity
24OPENTELEMETRY_LINK_LIBS = -lopentelemetry_metrics -lopentelemetry_exporter_ostream_metrics -lopentelemetry_resources -lopentelemetry_common
25
26HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
27SYSTEM ?= $(HOST_SYSTEM)
28CXX = g++
29CPPFLAGS += `pkg-config --cflags protobuf grpc absl_flags absl_flags_parse`
30CXXFLAGS += -std=c++17
31ifeq ($(SYSTEM),Darwin)
32LDFLAGS += -L/usr/local/lib `pkg-config --libs --static protobuf grpc++ grpcpp_otel_plugin absl_flags absl_flags_parse $(PROTOBUF_ABSL_DEPS)` \
33           $(PROTOBUF_UTF8_RANGE_LINK_LIBS) \
34	       $(OPENTELEMETRY_LINK_LIBS) \
35           -pthread \
36           -lgrpc++_reflection \
37           -ldl
38else
39LDFLAGS += -L/usr/local/lib `pkg-config --libs --static protobuf grpc++ grpcpp_otel_plugin absl_flags absl_flags_parse $(PROTOBUF_ABSL_DEPS)` \
40           $(PROTOBUF_UTF8_RANGE_LINK_LIBS) \
41	       $(OPENTELEMETRY_LINK_LIBS) \
42           -pthread \
43           -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed \
44           -ldl
45endif
46PROTOC = protoc
47GRPC_CPP_PLUGIN = grpc_cpp_plugin
48GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
49
50PROTOS_PATH = ../../../protos
51
52vpath %.proto $(PROTOS_PATH)
53
54all: system-check greeter_callback_client greeter_callback_server
55
56greeter_callback_client: util.o helloworld.pb.o helloworld.grpc.pb.o greeter_callback_client.o
57	$(CXX) $^ $(LDFLAGS) -o $@
58
59greeter_callback_server: util.o helloworld.pb.o helloworld.grpc.pb.o greeter_callback_server.o
60	$(CXX) $^ $(LDFLAGS) -o $@
61
62.PRECIOUS: %.grpc.pb.cc
63%.grpc.pb.cc: %.proto
64	$(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
65
66.PRECIOUS: %.pb.cc
67%.pb.cc: %.proto
68	$(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $<
69
70util.o: ../util.cc
71	$(CXX) $^ -I . $(CPPFLAGS) $(CXXFLAGS) -c -o $@
72
73clean:
74	rm -f *.o *.pb.cc *.pb.h greeter_callback_client greeter_callback_server
75
76
77# The following is to test your system and ensure a smoother experience.
78# They are by no means necessary to actually compile a grpc-enabled software.
79
80PROTOC_CMD = which $(PROTOC)
81PROTOC_CHECK_CMD = $(PROTOC) --version | grep -q 'libprotoc.3\|libprotoc [0-9][0-9]\.'
82PLUGIN_CHECK_CMD = which $(GRPC_CPP_PLUGIN)
83HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false)
84ifeq ($(HAS_PROTOC),true)
85HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
86endif
87HAS_PLUGIN = $(shell $(PLUGIN_CHECK_CMD) > /dev/null && echo true || echo false)
88
89SYSTEM_OK = false
90ifeq ($(HAS_VALID_PROTOC),true)
91ifeq ($(HAS_PLUGIN),true)
92SYSTEM_OK = true
93endif
94endif
95
96system-check:
97ifneq ($(HAS_VALID_PROTOC),true)
98	@echo " DEPENDENCY ERROR"
99	@echo
100	@echo "You don't have protoc 3.0.0 or newer installed in your path."
101	@echo "Please install an up-to-date version of Google protocol buffers."
102	@echo "You can find it here:"
103	@echo
104	@echo "   https://github.com/protocolbuffers/protobuf/releases"
105	@echo
106	@echo "Here is what I get when trying to evaluate your version of protoc:"
107	@echo
108	-$(PROTOC) --version
109	@echo
110	@echo
111endif
112ifneq ($(HAS_PLUGIN),true)
113	@echo " DEPENDENCY ERROR"
114	@echo
115	@echo "You don't have the grpc c++ protobuf plugin installed in your path."
116	@echo "Please install grpc. You can find it here:"
117	@echo
118	@echo "   https://github.com/grpc/grpc"
119	@echo
120	@echo "Here is what I get when trying to detect if you have the plugin:"
121	@echo
122	-which $(GRPC_CPP_PLUGIN)
123	@echo
124	@echo
125endif
126ifneq ($(SYSTEM_OK),true)
127	@false
128endif
129