blob: a9dd171b8410048475abb8fe3fdd92c499710fb3 [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 Tiller78222f72016-05-10 09:55:38 -0700209 %for warning in CHECK_WARNINGS:
210 ${warning_var('CHECK_%s_WORKS_CMD', warning)} = $(CC) -std=c99 -Werror -W${warning} -o $(TMPOUT) -c test/build/${warning}.c
211 ${warning_var('HAS_WORKING_%s', warning)} = $(shell $(${warning_var('CHECK_%s_WORKS_CMD', warning)}) 2> /dev/null && echo true || echo false)
212 ifeq ($(${warning_var('HAS_WORKING_%s', warning)}),true)
213 ${warning_var('W_%s', warning)}=-W${warning}
214 ${warning_var('NO_W_%s', warning)}=-W${neg_warning(warning)}
Craig Tiller804b8552016-02-23 16:50:24 -0800215 endif
Craig Tiller78222f72016-05-10 09:55:38 -0700216 %endfor
Craig Tiller16872b82016-01-25 10:55:20 -0800217
Craig Tiller841c8802015-09-10 13:06:37 -0700218 # The HOST compiler settings are used to compile the protoc plugins.
219 # In most cases, you won't have to change anything, but if you are
220 # cross-compiling, you can override these variables from GNU make's
221 # command line: make CC=cross-gcc HOST_CC=gcc
Nicolas Noble047b7272015-01-16 13:55:05 -0800222
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100223 HOST_CC ?= $(CC)
224 HOST_CXX ?= $(CXX)
225 HOST_LD ?= $(LD)
226 HOST_LDXX ?= $(LDXX)
nnoble72309c62014-12-12 11:42:26 -0800227
Craig Tiller78222f72016-05-10 09:55:38 -0700228 CFLAGS += -std=c99 -Wsign-conversion -Wconversion ${' '.join(warning_var('$(W_%s)', warning) for warning in PREFERRED_WARNINGS)}
Craig Tiller841c8802015-09-10 13:06:37 -0700229 CXXFLAGS += -std=c++11
Nicolas "Pixel" Noble51b1aee2016-01-28 01:14:58 +0100230 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES']:
231 % if defaults.get('global', []).get(arg, None) is not None:
232 ${arg} += ${defaults.get('global').get(arg)}
233 % endif
234 % endfor
Nicolas Noblef8681182015-03-18 14:25:44 -0700235
Craig Tiller841c8802015-09-10 13:06:37 -0700236 CPPFLAGS += $(CPPFLAGS_$(CONFIG))
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800237 CFLAGS += $(CFLAGS_$(CONFIG))
238 CXXFLAGS += $(CXXFLAGS_$(CONFIG))
Craig Tiller841c8802015-09-10 13:06:37 -0700239 DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
240 LDFLAGS += $(LDFLAGS_$(CONFIG))
Nicolas "Pixel" Noble482d7612015-07-16 23:43:30 +0200241
Craig Tiller841c8802015-09-10 13:06:37 -0700242 ifneq ($(SYSTEM),MINGW32)
243 PIC_CPPFLAGS = -fPIC
244 CPPFLAGS += -fPIC
245 LDFLAGS += -fPIC
246 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800247
Craig Tiller841c8802015-09-10 13:06:37 -0700248 INCLUDES = . include $(GENDIR)
249 LDFLAGS += -Llibs/$(CONFIG)
Nicolas "Pixel" Noble3adab742015-06-02 00:33:06 +0200250
Craig Tiller841c8802015-09-10 13:06:37 -0700251 ifeq ($(SYSTEM),Darwin)
252 ifneq ($(wildcard /usr/local/ssl/include),)
253 INCLUDES += /usr/local/ssl/include
254 endif
255 ifneq ($(wildcard /opt/local/include),)
256 INCLUDES += /opt/local/include
257 endif
258 ifneq ($(wildcard /usr/local/include),)
259 INCLUDES += /usr/local/include
260 endif
261 LIBS = m z
262 ifneq ($(wildcard /usr/local/ssl/lib),)
263 LDFLAGS += -L/usr/local/ssl/lib
264 endif
265 ifneq ($(wildcard /opt/local/lib),)
266 LDFLAGS += -L/opt/local/lib
267 endif
268 ifneq ($(wildcard /usr/local/lib),)
269 LDFLAGS += -L/usr/local/lib
270 endif
271 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700272
Craig Tiller841c8802015-09-10 13:06:37 -0700273 ifeq ($(SYSTEM),Linux)
Craig Tiller1b1e2382016-02-03 07:33:56 -0800274 LIBS = dl rt m pthread
Craig Tiller841c8802015-09-10 13:06:37 -0700275 LDFLAGS += -pthread
276 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800277
Craig Tiller841c8802015-09-10 13:06:37 -0700278 ifeq ($(SYSTEM),MINGW32)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100279 LIBS = m pthread ws2_32
Craig Tiller841c8802015-09-10 13:06:37 -0700280 LDFLAGS += -pthread
281 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700282
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700283 #
284 # The steps for cross-compiling are as follows:
285 # First, clone and make install of grpc using the native compilers for the host.
286 # Also, install protoc (e.g., from a package like apt-get)
287 # Then clone a fresh grpc for the actual cross-compiled build
288 # Set the environment variable GRPC_CROSS_COMPILE to true
289 # Set CC, CXX, LD, LDXX, AR, and STRIP to the cross-compiling binaries
290 # Also set PROTOBUF_CONFIG_OPTS to indicate cross-compilation to protobuf (e.g.,
291 # PROTOBUF_CONFIG_OPTS="--host=arm-linux --with-protoc=/usr/local/bin/protoc" )
292 # Set HAS_PKG_CONFIG=false
293 # To build tests, go to third_party/gflags and follow its ccmake instructions
294 # Make sure that you enable building shared libraries and set your prefix to
295 # something useful like /usr/local/cross
296 # You will also need to set GRPC_CROSS_LDOPTS and GRPC_CROSS_AROPTS to hold
297 # additional required arguments for LD and AR (examples below)
298 # Then you can do a make from the cross-compiling fresh clone!
299 #
300 ifeq ($(GRPC_CROSS_COMPILE),true)
301 LDFLAGS += $(GRPC_CROSS_LDOPTS) # e.g. -L/usr/local/lib -L/usr/local/cross/lib
302 AROPTS = $(GRPC_CROSS_AROPTS) # e.g., rc --target=elf32-little
303 USE_BUILT_PROTOC = false
304 endif
305
Mahak Mukhifb059a22017-04-18 14:40:00 -0700306 GTEST_LIB = -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googletest third_party/googletest/googletest/src/gtest-all.cc -Ithird_party/googletest/googlemock/include -Ithird_party/googletest/googlemock third_party/googletest/googlemock/src/gmock-all.cc
Craig Tiller841c8802015-09-10 13:06:37 -0700307 GTEST_LIB += -lgflags
308 ifeq ($(V),1)
309 E = @:
310 Q =
311 else
312 E = @echo
313 Q = @
314 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800315
Craig Tiller38b99e92016-09-15 16:18:09 -0700316 CORE_VERSION = ${settings.core_version}
317 CPP_VERSION = ${settings.cpp_version}
318 CSHARP_VERSION = ${settings.csharp_version}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800319
Craig Tiller841c8802015-09-10 13:06:37 -0700320 CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
321 CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800322
Craig Tiller841c8802015-09-10 13:06:37 -0700323 LDFLAGS += $(ARCH_FLAGS)
324 LDLIBS += $(addprefix -l, $(LIBS))
325 LDLIBSXX += $(addprefix -l, $(LIBSXX))
nnoble72309c62014-12-12 11:42:26 -0800326
murgatroid99c36f6ea2016-10-03 09:24:09 -0700327
328 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES', 'LDLIBS']:
329 ${arg} += $(EXTRA_${arg})
330 % endfor
331
Craig Tiller841c8802015-09-10 13:06:37 -0700332 HOST_CPPFLAGS = $(CPPFLAGS)
333 HOST_CFLAGS = $(CFLAGS)
334 HOST_CXXFLAGS = $(CXXFLAGS)
335 HOST_LDFLAGS = $(LDFLAGS)
336 HOST_LDLIBS = $(LDLIBS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800337
Craig Tiller841c8802015-09-10 13:06:37 -0700338 # These are automatically computed variables.
339 # There shouldn't be any need to change anything from now on.
nnoble69ac39f2014-12-12 15:43:38 -0800340
Craig Tiller841c8802015-09-10 13:06:37 -0700341 -include cache.mk
murgatroid9924e2f4a2015-06-29 11:12:01 -0700342
Craig Tiller841c8802015-09-10 13:06:37 -0700343 CACHE_MK =
murgatroid99aa521572015-07-10 14:49:12 -0700344
Craig Tiller841c8802015-09-10 13:06:37 -0700345 HAS_PKG_CONFIG ?= $(shell command -v $(PKG_CONFIG) >/dev/null 2>&1 && echo true || echo false)
murgatroid99aa521572015-07-10 14:49:12 -0700346
Craig Tiller841c8802015-09-10 13:06:37 -0700347 ifeq ($(HAS_PKG_CONFIG), true)
348 CACHE_MK += HAS_PKG_CONFIG = true,
349 endif
nnoble69ac39f2014-12-12 15:43:38 -0800350
Craig Tiller38b99e92016-09-15 16:18:09 -0700351 CORE_PC_TEMPLATE = prefix=$(prefix),\
Craig Tiller841c8802015-09-10 13:06:37 -0700352 exec_prefix=${'\$${prefix}'},\
353 includedir=${'\$${prefix}'}/include,\
354 libdir=${'\$${exec_prefix}'}/lib,\
355 ,\
356 Name: $(PC_NAME),\
357 Description: $(PC_DESCRIPTION),\
Craig Tiller38b99e92016-09-15 16:18:09 -0700358 Version: $(CORE_VERSION),\
359 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
360 Requires.private: $(PC_REQUIRES_PRIVATE),\
361 Libs: -L${'\$${libdir}'} $(PC_LIB),\
362 Libs.private: $(PC_LIBS_PRIVATE)
363
364 CPP_PC_TEMPLATE = prefix=$(prefix),\
365 exec_prefix=${'\$${prefix}'},\
366 includedir=${'\$${prefix}'}/include,\
367 libdir=${'\$${exec_prefix}'}/lib,\
368 ,\
369 Name: $(PC_NAME),\
370 Description: $(PC_DESCRIPTION),\
371 Version: $(CPP_VERSION),\
372 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
373 Requires.private: $(PC_REQUIRES_PRIVATE),\
374 Libs: -L${'\$${libdir}'} $(PC_LIB),\
375 Libs.private: $(PC_LIBS_PRIVATE)
376
377 CSHARP_PC_TEMPLATE = prefix=$(prefix),\
378 exec_prefix=${'\$${prefix}'},\
379 includedir=${'\$${prefix}'}/include,\
380 libdir=${'\$${exec_prefix}'}/lib,\
381 ,\
382 Name: $(PC_NAME),\
383 Description: $(PC_DESCRIPTION),\
384 Version: $(CSHARP_VERSION),\
Craig Tiller841c8802015-09-10 13:06:37 -0700385 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
386 Requires.private: $(PC_REQUIRES_PRIVATE),\
387 Libs: -L${'\$${libdir}'} $(PC_LIB),\
388 Libs.private: $(PC_LIBS_PRIVATE)
murgatroid998faab232015-06-30 17:24:21 -0700389
Craig Tiller841c8802015-09-10 13:06:37 -0700390 ifeq ($(SYSTEM),MINGW32)
Mario Emmenlauer121d2892016-12-12 23:49:27 +0100391 EXECUTABLE_SUFFIX = .exe
Craig Tiller38b99e92016-09-15 16:18:09 -0700392 SHARED_EXT_CORE = dll
393 SHARED_EXT_CPP = dll
394 SHARED_EXT_CSHARP = dll
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100395 SHARED_PREFIX =
Craig Tiller27f70842016-09-15 16:21:54 -0700396 SHARED_VERSION_CORE = -${settings.core_version.major}
397 SHARED_VERSION_CPP = -${settings.cpp_version.major}
398 SHARED_VERSION_CSHARP = -${settings.csharp_version.major}
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100399 else ifeq ($(SYSTEM),Darwin)
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800400 EXECUTABLE_SUFFIX =
Craig Tiller38b99e92016-09-15 16:18:09 -0700401 SHARED_EXT_CORE = dylib
402 SHARED_EXT_CPP = dylib
403 SHARED_EXT_CSHARP = dylib
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100404 SHARED_PREFIX = lib
Craig Tiller27f70842016-09-15 16:21:54 -0700405 SHARED_VERSION_CORE =
406 SHARED_VERSION_CPP =
407 SHARED_VERSION_CSHARP =
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100408 else
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800409 EXECUTABLE_SUFFIX =
Craig Tiller38b99e92016-09-15 16:18:09 -0700410 SHARED_EXT_CORE = so.$(CORE_VERSION)
411 SHARED_EXT_CPP = so.$(CPP_VERSION)
412 SHARED_EXT_CSHARP = so.$(CSHARP_VERSION)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100413 SHARED_PREFIX = lib
Craig Tiller27f70842016-09-15 16:21:54 -0700414 SHARED_VERSION_CORE =
415 SHARED_VERSION_CPP =
416 SHARED_VERSION_CSHARP =
Craig Tiller841c8802015-09-10 13:06:37 -0700417 endif
nnoble5b7f32a2014-12-22 08:12:44 -0800418
Craig Tiller841c8802015-09-10 13:06:37 -0700419 ifeq ($(wildcard .git),)
420 IS_GIT_FOLDER = false
421 else
422 IS_GIT_FOLDER = true
423 endif
nnoble69ac39f2014-12-12 15:43:38 -0800424
Craig Tiller841c8802015-09-10 13:06:37 -0700425 ifeq ($(HAS_PKG_CONFIG),true)
426 OPENSSL_ALPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.2 openssl
427 OPENSSL_NPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.1 openssl
428 ZLIB_CHECK_CMD = $(PKG_CONFIG) --exists zlib
Yuchen Zengd4df55e2016-08-15 16:41:18 -0700429 PROTOBUF_CHECK_CMD = $(PKG_CONFIG) --atleast-version=3.0.0 protobuf
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700430 CARES_CHECK_CMD = $(PKG_CONFIG) --exists libcares
Craig Tiller841c8802015-09-10 13:06:37 -0700431 else # HAS_PKG_CONFIG
murgatroid9924e2f4a2015-06-29 11:12:01 -0700432
Craig Tiller841c8802015-09-10 13:06:37 -0700433 ifeq ($(SYSTEM),MINGW32)
434 OPENSSL_LIBS = ssl32 eay32
435 else
436 OPENSSL_LIBS = ssl crypto
437 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700438
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100439 OPENSSL_ALPN_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
440 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 -0800441 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 +0100442 ZLIB_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
443 PROTOBUF_CHECK_CMD = $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700444 CARES_CHECK_CMD = $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $(TMPOUT) test/build/c-ares.c -lcares $(LDFLAGS)
Craig Tiller297fafa2015-01-15 15:46:39 -0800445
Craig Tiller841c8802015-09-10 13:06:37 -0700446 endif # HAS_PKG_CONFIG
murgatroid9924e2f4a2015-06-29 11:12:01 -0700447
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100448 PERFTOOLS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
murgatroid996d9e4012015-07-08 10:22:45 -0700449
Craig Tiller841c8802015-09-10 13:06:37 -0700450 PROTOC_CHECK_CMD = which protoc > /dev/null
451 PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3
452 DTRACE_CHECK_CMD = which dtrace > /dev/null
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100453 SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS)
murgatroid9924e2f4a2015-06-29 11:12:01 -0700454
Craig Tiller841c8802015-09-10 13:06:37 -0700455 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
456 HAS_SYSTEM_PERFTOOLS ?= $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
457 ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
458 DEFINES += GRPC_HAVE_PERFTOOLS
459 LIBS += profiler
460 CACHE_MK += HAS_SYSTEM_PERFTOOLS = true,
461 endif
462 endif
nnoble69ac39f2014-12-12 15:43:38 -0800463
Craig Tiller841c8802015-09-10 13:06:37 -0700464 HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
465 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
466 HAS_SYSTEM_OPENSSL_ALPN ?= $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
467 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
468 HAS_SYSTEM_OPENSSL_NPN = true
469 CACHE_MK += HAS_SYSTEM_OPENSSL_ALPN = true,
470 else
471 HAS_SYSTEM_OPENSSL_NPN ?= $(shell $(OPENSSL_NPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
472 endif
473 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
474 CACHE_MK += HAS_SYSTEM_OPENSSL_NPN = true,
475 endif
476 HAS_SYSTEM_ZLIB ?= $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
477 ifeq ($(HAS_SYSTEM_ZLIB),true)
478 CACHE_MK += HAS_SYSTEM_ZLIB = true,
479 endif
480 HAS_SYSTEM_PROTOBUF ?= $(HAS_SYSTEM_PROTOBUF_VERIFY)
481 ifeq ($(HAS_SYSTEM_PROTOBUF),true)
482 CACHE_MK += HAS_SYSTEM_PROTOBUF = true,
483 endif
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700484 HAS_SYSTEM_CARES ?= $(shell $(CARES_CHECK_CMD) 2> /dev/null && echo true || echo false)
485 ifeq ($(HAS_SYSTEM_CARES),true)
486 CACHE_MK += HAS_SYSTEM_CARES = true,
487 endif
Craig Tiller841c8802015-09-10 13:06:37 -0700488 else
489 # override system libraries if the config requires a custom compiled library
490 HAS_SYSTEM_OPENSSL_ALPN = false
491 HAS_SYSTEM_OPENSSL_NPN = false
492 HAS_SYSTEM_ZLIB = false
493 HAS_SYSTEM_PROTOBUF = false
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700494 HAS_SYSTEM_CARES = false
Craig Tiller841c8802015-09-10 13:06:37 -0700495 endif
nnoble69ac39f2014-12-12 15:43:38 -0800496
Craig Tiller841c8802015-09-10 13:06:37 -0700497 HAS_PROTOC ?= $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
498 ifeq ($(HAS_PROTOC),true)
499 CACHE_MK += HAS_PROTOC = true,
500 HAS_VALID_PROTOC ?= $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false)
501 ifeq ($(HAS_VALID_PROTOC),true)
502 CACHE_MK += HAS_VALID_PROTOC = true,
503 endif
504 else
505 HAS_VALID_PROTOC = false
506 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800507
Craig Tiller841c8802015-09-10 13:06:37 -0700508 # Check for Systemtap (https://sourceware.org/systemtap/), first by making sure <sys/sdt.h> is present
509 # in the system and secondly by checking for the "dtrace" binary (on Linux, this is part of the Systemtap
510 # distribution. It's part of the base system on BSD/Solaris machines).
511 ifndef HAS_SYSTEMTAP
512 HAS_SYSTEMTAP_HEADERS = $(shell $(SYSTEMTAP_HEADERS_CHECK_CMD) 2> /dev/null && echo true || echo false)
513 HAS_DTRACE = $(shell $(DTRACE_CHECK_CMD) 2> /dev/null && echo true || echo false)
514 HAS_SYSTEMTAP = false
515 ifeq ($(HAS_SYSTEMTAP_HEADERS),true)
516 ifeq ($(HAS_DTRACE),true)
517 HAS_SYSTEMTAP = true
518 endif
519 endif
520 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -0700521
Craig Tiller841c8802015-09-10 13:06:37 -0700522 ifeq ($(HAS_SYSTEMTAP),true)
523 CACHE_MK += HAS_SYSTEMTAP = true,
524 endif
nnoble69ac39f2014-12-12 15:43:38 -0800525
Craig Tiller841c8802015-09-10 13:06:37 -0700526 # Note that for testing purposes, one can do:
527 # make HAS_EMBEDDED_OPENSSL_ALPN=false
528 # to emulate the fact we do not have OpenSSL in the third_party folder.
Craig Tillerb79c1e12016-02-23 10:00:58 -0800529 ifneq ($(wildcard third_party/${openssl_fallback.extraction_dir}/libssl.a),)
530 HAS_EMBEDDED_OPENSSL_ALPN = third_party/${openssl_fallback.extraction_dir}
531 else ifeq ($(wildcard third_party/boringssl/include/openssl/ssl.h),)
Craig Tiller841c8802015-09-10 13:06:37 -0700532 HAS_EMBEDDED_OPENSSL_ALPN = false
533 else
Craig Tillerb79c1e12016-02-23 10:00:58 -0800534 CAN_COMPILE_EMBEDDED_OPENSSL ?= $(shell $(BORINGSSL_COMPILE_CHECK_CMD) 2> /dev/null && echo true || echo false)
535 HAS_EMBEDDED_OPENSSL_ALPN = $(CAN_COMPILE_EMBEDDED_OPENSSL)
Craig Tiller841c8802015-09-10 13:06:37 -0700536 endif
nnoble69ac39f2014-12-12 15:43:38 -0800537
Craig Tiller841c8802015-09-10 13:06:37 -0700538 ifeq ($(wildcard third_party/zlib/zlib.h),)
539 HAS_EMBEDDED_ZLIB = false
540 else
541 HAS_EMBEDDED_ZLIB = true
542 endif
nnoble69ac39f2014-12-12 15:43:38 -0800543
Craig Tiller841c8802015-09-10 13:06:37 -0700544 ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
545 HAS_EMBEDDED_PROTOBUF = false
546 ifneq ($(HAS_VALID_PROTOC),true)
547 NO_PROTOC = true
548 endif
549 else
550 HAS_EMBEDDED_PROTOBUF = true
551 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800552
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800553 ifeq ($(wildcard third_party/cares/cares/ares.h),)
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700554 HAS_EMBEDDED_CARES = false
555 else
556 HAS_EMBEDDED_CARES = true
557 endif
558
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100559 PC_REQUIRES_GRPC =
Craig Tiller841c8802015-09-10 13:06:37 -0700560 PC_LIBS_GRPC =
murgatroid998faab232015-06-30 17:24:21 -0700561
Craig Tiller841c8802015-09-10 13:06:37 -0700562 ifeq ($(HAS_SYSTEM_ZLIB),false)
Craig Tiller3dca23a2016-01-21 11:44:55 -0800563 ifeq ($(HAS_EMBEDDED_ZLIB), true)
564 EMBED_ZLIB ?= true
Craig Tiller841c8802015-09-10 13:06:37 -0700565 else
566 DEP_MISSING += zlib
Craig Tiller3dca23a2016-01-21 11:44:55 -0800567 EMBED_ZLIB ?= broken
Craig Tiller841c8802015-09-10 13:06:37 -0700568 endif
569 else
Craig Tiller3dca23a2016-01-21 11:44:55 -0800570 EMBED_ZLIB ?= false
571 endif
572
573 ifeq ($(EMBED_ZLIB),true)
574 ZLIB_DEP = $(LIBDIR)/$(CONFIG)/libz.a
575 ZLIB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libz.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +0100576 ZLIB_MERGE_OBJS = $(LIBZ_OBJS)
Craig Tiller3dca23a2016-01-21 11:44:55 -0800577 CPPFLAGS += -Ithird_party/zlib
578 LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib
579 else
Craig Tiller841c8802015-09-10 13:06:37 -0700580 ifeq ($(HAS_PKG_CONFIG),true)
581 CPPFLAGS += $(shell $(PKG_CONFIG) --cflags zlib)
582 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L zlib)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800583 LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l zlib))
Craig Tiller841c8802015-09-10 13:06:37 -0700584 PC_REQUIRES_GRPC += zlib
585 else
586 PC_LIBS_GRPC += -lz
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800587 LIBS += z
Craig Tiller841c8802015-09-10 13:06:37 -0700588 endif
589 endif
nnoble69ac39f2014-12-12 15:43:38 -0800590
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700591 CARES_PKG_CONFIG = false
592
Yuchen Zengb1b21152016-08-12 11:27:30 -0700593 ifeq ($(HAS_SYSTEM_CARES),false)
594 ifeq ($(HAS_EMBEDDED_CARES), true)
595 EMBED_CARES ?= true
596 else
597 DEP_MISSING += cares
598 EMBED_CARES ?= broken
599 endif
600 else
601 EMBED_CARES ?= false
602 endif
603
604 ifeq ($(EMBED_CARES),true)
Yuchen Zeng15141a62016-08-17 18:56:04 -0700605 CARES_DEP = $(LIBDIR)/$(CONFIG)/libares.a
606 CARES_MERGE_OBJS = $(LIBARES_OBJS)
607 CARES_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libares.a
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800608 CPPFLAGS := -Ithird_party/cares -Ithird_party/cares/cares $(CPPFLAGS)
Yuchen Zengb1b21152016-08-12 11:27:30 -0700609 LDFLAGS := -L$(LIBDIR)/$(CONFIG)/c-ares $(LDFLAGS)
Yuchen Zengb1b21152016-08-12 11:27:30 -0700610 else
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700611 ifeq ($(HAS_PKG_CONFIG),true)
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700612 PC_REQUIRES_GRPC += libcares
613 CPPFLAGS += $(shell $(PKG_CONFIG) --cflags libcares)
Yuchen Zengdf2a7b72016-08-18 14:57:03 -0700614 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libcares)
615 LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l libcares))
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700616 else
617 PC_LIBS_GRPC += -lcares
Yuchen Zengdf2a7b72016-08-18 14:57:03 -0700618 LIBS += cares
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700619 endif
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700620 endif
621
Craig Tiller841c8802015-09-10 13:06:37 -0700622 OPENSSL_PKG_CONFIG = false
murgatroid99da7a9942015-06-29 14:57:37 -0700623
Craig Tiller841c8802015-09-10 13:06:37 -0700624 PC_REQUIRES_SECURE =
625 PC_LIBS_SECURE =
murgatroid998faab232015-06-30 17:24:21 -0700626
Craig Tiller841c8802015-09-10 13:06:37 -0700627 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800628 EMBED_OPENSSL ?= false
629 NO_SECURE ?= false
630 else # HAS_SYSTEM_OPENSSL_ALPN=false
Craig Tillerb79c1e12016-02-23 10:00:58 -0800631 ifneq ($(HAS_EMBEDDED_OPENSSL_ALPN),false)
632 EMBED_OPENSSL ?= $(HAS_EMBEDDED_OPENSSL_ALPN)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800633 NO_SECURE ?= false
634 else # HAS_EMBEDDED_OPENSSL_ALPN=false
635 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
636 EMBED_OPENSSL ?= false
637 NO_SECURE ?= false
638 else
639 NO_SECURE ?= true
640 endif # HAS_SYSTEM_OPENSSL_NPN=true
641 endif # HAS_EMBEDDED_OPENSSL_ALPN
642 endif # HAS_SYSTEM_OPENSSL_ALPN
643
644 OPENSSL_DEP :=
645 OPENSSL_MERGE_LIBS :=
646 ifeq ($(NO_SECURE),false)
647 ifeq ($(EMBED_OPENSSL),true)
648 OPENSSL_DEP += $(LIBDIR)/$(CONFIG)/libboringssl.a
649 OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/libboringssl.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +0100650 OPENSSL_MERGE_OBJS += $(LIBBORINGSSL_OBJS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800651 # need to prefix these to ensure overriding system libraries
652 CPPFLAGS := -Ithird_party/boringssl/include $(CPPFLAGS)
Craig Tillerb79c1e12016-02-23 10:00:58 -0800653 else ifneq ($(EMBED_OPENSSL),false)
654 OPENSSL_DEP += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
655 OPENSSL_MERGE_LIBS += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
656 OPENSSL_MERGE_OBJS += $(wildcard $(EMBED_OPENSSL)/grpc_obj/*.o)
657 # need to prefix these to ensure overriding system libraries
658 CPPFLAGS := -I$(EMBED_OPENSSL)/include $(CPPFLAGS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800659 else # EMBED_OPENSSL=false
Craig Tiller841c8802015-09-10 13:06:37 -0700660 ifeq ($(HAS_PKG_CONFIG),true)
661 OPENSSL_PKG_CONFIG = true
662 PC_REQUIRES_SECURE = openssl
663 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags openssl) $(CPPFLAGS)
664 LDFLAGS_OPENSSL_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L openssl)
665 ifeq ($(SYSTEM),Linux)
666 ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),)
667 LDFLAGS_OPENSSL_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L openssl | sed s/L/Wl,-rpath,/)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800668 endif # LDFLAGS_OPENSSL_PKG_CONFIG=''
669 endif # System=Linux
Craig Tiller841c8802015-09-10 13:06:37 -0700670 LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800671 else # HAS_PKG_CONFIG=false
Craig Tiller841c8802015-09-10 13:06:37 -0700672 LIBS_SECURE = $(OPENSSL_LIBS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800673 endif # HAS_PKG_CONFIG
674 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
675 CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0
676 LIBS_SECURE = $(OPENSSL_LIBS)
677 endif # HAS_SYSTEM_OPENSSL_NPN
Craig Tiller841c8802015-09-10 13:06:37 -0700678 PC_LIBS_SECURE = $(addprefix -l, $(LIBS_SECURE))
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800679 endif # EMBED_OPENSSL
680 endif # NO_SECURE
nnoble69ac39f2014-12-12 15:43:38 -0800681
Craig Tiller841c8802015-09-10 13:06:37 -0700682 ifeq ($(OPENSSL_PKG_CONFIG),true)
683 LDLIBS_SECURE += $(shell $(PKG_CONFIG) --libs-only-l openssl)
684 else
685 LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
686 endif
nnoble5b7f32a2014-12-22 08:12:44 -0800687
Craig Tiller841c8802015-09-10 13:06:37 -0700688 # grpc .pc file
689 PC_NAME = gRPC
Craig Tillerda179ce2016-02-09 12:01:53 -0800690 PC_DESCRIPTION = high performance general RPC framework
691 PC_CFLAGS =
692 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC) $(PC_REQUIRES_SECURE)
Craig Tiller841c8802015-09-10 13:06:37 -0700693 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) $(PC_LIBS_SECURE)
694 PC_LIB = -lgrpc
Craig Tiller38b99e92016-09-15 16:18:09 -0700695 GRPC_PC_FILE := $(CORE_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700696
Craig Tiller4a67be42016-02-09 12:40:32 -0800697 # grpc_unsecure .pc file
Craig Tiller841c8802015-09-10 13:06:37 -0700698 PC_NAME = gRPC unsecure
Craig Tillerda179ce2016-02-09 12:01:53 -0800699 PC_DESCRIPTION = high performance general RPC framework without SSL
700 PC_CFLAGS =
701 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC)
Craig Tiller841c8802015-09-10 13:06:37 -0700702 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC)
703 PC_LIB = -lgrpc
Craig Tiller38b99e92016-09-15 16:18:09 -0700704 GRPC_UNSECURE_PC_FILE := $(CORE_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700705
Craig Tiller841c8802015-09-10 13:06:37 -0700706 PROTOBUF_PKG_CONFIG = false
murgatroid99da7a9942015-06-29 14:57:37 -0700707
Craig Tiller841c8802015-09-10 13:06:37 -0700708 PC_REQUIRES_GRPCXX =
709 PC_LIBS_GRPCXX =
murgatroid998faab232015-06-30 17:24:21 -0700710
Mahak Mukhifb059a22017-04-18 14:40:00 -0700711 CPPFLAGS := -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googlemock/include $(CPPFLAGS)
Craig Tiller16f6dac2015-08-24 17:00:04 -0700712
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700713 PROTOC_PLUGINS_ALL =\
714 % for tgt in targets:
715 % if tgt.build == 'protoc':
716 $(BINDIR)/$(CONFIG)/${tgt.name}\
717 % endif
718 % endfor
719
720 PROTOC_PLUGINS_DIR = $(BINDIR)/$(CONFIG)
721
Craig Tiller841c8802015-09-10 13:06:37 -0700722 ifeq ($(HAS_SYSTEM_PROTOBUF),true)
723 ifeq ($(HAS_PKG_CONFIG),true)
724 PROTOBUF_PKG_CONFIG = true
725 PC_REQUIRES_GRPCXX = protobuf
726 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags protobuf) $(CPPFLAGS)
727 LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L protobuf)
728 ifeq ($(SYSTEM),Linux)
729 ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),)
730 LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L protobuf | sed s/L/Wl,-rpath,/)
731 endif
732 endif
733 else
734 PC_LIBS_GRPCXX = -lprotobuf
735 endif
Nicolas "Pixel" Noblef7fbdd42016-07-25 20:31:22 +0200736 PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
Craig Tiller841c8802015-09-10 13:06:37 -0700737 else
738 ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
739 PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
740 CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
741 LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700742 ifneq ($(USE_BUILT_PROTOC),false)
Craig Tiller841c8802015-09-10 13:06:37 -0700743 PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700744 PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
745 else
746 PROTOC_PLUGINS =
747 PROTOC_PLUGINS_DIR = $(prefix)/bin
748 endif
Craig Tiller841c8802015-09-10 13:06:37 -0700749 else
750 NO_PROTOBUF = true
751 endif
752 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800753
Craig Tiller841c8802015-09-10 13:06:37 -0700754 LIBS_PROTOBUF = protobuf
755 LIBS_PROTOC = protoc protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800756
Craig Tiller841c8802015-09-10 13:06:37 -0700757 HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
Nicolas Noble53830622015-02-12 16:56:38 -0800758
Craig Tiller841c8802015-09-10 13:06:37 -0700759 ifeq ($(PROTOBUF_PKG_CONFIG),true)
760 LDLIBS_PROTOBUF += $(shell $(PKG_CONFIG) --libs-only-l protobuf)
761 else
762 LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
763 endif
murgatroid9924e2f4a2015-06-29 11:12:01 -0700764
Craig Tiller841c8802015-09-10 13:06:37 -0700765 # grpc++ .pc file
766 PC_NAME = gRPC++
767 PC_DESCRIPTION = C++ wrapper for gRPC
768 PC_CFLAGS =
769 PC_REQUIRES_PRIVATE = grpc $(PC_REQUIRES_GRPCXX)
770 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
771 PC_LIB = -lgrpc++
Craig Tiller38b99e92016-09-15 16:18:09 -0700772 GRPCXX_PC_FILE := $(CPP_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700773
Craig Tiller841c8802015-09-10 13:06:37 -0700774 # grpc++_unsecure .pc file
775 PC_NAME = gRPC++ unsecure
776 PC_DESCRIPTION = C++ wrapper for gRPC without SSL
777 PC_CFLAGS =
778 PC_REQUIRES_PRIVATE = grpc_unsecure $(PC_REQUIRES_GRPCXX)
779 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
780 PC_LIB = -lgrpc++
Craig Tiller38b99e92016-09-15 16:18:09 -0700781 GRPCXX_UNSECURE_PC_FILE := $(CPP_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700782
Craig Tiller841c8802015-09-10 13:06:37 -0700783 ifeq ($(MAKECMDGOALS),clean)
784 NO_DEPS = true
785 endif
nnoble69ac39f2014-12-12 15:43:38 -0800786
Craig Tiller841c8802015-09-10 13:06:37 -0700787 .SECONDARY = %.pb.h %.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800788
Craig Tiller841c8802015-09-10 13:06:37 -0700789 ifeq ($(DEP_MISSING),)
790 all: static shared plugins\
791 % for tgt in targets:
792 % if tgt.build == 'all':
793 $(BINDIR)/$(CONFIG)/${tgt.name}\
794 % endif
795 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800796
Craig Tiller841c8802015-09-10 13:06:37 -0700797 dep_error:
798 @echo "You shouldn't see this message - all of your dependencies are correct."
799 else
800 all: dep_error git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800801
Craig Tiller841c8802015-09-10 13:06:37 -0700802 dep_error:
803 @echo
804 @echo "DEPENDENCY ERROR"
805 @echo
806 @echo "You are missing system dependencies that are essential to build grpc,"
807 @echo "and the third_party directory doesn't have them:"
808 @echo
809 @echo " $(DEP_MISSING)"
810 @echo
811 @echo "Installing the development packages for your system will solve"
812 @echo "this issue. Please consult INSTALL to get more information."
813 @echo
814 @echo "If you need information about why these tests failed, run:"
815 @echo
816 @echo " make run_dep_checks"
817 @echo
818 endif
nnoble69ac39f2014-12-12 15:43:38 -0800819
Craig Tiller841c8802015-09-10 13:06:37 -0700820 git_update:
821 ifeq ($(IS_GIT_FOLDER),true)
822 @echo "Additionally, since you are in a git clone, you can download the"
823 @echo "missing dependencies in third_party by running the following command:"
824 @echo
825 @echo " git submodule update --init"
826 @echo
827 endif
nnoble69ac39f2014-12-12 15:43:38 -0800828
Craig Tiller841c8802015-09-10 13:06:37 -0700829 openssl_dep_error: openssl_dep_message git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800830
Craig Tiller841c8802015-09-10 13:06:37 -0700831 protobuf_dep_error: protobuf_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800832
Craig Tiller841c8802015-09-10 13:06:37 -0700833 protoc_dep_error: protoc_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800834
Craig Tiller841c8802015-09-10 13:06:37 -0700835 openssl_dep_message:
836 @echo
837 @echo "DEPENDENCY ERROR"
838 @echo
Craig Tillerb79c1e12016-02-23 10:00:58 -0800839 @echo "The target you are trying to run requires an OpenSSL implementation."
840 @echo "Your system doesn't have one, and either the third_party directory"
841 @echo "doesn't have it, or your compiler can't build BoringSSL."
Craig Tiller841c8802015-09-10 13:06:37 -0700842 @echo
843 @echo "Please consult INSTALL to get more information."
844 @echo
845 @echo "If you need information about why these tests failed, run:"
846 @echo
847 @echo " make run_dep_checks"
848 @echo
nnoble69ac39f2014-12-12 15:43:38 -0800849
Craig Tiller841c8802015-09-10 13:06:37 -0700850 protobuf_dep_message:
851 @echo
852 @echo "DEPENDENCY ERROR"
853 @echo
854 @echo "The target you are trying to run requires protobuf 3.0.0+"
855 @echo "Your system doesn't have it, and neither does the third_party directory."
856 @echo
857 @echo "Please consult INSTALL to get more information."
858 @echo
859 @echo "If you need information about why these tests failed, run:"
860 @echo
861 @echo " make run_dep_checks"
862 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800863
Craig Tiller841c8802015-09-10 13:06:37 -0700864 protoc_dep_message:
865 @echo
866 @echo "DEPENDENCY ERROR"
867 @echo
868 @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
869 @echo "Your system doesn't have it, and neither does the third_party directory."
870 @echo
871 @echo "Please consult INSTALL to get more information."
872 @echo
873 @echo "If you need information about why these tests failed, run:"
874 @echo
875 @echo " make run_dep_checks"
876 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800877
Craig Tiller841c8802015-09-10 13:06:37 -0700878 systemtap_dep_error:
879 @echo
880 @echo "DEPENDENCY ERROR"
881 @echo
882 @echo "Under the '$(CONFIG)' configutation, the target you are trying "
883 @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other "
884 @echo "platforms such as Solaris and *BSD). "
885 @echo
886 @echo "Please consult INSTALL to get more information."
887 @echo
David Garcia Quintas8954e902015-04-29 09:46:33 -0700888
Craig Tiller841c8802015-09-10 13:06:37 -0700889 stop:
890 @false
nnoble69ac39f2014-12-12 15:43:38 -0800891
Craig Tiller841c8802015-09-10 13:06:37 -0700892 % for tgt in targets:
893 ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
894 % endfor
ctiller09cb6d52014-12-19 17:38:22 -0800895
Craig Tiller841c8802015-09-10 13:06:37 -0700896 run_dep_checks:
897 $(OPENSSL_ALPN_CHECK_CMD) || true
898 $(OPENSSL_NPN_CHECK_CMD) || true
899 $(ZLIB_CHECK_CMD) || true
900 $(PERFTOOLS_CHECK_CMD) || true
901 $(PROTOBUF_CHECK_CMD) || true
902 $(PROTOC_CHECK_VERSION_CMD) || true
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700903 $(CARES_CHECK_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800904
Craig Tiller841c8802015-09-10 13:06:37 -0700905 third_party/protobuf/configure:
906 $(E) "[AUTOGEN] Preparing protobuf"
907 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
Nicolas Noble53830622015-02-12 16:56:38 -0800908
Craig Tiller841c8802015-09-10 13:06:37 -0700909 $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
910 $(E) "[MAKE] Building protobuf"
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700911 $(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 -0700912 $(Q)$(MAKE) -C third_party/protobuf clean
913 $(Q)$(MAKE) -C third_party/protobuf
914 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
915 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
916 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
917 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
918 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800919
Craig Tiller841c8802015-09-10 13:06:37 -0700920 static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800921
Craig Tillereda85c62016-07-01 12:45:19 -0700922 static_c: pc_c pc_c_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700923 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100924 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700925 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
926 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
927 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100928 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700929 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800930
931
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100932 static_cxx: pc_cxx pc_cxx_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700933 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100934 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700935 % if lib.build == 'all' and lib.language == 'c++':
936 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
937 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100938 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700939 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800940
941
Craig Tiller841c8802015-09-10 13:06:37 -0700942 shared: shared_c shared_cxx
nnoble29e1d292014-12-01 10:27:40 -0800943
Craig Tillereda85c62016-07-01 12:45:19 -0700944 shared_c: pc_c pc_c_unsecure cache.mk\
Craig Tiller841c8802015-09-10 13:06:37 -0700945 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100946 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700947 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -0700948 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)\
Craig Tiller841c8802015-09-10 13:06:37 -0700949 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100950 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700951 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800952
Craig Tiller841c8802015-09-10 13:06:37 -0700953 shared_cxx: pc_cxx pc_cxx_unsecure cache.mk\
954 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100955 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700956 % if lib.build == 'all' and lib.language == 'c++':
Craig Tiller27f70842016-09-15 16:21:54 -0700957 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)\
Craig Tiller841c8802015-09-10 13:06:37 -0700958 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100959 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700960 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800961
962
Craig Tiller841c8802015-09-10 13:06:37 -0700963 shared_csharp: shared_c \
964 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100965 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700966 % if lib.build == 'all' and lib.language == 'csharp':
Craig Tiller27f70842016-09-15 16:21:54 -0700967 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)\
Craig Tiller841c8802015-09-10 13:06:37 -0700968 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100969 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700970 % endfor
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800971
Craig Tiller841c8802015-09-10 13:06:37 -0700972 grpc_csharp_ext: shared_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800973
Craig Tiller841c8802015-09-10 13:06:37 -0700974 plugins: $(PROTOC_PLUGINS)
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100975
Craig Tiller841c8802015-09-10 13:06:37 -0700976 privatelibs: privatelibs_c privatelibs_cxx
nnoble29e1d292014-12-01 10:27:40 -0800977
Craig Tiller841c8802015-09-10 13:06:37 -0700978 privatelibs_c: \
979 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100980 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800981 % 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 -0700982 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
983 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100984 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700985 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800986
Craig Tiller841c8802015-09-10 13:06:37 -0700987 pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc
murgatroid998faab232015-06-30 17:24:21 -0700988
Craig Tiller841c8802015-09-10 13:06:37 -0700989 pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -0700990
Craig Tiller841c8802015-09-10 13:06:37 -0700991 pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc
murgatroid998faab232015-06-30 17:24:21 -0700992
Craig Tiller841c8802015-09-10 13:06:37 -0700993 pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800994
vjpai20410922016-06-15 09:21:42 -0700995 ifeq ($(EMBED_OPENSSL),true)
Craig Tiller841c8802015-09-10 13:06:37 -0700996 privatelibs_cxx: \
997 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100998 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700999 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None):
1000 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
1001 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001002 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001003 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -07001004
vjpai20410922016-06-15 09:21:42 -07001005 else
1006 privatelibs_cxx: \
1007 % for lib in libs:
1008 % if 'Makefile' in lib.get('build_system', ['Makefile']):
1009 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None) and not lib.boringssl:
1010 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
1011 % endif
1012 % endif
1013 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -07001014
vjpai20410922016-06-15 09:21:42 -07001015 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001016
1017
Craig Tillereda85c62016-07-01 12:45:19 -07001018 buildtests: buildtests_c buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -08001019
Craig Tiller3824b6e2015-12-09 11:19:59 -08001020 buildtests_c: privatelibs_c <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001021 % for tgt in targets:
1022 % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -08001023 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001024 % endif
1025 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001026
1027
vjpai20410922016-06-15 09:21:42 -07001028 ifeq ($(EMBED_OPENSSL),true)
Craig Tillereda85c62016-07-01 12:45:19 -07001029 buildtests_cxx: privatelibs_cxx <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001030 % for tgt in targets:
1031 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -08001032 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001033 % endif
1034 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -07001035
vjpai20410922016-06-15 09:21:42 -07001036 else
Craig Tillereda85c62016-07-01 12:45:19 -07001037 buildtests_cxx: privatelibs_cxx <%text>\</%text>
vjpai20410922016-06-15 09:21:42 -07001038 % for tgt in targets:
1039 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl:
1040 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
1041 % endif
1042 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -07001043
vjpai20410922016-06-15 09:21:42 -07001044 endif
nnoble29e1d292014-12-01 10:27:40 -08001045
1046
Craig Tillereda85c62016-07-01 12:45:19 -07001047 test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -08001048
Craig Tillereda85c62016-07-01 12:45:19 -07001049 flaky_test: flaky_test_c flaky_test_cxx
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001050
Craig Tiller841c8802015-09-10 13:06:37 -07001051 test_c: buildtests_c
1052 % for tgt in targets:
1053 % 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):
1054 $(E) "[RUN] Testing ${tgt.name}"
1055 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1056 % endif
1057 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001058
1059
Craig Tiller841c8802015-09-10 13:06:37 -07001060 flaky_test_c: buildtests_c
1061 % for tgt in targets:
1062 % 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):
1063 $(E) "[RUN] Testing ${tgt.name}"
1064 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1065 % endif
1066 % endfor
nnoble29e1d292014-12-01 10:27:40 -08001067
1068
Craig Tillereda85c62016-07-01 12:45:19 -07001069 test_cxx: buildtests_cxx
Craig Tiller841c8802015-09-10 13:06:37 -07001070 % for tgt in targets:
1071 % 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):
1072 $(E) "[RUN] Testing ${tgt.name}"
1073 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1074 % endif
1075 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001076
1077
Craig Tiller841c8802015-09-10 13:06:37 -07001078 flaky_test_cxx: buildtests_cxx
1079 % for tgt in targets:
1080 % 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):
1081 $(E) "[RUN] Testing ${tgt.name}"
1082 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1083 % endif
1084 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001085
1086
Craig Tiller841c8802015-09-10 13:06:37 -07001087 test_python: static_c
1088 $(E) "[RUN] Testing python code"
1089 $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
Nicolas "Pixel" Noble051a28f2015-03-17 22:54:54 +01001090
1091
Craig Tiller841c8802015-09-10 13:06:37 -07001092 tools: tools_c tools_cxx
Craig Tiller7552f0f2015-06-19 17:46:20 -07001093
1094
Craig Tiller841c8802015-09-10 13:06:37 -07001095 tools_c: privatelibs_c\
1096 % for tgt in targets:
1097 % if tgt.build == 'tool' and not tgt.language=='c++':
1098 $(BINDIR)/$(CONFIG)/${tgt.name}\
1099 % endif
1100 % endfor
Craig Tiller7552f0f2015-06-19 17:46:20 -07001101
1102
Craig Tiller841c8802015-09-10 13:06:37 -07001103 tools_cxx: privatelibs_cxx\
1104 % for tgt in targets:
1105 % if tgt.build == 'tool' and tgt.language=='c++':
1106 $(BINDIR)/$(CONFIG)/${tgt.name}\
1107 % endif
1108 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001109
1110
Craig Tiller841c8802015-09-10 13:06:37 -07001111 buildbenchmarks: privatelibs\
1112 % for tgt in targets:
1113 % if tgt.build == 'benchmark':
1114 $(BINDIR)/$(CONFIG)/${tgt.name}\
1115 % endif
1116 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001117
1118
Craig Tiller841c8802015-09-10 13:06:37 -07001119 benchmarks: buildbenchmarks
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001120
Craig Tiller841c8802015-09-10 13:06:37 -07001121 strip: strip-static strip-shared
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001122
Craig Tiller841c8802015-09-10 13:06:37 -07001123 strip-static: strip-static_c strip-static_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001124
Craig Tiller841c8802015-09-10 13:06:37 -07001125 strip-shared: strip-shared_c strip-shared_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001126
Nicolas Noble047b7272015-01-16 13:55:05 -08001127
Craig Tiller841c8802015-09-10 13:06:37 -07001128 # TODO(nnoble): the strip target is stripping in-place, instead
1129 # of copying files in a temporary folder.
1130 # This prevents proper debugging after running make install.
Nicolas Noble047b7272015-01-16 13:55:05 -08001131
Craig Tiller841c8802015-09-10 13:06:37 -07001132 strip-static_c: static_c
1133 ifeq ($(CONFIG),opt)
1134 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001135 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001136 % if lib.language == "c":
1137 % if lib.build == "all":
1138 % if not lib.get('external_deps', None):
1139 $(E) "[STRIP] Stripping lib${lib.name}.a"
1140 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1141 % endif
1142 % endif
1143 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001144 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001145 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001146 endif
nnoble85a49262014-12-08 18:14:03 -08001147
Craig Tiller841c8802015-09-10 13:06:37 -07001148 strip-static_cxx: static_cxx
1149 ifeq ($(CONFIG),opt)
1150 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001151 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001152 % if lib.language == "c++":
1153 % if lib.build == "all":
1154 $(E) "[STRIP] Stripping lib${lib.name}.a"
1155 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1156 % endif
1157 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001158 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001159 % endfor
1160 endif
Nicolas "Pixel" Noble4ef9b862015-08-14 19:35:24 +02001161
Craig Tiller841c8802015-09-10 13:06:37 -07001162 strip-shared_c: shared_c
1163 ifeq ($(CONFIG),opt)
1164 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001165 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001166 % if lib.language == "c":
1167 % if lib.build == "all":
1168 % if not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -07001169 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)"
1170 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)
Craig Tiller841c8802015-09-10 13:06:37 -07001171 % endif
1172 % endif
1173 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001174 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001175 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001176 endif
nnoble85a49262014-12-08 18:14:03 -08001177
Craig Tiller841c8802015-09-10 13:06:37 -07001178 strip-shared_cxx: shared_cxx
1179 ifeq ($(CONFIG),opt)
1180 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001181 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001182 % if lib.language == "c++":
1183 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001184 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)"
1185 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)
Craig Tiller841c8802015-09-10 13:06:37 -07001186 % endif
1187 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001188 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001189 % endfor
1190 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001191
Craig Tiller841c8802015-09-10 13:06:37 -07001192 strip-shared_csharp: shared_csharp
1193 ifeq ($(CONFIG),opt)
1194 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001195 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001196 % if lib.language == "csharp":
1197 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001198 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)"
1199 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)
Craig Tiller841c8802015-09-10 13:06:37 -07001200 % endif
1201 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001202 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001203 % endfor
1204 endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001205
Craig Tiller841c8802015-09-10 13:06:37 -07001206 cache.mk::
1207 $(E) "[MAKE] Generating $@"
1208 $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@
murgatroid99aa521572015-07-10 14:49:12 -07001209
Craig Tiller841c8802015-09-10 13:06:37 -07001210 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc:
1211 $(E) "[MAKE] Generating $@"
1212 $(Q) mkdir -p $(@D)
1213 $(Q) echo "$(GRPC_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001214
Craig Tiller841c8802015-09-10 13:06:37 -07001215 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc:
1216 $(E) "[MAKE] Generating $@"
1217 $(Q) mkdir -p $(@D)
1218 $(Q) echo "$(GRPC_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001219
Craig Tiller841c8802015-09-10 13:06:37 -07001220 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc:
1221 $(E) "[MAKE] Generating $@"
1222 $(Q) mkdir -p $(@D)
1223 $(Q) echo "$(GRPCXX_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001224
Craig Tiller841c8802015-09-10 13:06:37 -07001225 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc:
1226 $(E) "[MAKE] Generating $@"
1227 $(Q) mkdir -p $(@D)
1228 $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001229
Craig Tiller841c8802015-09-10 13:06:37 -07001230 % for p in protos:
1231 ifeq ($(NO_PROTOC),true)
1232 $(GENDIR)/${p}.pb.cc: protoc_dep_error
1233 $(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error
1234 else
Mahak Mukhifb059a22017-04-18 14:40:00 -07001235 <%
1236 pluginflags=""
1237 %>
1238 % if p in ["src/proto/grpc/testing/compiler_test", "src/proto/grpc/testing/echo"]:
1239 <%
1240 pluginflags="generate_mock_code=true:"
1241 %>
1242 % endif
Craig Tiller1b4e3302015-12-17 16:35:00 -08001243 $(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 -07001244 $(E) "[PROTOC] Generating protobuf CC file from $<"
1245 $(Q) mkdir -p `dirname $@`
David Garcia Quintase68ed6f2016-06-17 12:49:14 -07001246 $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --cpp_out=$(GENDIR) $<
Nicolas "Pixel" Noble0caebbf2015-04-09 23:08:51 +02001247
Craig Tiller1b4e3302015-12-17 16:35:00 -08001248 $(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 -07001249 $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
1250 $(Q) mkdir -p `dirname $@`
Mahak Mukhifb059a22017-04-18 14:40:00 -07001251 $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=${pluginflags}$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $<
Craig Tiller841c8802015-09-10 13:06:37 -07001252 endif
nnoble72309c62014-12-12 11:42:26 -08001253
Craig Tiller841c8802015-09-10 13:06:37 -07001254 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001255
Craig Tiller841c8802015-09-10 13:06:37 -07001256 ifeq ($(CONFIG),stapprof)
1257 src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h
1258 ifeq ($(HAS_SYSTEMTAP),true)
1259 $(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d
1260 $(E) "[DTRACE] Compiling $<"
1261 $(Q) mkdir -p `dirname $@`
1262 $(Q) $(DTRACE) -C -h -s $< -o $@
1263 else
1264 $(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop
1265 endif
1266 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -07001267
Craig Tiller841c8802015-09-10 13:06:37 -07001268 $(OBJDIR)/$(CONFIG)/%.o : %.c
1269 $(E) "[C] Compiling $<"
1270 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001271 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001272
Craig Tiller841c8802015-09-10 13:06:37 -07001273 $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
1274 $(E) "[CXX] Compiling $<"
1275 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001276 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001277
Craig Tiller841c8802015-09-10 13:06:37 -07001278 $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
1279 $(E) "[HOSTCXX] Compiling $<"
1280 $(Q) mkdir -p `dirname $@`
1281 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -08001282
Craig Tiller841c8802015-09-10 13:06:37 -07001283 $(OBJDIR)/$(CONFIG)/%.o : %.cc
1284 $(E) "[CXX] Compiling $<"
1285 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001286 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001287
murgatroid99a3c55352016-08-10 13:41:31 -07001288 install: install_c install_cxx install-plugins install-certs
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001289
Craig Tiller841c8802015-09-10 13:06:37 -07001290 install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001291
Craig Tiller841c8802015-09-10 13:06:37 -07001292 install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
nnoble85a49262014-12-08 18:14:03 -08001293
Craig Tiller841c8802015-09-10 13:06:37 -07001294 install_csharp: install-shared_csharp install_c
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001295
Craig Tiller841c8802015-09-10 13:06:37 -07001296 install_grpc_csharp_ext: install_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001297
Craig Tiller841c8802015-09-10 13:06:37 -07001298 install-headers: install-headers_c install-headers_cxx
nnoble85a49262014-12-08 18:14:03 -08001299
Craig Tiller841c8802015-09-10 13:06:37 -07001300 install-headers_c:
1301 $(E) "[INSTALL] Installing public C headers"
1302 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1303 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001304
Craig Tiller841c8802015-09-10 13:06:37 -07001305 install-headers_cxx:
1306 $(E) "[INSTALL] Installing public C++ headers"
1307 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1308 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001309
Craig Tiller841c8802015-09-10 13:06:37 -07001310 install-static: install-static_c install-static_cxx
nnoble85a49262014-12-08 18:14:03 -08001311
Craig Tiller841c8802015-09-10 13:06:37 -07001312 install-static_c: static_c strip-static_c install-pkg-config_c
1313 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001314 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001315 % if lib.language == "c":
1316 % if lib.build == "all":
1317 % if not lib.get('external_deps', None):
1318 $(E) "[INSTALL] Installing lib${lib.name}.a"
1319 $(Q) $(INSTALL) -d $(prefix)/lib
1320 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1321 % endif
1322 % endif
1323 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001324 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001325 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001326
Craig Tiller841c8802015-09-10 13:06:37 -07001327 install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx
1328 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001329 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001330 % if lib.language == "c++":
1331 % if lib.build == "all":
1332 $(E) "[INSTALL] Installing lib${lib.name}.a"
1333 $(Q) $(INSTALL) -d $(prefix)/lib
1334 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1335 % endif
1336 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001337 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001338 % endfor
nnoble85a49262014-12-08 18:14:03 -08001339
Craig Tiller841c8802015-09-10 13:06:37 -07001340 <%def name="install_shared(lang_filter)">\
1341 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001342 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001343 % if lib.language == lang_filter:
1344 % if lib.build == "all":
1345 % if not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -07001346 $(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 +01001347 $(Q) $(INSTALL) -d $(prefix)/lib
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001348 $(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 -07001349 ifeq ($(SYSTEM),MINGW32)
Mario Emmenlauer44b2d082017-01-13 12:35:49 +01001350 $(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 +01001351 else ifneq ($(SYSTEM),Darwin)
Craig Tiller27f70842016-09-15 16:21:54 -07001352 $(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}
1353 $(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 -07001354 endif
1355 % endif
1356 % endif
1357 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001358 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001359 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001360 ifneq ($(SYSTEM),MINGW32)
1361 ifneq ($(SYSTEM),Darwin)
1362 $(Q) ldconfig || true
1363 endif
1364 endif
1365 </%def>
nnoble85a49262014-12-08 18:14:03 -08001366
Craig Tiller841c8802015-09-10 13:06:37 -07001367 install-shared_c: shared_c strip-shared_c install-pkg-config_c
1368 ${install_shared("c")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001369
Craig Tiller841c8802015-09-10 13:06:37 -07001370 install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c install-pkg-config_cxx
1371 ${install_shared("c++")}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001372
Craig Tiller841c8802015-09-10 13:06:37 -07001373 install-shared_csharp: shared_csharp strip-shared_csharp
1374 ${install_shared("csharp")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001375
Craig Tiller841c8802015-09-10 13:06:37 -07001376 install-plugins: $(PROTOC_PLUGINS)
Craig Tiller841c8802015-09-10 13:06:37 -07001377 $(E) "[INSTALL] Installing grpc protoc plugins"
1378 % for tgt in targets:
1379 % if tgt.build == 'protoc':
1380 $(Q) $(INSTALL) -d $(prefix)/bin
1381 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
1382 % endif
1383 % endfor
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001384
Craig Tillereda85c62016-07-01 12:45:19 -07001385 install-pkg-config_c: pc_c pc_c_unsecure
Craig Tiller841c8802015-09-10 13:06:37 -07001386 $(E) "[INSTALL] Installing C pkg-config files"
1387 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
Craig Tiller841c8802015-09-10 13:06:37 -07001388 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(prefix)/lib/pkgconfig/grpc.pc
1389 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(prefix)/lib/pkgconfig/grpc_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -07001390
Craig Tiller841c8802015-09-10 13:06:37 -07001391 install-pkg-config_cxx: pc_cxx pc_cxx_unsecure
1392 $(E) "[INSTALL] Installing C++ pkg-config files"
1393 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
1394 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc $(prefix)/lib/pkgconfig/grpc++.pc
1395 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc $(prefix)/lib/pkgconfig/grpc++_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -07001396
Craig Tiller841c8802015-09-10 13:06:37 -07001397 install-certs: etc/roots.pem
1398 $(E) "[INSTALL] Installing root certificates"
1399 $(Q) $(INSTALL) -d $(prefix)/share/grpc
1400 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +01001401
Craig Tiller841c8802015-09-10 13:06:37 -07001402 clean:
1403 $(E) "[CLEAN] Cleaning build directories."
1404 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001405
1406
Craig Tiller841c8802015-09-10 13:06:37 -07001407 # The various libraries
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001408
Craig Tiller841c8802015-09-10 13:06:37 -07001409 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001410 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001411 ${makelib(lib)}
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001412 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001413 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001414
1415
Craig Tiller841c8802015-09-10 13:06:37 -07001416 # All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001417
Craig Tiller841c8802015-09-10 13:06:37 -07001418 % for tgt in targets:
1419 ${maketarget(tgt)}
1420 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001421
Craig Tiller841c8802015-09-10 13:06:37 -07001422 <%def name="makelib(lib)">
1423 LIB${lib.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001424
Craig Tiller841c8802015-09-10 13:06:37 -07001425 % for src in lib.src:
1426 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001427
Craig Tiller841c8802015-09-10 13:06:37 -07001428 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001429
Craig Tiller841c8802015-09-10 13:06:37 -07001430 % if "public_headers" in lib:
1431 % if lib.language == "c++":
1432 PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001433
Craig Tiller841c8802015-09-10 13:06:37 -07001434 % else:
1435 PUBLIC_HEADERS_C += \\
nnoble85a49262014-12-08 18:14:03 -08001436
Craig Tiller841c8802015-09-10 13:06:37 -07001437 % endif
1438 % for hdr in lib.public_headers:
1439 ${hdr} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001440
Craig Tiller841c8802015-09-10 13:06:37 -07001441 % endfor
1442 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001443
Craig Tiller841c8802015-09-10 13:06:37 -07001444 LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001445
Nicolas "Pixel" Noble51b1aee2016-01-28 01:14:58 +01001446 % if lib.get('defaults', None):
1447 % for name, value in defaults.get(lib.defaults).iteritems():
1448 $(LIB${lib.name.upper()}_OBJS): ${name} += ${value}
1449 % endfor
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001450 % endif
1451
Craig Tiller841c8802015-09-10 13:06:37 -07001452 ## If the library requires OpenSSL, let's add some restrictions.
1453 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1454 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001455
Craig Tiller841c8802015-09-10 13:06:37 -07001456 # You can't build secure libraries if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001457
Craig Tiller841c8802015-09-10 13:06:37 -07001458 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001459
Craig Tiller841c8802015-09-10 13:06:37 -07001460 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001461 $(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 -07001462 % endif
nnoble5b7f32a2014-12-22 08:12:44 -08001463
Craig Tiller841c8802015-09-10 13:06:37 -07001464 else
nnoble69ac39f2014-12-12 15:43:38 -08001465
Craig Tiller841c8802015-09-10 13:06:37 -07001466 % if lib.language == 'c++':
1467 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001468
Craig Tiller841c8802015-09-10 13:06:37 -07001469 # 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 -08001470
Craig Tiller841c8802015-09-10 13:06:37 -07001471 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001472
Craig Tiller841c8802015-09-10 13:06:37 -07001473 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001474 $(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 -07001475 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001476
Craig Tiller841c8802015-09-10 13:06:37 -07001477 else
1478 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001479
Nicolas "Pixel" Nobleb0367ca2017-03-29 21:53:38 +02001480 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(CARES_DEP)\
Craig Tiller841c8802015-09-10 13:06:37 -07001481 ## The else here corresponds to the if secure earlier.
1482 % else:
1483 % if lib.language == 'c++':
1484 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001485
Craig Tiller841c8802015-09-10 13:06:37 -07001486 # 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 -08001487
Craig Tiller841c8802015-09-10 13:06:37 -07001488 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001489
Craig Tiller841c8802015-09-10 13:06:37 -07001490 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001491 $(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 -07001492 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001493
Craig Tiller841c8802015-09-10 13:06:37 -07001494 else
Nicolas Noble53830622015-02-12 16:56:38 -08001495
Craig Tiller841c8802015-09-10 13:06:37 -07001496 % endif
Yuchen Zeng78f9f942016-08-05 18:21:57 -07001497 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: \
Nicolas "Pixel" Nobled649c212016-01-27 20:27:30 +01001498 % if lib.name != 'z':
1499 $(ZLIB_DEP) \
1500 % endif
Yuchen Zeng15141a62016-08-17 18:56:04 -07001501 % if lib.name != 'ares':
1502 $(CARES_DEP) \
Yuchen Zengf64bf282016-08-11 21:21:32 -07001503 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001504 % endif
1505 % if lib.language == 'c++':
1506 $(PROTOBUF_DEP)\
1507 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001508 $(LIB${lib.name.upper()}_OBJS) \
1509 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001510 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001511 $(ZLIB_MERGE_OBJS) \
Yuchen Zeng15141a62016-08-17 18:56:04 -07001512 $(CARES_MERGE_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001513 % if lib.get('secure', 'check') == True:
1514 $(OPENSSL_MERGE_OBJS) \
1515 % endif
1516 % endif
1517
Craig Tiller841c8802015-09-10 13:06:37 -07001518 $(E) "[AR] Creating $@"
1519 $(Q) mkdir -p `dirname $@`
1520 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Vijay Paicc7eb8e2016-07-19 19:03:55 -07001521 $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001522 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001523 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001524 $(ZLIB_MERGE_OBJS) \
Yuchen Zeng15141a62016-08-17 18:56:04 -07001525 $(CARES_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001526 % if lib.get('secure', 'check') == True:
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001527 $(OPENSSL_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001528 % endif
1529 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001530
Craig Tiller841c8802015-09-10 13:06:37 -07001531 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001532 $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tiller841c8802015-09-10 13:06:37 -07001533 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001534
Craig Tiller841c8802015-09-10 13:06:37 -07001535 <%
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001536
Craig Tiller841c8802015-09-10 13:06:37 -07001537 if lib.language == 'c++':
1538 ld = '$(LDXX)'
1539 else:
1540 ld = '$(LD)'
nnoble5b7f32a2014-12-22 08:12:44 -08001541
Craig Tiller40c8fba2016-09-15 16:29:09 -07001542 out_mingbase = '$(LIBDIR)/$(CONFIG)/' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
1543 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
nnoble5b7f32a2014-12-22 08:12:44 -08001544
Nicolas "Pixel" Noble8087d702017-02-01 02:23:50 +01001545 common = '$(LIB' + lib.name.upper() + '_OBJS)'
nnoble5b7f32a2014-12-22 08:12:44 -08001546
Craig Tillerd7b1bdf2016-11-04 16:20:13 -07001547 link_libs = ''
Yuchen Zeng9b5aa632016-07-26 19:09:56 -07001548 lib_deps = ' $(ZLIB_DEP) $(CARES_DEP)'
Craig Tiller841c8802015-09-10 13:06:37 -07001549 mingw_libs = ''
Yuchen Zeng9b5aa632016-07-26 19:09:56 -07001550 mingw_lib_deps = ' $(ZLIB_DEP) $(CARES_DEP)'
Craig Tiller841c8802015-09-10 13:06:37 -07001551 if lib.language == 'c++':
1552 lib_deps += ' $(PROTOBUF_DEP)'
1553 mingw_lib_deps += ' $(PROTOBUF_DEP)'
Jan Tattermusch324140c2016-01-12 08:54:01 -08001554 if lib.get('deps_linkage', None) == 'static':
1555 for dep in lib.get('deps', []):
1556 lib_archive = '$(LIBDIR)/$(CONFIG)/lib' + dep + '.a'
1557 common = common + ' ' + lib_archive
1558 lib_deps = lib_deps + ' ' + lib_archive
1559 mingw_lib_deps = mingw_lib_deps + ' ' + lib_archive
1560 else:
1561 for dep in lib.get('deps', []):
Craig Tillerd7b1bdf2016-11-04 16:20:13 -07001562 dep_lib = None
1563 for dl in libs:
1564 if dl.name == dep:
1565 dep_lib = dl
1566 assert dep_lib, 'lib %s not found (in %s)' % (dep, lib.name)
1567 link_libs = link_libs + ' -l' + dep
1568 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT_' + lang_to_var[dep_lib.language] + ')'
Mario Emmenlauer44b2d082017-01-13 12:35:49 +01001569 mingw_libs = mingw_libs + ' -l' + dep + '$(SHARED_VERSION_' + lang_to_var[dep_lib.language] + ')-dll'
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001570 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 -08001571
Craig Tiller841c8802015-09-10 13:06:37 -07001572 security = lib.get('secure', 'check')
1573 if security == True:
1574 common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)'
Yuchen Zeng15141a62016-08-17 18:56:04 -07001575 common = common + ' $(ZLIB_MERGE_LIBS) $(CARES_MERGE_LIBS)'
Nicolas "Pixel" Noblea7c162c2015-07-24 20:21:51 +02001576
Craig Tiller841c8802015-09-10 13:06:37 -07001577 if security in [True, 'check']:
1578 for src in lib.src:
1579 if not proto_re.match(src):
1580 sources_that_need_openssl.add(src)
1581 else:
1582 for src in lib.src:
1583 sources_that_don_t_need_openssl.add(src)
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001584
Craig Tiller841c8802015-09-10 13:06:37 -07001585 if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1586 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1587 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001588
Craig Tiller841c8802015-09-10 13:06:37 -07001589 if lib.language == 'c++':
1590 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
Craig Tiller4bef7ce2016-02-02 08:38:43 -08001591
1592 ldflags = '$(LDFLAGS)'
1593 if lib.get('LDFLAGS', None):
1594 ldflags += ' ' + lib['LDFLAGS']
Nicolas "Pixel" Noble8087d702017-02-01 02:23:50 +01001595
1596 common = common + ' $(LDLIBS)'
Craig Tiller841c8802015-09-10 13:06:37 -07001597 %>
nnoble5b7f32a2014-12-22 08:12:44 -08001598
Craig Tiller841c8802015-09-10 13:06:37 -07001599 % if lib.build == "all":
1600 ifeq ($(SYSTEM),MINGW32)
Craig Tiller38b99e92016-09-15 16:18:09 -07001601 ${out_mingbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Craig Tiller841c8802015-09-10 13:06:37 -07001602 $(E) "[LD] Linking $@"
1603 $(Q) mkdir -p `dirname $@`
Mario Emmenlauer294dc2f2016-12-13 00:07:12 +01001604 $(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 -07001605 else
Craig Tiller38b99e92016-09-15 16:18:09 -07001606 ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
Craig Tiller841c8802015-09-10 13:06:37 -07001607 $(E) "[LD] Linking $@"
1608 $(Q) mkdir -p `dirname $@`
1609 ifeq ($(SYSTEM),Darwin)
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001610 $(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 -07001611 else
murgatroid99d166e382017-03-24 10:03:10 -07001612 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.get(lang_to_var[lib.language].lower() + '_version').major} -o ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${link_libs}
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001613 $(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}
1614 $(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 -07001615 endif
1616 endif
1617 % endif
1618 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1619 ## If the lib was secure, we have to close the Makefile's if that tested
1620 ## the presence of OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001621
Craig Tiller841c8802015-09-10 13:06:37 -07001622 endif
1623 % endif
1624 % if lib.language == 'c++':
1625 ## If the lib was C++, we have to close the Makefile's if that tested
1626 ## the presence of protobuf 3.0.0+
nnoble69ac39f2014-12-12 15:43:38 -08001627
Craig Tiller841c8802015-09-10 13:06:37 -07001628 endif
1629 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001630
Craig Tiller841c8802015-09-10 13:06:37 -07001631 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1632 ifneq ($(NO_SECURE),true)
1633 % endif
1634 ifneq ($(NO_DEPS),true)
1635 -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
1636 endif
1637 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1638 endif
1639 % endif
1640 % for src in lib.src:
1641 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src):
1642 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))}
1643 % endif
1644 % endfor
1645 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001646
Craig Tiller841c8802015-09-10 13:06:37 -07001647 <%def name="maketarget(tgt)"><% has_no_sources = not tgt.src %>
1648 % if not has_no_sources:
1649 ${tgt.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001650
Craig Tiller841c8802015-09-10 13:06:37 -07001651 % for src in tgt.src:
1652 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001653
Craig Tiller841c8802015-09-10 13:06:37 -07001654 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001655
Craig Tiller841c8802015-09-10 13:06:37 -07001656 ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
1657 % endif
1658 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1659 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001660
Craig Tiller841c8802015-09-10 13:06:37 -07001661 # You can't build secure targets if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001662
Craig Tiller841c8802015-09-10 13:06:37 -07001663 $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001664
Craig Tiller841c8802015-09-10 13:06:37 -07001665 else
nnoble69ac39f2014-12-12 15:43:38 -08001666
Craig Tiller841c8802015-09-10 13:06:37 -07001667 % endif
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001668
1669 % if tgt.boringssl:
1670 # boringssl needs an override to ensure that it does not include
1671 # system openssl headers regardless of other configuration
1672 # we do so here with a target specific variable assignment
Craig Tiller78222f72016-05-10 09:55:38 -07001673 $(${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 -08001674 $(${tgt.name.upper()}_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS)
1675 $(${tgt.name.upper()}_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE
1676 % else:
1677 % endif
1678
Craig Tiller841c8802015-09-10 13:06:37 -07001679 ##
1680 ## We're not trying to add a dependency on building zlib and openssl here,
1681 ## as it's already done in the libraries. We're assuming that the build
1682 ## trickles down, and that a secure target requires a secure version of
1683 ## a library.
1684 ##
1685 ## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1686 ## I can live with that.
1687 ##
1688 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001689
Craig Tiller841c8802015-09-10 13:06:37 -07001690 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001691
Craig Tiller841c8802015-09-10 13:06:37 -07001692 # 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 -08001693
Craig Tiller841c8802015-09-10 13:06:37 -07001694 $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001695
Craig Tiller841c8802015-09-10 13:06:37 -07001696 else
Nicolas Noble53830622015-02-12 16:56:38 -08001697
Craig Tiller841c8802015-09-10 13:06:37 -07001698 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1699 % if not has_no_sources:
1700 $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
1701 % endif
1702 % else:
1703 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1704 % if not has_no_sources:
1705 $(${tgt.name.upper()}_OBJS)\
1706 % endif
1707 % endif
1708 % for dep in tgt.deps:
1709 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1710 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001711
Craig Tiller32173c52016-03-17 14:12:45 -07001712 % if tgt.language == "c++" or tgt.boringssl or tgt.build == 'fuzzer':
Craig Tiller841c8802015-09-10 13:06:37 -07001713 ## C++ targets specificies.
1714 % if tgt.build == 'protoc':
1715 $(E) "[HOSTLD] Linking $@"
1716 $(Q) mkdir -p `dirname $@`
1717 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) \
1718 % if not has_no_sources:
1719 $(${tgt.name.upper()}_OBJS)\
1720 % endif
1721 % else:
1722 $(E) "[LD] Linking $@"
1723 $(Q) mkdir -p `dirname $@`
1724 $(Q) $(LDXX) $(LDFLAGS) \
1725 % if not has_no_sources:
1726 $(${tgt.name.upper()}_OBJS)\
1727 % endif
1728 % endif
1729 % else:
1730 ## C-only targets specificities.
1731 $(E) "[LD] Linking $@"
1732 $(Q) mkdir -p `dirname $@`
1733 $(Q) $(LD) $(LDFLAGS) \
1734 % if not has_no_sources:
1735 $(${tgt.name.upper()}_OBJS)\
1736 % endif
1737 % endif
1738 % for dep in tgt.deps:
1739 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1740 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001741 % if tgt.language == "c++":
1742 % if tgt.build == 'protoc':
1743 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
1744 % else:
1745 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
1746 % endif
1747 % endif
1748 % if tgt.build == 'protoc':
1749 $(HOST_LDLIBS)\
1750 % else:
1751 $(LDLIBS)\
1752 % endif
1753 % if tgt.build == 'protoc':
1754 $(HOST_LDLIBS_PROTOC)\
1755 % elif tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1756 $(LDLIBS_SECURE)\
1757 % endif
1758 % if tgt.language == 'c++' and tgt.build == 'test':
1759 $(GTEST_LIB)\
1760 % elif tgt.language == 'c++' and tgt.build == 'benchmark':
1761 $(GTEST_LIB)\
1762 % endif
Craig Tiller32173c52016-03-17 14:12:45 -07001763 % if tgt.build == 'fuzzer':
1764 -lFuzzer\
1765 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001766 -o $(BINDIR)/$(CONFIG)/${tgt.name}
1767 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001768
Craig Tiller841c8802015-09-10 13:06:37 -07001769 endif
1770 % endif
1771 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001772
Craig Tiller841c8802015-09-10 13:06:37 -07001773 endif
1774 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001775
Craig Tiller19f3ea22017-02-17 15:17:05 -08001776 % if tgt.get('defaults', None):
1777 % for name, value in defaults.get(tgt.defaults).iteritems():
1778 $(${tgt.name.upper()}_OBJS): ${name} += ${value}
1779 % endfor
1780 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001781 % for src in tgt.src:
1782 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
1783 % for dep in tgt.deps:
1784 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1785 % endfor
Craig Tillerf5371ef2015-01-12 16:40:18 -08001786
Craig Tillerab230452016-01-04 08:18:43 -08001787 % if tgt.language == 'c89':
1788 % for src in tgt.src:
Craig Tillerea21ca22016-01-04 12:34:29 -08001789 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o : ${src}
1790 $(E) "[C] Compiling $<"
1791 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001792 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -std=c89 -pedantic -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Craig Tillerab230452016-01-04 08:18:43 -08001793 % endfor
1794 % endif
1795
Craig Tiller841c8802015-09-10 13:06:37 -07001796 % endfor
1797 % if not has_no_sources:
1798 deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
1799 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001800
Craig Tiller841c8802015-09-10 13:06:37 -07001801 % if not has_no_sources:
1802 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1803 ifneq ($(NO_SECURE),true)
1804 % endif
1805 ifneq ($(NO_DEPS),true)
1806 -include $(${tgt.name.upper()}_OBJS:.o=.dep)
1807 endif
1808 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1809 endif
1810 % endif
1811 % endif
Nicolas "Pixel" Noble472bb682015-11-03 19:09:01 +01001812 % for src in tgt.src:
1813 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in tgt.src):
1814 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in tgt.src if proto_re.match(src2))}
1815 % endif
1816 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001817 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001818
Craig Tiller841c8802015-09-10 13:06:37 -07001819 ifneq ($(OPENSSL_DEP),)
1820 # This is to ensure the embedded OpenSSL is built beforehand, properly
1821 # installing headers to their final destination on the drive. We need this
1822 # otherwise parallel compilation will fail if a source is compiled first.
1823 % for src in sorted(sources_that_need_openssl):
1824 % if src not in sources_that_don_t_need_openssl:
1825 ${src}: $(OPENSSL_DEP)
1826 % endif
1827 % endfor
1828 endif
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001829
Craig Tiller841c8802015-09-10 13:06:37 -07001830 .PHONY: all strip tools \
1831 dep_error openssl_dep_error openssl_dep_message git_update stop \
1832 buildtests buildtests_c buildtests_cxx \
1833 test test_c test_cxx \
1834 install install_c install_cxx \
1835 install-headers install-headers_c install-headers_cxx \
1836 install-shared install-shared_c install-shared_cxx \
1837 install-static install-static_c install-static_cxx \
1838 strip strip-shared strip-static \
1839 strip_c strip-shared_c strip-static_c \
1840 strip_cxx strip-shared_cxx strip-static_cxx \
1841 dep_c dep_cxx bins_dep_c bins_dep_cxx \
1842 clean
Craig Tillerb79c1e12016-02-23 10:00:58 -08001843
1844 .PHONY: printvars
1845 printvars:
1846 @$(foreach V,$(sort $(.VARIABLES)), \
1847 $(if $(filter-out environment% default automatic, \
1848 $(origin $V)),$(warning $V=$($V) ($(value $V)))))