blob: 628056ed4db79a72bccefa26316121c739154f00 [file] [log] [blame]
Craig Tiller841c8802015-09-10 13:06:37 -07001%YAML 1.2
2--- |
3 # GRPC global makefile
4 # This currently builds C and C++ code.
5 # This file has been automatically generated from a template file.
6 # Please look at the templates directory instead.
7 # This file can be regenerated from the template by running
8 # tools/buildgen/generate_projects.sh
Craig Tiller3b935482015-02-16 12:15:48 -08009
Jan Tattermusch4d5c3102017-06-07 10:23:56 +020010 # Copyright 2015 gRPC authors.
Craig Tiller841c8802015-09-10 13:06:37 -070011 #
Jan Tattermusch4d5c3102017-06-07 10:23:56 +020012 # Licensed under the Apache License, Version 2.0 (the "License");
13 # you may not use this file except in compliance with the License.
14 # You may obtain a copy of the License at
Craig Tiller841c8802015-09-10 13:06:37 -070015 #
Jan Tattermusch4d5c3102017-06-07 10:23:56 +020016 # http://www.apache.org/licenses/LICENSE-2.0
Craig Tiller841c8802015-09-10 13:06:37 -070017 #
Jan Tattermusch4d5c3102017-06-07 10:23:56 +020018 # Unless required by applicable law or agreed to in writing, software
19 # distributed under the License is distributed on an "AS IS" BASIS,
20 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 # See the License for the specific language governing permissions and
22 # limitations under the License.
Craig Tiller841c8802015-09-10 13:06:37 -070023 <%!
24 import re
25 import os
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080026
Craig Tiller841c8802015-09-10 13:06:37 -070027 proto_re = re.compile('(.*)\\.proto')
nnoble72309c62014-12-12 11:42:26 -080028
Craig Tiller841c8802015-09-10 13:06:37 -070029 def proto_to_cc(filename):
30 m = proto_re.match(filename)
31 if not m:
32 return filename
33 return '$(GENDIR)/' + m.group(1) + '.pb.cc $(GENDIR)/' + m.group(1) + '.grpc.pb.cc'
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +020034
Craig Tiller841c8802015-09-10 13:06:37 -070035 sources_that_need_openssl = set()
36 sources_that_don_t_need_openssl = set()
Craig Tiller78222f72016-05-10 09:55:38 -070037
38 # warnings we'd like, but that dont exist in all compilers
39 PREFERRED_WARNINGS=['shadow', 'extra-semi']
Nicolas "Pixel" Nobled7c6c6e2018-06-26 23:20:26 +020040 CHECK_WARNINGS=PREFERRED_WARNINGS + ['no-shift-negative-value', 'no-unused-but-set-variable', 'no-maybe-uninitialized']
Craig Tiller78222f72016-05-10 09:55:38 -070041
42 def warning_var(fmt, warning):
Nicolas "Pixel" Noblec6ed8232018-06-23 10:22:49 +020043 return fmt % warning.replace('-', '_').replace('+', 'X').upper()
Craig Tiller78222f72016-05-10 09:55:38 -070044
45 def neg_warning(warning):
46 if warning[0:3] == 'no-':
47 return warning[3:]
48 else:
49 return 'no-' + warning
Craig Tiller38b99e92016-09-15 16:18:09 -070050
51 lang_to_var = {
52 'c': 'CORE',
53 'c++': 'CPP',
54 'csharp': 'CSHARP'
55 }
Craig Tiller841c8802015-09-10 13:06:37 -070056 %>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080057
Craig Tiller96b49552015-01-21 16:29:01 -080058
Craig Tiller71a86042016-01-15 14:59:58 -080059 comma := ,
60
61
Craig Tiller841c8802015-09-10 13:06:37 -070062 # Basic platform detection
63 HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +010064 SYSTEM ?= $(HOST_SYSTEM)
Craig Tiller841c8802015-09-10 13:06:37 -070065 ifeq ($(SYSTEM),MSYS)
66 SYSTEM = MINGW32
67 endif
68 ifeq ($(SYSTEM),MINGW64)
69 SYSTEM = MINGW32
70 endif
Craig Tiller96b49552015-01-21 16:29:01 -080071
72
Nicolas "Pixel" Noble6dad9b02015-09-23 18:32:26 +020073 MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
Craig Tiller841c8802015-09-10 13:06:37 -070074 ifndef BUILDDIR
Nicolas "Pixel" Noble42b4c282015-09-17 23:57:08 +020075 BUILDDIR_ABSOLUTE = $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))
76 else
77 BUILDDIR_ABSOLUTE = $(abspath $(BUILDDIR))
Craig Tiller841c8802015-09-10 13:06:37 -070078 endif
Craig Tiller61b910f2015-02-15 10:54:07 -080079
Craig Tiller841c8802015-09-10 13:06:37 -070080 HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false)
81 HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false)
82 HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false)
Nicolas Noblef8681182015-03-18 14:25:44 -070083
Craig Tiller841c8802015-09-10 13:06:37 -070084 ifeq ($(HAS_CC),true)
85 DEFAULT_CC = cc
86 DEFAULT_CXX = c++
87 else
88 ifeq ($(HAS_GCC),true)
89 DEFAULT_CC = gcc
90 DEFAULT_CXX = g++
91 else
92 ifeq ($(HAS_CLANG),true)
93 DEFAULT_CC = clang
94 DEFAULT_CXX = clang++
95 else
96 DEFAULT_CC = no_c_compiler
97 DEFAULT_CXX = no_c++_compiler
98 endif
99 endif
100 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700101
102
Nicolas "Pixel" Noble42b4c282015-09-17 23:57:08 +0200103 BINDIR = $(BUILDDIR_ABSOLUTE)/bins
104 OBJDIR = $(BUILDDIR_ABSOLUTE)/objs
105 LIBDIR = $(BUILDDIR_ABSOLUTE)/libs
106 GENDIR = $(BUILDDIR_ABSOLUTE)/gens
Craig Tiller61b910f2015-02-15 10:54:07 -0800107
Craig Tiller841c8802015-09-10 13:06:37 -0700108 # Configurations
ctiller8cfebb92015-01-06 15:02:12 -0800109
Craig Tillera0f85172016-01-20 15:56:06 -0800110 % for name, args in configs.iteritems():
111 VALID_CONFIG_${name} = 1
112 % if args.get('compile_the_world', False):
113 REQUIRE_CUSTOM_LIBRARIES_${name} = 1
114 % endif
Craig Tilleraff3d502016-01-20 15:59:31 -0800115 % for tool, default in [('CC', 'CC'), ('CXX', 'CXX'), ('LD', 'CC'), ('LDXX', 'CXX')]:
Craig Tillera0f85172016-01-20 15:56:06 -0800116 ${tool}_${name} = ${args.get(tool, '$(DEFAULT_%s)' % default)}
117 % endfor
118 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES']:
119 % if args.get(arg, None) is not None:
120 ${arg}_${name} = ${args.get(arg)}
121 % endif
122 % endfor
ctiller8cfebb92015-01-06 15:02:12 -0800123
Craig Tillera0f85172016-01-20 15:56:06 -0800124 % endfor
Craig Tiller699ba212015-01-13 17:02:20 -0800125
Nicolas Noble047b7272015-01-16 13:55:05 -0800126
Craig Tiller841c8802015-09-10 13:06:37 -0700127 # General settings.
128 # You may want to change these depending on your system.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800129
Craig Tiller841c8802015-09-10 13:06:37 -0700130 prefix ?= /usr/local
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800131
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100132 PROTOC ?= protoc
133 DTRACE ?= dtrace
Craig Tiller841c8802015-09-10 13:06:37 -0700134 CONFIG ?= opt
Nicolas "Pixel" Noblefba36bc2016-01-27 03:24:03 +0100135 # Doing X ?= Y is the same as:
136 # ifeq ($(origin X), undefined)
137 # X = Y
138 # endif
139 # but some variables, such as CC, CXX, LD or AR, have defaults.
140 # So instead of using ?= on them, we need to check their origin.
141 # See:
142 # https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
143 # https://www.gnu.org/software/make/manual/html_node/Flavors.html#index-_003f_003d
144 # https://www.gnu.org/software/make/manual/html_node/Origin-Function.html
145 ifeq ($(origin CC), default)
146 CC = $(CC_$(CONFIG))
147 endif
148 ifeq ($(origin CXX), default)
149 CXX = $(CXX_$(CONFIG))
150 endif
151 ifeq ($(origin LD), default)
152 LD = $(LD_$(CONFIG))
153 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100154 LDXX ?= $(LDXX_$(CONFIG))
Craig Tiller841c8802015-09-10 13:06:37 -0700155 ifeq ($(SYSTEM),Linux)
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100156 ifeq ($(origin AR), default)
157 AR = ar rcs
158 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100159 STRIP ?= strip --strip-unneeded
Craig Tiller841c8802015-09-10 13:06:37 -0700160 else
161 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100162 ifeq ($(origin AR), default)
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100163 AR = libtool -no_warning_for_no_symbols -o
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100164 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100165 STRIP ?= strip -x
Craig Tiller841c8802015-09-10 13:06:37 -0700166 else
Mario Emmenlauer1643c042016-12-12 23:12:47 +0100167 ifeq ($(SYSTEM),MINGW32)
168 ifeq ($(origin AR), default)
169 AR = ar rcs
170 endif
171 STRIP ?= strip --strip-unneeded
172 else
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100173 ifeq ($(origin AR), default)
174 AR = ar rcs
175 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100176 STRIP ?= strip
Craig Tiller841c8802015-09-10 13:06:37 -0700177 endif
178 endif
Mario Emmenlauer1643c042016-12-12 23:12:47 +0100179 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100180 INSTALL ?= install
181 RM ?= rm -f
182 PKG_CONFIG ?= pkg-config
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800183
Craig Tiller841c8802015-09-10 13:06:37 -0700184 ifndef VALID_CONFIG_$(CONFIG)
185 $(error Invalid CONFIG value '$(CONFIG)')
186 endif
yangg102e4fe2015-01-06 16:02:50 -0800187
Craig Tiller841c8802015-09-10 13:06:37 -0700188 ifeq ($(SYSTEM),Linux)
189 TMPOUT = /dev/null
190 else
191 TMPOUT = `mktemp /tmp/test-out-XXXXXX`
192 endif
Nicolas Noble047b7272015-01-16 13:55:05 -0800193
Nicolas "Pixel" Nobleb71da612018-06-24 21:56:32 +0200194 CHECK_NO_CXX14_COMPAT_WORKS_CMD = $(CC) -std=c++11 -Werror -Wno-c++14-compat -o $(TMPOUT) -c test/build/no-c++14-compat.cc
195 HAS_WORKING_NO_CXX14_COMPAT = $(shell $(CHECK_NO_CXX14_COMPAT_WORKS_CMD) 2> /dev/null && echo true || echo false)
196 ifeq ($(HAS_WORKING_NO_CXX14_COMPAT),true)
197 W_NO_CXX14_COMPAT=-Wno-c++14-compat
198 endif
199
Craig Tiller78222f72016-05-10 09:55:38 -0700200 %for warning in CHECK_WARNINGS:
201 ${warning_var('CHECK_%s_WORKS_CMD', warning)} = $(CC) -std=c99 -Werror -W${warning} -o $(TMPOUT) -c test/build/${warning}.c
202 ${warning_var('HAS_WORKING_%s', warning)} = $(shell $(${warning_var('CHECK_%s_WORKS_CMD', warning)}) 2> /dev/null && echo true || echo false)
203 ifeq ($(${warning_var('HAS_WORKING_%s', warning)}),true)
204 ${warning_var('W_%s', warning)}=-W${warning}
205 ${warning_var('NO_W_%s', warning)}=-W${neg_warning(warning)}
Craig Tiller804b8552016-02-23 16:50:24 -0800206 endif
Craig Tiller78222f72016-05-10 09:55:38 -0700207 %endfor
Craig Tiller16872b82016-01-25 10:55:20 -0800208
Craig Tiller841c8802015-09-10 13:06:37 -0700209 # The HOST compiler settings are used to compile the protoc plugins.
210 # In most cases, you won't have to change anything, but if you are
211 # cross-compiling, you can override these variables from GNU make's
212 # command line: make CC=cross-gcc HOST_CC=gcc
Nicolas Noble047b7272015-01-16 13:55:05 -0800213
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100214 HOST_CC ?= $(CC)
215 HOST_CXX ?= $(CXX)
216 HOST_LD ?= $(LD)
217 HOST_LDXX ?= $(LDXX)
nnoble72309c62014-12-12 11:42:26 -0800218
Craig Tiller78222f72016-05-10 09:55:38 -0700219 CFLAGS += -std=c99 -Wsign-conversion -Wconversion ${' '.join(warning_var('$(W_%s)', warning) for warning in PREFERRED_WARNINGS)}
Craig Tiller841c8802015-09-10 13:06:37 -0700220 CXXFLAGS += -std=c++11
Ken Paysonf8d6fb72017-06-15 17:32:49 -0700221 ifeq ($(SYSTEM),Darwin)
222 CXXFLAGS += -stdlib=libc++
223 endif
ncteisenf9d7c272017-11-06 20:32:57 -0800224 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'COREFLAGS', 'LDFLAGS', 'DEFINES']:
Nicolas "Pixel" Noble51b1aee2016-01-28 01:14:58 +0100225 % if defaults.get('global', []).get(arg, None) is not None:
226 ${arg} += ${defaults.get('global').get(arg)}
227 % endif
228 % endfor
Nicolas Noblef8681182015-03-18 14:25:44 -0700229
Craig Tiller841c8802015-09-10 13:06:37 -0700230 CPPFLAGS += $(CPPFLAGS_$(CONFIG))
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800231 CFLAGS += $(CFLAGS_$(CONFIG))
232 CXXFLAGS += $(CXXFLAGS_$(CONFIG))
Craig Tiller841c8802015-09-10 13:06:37 -0700233 DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
234 LDFLAGS += $(LDFLAGS_$(CONFIG))
Nicolas "Pixel" Noble482d7612015-07-16 23:43:30 +0200235
Craig Tiller841c8802015-09-10 13:06:37 -0700236 ifneq ($(SYSTEM),MINGW32)
237 PIC_CPPFLAGS = -fPIC
238 CPPFLAGS += -fPIC
239 LDFLAGS += -fPIC
240 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800241
Craig Tiller841c8802015-09-10 13:06:37 -0700242 INCLUDES = . include $(GENDIR)
243 LDFLAGS += -Llibs/$(CONFIG)
Nicolas "Pixel" Noble3adab742015-06-02 00:33:06 +0200244
Craig Tiller841c8802015-09-10 13:06:37 -0700245 ifeq ($(SYSTEM),Darwin)
246 ifneq ($(wildcard /usr/local/ssl/include),)
247 INCLUDES += /usr/local/ssl/include
248 endif
249 ifneq ($(wildcard /opt/local/include),)
250 INCLUDES += /opt/local/include
251 endif
252 ifneq ($(wildcard /usr/local/include),)
253 INCLUDES += /usr/local/include
254 endif
255 LIBS = m z
256 ifneq ($(wildcard /usr/local/ssl/lib),)
257 LDFLAGS += -L/usr/local/ssl/lib
258 endif
259 ifneq ($(wildcard /opt/local/lib),)
260 LDFLAGS += -L/opt/local/lib
261 endif
262 ifneq ($(wildcard /usr/local/lib),)
263 LDFLAGS += -L/usr/local/lib
264 endif
265 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700266
Craig Tiller841c8802015-09-10 13:06:37 -0700267 ifeq ($(SYSTEM),Linux)
Craig Tiller1b1e2382016-02-03 07:33:56 -0800268 LIBS = dl rt m pthread
Craig Tiller841c8802015-09-10 13:06:37 -0700269 LDFLAGS += -pthread
270 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800271
Craig Tiller841c8802015-09-10 13:06:37 -0700272 ifeq ($(SYSTEM),MINGW32)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100273 LIBS = m pthread ws2_32
Craig Tiller841c8802015-09-10 13:06:37 -0700274 LDFLAGS += -pthread
275 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700276
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700277 #
278 # The steps for cross-compiling are as follows:
279 # First, clone and make install of grpc using the native compilers for the host.
280 # Also, install protoc (e.g., from a package like apt-get)
281 # Then clone a fresh grpc for the actual cross-compiled build
282 # Set the environment variable GRPC_CROSS_COMPILE to true
283 # Set CC, CXX, LD, LDXX, AR, and STRIP to the cross-compiling binaries
284 # Also set PROTOBUF_CONFIG_OPTS to indicate cross-compilation to protobuf (e.g.,
285 # PROTOBUF_CONFIG_OPTS="--host=arm-linux --with-protoc=/usr/local/bin/protoc" )
286 # Set HAS_PKG_CONFIG=false
287 # To build tests, go to third_party/gflags and follow its ccmake instructions
288 # Make sure that you enable building shared libraries and set your prefix to
289 # something useful like /usr/local/cross
290 # You will also need to set GRPC_CROSS_LDOPTS and GRPC_CROSS_AROPTS to hold
291 # additional required arguments for LD and AR (examples below)
292 # Then you can do a make from the cross-compiling fresh clone!
293 #
294 ifeq ($(GRPC_CROSS_COMPILE),true)
295 LDFLAGS += $(GRPC_CROSS_LDOPTS) # e.g. -L/usr/local/lib -L/usr/local/cross/lib
296 AROPTS = $(GRPC_CROSS_AROPTS) # e.g., rc --target=elf32-little
297 USE_BUILT_PROTOC = false
298 endif
299
Mahak Mukhifb059a22017-04-18 14:40:00 -0700300 GTEST_LIB = -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googletest third_party/googletest/googletest/src/gtest-all.cc -Ithird_party/googletest/googlemock/include -Ithird_party/googletest/googlemock third_party/googletest/googlemock/src/gmock-all.cc
Craig Tiller841c8802015-09-10 13:06:37 -0700301 GTEST_LIB += -lgflags
302 ifeq ($(V),1)
303 E = @:
304 Q =
305 else
306 E = @echo
307 Q = @
308 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800309
Craig Tiller38b99e92016-09-15 16:18:09 -0700310 CORE_VERSION = ${settings.core_version}
311 CPP_VERSION = ${settings.cpp_version}
312 CSHARP_VERSION = ${settings.csharp_version}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800313
Craig Tiller841c8802015-09-10 13:06:37 -0700314 CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
315 CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800316
Craig Tiller841c8802015-09-10 13:06:37 -0700317 LDFLAGS += $(ARCH_FLAGS)
318 LDLIBS += $(addprefix -l, $(LIBS))
319 LDLIBSXX += $(addprefix -l, $(LIBSXX))
nnoble72309c62014-12-12 11:42:26 -0800320
murgatroid99c36f6ea2016-10-03 09:24:09 -0700321
322 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES', 'LDLIBS']:
323 ${arg} += $(EXTRA_${arg})
324 % endfor
325
Craig Tiller841c8802015-09-10 13:06:37 -0700326 HOST_CPPFLAGS = $(CPPFLAGS)
327 HOST_CFLAGS = $(CFLAGS)
328 HOST_CXXFLAGS = $(CXXFLAGS)
329 HOST_LDFLAGS = $(LDFLAGS)
330 HOST_LDLIBS = $(LDLIBS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800331
Craig Tiller841c8802015-09-10 13:06:37 -0700332 # These are automatically computed variables.
333 # There shouldn't be any need to change anything from now on.
nnoble69ac39f2014-12-12 15:43:38 -0800334
Craig Tiller841c8802015-09-10 13:06:37 -0700335 -include cache.mk
murgatroid9924e2f4a2015-06-29 11:12:01 -0700336
Craig Tiller841c8802015-09-10 13:06:37 -0700337 CACHE_MK =
murgatroid99aa521572015-07-10 14:49:12 -0700338
Craig Tiller841c8802015-09-10 13:06:37 -0700339 HAS_PKG_CONFIG ?= $(shell command -v $(PKG_CONFIG) >/dev/null 2>&1 && echo true || echo false)
murgatroid99aa521572015-07-10 14:49:12 -0700340
Craig Tiller841c8802015-09-10 13:06:37 -0700341 ifeq ($(HAS_PKG_CONFIG), true)
342 CACHE_MK += HAS_PKG_CONFIG = true,
343 endif
nnoble69ac39f2014-12-12 15:43:38 -0800344
Craig Tiller38b99e92016-09-15 16:18:09 -0700345 CORE_PC_TEMPLATE = prefix=$(prefix),\
Craig Tiller841c8802015-09-10 13:06:37 -0700346 exec_prefix=${'\$${prefix}'},\
347 includedir=${'\$${prefix}'}/include,\
348 libdir=${'\$${exec_prefix}'}/lib,\
349 ,\
350 Name: $(PC_NAME),\
351 Description: $(PC_DESCRIPTION),\
Craig Tiller38b99e92016-09-15 16:18:09 -0700352 Version: $(CORE_VERSION),\
353 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
354 Requires.private: $(PC_REQUIRES_PRIVATE),\
355 Libs: -L${'\$${libdir}'} $(PC_LIB),\
356 Libs.private: $(PC_LIBS_PRIVATE)
357
358 CPP_PC_TEMPLATE = prefix=$(prefix),\
359 exec_prefix=${'\$${prefix}'},\
360 includedir=${'\$${prefix}'}/include,\
361 libdir=${'\$${exec_prefix}'}/lib,\
362 ,\
363 Name: $(PC_NAME),\
364 Description: $(PC_DESCRIPTION),\
365 Version: $(CPP_VERSION),\
366 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
367 Requires.private: $(PC_REQUIRES_PRIVATE),\
368 Libs: -L${'\$${libdir}'} $(PC_LIB),\
369 Libs.private: $(PC_LIBS_PRIVATE)
370
371 CSHARP_PC_TEMPLATE = prefix=$(prefix),\
372 exec_prefix=${'\$${prefix}'},\
373 includedir=${'\$${prefix}'}/include,\
374 libdir=${'\$${exec_prefix}'}/lib,\
375 ,\
376 Name: $(PC_NAME),\
377 Description: $(PC_DESCRIPTION),\
378 Version: $(CSHARP_VERSION),\
Craig Tiller841c8802015-09-10 13:06:37 -0700379 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
380 Requires.private: $(PC_REQUIRES_PRIVATE),\
381 Libs: -L${'\$${libdir}'} $(PC_LIB),\
382 Libs.private: $(PC_LIBS_PRIVATE)
murgatroid998faab232015-06-30 17:24:21 -0700383
Craig Tiller841c8802015-09-10 13:06:37 -0700384 ifeq ($(SYSTEM),MINGW32)
Mario Emmenlauer121d2892016-12-12 23:49:27 +0100385 EXECUTABLE_SUFFIX = .exe
Craig Tiller38b99e92016-09-15 16:18:09 -0700386 SHARED_EXT_CORE = dll
387 SHARED_EXT_CPP = dll
388 SHARED_EXT_CSHARP = dll
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100389 SHARED_PREFIX =
Craig Tiller27f70842016-09-15 16:21:54 -0700390 SHARED_VERSION_CORE = -${settings.core_version.major}
391 SHARED_VERSION_CPP = -${settings.cpp_version.major}
392 SHARED_VERSION_CSHARP = -${settings.csharp_version.major}
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100393 else ifeq ($(SYSTEM),Darwin)
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800394 EXECUTABLE_SUFFIX =
Craig Tiller38b99e92016-09-15 16:18:09 -0700395 SHARED_EXT_CORE = dylib
396 SHARED_EXT_CPP = dylib
397 SHARED_EXT_CSHARP = dylib
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100398 SHARED_PREFIX = lib
Craig Tiller27f70842016-09-15 16:21:54 -0700399 SHARED_VERSION_CORE =
400 SHARED_VERSION_CPP =
401 SHARED_VERSION_CSHARP =
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100402 else
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800403 EXECUTABLE_SUFFIX =
Craig Tiller38b99e92016-09-15 16:18:09 -0700404 SHARED_EXT_CORE = so.$(CORE_VERSION)
405 SHARED_EXT_CPP = so.$(CPP_VERSION)
406 SHARED_EXT_CSHARP = so.$(CSHARP_VERSION)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100407 SHARED_PREFIX = lib
Craig Tiller27f70842016-09-15 16:21:54 -0700408 SHARED_VERSION_CORE =
409 SHARED_VERSION_CPP =
410 SHARED_VERSION_CSHARP =
Craig Tiller841c8802015-09-10 13:06:37 -0700411 endif
nnoble5b7f32a2014-12-22 08:12:44 -0800412
Craig Tiller841c8802015-09-10 13:06:37 -0700413 ifeq ($(wildcard .git),)
414 IS_GIT_FOLDER = false
415 else
416 IS_GIT_FOLDER = true
417 endif
nnoble69ac39f2014-12-12 15:43:38 -0800418
Craig Tiller841c8802015-09-10 13:06:37 -0700419 ifeq ($(HAS_PKG_CONFIG),true)
420 OPENSSL_ALPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.2 openssl
Craig Tiller841c8802015-09-10 13:06:37 -0700421 ZLIB_CHECK_CMD = $(PKG_CONFIG) --exists zlib
Srini Polavarapucdc0e282018-03-26 18:16:15 -0700422 PROTOBUF_CHECK_CMD = $(PKG_CONFIG) --atleast-version=3.5.0 protobuf
Yuchen Zengf8b6d6f2017-06-02 15:36:25 -0700423 CARES_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.11.0 libcares
Craig Tiller841c8802015-09-10 13:06:37 -0700424 else # HAS_PKG_CONFIG
murgatroid9924e2f4a2015-06-29 11:12:01 -0700425
Craig Tiller841c8802015-09-10 13:06:37 -0700426 ifeq ($(SYSTEM),MINGW32)
427 OPENSSL_LIBS = ssl32 eay32
428 else
429 OPENSSL_LIBS = ssl crypto
430 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700431
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100432 OPENSSL_ALPN_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
Craig Tillerb79c1e12016-02-23 10:00:58 -0800433 BORINGSSL_COMPILE_CHECK_CMD = $(CC) $(CPPFLAGS) ${defaults.boringssl.CPPFLAGS} $(CFLAGS) ${defaults.boringssl.CFLAGS} -o $(TMPOUT) test/build/boringssl.c $(LDFLAGS)
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100434 ZLIB_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
435 PROTOBUF_CHECK_CMD = $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700436 CARES_CHECK_CMD = $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $(TMPOUT) test/build/c-ares.c -lcares $(LDFLAGS)
Craig Tiller297fafa2015-01-15 15:46:39 -0800437
Craig Tiller841c8802015-09-10 13:06:37 -0700438 endif # HAS_PKG_CONFIG
murgatroid9924e2f4a2015-06-29 11:12:01 -0700439
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100440 PERFTOOLS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
murgatroid996d9e4012015-07-08 10:22:45 -0700441
Craig Tiller841c8802015-09-10 13:06:37 -0700442 PROTOC_CHECK_CMD = which protoc > /dev/null
443 PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3
444 DTRACE_CHECK_CMD = which dtrace > /dev/null
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100445 SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS)
murgatroid9924e2f4a2015-06-29 11:12:01 -0700446
Craig Tiller841c8802015-09-10 13:06:37 -0700447 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
448 HAS_SYSTEM_PERFTOOLS ?= $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
449 ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
450 DEFINES += GRPC_HAVE_PERFTOOLS
451 LIBS += profiler
452 CACHE_MK += HAS_SYSTEM_PERFTOOLS = true,
453 endif
454 endif
nnoble69ac39f2014-12-12 15:43:38 -0800455
Craig Tiller841c8802015-09-10 13:06:37 -0700456 HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
457 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
458 HAS_SYSTEM_OPENSSL_ALPN ?= $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
459 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
Craig Tiller841c8802015-09-10 13:06:37 -0700460 CACHE_MK += HAS_SYSTEM_OPENSSL_ALPN = true,
Craig Tiller841c8802015-09-10 13:06:37 -0700461 endif
462 HAS_SYSTEM_ZLIB ?= $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
463 ifeq ($(HAS_SYSTEM_ZLIB),true)
464 CACHE_MK += HAS_SYSTEM_ZLIB = true,
465 endif
466 HAS_SYSTEM_PROTOBUF ?= $(HAS_SYSTEM_PROTOBUF_VERIFY)
467 ifeq ($(HAS_SYSTEM_PROTOBUF),true)
468 CACHE_MK += HAS_SYSTEM_PROTOBUF = true,
469 endif
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700470 HAS_SYSTEM_CARES ?= $(shell $(CARES_CHECK_CMD) 2> /dev/null && echo true || echo false)
471 ifeq ($(HAS_SYSTEM_CARES),true)
472 CACHE_MK += HAS_SYSTEM_CARES = true,
473 endif
Craig Tiller841c8802015-09-10 13:06:37 -0700474 else
475 # override system libraries if the config requires a custom compiled library
476 HAS_SYSTEM_OPENSSL_ALPN = false
Craig Tiller841c8802015-09-10 13:06:37 -0700477 HAS_SYSTEM_ZLIB = false
478 HAS_SYSTEM_PROTOBUF = false
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700479 HAS_SYSTEM_CARES = false
Craig Tiller841c8802015-09-10 13:06:37 -0700480 endif
nnoble69ac39f2014-12-12 15:43:38 -0800481
Craig Tiller841c8802015-09-10 13:06:37 -0700482 HAS_PROTOC ?= $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
483 ifeq ($(HAS_PROTOC),true)
484 CACHE_MK += HAS_PROTOC = true,
485 HAS_VALID_PROTOC ?= $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false)
486 ifeq ($(HAS_VALID_PROTOC),true)
487 CACHE_MK += HAS_VALID_PROTOC = true,
488 endif
489 else
490 HAS_VALID_PROTOC = false
491 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800492
Craig Tiller841c8802015-09-10 13:06:37 -0700493 # Check for Systemtap (https://sourceware.org/systemtap/), first by making sure <sys/sdt.h> is present
494 # in the system and secondly by checking for the "dtrace" binary (on Linux, this is part of the Systemtap
495 # distribution. It's part of the base system on BSD/Solaris machines).
496 ifndef HAS_SYSTEMTAP
497 HAS_SYSTEMTAP_HEADERS = $(shell $(SYSTEMTAP_HEADERS_CHECK_CMD) 2> /dev/null && echo true || echo false)
498 HAS_DTRACE = $(shell $(DTRACE_CHECK_CMD) 2> /dev/null && echo true || echo false)
499 HAS_SYSTEMTAP = false
500 ifeq ($(HAS_SYSTEMTAP_HEADERS),true)
501 ifeq ($(HAS_DTRACE),true)
502 HAS_SYSTEMTAP = true
503 endif
504 endif
505 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -0700506
Craig Tiller841c8802015-09-10 13:06:37 -0700507 ifeq ($(HAS_SYSTEMTAP),true)
508 CACHE_MK += HAS_SYSTEMTAP = true,
509 endif
nnoble69ac39f2014-12-12 15:43:38 -0800510
Craig Tiller841c8802015-09-10 13:06:37 -0700511 # Note that for testing purposes, one can do:
512 # make HAS_EMBEDDED_OPENSSL_ALPN=false
513 # to emulate the fact we do not have OpenSSL in the third_party folder.
Craig Tillerb79c1e12016-02-23 10:00:58 -0800514 ifneq ($(wildcard third_party/${openssl_fallback.extraction_dir}/libssl.a),)
515 HAS_EMBEDDED_OPENSSL_ALPN = third_party/${openssl_fallback.extraction_dir}
516 else ifeq ($(wildcard third_party/boringssl/include/openssl/ssl.h),)
Craig Tiller841c8802015-09-10 13:06:37 -0700517 HAS_EMBEDDED_OPENSSL_ALPN = false
518 else
Craig Tillerb79c1e12016-02-23 10:00:58 -0800519 CAN_COMPILE_EMBEDDED_OPENSSL ?= $(shell $(BORINGSSL_COMPILE_CHECK_CMD) 2> /dev/null && echo true || echo false)
520 HAS_EMBEDDED_OPENSSL_ALPN = $(CAN_COMPILE_EMBEDDED_OPENSSL)
Craig Tiller841c8802015-09-10 13:06:37 -0700521 endif
nnoble69ac39f2014-12-12 15:43:38 -0800522
Craig Tiller841c8802015-09-10 13:06:37 -0700523 ifeq ($(wildcard third_party/zlib/zlib.h),)
524 HAS_EMBEDDED_ZLIB = false
525 else
526 HAS_EMBEDDED_ZLIB = true
527 endif
nnoble69ac39f2014-12-12 15:43:38 -0800528
Craig Tiller841c8802015-09-10 13:06:37 -0700529 ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
530 HAS_EMBEDDED_PROTOBUF = false
531 ifneq ($(HAS_VALID_PROTOC),true)
532 NO_PROTOC = true
533 endif
534 else
535 HAS_EMBEDDED_PROTOBUF = true
536 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800537
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800538 ifeq ($(wildcard third_party/cares/cares/ares.h),)
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700539 HAS_EMBEDDED_CARES = false
540 else
541 HAS_EMBEDDED_CARES = true
542 endif
543
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100544 PC_REQUIRES_GRPC =
Craig Tiller841c8802015-09-10 13:06:37 -0700545 PC_LIBS_GRPC =
murgatroid998faab232015-06-30 17:24:21 -0700546
Craig Tiller841c8802015-09-10 13:06:37 -0700547 ifeq ($(HAS_SYSTEM_ZLIB),false)
Craig Tiller3dca23a2016-01-21 11:44:55 -0800548 ifeq ($(HAS_EMBEDDED_ZLIB), true)
549 EMBED_ZLIB ?= true
Craig Tiller841c8802015-09-10 13:06:37 -0700550 else
551 DEP_MISSING += zlib
Craig Tiller3dca23a2016-01-21 11:44:55 -0800552 EMBED_ZLIB ?= broken
Craig Tiller841c8802015-09-10 13:06:37 -0700553 endif
554 else
Craig Tiller3dca23a2016-01-21 11:44:55 -0800555 EMBED_ZLIB ?= false
556 endif
557
558 ifeq ($(EMBED_ZLIB),true)
559 ZLIB_DEP = $(LIBDIR)/$(CONFIG)/libz.a
560 ZLIB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libz.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +0100561 ZLIB_MERGE_OBJS = $(LIBZ_OBJS)
Craig Tiller3dca23a2016-01-21 11:44:55 -0800562 CPPFLAGS += -Ithird_party/zlib
Craig Tiller3dca23a2016-01-21 11:44:55 -0800563 else
Craig Tiller841c8802015-09-10 13:06:37 -0700564 ifeq ($(HAS_PKG_CONFIG),true)
565 CPPFLAGS += $(shell $(PKG_CONFIG) --cflags zlib)
566 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L zlib)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800567 LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l zlib))
Craig Tiller841c8802015-09-10 13:06:37 -0700568 PC_REQUIRES_GRPC += zlib
569 else
570 PC_LIBS_GRPC += -lz
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800571 LIBS += z
Craig Tiller841c8802015-09-10 13:06:37 -0700572 endif
573 endif
nnoble69ac39f2014-12-12 15:43:38 -0800574
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700575 CARES_PKG_CONFIG = false
576
Yuchen Zengb1b21152016-08-12 11:27:30 -0700577 ifeq ($(HAS_SYSTEM_CARES),false)
578 ifeq ($(HAS_EMBEDDED_CARES), true)
579 EMBED_CARES ?= true
580 else
581 DEP_MISSING += cares
582 EMBED_CARES ?= broken
583 endif
584 else
585 EMBED_CARES ?= false
586 endif
587
Alexander Polcyn690dde62017-10-18 00:20:33 -0700588 ADDRESS_SORTING_DEP = $(LIBDIR)/$(CONFIG)/libaddress_sorting.a
589 ADDRESS_SORTING_MERGE_OBJS = $(LIBADDRESS_SORTING_OBJS)
590 ADDRESS_SORTING_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libaddress_sorting.a
Alex Polcyn77f64f72018-03-01 19:22:53 +0000591 CPPFLAGS := -Ithird_party/address_sorting/include $(CPPFLAGS)
Alexander Polcyn690dde62017-10-18 00:20:33 -0700592
Yuchen Zengb1b21152016-08-12 11:27:30 -0700593 ifeq ($(EMBED_CARES),true)
Yuchen Zeng15141a62016-08-17 18:56:04 -0700594 CARES_DEP = $(LIBDIR)/$(CONFIG)/libares.a
595 CARES_MERGE_OBJS = $(LIBARES_OBJS)
596 CARES_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libares.a
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800597 CPPFLAGS := -Ithird_party/cares -Ithird_party/cares/cares $(CPPFLAGS)
Yuchen Zengb1b21152016-08-12 11:27:30 -0700598 else
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700599 ifeq ($(HAS_PKG_CONFIG),true)
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700600 PC_REQUIRES_GRPC += libcares
601 CPPFLAGS += $(shell $(PKG_CONFIG) --cflags libcares)
Yuchen Zengdf2a7b72016-08-18 14:57:03 -0700602 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libcares)
603 LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l libcares))
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700604 else
605 PC_LIBS_GRPC += -lcares
Yuchen Zengdf2a7b72016-08-18 14:57:03 -0700606 LIBS += cares
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700607 endif
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700608 endif
609
Craig Tiller841c8802015-09-10 13:06:37 -0700610 OPENSSL_PKG_CONFIG = false
murgatroid99da7a9942015-06-29 14:57:37 -0700611
Craig Tiller841c8802015-09-10 13:06:37 -0700612 PC_REQUIRES_SECURE =
613 PC_LIBS_SECURE =
murgatroid998faab232015-06-30 17:24:21 -0700614
Craig Tiller841c8802015-09-10 13:06:37 -0700615 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800616 EMBED_OPENSSL ?= false
617 NO_SECURE ?= false
618 else # HAS_SYSTEM_OPENSSL_ALPN=false
Craig Tillerb79c1e12016-02-23 10:00:58 -0800619 ifneq ($(HAS_EMBEDDED_OPENSSL_ALPN),false)
620 EMBED_OPENSSL ?= $(HAS_EMBEDDED_OPENSSL_ALPN)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800621 NO_SECURE ?= false
622 else # HAS_EMBEDDED_OPENSSL_ALPN=false
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800623 NO_SECURE ?= true
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800624 endif # HAS_EMBEDDED_OPENSSL_ALPN
625 endif # HAS_SYSTEM_OPENSSL_ALPN
626
627 OPENSSL_DEP :=
628 OPENSSL_MERGE_LIBS :=
629 ifeq ($(NO_SECURE),false)
630 ifeq ($(EMBED_OPENSSL),true)
631 OPENSSL_DEP += $(LIBDIR)/$(CONFIG)/libboringssl.a
632 OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/libboringssl.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +0100633 OPENSSL_MERGE_OBJS += $(LIBBORINGSSL_OBJS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800634 # need to prefix these to ensure overriding system libraries
635 CPPFLAGS := -Ithird_party/boringssl/include $(CPPFLAGS)
Craig Tillerb79c1e12016-02-23 10:00:58 -0800636 else ifneq ($(EMBED_OPENSSL),false)
637 OPENSSL_DEP += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
638 OPENSSL_MERGE_LIBS += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
639 OPENSSL_MERGE_OBJS += $(wildcard $(EMBED_OPENSSL)/grpc_obj/*.o)
640 # need to prefix these to ensure overriding system libraries
641 CPPFLAGS := -I$(EMBED_OPENSSL)/include $(CPPFLAGS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800642 else # EMBED_OPENSSL=false
Craig Tiller841c8802015-09-10 13:06:37 -0700643 ifeq ($(HAS_PKG_CONFIG),true)
644 OPENSSL_PKG_CONFIG = true
645 PC_REQUIRES_SECURE = openssl
646 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags openssl) $(CPPFLAGS)
647 LDFLAGS_OPENSSL_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L openssl)
648 ifeq ($(SYSTEM),Linux)
649 ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),)
650 LDFLAGS_OPENSSL_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L openssl | sed s/L/Wl,-rpath,/)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800651 endif # LDFLAGS_OPENSSL_PKG_CONFIG=''
652 endif # System=Linux
Craig Tiller841c8802015-09-10 13:06:37 -0700653 LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800654 else # HAS_PKG_CONFIG=false
Craig Tiller841c8802015-09-10 13:06:37 -0700655 LIBS_SECURE = $(OPENSSL_LIBS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800656 endif # HAS_PKG_CONFIG
Nicolas "Pixel" Noble494d65d2018-05-15 00:06:04 +0200657 ifeq ($(DISABLE_ALPN),true)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800658 CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0
659 LIBS_SECURE = $(OPENSSL_LIBS)
Nicolas "Pixel" Noble494d65d2018-05-15 00:06:04 +0200660 endif # DISABLE_ALPN
Craig Tiller841c8802015-09-10 13:06:37 -0700661 PC_LIBS_SECURE = $(addprefix -l, $(LIBS_SECURE))
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800662 endif # EMBED_OPENSSL
663 endif # NO_SECURE
nnoble69ac39f2014-12-12 15:43:38 -0800664
Craig Tiller841c8802015-09-10 13:06:37 -0700665 ifeq ($(OPENSSL_PKG_CONFIG),true)
666 LDLIBS_SECURE += $(shell $(PKG_CONFIG) --libs-only-l openssl)
667 else
668 LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
669 endif
nnoble5b7f32a2014-12-22 08:12:44 -0800670
Craig Tiller841c8802015-09-10 13:06:37 -0700671 # grpc .pc file
672 PC_NAME = gRPC
Craig Tillerda179ce2016-02-09 12:01:53 -0800673 PC_DESCRIPTION = high performance general RPC framework
674 PC_CFLAGS =
675 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC) $(PC_REQUIRES_SECURE)
Craig Tiller841c8802015-09-10 13:06:37 -0700676 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) $(PC_LIBS_SECURE)
677 PC_LIB = -lgrpc
Craig Tiller38b99e92016-09-15 16:18:09 -0700678 GRPC_PC_FILE := $(CORE_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700679
Craig Tiller4a67be42016-02-09 12:40:32 -0800680 # grpc_unsecure .pc file
Craig Tiller841c8802015-09-10 13:06:37 -0700681 PC_NAME = gRPC unsecure
Craig Tillerda179ce2016-02-09 12:01:53 -0800682 PC_DESCRIPTION = high performance general RPC framework without SSL
683 PC_CFLAGS =
684 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC)
Craig Tiller841c8802015-09-10 13:06:37 -0700685 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC)
686 PC_LIB = -lgrpc
Craig Tiller38b99e92016-09-15 16:18:09 -0700687 GRPC_UNSECURE_PC_FILE := $(CORE_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700688
Craig Tiller841c8802015-09-10 13:06:37 -0700689 PROTOBUF_PKG_CONFIG = false
murgatroid99da7a9942015-06-29 14:57:37 -0700690
Craig Tiller841c8802015-09-10 13:06:37 -0700691 PC_REQUIRES_GRPCXX =
692 PC_LIBS_GRPCXX =
murgatroid998faab232015-06-30 17:24:21 -0700693
Mahak Mukhifb059a22017-04-18 14:40:00 -0700694 CPPFLAGS := -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googlemock/include $(CPPFLAGS)
Craig Tiller16f6dac2015-08-24 17:00:04 -0700695
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700696 PROTOC_PLUGINS_ALL =\
697 % for tgt in targets:
698 % if tgt.build == 'protoc':
699 $(BINDIR)/$(CONFIG)/${tgt.name}\
700 % endif
701 % endfor
702
703 PROTOC_PLUGINS_DIR = $(BINDIR)/$(CONFIG)
704
Craig Tiller841c8802015-09-10 13:06:37 -0700705 ifeq ($(HAS_SYSTEM_PROTOBUF),true)
706 ifeq ($(HAS_PKG_CONFIG),true)
707 PROTOBUF_PKG_CONFIG = true
708 PC_REQUIRES_GRPCXX = protobuf
709 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags protobuf) $(CPPFLAGS)
710 LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L protobuf)
711 ifeq ($(SYSTEM),Linux)
712 ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),)
713 LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L protobuf | sed s/L/Wl,-rpath,/)
714 endif
715 endif
716 else
717 PC_LIBS_GRPCXX = -lprotobuf
718 endif
Nicolas "Pixel" Noblef7fbdd42016-07-25 20:31:22 +0200719 PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
Craig Tiller841c8802015-09-10 13:06:37 -0700720 else
721 ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
722 PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
723 CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
724 LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700725 ifneq ($(USE_BUILT_PROTOC),false)
Craig Tiller841c8802015-09-10 13:06:37 -0700726 PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700727 PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
728 else
729 PROTOC_PLUGINS =
730 PROTOC_PLUGINS_DIR = $(prefix)/bin
731 endif
Craig Tiller841c8802015-09-10 13:06:37 -0700732 else
733 NO_PROTOBUF = true
734 endif
735 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800736
Craig Tiller841c8802015-09-10 13:06:37 -0700737 LIBS_PROTOBUF = protobuf
738 LIBS_PROTOC = protoc protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800739
Craig Tiller841c8802015-09-10 13:06:37 -0700740 HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
Nicolas Noble53830622015-02-12 16:56:38 -0800741
Craig Tiller841c8802015-09-10 13:06:37 -0700742 ifeq ($(PROTOBUF_PKG_CONFIG),true)
743 LDLIBS_PROTOBUF += $(shell $(PKG_CONFIG) --libs-only-l protobuf)
744 else
745 LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
746 endif
murgatroid9924e2f4a2015-06-29 11:12:01 -0700747
Craig Tiller841c8802015-09-10 13:06:37 -0700748 # grpc++ .pc file
749 PC_NAME = gRPC++
750 PC_DESCRIPTION = C++ wrapper for gRPC
751 PC_CFLAGS =
752 PC_REQUIRES_PRIVATE = grpc $(PC_REQUIRES_GRPCXX)
753 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
754 PC_LIB = -lgrpc++
Craig Tiller38b99e92016-09-15 16:18:09 -0700755 GRPCXX_PC_FILE := $(CPP_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700756
Craig Tiller841c8802015-09-10 13:06:37 -0700757 # grpc++_unsecure .pc file
758 PC_NAME = gRPC++ unsecure
759 PC_DESCRIPTION = C++ wrapper for gRPC without SSL
760 PC_CFLAGS =
761 PC_REQUIRES_PRIVATE = grpc_unsecure $(PC_REQUIRES_GRPCXX)
762 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
763 PC_LIB = -lgrpc++
Craig Tiller38b99e92016-09-15 16:18:09 -0700764 GRPCXX_UNSECURE_PC_FILE := $(CPP_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700765
Craig Tiller841c8802015-09-10 13:06:37 -0700766 ifeq ($(MAKECMDGOALS),clean)
767 NO_DEPS = true
768 endif
nnoble69ac39f2014-12-12 15:43:38 -0800769
Craig Tiller841c8802015-09-10 13:06:37 -0700770 .SECONDARY = %.pb.h %.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800771
Craig Tiller841c8802015-09-10 13:06:37 -0700772 ifeq ($(DEP_MISSING),)
773 all: static shared plugins\
774 % for tgt in targets:
775 % if tgt.build == 'all':
776 $(BINDIR)/$(CONFIG)/${tgt.name}\
777 % endif
778 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800779
Craig Tiller841c8802015-09-10 13:06:37 -0700780 dep_error:
781 @echo "You shouldn't see this message - all of your dependencies are correct."
782 else
783 all: dep_error git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800784
Craig Tiller841c8802015-09-10 13:06:37 -0700785 dep_error:
786 @echo
787 @echo "DEPENDENCY ERROR"
788 @echo
789 @echo "You are missing system dependencies that are essential to build grpc,"
790 @echo "and the third_party directory doesn't have them:"
791 @echo
792 @echo " $(DEP_MISSING)"
793 @echo
794 @echo "Installing the development packages for your system will solve"
795 @echo "this issue. Please consult INSTALL to get more information."
796 @echo
797 @echo "If you need information about why these tests failed, run:"
798 @echo
799 @echo " make run_dep_checks"
800 @echo
801 endif
nnoble69ac39f2014-12-12 15:43:38 -0800802
Craig Tiller841c8802015-09-10 13:06:37 -0700803 git_update:
804 ifeq ($(IS_GIT_FOLDER),true)
805 @echo "Additionally, since you are in a git clone, you can download the"
806 @echo "missing dependencies in third_party by running the following command:"
807 @echo
808 @echo " git submodule update --init"
809 @echo
810 endif
nnoble69ac39f2014-12-12 15:43:38 -0800811
Craig Tiller841c8802015-09-10 13:06:37 -0700812 openssl_dep_error: openssl_dep_message git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800813
Craig Tiller841c8802015-09-10 13:06:37 -0700814 protobuf_dep_error: protobuf_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800815
Craig Tiller841c8802015-09-10 13:06:37 -0700816 protoc_dep_error: protoc_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800817
Craig Tiller841c8802015-09-10 13:06:37 -0700818 openssl_dep_message:
819 @echo
820 @echo "DEPENDENCY ERROR"
821 @echo
Craig Tillerb79c1e12016-02-23 10:00:58 -0800822 @echo "The target you are trying to run requires an OpenSSL implementation."
823 @echo "Your system doesn't have one, and either the third_party directory"
824 @echo "doesn't have it, or your compiler can't build BoringSSL."
Craig Tiller841c8802015-09-10 13:06:37 -0700825 @echo
826 @echo "Please consult INSTALL to get more information."
827 @echo
828 @echo "If you need information about why these tests failed, run:"
829 @echo
830 @echo " make run_dep_checks"
831 @echo
nnoble69ac39f2014-12-12 15:43:38 -0800832
Craig Tiller841c8802015-09-10 13:06:37 -0700833 protobuf_dep_message:
834 @echo
835 @echo "DEPENDENCY ERROR"
836 @echo
Srini Polavarapucdc0e282018-03-26 18:16:15 -0700837 @echo "The target you are trying to run requires protobuf 3.5.0+"
Craig Tiller841c8802015-09-10 13:06:37 -0700838 @echo "Your system doesn't have it, and neither does the third_party directory."
839 @echo
840 @echo "Please consult INSTALL to get more information."
841 @echo
842 @echo "If you need information about why these tests failed, run:"
843 @echo
844 @echo " make run_dep_checks"
845 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800846
Craig Tiller841c8802015-09-10 13:06:37 -0700847 protoc_dep_message:
848 @echo
849 @echo "DEPENDENCY ERROR"
850 @echo
Srini Polavarapucdc0e282018-03-26 18:16:15 -0700851 @echo "The target you are trying to run requires protobuf-compiler 3.5.0+"
Craig Tiller841c8802015-09-10 13:06:37 -0700852 @echo "Your system doesn't have it, and neither does the third_party directory."
853 @echo
854 @echo "Please consult INSTALL to get more information."
855 @echo
856 @echo "If you need information about why these tests failed, run:"
857 @echo
858 @echo " make run_dep_checks"
859 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800860
Craig Tiller841c8802015-09-10 13:06:37 -0700861 systemtap_dep_error:
862 @echo
863 @echo "DEPENDENCY ERROR"
864 @echo
865 @echo "Under the '$(CONFIG)' configutation, the target you are trying "
866 @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other "
867 @echo "platforms such as Solaris and *BSD). "
868 @echo
869 @echo "Please consult INSTALL to get more information."
870 @echo
David Garcia Quintas8954e902015-04-29 09:46:33 -0700871
Craig Tiller841c8802015-09-10 13:06:37 -0700872 stop:
873 @false
nnoble69ac39f2014-12-12 15:43:38 -0800874
Craig Tiller841c8802015-09-10 13:06:37 -0700875 % for tgt in targets:
876 ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
877 % endfor
ctiller09cb6d52014-12-19 17:38:22 -0800878
Craig Tiller841c8802015-09-10 13:06:37 -0700879 run_dep_checks:
880 $(OPENSSL_ALPN_CHECK_CMD) || true
Craig Tiller841c8802015-09-10 13:06:37 -0700881 $(ZLIB_CHECK_CMD) || true
882 $(PERFTOOLS_CHECK_CMD) || true
883 $(PROTOBUF_CHECK_CMD) || true
884 $(PROTOC_CHECK_VERSION_CMD) || true
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700885 $(CARES_CHECK_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800886
Craig Tiller841c8802015-09-10 13:06:37 -0700887 third_party/protobuf/configure:
888 $(E) "[AUTOGEN] Preparing protobuf"
889 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
Nicolas Noble53830622015-02-12 16:56:38 -0800890
Craig Tiller841c8802015-09-10 13:06:37 -0700891 $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
892 $(E) "[MAKE] Building protobuf"
Vijay Pai52338fb2018-01-11 00:25:00 -0800893 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700894 $(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g $(PROTOBUF_LDFLAGS_EXTRA)" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g $(PROTOBUF_CPPFLAGS_EXTRA)" ./configure --disable-shared --enable-static $(PROTOBUF_CONFIG_OPTS))
Craig Tiller841c8802015-09-10 13:06:37 -0700895 $(Q)$(MAKE) -C third_party/protobuf clean
896 $(Q)$(MAKE) -C third_party/protobuf
Craig Tiller841c8802015-09-10 13:06:37 -0700897 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
898 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
899 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
900 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800901
Craig Tiller841c8802015-09-10 13:06:37 -0700902 static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800903
Craig Tillereda85c62016-07-01 12:45:19 -0700904 static_c: pc_c pc_c_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700905 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100906 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700907 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
908 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
909 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100910 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700911 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800912
913
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100914 static_cxx: pc_cxx pc_cxx_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700915 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100916 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700917 % if lib.build == 'all' and lib.language == 'c++':
918 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
919 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100920 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700921 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800922
923
Craig Tiller841c8802015-09-10 13:06:37 -0700924 shared: shared_c shared_cxx
nnoble29e1d292014-12-01 10:27:40 -0800925
Craig Tillereda85c62016-07-01 12:45:19 -0700926 shared_c: pc_c pc_c_unsecure cache.mk\
Craig Tiller841c8802015-09-10 13:06:37 -0700927 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100928 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700929 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -0700930 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)\
Craig Tiller841c8802015-09-10 13:06:37 -0700931 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100932 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700933 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800934
Craig Tiller841c8802015-09-10 13:06:37 -0700935 shared_cxx: pc_cxx pc_cxx_unsecure cache.mk\
936 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100937 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700938 % if lib.build == 'all' and lib.language == 'c++':
Craig Tiller27f70842016-09-15 16:21:54 -0700939 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)\
Craig Tiller841c8802015-09-10 13:06:37 -0700940 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100941 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700942 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800943
944
Craig Tiller841c8802015-09-10 13:06:37 -0700945 shared_csharp: shared_c \
946 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100947 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700948 % if lib.build == 'all' and lib.language == 'csharp':
Craig Tiller27f70842016-09-15 16:21:54 -0700949 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)\
Craig Tiller841c8802015-09-10 13:06:37 -0700950 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100951 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700952 % endfor
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800953
Craig Tiller841c8802015-09-10 13:06:37 -0700954 grpc_csharp_ext: shared_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800955
Craig Tiller841c8802015-09-10 13:06:37 -0700956 plugins: $(PROTOC_PLUGINS)
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100957
Craig Tiller841c8802015-09-10 13:06:37 -0700958 privatelibs: privatelibs_c privatelibs_cxx
nnoble29e1d292014-12-01 10:27:40 -0800959
Craig Tiller841c8802015-09-10 13:06:37 -0700960 privatelibs_c: \
961 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100962 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800963 % if lib.build == 'private' and lib.language == 'c' and not lib.get('external_deps', None) and not lib.boringssl:
Craig Tiller841c8802015-09-10 13:06:37 -0700964 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
965 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100966 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700967 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800968
Craig Tiller841c8802015-09-10 13:06:37 -0700969 pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc
murgatroid998faab232015-06-30 17:24:21 -0700970
Craig Tiller841c8802015-09-10 13:06:37 -0700971 pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -0700972
Craig Tiller841c8802015-09-10 13:06:37 -0700973 pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc
murgatroid998faab232015-06-30 17:24:21 -0700974
Craig Tiller841c8802015-09-10 13:06:37 -0700975 pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800976
vjpai20410922016-06-15 09:21:42 -0700977 ifeq ($(EMBED_OPENSSL),true)
Craig Tiller841c8802015-09-10 13:06:37 -0700978 privatelibs_cxx: \
979 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100980 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700981 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None):
982 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
983 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100984 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700985 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -0700986
vjpai20410922016-06-15 09:21:42 -0700987 else
988 privatelibs_cxx: \
989 % for lib in libs:
990 % if 'Makefile' in lib.get('build_system', ['Makefile']):
991 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None) and not lib.boringssl:
992 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
993 % endif
994 % endif
995 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -0700996
vjpai20410922016-06-15 09:21:42 -0700997 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800998
999
Craig Tillereda85c62016-07-01 12:45:19 -07001000 buildtests: buildtests_c buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -08001001
Craig Tiller3824b6e2015-12-09 11:19:59 -08001002 buildtests_c: privatelibs_c <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001003 % for tgt in targets:
1004 % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -08001005 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001006 % endif
1007 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001008
1009
vjpai20410922016-06-15 09:21:42 -07001010 ifeq ($(EMBED_OPENSSL),true)
Craig Tillereda85c62016-07-01 12:45:19 -07001011 buildtests_cxx: privatelibs_cxx <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001012 % for tgt in targets:
1013 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -08001014 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001015 % endif
1016 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -07001017
vjpai20410922016-06-15 09:21:42 -07001018 else
Craig Tillereda85c62016-07-01 12:45:19 -07001019 buildtests_cxx: privatelibs_cxx <%text>\</%text>
vjpai20410922016-06-15 09:21:42 -07001020 % for tgt in targets:
1021 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl:
1022 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
1023 % endif
1024 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -07001025
vjpai20410922016-06-15 09:21:42 -07001026 endif
nnoble29e1d292014-12-01 10:27:40 -08001027
1028
Craig Tillereda85c62016-07-01 12:45:19 -07001029 test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -08001030
Craig Tillereda85c62016-07-01 12:45:19 -07001031 flaky_test: flaky_test_c flaky_test_cxx
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001032
Craig Tiller841c8802015-09-10 13:06:37 -07001033 test_c: buildtests_c
1034 % for tgt in targets:
1035 % if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++' and not tgt.get('flaky', False) and not tgt.get('external_deps', None):
1036 $(E) "[RUN] Testing ${tgt.name}"
1037 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1038 % endif
1039 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001040
1041
Craig Tiller841c8802015-09-10 13:06:37 -07001042 flaky_test_c: buildtests_c
1043 % for tgt in targets:
1044 % if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++' and tgt.get('flaky', False) and not tgt.get('external_deps', None):
1045 $(E) "[RUN] Testing ${tgt.name}"
1046 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1047 % endif
1048 % endfor
nnoble29e1d292014-12-01 10:27:40 -08001049
1050
Craig Tillereda85c62016-07-01 12:45:19 -07001051 test_cxx: buildtests_cxx
Craig Tiller841c8802015-09-10 13:06:37 -07001052 % for tgt in targets:
1053 % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and not tgt.get('flaky', False) and not tgt.get('external_deps', None):
1054 $(E) "[RUN] Testing ${tgt.name}"
1055 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1056 % endif
1057 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001058
1059
Craig Tiller841c8802015-09-10 13:06:37 -07001060 flaky_test_cxx: buildtests_cxx
1061 % for tgt in targets:
1062 % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and tgt.get('flaky', False) and not tgt.get('external_deps', None):
1063 $(E) "[RUN] Testing ${tgt.name}"
1064 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1065 % endif
1066 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001067
1068
Craig Tiller841c8802015-09-10 13:06:37 -07001069 test_python: static_c
1070 $(E) "[RUN] Testing python code"
1071 $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
Nicolas "Pixel" Noble051a28f2015-03-17 22:54:54 +01001072
1073
Craig Tiller841c8802015-09-10 13:06:37 -07001074 tools: tools_c tools_cxx
Craig Tiller7552f0f2015-06-19 17:46:20 -07001075
1076
Craig Tiller841c8802015-09-10 13:06:37 -07001077 tools_c: privatelibs_c\
1078 % for tgt in targets:
1079 % if tgt.build == 'tool' and not tgt.language=='c++':
1080 $(BINDIR)/$(CONFIG)/${tgt.name}\
1081 % endif
1082 % endfor
Craig Tiller7552f0f2015-06-19 17:46:20 -07001083
1084
Craig Tiller841c8802015-09-10 13:06:37 -07001085 tools_cxx: privatelibs_cxx\
1086 % for tgt in targets:
1087 % if tgt.build == 'tool' and tgt.language=='c++':
1088 $(BINDIR)/$(CONFIG)/${tgt.name}\
1089 % endif
1090 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001091
1092
Craig Tiller841c8802015-09-10 13:06:37 -07001093 buildbenchmarks: privatelibs\
1094 % for tgt in targets:
1095 % if tgt.build == 'benchmark':
1096 $(BINDIR)/$(CONFIG)/${tgt.name}\
1097 % endif
1098 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001099
1100
Craig Tiller841c8802015-09-10 13:06:37 -07001101 benchmarks: buildbenchmarks
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001102
Craig Tiller841c8802015-09-10 13:06:37 -07001103 strip: strip-static strip-shared
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001104
Craig Tiller841c8802015-09-10 13:06:37 -07001105 strip-static: strip-static_c strip-static_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001106
Craig Tiller841c8802015-09-10 13:06:37 -07001107 strip-shared: strip-shared_c strip-shared_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001108
Nicolas Noble047b7272015-01-16 13:55:05 -08001109
Craig Tiller841c8802015-09-10 13:06:37 -07001110 # TODO(nnoble): the strip target is stripping in-place, instead
1111 # of copying files in a temporary folder.
1112 # This prevents proper debugging after running make install.
Nicolas Noble047b7272015-01-16 13:55:05 -08001113
Craig Tiller841c8802015-09-10 13:06:37 -07001114 strip-static_c: static_c
1115 ifeq ($(CONFIG),opt)
1116 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001117 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001118 % if lib.language == "c":
1119 % if lib.build == "all":
1120 % if not lib.get('external_deps', None):
1121 $(E) "[STRIP] Stripping lib${lib.name}.a"
1122 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1123 % endif
1124 % endif
1125 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001126 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001127 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001128 endif
nnoble85a49262014-12-08 18:14:03 -08001129
Craig Tiller841c8802015-09-10 13:06:37 -07001130 strip-static_cxx: static_cxx
1131 ifeq ($(CONFIG),opt)
1132 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001133 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001134 % if lib.language == "c++":
1135 % if lib.build == "all":
1136 $(E) "[STRIP] Stripping lib${lib.name}.a"
1137 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1138 % endif
1139 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001140 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001141 % endfor
1142 endif
Nicolas "Pixel" Noble4ef9b862015-08-14 19:35:24 +02001143
Craig Tiller841c8802015-09-10 13:06:37 -07001144 strip-shared_c: shared_c
1145 ifeq ($(CONFIG),opt)
1146 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001147 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001148 % if lib.language == "c":
1149 % if lib.build == "all":
1150 % if not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -07001151 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)"
1152 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)
Craig Tiller841c8802015-09-10 13:06:37 -07001153 % endif
1154 % endif
1155 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001156 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001157 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001158 endif
nnoble85a49262014-12-08 18:14:03 -08001159
Craig Tiller841c8802015-09-10 13:06:37 -07001160 strip-shared_cxx: shared_cxx
1161 ifeq ($(CONFIG),opt)
1162 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001163 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001164 % if lib.language == "c++":
1165 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001166 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)"
1167 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)
Craig Tiller841c8802015-09-10 13:06:37 -07001168 % endif
1169 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001170 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001171 % endfor
1172 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001173
Craig Tiller841c8802015-09-10 13:06:37 -07001174 strip-shared_csharp: shared_csharp
1175 ifeq ($(CONFIG),opt)
1176 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001177 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001178 % if lib.language == "csharp":
1179 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001180 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)"
1181 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)
Craig Tiller841c8802015-09-10 13:06:37 -07001182 % endif
1183 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001184 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001185 % endfor
1186 endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001187
Craig Tiller841c8802015-09-10 13:06:37 -07001188 cache.mk::
1189 $(E) "[MAKE] Generating $@"
1190 $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@
murgatroid99aa521572015-07-10 14:49:12 -07001191
Craig Tiller841c8802015-09-10 13:06:37 -07001192 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc:
1193 $(E) "[MAKE] Generating $@"
1194 $(Q) mkdir -p $(@D)
1195 $(Q) echo "$(GRPC_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001196
Craig Tiller841c8802015-09-10 13:06:37 -07001197 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc:
1198 $(E) "[MAKE] Generating $@"
1199 $(Q) mkdir -p $(@D)
1200 $(Q) echo "$(GRPC_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001201
Craig Tiller841c8802015-09-10 13:06:37 -07001202 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc:
1203 $(E) "[MAKE] Generating $@"
1204 $(Q) mkdir -p $(@D)
1205 $(Q) echo "$(GRPCXX_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001206
Craig Tiller841c8802015-09-10 13:06:37 -07001207 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc:
1208 $(E) "[MAKE] Generating $@"
1209 $(Q) mkdir -p $(@D)
1210 $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001211
Craig Tiller841c8802015-09-10 13:06:37 -07001212 % for p in protos:
1213 ifeq ($(NO_PROTOC),true)
1214 $(GENDIR)/${p}.pb.cc: protoc_dep_error
1215 $(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error
1216 else
Mahak Mukhifb059a22017-04-18 14:40:00 -07001217 <%
1218 pluginflags=""
1219 %>
1220 % if p in ["src/proto/grpc/testing/compiler_test", "src/proto/grpc/testing/echo"]:
1221 <%
1222 pluginflags="generate_mock_code=true:"
1223 %>
1224 % endif
Craig Tiller1b4e3302015-12-17 16:35:00 -08001225 $(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) ${' '.join('$(GENDIR)/%s.pb.cc' % q for q in proto_deps.get(p, []))}
Craig Tiller841c8802015-09-10 13:06:37 -07001226 $(E) "[PROTOC] Generating protobuf CC file from $<"
1227 $(Q) mkdir -p `dirname $@`
David Garcia Quintase68ed6f2016-06-17 12:49:14 -07001228 $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --cpp_out=$(GENDIR) $<
Nicolas "Pixel" Noble0caebbf2015-04-09 23:08:51 +02001229
Vijay Paie00f2a32017-07-31 01:04:45 -07001230 $(GENDIR)/${p}.grpc.pb.cc: ${p}.proto $(GENDIR)/${p}.pb.cc $(PROTOBUF_DEP) $(PROTOC_PLUGINS) ${' '.join('$(GENDIR)/%s.pb.cc $(GENDIR)/%s.grpc.pb.cc' % (q,q) for q in proto_deps.get(p, []))}
Craig Tiller841c8802015-09-10 13:06:37 -07001231 $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
1232 $(Q) mkdir -p `dirname $@`
Mahak Mukhifb059a22017-04-18 14:40:00 -07001233 $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=${pluginflags}$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $<
Craig Tiller841c8802015-09-10 13:06:37 -07001234 endif
nnoble72309c62014-12-12 11:42:26 -08001235
Craig Tiller841c8802015-09-10 13:06:37 -07001236 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001237
Craig Tiller841c8802015-09-10 13:06:37 -07001238 ifeq ($(CONFIG),stapprof)
1239 src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h
1240 ifeq ($(HAS_SYSTEMTAP),true)
1241 $(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d
1242 $(E) "[DTRACE] Compiling $<"
1243 $(Q) mkdir -p `dirname $@`
1244 $(Q) $(DTRACE) -C -h -s $< -o $@
1245 else
1246 $(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop
1247 endif
1248 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -07001249
Craig Tiller841c8802015-09-10 13:06:37 -07001250 $(OBJDIR)/$(CONFIG)/%.o : %.c
1251 $(E) "[C] Compiling $<"
1252 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001253 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001254
Craig Tiller841c8802015-09-10 13:06:37 -07001255 $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
1256 $(E) "[CXX] Compiling $<"
1257 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001258 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001259
Craig Tiller841c8802015-09-10 13:06:37 -07001260 $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
1261 $(E) "[HOSTCXX] Compiling $<"
1262 $(Q) mkdir -p `dirname $@`
1263 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -08001264
ncteisenf9d7c272017-11-06 20:32:57 -08001265 $(OBJDIR)/$(CONFIG)/src/core/%.o : src/core/%.cc
1266 $(E) "[CXX] Compiling $<"
1267 $(Q) mkdir -p `dirname $@`
1268 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
1269
1270 $(OBJDIR)/$(CONFIG)/test/core/%.o : test/core/%.cc
1271 $(E) "[CXX] Compiling $<"
1272 $(Q) mkdir -p `dirname $@`
1273 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
1274
Craig Tiller841c8802015-09-10 13:06:37 -07001275 $(OBJDIR)/$(CONFIG)/%.o : %.cc
1276 $(E) "[CXX] Compiling $<"
1277 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001278 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001279
Nicolas "Pixel" Noblecbdf1322018-06-14 00:53:15 +02001280 $(OBJDIR)/$(CONFIG)/%.o : %.cpp
1281 $(E) "[CXX] Compiling $<"
1282 $(Q) mkdir -p `dirname $@`
1283 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
1284
murgatroid99a3c55352016-08-10 13:41:31 -07001285 install: install_c install_cxx install-plugins install-certs
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001286
Craig Tiller841c8802015-09-10 13:06:37 -07001287 install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001288
Craig Tiller841c8802015-09-10 13:06:37 -07001289 install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
nnoble85a49262014-12-08 18:14:03 -08001290
Craig Tiller841c8802015-09-10 13:06:37 -07001291 install_csharp: install-shared_csharp install_c
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001292
Craig Tiller841c8802015-09-10 13:06:37 -07001293 install_grpc_csharp_ext: install_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001294
Craig Tiller841c8802015-09-10 13:06:37 -07001295 install-headers: install-headers_c install-headers_cxx
nnoble85a49262014-12-08 18:14:03 -08001296
Craig Tiller841c8802015-09-10 13:06:37 -07001297 install-headers_c:
1298 $(E) "[INSTALL] Installing public C headers"
1299 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1300 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001301
Craig Tiller841c8802015-09-10 13:06:37 -07001302 install-headers_cxx:
1303 $(E) "[INSTALL] Installing public C++ headers"
1304 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1305 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001306
Craig Tiller841c8802015-09-10 13:06:37 -07001307 install-static: install-static_c install-static_cxx
nnoble85a49262014-12-08 18:14:03 -08001308
Craig Tiller841c8802015-09-10 13:06:37 -07001309 install-static_c: static_c strip-static_c install-pkg-config_c
1310 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001311 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001312 % if lib.language == "c":
1313 % if lib.build == "all":
1314 % if not lib.get('external_deps', None):
1315 $(E) "[INSTALL] Installing lib${lib.name}.a"
1316 $(Q) $(INSTALL) -d $(prefix)/lib
1317 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1318 % endif
1319 % endif
1320 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001321 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001322 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001323
Craig Tiller841c8802015-09-10 13:06:37 -07001324 install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx
1325 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001326 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001327 % if lib.language == "c++":
1328 % if lib.build == "all":
1329 $(E) "[INSTALL] Installing lib${lib.name}.a"
1330 $(Q) $(INSTALL) -d $(prefix)/lib
1331 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1332 % endif
1333 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001334 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001335 % endfor
nnoble85a49262014-12-08 18:14:03 -08001336
Craig Tiller841c8802015-09-10 13:06:37 -07001337 <%def name="install_shared(lang_filter)">\
1338 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001339 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001340 % if lib.language == lang_filter:
1341 % if lib.build == "all":
1342 % if not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -07001343 $(E) "[INSTALL] Installing $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]})"
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001344 $(Q) $(INSTALL) -d $(prefix)/lib
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001345 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) $(prefix)/lib/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]})
Craig Tiller841c8802015-09-10 13:06:37 -07001346 ifeq ($(SYSTEM),MINGW32)
Mario Emmenlauer44b2d082017-01-13 12:35:49 +01001347 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]})-dll.a $(prefix)/lib/lib${lib.name}.a
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001348 else ifneq ($(SYSTEM),Darwin)
Craig Tiller27f70842016-09-15 16:21:54 -07001349 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) $(prefix)/lib/lib${lib.name}.so.${settings.core_version.major}
1350 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) $(prefix)/lib/lib${lib.name}.so
Craig Tiller841c8802015-09-10 13:06:37 -07001351 endif
1352 % endif
1353 % endif
1354 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001355 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001356 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001357 ifneq ($(SYSTEM),MINGW32)
1358 ifneq ($(SYSTEM),Darwin)
1359 $(Q) ldconfig || true
1360 endif
1361 endif
1362 </%def>
nnoble85a49262014-12-08 18:14:03 -08001363
Craig Tiller841c8802015-09-10 13:06:37 -07001364 install-shared_c: shared_c strip-shared_c install-pkg-config_c
1365 ${install_shared("c")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001366
Craig Tiller841c8802015-09-10 13:06:37 -07001367 install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c install-pkg-config_cxx
1368 ${install_shared("c++")}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001369
Craig Tiller841c8802015-09-10 13:06:37 -07001370 install-shared_csharp: shared_csharp strip-shared_csharp
1371 ${install_shared("csharp")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001372
Craig Tiller841c8802015-09-10 13:06:37 -07001373 install-plugins: $(PROTOC_PLUGINS)
Craig Tiller841c8802015-09-10 13:06:37 -07001374 $(E) "[INSTALL] Installing grpc protoc plugins"
1375 % for tgt in targets:
1376 % if tgt.build == 'protoc':
1377 $(Q) $(INSTALL) -d $(prefix)/bin
1378 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
1379 % endif
1380 % endfor
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001381
Tobias Jungel5e176d52018-01-23 10:30:55 +01001382 install-grpc-cli: grpc_cli
1383 $(E) "[INSTALL] Installing grpc cli"
1384 $(Q) $(INSTALL) -d $(prefix)/bin
1385 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/grpc_cli $(prefix)/bin/grpc_cli
1386
Craig Tillereda85c62016-07-01 12:45:19 -07001387 install-pkg-config_c: pc_c pc_c_unsecure
Craig Tiller841c8802015-09-10 13:06:37 -07001388 $(E) "[INSTALL] Installing C pkg-config files"
1389 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
ncteisenbddedb92017-12-20 13:49:46 -05001390 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(prefix)/lib/pkgconfig/grpc.pc
1391 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(prefix)/lib/pkgconfig/grpc_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -07001392
Craig Tiller841c8802015-09-10 13:06:37 -07001393 install-pkg-config_cxx: pc_cxx pc_cxx_unsecure
1394 $(E) "[INSTALL] Installing C++ pkg-config files"
1395 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
ncteisenbddedb92017-12-20 13:49:46 -05001396 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc $(prefix)/lib/pkgconfig/grpc++.pc
1397 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc $(prefix)/lib/pkgconfig/grpc++_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -07001398
Craig Tiller841c8802015-09-10 13:06:37 -07001399 install-certs: etc/roots.pem
1400 $(E) "[INSTALL] Installing root certificates"
1401 $(Q) $(INSTALL) -d $(prefix)/share/grpc
1402 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +01001403
Craig Tiller841c8802015-09-10 13:06:37 -07001404 clean:
1405 $(E) "[CLEAN] Cleaning build directories."
1406 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001407
1408
Craig Tiller841c8802015-09-10 13:06:37 -07001409 # The various libraries
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001410
Craig Tiller841c8802015-09-10 13:06:37 -07001411 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001412 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001413 ${makelib(lib)}
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001414 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001415 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001416
1417
Craig Tiller841c8802015-09-10 13:06:37 -07001418 # All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001419
Craig Tiller841c8802015-09-10 13:06:37 -07001420 % for tgt in targets:
1421 ${maketarget(tgt)}
1422 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001423
Craig Tiller841c8802015-09-10 13:06:37 -07001424 <%def name="makelib(lib)">
1425 LIB${lib.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001426
Craig Tiller841c8802015-09-10 13:06:37 -07001427 % for src in lib.src:
1428 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001429
Craig Tiller841c8802015-09-10 13:06:37 -07001430 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001431
Craig Tiller841c8802015-09-10 13:06:37 -07001432 % if "public_headers" in lib:
1433 % if lib.language == "c++":
1434 PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001435
Craig Tiller841c8802015-09-10 13:06:37 -07001436 % else:
1437 PUBLIC_HEADERS_C += \\
nnoble85a49262014-12-08 18:14:03 -08001438
Craig Tiller841c8802015-09-10 13:06:37 -07001439 % endif
1440 % for hdr in lib.public_headers:
1441 ${hdr} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001442
Craig Tiller841c8802015-09-10 13:06:37 -07001443 % endfor
1444 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001445
Craig Tiller841c8802015-09-10 13:06:37 -07001446 LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001447
Nicolas "Pixel" Noble51b1aee2016-01-28 01:14:58 +01001448 % if lib.get('defaults', None):
1449 % for name, value in defaults.get(lib.defaults).iteritems():
1450 $(LIB${lib.name.upper()}_OBJS): ${name} += ${value}
1451 % endfor
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001452 % endif
1453
Craig Tiller841c8802015-09-10 13:06:37 -07001454 ## If the library requires OpenSSL, let's add some restrictions.
1455 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1456 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001457
Craig Tiller841c8802015-09-10 13:06:37 -07001458 # You can't build secure libraries if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001459
Craig Tiller841c8802015-09-10 13:06:37 -07001460 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001461
Craig Tiller841c8802015-09-10 13:06:37 -07001462 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001463 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}): openssl_dep_error
Craig Tiller841c8802015-09-10 13:06:37 -07001464 % endif
nnoble5b7f32a2014-12-22 08:12:44 -08001465
Craig Tiller841c8802015-09-10 13:06:37 -07001466 else
nnoble69ac39f2014-12-12 15:43:38 -08001467
Craig Tiller841c8802015-09-10 13:06:37 -07001468 % if lib.language == 'c++':
1469 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001470
Craig Tiller841c8802015-09-10 13:06:37 -07001471 # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
Nicolas Noble53830622015-02-12 16:56:38 -08001472
Craig Tiller841c8802015-09-10 13:06:37 -07001473 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001474
Craig Tiller841c8802015-09-10 13:06:37 -07001475 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001476 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}): protobuf_dep_error
Craig Tiller841c8802015-09-10 13:06:37 -07001477 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001478
Craig Tiller841c8802015-09-10 13:06:37 -07001479 else
1480 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001481
Alexander Polcyn690dde62017-10-18 00:20:33 -07001482 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP)\
Craig Tiller841c8802015-09-10 13:06:37 -07001483 ## The else here corresponds to the if secure earlier.
1484 % else:
1485 % if lib.language == 'c++':
1486 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001487
Craig Tiller841c8802015-09-10 13:06:37 -07001488 # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
Nicolas Noble53830622015-02-12 16:56:38 -08001489
Craig Tiller841c8802015-09-10 13:06:37 -07001490 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001491
Craig Tiller841c8802015-09-10 13:06:37 -07001492 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001493 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}): protobuf_dep_error
Craig Tiller841c8802015-09-10 13:06:37 -07001494 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001495
Craig Tiller841c8802015-09-10 13:06:37 -07001496 else
Nicolas Noble53830622015-02-12 16:56:38 -08001497
Craig Tiller841c8802015-09-10 13:06:37 -07001498 % endif
Yuchen Zeng78f9f942016-08-05 18:21:57 -07001499 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: \
Alexander Polcyn80f9c2a2018-05-16 20:15:16 -07001500 % if lib.name not in ['z', 'ares', 'address_sorting']:
Nicolas "Pixel" Nobled649c212016-01-27 20:27:30 +01001501 $(ZLIB_DEP) \
Yuchen Zeng15141a62016-08-17 18:56:04 -07001502 $(CARES_DEP) \
Alexander Polcyn690dde62017-10-18 00:20:33 -07001503 $(ADDRESS_SORTING_DEP) \
1504 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001505 % endif
1506 % if lib.language == 'c++':
1507 $(PROTOBUF_DEP)\
1508 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001509 $(LIB${lib.name.upper()}_OBJS) \
1510 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001511 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001512 $(ZLIB_MERGE_OBJS) \
Yuchen Zeng15141a62016-08-17 18:56:04 -07001513 $(CARES_MERGE_OBJS) \
Alexander Polcyn690dde62017-10-18 00:20:33 -07001514 $(ADDRESS_SORTING_MERGE_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001515 % if lib.get('secure', 'check') == True:
1516 $(OPENSSL_MERGE_OBJS) \
1517 % endif
1518 % endif
1519
Craig Tiller841c8802015-09-10 13:06:37 -07001520 $(E) "[AR] Creating $@"
1521 $(Q) mkdir -p `dirname $@`
1522 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Vijay Paicc7eb8e2016-07-19 19:03:55 -07001523 $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001524 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001525 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001526 $(ZLIB_MERGE_OBJS) \
Yuchen Zeng15141a62016-08-17 18:56:04 -07001527 $(CARES_MERGE_OBJS) \
Alexander Polcyn690dde62017-10-18 00:20:33 -07001528 $(ADDRESS_SORTING_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001529 % if lib.get('secure', 'check') == True:
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001530 $(OPENSSL_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001531 % endif
1532 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001533
Craig Tiller841c8802015-09-10 13:06:37 -07001534 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001535 $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tiller841c8802015-09-10 13:06:37 -07001536 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001537
Craig Tiller841c8802015-09-10 13:06:37 -07001538 <%
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001539
Craig Tiller841c8802015-09-10 13:06:37 -07001540 if lib.language == 'c++':
1541 ld = '$(LDXX)'
1542 else:
1543 ld = '$(LD)'
nnoble5b7f32a2014-12-22 08:12:44 -08001544
Craig Tiller40c8fba2016-09-15 16:29:09 -07001545 out_mingbase = '$(LIBDIR)/$(CONFIG)/' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
1546 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
nnoble5b7f32a2014-12-22 08:12:44 -08001547
Nicolas "Pixel" Noble8087d702017-02-01 02:23:50 +01001548 common = '$(LIB' + lib.name.upper() + '_OBJS)'
nnoble5b7f32a2014-12-22 08:12:44 -08001549
Craig Tillerd7b1bdf2016-11-04 16:20:13 -07001550 link_libs = ''
Alexander Polcyn690dde62017-10-18 00:20:33 -07001551 lib_deps = ' $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP)'
Craig Tiller841c8802015-09-10 13:06:37 -07001552 mingw_libs = ''
Alexander Polcyn690dde62017-10-18 00:20:33 -07001553 mingw_lib_deps = ' $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP)'
Craig Tiller841c8802015-09-10 13:06:37 -07001554 if lib.language == 'c++':
1555 lib_deps += ' $(PROTOBUF_DEP)'
1556 mingw_lib_deps += ' $(PROTOBUF_DEP)'
Jan Tattermusch324140c2016-01-12 08:54:01 -08001557 if lib.get('deps_linkage', None) == 'static':
1558 for dep in lib.get('deps', []):
1559 lib_archive = '$(LIBDIR)/$(CONFIG)/lib' + dep + '.a'
1560 common = common + ' ' + lib_archive
1561 lib_deps = lib_deps + ' ' + lib_archive
1562 mingw_lib_deps = mingw_lib_deps + ' ' + lib_archive
1563 else:
1564 for dep in lib.get('deps', []):
Craig Tillerd7b1bdf2016-11-04 16:20:13 -07001565 dep_lib = None
1566 for dl in libs:
1567 if dl.name == dep:
1568 dep_lib = dl
1569 assert dep_lib, 'lib %s not found (in %s)' % (dep, lib.name)
1570 link_libs = link_libs + ' -l' + dep
1571 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT_' + lang_to_var[dep_lib.language] + ')'
Mario Emmenlauer44b2d082017-01-13 12:35:49 +01001572 mingw_libs = mingw_libs + ' -l' + dep + '$(SHARED_VERSION_' + lang_to_var[dep_lib.language] + ')-dll'
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001573 mingw_lib_deps = mingw_lib_deps + ' $(LIBDIR)/$(CONFIG)/' + dep + '$(SHARED_VERSION_' + lang_to_var[dep_lib.language] + ').$(SHARED_EXT_' + lang_to_var[dep_lib.language] + ')'
nnoble5b7f32a2014-12-22 08:12:44 -08001574
Craig Tiller841c8802015-09-10 13:06:37 -07001575 security = lib.get('secure', 'check')
1576 if security == True:
1577 common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)'
Alexander Polcyn690dde62017-10-18 00:20:33 -07001578 common = common + ' $(ZLIB_MERGE_LIBS) $(CARES_MERGE_LIBS) $(ADDRESS_SORTING_MERGE_LIBS)'
Nicolas "Pixel" Noblea7c162c2015-07-24 20:21:51 +02001579
Craig Tiller841c8802015-09-10 13:06:37 -07001580 if security in [True, 'check']:
1581 for src in lib.src:
1582 if not proto_re.match(src):
1583 sources_that_need_openssl.add(src)
1584 else:
1585 for src in lib.src:
1586 sources_that_don_t_need_openssl.add(src)
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001587
Craig Tiller841c8802015-09-10 13:06:37 -07001588 if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1589 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1590 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001591
Craig Tiller841c8802015-09-10 13:06:37 -07001592 if lib.language == 'c++':
1593 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
Craig Tiller4bef7ce2016-02-02 08:38:43 -08001594
1595 ldflags = '$(LDFLAGS)'
1596 if lib.get('LDFLAGS', None):
1597 ldflags += ' ' + lib['LDFLAGS']
Nicolas "Pixel" Noble8087d702017-02-01 02:23:50 +01001598
1599 common = common + ' $(LDLIBS)'
Craig Tiller841c8802015-09-10 13:06:37 -07001600 %>
nnoble5b7f32a2014-12-22 08:12:44 -08001601
Craig Tiller841c8802015-09-10 13:06:37 -07001602 % if lib.build == "all":
1603 ifeq ($(SYSTEM),MINGW32)
Craig Tiller38b99e92016-09-15 16:18:09 -07001604 ${out_mingbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Craig Tiller841c8802015-09-10 13:06:37 -07001605 $(E) "[LD] Linking $@"
1606 $(Q) mkdir -p `dirname $@`
Mario Emmenlauer294dc2f2016-12-13 00:07:12 +01001607 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=${out_mingbase}.def -Wl,--out-implib=${out_libbase}-dll.a -o ${out_mingbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${mingw_libs}
Craig Tiller841c8802015-09-10 13:06:37 -07001608 else
Craig Tiller38b99e92016-09-15 16:18:09 -07001609 ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
Craig Tiller841c8802015-09-10 13:06:37 -07001610 $(E) "[LD] Linking $@"
1611 $(Q) mkdir -p `dirname $@`
1612 ifeq ($(SYSTEM),Darwin)
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001613 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) -dynamiclib -o ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${link_libs}
Craig Tiller841c8802015-09-10 13:06:37 -07001614 else
murgatroid99d166e382017-03-24 10:03:10 -07001615 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.get(lang_to_var[lib.language].lower() + '_version').major} -o ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${link_libs}
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001616 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) ${out_libbase}.so.${settings.get(lang_to_var[lib.language].lower() + '_version').major}
1617 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) ${out_libbase}.so
Craig Tiller841c8802015-09-10 13:06:37 -07001618 endif
1619 endif
1620 % endif
1621 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1622 ## If the lib was secure, we have to close the Makefile's if that tested
1623 ## the presence of OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001624
Craig Tiller841c8802015-09-10 13:06:37 -07001625 endif
1626 % endif
1627 % if lib.language == 'c++':
1628 ## If the lib was C++, we have to close the Makefile's if that tested
Srini Polavarapucdc0e282018-03-26 18:16:15 -07001629 ## the presence of protobuf 3.5.0+
nnoble69ac39f2014-12-12 15:43:38 -08001630
Craig Tiller841c8802015-09-10 13:06:37 -07001631 endif
1632 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001633
Craig Tiller841c8802015-09-10 13:06:37 -07001634 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1635 ifneq ($(NO_SECURE),true)
1636 % endif
1637 ifneq ($(NO_DEPS),true)
1638 -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
1639 endif
1640 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1641 endif
1642 % endif
1643 % for src in lib.src:
1644 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src):
1645 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))}
1646 % endif
1647 % endfor
1648 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001649
Craig Tiller841c8802015-09-10 13:06:37 -07001650 <%def name="maketarget(tgt)"><% has_no_sources = not tgt.src %>
1651 % if not has_no_sources:
1652 ${tgt.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001653
Craig Tiller841c8802015-09-10 13:06:37 -07001654 % for src in tgt.src:
1655 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001656
Craig Tiller841c8802015-09-10 13:06:37 -07001657 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001658
Craig Tiller841c8802015-09-10 13:06:37 -07001659 ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
1660 % endif
1661 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1662 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001663
Craig Tiller841c8802015-09-10 13:06:37 -07001664 # You can't build secure targets if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001665
Craig Tiller841c8802015-09-10 13:06:37 -07001666 $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001667
Craig Tiller841c8802015-09-10 13:06:37 -07001668 else
nnoble69ac39f2014-12-12 15:43:38 -08001669
Craig Tiller841c8802015-09-10 13:06:37 -07001670 % endif
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001671
1672 % if tgt.boringssl:
1673 # boringssl needs an override to ensure that it does not include
1674 # system openssl headers regardless of other configuration
1675 # we do so here with a target specific variable assignment
Craig Tiller78222f72016-05-10 09:55:38 -07001676 $(${tgt.name.upper()}_OBJS): CFLAGS := -Ithird_party/boringssl/include $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value $(NO_W_EXTRA_SEMI)
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001677 $(${tgt.name.upper()}_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS)
1678 $(${tgt.name.upper()}_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE
1679 % else:
1680 % endif
1681
Craig Tiller841c8802015-09-10 13:06:37 -07001682 ##
1683 ## We're not trying to add a dependency on building zlib and openssl here,
1684 ## as it's already done in the libraries. We're assuming that the build
1685 ## trickles down, and that a secure target requires a secure version of
1686 ## a library.
1687 ##
1688 ## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1689 ## I can live with that.
1690 ##
1691 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001692
Craig Tiller841c8802015-09-10 13:06:37 -07001693 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001694
Srini Polavarapucdc0e282018-03-26 18:16:15 -07001695 # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.5.0+.
Nicolas Noble53830622015-02-12 16:56:38 -08001696
Craig Tiller841c8802015-09-10 13:06:37 -07001697 $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001698
Craig Tiller841c8802015-09-10 13:06:37 -07001699 else
Nicolas Noble53830622015-02-12 16:56:38 -08001700
Craig Tiller841c8802015-09-10 13:06:37 -07001701 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1702 % if not has_no_sources:
1703 $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
1704 % endif
1705 % else:
1706 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1707 % if not has_no_sources:
1708 $(${tgt.name.upper()}_OBJS)\
1709 % endif
1710 % endif
1711 % for dep in tgt.deps:
1712 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1713 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001714
Craig Tiller32173c52016-03-17 14:12:45 -07001715 % if tgt.language == "c++" or tgt.boringssl or tgt.build == 'fuzzer':
Craig Tiller841c8802015-09-10 13:06:37 -07001716 ## C++ targets specificies.
1717 % if tgt.build == 'protoc':
1718 $(E) "[HOSTLD] Linking $@"
1719 $(Q) mkdir -p `dirname $@`
1720 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) \
1721 % if not has_no_sources:
1722 $(${tgt.name.upper()}_OBJS)\
1723 % endif
1724 % else:
1725 $(E) "[LD] Linking $@"
1726 $(Q) mkdir -p `dirname $@`
1727 $(Q) $(LDXX) $(LDFLAGS) \
1728 % if not has_no_sources:
1729 $(${tgt.name.upper()}_OBJS)\
1730 % endif
1731 % endif
1732 % else:
1733 ## C-only targets specificities.
1734 $(E) "[LD] Linking $@"
1735 $(Q) mkdir -p `dirname $@`
1736 $(Q) $(LD) $(LDFLAGS) \
1737 % if not has_no_sources:
1738 $(${tgt.name.upper()}_OBJS)\
1739 % endif
1740 % endif
1741 % for dep in tgt.deps:
1742 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1743 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001744 % if tgt.language == "c++":
1745 % if tgt.build == 'protoc':
1746 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
1747 % else:
1748 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
1749 % endif
1750 % endif
1751 % if tgt.build == 'protoc':
1752 $(HOST_LDLIBS)\
1753 % else:
1754 $(LDLIBS)\
1755 % endif
1756 % if tgt.build == 'protoc':
1757 $(HOST_LDLIBS_PROTOC)\
1758 % elif tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1759 $(LDLIBS_SECURE)\
1760 % endif
1761 % if tgt.language == 'c++' and tgt.build == 'test':
1762 $(GTEST_LIB)\
1763 % elif tgt.language == 'c++' and tgt.build == 'benchmark':
1764 $(GTEST_LIB)\
1765 % endif
Craig Tiller32173c52016-03-17 14:12:45 -07001766 % if tgt.build == 'fuzzer':
1767 -lFuzzer\
1768 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001769 -o $(BINDIR)/$(CONFIG)/${tgt.name}
1770 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001771
Craig Tiller841c8802015-09-10 13:06:37 -07001772 endif
1773 % endif
1774 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001775
Craig Tiller841c8802015-09-10 13:06:37 -07001776 endif
1777 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001778
Craig Tiller19f3ea22017-02-17 15:17:05 -08001779 % if tgt.get('defaults', None):
1780 % for name, value in defaults.get(tgt.defaults).iteritems():
1781 $(${tgt.name.upper()}_OBJS): ${name} += ${value}
1782 % endfor
1783 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001784 % for src in tgt.src:
1785 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
1786 % for dep in tgt.deps:
1787 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1788 % endfor
Craig Tillerf5371ef2015-01-12 16:40:18 -08001789
Craig Tillerab230452016-01-04 08:18:43 -08001790 % if tgt.language == 'c89':
1791 % for src in tgt.src:
Craig Tillerea21ca22016-01-04 12:34:29 -08001792 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o : ${src}
1793 $(E) "[C] Compiling $<"
1794 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001795 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -std=c89 -pedantic -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Craig Tillerab230452016-01-04 08:18:43 -08001796 % endfor
1797 % endif
1798
Craig Tiller841c8802015-09-10 13:06:37 -07001799 % endfor
1800 % if not has_no_sources:
1801 deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
1802 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001803
Craig Tiller841c8802015-09-10 13:06:37 -07001804 % if not has_no_sources:
1805 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1806 ifneq ($(NO_SECURE),true)
1807 % endif
1808 ifneq ($(NO_DEPS),true)
1809 -include $(${tgt.name.upper()}_OBJS:.o=.dep)
1810 endif
1811 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1812 endif
1813 % endif
1814 % endif
Nicolas "Pixel" Noble472bb682015-11-03 19:09:01 +01001815 % for src in tgt.src:
1816 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in tgt.src):
1817 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in tgt.src if proto_re.match(src2))}
1818 % endif
1819 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001820 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001821
Craig Tiller841c8802015-09-10 13:06:37 -07001822 ifneq ($(OPENSSL_DEP),)
1823 # This is to ensure the embedded OpenSSL is built beforehand, properly
1824 # installing headers to their final destination on the drive. We need this
1825 # otherwise parallel compilation will fail if a source is compiled first.
1826 % for src in sorted(sources_that_need_openssl):
1827 % if src not in sources_that_don_t_need_openssl:
1828 ${src}: $(OPENSSL_DEP)
1829 % endif
1830 % endfor
1831 endif
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001832
Craig Tiller841c8802015-09-10 13:06:37 -07001833 .PHONY: all strip tools \
1834 dep_error openssl_dep_error openssl_dep_message git_update stop \
1835 buildtests buildtests_c buildtests_cxx \
1836 test test_c test_cxx \
1837 install install_c install_cxx \
1838 install-headers install-headers_c install-headers_cxx \
1839 install-shared install-shared_c install-shared_cxx \
1840 install-static install-static_c install-static_cxx \
1841 strip strip-shared strip-static \
1842 strip_c strip-shared_c strip-static_c \
1843 strip_cxx strip-shared_cxx strip-static_cxx \
1844 dep_c dep_cxx bins_dep_c bins_dep_cxx \
1845 clean
Craig Tillerb79c1e12016-02-23 10:00:58 -08001846
1847 .PHONY: printvars
1848 printvars:
1849 @$(foreach V,$(sort $(.VARIABLES)), \
1850 $(if $(filter-out environment% default automatic, \
1851 $(origin $V)),$(warning $V=$($V) ($(value $V)))))