blob: 5ce606f8280145c3c1832777d628d78af89e4504 [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
Craig Tiller6169d5f2016-03-31 07:46:18 -070010 # Copyright 2015, Google Inc.
Craig Tiller841c8802015-09-10 13:06:37 -070011 # All rights reserved.
12 #
13 # Redistribution and use in source and binary forms, with or without
14 # modification, are permitted provided that the following conditions are
15 # met:
16 #
17 # * Redistributions of source code must retain the above copyright
18 # notice, this list of conditions and the following disclaimer.
19 # * Redistributions in binary form must reproduce the above
20 # copyright notice, this list of conditions and the following disclaimer
21 # in the documentation and/or other materials provided with the
22 # distribution.
23 # * Neither the name of Google Inc. nor the names of its
24 # contributors may be used to endorse or promote products derived from
25 # this software without specific prior written permission.
26 #
27 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 <%!
39 import re
40 import os
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080041
Craig Tiller841c8802015-09-10 13:06:37 -070042 proto_re = re.compile('(.*)\\.proto')
nnoble72309c62014-12-12 11:42:26 -080043
Craig Tiller841c8802015-09-10 13:06:37 -070044 def proto_to_cc(filename):
45 m = proto_re.match(filename)
46 if not m:
47 return filename
48 return '$(GENDIR)/' + m.group(1) + '.pb.cc $(GENDIR)/' + m.group(1) + '.grpc.pb.cc'
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +020049
Craig Tiller841c8802015-09-10 13:06:37 -070050 sources_that_need_openssl = set()
51 sources_that_don_t_need_openssl = set()
Craig Tiller78222f72016-05-10 09:55:38 -070052
53 # warnings we'd like, but that dont exist in all compilers
54 PREFERRED_WARNINGS=['shadow', 'extra-semi']
55 CHECK_WARNINGS=PREFERRED_WARNINGS + ['no-shift-negative-value']
56
57 def warning_var(fmt, warning):
58 return fmt % warning.replace('-', '_').upper()
59
60 def neg_warning(warning):
61 if warning[0:3] == 'no-':
62 return warning[3:]
63 else:
64 return 'no-' + warning
Craig Tiller38b99e92016-09-15 16:18:09 -070065
66 lang_to_var = {
67 'c': 'CORE',
68 'c++': 'CPP',
69 'csharp': 'CSHARP'
70 }
Craig Tiller841c8802015-09-10 13:06:37 -070071 %>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080072
Craig Tiller96b49552015-01-21 16:29:01 -080073
Craig Tiller71a86042016-01-15 14:59:58 -080074 comma := ,
75
76
Craig Tiller841c8802015-09-10 13:06:37 -070077 # Basic platform detection
78 HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +010079 SYSTEM ?= $(HOST_SYSTEM)
Craig Tiller841c8802015-09-10 13:06:37 -070080 ifeq ($(SYSTEM),MSYS)
81 SYSTEM = MINGW32
82 endif
83 ifeq ($(SYSTEM),MINGW64)
84 SYSTEM = MINGW32
85 endif
Craig Tiller96b49552015-01-21 16:29:01 -080086
87
Nicolas "Pixel" Noble6dad9b02015-09-23 18:32:26 +020088 MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
Craig Tiller841c8802015-09-10 13:06:37 -070089 ifndef BUILDDIR
Nicolas "Pixel" Noble42b4c282015-09-17 23:57:08 +020090 BUILDDIR_ABSOLUTE = $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))
91 else
92 BUILDDIR_ABSOLUTE = $(abspath $(BUILDDIR))
Craig Tiller841c8802015-09-10 13:06:37 -070093 endif
Craig Tiller61b910f2015-02-15 10:54:07 -080094
Craig Tiller841c8802015-09-10 13:06:37 -070095 HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false)
96 HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false)
97 HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false)
Nicolas Noblef8681182015-03-18 14:25:44 -070098
Craig Tiller841c8802015-09-10 13:06:37 -070099 ifeq ($(HAS_CC),true)
100 DEFAULT_CC = cc
101 DEFAULT_CXX = c++
102 else
103 ifeq ($(HAS_GCC),true)
104 DEFAULT_CC = gcc
105 DEFAULT_CXX = g++
106 else
107 ifeq ($(HAS_CLANG),true)
108 DEFAULT_CC = clang
109 DEFAULT_CXX = clang++
110 else
111 DEFAULT_CC = no_c_compiler
112 DEFAULT_CXX = no_c++_compiler
113 endif
114 endif
115 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700116
117
Nicolas "Pixel" Noble42b4c282015-09-17 23:57:08 +0200118 BINDIR = $(BUILDDIR_ABSOLUTE)/bins
119 OBJDIR = $(BUILDDIR_ABSOLUTE)/objs
120 LIBDIR = $(BUILDDIR_ABSOLUTE)/libs
121 GENDIR = $(BUILDDIR_ABSOLUTE)/gens
Craig Tiller61b910f2015-02-15 10:54:07 -0800122
Craig Tiller841c8802015-09-10 13:06:37 -0700123 # Configurations
ctiller8cfebb92015-01-06 15:02:12 -0800124
Craig Tillera0f85172016-01-20 15:56:06 -0800125 % for name, args in configs.iteritems():
126 VALID_CONFIG_${name} = 1
127 % if args.get('compile_the_world', False):
128 REQUIRE_CUSTOM_LIBRARIES_${name} = 1
129 % endif
Craig Tilleraff3d502016-01-20 15:59:31 -0800130 % for tool, default in [('CC', 'CC'), ('CXX', 'CXX'), ('LD', 'CC'), ('LDXX', 'CXX')]:
Craig Tillera0f85172016-01-20 15:56:06 -0800131 ${tool}_${name} = ${args.get(tool, '$(DEFAULT_%s)' % default)}
132 % endfor
133 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES']:
134 % if args.get(arg, None) is not None:
135 ${arg}_${name} = ${args.get(arg)}
136 % endif
137 % endfor
ctiller8cfebb92015-01-06 15:02:12 -0800138
Craig Tillera0f85172016-01-20 15:56:06 -0800139 % endfor
Craig Tiller699ba212015-01-13 17:02:20 -0800140
Nicolas Noble047b7272015-01-16 13:55:05 -0800141
Craig Tiller841c8802015-09-10 13:06:37 -0700142 # General settings.
143 # You may want to change these depending on your system.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800144
Craig Tiller841c8802015-09-10 13:06:37 -0700145 prefix ?= /usr/local
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800146
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100147 PROTOC ?= protoc
148 DTRACE ?= dtrace
Craig Tiller841c8802015-09-10 13:06:37 -0700149 CONFIG ?= opt
Nicolas "Pixel" Noblefba36bc2016-01-27 03:24:03 +0100150 # Doing X ?= Y is the same as:
151 # ifeq ($(origin X), undefined)
152 # X = Y
153 # endif
154 # but some variables, such as CC, CXX, LD or AR, have defaults.
155 # So instead of using ?= on them, we need to check their origin.
156 # See:
157 # https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
158 # https://www.gnu.org/software/make/manual/html_node/Flavors.html#index-_003f_003d
159 # https://www.gnu.org/software/make/manual/html_node/Origin-Function.html
160 ifeq ($(origin CC), default)
161 CC = $(CC_$(CONFIG))
162 endif
163 ifeq ($(origin CXX), default)
164 CXX = $(CXX_$(CONFIG))
165 endif
166 ifeq ($(origin LD), default)
167 LD = $(LD_$(CONFIG))
168 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100169 LDXX ?= $(LDXX_$(CONFIG))
Craig Tiller841c8802015-09-10 13:06:37 -0700170 ifeq ($(SYSTEM),Linux)
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100171 ifeq ($(origin AR), default)
172 AR = ar rcs
173 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100174 STRIP ?= strip --strip-unneeded
Craig Tiller841c8802015-09-10 13:06:37 -0700175 else
176 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100177 ifeq ($(origin AR), default)
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100178 AR = libtool -no_warning_for_no_symbols -o
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100179 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100180 STRIP ?= strip -x
Craig Tiller841c8802015-09-10 13:06:37 -0700181 else
Mario Emmenlauer1643c042016-12-12 23:12:47 +0100182 ifeq ($(SYSTEM),MINGW32)
183 ifeq ($(origin AR), default)
184 AR = ar rcs
185 endif
186 STRIP ?= strip --strip-unneeded
187 else
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100188 ifeq ($(origin AR), default)
189 AR = ar rcs
190 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100191 STRIP ?= strip
Craig Tiller841c8802015-09-10 13:06:37 -0700192 endif
193 endif
Mario Emmenlauer1643c042016-12-12 23:12:47 +0100194 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100195 INSTALL ?= install
196 RM ?= rm -f
197 PKG_CONFIG ?= pkg-config
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800198
Craig Tiller841c8802015-09-10 13:06:37 -0700199 ifndef VALID_CONFIG_$(CONFIG)
200 $(error Invalid CONFIG value '$(CONFIG)')
201 endif
yangg102e4fe2015-01-06 16:02:50 -0800202
Craig Tiller841c8802015-09-10 13:06:37 -0700203 ifeq ($(SYSTEM),Linux)
204 TMPOUT = /dev/null
205 else
206 TMPOUT = `mktemp /tmp/test-out-XXXXXX`
207 endif
Nicolas Noble047b7272015-01-16 13:55:05 -0800208
Craig Tiller841c8802015-09-10 13:06:37 -0700209 # Detect if we can use C++11
210 CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc
211 HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false)
Craig Tillercf133f42015-02-26 14:05:56 -0800212
Craig Tiller78222f72016-05-10 09:55:38 -0700213 %for warning in CHECK_WARNINGS:
214 ${warning_var('CHECK_%s_WORKS_CMD', warning)} = $(CC) -std=c99 -Werror -W${warning} -o $(TMPOUT) -c test/build/${warning}.c
215 ${warning_var('HAS_WORKING_%s', warning)} = $(shell $(${warning_var('CHECK_%s_WORKS_CMD', warning)}) 2> /dev/null && echo true || echo false)
216 ifeq ($(${warning_var('HAS_WORKING_%s', warning)}),true)
217 ${warning_var('W_%s', warning)}=-W${warning}
218 ${warning_var('NO_W_%s', warning)}=-W${neg_warning(warning)}
Craig Tiller804b8552016-02-23 16:50:24 -0800219 endif
Craig Tiller78222f72016-05-10 09:55:38 -0700220 %endfor
Craig Tiller16872b82016-01-25 10:55:20 -0800221
Craig Tiller841c8802015-09-10 13:06:37 -0700222 # The HOST compiler settings are used to compile the protoc plugins.
223 # In most cases, you won't have to change anything, but if you are
224 # cross-compiling, you can override these variables from GNU make's
225 # command line: make CC=cross-gcc HOST_CC=gcc
Nicolas Noble047b7272015-01-16 13:55:05 -0800226
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100227 HOST_CC ?= $(CC)
228 HOST_CXX ?= $(CXX)
229 HOST_LD ?= $(LD)
230 HOST_LDXX ?= $(LDXX)
nnoble72309c62014-12-12 11:42:26 -0800231
Craig Tiller78222f72016-05-10 09:55:38 -0700232 CFLAGS += -std=c99 -Wsign-conversion -Wconversion ${' '.join(warning_var('$(W_%s)', warning) for warning in PREFERRED_WARNINGS)}
Craig Tiller841c8802015-09-10 13:06:37 -0700233 ifeq ($(HAS_CXX11),true)
234 CXXFLAGS += -std=c++11
235 else
236 CXXFLAGS += -std=c++0x
237 endif
Nicolas "Pixel" Noble51b1aee2016-01-28 01:14:58 +0100238 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES']:
239 % if defaults.get('global', []).get(arg, None) is not None:
240 ${arg} += ${defaults.get('global').get(arg)}
241 % endif
242 % endfor
Nicolas Noblef8681182015-03-18 14:25:44 -0700243
Craig Tiller841c8802015-09-10 13:06:37 -0700244 CPPFLAGS += $(CPPFLAGS_$(CONFIG))
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800245 CFLAGS += $(CFLAGS_$(CONFIG))
246 CXXFLAGS += $(CXXFLAGS_$(CONFIG))
Craig Tiller841c8802015-09-10 13:06:37 -0700247 DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
248 LDFLAGS += $(LDFLAGS_$(CONFIG))
Nicolas "Pixel" Noble482d7612015-07-16 23:43:30 +0200249
Craig Tiller841c8802015-09-10 13:06:37 -0700250 ifneq ($(SYSTEM),MINGW32)
251 PIC_CPPFLAGS = -fPIC
252 CPPFLAGS += -fPIC
253 LDFLAGS += -fPIC
254 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800255
Craig Tiller841c8802015-09-10 13:06:37 -0700256 INCLUDES = . include $(GENDIR)
257 LDFLAGS += -Llibs/$(CONFIG)
Nicolas "Pixel" Noble3adab742015-06-02 00:33:06 +0200258
Craig Tiller841c8802015-09-10 13:06:37 -0700259 ifeq ($(SYSTEM),Darwin)
260 ifneq ($(wildcard /usr/local/ssl/include),)
261 INCLUDES += /usr/local/ssl/include
262 endif
263 ifneq ($(wildcard /opt/local/include),)
264 INCLUDES += /opt/local/include
265 endif
266 ifneq ($(wildcard /usr/local/include),)
267 INCLUDES += /usr/local/include
268 endif
269 LIBS = m z
270 ifneq ($(wildcard /usr/local/ssl/lib),)
271 LDFLAGS += -L/usr/local/ssl/lib
272 endif
273 ifneq ($(wildcard /opt/local/lib),)
274 LDFLAGS += -L/opt/local/lib
275 endif
276 ifneq ($(wildcard /usr/local/lib),)
277 LDFLAGS += -L/usr/local/lib
278 endif
279 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700280
Craig Tiller841c8802015-09-10 13:06:37 -0700281 ifeq ($(SYSTEM),Linux)
Craig Tiller1b1e2382016-02-03 07:33:56 -0800282 LIBS = dl rt m pthread
Craig Tiller841c8802015-09-10 13:06:37 -0700283 LDFLAGS += -pthread
284 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800285
Craig Tiller841c8802015-09-10 13:06:37 -0700286 ifeq ($(SYSTEM),MINGW32)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100287 LIBS = m pthread ws2_32
Craig Tiller841c8802015-09-10 13:06:37 -0700288 LDFLAGS += -pthread
289 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700290
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700291 #
292 # The steps for cross-compiling are as follows:
293 # First, clone and make install of grpc using the native compilers for the host.
294 # Also, install protoc (e.g., from a package like apt-get)
295 # Then clone a fresh grpc for the actual cross-compiled build
296 # Set the environment variable GRPC_CROSS_COMPILE to true
297 # Set CC, CXX, LD, LDXX, AR, and STRIP to the cross-compiling binaries
298 # Also set PROTOBUF_CONFIG_OPTS to indicate cross-compilation to protobuf (e.g.,
299 # PROTOBUF_CONFIG_OPTS="--host=arm-linux --with-protoc=/usr/local/bin/protoc" )
300 # Set HAS_PKG_CONFIG=false
301 # To build tests, go to third_party/gflags and follow its ccmake instructions
302 # Make sure that you enable building shared libraries and set your prefix to
303 # something useful like /usr/local/cross
304 # You will also need to set GRPC_CROSS_LDOPTS and GRPC_CROSS_AROPTS to hold
305 # additional required arguments for LD and AR (examples below)
306 # Then you can do a make from the cross-compiling fresh clone!
307 #
308 ifeq ($(GRPC_CROSS_COMPILE),true)
309 LDFLAGS += $(GRPC_CROSS_LDOPTS) # e.g. -L/usr/local/lib -L/usr/local/cross/lib
310 AROPTS = $(GRPC_CROSS_AROPTS) # e.g., rc --target=elf32-little
311 USE_BUILT_PROTOC = false
312 endif
313
Mahak Mukhifb059a22017-04-18 14:40:00 -0700314 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 -0700315 GTEST_LIB += -lgflags
316 ifeq ($(V),1)
317 E = @:
318 Q =
319 else
320 E = @echo
321 Q = @
322 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800323
Craig Tiller38b99e92016-09-15 16:18:09 -0700324 CORE_VERSION = ${settings.core_version}
325 CPP_VERSION = ${settings.cpp_version}
326 CSHARP_VERSION = ${settings.csharp_version}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800327
Craig Tiller841c8802015-09-10 13:06:37 -0700328 CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
329 CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800330
Craig Tiller841c8802015-09-10 13:06:37 -0700331 LDFLAGS += $(ARCH_FLAGS)
332 LDLIBS += $(addprefix -l, $(LIBS))
333 LDLIBSXX += $(addprefix -l, $(LIBSXX))
nnoble72309c62014-12-12 11:42:26 -0800334
murgatroid99c36f6ea2016-10-03 09:24:09 -0700335
336 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES', 'LDLIBS']:
337 ${arg} += $(EXTRA_${arg})
338 % endfor
339
Craig Tiller841c8802015-09-10 13:06:37 -0700340 HOST_CPPFLAGS = $(CPPFLAGS)
341 HOST_CFLAGS = $(CFLAGS)
342 HOST_CXXFLAGS = $(CXXFLAGS)
343 HOST_LDFLAGS = $(LDFLAGS)
344 HOST_LDLIBS = $(LDLIBS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800345
Craig Tiller841c8802015-09-10 13:06:37 -0700346 # These are automatically computed variables.
347 # There shouldn't be any need to change anything from now on.
nnoble69ac39f2014-12-12 15:43:38 -0800348
Craig Tiller841c8802015-09-10 13:06:37 -0700349 -include cache.mk
murgatroid9924e2f4a2015-06-29 11:12:01 -0700350
Craig Tiller841c8802015-09-10 13:06:37 -0700351 CACHE_MK =
murgatroid99aa521572015-07-10 14:49:12 -0700352
Craig Tiller841c8802015-09-10 13:06:37 -0700353 HAS_PKG_CONFIG ?= $(shell command -v $(PKG_CONFIG) >/dev/null 2>&1 && echo true || echo false)
murgatroid99aa521572015-07-10 14:49:12 -0700354
Craig Tiller841c8802015-09-10 13:06:37 -0700355 ifeq ($(HAS_PKG_CONFIG), true)
356 CACHE_MK += HAS_PKG_CONFIG = true,
357 endif
nnoble69ac39f2014-12-12 15:43:38 -0800358
Craig Tiller38b99e92016-09-15 16:18:09 -0700359 CORE_PC_TEMPLATE = prefix=$(prefix),\
Craig Tiller841c8802015-09-10 13:06:37 -0700360 exec_prefix=${'\$${prefix}'},\
361 includedir=${'\$${prefix}'}/include,\
362 libdir=${'\$${exec_prefix}'}/lib,\
363 ,\
364 Name: $(PC_NAME),\
365 Description: $(PC_DESCRIPTION),\
Craig Tiller38b99e92016-09-15 16:18:09 -0700366 Version: $(CORE_VERSION),\
367 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
368 Requires.private: $(PC_REQUIRES_PRIVATE),\
369 Libs: -L${'\$${libdir}'} $(PC_LIB),\
370 Libs.private: $(PC_LIBS_PRIVATE)
371
372 CPP_PC_TEMPLATE = prefix=$(prefix),\
373 exec_prefix=${'\$${prefix}'},\
374 includedir=${'\$${prefix}'}/include,\
375 libdir=${'\$${exec_prefix}'}/lib,\
376 ,\
377 Name: $(PC_NAME),\
378 Description: $(PC_DESCRIPTION),\
379 Version: $(CPP_VERSION),\
380 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
381 Requires.private: $(PC_REQUIRES_PRIVATE),\
382 Libs: -L${'\$${libdir}'} $(PC_LIB),\
383 Libs.private: $(PC_LIBS_PRIVATE)
384
385 CSHARP_PC_TEMPLATE = prefix=$(prefix),\
386 exec_prefix=${'\$${prefix}'},\
387 includedir=${'\$${prefix}'}/include,\
388 libdir=${'\$${exec_prefix}'}/lib,\
389 ,\
390 Name: $(PC_NAME),\
391 Description: $(PC_DESCRIPTION),\
392 Version: $(CSHARP_VERSION),\
Craig Tiller841c8802015-09-10 13:06:37 -0700393 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
394 Requires.private: $(PC_REQUIRES_PRIVATE),\
395 Libs: -L${'\$${libdir}'} $(PC_LIB),\
396 Libs.private: $(PC_LIBS_PRIVATE)
murgatroid998faab232015-06-30 17:24:21 -0700397
Craig Tiller841c8802015-09-10 13:06:37 -0700398 ifeq ($(SYSTEM),MINGW32)
Mario Emmenlauer121d2892016-12-12 23:49:27 +0100399 EXECUTABLE_SUFFIX = .exe
Craig Tiller38b99e92016-09-15 16:18:09 -0700400 SHARED_EXT_CORE = dll
401 SHARED_EXT_CPP = dll
402 SHARED_EXT_CSHARP = dll
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100403 SHARED_PREFIX =
Craig Tiller27f70842016-09-15 16:21:54 -0700404 SHARED_VERSION_CORE = -${settings.core_version.major}
405 SHARED_VERSION_CPP = -${settings.cpp_version.major}
406 SHARED_VERSION_CSHARP = -${settings.csharp_version.major}
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100407 else ifeq ($(SYSTEM),Darwin)
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800408 EXECUTABLE_SUFFIX =
Craig Tiller38b99e92016-09-15 16:18:09 -0700409 SHARED_EXT_CORE = dylib
410 SHARED_EXT_CPP = dylib
411 SHARED_EXT_CSHARP = dylib
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100412 SHARED_PREFIX = lib
Craig Tiller27f70842016-09-15 16:21:54 -0700413 SHARED_VERSION_CORE =
414 SHARED_VERSION_CPP =
415 SHARED_VERSION_CSHARP =
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100416 else
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800417 EXECUTABLE_SUFFIX =
Craig Tiller38b99e92016-09-15 16:18:09 -0700418 SHARED_EXT_CORE = so.$(CORE_VERSION)
419 SHARED_EXT_CPP = so.$(CPP_VERSION)
420 SHARED_EXT_CSHARP = so.$(CSHARP_VERSION)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100421 SHARED_PREFIX = lib
Craig Tiller27f70842016-09-15 16:21:54 -0700422 SHARED_VERSION_CORE =
423 SHARED_VERSION_CPP =
424 SHARED_VERSION_CSHARP =
Craig Tiller841c8802015-09-10 13:06:37 -0700425 endif
nnoble5b7f32a2014-12-22 08:12:44 -0800426
Craig Tiller841c8802015-09-10 13:06:37 -0700427 ifeq ($(wildcard .git),)
428 IS_GIT_FOLDER = false
429 else
430 IS_GIT_FOLDER = true
431 endif
nnoble69ac39f2014-12-12 15:43:38 -0800432
Craig Tiller841c8802015-09-10 13:06:37 -0700433 ifeq ($(HAS_PKG_CONFIG),true)
434 OPENSSL_ALPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.2 openssl
435 OPENSSL_NPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.1 openssl
436 ZLIB_CHECK_CMD = $(PKG_CONFIG) --exists zlib
Yuchen Zengd4df55e2016-08-15 16:41:18 -0700437 PROTOBUF_CHECK_CMD = $(PKG_CONFIG) --atleast-version=3.0.0 protobuf
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700438 CARES_CHECK_CMD = $(PKG_CONFIG) --exists libcares
Craig Tiller841c8802015-09-10 13:06:37 -0700439 else # HAS_PKG_CONFIG
murgatroid9924e2f4a2015-06-29 11:12:01 -0700440
Craig Tiller841c8802015-09-10 13:06:37 -0700441 ifeq ($(SYSTEM),MINGW32)
442 OPENSSL_LIBS = ssl32 eay32
443 else
444 OPENSSL_LIBS = ssl crypto
445 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700446
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100447 OPENSSL_ALPN_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
448 OPENSSL_NPN_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/openssl-npn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
Craig Tillerb79c1e12016-02-23 10:00:58 -0800449 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 +0100450 ZLIB_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
451 PROTOBUF_CHECK_CMD = $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700452 CARES_CHECK_CMD = $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $(TMPOUT) test/build/c-ares.c -lcares $(LDFLAGS)
Craig Tiller297fafa2015-01-15 15:46:39 -0800453
Craig Tiller841c8802015-09-10 13:06:37 -0700454 endif # HAS_PKG_CONFIG
murgatroid9924e2f4a2015-06-29 11:12:01 -0700455
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100456 PERFTOOLS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
murgatroid996d9e4012015-07-08 10:22:45 -0700457
Craig Tiller841c8802015-09-10 13:06:37 -0700458 PROTOC_CHECK_CMD = which protoc > /dev/null
459 PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3
460 DTRACE_CHECK_CMD = which dtrace > /dev/null
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100461 SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS)
murgatroid9924e2f4a2015-06-29 11:12:01 -0700462
Craig Tiller841c8802015-09-10 13:06:37 -0700463 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
464 HAS_SYSTEM_PERFTOOLS ?= $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
465 ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
466 DEFINES += GRPC_HAVE_PERFTOOLS
467 LIBS += profiler
468 CACHE_MK += HAS_SYSTEM_PERFTOOLS = true,
469 endif
470 endif
nnoble69ac39f2014-12-12 15:43:38 -0800471
Craig Tiller841c8802015-09-10 13:06:37 -0700472 HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
473 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
474 HAS_SYSTEM_OPENSSL_ALPN ?= $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
475 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
476 HAS_SYSTEM_OPENSSL_NPN = true
477 CACHE_MK += HAS_SYSTEM_OPENSSL_ALPN = true,
478 else
479 HAS_SYSTEM_OPENSSL_NPN ?= $(shell $(OPENSSL_NPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
480 endif
481 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
482 CACHE_MK += HAS_SYSTEM_OPENSSL_NPN = true,
483 endif
484 HAS_SYSTEM_ZLIB ?= $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
485 ifeq ($(HAS_SYSTEM_ZLIB),true)
486 CACHE_MK += HAS_SYSTEM_ZLIB = true,
487 endif
488 HAS_SYSTEM_PROTOBUF ?= $(HAS_SYSTEM_PROTOBUF_VERIFY)
489 ifeq ($(HAS_SYSTEM_PROTOBUF),true)
490 CACHE_MK += HAS_SYSTEM_PROTOBUF = true,
491 endif
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700492 HAS_SYSTEM_CARES ?= $(shell $(CARES_CHECK_CMD) 2> /dev/null && echo true || echo false)
493 ifeq ($(HAS_SYSTEM_CARES),true)
494 CACHE_MK += HAS_SYSTEM_CARES = true,
495 endif
Craig Tiller841c8802015-09-10 13:06:37 -0700496 else
497 # override system libraries if the config requires a custom compiled library
498 HAS_SYSTEM_OPENSSL_ALPN = false
499 HAS_SYSTEM_OPENSSL_NPN = false
500 HAS_SYSTEM_ZLIB = false
501 HAS_SYSTEM_PROTOBUF = false
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700502 HAS_SYSTEM_CARES = false
Craig Tiller841c8802015-09-10 13:06:37 -0700503 endif
nnoble69ac39f2014-12-12 15:43:38 -0800504
Craig Tiller841c8802015-09-10 13:06:37 -0700505 HAS_PROTOC ?= $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
506 ifeq ($(HAS_PROTOC),true)
507 CACHE_MK += HAS_PROTOC = true,
508 HAS_VALID_PROTOC ?= $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false)
509 ifeq ($(HAS_VALID_PROTOC),true)
510 CACHE_MK += HAS_VALID_PROTOC = true,
511 endif
512 else
513 HAS_VALID_PROTOC = false
514 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800515
Craig Tiller841c8802015-09-10 13:06:37 -0700516 # Check for Systemtap (https://sourceware.org/systemtap/), first by making sure <sys/sdt.h> is present
517 # in the system and secondly by checking for the "dtrace" binary (on Linux, this is part of the Systemtap
518 # distribution. It's part of the base system on BSD/Solaris machines).
519 ifndef HAS_SYSTEMTAP
520 HAS_SYSTEMTAP_HEADERS = $(shell $(SYSTEMTAP_HEADERS_CHECK_CMD) 2> /dev/null && echo true || echo false)
521 HAS_DTRACE = $(shell $(DTRACE_CHECK_CMD) 2> /dev/null && echo true || echo false)
522 HAS_SYSTEMTAP = false
523 ifeq ($(HAS_SYSTEMTAP_HEADERS),true)
524 ifeq ($(HAS_DTRACE),true)
525 HAS_SYSTEMTAP = true
526 endif
527 endif
528 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -0700529
Craig Tiller841c8802015-09-10 13:06:37 -0700530 ifeq ($(HAS_SYSTEMTAP),true)
531 CACHE_MK += HAS_SYSTEMTAP = true,
532 endif
nnoble69ac39f2014-12-12 15:43:38 -0800533
Craig Tiller841c8802015-09-10 13:06:37 -0700534 # Note that for testing purposes, one can do:
535 # make HAS_EMBEDDED_OPENSSL_ALPN=false
536 # to emulate the fact we do not have OpenSSL in the third_party folder.
Craig Tillerb79c1e12016-02-23 10:00:58 -0800537 ifneq ($(wildcard third_party/${openssl_fallback.extraction_dir}/libssl.a),)
538 HAS_EMBEDDED_OPENSSL_ALPN = third_party/${openssl_fallback.extraction_dir}
539 else ifeq ($(wildcard third_party/boringssl/include/openssl/ssl.h),)
Craig Tiller841c8802015-09-10 13:06:37 -0700540 HAS_EMBEDDED_OPENSSL_ALPN = false
541 else
Craig Tillerb79c1e12016-02-23 10:00:58 -0800542 CAN_COMPILE_EMBEDDED_OPENSSL ?= $(shell $(BORINGSSL_COMPILE_CHECK_CMD) 2> /dev/null && echo true || echo false)
543 HAS_EMBEDDED_OPENSSL_ALPN = $(CAN_COMPILE_EMBEDDED_OPENSSL)
Craig Tiller841c8802015-09-10 13:06:37 -0700544 endif
nnoble69ac39f2014-12-12 15:43:38 -0800545
Craig Tiller841c8802015-09-10 13:06:37 -0700546 ifeq ($(wildcard third_party/zlib/zlib.h),)
547 HAS_EMBEDDED_ZLIB = false
548 else
549 HAS_EMBEDDED_ZLIB = true
550 endif
nnoble69ac39f2014-12-12 15:43:38 -0800551
Craig Tiller841c8802015-09-10 13:06:37 -0700552 ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
553 HAS_EMBEDDED_PROTOBUF = false
554 ifneq ($(HAS_VALID_PROTOC),true)
555 NO_PROTOC = true
556 endif
557 else
558 HAS_EMBEDDED_PROTOBUF = true
559 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800560
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800561 ifeq ($(wildcard third_party/cares/cares/ares.h),)
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700562 HAS_EMBEDDED_CARES = false
563 else
564 HAS_EMBEDDED_CARES = true
565 endif
566
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100567 PC_REQUIRES_GRPC =
Craig Tiller841c8802015-09-10 13:06:37 -0700568 PC_LIBS_GRPC =
murgatroid998faab232015-06-30 17:24:21 -0700569
Craig Tiller841c8802015-09-10 13:06:37 -0700570 ifeq ($(HAS_SYSTEM_ZLIB),false)
Craig Tiller3dca23a2016-01-21 11:44:55 -0800571 ifeq ($(HAS_EMBEDDED_ZLIB), true)
572 EMBED_ZLIB ?= true
Craig Tiller841c8802015-09-10 13:06:37 -0700573 else
574 DEP_MISSING += zlib
Craig Tiller3dca23a2016-01-21 11:44:55 -0800575 EMBED_ZLIB ?= broken
Craig Tiller841c8802015-09-10 13:06:37 -0700576 endif
577 else
Craig Tiller3dca23a2016-01-21 11:44:55 -0800578 EMBED_ZLIB ?= false
579 endif
580
581 ifeq ($(EMBED_ZLIB),true)
582 ZLIB_DEP = $(LIBDIR)/$(CONFIG)/libz.a
583 ZLIB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libz.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +0100584 ZLIB_MERGE_OBJS = $(LIBZ_OBJS)
Craig Tiller3dca23a2016-01-21 11:44:55 -0800585 CPPFLAGS += -Ithird_party/zlib
586 LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib
587 else
Craig Tiller841c8802015-09-10 13:06:37 -0700588 ifeq ($(HAS_PKG_CONFIG),true)
589 CPPFLAGS += $(shell $(PKG_CONFIG) --cflags zlib)
590 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L zlib)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800591 LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l zlib))
Craig Tiller841c8802015-09-10 13:06:37 -0700592 PC_REQUIRES_GRPC += zlib
593 else
594 PC_LIBS_GRPC += -lz
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800595 LIBS += z
Craig Tiller841c8802015-09-10 13:06:37 -0700596 endif
597 endif
nnoble69ac39f2014-12-12 15:43:38 -0800598
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700599 CARES_PKG_CONFIG = false
600
Yuchen Zengb1b21152016-08-12 11:27:30 -0700601 ifeq ($(HAS_SYSTEM_CARES),false)
602 ifeq ($(HAS_EMBEDDED_CARES), true)
603 EMBED_CARES ?= true
604 else
605 DEP_MISSING += cares
606 EMBED_CARES ?= broken
607 endif
608 else
609 EMBED_CARES ?= false
610 endif
611
612 ifeq ($(EMBED_CARES),true)
Yuchen Zeng15141a62016-08-17 18:56:04 -0700613 CARES_DEP = $(LIBDIR)/$(CONFIG)/libares.a
614 CARES_MERGE_OBJS = $(LIBARES_OBJS)
615 CARES_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libares.a
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800616 CPPFLAGS := -Ithird_party/cares -Ithird_party/cares/cares $(CPPFLAGS)
Yuchen Zengb1b21152016-08-12 11:27:30 -0700617 LDFLAGS := -L$(LIBDIR)/$(CONFIG)/c-ares $(LDFLAGS)
Yuchen Zengb1b21152016-08-12 11:27:30 -0700618 else
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700619 ifeq ($(HAS_PKG_CONFIG),true)
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700620 PC_REQUIRES_GRPC += libcares
621 CPPFLAGS += $(shell $(PKG_CONFIG) --cflags libcares)
Yuchen Zengdf2a7b72016-08-18 14:57:03 -0700622 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libcares)
623 LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l libcares))
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700624 else
625 PC_LIBS_GRPC += -lcares
Yuchen Zengdf2a7b72016-08-18 14:57:03 -0700626 LIBS += cares
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700627 endif
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700628 endif
629
Craig Tiller841c8802015-09-10 13:06:37 -0700630 OPENSSL_PKG_CONFIG = false
murgatroid99da7a9942015-06-29 14:57:37 -0700631
Craig Tiller841c8802015-09-10 13:06:37 -0700632 PC_REQUIRES_SECURE =
633 PC_LIBS_SECURE =
murgatroid998faab232015-06-30 17:24:21 -0700634
Craig Tiller841c8802015-09-10 13:06:37 -0700635 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800636 EMBED_OPENSSL ?= false
637 NO_SECURE ?= false
638 else # HAS_SYSTEM_OPENSSL_ALPN=false
Craig Tillerb79c1e12016-02-23 10:00:58 -0800639 ifneq ($(HAS_EMBEDDED_OPENSSL_ALPN),false)
640 EMBED_OPENSSL ?= $(HAS_EMBEDDED_OPENSSL_ALPN)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800641 NO_SECURE ?= false
642 else # HAS_EMBEDDED_OPENSSL_ALPN=false
643 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
644 EMBED_OPENSSL ?= false
645 NO_SECURE ?= false
646 else
647 NO_SECURE ?= true
648 endif # HAS_SYSTEM_OPENSSL_NPN=true
649 endif # HAS_EMBEDDED_OPENSSL_ALPN
650 endif # HAS_SYSTEM_OPENSSL_ALPN
651
652 OPENSSL_DEP :=
653 OPENSSL_MERGE_LIBS :=
654 ifeq ($(NO_SECURE),false)
655 ifeq ($(EMBED_OPENSSL),true)
656 OPENSSL_DEP += $(LIBDIR)/$(CONFIG)/libboringssl.a
657 OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/libboringssl.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +0100658 OPENSSL_MERGE_OBJS += $(LIBBORINGSSL_OBJS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800659 # need to prefix these to ensure overriding system libraries
660 CPPFLAGS := -Ithird_party/boringssl/include $(CPPFLAGS)
Craig Tillerb79c1e12016-02-23 10:00:58 -0800661 else ifneq ($(EMBED_OPENSSL),false)
662 OPENSSL_DEP += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
663 OPENSSL_MERGE_LIBS += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
664 OPENSSL_MERGE_OBJS += $(wildcard $(EMBED_OPENSSL)/grpc_obj/*.o)
665 # need to prefix these to ensure overriding system libraries
666 CPPFLAGS := -I$(EMBED_OPENSSL)/include $(CPPFLAGS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800667 else # EMBED_OPENSSL=false
Craig Tiller841c8802015-09-10 13:06:37 -0700668 ifeq ($(HAS_PKG_CONFIG),true)
669 OPENSSL_PKG_CONFIG = true
670 PC_REQUIRES_SECURE = openssl
671 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags openssl) $(CPPFLAGS)
672 LDFLAGS_OPENSSL_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L openssl)
673 ifeq ($(SYSTEM),Linux)
674 ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),)
675 LDFLAGS_OPENSSL_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L openssl | sed s/L/Wl,-rpath,/)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800676 endif # LDFLAGS_OPENSSL_PKG_CONFIG=''
677 endif # System=Linux
Craig Tiller841c8802015-09-10 13:06:37 -0700678 LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800679 else # HAS_PKG_CONFIG=false
Craig Tiller841c8802015-09-10 13:06:37 -0700680 LIBS_SECURE = $(OPENSSL_LIBS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800681 endif # HAS_PKG_CONFIG
682 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
683 CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0
684 LIBS_SECURE = $(OPENSSL_LIBS)
685 endif # HAS_SYSTEM_OPENSSL_NPN
Craig Tiller841c8802015-09-10 13:06:37 -0700686 PC_LIBS_SECURE = $(addprefix -l, $(LIBS_SECURE))
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800687 endif # EMBED_OPENSSL
688 endif # NO_SECURE
nnoble69ac39f2014-12-12 15:43:38 -0800689
Craig Tiller841c8802015-09-10 13:06:37 -0700690 ifeq ($(OPENSSL_PKG_CONFIG),true)
691 LDLIBS_SECURE += $(shell $(PKG_CONFIG) --libs-only-l openssl)
692 else
693 LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
694 endif
nnoble5b7f32a2014-12-22 08:12:44 -0800695
Craig Tiller841c8802015-09-10 13:06:37 -0700696 # grpc .pc file
697 PC_NAME = gRPC
Craig Tillerda179ce2016-02-09 12:01:53 -0800698 PC_DESCRIPTION = high performance general RPC framework
699 PC_CFLAGS =
700 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC) $(PC_REQUIRES_SECURE)
Craig Tiller841c8802015-09-10 13:06:37 -0700701 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) $(PC_LIBS_SECURE)
702 PC_LIB = -lgrpc
Craig Tiller38b99e92016-09-15 16:18:09 -0700703 GRPC_PC_FILE := $(CORE_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700704
Craig Tiller4a67be42016-02-09 12:40:32 -0800705 # grpc_unsecure .pc file
Craig Tiller841c8802015-09-10 13:06:37 -0700706 PC_NAME = gRPC unsecure
Craig Tillerda179ce2016-02-09 12:01:53 -0800707 PC_DESCRIPTION = high performance general RPC framework without SSL
708 PC_CFLAGS =
709 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC)
Craig Tiller841c8802015-09-10 13:06:37 -0700710 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC)
711 PC_LIB = -lgrpc
Craig Tiller38b99e92016-09-15 16:18:09 -0700712 GRPC_UNSECURE_PC_FILE := $(CORE_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700713
Craig Tiller841c8802015-09-10 13:06:37 -0700714 PROTOBUF_PKG_CONFIG = false
murgatroid99da7a9942015-06-29 14:57:37 -0700715
Craig Tiller841c8802015-09-10 13:06:37 -0700716 PC_REQUIRES_GRPCXX =
717 PC_LIBS_GRPCXX =
murgatroid998faab232015-06-30 17:24:21 -0700718
Mahak Mukhifb059a22017-04-18 14:40:00 -0700719 CPPFLAGS := -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googlemock/include $(CPPFLAGS)
Craig Tiller16f6dac2015-08-24 17:00:04 -0700720
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700721 PROTOC_PLUGINS_ALL =\
722 % for tgt in targets:
723 % if tgt.build == 'protoc':
724 $(BINDIR)/$(CONFIG)/${tgt.name}\
725 % endif
726 % endfor
727
728 PROTOC_PLUGINS_DIR = $(BINDIR)/$(CONFIG)
729
Craig Tiller841c8802015-09-10 13:06:37 -0700730 ifeq ($(HAS_SYSTEM_PROTOBUF),true)
731 ifeq ($(HAS_PKG_CONFIG),true)
732 PROTOBUF_PKG_CONFIG = true
733 PC_REQUIRES_GRPCXX = protobuf
734 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags protobuf) $(CPPFLAGS)
735 LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L protobuf)
736 ifeq ($(SYSTEM),Linux)
737 ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),)
738 LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L protobuf | sed s/L/Wl,-rpath,/)
739 endif
740 endif
741 else
742 PC_LIBS_GRPCXX = -lprotobuf
743 endif
Nicolas "Pixel" Noblef7fbdd42016-07-25 20:31:22 +0200744 PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
Craig Tiller841c8802015-09-10 13:06:37 -0700745 else
746 ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
747 PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
748 CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
749 LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700750 ifneq ($(USE_BUILT_PROTOC),false)
Craig Tiller841c8802015-09-10 13:06:37 -0700751 PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700752 PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
753 else
754 PROTOC_PLUGINS =
755 PROTOC_PLUGINS_DIR = $(prefix)/bin
756 endif
Craig Tiller841c8802015-09-10 13:06:37 -0700757 else
758 NO_PROTOBUF = true
759 endif
760 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800761
Craig Tiller841c8802015-09-10 13:06:37 -0700762 LIBS_PROTOBUF = protobuf
763 LIBS_PROTOC = protoc protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800764
Craig Tiller841c8802015-09-10 13:06:37 -0700765 HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
Nicolas Noble53830622015-02-12 16:56:38 -0800766
Craig Tiller841c8802015-09-10 13:06:37 -0700767 ifeq ($(PROTOBUF_PKG_CONFIG),true)
768 LDLIBS_PROTOBUF += $(shell $(PKG_CONFIG) --libs-only-l protobuf)
769 else
770 LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
771 endif
murgatroid9924e2f4a2015-06-29 11:12:01 -0700772
Craig Tiller841c8802015-09-10 13:06:37 -0700773 # grpc++ .pc file
774 PC_NAME = gRPC++
775 PC_DESCRIPTION = C++ wrapper for gRPC
776 PC_CFLAGS =
777 PC_REQUIRES_PRIVATE = grpc $(PC_REQUIRES_GRPCXX)
778 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
779 PC_LIB = -lgrpc++
Craig Tiller38b99e92016-09-15 16:18:09 -0700780 GRPCXX_PC_FILE := $(CPP_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700781
Craig Tiller841c8802015-09-10 13:06:37 -0700782 # grpc++_unsecure .pc file
783 PC_NAME = gRPC++ unsecure
784 PC_DESCRIPTION = C++ wrapper for gRPC without SSL
785 PC_CFLAGS =
786 PC_REQUIRES_PRIVATE = grpc_unsecure $(PC_REQUIRES_GRPCXX)
787 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
788 PC_LIB = -lgrpc++
Craig Tiller38b99e92016-09-15 16:18:09 -0700789 GRPCXX_UNSECURE_PC_FILE := $(CPP_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700790
Craig Tiller841c8802015-09-10 13:06:37 -0700791 ifeq ($(MAKECMDGOALS),clean)
792 NO_DEPS = true
793 endif
nnoble69ac39f2014-12-12 15:43:38 -0800794
Craig Tiller841c8802015-09-10 13:06:37 -0700795 .SECONDARY = %.pb.h %.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800796
Craig Tiller841c8802015-09-10 13:06:37 -0700797 ifeq ($(DEP_MISSING),)
798 all: static shared plugins\
799 % for tgt in targets:
800 % if tgt.build == 'all':
801 $(BINDIR)/$(CONFIG)/${tgt.name}\
802 % endif
803 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800804
Craig Tiller841c8802015-09-10 13:06:37 -0700805 dep_error:
806 @echo "You shouldn't see this message - all of your dependencies are correct."
807 else
808 all: dep_error git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800809
Craig Tiller841c8802015-09-10 13:06:37 -0700810 dep_error:
811 @echo
812 @echo "DEPENDENCY ERROR"
813 @echo
814 @echo "You are missing system dependencies that are essential to build grpc,"
815 @echo "and the third_party directory doesn't have them:"
816 @echo
817 @echo " $(DEP_MISSING)"
818 @echo
819 @echo "Installing the development packages for your system will solve"
820 @echo "this issue. Please consult INSTALL to get more information."
821 @echo
822 @echo "If you need information about why these tests failed, run:"
823 @echo
824 @echo " make run_dep_checks"
825 @echo
826 endif
nnoble69ac39f2014-12-12 15:43:38 -0800827
Craig Tiller841c8802015-09-10 13:06:37 -0700828 git_update:
829 ifeq ($(IS_GIT_FOLDER),true)
830 @echo "Additionally, since you are in a git clone, you can download the"
831 @echo "missing dependencies in third_party by running the following command:"
832 @echo
833 @echo " git submodule update --init"
834 @echo
835 endif
nnoble69ac39f2014-12-12 15:43:38 -0800836
Craig Tiller841c8802015-09-10 13:06:37 -0700837 openssl_dep_error: openssl_dep_message git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800838
Craig Tiller841c8802015-09-10 13:06:37 -0700839 protobuf_dep_error: protobuf_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800840
Craig Tiller841c8802015-09-10 13:06:37 -0700841 protoc_dep_error: protoc_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800842
Craig Tiller841c8802015-09-10 13:06:37 -0700843 openssl_dep_message:
844 @echo
845 @echo "DEPENDENCY ERROR"
846 @echo
Craig Tillerb79c1e12016-02-23 10:00:58 -0800847 @echo "The target you are trying to run requires an OpenSSL implementation."
848 @echo "Your system doesn't have one, and either the third_party directory"
849 @echo "doesn't have it, or your compiler can't build BoringSSL."
Craig Tiller841c8802015-09-10 13:06:37 -0700850 @echo
851 @echo "Please consult INSTALL to get more information."
852 @echo
853 @echo "If you need information about why these tests failed, run:"
854 @echo
855 @echo " make run_dep_checks"
856 @echo
nnoble69ac39f2014-12-12 15:43:38 -0800857
Craig Tiller841c8802015-09-10 13:06:37 -0700858 protobuf_dep_message:
859 @echo
860 @echo "DEPENDENCY ERROR"
861 @echo
862 @echo "The target you are trying to run requires protobuf 3.0.0+"
863 @echo "Your system doesn't have it, and neither does the third_party directory."
864 @echo
865 @echo "Please consult INSTALL to get more information."
866 @echo
867 @echo "If you need information about why these tests failed, run:"
868 @echo
869 @echo " make run_dep_checks"
870 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800871
Craig Tiller841c8802015-09-10 13:06:37 -0700872 protoc_dep_message:
873 @echo
874 @echo "DEPENDENCY ERROR"
875 @echo
876 @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
877 @echo "Your system doesn't have it, and neither does the third_party directory."
878 @echo
879 @echo "Please consult INSTALL to get more information."
880 @echo
881 @echo "If you need information about why these tests failed, run:"
882 @echo
883 @echo " make run_dep_checks"
884 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800885
Craig Tiller841c8802015-09-10 13:06:37 -0700886 systemtap_dep_error:
887 @echo
888 @echo "DEPENDENCY ERROR"
889 @echo
890 @echo "Under the '$(CONFIG)' configutation, the target you are trying "
891 @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other "
892 @echo "platforms such as Solaris and *BSD). "
893 @echo
894 @echo "Please consult INSTALL to get more information."
895 @echo
David Garcia Quintas8954e902015-04-29 09:46:33 -0700896
Craig Tiller841c8802015-09-10 13:06:37 -0700897 stop:
898 @false
nnoble69ac39f2014-12-12 15:43:38 -0800899
Craig Tiller841c8802015-09-10 13:06:37 -0700900 % for tgt in targets:
901 ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
902 % endfor
ctiller09cb6d52014-12-19 17:38:22 -0800903
Craig Tiller841c8802015-09-10 13:06:37 -0700904 run_dep_checks:
905 $(OPENSSL_ALPN_CHECK_CMD) || true
906 $(OPENSSL_NPN_CHECK_CMD) || true
907 $(ZLIB_CHECK_CMD) || true
908 $(PERFTOOLS_CHECK_CMD) || true
909 $(PROTOBUF_CHECK_CMD) || true
910 $(PROTOC_CHECK_VERSION_CMD) || true
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700911 $(CARES_CHECK_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800912
Craig Tiller841c8802015-09-10 13:06:37 -0700913 third_party/protobuf/configure:
914 $(E) "[AUTOGEN] Preparing protobuf"
915 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
Nicolas Noble53830622015-02-12 16:56:38 -0800916
Craig Tiller841c8802015-09-10 13:06:37 -0700917 $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
918 $(E) "[MAKE] Building protobuf"
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700919 $(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 -0700920 $(Q)$(MAKE) -C third_party/protobuf clean
921 $(Q)$(MAKE) -C third_party/protobuf
922 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
923 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
924 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
925 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
926 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800927
Craig Tiller841c8802015-09-10 13:06:37 -0700928 static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800929
Craig Tillereda85c62016-07-01 12:45:19 -0700930 static_c: pc_c pc_c_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700931 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100932 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700933 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
934 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
935 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100936 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700937 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800938
939
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100940 static_cxx: pc_cxx pc_cxx_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700941 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100942 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700943 % if lib.build == 'all' and lib.language == 'c++':
944 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
945 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100946 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700947 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800948
949
Craig Tiller841c8802015-09-10 13:06:37 -0700950 shared: shared_c shared_cxx
nnoble29e1d292014-12-01 10:27:40 -0800951
Craig Tillereda85c62016-07-01 12:45:19 -0700952 shared_c: pc_c pc_c_unsecure cache.mk\
Craig Tiller841c8802015-09-10 13:06:37 -0700953 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100954 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700955 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -0700956 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)\
Craig Tiller841c8802015-09-10 13:06:37 -0700957 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100958 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700959 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800960
Craig Tiller841c8802015-09-10 13:06:37 -0700961 shared_cxx: pc_cxx pc_cxx_unsecure cache.mk\
962 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100963 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700964 % if lib.build == 'all' and lib.language == 'c++':
Craig Tiller27f70842016-09-15 16:21:54 -0700965 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)\
Craig Tiller841c8802015-09-10 13:06:37 -0700966 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100967 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700968 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800969
970
Craig Tiller841c8802015-09-10 13:06:37 -0700971 shared_csharp: shared_c \
972 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100973 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700974 % if lib.build == 'all' and lib.language == 'csharp':
Craig Tiller27f70842016-09-15 16:21:54 -0700975 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)\
Craig Tiller841c8802015-09-10 13:06:37 -0700976 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100977 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700978 % endfor
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800979
Craig Tiller841c8802015-09-10 13:06:37 -0700980 grpc_csharp_ext: shared_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800981
Craig Tiller841c8802015-09-10 13:06:37 -0700982 plugins: $(PROTOC_PLUGINS)
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100983
Craig Tiller841c8802015-09-10 13:06:37 -0700984 privatelibs: privatelibs_c privatelibs_cxx
nnoble29e1d292014-12-01 10:27:40 -0800985
Craig Tiller841c8802015-09-10 13:06:37 -0700986 privatelibs_c: \
987 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100988 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800989 % 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 -0700990 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
991 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100992 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700993 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800994
Craig Tiller841c8802015-09-10 13:06:37 -0700995 pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc
murgatroid998faab232015-06-30 17:24:21 -0700996
Craig Tiller841c8802015-09-10 13:06:37 -0700997 pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -0700998
Craig Tiller841c8802015-09-10 13:06:37 -0700999 pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc
murgatroid998faab232015-06-30 17:24:21 -07001000
Craig Tiller841c8802015-09-10 13:06:37 -07001001 pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001002
vjpai20410922016-06-15 09:21:42 -07001003 ifeq ($(EMBED_OPENSSL),true)
Craig Tiller841c8802015-09-10 13:06:37 -07001004 privatelibs_cxx: \
1005 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001006 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001007 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None):
1008 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
1009 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001010 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001011 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -07001012
vjpai20410922016-06-15 09:21:42 -07001013 else
1014 privatelibs_cxx: \
1015 % for lib in libs:
1016 % if 'Makefile' in lib.get('build_system', ['Makefile']):
1017 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None) and not lib.boringssl:
1018 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
1019 % endif
1020 % endif
1021 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -07001022
vjpai20410922016-06-15 09:21:42 -07001023 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001024
1025
Craig Tillereda85c62016-07-01 12:45:19 -07001026 buildtests: buildtests_c buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -08001027
Craig Tiller3824b6e2015-12-09 11:19:59 -08001028 buildtests_c: privatelibs_c <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001029 % for tgt in targets:
1030 % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -08001031 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001032 % endif
1033 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001034
1035
vjpai20410922016-06-15 09:21:42 -07001036 ifeq ($(EMBED_OPENSSL),true)
Craig Tillereda85c62016-07-01 12:45:19 -07001037 buildtests_cxx: privatelibs_cxx <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001038 % for tgt in targets:
1039 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -08001040 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001041 % endif
1042 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -07001043
vjpai20410922016-06-15 09:21:42 -07001044 else
Craig Tillereda85c62016-07-01 12:45:19 -07001045 buildtests_cxx: privatelibs_cxx <%text>\</%text>
vjpai20410922016-06-15 09:21:42 -07001046 % for tgt in targets:
1047 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl:
1048 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
1049 % endif
1050 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -07001051
vjpai20410922016-06-15 09:21:42 -07001052 endif
nnoble29e1d292014-12-01 10:27:40 -08001053
1054
Craig Tillereda85c62016-07-01 12:45:19 -07001055 test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -08001056
Craig Tillereda85c62016-07-01 12:45:19 -07001057 flaky_test: flaky_test_c flaky_test_cxx
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001058
Craig Tiller841c8802015-09-10 13:06:37 -07001059 test_c: buildtests_c
1060 % for tgt in targets:
1061 % 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):
1062 $(E) "[RUN] Testing ${tgt.name}"
1063 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1064 % endif
1065 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001066
1067
Craig Tiller841c8802015-09-10 13:06:37 -07001068 flaky_test_c: buildtests_c
1069 % for tgt in targets:
1070 % 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):
1071 $(E) "[RUN] Testing ${tgt.name}"
1072 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1073 % endif
1074 % endfor
nnoble29e1d292014-12-01 10:27:40 -08001075
1076
Craig Tillereda85c62016-07-01 12:45:19 -07001077 test_cxx: buildtests_cxx
Craig Tiller841c8802015-09-10 13:06:37 -07001078 % for tgt in targets:
1079 % 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):
1080 $(E) "[RUN] Testing ${tgt.name}"
1081 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1082 % endif
1083 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001084
1085
Craig Tiller841c8802015-09-10 13:06:37 -07001086 flaky_test_cxx: buildtests_cxx
1087 % for tgt in targets:
1088 % 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):
1089 $(E) "[RUN] Testing ${tgt.name}"
1090 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1091 % endif
1092 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001093
1094
Craig Tiller841c8802015-09-10 13:06:37 -07001095 test_python: static_c
1096 $(E) "[RUN] Testing python code"
1097 $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
Nicolas "Pixel" Noble051a28f2015-03-17 22:54:54 +01001098
1099
Craig Tiller841c8802015-09-10 13:06:37 -07001100 tools: tools_c tools_cxx
Craig Tiller7552f0f2015-06-19 17:46:20 -07001101
1102
Craig Tiller841c8802015-09-10 13:06:37 -07001103 tools_c: privatelibs_c\
1104 % for tgt in targets:
1105 % if tgt.build == 'tool' and not tgt.language=='c++':
1106 $(BINDIR)/$(CONFIG)/${tgt.name}\
1107 % endif
1108 % endfor
Craig Tiller7552f0f2015-06-19 17:46:20 -07001109
1110
Craig Tiller841c8802015-09-10 13:06:37 -07001111 tools_cxx: privatelibs_cxx\
1112 % for tgt in targets:
1113 % if tgt.build == 'tool' and tgt.language=='c++':
1114 $(BINDIR)/$(CONFIG)/${tgt.name}\
1115 % endif
1116 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001117
1118
Craig Tiller841c8802015-09-10 13:06:37 -07001119 buildbenchmarks: privatelibs\
1120 % for tgt in targets:
1121 % if tgt.build == 'benchmark':
1122 $(BINDIR)/$(CONFIG)/${tgt.name}\
1123 % endif
1124 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001125
1126
Craig Tiller841c8802015-09-10 13:06:37 -07001127 benchmarks: buildbenchmarks
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001128
Craig Tiller841c8802015-09-10 13:06:37 -07001129 strip: strip-static strip-shared
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001130
Craig Tiller841c8802015-09-10 13:06:37 -07001131 strip-static: strip-static_c strip-static_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001132
Craig Tiller841c8802015-09-10 13:06:37 -07001133 strip-shared: strip-shared_c strip-shared_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001134
Nicolas Noble047b7272015-01-16 13:55:05 -08001135
Craig Tiller841c8802015-09-10 13:06:37 -07001136 # TODO(nnoble): the strip target is stripping in-place, instead
1137 # of copying files in a temporary folder.
1138 # This prevents proper debugging after running make install.
Nicolas Noble047b7272015-01-16 13:55:05 -08001139
Craig Tiller841c8802015-09-10 13:06:37 -07001140 strip-static_c: static_c
1141 ifeq ($(CONFIG),opt)
1142 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001143 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001144 % if lib.language == "c":
1145 % if lib.build == "all":
1146 % if not lib.get('external_deps', None):
1147 $(E) "[STRIP] Stripping lib${lib.name}.a"
1148 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1149 % endif
1150 % endif
1151 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001152 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001153 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001154 endif
nnoble85a49262014-12-08 18:14:03 -08001155
Craig Tiller841c8802015-09-10 13:06:37 -07001156 strip-static_cxx: static_cxx
1157 ifeq ($(CONFIG),opt)
1158 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001159 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001160 % if lib.language == "c++":
1161 % if lib.build == "all":
1162 $(E) "[STRIP] Stripping lib${lib.name}.a"
1163 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1164 % endif
1165 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001166 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001167 % endfor
1168 endif
Nicolas "Pixel" Noble4ef9b862015-08-14 19:35:24 +02001169
Craig Tiller841c8802015-09-10 13:06:37 -07001170 strip-shared_c: shared_c
1171 ifeq ($(CONFIG),opt)
1172 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001173 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001174 % if lib.language == "c":
1175 % if lib.build == "all":
1176 % if not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -07001177 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)"
1178 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)
Craig Tiller841c8802015-09-10 13:06:37 -07001179 % endif
1180 % endif
1181 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001182 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001183 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001184 endif
nnoble85a49262014-12-08 18:14:03 -08001185
Craig Tiller841c8802015-09-10 13:06:37 -07001186 strip-shared_cxx: shared_cxx
1187 ifeq ($(CONFIG),opt)
1188 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001189 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001190 % if lib.language == "c++":
1191 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001192 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)"
1193 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)
Craig Tiller841c8802015-09-10 13:06:37 -07001194 % endif
1195 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001196 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001197 % endfor
1198 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001199
Craig Tiller841c8802015-09-10 13:06:37 -07001200 strip-shared_csharp: shared_csharp
1201 ifeq ($(CONFIG),opt)
1202 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001203 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001204 % if lib.language == "csharp":
1205 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001206 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)"
1207 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)
Craig Tiller841c8802015-09-10 13:06:37 -07001208 % endif
1209 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001210 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001211 % endfor
1212 endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001213
Craig Tiller841c8802015-09-10 13:06:37 -07001214 cache.mk::
1215 $(E) "[MAKE] Generating $@"
1216 $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@
murgatroid99aa521572015-07-10 14:49:12 -07001217
Craig Tiller841c8802015-09-10 13:06:37 -07001218 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc:
1219 $(E) "[MAKE] Generating $@"
1220 $(Q) mkdir -p $(@D)
1221 $(Q) echo "$(GRPC_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001222
Craig Tiller841c8802015-09-10 13:06:37 -07001223 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc:
1224 $(E) "[MAKE] Generating $@"
1225 $(Q) mkdir -p $(@D)
1226 $(Q) echo "$(GRPC_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001227
Craig Tiller841c8802015-09-10 13:06:37 -07001228 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc:
1229 $(E) "[MAKE] Generating $@"
1230 $(Q) mkdir -p $(@D)
1231 $(Q) echo "$(GRPCXX_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001232
Craig Tiller841c8802015-09-10 13:06:37 -07001233 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc:
1234 $(E) "[MAKE] Generating $@"
1235 $(Q) mkdir -p $(@D)
1236 $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001237
Craig Tiller841c8802015-09-10 13:06:37 -07001238 % for p in protos:
1239 ifeq ($(NO_PROTOC),true)
1240 $(GENDIR)/${p}.pb.cc: protoc_dep_error
1241 $(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error
1242 else
Mahak Mukhifb059a22017-04-18 14:40:00 -07001243 <%
1244 pluginflags=""
1245 %>
1246 % if p in ["src/proto/grpc/testing/compiler_test", "src/proto/grpc/testing/echo"]:
1247 <%
1248 pluginflags="generate_mock_code=true:"
1249 %>
1250 % endif
Craig Tiller1b4e3302015-12-17 16:35:00 -08001251 $(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 -07001252 $(E) "[PROTOC] Generating protobuf CC file from $<"
1253 $(Q) mkdir -p `dirname $@`
David Garcia Quintase68ed6f2016-06-17 12:49:14 -07001254 $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --cpp_out=$(GENDIR) $<
Nicolas "Pixel" Noble0caebbf2015-04-09 23:08:51 +02001255
Craig Tiller1b4e3302015-12-17 16:35:00 -08001256 $(GENDIR)/${p}.grpc.pb.cc: ${p}.proto $(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 -07001257 $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
1258 $(Q) mkdir -p `dirname $@`
Mahak Mukhifb059a22017-04-18 14:40:00 -07001259 $(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 -07001260 endif
nnoble72309c62014-12-12 11:42:26 -08001261
Craig Tiller841c8802015-09-10 13:06:37 -07001262 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001263
Craig Tiller841c8802015-09-10 13:06:37 -07001264 ifeq ($(CONFIG),stapprof)
1265 src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h
1266 ifeq ($(HAS_SYSTEMTAP),true)
1267 $(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d
1268 $(E) "[DTRACE] Compiling $<"
1269 $(Q) mkdir -p `dirname $@`
1270 $(Q) $(DTRACE) -C -h -s $< -o $@
1271 else
1272 $(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop
1273 endif
1274 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -07001275
Craig Tiller841c8802015-09-10 13:06:37 -07001276 $(OBJDIR)/$(CONFIG)/%.o : %.c
1277 $(E) "[C] Compiling $<"
1278 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001279 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001280
Craig Tiller841c8802015-09-10 13:06:37 -07001281 $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
1282 $(E) "[CXX] Compiling $<"
1283 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001284 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001285
Craig Tiller841c8802015-09-10 13:06:37 -07001286 $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
1287 $(E) "[HOSTCXX] Compiling $<"
1288 $(Q) mkdir -p `dirname $@`
1289 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -08001290
Craig Tiller841c8802015-09-10 13:06:37 -07001291 $(OBJDIR)/$(CONFIG)/%.o : %.cc
1292 $(E) "[CXX] Compiling $<"
1293 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001294 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001295
murgatroid99a3c55352016-08-10 13:41:31 -07001296 install: install_c install_cxx install-plugins install-certs
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001297
Craig Tiller841c8802015-09-10 13:06:37 -07001298 install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001299
Craig Tiller841c8802015-09-10 13:06:37 -07001300 install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
nnoble85a49262014-12-08 18:14:03 -08001301
Craig Tiller841c8802015-09-10 13:06:37 -07001302 install_csharp: install-shared_csharp install_c
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001303
Craig Tiller841c8802015-09-10 13:06:37 -07001304 install_grpc_csharp_ext: install_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001305
Craig Tiller841c8802015-09-10 13:06:37 -07001306 install-headers: install-headers_c install-headers_cxx
nnoble85a49262014-12-08 18:14:03 -08001307
Craig Tiller841c8802015-09-10 13:06:37 -07001308 install-headers_c:
1309 $(E) "[INSTALL] Installing public C headers"
1310 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1311 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001312
Craig Tiller841c8802015-09-10 13:06:37 -07001313 install-headers_cxx:
1314 $(E) "[INSTALL] Installing public C++ headers"
1315 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1316 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001317
Craig Tiller841c8802015-09-10 13:06:37 -07001318 install-static: install-static_c install-static_cxx
nnoble85a49262014-12-08 18:14:03 -08001319
Craig Tiller841c8802015-09-10 13:06:37 -07001320 install-static_c: static_c strip-static_c install-pkg-config_c
1321 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001322 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001323 % if lib.language == "c":
1324 % if lib.build == "all":
1325 % if not lib.get('external_deps', None):
1326 $(E) "[INSTALL] Installing lib${lib.name}.a"
1327 $(Q) $(INSTALL) -d $(prefix)/lib
1328 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1329 % endif
1330 % endif
1331 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001332 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001333 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001334
Craig Tiller841c8802015-09-10 13:06:37 -07001335 install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx
1336 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001337 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001338 % if lib.language == "c++":
1339 % if lib.build == "all":
1340 $(E) "[INSTALL] Installing lib${lib.name}.a"
1341 $(Q) $(INSTALL) -d $(prefix)/lib
1342 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1343 % endif
1344 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001345 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001346 % endfor
nnoble85a49262014-12-08 18:14:03 -08001347
Craig Tiller841c8802015-09-10 13:06:37 -07001348 <%def name="install_shared(lang_filter)">\
1349 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001350 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001351 % if lib.language == lang_filter:
1352 % if lib.build == "all":
1353 % if not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -07001354 $(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 +01001355 $(Q) $(INSTALL) -d $(prefix)/lib
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001356 $(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 -07001357 ifeq ($(SYSTEM),MINGW32)
Mario Emmenlauer44b2d082017-01-13 12:35:49 +01001358 $(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 +01001359 else ifneq ($(SYSTEM),Darwin)
Craig Tiller27f70842016-09-15 16:21:54 -07001360 $(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}
1361 $(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 -07001362 endif
1363 % endif
1364 % endif
1365 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001366 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001367 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001368 ifneq ($(SYSTEM),MINGW32)
1369 ifneq ($(SYSTEM),Darwin)
1370 $(Q) ldconfig || true
1371 endif
1372 endif
1373 </%def>
nnoble85a49262014-12-08 18:14:03 -08001374
Craig Tiller841c8802015-09-10 13:06:37 -07001375 install-shared_c: shared_c strip-shared_c install-pkg-config_c
1376 ${install_shared("c")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001377
Craig Tiller841c8802015-09-10 13:06:37 -07001378 install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c install-pkg-config_cxx
1379 ${install_shared("c++")}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001380
Craig Tiller841c8802015-09-10 13:06:37 -07001381 install-shared_csharp: shared_csharp strip-shared_csharp
1382 ${install_shared("csharp")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001383
Craig Tiller841c8802015-09-10 13:06:37 -07001384 install-plugins: $(PROTOC_PLUGINS)
Craig Tiller841c8802015-09-10 13:06:37 -07001385 $(E) "[INSTALL] Installing grpc protoc plugins"
1386 % for tgt in targets:
1387 % if tgt.build == 'protoc':
1388 $(Q) $(INSTALL) -d $(prefix)/bin
1389 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
1390 % endif
1391 % endfor
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001392
Craig Tillereda85c62016-07-01 12:45:19 -07001393 install-pkg-config_c: pc_c pc_c_unsecure
Craig Tiller841c8802015-09-10 13:06:37 -07001394 $(E) "[INSTALL] Installing C pkg-config files"
1395 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
Craig Tiller841c8802015-09-10 13:06:37 -07001396 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(prefix)/lib/pkgconfig/grpc.pc
1397 $(Q) $(INSTALL) $(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-pkg-config_cxx: pc_cxx pc_cxx_unsecure
1400 $(E) "[INSTALL] Installing C++ pkg-config files"
1401 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
1402 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc $(prefix)/lib/pkgconfig/grpc++.pc
1403 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc $(prefix)/lib/pkgconfig/grpc++_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -07001404
Craig Tiller841c8802015-09-10 13:06:37 -07001405 install-certs: etc/roots.pem
1406 $(E) "[INSTALL] Installing root certificates"
1407 $(Q) $(INSTALL) -d $(prefix)/share/grpc
1408 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +01001409
Craig Tiller841c8802015-09-10 13:06:37 -07001410 clean:
1411 $(E) "[CLEAN] Cleaning build directories."
1412 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001413
1414
Craig Tiller841c8802015-09-10 13:06:37 -07001415 # The various libraries
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001416
Craig Tiller841c8802015-09-10 13:06:37 -07001417 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001418 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001419 ${makelib(lib)}
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001420 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001421 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001422
1423
Craig Tiller841c8802015-09-10 13:06:37 -07001424 # All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001425
Craig Tiller841c8802015-09-10 13:06:37 -07001426 % for tgt in targets:
1427 ${maketarget(tgt)}
1428 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001429
Craig Tiller841c8802015-09-10 13:06:37 -07001430 <%def name="makelib(lib)">
1431 LIB${lib.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001432
Craig Tiller841c8802015-09-10 13:06:37 -07001433 % for src in lib.src:
1434 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001435
Craig Tiller841c8802015-09-10 13:06:37 -07001436 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001437
Craig Tiller841c8802015-09-10 13:06:37 -07001438 % if "public_headers" in lib:
1439 % if lib.language == "c++":
1440 PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001441
Craig Tiller841c8802015-09-10 13:06:37 -07001442 % else:
1443 PUBLIC_HEADERS_C += \\
nnoble85a49262014-12-08 18:14:03 -08001444
Craig Tiller841c8802015-09-10 13:06:37 -07001445 % endif
1446 % for hdr in lib.public_headers:
1447 ${hdr} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001448
Craig Tiller841c8802015-09-10 13:06:37 -07001449 % endfor
1450 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001451
Craig Tiller841c8802015-09-10 13:06:37 -07001452 LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001453
Nicolas "Pixel" Noble51b1aee2016-01-28 01:14:58 +01001454 % if lib.get('defaults', None):
1455 % for name, value in defaults.get(lib.defaults).iteritems():
1456 $(LIB${lib.name.upper()}_OBJS): ${name} += ${value}
1457 % endfor
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001458 % endif
1459
Craig Tiller841c8802015-09-10 13:06:37 -07001460 ## If the library requires OpenSSL, let's add some restrictions.
1461 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1462 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001463
Craig Tiller841c8802015-09-10 13:06:37 -07001464 # You can't build secure libraries if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001465
Craig Tiller841c8802015-09-10 13:06:37 -07001466 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001467
Craig Tiller841c8802015-09-10 13:06:37 -07001468 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001469 $(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 -07001470 % endif
nnoble5b7f32a2014-12-22 08:12:44 -08001471
Craig Tiller841c8802015-09-10 13:06:37 -07001472 else
nnoble69ac39f2014-12-12 15:43:38 -08001473
Craig Tiller841c8802015-09-10 13:06:37 -07001474 % if lib.language == 'c++':
1475 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001476
Craig Tiller841c8802015-09-10 13:06:37 -07001477 # 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 -08001478
Craig Tiller841c8802015-09-10 13:06:37 -07001479 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001480
Craig Tiller841c8802015-09-10 13:06:37 -07001481 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001482 $(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 -07001483 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001484
Craig Tiller841c8802015-09-10 13:06:37 -07001485 else
1486 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001487
Nicolas "Pixel" Nobleb0367ca2017-03-29 21:53:38 +02001488 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(CARES_DEP)\
Craig Tiller841c8802015-09-10 13:06:37 -07001489 ## The else here corresponds to the if secure earlier.
1490 % else:
1491 % if lib.language == 'c++':
1492 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001493
Craig Tiller841c8802015-09-10 13:06:37 -07001494 # 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 -08001495
Craig Tiller841c8802015-09-10 13:06:37 -07001496 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001497
Craig Tiller841c8802015-09-10 13:06:37 -07001498 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001499 $(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 -07001500 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001501
Craig Tiller841c8802015-09-10 13:06:37 -07001502 else
Nicolas Noble53830622015-02-12 16:56:38 -08001503
Craig Tiller841c8802015-09-10 13:06:37 -07001504 % endif
Yuchen Zeng78f9f942016-08-05 18:21:57 -07001505 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: \
Nicolas "Pixel" Nobled649c212016-01-27 20:27:30 +01001506 % if lib.name != 'z':
1507 $(ZLIB_DEP) \
1508 % endif
Yuchen Zeng15141a62016-08-17 18:56:04 -07001509 % if lib.name != 'ares':
1510 $(CARES_DEP) \
Yuchen Zengf64bf282016-08-11 21:21:32 -07001511 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001512 % endif
1513 % if lib.language == 'c++':
1514 $(PROTOBUF_DEP)\
1515 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001516 $(LIB${lib.name.upper()}_OBJS) \
1517 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001518 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001519 $(ZLIB_MERGE_OBJS) \
Yuchen Zeng15141a62016-08-17 18:56:04 -07001520 $(CARES_MERGE_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001521 % if lib.get('secure', 'check') == True:
1522 $(OPENSSL_MERGE_OBJS) \
1523 % endif
1524 % endif
1525
Craig Tiller841c8802015-09-10 13:06:37 -07001526 $(E) "[AR] Creating $@"
1527 $(Q) mkdir -p `dirname $@`
1528 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Vijay Paicc7eb8e2016-07-19 19:03:55 -07001529 $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001530 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001531 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001532 $(ZLIB_MERGE_OBJS) \
Yuchen Zeng15141a62016-08-17 18:56:04 -07001533 $(CARES_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001534 % if lib.get('secure', 'check') == True:
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001535 $(OPENSSL_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001536 % endif
1537 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001538
Craig Tiller841c8802015-09-10 13:06:37 -07001539 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001540 $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tiller841c8802015-09-10 13:06:37 -07001541 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001542
Craig Tiller841c8802015-09-10 13:06:37 -07001543 <%
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001544
Craig Tiller841c8802015-09-10 13:06:37 -07001545 if lib.language == 'c++':
1546 ld = '$(LDXX)'
1547 else:
1548 ld = '$(LD)'
nnoble5b7f32a2014-12-22 08:12:44 -08001549
Craig Tiller40c8fba2016-09-15 16:29:09 -07001550 out_mingbase = '$(LIBDIR)/$(CONFIG)/' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
1551 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
nnoble5b7f32a2014-12-22 08:12:44 -08001552
Nicolas "Pixel" Noble8087d702017-02-01 02:23:50 +01001553 common = '$(LIB' + lib.name.upper() + '_OBJS)'
nnoble5b7f32a2014-12-22 08:12:44 -08001554
Craig Tillerd7b1bdf2016-11-04 16:20:13 -07001555 link_libs = ''
Yuchen Zeng9b5aa632016-07-26 19:09:56 -07001556 lib_deps = ' $(ZLIB_DEP) $(CARES_DEP)'
Craig Tiller841c8802015-09-10 13:06:37 -07001557 mingw_libs = ''
Yuchen Zeng9b5aa632016-07-26 19:09:56 -07001558 mingw_lib_deps = ' $(ZLIB_DEP) $(CARES_DEP)'
Craig Tiller841c8802015-09-10 13:06:37 -07001559 if lib.language == 'c++':
1560 lib_deps += ' $(PROTOBUF_DEP)'
1561 mingw_lib_deps += ' $(PROTOBUF_DEP)'
Jan Tattermusch324140c2016-01-12 08:54:01 -08001562 if lib.get('deps_linkage', None) == 'static':
1563 for dep in lib.get('deps', []):
1564 lib_archive = '$(LIBDIR)/$(CONFIG)/lib' + dep + '.a'
1565 common = common + ' ' + lib_archive
1566 lib_deps = lib_deps + ' ' + lib_archive
1567 mingw_lib_deps = mingw_lib_deps + ' ' + lib_archive
1568 else:
1569 for dep in lib.get('deps', []):
Craig Tillerd7b1bdf2016-11-04 16:20:13 -07001570 dep_lib = None
1571 for dl in libs:
1572 if dl.name == dep:
1573 dep_lib = dl
1574 assert dep_lib, 'lib %s not found (in %s)' % (dep, lib.name)
1575 link_libs = link_libs + ' -l' + dep
1576 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT_' + lang_to_var[dep_lib.language] + ')'
Mario Emmenlauer44b2d082017-01-13 12:35:49 +01001577 mingw_libs = mingw_libs + ' -l' + dep + '$(SHARED_VERSION_' + lang_to_var[dep_lib.language] + ')-dll'
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001578 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 -08001579
Craig Tiller841c8802015-09-10 13:06:37 -07001580 security = lib.get('secure', 'check')
1581 if security == True:
1582 common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)'
Yuchen Zeng15141a62016-08-17 18:56:04 -07001583 common = common + ' $(ZLIB_MERGE_LIBS) $(CARES_MERGE_LIBS)'
Nicolas "Pixel" Noblea7c162c2015-07-24 20:21:51 +02001584
Craig Tiller841c8802015-09-10 13:06:37 -07001585 if security in [True, 'check']:
1586 for src in lib.src:
1587 if not proto_re.match(src):
1588 sources_that_need_openssl.add(src)
1589 else:
1590 for src in lib.src:
1591 sources_that_don_t_need_openssl.add(src)
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001592
Craig Tiller841c8802015-09-10 13:06:37 -07001593 if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1594 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1595 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001596
Craig Tiller841c8802015-09-10 13:06:37 -07001597 if lib.language == 'c++':
1598 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
Craig Tiller4bef7ce2016-02-02 08:38:43 -08001599
1600 ldflags = '$(LDFLAGS)'
1601 if lib.get('LDFLAGS', None):
1602 ldflags += ' ' + lib['LDFLAGS']
Nicolas "Pixel" Noble8087d702017-02-01 02:23:50 +01001603
1604 common = common + ' $(LDLIBS)'
Craig Tiller841c8802015-09-10 13:06:37 -07001605 %>
nnoble5b7f32a2014-12-22 08:12:44 -08001606
Craig Tiller841c8802015-09-10 13:06:37 -07001607 % if lib.build == "all":
1608 ifeq ($(SYSTEM),MINGW32)
Craig Tiller38b99e92016-09-15 16:18:09 -07001609 ${out_mingbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Craig Tiller841c8802015-09-10 13:06:37 -07001610 $(E) "[LD] Linking $@"
1611 $(Q) mkdir -p `dirname $@`
Mario Emmenlauer294dc2f2016-12-13 00:07:12 +01001612 $(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 -07001613 else
Craig Tiller38b99e92016-09-15 16:18:09 -07001614 ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
Craig Tiller841c8802015-09-10 13:06:37 -07001615 $(E) "[LD] Linking $@"
1616 $(Q) mkdir -p `dirname $@`
1617 ifeq ($(SYSTEM),Darwin)
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001618 $(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 -07001619 else
murgatroid99d166e382017-03-24 10:03:10 -07001620 $(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 +01001621 $(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}
1622 $(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 -07001623 endif
1624 endif
1625 % endif
1626 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1627 ## If the lib was secure, we have to close the Makefile's if that tested
1628 ## the presence of OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001629
Craig Tiller841c8802015-09-10 13:06:37 -07001630 endif
1631 % endif
1632 % if lib.language == 'c++':
1633 ## If the lib was C++, we have to close the Makefile's if that tested
1634 ## the presence of protobuf 3.0.0+
nnoble69ac39f2014-12-12 15:43:38 -08001635
Craig Tiller841c8802015-09-10 13:06:37 -07001636 endif
1637 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001638
Craig Tiller841c8802015-09-10 13:06:37 -07001639 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1640 ifneq ($(NO_SECURE),true)
1641 % endif
1642 ifneq ($(NO_DEPS),true)
1643 -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
1644 endif
1645 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1646 endif
1647 % endif
1648 % for src in lib.src:
1649 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src):
1650 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))}
1651 % endif
1652 % endfor
1653 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001654
Craig Tiller841c8802015-09-10 13:06:37 -07001655 <%def name="maketarget(tgt)"><% has_no_sources = not tgt.src %>
1656 % if not has_no_sources:
1657 ${tgt.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001658
Craig Tiller841c8802015-09-10 13:06:37 -07001659 % for src in tgt.src:
1660 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001661
Craig Tiller841c8802015-09-10 13:06:37 -07001662 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001663
Craig Tiller841c8802015-09-10 13:06:37 -07001664 ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
1665 % endif
1666 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1667 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001668
Craig Tiller841c8802015-09-10 13:06:37 -07001669 # You can't build secure targets if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001670
Craig Tiller841c8802015-09-10 13:06:37 -07001671 $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001672
Craig Tiller841c8802015-09-10 13:06:37 -07001673 else
nnoble69ac39f2014-12-12 15:43:38 -08001674
Craig Tiller841c8802015-09-10 13:06:37 -07001675 % endif
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001676
1677 % if tgt.boringssl:
1678 # boringssl needs an override to ensure that it does not include
1679 # system openssl headers regardless of other configuration
1680 # we do so here with a target specific variable assignment
Craig Tiller78222f72016-05-10 09:55:38 -07001681 $(${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 -08001682 $(${tgt.name.upper()}_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS)
1683 $(${tgt.name.upper()}_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE
1684 % else:
1685 % endif
1686
Craig Tiller841c8802015-09-10 13:06:37 -07001687 ##
1688 ## We're not trying to add a dependency on building zlib and openssl here,
1689 ## as it's already done in the libraries. We're assuming that the build
1690 ## trickles down, and that a secure target requires a secure version of
1691 ## a library.
1692 ##
1693 ## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1694 ## I can live with that.
1695 ##
1696 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001697
Craig Tiller841c8802015-09-10 13:06:37 -07001698 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001699
Craig Tiller841c8802015-09-10 13:06:37 -07001700 # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+.
Nicolas Noble53830622015-02-12 16:56:38 -08001701
Craig Tiller841c8802015-09-10 13:06:37 -07001702 $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001703
Craig Tiller841c8802015-09-10 13:06:37 -07001704 else
Nicolas Noble53830622015-02-12 16:56:38 -08001705
Craig Tiller841c8802015-09-10 13:06:37 -07001706 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1707 % if not has_no_sources:
1708 $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
1709 % endif
1710 % else:
1711 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1712 % if not has_no_sources:
1713 $(${tgt.name.upper()}_OBJS)\
1714 % endif
1715 % endif
1716 % for dep in tgt.deps:
1717 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1718 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001719
Craig Tiller32173c52016-03-17 14:12:45 -07001720 % if tgt.language == "c++" or tgt.boringssl or tgt.build == 'fuzzer':
Craig Tiller841c8802015-09-10 13:06:37 -07001721 ## C++ targets specificies.
1722 % if tgt.build == 'protoc':
1723 $(E) "[HOSTLD] Linking $@"
1724 $(Q) mkdir -p `dirname $@`
1725 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) \
1726 % if not has_no_sources:
1727 $(${tgt.name.upper()}_OBJS)\
1728 % endif
1729 % else:
1730 $(E) "[LD] Linking $@"
1731 $(Q) mkdir -p `dirname $@`
1732 $(Q) $(LDXX) $(LDFLAGS) \
1733 % if not has_no_sources:
1734 $(${tgt.name.upper()}_OBJS)\
1735 % endif
1736 % endif
1737 % else:
1738 ## C-only targets specificities.
1739 $(E) "[LD] Linking $@"
1740 $(Q) mkdir -p `dirname $@`
1741 $(Q) $(LD) $(LDFLAGS) \
1742 % if not has_no_sources:
1743 $(${tgt.name.upper()}_OBJS)\
1744 % endif
1745 % endif
1746 % for dep in tgt.deps:
1747 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1748 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001749 % if tgt.language == "c++":
1750 % if tgt.build == 'protoc':
1751 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
1752 % else:
1753 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
1754 % endif
1755 % endif
1756 % if tgt.build == 'protoc':
1757 $(HOST_LDLIBS)\
1758 % else:
1759 $(LDLIBS)\
1760 % endif
1761 % if tgt.build == 'protoc':
1762 $(HOST_LDLIBS_PROTOC)\
1763 % elif tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1764 $(LDLIBS_SECURE)\
1765 % endif
1766 % if tgt.language == 'c++' and tgt.build == 'test':
1767 $(GTEST_LIB)\
1768 % elif tgt.language == 'c++' and tgt.build == 'benchmark':
1769 $(GTEST_LIB)\
1770 % endif
Craig Tiller32173c52016-03-17 14:12:45 -07001771 % if tgt.build == 'fuzzer':
1772 -lFuzzer\
1773 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001774 -o $(BINDIR)/$(CONFIG)/${tgt.name}
1775 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001776
Craig Tiller841c8802015-09-10 13:06:37 -07001777 endif
1778 % endif
1779 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001780
Craig Tiller841c8802015-09-10 13:06:37 -07001781 endif
1782 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001783
Craig Tiller19f3ea22017-02-17 15:17:05 -08001784 % if tgt.get('defaults', None):
1785 % for name, value in defaults.get(tgt.defaults).iteritems():
1786 $(${tgt.name.upper()}_OBJS): ${name} += ${value}
1787 % endfor
1788 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001789 % for src in tgt.src:
1790 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
1791 % for dep in tgt.deps:
1792 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1793 % endfor
Craig Tillerf5371ef2015-01-12 16:40:18 -08001794
Craig Tillerab230452016-01-04 08:18:43 -08001795 % if tgt.language == 'c89':
1796 % for src in tgt.src:
Craig Tillerea21ca22016-01-04 12:34:29 -08001797 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o : ${src}
1798 $(E) "[C] Compiling $<"
1799 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001800 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -std=c89 -pedantic -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Craig Tillerab230452016-01-04 08:18:43 -08001801 % endfor
1802 % endif
1803
Craig Tiller841c8802015-09-10 13:06:37 -07001804 % endfor
1805 % if not has_no_sources:
1806 deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
1807 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001808
Craig Tiller841c8802015-09-10 13:06:37 -07001809 % if not has_no_sources:
1810 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1811 ifneq ($(NO_SECURE),true)
1812 % endif
1813 ifneq ($(NO_DEPS),true)
1814 -include $(${tgt.name.upper()}_OBJS:.o=.dep)
1815 endif
1816 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1817 endif
1818 % endif
1819 % endif
Nicolas "Pixel" Noble472bb682015-11-03 19:09:01 +01001820 % for src in tgt.src:
1821 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in tgt.src):
1822 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in tgt.src if proto_re.match(src2))}
1823 % endif
1824 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001825 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001826
Craig Tiller841c8802015-09-10 13:06:37 -07001827 ifneq ($(OPENSSL_DEP),)
1828 # This is to ensure the embedded OpenSSL is built beforehand, properly
1829 # installing headers to their final destination on the drive. We need this
1830 # otherwise parallel compilation will fail if a source is compiled first.
1831 % for src in sorted(sources_that_need_openssl):
1832 % if src not in sources_that_don_t_need_openssl:
1833 ${src}: $(OPENSSL_DEP)
1834 % endif
1835 % endfor
1836 endif
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001837
Craig Tiller841c8802015-09-10 13:06:37 -07001838 .PHONY: all strip tools \
1839 dep_error openssl_dep_error openssl_dep_message git_update stop \
1840 buildtests buildtests_c buildtests_cxx \
1841 test test_c test_cxx \
1842 install install_c install_cxx \
1843 install-headers install-headers_c install-headers_cxx \
1844 install-shared install-shared_c install-shared_cxx \
1845 install-static install-static_c install-static_cxx \
1846 strip strip-shared strip-static \
1847 strip_c strip-shared_c strip-static_c \
1848 strip_cxx strip-shared_cxx strip-static_cxx \
1849 dep_c dep_cxx bins_dep_c bins_dep_cxx \
1850 clean
Craig Tillerb79c1e12016-02-23 10:00:58 -08001851
1852 .PHONY: printvars
1853 printvars:
1854 @$(foreach V,$(sort $(.VARIABLES)), \
1855 $(if $(filter-out environment% default automatic, \
1856 $(origin $V)),$(warning $V=$($V) ($(value $V)))))