blob: f81d64399136940fea355eabcc2ad6a77fd623e6 [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
Craig Tiller841c8802015-09-10 13:06:37 -0700314 GTEST_LIB = -Ithird_party/googletest/include -Ithird_party/googletest third_party/googletest/src/gtest-all.cc
315 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)
Mario Emmenlauer121d2892016-12-12 23:49:27 +0100408 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
Mario Emmenlauer121d2892016-12-12 23:49:27 +0100417 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
Craig Tiller841c8802015-09-10 13:06:37 -0700438 else # HAS_PKG_CONFIG
murgatroid9924e2f4a2015-06-29 11:12:01 -0700439
Craig Tiller841c8802015-09-10 13:06:37 -0700440 ifeq ($(SYSTEM),MINGW32)
441 OPENSSL_LIBS = ssl32 eay32
442 else
443 OPENSSL_LIBS = ssl crypto
444 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700445
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100446 OPENSSL_ALPN_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
447 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 -0800448 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 +0100449 ZLIB_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
450 PROTOBUF_CHECK_CMD = $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
Craig Tiller297fafa2015-01-15 15:46:39 -0800451
Craig Tiller841c8802015-09-10 13:06:37 -0700452 endif # HAS_PKG_CONFIG
murgatroid9924e2f4a2015-06-29 11:12:01 -0700453
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100454 PERFTOOLS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
murgatroid996d9e4012015-07-08 10:22:45 -0700455
Craig Tiller841c8802015-09-10 13:06:37 -0700456 PROTOC_CHECK_CMD = which protoc > /dev/null
457 PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3
458 DTRACE_CHECK_CMD = which dtrace > /dev/null
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100459 SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS)
murgatroid9924e2f4a2015-06-29 11:12:01 -0700460
Craig Tiller841c8802015-09-10 13:06:37 -0700461 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
462 HAS_SYSTEM_PERFTOOLS ?= $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
463 ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
464 DEFINES += GRPC_HAVE_PERFTOOLS
465 LIBS += profiler
466 CACHE_MK += HAS_SYSTEM_PERFTOOLS = true,
467 endif
468 endif
nnoble69ac39f2014-12-12 15:43:38 -0800469
Craig Tiller841c8802015-09-10 13:06:37 -0700470 HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
471 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
472 HAS_SYSTEM_OPENSSL_ALPN ?= $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
473 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
474 HAS_SYSTEM_OPENSSL_NPN = true
475 CACHE_MK += HAS_SYSTEM_OPENSSL_ALPN = true,
476 else
477 HAS_SYSTEM_OPENSSL_NPN ?= $(shell $(OPENSSL_NPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
478 endif
479 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
480 CACHE_MK += HAS_SYSTEM_OPENSSL_NPN = true,
481 endif
482 HAS_SYSTEM_ZLIB ?= $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
483 ifeq ($(HAS_SYSTEM_ZLIB),true)
484 CACHE_MK += HAS_SYSTEM_ZLIB = true,
485 endif
486 HAS_SYSTEM_PROTOBUF ?= $(HAS_SYSTEM_PROTOBUF_VERIFY)
487 ifeq ($(HAS_SYSTEM_PROTOBUF),true)
488 CACHE_MK += HAS_SYSTEM_PROTOBUF = true,
489 endif
490 else
491 # override system libraries if the config requires a custom compiled library
492 HAS_SYSTEM_OPENSSL_ALPN = false
493 HAS_SYSTEM_OPENSSL_NPN = false
494 HAS_SYSTEM_ZLIB = false
495 HAS_SYSTEM_PROTOBUF = false
496 endif
nnoble69ac39f2014-12-12 15:43:38 -0800497
Craig Tiller841c8802015-09-10 13:06:37 -0700498 HAS_PROTOC ?= $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
499 ifeq ($(HAS_PROTOC),true)
500 CACHE_MK += HAS_PROTOC = true,
501 HAS_VALID_PROTOC ?= $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false)
502 ifeq ($(HAS_VALID_PROTOC),true)
503 CACHE_MK += HAS_VALID_PROTOC = true,
504 endif
505 else
506 HAS_VALID_PROTOC = false
507 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800508
Craig Tiller841c8802015-09-10 13:06:37 -0700509 # Check for Systemtap (https://sourceware.org/systemtap/), first by making sure <sys/sdt.h> is present
510 # in the system and secondly by checking for the "dtrace" binary (on Linux, this is part of the Systemtap
511 # distribution. It's part of the base system on BSD/Solaris machines).
512 ifndef HAS_SYSTEMTAP
513 HAS_SYSTEMTAP_HEADERS = $(shell $(SYSTEMTAP_HEADERS_CHECK_CMD) 2> /dev/null && echo true || echo false)
514 HAS_DTRACE = $(shell $(DTRACE_CHECK_CMD) 2> /dev/null && echo true || echo false)
515 HAS_SYSTEMTAP = false
516 ifeq ($(HAS_SYSTEMTAP_HEADERS),true)
517 ifeq ($(HAS_DTRACE),true)
518 HAS_SYSTEMTAP = true
519 endif
520 endif
521 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -0700522
Craig Tiller841c8802015-09-10 13:06:37 -0700523 ifeq ($(HAS_SYSTEMTAP),true)
524 CACHE_MK += HAS_SYSTEMTAP = true,
525 endif
nnoble69ac39f2014-12-12 15:43:38 -0800526
Craig Tiller841c8802015-09-10 13:06:37 -0700527 # Note that for testing purposes, one can do:
528 # make HAS_EMBEDDED_OPENSSL_ALPN=false
529 # to emulate the fact we do not have OpenSSL in the third_party folder.
Craig Tillerb79c1e12016-02-23 10:00:58 -0800530 ifneq ($(wildcard third_party/${openssl_fallback.extraction_dir}/libssl.a),)
531 HAS_EMBEDDED_OPENSSL_ALPN = third_party/${openssl_fallback.extraction_dir}
532 else ifeq ($(wildcard third_party/boringssl/include/openssl/ssl.h),)
Craig Tiller841c8802015-09-10 13:06:37 -0700533 HAS_EMBEDDED_OPENSSL_ALPN = false
534 else
Craig Tillerb79c1e12016-02-23 10:00:58 -0800535 CAN_COMPILE_EMBEDDED_OPENSSL ?= $(shell $(BORINGSSL_COMPILE_CHECK_CMD) 2> /dev/null && echo true || echo false)
536 HAS_EMBEDDED_OPENSSL_ALPN = $(CAN_COMPILE_EMBEDDED_OPENSSL)
Craig Tiller841c8802015-09-10 13:06:37 -0700537 endif
nnoble69ac39f2014-12-12 15:43:38 -0800538
Craig Tiller841c8802015-09-10 13:06:37 -0700539 ifeq ($(wildcard third_party/zlib/zlib.h),)
540 HAS_EMBEDDED_ZLIB = false
541 else
542 HAS_EMBEDDED_ZLIB = true
543 endif
nnoble69ac39f2014-12-12 15:43:38 -0800544
Craig Tiller841c8802015-09-10 13:06:37 -0700545 ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
546 HAS_EMBEDDED_PROTOBUF = false
547 ifneq ($(HAS_VALID_PROTOC),true)
548 NO_PROTOC = true
549 endif
550 else
551 HAS_EMBEDDED_PROTOBUF = true
552 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800553
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100554 PC_REQUIRES_GRPC =
Craig Tiller841c8802015-09-10 13:06:37 -0700555 PC_LIBS_GRPC =
murgatroid998faab232015-06-30 17:24:21 -0700556
Craig Tiller841c8802015-09-10 13:06:37 -0700557 ifeq ($(HAS_SYSTEM_ZLIB),false)
Craig Tiller3dca23a2016-01-21 11:44:55 -0800558 ifeq ($(HAS_EMBEDDED_ZLIB), true)
559 EMBED_ZLIB ?= true
Craig Tiller841c8802015-09-10 13:06:37 -0700560 else
561 DEP_MISSING += zlib
Craig Tiller3dca23a2016-01-21 11:44:55 -0800562 EMBED_ZLIB ?= broken
Craig Tiller841c8802015-09-10 13:06:37 -0700563 endif
564 else
Craig Tiller3dca23a2016-01-21 11:44:55 -0800565 EMBED_ZLIB ?= false
566 endif
567
568 ifeq ($(EMBED_ZLIB),true)
569 ZLIB_DEP = $(LIBDIR)/$(CONFIG)/libz.a
570 ZLIB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libz.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +0100571 ZLIB_MERGE_OBJS = $(LIBZ_OBJS)
Craig Tiller3dca23a2016-01-21 11:44:55 -0800572 CPPFLAGS += -Ithird_party/zlib
573 LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib
574 else
Craig Tiller841c8802015-09-10 13:06:37 -0700575 ifeq ($(HAS_PKG_CONFIG),true)
576 CPPFLAGS += $(shell $(PKG_CONFIG) --cflags zlib)
577 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L zlib)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800578 LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l zlib))
Craig Tiller841c8802015-09-10 13:06:37 -0700579 PC_REQUIRES_GRPC += zlib
580 else
581 PC_LIBS_GRPC += -lz
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800582 LIBS += z
Craig Tiller841c8802015-09-10 13:06:37 -0700583 endif
584 endif
nnoble69ac39f2014-12-12 15:43:38 -0800585
Craig Tiller841c8802015-09-10 13:06:37 -0700586 OPENSSL_PKG_CONFIG = false
murgatroid99da7a9942015-06-29 14:57:37 -0700587
Craig Tiller841c8802015-09-10 13:06:37 -0700588 PC_REQUIRES_SECURE =
589 PC_LIBS_SECURE =
murgatroid998faab232015-06-30 17:24:21 -0700590
Craig Tiller841c8802015-09-10 13:06:37 -0700591 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800592 EMBED_OPENSSL ?= false
593 NO_SECURE ?= false
594 else # HAS_SYSTEM_OPENSSL_ALPN=false
Craig Tillerb79c1e12016-02-23 10:00:58 -0800595 ifneq ($(HAS_EMBEDDED_OPENSSL_ALPN),false)
596 EMBED_OPENSSL ?= $(HAS_EMBEDDED_OPENSSL_ALPN)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800597 NO_SECURE ?= false
598 else # HAS_EMBEDDED_OPENSSL_ALPN=false
599 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
600 EMBED_OPENSSL ?= false
601 NO_SECURE ?= false
602 else
603 NO_SECURE ?= true
604 endif # HAS_SYSTEM_OPENSSL_NPN=true
605 endif # HAS_EMBEDDED_OPENSSL_ALPN
606 endif # HAS_SYSTEM_OPENSSL_ALPN
607
608 OPENSSL_DEP :=
609 OPENSSL_MERGE_LIBS :=
610 ifeq ($(NO_SECURE),false)
611 ifeq ($(EMBED_OPENSSL),true)
612 OPENSSL_DEP += $(LIBDIR)/$(CONFIG)/libboringssl.a
613 OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/libboringssl.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +0100614 OPENSSL_MERGE_OBJS += $(LIBBORINGSSL_OBJS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800615 # need to prefix these to ensure overriding system libraries
616 CPPFLAGS := -Ithird_party/boringssl/include $(CPPFLAGS)
Craig Tillerb79c1e12016-02-23 10:00:58 -0800617 else ifneq ($(EMBED_OPENSSL),false)
618 OPENSSL_DEP += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
619 OPENSSL_MERGE_LIBS += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
620 OPENSSL_MERGE_OBJS += $(wildcard $(EMBED_OPENSSL)/grpc_obj/*.o)
621 # need to prefix these to ensure overriding system libraries
622 CPPFLAGS := -I$(EMBED_OPENSSL)/include $(CPPFLAGS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800623 else # EMBED_OPENSSL=false
Craig Tiller841c8802015-09-10 13:06:37 -0700624 ifeq ($(HAS_PKG_CONFIG),true)
625 OPENSSL_PKG_CONFIG = true
626 PC_REQUIRES_SECURE = openssl
627 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags openssl) $(CPPFLAGS)
628 LDFLAGS_OPENSSL_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L openssl)
629 ifeq ($(SYSTEM),Linux)
630 ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),)
631 LDFLAGS_OPENSSL_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L openssl | sed s/L/Wl,-rpath,/)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800632 endif # LDFLAGS_OPENSSL_PKG_CONFIG=''
633 endif # System=Linux
Craig Tiller841c8802015-09-10 13:06:37 -0700634 LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800635 else # HAS_PKG_CONFIG=false
Craig Tiller841c8802015-09-10 13:06:37 -0700636 LIBS_SECURE = $(OPENSSL_LIBS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800637 endif # HAS_PKG_CONFIG
638 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
639 CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0
640 LIBS_SECURE = $(OPENSSL_LIBS)
641 endif # HAS_SYSTEM_OPENSSL_NPN
Craig Tiller841c8802015-09-10 13:06:37 -0700642 PC_LIBS_SECURE = $(addprefix -l, $(LIBS_SECURE))
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800643 endif # EMBED_OPENSSL
644 endif # NO_SECURE
nnoble69ac39f2014-12-12 15:43:38 -0800645
Craig Tiller841c8802015-09-10 13:06:37 -0700646 ifeq ($(OPENSSL_PKG_CONFIG),true)
647 LDLIBS_SECURE += $(shell $(PKG_CONFIG) --libs-only-l openssl)
648 else
649 LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
650 endif
nnoble5b7f32a2014-12-22 08:12:44 -0800651
Craig Tiller841c8802015-09-10 13:06:37 -0700652 # grpc .pc file
653 PC_NAME = gRPC
Craig Tillerda179ce2016-02-09 12:01:53 -0800654 PC_DESCRIPTION = high performance general RPC framework
655 PC_CFLAGS =
656 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC) $(PC_REQUIRES_SECURE)
Craig Tiller841c8802015-09-10 13:06:37 -0700657 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) $(PC_LIBS_SECURE)
658 PC_LIB = -lgrpc
Craig Tiller38b99e92016-09-15 16:18:09 -0700659 GRPC_PC_FILE := $(CORE_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700660
Craig Tiller4a67be42016-02-09 12:40:32 -0800661 # grpc_unsecure .pc file
Craig Tiller841c8802015-09-10 13:06:37 -0700662 PC_NAME = gRPC unsecure
Craig Tillerda179ce2016-02-09 12:01:53 -0800663 PC_DESCRIPTION = high performance general RPC framework without SSL
664 PC_CFLAGS =
665 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC)
Craig Tiller841c8802015-09-10 13:06:37 -0700666 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC)
667 PC_LIB = -lgrpc
Craig Tiller38b99e92016-09-15 16:18:09 -0700668 GRPC_UNSECURE_PC_FILE := $(CORE_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700669
Craig Tiller841c8802015-09-10 13:06:37 -0700670 PROTOBUF_PKG_CONFIG = false
murgatroid99da7a9942015-06-29 14:57:37 -0700671
Craig Tiller841c8802015-09-10 13:06:37 -0700672 PC_REQUIRES_GRPCXX =
673 PC_LIBS_GRPCXX =
murgatroid998faab232015-06-30 17:24:21 -0700674
Craig Tiller841c8802015-09-10 13:06:37 -0700675 CPPFLAGS := -Ithird_party/googletest/include $(CPPFLAGS)
Craig Tiller16f6dac2015-08-24 17:00:04 -0700676
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700677 PROTOC_PLUGINS_ALL =\
678 % for tgt in targets:
679 % if tgt.build == 'protoc':
680 $(BINDIR)/$(CONFIG)/${tgt.name}\
681 % endif
682 % endfor
683
684 PROTOC_PLUGINS_DIR = $(BINDIR)/$(CONFIG)
685
Craig Tiller841c8802015-09-10 13:06:37 -0700686 ifeq ($(HAS_SYSTEM_PROTOBUF),true)
687 ifeq ($(HAS_PKG_CONFIG),true)
688 PROTOBUF_PKG_CONFIG = true
689 PC_REQUIRES_GRPCXX = protobuf
690 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags protobuf) $(CPPFLAGS)
691 LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L protobuf)
692 ifeq ($(SYSTEM),Linux)
693 ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),)
694 LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L protobuf | sed s/L/Wl,-rpath,/)
695 endif
696 endif
697 else
698 PC_LIBS_GRPCXX = -lprotobuf
699 endif
Nicolas "Pixel" Noblef7fbdd42016-07-25 20:31:22 +0200700 PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
Craig Tiller841c8802015-09-10 13:06:37 -0700701 else
702 ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
703 PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
704 CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
705 LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700706 ifneq ($(USE_BUILT_PROTOC),false)
Craig Tiller841c8802015-09-10 13:06:37 -0700707 PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700708 PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
709 else
710 PROTOC_PLUGINS =
711 PROTOC_PLUGINS_DIR = $(prefix)/bin
712 endif
Craig Tiller841c8802015-09-10 13:06:37 -0700713 else
714 NO_PROTOBUF = true
715 endif
716 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800717
Craig Tiller841c8802015-09-10 13:06:37 -0700718 LIBS_PROTOBUF = protobuf
719 LIBS_PROTOC = protoc protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800720
Craig Tiller841c8802015-09-10 13:06:37 -0700721 HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
Nicolas Noble53830622015-02-12 16:56:38 -0800722
Craig Tiller841c8802015-09-10 13:06:37 -0700723 ifeq ($(PROTOBUF_PKG_CONFIG),true)
724 LDLIBS_PROTOBUF += $(shell $(PKG_CONFIG) --libs-only-l protobuf)
725 else
726 LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
727 endif
murgatroid9924e2f4a2015-06-29 11:12:01 -0700728
Craig Tiller841c8802015-09-10 13:06:37 -0700729 # grpc++ .pc file
730 PC_NAME = gRPC++
731 PC_DESCRIPTION = C++ wrapper for gRPC
732 PC_CFLAGS =
733 PC_REQUIRES_PRIVATE = grpc $(PC_REQUIRES_GRPCXX)
734 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
735 PC_LIB = -lgrpc++
Craig Tiller38b99e92016-09-15 16:18:09 -0700736 GRPCXX_PC_FILE := $(CPP_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700737
Craig Tiller841c8802015-09-10 13:06:37 -0700738 # grpc++_unsecure .pc file
739 PC_NAME = gRPC++ unsecure
740 PC_DESCRIPTION = C++ wrapper for gRPC without SSL
741 PC_CFLAGS =
742 PC_REQUIRES_PRIVATE = grpc_unsecure $(PC_REQUIRES_GRPCXX)
743 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
744 PC_LIB = -lgrpc++
Craig Tiller38b99e92016-09-15 16:18:09 -0700745 GRPCXX_UNSECURE_PC_FILE := $(CPP_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700746
Craig Tiller841c8802015-09-10 13:06:37 -0700747 ifeq ($(MAKECMDGOALS),clean)
748 NO_DEPS = true
749 endif
nnoble69ac39f2014-12-12 15:43:38 -0800750
Craig Tiller841c8802015-09-10 13:06:37 -0700751 .SECONDARY = %.pb.h %.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800752
Craig Tiller841c8802015-09-10 13:06:37 -0700753 ifeq ($(DEP_MISSING),)
754 all: static shared plugins\
755 % for tgt in targets:
756 % if tgt.build == 'all':
757 $(BINDIR)/$(CONFIG)/${tgt.name}\
758 % endif
759 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800760
Craig Tiller841c8802015-09-10 13:06:37 -0700761 dep_error:
762 @echo "You shouldn't see this message - all of your dependencies are correct."
763 else
764 all: dep_error git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800765
Craig Tiller841c8802015-09-10 13:06:37 -0700766 dep_error:
767 @echo
768 @echo "DEPENDENCY ERROR"
769 @echo
770 @echo "You are missing system dependencies that are essential to build grpc,"
771 @echo "and the third_party directory doesn't have them:"
772 @echo
773 @echo " $(DEP_MISSING)"
774 @echo
775 @echo "Installing the development packages for your system will solve"
776 @echo "this issue. Please consult INSTALL to get more information."
777 @echo
778 @echo "If you need information about why these tests failed, run:"
779 @echo
780 @echo " make run_dep_checks"
781 @echo
782 endif
nnoble69ac39f2014-12-12 15:43:38 -0800783
Craig Tiller841c8802015-09-10 13:06:37 -0700784 git_update:
785 ifeq ($(IS_GIT_FOLDER),true)
786 @echo "Additionally, since you are in a git clone, you can download the"
787 @echo "missing dependencies in third_party by running the following command:"
788 @echo
789 @echo " git submodule update --init"
790 @echo
791 endif
nnoble69ac39f2014-12-12 15:43:38 -0800792
Craig Tiller841c8802015-09-10 13:06:37 -0700793 openssl_dep_error: openssl_dep_message git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800794
Craig Tiller841c8802015-09-10 13:06:37 -0700795 protobuf_dep_error: protobuf_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800796
Craig Tiller841c8802015-09-10 13:06:37 -0700797 protoc_dep_error: protoc_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800798
Craig Tiller841c8802015-09-10 13:06:37 -0700799 openssl_dep_message:
800 @echo
801 @echo "DEPENDENCY ERROR"
802 @echo
Craig Tillerb79c1e12016-02-23 10:00:58 -0800803 @echo "The target you are trying to run requires an OpenSSL implementation."
804 @echo "Your system doesn't have one, and either the third_party directory"
805 @echo "doesn't have it, or your compiler can't build BoringSSL."
Craig Tiller841c8802015-09-10 13:06:37 -0700806 @echo
807 @echo "Please consult INSTALL to get more information."
808 @echo
809 @echo "If you need information about why these tests failed, run:"
810 @echo
811 @echo " make run_dep_checks"
812 @echo
nnoble69ac39f2014-12-12 15:43:38 -0800813
Craig Tiller841c8802015-09-10 13:06:37 -0700814 protobuf_dep_message:
815 @echo
816 @echo "DEPENDENCY ERROR"
817 @echo
818 @echo "The target you are trying to run requires protobuf 3.0.0+"
819 @echo "Your system doesn't have it, and neither does the third_party directory."
820 @echo
821 @echo "Please consult INSTALL to get more information."
822 @echo
823 @echo "If you need information about why these tests failed, run:"
824 @echo
825 @echo " make run_dep_checks"
826 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800827
Craig Tiller841c8802015-09-10 13:06:37 -0700828 protoc_dep_message:
829 @echo
830 @echo "DEPENDENCY ERROR"
831 @echo
832 @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
833 @echo "Your system doesn't have it, and neither does the third_party directory."
834 @echo
835 @echo "Please consult INSTALL to get more information."
836 @echo
837 @echo "If you need information about why these tests failed, run:"
838 @echo
839 @echo " make run_dep_checks"
840 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800841
Craig Tiller841c8802015-09-10 13:06:37 -0700842 systemtap_dep_error:
843 @echo
844 @echo "DEPENDENCY ERROR"
845 @echo
846 @echo "Under the '$(CONFIG)' configutation, the target you are trying "
847 @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other "
848 @echo "platforms such as Solaris and *BSD). "
849 @echo
850 @echo "Please consult INSTALL to get more information."
851 @echo
David Garcia Quintas8954e902015-04-29 09:46:33 -0700852
Craig Tiller841c8802015-09-10 13:06:37 -0700853 stop:
854 @false
nnoble69ac39f2014-12-12 15:43:38 -0800855
Craig Tiller841c8802015-09-10 13:06:37 -0700856 % for tgt in targets:
857 ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
858 % endfor
ctiller09cb6d52014-12-19 17:38:22 -0800859
Craig Tiller841c8802015-09-10 13:06:37 -0700860 run_dep_checks:
861 $(OPENSSL_ALPN_CHECK_CMD) || true
862 $(OPENSSL_NPN_CHECK_CMD) || true
863 $(ZLIB_CHECK_CMD) || true
864 $(PERFTOOLS_CHECK_CMD) || true
865 $(PROTOBUF_CHECK_CMD) || true
866 $(PROTOC_CHECK_VERSION_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800867
Craig Tiller841c8802015-09-10 13:06:37 -0700868 third_party/protobuf/configure:
869 $(E) "[AUTOGEN] Preparing protobuf"
870 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
Nicolas Noble53830622015-02-12 16:56:38 -0800871
Craig Tiller841c8802015-09-10 13:06:37 -0700872 $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
873 $(E) "[MAKE] Building protobuf"
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700874 $(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 -0700875 $(Q)$(MAKE) -C third_party/protobuf clean
876 $(Q)$(MAKE) -C third_party/protobuf
877 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
878 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
879 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
880 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
881 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800882
Craig Tiller841c8802015-09-10 13:06:37 -0700883 static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800884
Craig Tillereda85c62016-07-01 12:45:19 -0700885 static_c: pc_c pc_c_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700886 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100887 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700888 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
889 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
890 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100891 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700892 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800893
894
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100895 static_cxx: pc_cxx pc_cxx_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700896 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100897 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700898 % if lib.build == 'all' and lib.language == 'c++':
899 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
900 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100901 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700902 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800903
904
Craig Tiller841c8802015-09-10 13:06:37 -0700905 shared: shared_c shared_cxx
nnoble29e1d292014-12-01 10:27:40 -0800906
Craig Tillereda85c62016-07-01 12:45:19 -0700907 shared_c: pc_c pc_c_unsecure cache.mk\
Craig Tiller841c8802015-09-10 13:06:37 -0700908 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100909 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700910 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -0700911 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)\
Craig Tiller841c8802015-09-10 13:06:37 -0700912 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100913 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700914 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800915
Craig Tiller841c8802015-09-10 13:06:37 -0700916 shared_cxx: pc_cxx pc_cxx_unsecure cache.mk\
917 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100918 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700919 % if lib.build == 'all' and lib.language == 'c++':
Craig Tiller27f70842016-09-15 16:21:54 -0700920 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)\
Craig Tiller841c8802015-09-10 13:06:37 -0700921 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100922 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700923 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800924
925
Craig Tiller841c8802015-09-10 13:06:37 -0700926 shared_csharp: shared_c \
927 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100928 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700929 % if lib.build == 'all' and lib.language == 'csharp':
Craig Tiller27f70842016-09-15 16:21:54 -0700930 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)\
Craig Tiller841c8802015-09-10 13:06:37 -0700931 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100932 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700933 % endfor
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800934
Craig Tiller841c8802015-09-10 13:06:37 -0700935 grpc_csharp_ext: shared_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800936
Craig Tiller841c8802015-09-10 13:06:37 -0700937 plugins: $(PROTOC_PLUGINS)
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100938
Craig Tiller841c8802015-09-10 13:06:37 -0700939 privatelibs: privatelibs_c privatelibs_cxx
nnoble29e1d292014-12-01 10:27:40 -0800940
Craig Tiller841c8802015-09-10 13:06:37 -0700941 privatelibs_c: \
942 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100943 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800944 % 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 -0700945 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
946 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100947 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700948 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800949
Craig Tiller841c8802015-09-10 13:06:37 -0700950 pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc
murgatroid998faab232015-06-30 17:24:21 -0700951
Craig Tiller841c8802015-09-10 13:06:37 -0700952 pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -0700953
Craig Tiller841c8802015-09-10 13:06:37 -0700954 pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc
murgatroid998faab232015-06-30 17:24:21 -0700955
Craig Tiller841c8802015-09-10 13:06:37 -0700956 pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800957
vjpai20410922016-06-15 09:21:42 -0700958 ifeq ($(EMBED_OPENSSL),true)
Craig Tiller841c8802015-09-10 13:06:37 -0700959 privatelibs_cxx: \
960 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100961 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700962 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None):
963 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
964 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100965 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700966 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -0700967
vjpai20410922016-06-15 09:21:42 -0700968 else
969 privatelibs_cxx: \
970 % for lib in libs:
971 % if 'Makefile' in lib.get('build_system', ['Makefile']):
972 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None) and not lib.boringssl:
973 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
974 % endif
975 % endif
976 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -0700977
vjpai20410922016-06-15 09:21:42 -0700978 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800979
980
Craig Tillereda85c62016-07-01 12:45:19 -0700981 buildtests: buildtests_c buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -0800982
Craig Tiller3824b6e2015-12-09 11:19:59 -0800983 buildtests_c: privatelibs_c <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700984 % for tgt in targets:
985 % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -0800986 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700987 % endif
988 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800989
990
vjpai20410922016-06-15 09:21:42 -0700991 ifeq ($(EMBED_OPENSSL),true)
Craig Tillereda85c62016-07-01 12:45:19 -0700992 buildtests_cxx: privatelibs_cxx <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700993 % for tgt in targets:
994 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -0800995 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700996 % endif
997 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -0700998
vjpai20410922016-06-15 09:21:42 -0700999 else
Craig Tillereda85c62016-07-01 12:45:19 -07001000 buildtests_cxx: privatelibs_cxx <%text>\</%text>
vjpai20410922016-06-15 09:21:42 -07001001 % for tgt in targets:
1002 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl:
1003 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
1004 % endif
1005 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -07001006
vjpai20410922016-06-15 09:21:42 -07001007 endif
nnoble29e1d292014-12-01 10:27:40 -08001008
1009
Craig Tillereda85c62016-07-01 12:45:19 -07001010 test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -08001011
Craig Tillereda85c62016-07-01 12:45:19 -07001012 flaky_test: flaky_test_c flaky_test_cxx
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001013
Craig Tiller841c8802015-09-10 13:06:37 -07001014 test_c: buildtests_c
1015 % for tgt in targets:
1016 % 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):
1017 $(E) "[RUN] Testing ${tgt.name}"
1018 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1019 % endif
1020 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001021
1022
Craig Tiller841c8802015-09-10 13:06:37 -07001023 flaky_test_c: buildtests_c
1024 % for tgt in targets:
1025 % 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):
1026 $(E) "[RUN] Testing ${tgt.name}"
1027 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1028 % endif
1029 % endfor
nnoble29e1d292014-12-01 10:27:40 -08001030
1031
Craig Tillereda85c62016-07-01 12:45:19 -07001032 test_cxx: buildtests_cxx
Craig Tiller841c8802015-09-10 13:06:37 -07001033 % for tgt in targets:
1034 % 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):
1035 $(E) "[RUN] Testing ${tgt.name}"
1036 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1037 % endif
1038 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001039
1040
Craig Tiller841c8802015-09-10 13:06:37 -07001041 flaky_test_cxx: buildtests_cxx
1042 % for tgt in targets:
1043 % 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):
1044 $(E) "[RUN] Testing ${tgt.name}"
1045 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1046 % endif
1047 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001048
1049
Craig Tiller841c8802015-09-10 13:06:37 -07001050 test_python: static_c
1051 $(E) "[RUN] Testing python code"
1052 $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
Nicolas "Pixel" Noble051a28f2015-03-17 22:54:54 +01001053
1054
Craig Tiller841c8802015-09-10 13:06:37 -07001055 tools: tools_c tools_cxx
Craig Tiller7552f0f2015-06-19 17:46:20 -07001056
1057
Craig Tiller841c8802015-09-10 13:06:37 -07001058 tools_c: privatelibs_c\
1059 % for tgt in targets:
1060 % if tgt.build == 'tool' and not tgt.language=='c++':
1061 $(BINDIR)/$(CONFIG)/${tgt.name}\
1062 % endif
1063 % endfor
Craig Tiller7552f0f2015-06-19 17:46:20 -07001064
1065
Craig Tiller841c8802015-09-10 13:06:37 -07001066 tools_cxx: privatelibs_cxx\
1067 % for tgt in targets:
1068 % if tgt.build == 'tool' and tgt.language=='c++':
1069 $(BINDIR)/$(CONFIG)/${tgt.name}\
1070 % endif
1071 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001072
1073
Craig Tiller841c8802015-09-10 13:06:37 -07001074 buildbenchmarks: privatelibs\
1075 % for tgt in targets:
1076 % if tgt.build == 'benchmark':
1077 $(BINDIR)/$(CONFIG)/${tgt.name}\
1078 % endif
1079 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001080
1081
Craig Tiller841c8802015-09-10 13:06:37 -07001082 benchmarks: buildbenchmarks
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001083
Craig Tiller841c8802015-09-10 13:06:37 -07001084 strip: strip-static strip-shared
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001085
Craig Tiller841c8802015-09-10 13:06:37 -07001086 strip-static: strip-static_c strip-static_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001087
Craig Tiller841c8802015-09-10 13:06:37 -07001088 strip-shared: strip-shared_c strip-shared_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001089
Nicolas Noble047b7272015-01-16 13:55:05 -08001090
Craig Tiller841c8802015-09-10 13:06:37 -07001091 # TODO(nnoble): the strip target is stripping in-place, instead
1092 # of copying files in a temporary folder.
1093 # This prevents proper debugging after running make install.
Nicolas Noble047b7272015-01-16 13:55:05 -08001094
Craig Tiller841c8802015-09-10 13:06:37 -07001095 strip-static_c: static_c
1096 ifeq ($(CONFIG),opt)
1097 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001098 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001099 % if lib.language == "c":
1100 % if lib.build == "all":
1101 % if not lib.get('external_deps', None):
1102 $(E) "[STRIP] Stripping lib${lib.name}.a"
1103 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1104 % endif
1105 % endif
1106 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001107 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001108 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001109 endif
nnoble85a49262014-12-08 18:14:03 -08001110
Craig Tiller841c8802015-09-10 13:06:37 -07001111 strip-static_cxx: static_cxx
1112 ifeq ($(CONFIG),opt)
1113 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001114 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001115 % if lib.language == "c++":
1116 % if lib.build == "all":
1117 $(E) "[STRIP] Stripping lib${lib.name}.a"
1118 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1119 % endif
1120 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001121 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001122 % endfor
1123 endif
Nicolas "Pixel" Noble4ef9b862015-08-14 19:35:24 +02001124
Craig Tiller841c8802015-09-10 13:06:37 -07001125 strip-shared_c: shared_c
1126 ifeq ($(CONFIG),opt)
1127 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001128 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001129 % if lib.language == "c":
1130 % if lib.build == "all":
1131 % if not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -07001132 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)"
1133 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)
Craig Tiller841c8802015-09-10 13:06:37 -07001134 % endif
1135 % endif
1136 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001137 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001138 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001139 endif
nnoble85a49262014-12-08 18:14:03 -08001140
Craig Tiller841c8802015-09-10 13:06:37 -07001141 strip-shared_cxx: shared_cxx
1142 ifeq ($(CONFIG),opt)
1143 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001144 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001145 % if lib.language == "c++":
1146 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001147 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)"
1148 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)
Craig Tiller841c8802015-09-10 13:06:37 -07001149 % endif
1150 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001151 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001152 % endfor
1153 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001154
Craig Tiller841c8802015-09-10 13:06:37 -07001155 strip-shared_csharp: shared_csharp
1156 ifeq ($(CONFIG),opt)
1157 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001158 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001159 % if lib.language == "csharp":
1160 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001161 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)"
1162 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)
Craig Tiller841c8802015-09-10 13:06:37 -07001163 % endif
1164 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001165 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001166 % endfor
1167 endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001168
Craig Tiller841c8802015-09-10 13:06:37 -07001169 cache.mk::
1170 $(E) "[MAKE] Generating $@"
1171 $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@
murgatroid99aa521572015-07-10 14:49:12 -07001172
Craig Tiller841c8802015-09-10 13:06:37 -07001173 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc:
1174 $(E) "[MAKE] Generating $@"
1175 $(Q) mkdir -p $(@D)
1176 $(Q) echo "$(GRPC_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001177
Craig Tiller841c8802015-09-10 13:06:37 -07001178 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc:
1179 $(E) "[MAKE] Generating $@"
1180 $(Q) mkdir -p $(@D)
1181 $(Q) echo "$(GRPC_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001182
Craig Tiller841c8802015-09-10 13:06:37 -07001183 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc:
1184 $(E) "[MAKE] Generating $@"
1185 $(Q) mkdir -p $(@D)
1186 $(Q) echo "$(GRPCXX_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001187
Craig Tiller841c8802015-09-10 13:06:37 -07001188 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc:
1189 $(E) "[MAKE] Generating $@"
1190 $(Q) mkdir -p $(@D)
1191 $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001192
Craig Tiller841c8802015-09-10 13:06:37 -07001193 % for p in protos:
1194 ifeq ($(NO_PROTOC),true)
1195 $(GENDIR)/${p}.pb.cc: protoc_dep_error
1196 $(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error
1197 else
Craig Tiller1b4e3302015-12-17 16:35:00 -08001198 $(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 -07001199 $(E) "[PROTOC] Generating protobuf CC file from $<"
1200 $(Q) mkdir -p `dirname $@`
David Garcia Quintase68ed6f2016-06-17 12:49:14 -07001201 $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --cpp_out=$(GENDIR) $<
Nicolas "Pixel" Noble0caebbf2015-04-09 23:08:51 +02001202
Craig Tiller1b4e3302015-12-17 16:35:00 -08001203 $(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 -07001204 $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
1205 $(Q) mkdir -p `dirname $@`
Mario Emmenlauer121d2892016-12-12 23:49:27 +01001206 $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $<
Craig Tiller841c8802015-09-10 13:06:37 -07001207 endif
nnoble72309c62014-12-12 11:42:26 -08001208
Craig Tiller841c8802015-09-10 13:06:37 -07001209 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001210
Craig Tiller841c8802015-09-10 13:06:37 -07001211 ifeq ($(CONFIG),stapprof)
1212 src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h
1213 ifeq ($(HAS_SYSTEMTAP),true)
1214 $(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d
1215 $(E) "[DTRACE] Compiling $<"
1216 $(Q) mkdir -p `dirname $@`
1217 $(Q) $(DTRACE) -C -h -s $< -o $@
1218 else
1219 $(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop
1220 endif
1221 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -07001222
Craig Tiller841c8802015-09-10 13:06:37 -07001223 $(OBJDIR)/$(CONFIG)/%.o : %.c
1224 $(E) "[C] Compiling $<"
1225 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001226 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001227
Craig Tiller841c8802015-09-10 13:06:37 -07001228 $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
1229 $(E) "[CXX] Compiling $<"
1230 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001231 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001232
Craig Tiller841c8802015-09-10 13:06:37 -07001233 $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
1234 $(E) "[HOSTCXX] Compiling $<"
1235 $(Q) mkdir -p `dirname $@`
1236 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -08001237
Craig Tiller841c8802015-09-10 13:06:37 -07001238 $(OBJDIR)/$(CONFIG)/%.o : %.cc
1239 $(E) "[CXX] Compiling $<"
1240 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001241 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001242
murgatroid99a3c55352016-08-10 13:41:31 -07001243 install: install_c install_cxx install-plugins install-certs
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001244
Craig Tiller841c8802015-09-10 13:06:37 -07001245 install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001246
Craig Tiller841c8802015-09-10 13:06:37 -07001247 install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
nnoble85a49262014-12-08 18:14:03 -08001248
Craig Tiller841c8802015-09-10 13:06:37 -07001249 install_csharp: install-shared_csharp install_c
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001250
Craig Tiller841c8802015-09-10 13:06:37 -07001251 install_grpc_csharp_ext: install_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001252
Craig Tiller841c8802015-09-10 13:06:37 -07001253 install-headers: install-headers_c install-headers_cxx
nnoble85a49262014-12-08 18:14:03 -08001254
Craig Tiller841c8802015-09-10 13:06:37 -07001255 install-headers_c:
1256 $(E) "[INSTALL] Installing public C headers"
1257 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1258 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001259
Craig Tiller841c8802015-09-10 13:06:37 -07001260 install-headers_cxx:
1261 $(E) "[INSTALL] Installing public C++ headers"
1262 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1263 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001264
Craig Tiller841c8802015-09-10 13:06:37 -07001265 install-static: install-static_c install-static_cxx
nnoble85a49262014-12-08 18:14:03 -08001266
Craig Tiller841c8802015-09-10 13:06:37 -07001267 install-static_c: static_c strip-static_c install-pkg-config_c
1268 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001269 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001270 % if lib.language == "c":
1271 % if lib.build == "all":
1272 % if not lib.get('external_deps', None):
1273 $(E) "[INSTALL] Installing lib${lib.name}.a"
1274 $(Q) $(INSTALL) -d $(prefix)/lib
1275 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1276 % endif
1277 % endif
1278 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001279 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001280 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001281
Craig Tiller841c8802015-09-10 13:06:37 -07001282 install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx
1283 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001284 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001285 % if lib.language == "c++":
1286 % if lib.build == "all":
1287 $(E) "[INSTALL] Installing lib${lib.name}.a"
1288 $(Q) $(INSTALL) -d $(prefix)/lib
1289 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1290 % endif
1291 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001292 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001293 % endfor
nnoble85a49262014-12-08 18:14:03 -08001294
Craig Tiller841c8802015-09-10 13:06:37 -07001295 <%def name="install_shared(lang_filter)">\
1296 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001297 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001298 % if lib.language == lang_filter:
1299 % if lib.build == "all":
1300 % if not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -07001301 $(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 +01001302 $(Q) $(INSTALL) -d $(prefix)/lib
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001303 $(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 -07001304 ifeq ($(SYSTEM),MINGW32)
Mario Emmenlauer44b2d082017-01-13 12:35:49 +01001305 $(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 +01001306 else ifneq ($(SYSTEM),Darwin)
Craig Tiller27f70842016-09-15 16:21:54 -07001307 $(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}
1308 $(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 -07001309 endif
1310 % endif
1311 % endif
1312 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001313 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001314 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001315 ifneq ($(SYSTEM),MINGW32)
1316 ifneq ($(SYSTEM),Darwin)
1317 $(Q) ldconfig || true
1318 endif
1319 endif
1320 </%def>
nnoble85a49262014-12-08 18:14:03 -08001321
Craig Tiller841c8802015-09-10 13:06:37 -07001322 install-shared_c: shared_c strip-shared_c install-pkg-config_c
1323 ${install_shared("c")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001324
Craig Tiller841c8802015-09-10 13:06:37 -07001325 install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c install-pkg-config_cxx
1326 ${install_shared("c++")}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001327
Craig Tiller841c8802015-09-10 13:06:37 -07001328 install-shared_csharp: shared_csharp strip-shared_csharp
1329 ${install_shared("csharp")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001330
Craig Tiller841c8802015-09-10 13:06:37 -07001331 install-plugins: $(PROTOC_PLUGINS)
Craig Tiller841c8802015-09-10 13:06:37 -07001332 $(E) "[INSTALL] Installing grpc protoc plugins"
1333 % for tgt in targets:
1334 % if tgt.build == 'protoc':
1335 $(Q) $(INSTALL) -d $(prefix)/bin
1336 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
1337 % endif
1338 % endfor
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001339
Craig Tillereda85c62016-07-01 12:45:19 -07001340 install-pkg-config_c: pc_c pc_c_unsecure
Craig Tiller841c8802015-09-10 13:06:37 -07001341 $(E) "[INSTALL] Installing C pkg-config files"
1342 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
Craig Tiller841c8802015-09-10 13:06:37 -07001343 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(prefix)/lib/pkgconfig/grpc.pc
1344 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(prefix)/lib/pkgconfig/grpc_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -07001345
Craig Tiller841c8802015-09-10 13:06:37 -07001346 install-pkg-config_cxx: pc_cxx pc_cxx_unsecure
1347 $(E) "[INSTALL] Installing C++ pkg-config files"
1348 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
1349 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc $(prefix)/lib/pkgconfig/grpc++.pc
1350 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc $(prefix)/lib/pkgconfig/grpc++_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -07001351
Craig Tiller841c8802015-09-10 13:06:37 -07001352 install-certs: etc/roots.pem
1353 $(E) "[INSTALL] Installing root certificates"
1354 $(Q) $(INSTALL) -d $(prefix)/share/grpc
1355 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +01001356
Craig Tiller841c8802015-09-10 13:06:37 -07001357 clean:
1358 $(E) "[CLEAN] Cleaning build directories."
1359 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001360
1361
Craig Tiller841c8802015-09-10 13:06:37 -07001362 # The various libraries
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001363
Craig Tiller841c8802015-09-10 13:06:37 -07001364 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001365 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001366 ${makelib(lib)}
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001367 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001368 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001369
1370
Craig Tiller841c8802015-09-10 13:06:37 -07001371 # All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001372
Craig Tiller841c8802015-09-10 13:06:37 -07001373 % for tgt in targets:
1374 ${maketarget(tgt)}
1375 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001376
Craig Tiller841c8802015-09-10 13:06:37 -07001377 <%def name="makelib(lib)">
1378 LIB${lib.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001379
Craig Tiller841c8802015-09-10 13:06:37 -07001380 % for src in lib.src:
1381 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001382
Craig Tiller841c8802015-09-10 13:06:37 -07001383 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001384
Craig Tiller841c8802015-09-10 13:06:37 -07001385 % if "public_headers" in lib:
1386 % if lib.language == "c++":
1387 PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001388
Craig Tiller841c8802015-09-10 13:06:37 -07001389 % else:
1390 PUBLIC_HEADERS_C += \\
nnoble85a49262014-12-08 18:14:03 -08001391
Craig Tiller841c8802015-09-10 13:06:37 -07001392 % endif
1393 % for hdr in lib.public_headers:
1394 ${hdr} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001395
Craig Tiller841c8802015-09-10 13:06:37 -07001396 % endfor
1397 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001398
Craig Tiller841c8802015-09-10 13:06:37 -07001399 LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001400
Nicolas "Pixel" Noble51b1aee2016-01-28 01:14:58 +01001401 % if lib.get('defaults', None):
1402 % for name, value in defaults.get(lib.defaults).iteritems():
1403 $(LIB${lib.name.upper()}_OBJS): ${name} += ${value}
1404 % endfor
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001405 % endif
1406
Craig Tiller841c8802015-09-10 13:06:37 -07001407 ## If the library requires OpenSSL, let's add some restrictions.
1408 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1409 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001410
Craig Tiller841c8802015-09-10 13:06:37 -07001411 # You can't build secure libraries if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001412
Craig Tiller841c8802015-09-10 13:06:37 -07001413 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001414
Craig Tiller841c8802015-09-10 13:06:37 -07001415 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001416 $(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 -07001417 % endif
nnoble5b7f32a2014-12-22 08:12:44 -08001418
Craig Tiller841c8802015-09-10 13:06:37 -07001419 else
nnoble69ac39f2014-12-12 15:43:38 -08001420
Craig Tiller841c8802015-09-10 13:06:37 -07001421 % if lib.language == 'c++':
1422 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001423
Craig Tiller841c8802015-09-10 13:06:37 -07001424 # 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 -08001425
Craig Tiller841c8802015-09-10 13:06:37 -07001426 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001427
Craig Tiller841c8802015-09-10 13:06:37 -07001428 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001429 $(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 -07001430 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001431
Craig Tiller841c8802015-09-10 13:06:37 -07001432 else
1433 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001434
Craig Tiller841c8802015-09-10 13:06:37 -07001435 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
1436 ## The else here corresponds to the if secure earlier.
1437 % else:
1438 % if lib.language == 'c++':
1439 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001440
Craig Tiller841c8802015-09-10 13:06:37 -07001441 # 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 -08001442
Craig Tiller841c8802015-09-10 13:06:37 -07001443 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001444
Craig Tiller841c8802015-09-10 13:06:37 -07001445 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001446 $(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 -07001447 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001448
Craig Tiller841c8802015-09-10 13:06:37 -07001449 else
Nicolas Noble53830622015-02-12 16:56:38 -08001450
Craig Tiller841c8802015-09-10 13:06:37 -07001451 % endif
Nicolas "Pixel" Nobled649c212016-01-27 20:27:30 +01001452 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: \
1453 % if lib.name != 'z':
1454 $(ZLIB_DEP) \
1455 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001456 % endif
1457 % if lib.language == 'c++':
1458 $(PROTOBUF_DEP)\
1459 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001460 $(LIB${lib.name.upper()}_OBJS) \
1461 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001462 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001463 $(ZLIB_MERGE_OBJS) \
1464 % if lib.get('secure', 'check') == True:
1465 $(OPENSSL_MERGE_OBJS) \
1466 % endif
1467 % endif
1468
Craig Tiller841c8802015-09-10 13:06:37 -07001469 $(E) "[AR] Creating $@"
1470 $(Q) mkdir -p `dirname $@`
1471 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Vijay Paicc7eb8e2016-07-19 19:03:55 -07001472 $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001473 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001474 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001475 $(ZLIB_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001476 % if lib.get('secure', 'check') == True:
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001477 $(OPENSSL_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001478 % endif
1479 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001480
Craig Tiller841c8802015-09-10 13:06:37 -07001481 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001482 $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tiller841c8802015-09-10 13:06:37 -07001483 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001484
Craig Tiller841c8802015-09-10 13:06:37 -07001485 <%
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001486
Craig Tiller841c8802015-09-10 13:06:37 -07001487 if lib.language == 'c++':
1488 ld = '$(LDXX)'
1489 else:
1490 ld = '$(LD)'
nnoble5b7f32a2014-12-22 08:12:44 -08001491
Craig Tiller40c8fba2016-09-15 16:29:09 -07001492 out_mingbase = '$(LIBDIR)/$(CONFIG)/' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
1493 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
nnoble5b7f32a2014-12-22 08:12:44 -08001494
Nicolas "Pixel" Noble8087d702017-02-01 02:23:50 +01001495 common = '$(LIB' + lib.name.upper() + '_OBJS)'
nnoble5b7f32a2014-12-22 08:12:44 -08001496
Craig Tillerd7b1bdf2016-11-04 16:20:13 -07001497 link_libs = ''
Craig Tiller841c8802015-09-10 13:06:37 -07001498 lib_deps = ' $(ZLIB_DEP)'
1499 mingw_libs = ''
1500 mingw_lib_deps = ' $(ZLIB_DEP)'
1501 if lib.language == 'c++':
1502 lib_deps += ' $(PROTOBUF_DEP)'
1503 mingw_lib_deps += ' $(PROTOBUF_DEP)'
Jan Tattermusch324140c2016-01-12 08:54:01 -08001504 if lib.get('deps_linkage', None) == 'static':
1505 for dep in lib.get('deps', []):
1506 lib_archive = '$(LIBDIR)/$(CONFIG)/lib' + dep + '.a'
1507 common = common + ' ' + lib_archive
1508 lib_deps = lib_deps + ' ' + lib_archive
1509 mingw_lib_deps = mingw_lib_deps + ' ' + lib_archive
1510 else:
1511 for dep in lib.get('deps', []):
Craig Tillerd7b1bdf2016-11-04 16:20:13 -07001512 dep_lib = None
1513 for dl in libs:
1514 if dl.name == dep:
1515 dep_lib = dl
1516 assert dep_lib, 'lib %s not found (in %s)' % (dep, lib.name)
1517 link_libs = link_libs + ' -l' + dep
1518 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT_' + lang_to_var[dep_lib.language] + ')'
Mario Emmenlauer44b2d082017-01-13 12:35:49 +01001519 mingw_libs = mingw_libs + ' -l' + dep + '$(SHARED_VERSION_' + lang_to_var[dep_lib.language] + ')-dll'
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001520 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 -08001521
Craig Tiller841c8802015-09-10 13:06:37 -07001522 security = lib.get('secure', 'check')
1523 if security == True:
1524 common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)'
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001525 common = common + ' $(ZLIB_MERGE_LIBS)'
Nicolas "Pixel" Noblea7c162c2015-07-24 20:21:51 +02001526
Craig Tiller841c8802015-09-10 13:06:37 -07001527 if security in [True, 'check']:
1528 for src in lib.src:
1529 if not proto_re.match(src):
1530 sources_that_need_openssl.add(src)
1531 else:
1532 for src in lib.src:
1533 sources_that_don_t_need_openssl.add(src)
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001534
Craig Tiller841c8802015-09-10 13:06:37 -07001535 if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1536 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1537 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001538
Craig Tiller841c8802015-09-10 13:06:37 -07001539 if lib.language == 'c++':
1540 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
Craig Tiller4bef7ce2016-02-02 08:38:43 -08001541
1542 ldflags = '$(LDFLAGS)'
1543 if lib.get('LDFLAGS', None):
1544 ldflags += ' ' + lib['LDFLAGS']
Nicolas "Pixel" Noble8087d702017-02-01 02:23:50 +01001545
1546 common = common + ' $(LDLIBS)'
Craig Tiller841c8802015-09-10 13:06:37 -07001547 %>
nnoble5b7f32a2014-12-22 08:12:44 -08001548
Craig Tiller841c8802015-09-10 13:06:37 -07001549 % if lib.build == "all":
1550 ifeq ($(SYSTEM),MINGW32)
Craig Tiller38b99e92016-09-15 16:18:09 -07001551 ${out_mingbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Craig Tiller841c8802015-09-10 13:06:37 -07001552 $(E) "[LD] Linking $@"
1553 $(Q) mkdir -p `dirname $@`
Mario Emmenlauer294dc2f2016-12-13 00:07:12 +01001554 $(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 -07001555 else
Craig Tiller38b99e92016-09-15 16:18:09 -07001556 ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
Craig Tiller841c8802015-09-10 13:06:37 -07001557 $(E) "[LD] Linking $@"
1558 $(Q) mkdir -p `dirname $@`
1559 ifeq ($(SYSTEM),Darwin)
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001560 $(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 -07001561 else
Craig Tillerd7b1bdf2016-11-04 16:20:13 -07001562 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.core_version.major} -o ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${link_libs}
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001563 $(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}
1564 $(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 -07001565 endif
1566 endif
1567 % endif
1568 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1569 ## If the lib was secure, we have to close the Makefile's if that tested
1570 ## the presence of OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001571
Craig Tiller841c8802015-09-10 13:06:37 -07001572 endif
1573 % endif
1574 % if lib.language == 'c++':
1575 ## If the lib was C++, we have to close the Makefile's if that tested
1576 ## the presence of protobuf 3.0.0+
nnoble69ac39f2014-12-12 15:43:38 -08001577
Craig Tiller841c8802015-09-10 13:06:37 -07001578 endif
1579 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001580
Craig Tiller841c8802015-09-10 13:06:37 -07001581 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1582 ifneq ($(NO_SECURE),true)
1583 % endif
1584 ifneq ($(NO_DEPS),true)
1585 -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
1586 endif
1587 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1588 endif
1589 % endif
1590 % for src in lib.src:
1591 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src):
1592 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))}
1593 % endif
1594 % endfor
1595 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001596
Craig Tiller841c8802015-09-10 13:06:37 -07001597 <%def name="maketarget(tgt)"><% has_no_sources = not tgt.src %>
1598 % if not has_no_sources:
1599 ${tgt.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001600
Craig Tiller841c8802015-09-10 13:06:37 -07001601 % for src in tgt.src:
1602 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001603
Craig Tiller841c8802015-09-10 13:06:37 -07001604 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001605
Craig Tiller841c8802015-09-10 13:06:37 -07001606 ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
1607 % endif
1608 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1609 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001610
Craig Tiller841c8802015-09-10 13:06:37 -07001611 # You can't build secure targets if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001612
Craig Tiller841c8802015-09-10 13:06:37 -07001613 $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001614
Craig Tiller841c8802015-09-10 13:06:37 -07001615 else
nnoble69ac39f2014-12-12 15:43:38 -08001616
Craig Tiller841c8802015-09-10 13:06:37 -07001617 % endif
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001618
1619 % if tgt.boringssl:
1620 # boringssl needs an override to ensure that it does not include
1621 # system openssl headers regardless of other configuration
1622 # we do so here with a target specific variable assignment
Craig Tiller78222f72016-05-10 09:55:38 -07001623 $(${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 -08001624 $(${tgt.name.upper()}_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS)
1625 $(${tgt.name.upper()}_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE
1626 % else:
1627 % endif
1628
Craig Tiller841c8802015-09-10 13:06:37 -07001629 ##
1630 ## We're not trying to add a dependency on building zlib and openssl here,
1631 ## as it's already done in the libraries. We're assuming that the build
1632 ## trickles down, and that a secure target requires a secure version of
1633 ## a library.
1634 ##
1635 ## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1636 ## I can live with that.
1637 ##
1638 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001639
Craig Tiller841c8802015-09-10 13:06:37 -07001640 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001641
Craig Tiller841c8802015-09-10 13:06:37 -07001642 # 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 -08001643
Craig Tiller841c8802015-09-10 13:06:37 -07001644 $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001645
Craig Tiller841c8802015-09-10 13:06:37 -07001646 else
Nicolas Noble53830622015-02-12 16:56:38 -08001647
Craig Tiller841c8802015-09-10 13:06:37 -07001648 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1649 % if not has_no_sources:
1650 $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
1651 % endif
1652 % else:
1653 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1654 % if not has_no_sources:
1655 $(${tgt.name.upper()}_OBJS)\
1656 % endif
1657 % endif
1658 % for dep in tgt.deps:
1659 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1660 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001661
Craig Tiller32173c52016-03-17 14:12:45 -07001662 % if tgt.language == "c++" or tgt.boringssl or tgt.build == 'fuzzer':
Craig Tiller841c8802015-09-10 13:06:37 -07001663 ## C++ targets specificies.
1664 % if tgt.build == 'protoc':
1665 $(E) "[HOSTLD] Linking $@"
1666 $(Q) mkdir -p `dirname $@`
1667 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) \
1668 % if not has_no_sources:
1669 $(${tgt.name.upper()}_OBJS)\
1670 % endif
1671 % else:
1672 $(E) "[LD] Linking $@"
1673 $(Q) mkdir -p `dirname $@`
1674 $(Q) $(LDXX) $(LDFLAGS) \
1675 % if not has_no_sources:
1676 $(${tgt.name.upper()}_OBJS)\
1677 % endif
1678 % endif
1679 % else:
1680 ## C-only targets specificities.
1681 $(E) "[LD] Linking $@"
1682 $(Q) mkdir -p `dirname $@`
1683 $(Q) $(LD) $(LDFLAGS) \
1684 % if not has_no_sources:
1685 $(${tgt.name.upper()}_OBJS)\
1686 % endif
1687 % endif
1688 % for dep in tgt.deps:
1689 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1690 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001691 % if tgt.language == "c++":
1692 % if tgt.build == 'protoc':
1693 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
1694 % else:
1695 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
1696 % endif
1697 % endif
1698 % if tgt.build == 'protoc':
1699 $(HOST_LDLIBS)\
1700 % else:
1701 $(LDLIBS)\
1702 % endif
1703 % if tgt.build == 'protoc':
1704 $(HOST_LDLIBS_PROTOC)\
1705 % elif tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1706 $(LDLIBS_SECURE)\
1707 % endif
1708 % if tgt.language == 'c++' and tgt.build == 'test':
1709 $(GTEST_LIB)\
1710 % elif tgt.language == 'c++' and tgt.build == 'benchmark':
1711 $(GTEST_LIB)\
1712 % endif
Craig Tiller32173c52016-03-17 14:12:45 -07001713 % if tgt.build == 'fuzzer':
1714 -lFuzzer\
1715 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001716 -o $(BINDIR)/$(CONFIG)/${tgt.name}
1717 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001718
Craig Tiller841c8802015-09-10 13:06:37 -07001719 endif
1720 % endif
1721 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001722
Craig Tiller841c8802015-09-10 13:06:37 -07001723 endif
1724 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001725
Craig Tiller841c8802015-09-10 13:06:37 -07001726 % for src in tgt.src:
1727 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
1728 % for dep in tgt.deps:
1729 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1730 % endfor
Craig Tillerf5371ef2015-01-12 16:40:18 -08001731
Craig Tillerab230452016-01-04 08:18:43 -08001732 % if tgt.language == 'c89':
1733 % for src in tgt.src:
Craig Tillerea21ca22016-01-04 12:34:29 -08001734 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o : ${src}
1735 $(E) "[C] Compiling $<"
1736 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001737 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -std=c89 -pedantic -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Craig Tillerab230452016-01-04 08:18:43 -08001738 % endfor
1739 % endif
1740
Craig Tiller841c8802015-09-10 13:06:37 -07001741 % endfor
1742 % if not has_no_sources:
1743 deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
1744 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001745
Craig Tiller841c8802015-09-10 13:06:37 -07001746 % if not has_no_sources:
1747 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1748 ifneq ($(NO_SECURE),true)
1749 % endif
1750 ifneq ($(NO_DEPS),true)
1751 -include $(${tgt.name.upper()}_OBJS:.o=.dep)
1752 endif
1753 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1754 endif
1755 % endif
1756 % endif
Nicolas "Pixel" Noble472bb682015-11-03 19:09:01 +01001757 % for src in tgt.src:
1758 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in tgt.src):
1759 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in tgt.src if proto_re.match(src2))}
1760 % endif
1761 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001762 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001763
Craig Tiller841c8802015-09-10 13:06:37 -07001764 ifneq ($(OPENSSL_DEP),)
1765 # This is to ensure the embedded OpenSSL is built beforehand, properly
1766 # installing headers to their final destination on the drive. We need this
1767 # otherwise parallel compilation will fail if a source is compiled first.
1768 % for src in sorted(sources_that_need_openssl):
1769 % if src not in sources_that_don_t_need_openssl:
1770 ${src}: $(OPENSSL_DEP)
1771 % endif
1772 % endfor
1773 endif
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001774
Craig Tiller841c8802015-09-10 13:06:37 -07001775 .PHONY: all strip tools \
1776 dep_error openssl_dep_error openssl_dep_message git_update stop \
1777 buildtests buildtests_c buildtests_cxx \
1778 test test_c test_cxx \
1779 install install_c install_cxx \
1780 install-headers install-headers_c install-headers_cxx \
1781 install-shared install-shared_c install-shared_cxx \
1782 install-static install-static_c install-static_cxx \
1783 strip strip-shared strip-static \
1784 strip_c strip-shared_c strip-static_c \
1785 strip_cxx strip-shared_cxx strip-static_cxx \
1786 dep_c dep_cxx bins_dep_c bins_dep_cxx \
1787 clean
Craig Tillerb79c1e12016-02-23 10:00:58 -08001788
1789 .PHONY: printvars
1790 printvars:
1791 @$(foreach V,$(sort $(.VARIABLES)), \
1792 $(if $(filter-out environment% default automatic, \
1793 $(origin $V)),$(warning $V=$($V) ($(value $V)))))