blob: 9afc6566e2faf6ac4f4431fa80a7a7122e384fa1 [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 Tiller841c8802015-09-10 13:06:37 -070065 %>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080066
Craig Tiller96b49552015-01-21 16:29:01 -080067
Craig Tiller71a86042016-01-15 14:59:58 -080068 comma := ,
69
70
Craig Tiller841c8802015-09-10 13:06:37 -070071 # Basic platform detection
72 HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +010073 SYSTEM ?= $(HOST_SYSTEM)
Craig Tiller841c8802015-09-10 13:06:37 -070074 ifeq ($(SYSTEM),MSYS)
75 SYSTEM = MINGW32
76 endif
77 ifeq ($(SYSTEM),MINGW64)
78 SYSTEM = MINGW32
79 endif
Craig Tiller96b49552015-01-21 16:29:01 -080080
81
Nicolas "Pixel" Noble6dad9b02015-09-23 18:32:26 +020082 MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
Craig Tiller841c8802015-09-10 13:06:37 -070083 ifndef BUILDDIR
Nicolas "Pixel" Noble42b4c282015-09-17 23:57:08 +020084 BUILDDIR_ABSOLUTE = $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))
85 else
86 BUILDDIR_ABSOLUTE = $(abspath $(BUILDDIR))
Craig Tiller841c8802015-09-10 13:06:37 -070087 endif
Craig Tiller61b910f2015-02-15 10:54:07 -080088
Craig Tiller841c8802015-09-10 13:06:37 -070089 HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false)
90 HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false)
91 HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false)
Nicolas Noblef8681182015-03-18 14:25:44 -070092
Craig Tiller841c8802015-09-10 13:06:37 -070093 ifeq ($(HAS_CC),true)
94 DEFAULT_CC = cc
95 DEFAULT_CXX = c++
96 else
97 ifeq ($(HAS_GCC),true)
98 DEFAULT_CC = gcc
99 DEFAULT_CXX = g++
100 else
101 ifeq ($(HAS_CLANG),true)
102 DEFAULT_CC = clang
103 DEFAULT_CXX = clang++
104 else
105 DEFAULT_CC = no_c_compiler
106 DEFAULT_CXX = no_c++_compiler
107 endif
108 endif
109 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700110
111
Nicolas "Pixel" Noble42b4c282015-09-17 23:57:08 +0200112 BINDIR = $(BUILDDIR_ABSOLUTE)/bins
113 OBJDIR = $(BUILDDIR_ABSOLUTE)/objs
114 LIBDIR = $(BUILDDIR_ABSOLUTE)/libs
115 GENDIR = $(BUILDDIR_ABSOLUTE)/gens
Craig Tiller61b910f2015-02-15 10:54:07 -0800116
Craig Tiller841c8802015-09-10 13:06:37 -0700117 # Configurations
ctiller8cfebb92015-01-06 15:02:12 -0800118
Craig Tillera0f85172016-01-20 15:56:06 -0800119 % for name, args in configs.iteritems():
120 VALID_CONFIG_${name} = 1
121 % if args.get('compile_the_world', False):
122 REQUIRE_CUSTOM_LIBRARIES_${name} = 1
123 % endif
Craig Tilleraff3d502016-01-20 15:59:31 -0800124 % for tool, default in [('CC', 'CC'), ('CXX', 'CXX'), ('LD', 'CC'), ('LDXX', 'CXX')]:
Craig Tillera0f85172016-01-20 15:56:06 -0800125 ${tool}_${name} = ${args.get(tool, '$(DEFAULT_%s)' % default)}
126 % endfor
127 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES']:
128 % if args.get(arg, None) is not None:
129 ${arg}_${name} = ${args.get(arg)}
130 % endif
131 % endfor
132 % if args.get('timeout_multiplier', 1) != 1:
133 DEFINES_${name} += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=${args.timeout_multiplier}
134 % endif
ctiller8cfebb92015-01-06 15:02:12 -0800135
Craig Tillera0f85172016-01-20 15:56:06 -0800136 % endfor
Craig Tiller699ba212015-01-13 17:02:20 -0800137
Nicolas Noble047b7272015-01-16 13:55:05 -0800138
Craig Tiller841c8802015-09-10 13:06:37 -0700139 # General settings.
140 # You may want to change these depending on your system.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800141
Craig Tiller841c8802015-09-10 13:06:37 -0700142 prefix ?= /usr/local
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800143
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100144 PROTOC ?= protoc
145 DTRACE ?= dtrace
Craig Tiller841c8802015-09-10 13:06:37 -0700146 CONFIG ?= opt
Nicolas "Pixel" Noblefba36bc2016-01-27 03:24:03 +0100147 # Doing X ?= Y is the same as:
148 # ifeq ($(origin X), undefined)
149 # X = Y
150 # endif
151 # but some variables, such as CC, CXX, LD or AR, have defaults.
152 # So instead of using ?= on them, we need to check their origin.
153 # See:
154 # https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
155 # https://www.gnu.org/software/make/manual/html_node/Flavors.html#index-_003f_003d
156 # https://www.gnu.org/software/make/manual/html_node/Origin-Function.html
157 ifeq ($(origin CC), default)
158 CC = $(CC_$(CONFIG))
159 endif
160 ifeq ($(origin CXX), default)
161 CXX = $(CXX_$(CONFIG))
162 endif
163 ifeq ($(origin LD), default)
164 LD = $(LD_$(CONFIG))
165 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100166 LDXX ?= $(LDXX_$(CONFIG))
Craig Tiller841c8802015-09-10 13:06:37 -0700167 ifeq ($(SYSTEM),Linux)
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100168 ifeq ($(origin AR), default)
169 AR = ar rcs
170 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100171 STRIP ?= strip --strip-unneeded
Craig Tiller841c8802015-09-10 13:06:37 -0700172 else
173 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100174 ifeq ($(origin AR), default)
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100175 AR = libtool -no_warning_for_no_symbols -o
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100176 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100177 STRIP ?= strip -x
Craig Tiller841c8802015-09-10 13:06:37 -0700178 else
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100179 ifeq ($(origin AR), default)
180 AR = ar rcs
181 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100182 STRIP ?= strip
Craig Tiller841c8802015-09-10 13:06:37 -0700183 endif
184 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100185 INSTALL ?= install
186 RM ?= rm -f
187 PKG_CONFIG ?= pkg-config
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800188
Craig Tiller841c8802015-09-10 13:06:37 -0700189 ifndef VALID_CONFIG_$(CONFIG)
190 $(error Invalid CONFIG value '$(CONFIG)')
191 endif
yangg102e4fe2015-01-06 16:02:50 -0800192
Craig Tiller841c8802015-09-10 13:06:37 -0700193 ifeq ($(SYSTEM),Linux)
194 TMPOUT = /dev/null
195 else
196 TMPOUT = `mktemp /tmp/test-out-XXXXXX`
197 endif
Nicolas Noble047b7272015-01-16 13:55:05 -0800198
Craig Tiller841c8802015-09-10 13:06:37 -0700199 # Detect if we can use C++11
200 CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc
201 HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false)
Craig Tillercf133f42015-02-26 14:05:56 -0800202
Craig Tiller78222f72016-05-10 09:55:38 -0700203 %for warning in CHECK_WARNINGS:
204 ${warning_var('CHECK_%s_WORKS_CMD', warning)} = $(CC) -std=c99 -Werror -W${warning} -o $(TMPOUT) -c test/build/${warning}.c
205 ${warning_var('HAS_WORKING_%s', warning)} = $(shell $(${warning_var('CHECK_%s_WORKS_CMD', warning)}) 2> /dev/null && echo true || echo false)
206 ifeq ($(${warning_var('HAS_WORKING_%s', warning)}),true)
207 ${warning_var('W_%s', warning)}=-W${warning}
208 ${warning_var('NO_W_%s', warning)}=-W${neg_warning(warning)}
Craig Tiller804b8552016-02-23 16:50:24 -0800209 endif
Craig Tiller78222f72016-05-10 09:55:38 -0700210 %endfor
Craig Tiller16872b82016-01-25 10:55:20 -0800211
Craig Tiller841c8802015-09-10 13:06:37 -0700212 # The HOST compiler settings are used to compile the protoc plugins.
213 # In most cases, you won't have to change anything, but if you are
214 # cross-compiling, you can override these variables from GNU make's
215 # command line: make CC=cross-gcc HOST_CC=gcc
Nicolas Noble047b7272015-01-16 13:55:05 -0800216
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100217 HOST_CC ?= $(CC)
218 HOST_CXX ?= $(CXX)
219 HOST_LD ?= $(LD)
220 HOST_LDXX ?= $(LDXX)
nnoble72309c62014-12-12 11:42:26 -0800221
Craig Tiller841c8802015-09-10 13:06:37 -0700222 ifdef EXTRA_DEFINES
223 DEFINES += $(EXTRA_DEFINES)
224 endif
Craig Tiller86fa1c52015-02-27 09:57:58 -0800225
Craig Tiller78222f72016-05-10 09:55:38 -0700226 CFLAGS += -std=c99 -Wsign-conversion -Wconversion ${' '.join(warning_var('$(W_%s)', warning) for warning in PREFERRED_WARNINGS)}
Craig Tiller841c8802015-09-10 13:06:37 -0700227 ifeq ($(HAS_CXX11),true)
228 CXXFLAGS += -std=c++11
229 else
230 CXXFLAGS += -std=c++0x
231 endif
Nicolas "Pixel" Noble51b1aee2016-01-28 01:14:58 +0100232 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES']:
233 % if defaults.get('global', []).get(arg, None) is not None:
234 ${arg} += ${defaults.get('global').get(arg)}
235 % endif
236 % endfor
Nicolas Noblef8681182015-03-18 14:25:44 -0700237
Craig Tiller841c8802015-09-10 13:06:37 -0700238 CPPFLAGS += $(CPPFLAGS_$(CONFIG))
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800239 CFLAGS += $(CFLAGS_$(CONFIG))
240 CXXFLAGS += $(CXXFLAGS_$(CONFIG))
Craig Tiller841c8802015-09-10 13:06:37 -0700241 DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
242 LDFLAGS += $(LDFLAGS_$(CONFIG))
Nicolas "Pixel" Noble482d7612015-07-16 23:43:30 +0200243
Craig Tiller841c8802015-09-10 13:06:37 -0700244 ifneq ($(SYSTEM),MINGW32)
245 PIC_CPPFLAGS = -fPIC
246 CPPFLAGS += -fPIC
247 LDFLAGS += -fPIC
248 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800249
Craig Tiller841c8802015-09-10 13:06:37 -0700250 INCLUDES = . include $(GENDIR)
251 LDFLAGS += -Llibs/$(CONFIG)
Nicolas "Pixel" Noble3adab742015-06-02 00:33:06 +0200252
Craig Tiller841c8802015-09-10 13:06:37 -0700253 ifeq ($(SYSTEM),Darwin)
254 ifneq ($(wildcard /usr/local/ssl/include),)
255 INCLUDES += /usr/local/ssl/include
256 endif
257 ifneq ($(wildcard /opt/local/include),)
258 INCLUDES += /opt/local/include
259 endif
260 ifneq ($(wildcard /usr/local/include),)
261 INCLUDES += /usr/local/include
262 endif
263 LIBS = m z
264 ifneq ($(wildcard /usr/local/ssl/lib),)
265 LDFLAGS += -L/usr/local/ssl/lib
266 endif
267 ifneq ($(wildcard /opt/local/lib),)
268 LDFLAGS += -L/opt/local/lib
269 endif
270 ifneq ($(wildcard /usr/local/lib),)
271 LDFLAGS += -L/usr/local/lib
272 endif
273 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700274
Craig Tiller841c8802015-09-10 13:06:37 -0700275 ifeq ($(SYSTEM),Linux)
Craig Tiller1b1e2382016-02-03 07:33:56 -0800276 LIBS = dl rt m pthread
Craig Tiller841c8802015-09-10 13:06:37 -0700277 LDFLAGS += -pthread
278 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800279
Craig Tiller841c8802015-09-10 13:06:37 -0700280 ifeq ($(SYSTEM),MINGW32)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100281 LIBS = m pthread ws2_32
Craig Tiller841c8802015-09-10 13:06:37 -0700282 LDFLAGS += -pthread
283 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700284
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700285 #
286 # The steps for cross-compiling are as follows:
287 # First, clone and make install of grpc using the native compilers for the host.
288 # Also, install protoc (e.g., from a package like apt-get)
289 # Then clone a fresh grpc for the actual cross-compiled build
290 # Set the environment variable GRPC_CROSS_COMPILE to true
291 # Set CC, CXX, LD, LDXX, AR, and STRIP to the cross-compiling binaries
292 # Also set PROTOBUF_CONFIG_OPTS to indicate cross-compilation to protobuf (e.g.,
293 # PROTOBUF_CONFIG_OPTS="--host=arm-linux --with-protoc=/usr/local/bin/protoc" )
294 # Set HAS_PKG_CONFIG=false
295 # To build tests, go to third_party/gflags and follow its ccmake instructions
296 # Make sure that you enable building shared libraries and set your prefix to
297 # something useful like /usr/local/cross
298 # You will also need to set GRPC_CROSS_LDOPTS and GRPC_CROSS_AROPTS to hold
299 # additional required arguments for LD and AR (examples below)
300 # Then you can do a make from the cross-compiling fresh clone!
301 #
302 ifeq ($(GRPC_CROSS_COMPILE),true)
303 LDFLAGS += $(GRPC_CROSS_LDOPTS) # e.g. -L/usr/local/lib -L/usr/local/cross/lib
304 AROPTS = $(GRPC_CROSS_AROPTS) # e.g., rc --target=elf32-little
305 USE_BUILT_PROTOC = false
306 endif
307
Craig Tiller841c8802015-09-10 13:06:37 -0700308 GTEST_LIB = -Ithird_party/googletest/include -Ithird_party/googletest third_party/googletest/src/gtest-all.cc
309 GTEST_LIB += -lgflags
310 ifeq ($(V),1)
311 E = @:
312 Q =
313 else
314 E = @echo
315 Q = @
316 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800317
Craig Tillerf008f062016-02-08 12:48:03 -0800318 VERSION = ${settings.core_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
Craig Tiller841c8802015-09-10 13:06:37 -0700327 HOST_CPPFLAGS = $(CPPFLAGS)
328 HOST_CFLAGS = $(CFLAGS)
329 HOST_CXXFLAGS = $(CXXFLAGS)
330 HOST_LDFLAGS = $(LDFLAGS)
331 HOST_LDLIBS = $(LDLIBS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800332
Craig Tiller841c8802015-09-10 13:06:37 -0700333 # These are automatically computed variables.
334 # There shouldn't be any need to change anything from now on.
nnoble69ac39f2014-12-12 15:43:38 -0800335
Craig Tiller841c8802015-09-10 13:06:37 -0700336 -include cache.mk
murgatroid9924e2f4a2015-06-29 11:12:01 -0700337
Craig Tiller841c8802015-09-10 13:06:37 -0700338 CACHE_MK =
murgatroid99aa521572015-07-10 14:49:12 -0700339
Craig Tiller841c8802015-09-10 13:06:37 -0700340 HAS_PKG_CONFIG ?= $(shell command -v $(PKG_CONFIG) >/dev/null 2>&1 && echo true || echo false)
murgatroid99aa521572015-07-10 14:49:12 -0700341
Craig Tiller841c8802015-09-10 13:06:37 -0700342 ifeq ($(HAS_PKG_CONFIG), true)
343 CACHE_MK += HAS_PKG_CONFIG = true,
344 endif
nnoble69ac39f2014-12-12 15:43:38 -0800345
Craig Tiller841c8802015-09-10 13:06:37 -0700346 PC_TEMPLATE = prefix=$(prefix),\
347 exec_prefix=${'\$${prefix}'},\
348 includedir=${'\$${prefix}'}/include,\
349 libdir=${'\$${exec_prefix}'}/lib,\
350 ,\
351 Name: $(PC_NAME),\
352 Description: $(PC_DESCRIPTION),\
353 Version: $(VERSION),\
354 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
355 Requires.private: $(PC_REQUIRES_PRIVATE),\
356 Libs: -L${'\$${libdir}'} $(PC_LIB),\
357 Libs.private: $(PC_LIBS_PRIVATE)
murgatroid998faab232015-06-30 17:24:21 -0700358
Craig Tiller841c8802015-09-10 13:06:37 -0700359 ifeq ($(SYSTEM),MINGW32)
360 SHARED_EXT = dll
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100361 SHARED_PREFIX =
Craig Tillerf008f062016-02-08 12:48:03 -0800362 SHARED_VERSION = -${settings.core_version.major}
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100363 else ifeq ($(SYSTEM),Darwin)
Craig Tiller841c8802015-09-10 13:06:37 -0700364 SHARED_EXT = dylib
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100365 SHARED_PREFIX = lib
366 SHARED_VERSION =
367 else
Craig Tiller841c8802015-09-10 13:06:37 -0700368 SHARED_EXT = so.$(VERSION)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100369 SHARED_PREFIX = lib
370 SHARED_VERSION =
Craig Tiller841c8802015-09-10 13:06:37 -0700371 endif
nnoble5b7f32a2014-12-22 08:12:44 -0800372
Craig Tiller841c8802015-09-10 13:06:37 -0700373 ifeq ($(wildcard .git),)
374 IS_GIT_FOLDER = false
375 else
376 IS_GIT_FOLDER = true
377 endif
nnoble69ac39f2014-12-12 15:43:38 -0800378
Craig Tiller841c8802015-09-10 13:06:37 -0700379 ifeq ($(HAS_PKG_CONFIG),true)
380 OPENSSL_ALPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.2 openssl
381 OPENSSL_NPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.1 openssl
382 ZLIB_CHECK_CMD = $(PKG_CONFIG) --exists zlib
383 PROTOBUF_CHECK_CMD = $(PKG_CONFIG) --atleast-version=3.0.0-alpha-3 protobuf
384 else # HAS_PKG_CONFIG
murgatroid9924e2f4a2015-06-29 11:12:01 -0700385
Craig Tiller841c8802015-09-10 13:06:37 -0700386 ifeq ($(SYSTEM),MINGW32)
387 OPENSSL_LIBS = ssl32 eay32
388 else
389 OPENSSL_LIBS = ssl crypto
390 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700391
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100392 OPENSSL_ALPN_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
393 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 -0800394 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 +0100395 ZLIB_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
396 PROTOBUF_CHECK_CMD = $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
Craig Tiller297fafa2015-01-15 15:46:39 -0800397
Craig Tiller841c8802015-09-10 13:06:37 -0700398 endif # HAS_PKG_CONFIG
murgatroid9924e2f4a2015-06-29 11:12:01 -0700399
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100400 PERFTOOLS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
murgatroid996d9e4012015-07-08 10:22:45 -0700401
Craig Tiller841c8802015-09-10 13:06:37 -0700402 PROTOC_CHECK_CMD = which protoc > /dev/null
403 PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3
404 DTRACE_CHECK_CMD = which dtrace > /dev/null
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100405 SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS)
murgatroid9924e2f4a2015-06-29 11:12:01 -0700406
Craig Tiller841c8802015-09-10 13:06:37 -0700407 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
408 HAS_SYSTEM_PERFTOOLS ?= $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
409 ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
410 DEFINES += GRPC_HAVE_PERFTOOLS
411 LIBS += profiler
412 CACHE_MK += HAS_SYSTEM_PERFTOOLS = true,
413 endif
414 endif
nnoble69ac39f2014-12-12 15:43:38 -0800415
Craig Tiller841c8802015-09-10 13:06:37 -0700416 HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
417 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
418 HAS_SYSTEM_OPENSSL_ALPN ?= $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
419 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
420 HAS_SYSTEM_OPENSSL_NPN = true
421 CACHE_MK += HAS_SYSTEM_OPENSSL_ALPN = true,
422 else
423 HAS_SYSTEM_OPENSSL_NPN ?= $(shell $(OPENSSL_NPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
424 endif
425 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
426 CACHE_MK += HAS_SYSTEM_OPENSSL_NPN = true,
427 endif
428 HAS_SYSTEM_ZLIB ?= $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
429 ifeq ($(HAS_SYSTEM_ZLIB),true)
430 CACHE_MK += HAS_SYSTEM_ZLIB = true,
431 endif
432 HAS_SYSTEM_PROTOBUF ?= $(HAS_SYSTEM_PROTOBUF_VERIFY)
433 ifeq ($(HAS_SYSTEM_PROTOBUF),true)
434 CACHE_MK += HAS_SYSTEM_PROTOBUF = true,
435 endif
436 else
437 # override system libraries if the config requires a custom compiled library
438 HAS_SYSTEM_OPENSSL_ALPN = false
439 HAS_SYSTEM_OPENSSL_NPN = false
440 HAS_SYSTEM_ZLIB = false
441 HAS_SYSTEM_PROTOBUF = false
442 endif
nnoble69ac39f2014-12-12 15:43:38 -0800443
Craig Tiller841c8802015-09-10 13:06:37 -0700444 HAS_PROTOC ?= $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
445 ifeq ($(HAS_PROTOC),true)
446 CACHE_MK += HAS_PROTOC = true,
447 HAS_VALID_PROTOC ?= $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false)
448 ifeq ($(HAS_VALID_PROTOC),true)
449 CACHE_MK += HAS_VALID_PROTOC = true,
450 endif
451 else
452 HAS_VALID_PROTOC = false
453 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800454
Craig Tiller841c8802015-09-10 13:06:37 -0700455 # Check for Systemtap (https://sourceware.org/systemtap/), first by making sure <sys/sdt.h> is present
456 # in the system and secondly by checking for the "dtrace" binary (on Linux, this is part of the Systemtap
457 # distribution. It's part of the base system on BSD/Solaris machines).
458 ifndef HAS_SYSTEMTAP
459 HAS_SYSTEMTAP_HEADERS = $(shell $(SYSTEMTAP_HEADERS_CHECK_CMD) 2> /dev/null && echo true || echo false)
460 HAS_DTRACE = $(shell $(DTRACE_CHECK_CMD) 2> /dev/null && echo true || echo false)
461 HAS_SYSTEMTAP = false
462 ifeq ($(HAS_SYSTEMTAP_HEADERS),true)
463 ifeq ($(HAS_DTRACE),true)
464 HAS_SYSTEMTAP = true
465 endif
466 endif
467 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -0700468
Craig Tiller841c8802015-09-10 13:06:37 -0700469 ifeq ($(HAS_SYSTEMTAP),true)
470 CACHE_MK += HAS_SYSTEMTAP = true,
471 endif
nnoble69ac39f2014-12-12 15:43:38 -0800472
Craig Tiller841c8802015-09-10 13:06:37 -0700473 # Note that for testing purposes, one can do:
474 # make HAS_EMBEDDED_OPENSSL_ALPN=false
475 # to emulate the fact we do not have OpenSSL in the third_party folder.
Craig Tillerb79c1e12016-02-23 10:00:58 -0800476 ifneq ($(wildcard third_party/${openssl_fallback.extraction_dir}/libssl.a),)
477 HAS_EMBEDDED_OPENSSL_ALPN = third_party/${openssl_fallback.extraction_dir}
478 else ifeq ($(wildcard third_party/boringssl/include/openssl/ssl.h),)
Craig Tiller841c8802015-09-10 13:06:37 -0700479 HAS_EMBEDDED_OPENSSL_ALPN = false
480 else
Craig Tillerb79c1e12016-02-23 10:00:58 -0800481 CAN_COMPILE_EMBEDDED_OPENSSL ?= $(shell $(BORINGSSL_COMPILE_CHECK_CMD) 2> /dev/null && echo true || echo false)
482 HAS_EMBEDDED_OPENSSL_ALPN = $(CAN_COMPILE_EMBEDDED_OPENSSL)
Craig Tiller841c8802015-09-10 13:06:37 -0700483 endif
nnoble69ac39f2014-12-12 15:43:38 -0800484
Craig Tiller841c8802015-09-10 13:06:37 -0700485 ifeq ($(wildcard third_party/zlib/zlib.h),)
486 HAS_EMBEDDED_ZLIB = false
487 else
488 HAS_EMBEDDED_ZLIB = true
489 endif
nnoble69ac39f2014-12-12 15:43:38 -0800490
Craig Tiller841c8802015-09-10 13:06:37 -0700491 ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
492 HAS_EMBEDDED_PROTOBUF = false
493 ifneq ($(HAS_VALID_PROTOC),true)
494 NO_PROTOC = true
495 endif
496 else
497 HAS_EMBEDDED_PROTOBUF = true
498 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800499
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100500 PC_REQUIRES_GRPC =
Craig Tiller841c8802015-09-10 13:06:37 -0700501 PC_LIBS_GRPC =
murgatroid998faab232015-06-30 17:24:21 -0700502
Craig Tiller841c8802015-09-10 13:06:37 -0700503 ifeq ($(HAS_SYSTEM_ZLIB),false)
Craig Tiller3dca23a2016-01-21 11:44:55 -0800504 ifeq ($(HAS_EMBEDDED_ZLIB), true)
505 EMBED_ZLIB ?= true
Craig Tiller841c8802015-09-10 13:06:37 -0700506 else
507 DEP_MISSING += zlib
Craig Tiller3dca23a2016-01-21 11:44:55 -0800508 EMBED_ZLIB ?= broken
Craig Tiller841c8802015-09-10 13:06:37 -0700509 endif
510 else
Craig Tiller3dca23a2016-01-21 11:44:55 -0800511 EMBED_ZLIB ?= false
512 endif
513
514 ifeq ($(EMBED_ZLIB),true)
515 ZLIB_DEP = $(LIBDIR)/$(CONFIG)/libz.a
516 ZLIB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libz.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +0100517 ZLIB_MERGE_OBJS = $(LIBZ_OBJS)
Craig Tiller3dca23a2016-01-21 11:44:55 -0800518 CPPFLAGS += -Ithird_party/zlib
519 LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib
520 else
Craig Tiller841c8802015-09-10 13:06:37 -0700521 ifeq ($(HAS_PKG_CONFIG),true)
522 CPPFLAGS += $(shell $(PKG_CONFIG) --cflags zlib)
523 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L zlib)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800524 LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l zlib))
Craig Tiller841c8802015-09-10 13:06:37 -0700525 PC_REQUIRES_GRPC += zlib
526 else
527 PC_LIBS_GRPC += -lz
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800528 LIBS += z
Craig Tiller841c8802015-09-10 13:06:37 -0700529 endif
530 endif
nnoble69ac39f2014-12-12 15:43:38 -0800531
Craig Tiller841c8802015-09-10 13:06:37 -0700532 OPENSSL_PKG_CONFIG = false
murgatroid99da7a9942015-06-29 14:57:37 -0700533
Craig Tiller841c8802015-09-10 13:06:37 -0700534 PC_REQUIRES_SECURE =
535 PC_LIBS_SECURE =
murgatroid998faab232015-06-30 17:24:21 -0700536
Craig Tiller841c8802015-09-10 13:06:37 -0700537 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800538 EMBED_OPENSSL ?= false
539 NO_SECURE ?= false
540 else # HAS_SYSTEM_OPENSSL_ALPN=false
Craig Tillerb79c1e12016-02-23 10:00:58 -0800541 ifneq ($(HAS_EMBEDDED_OPENSSL_ALPN),false)
542 EMBED_OPENSSL ?= $(HAS_EMBEDDED_OPENSSL_ALPN)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800543 NO_SECURE ?= false
544 else # HAS_EMBEDDED_OPENSSL_ALPN=false
545 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
546 EMBED_OPENSSL ?= false
547 NO_SECURE ?= false
548 else
549 NO_SECURE ?= true
550 endif # HAS_SYSTEM_OPENSSL_NPN=true
551 endif # HAS_EMBEDDED_OPENSSL_ALPN
552 endif # HAS_SYSTEM_OPENSSL_ALPN
553
554 OPENSSL_DEP :=
555 OPENSSL_MERGE_LIBS :=
556 ifeq ($(NO_SECURE),false)
557 ifeq ($(EMBED_OPENSSL),true)
558 OPENSSL_DEP += $(LIBDIR)/$(CONFIG)/libboringssl.a
559 OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/libboringssl.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +0100560 OPENSSL_MERGE_OBJS += $(LIBBORINGSSL_OBJS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800561 # need to prefix these to ensure overriding system libraries
562 CPPFLAGS := -Ithird_party/boringssl/include $(CPPFLAGS)
Craig Tillerb79c1e12016-02-23 10:00:58 -0800563 else ifneq ($(EMBED_OPENSSL),false)
564 OPENSSL_DEP += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
565 OPENSSL_MERGE_LIBS += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
566 OPENSSL_MERGE_OBJS += $(wildcard $(EMBED_OPENSSL)/grpc_obj/*.o)
567 # need to prefix these to ensure overriding system libraries
568 CPPFLAGS := -I$(EMBED_OPENSSL)/include $(CPPFLAGS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800569 else # EMBED_OPENSSL=false
Craig Tiller841c8802015-09-10 13:06:37 -0700570 ifeq ($(HAS_PKG_CONFIG),true)
571 OPENSSL_PKG_CONFIG = true
572 PC_REQUIRES_SECURE = openssl
573 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags openssl) $(CPPFLAGS)
574 LDFLAGS_OPENSSL_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L openssl)
575 ifeq ($(SYSTEM),Linux)
576 ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),)
577 LDFLAGS_OPENSSL_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L openssl | sed s/L/Wl,-rpath,/)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800578 endif # LDFLAGS_OPENSSL_PKG_CONFIG=''
579 endif # System=Linux
Craig Tiller841c8802015-09-10 13:06:37 -0700580 LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800581 else # HAS_PKG_CONFIG=false
Craig Tiller841c8802015-09-10 13:06:37 -0700582 LIBS_SECURE = $(OPENSSL_LIBS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800583 endif # HAS_PKG_CONFIG
584 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
585 CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0
586 LIBS_SECURE = $(OPENSSL_LIBS)
587 endif # HAS_SYSTEM_OPENSSL_NPN
Craig Tiller841c8802015-09-10 13:06:37 -0700588 PC_LIBS_SECURE = $(addprefix -l, $(LIBS_SECURE))
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800589 endif # EMBED_OPENSSL
590 endif # NO_SECURE
nnoble69ac39f2014-12-12 15:43:38 -0800591
Craig Tiller841c8802015-09-10 13:06:37 -0700592 ifeq ($(OPENSSL_PKG_CONFIG),true)
593 LDLIBS_SECURE += $(shell $(PKG_CONFIG) --libs-only-l openssl)
594 else
595 LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
596 endif
nnoble5b7f32a2014-12-22 08:12:44 -0800597
Craig Tiller841c8802015-09-10 13:06:37 -0700598 # grpc .pc file
599 PC_NAME = gRPC
Craig Tillerda179ce2016-02-09 12:01:53 -0800600 PC_DESCRIPTION = high performance general RPC framework
601 PC_CFLAGS =
602 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC) $(PC_REQUIRES_SECURE)
Craig Tiller841c8802015-09-10 13:06:37 -0700603 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) $(PC_LIBS_SECURE)
604 PC_LIB = -lgrpc
605 GRPC_PC_FILE := $(PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700606
Craig Tiller4a67be42016-02-09 12:40:32 -0800607 # grpc_unsecure .pc file
Craig Tiller841c8802015-09-10 13:06:37 -0700608 PC_NAME = gRPC unsecure
Craig Tillerda179ce2016-02-09 12:01:53 -0800609 PC_DESCRIPTION = high performance general RPC framework without SSL
610 PC_CFLAGS =
611 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC)
Craig Tiller841c8802015-09-10 13:06:37 -0700612 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC)
613 PC_LIB = -lgrpc
614 GRPC_UNSECURE_PC_FILE := $(PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700615
Craig Tiller841c8802015-09-10 13:06:37 -0700616 PROTOBUF_PKG_CONFIG = false
murgatroid99da7a9942015-06-29 14:57:37 -0700617
Craig Tiller841c8802015-09-10 13:06:37 -0700618 PC_REQUIRES_GRPCXX =
619 PC_LIBS_GRPCXX =
murgatroid998faab232015-06-30 17:24:21 -0700620
Craig Tiller841c8802015-09-10 13:06:37 -0700621 CPPFLAGS := -Ithird_party/googletest/include $(CPPFLAGS)
Craig Tiller16f6dac2015-08-24 17:00:04 -0700622
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700623 PROTOC_PLUGINS_ALL =\
624 % for tgt in targets:
625 % if tgt.build == 'protoc':
626 $(BINDIR)/$(CONFIG)/${tgt.name}\
627 % endif
628 % endfor
629
630 PROTOC_PLUGINS_DIR = $(BINDIR)/$(CONFIG)
631
Craig Tiller841c8802015-09-10 13:06:37 -0700632 ifeq ($(HAS_SYSTEM_PROTOBUF),true)
633 ifeq ($(HAS_PKG_CONFIG),true)
634 PROTOBUF_PKG_CONFIG = true
635 PC_REQUIRES_GRPCXX = protobuf
636 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags protobuf) $(CPPFLAGS)
637 LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L protobuf)
638 ifeq ($(SYSTEM),Linux)
639 ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),)
640 LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L protobuf | sed s/L/Wl,-rpath,/)
641 endif
642 endif
643 else
644 PC_LIBS_GRPCXX = -lprotobuf
645 endif
Nicolas "Pixel" Noblef7fbdd42016-07-25 20:31:22 +0200646 PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
Craig Tiller841c8802015-09-10 13:06:37 -0700647 else
648 ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
649 PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
650 CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
651 LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700652 ifneq ($(USE_BUILT_PROTOC),false)
Craig Tiller841c8802015-09-10 13:06:37 -0700653 PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700654 PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
655 else
656 PROTOC_PLUGINS =
657 PROTOC_PLUGINS_DIR = $(prefix)/bin
658 endif
Craig Tiller841c8802015-09-10 13:06:37 -0700659 else
660 NO_PROTOBUF = true
661 endif
662 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800663
Craig Tiller841c8802015-09-10 13:06:37 -0700664 LIBS_PROTOBUF = protobuf
665 LIBS_PROTOC = protoc protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800666
Craig Tiller841c8802015-09-10 13:06:37 -0700667 HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
Nicolas Noble53830622015-02-12 16:56:38 -0800668
Craig Tiller841c8802015-09-10 13:06:37 -0700669 ifeq ($(PROTOBUF_PKG_CONFIG),true)
670 LDLIBS_PROTOBUF += $(shell $(PKG_CONFIG) --libs-only-l protobuf)
671 else
672 LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
673 endif
murgatroid9924e2f4a2015-06-29 11:12:01 -0700674
Craig Tiller841c8802015-09-10 13:06:37 -0700675 # grpc++ .pc file
676 PC_NAME = gRPC++
677 PC_DESCRIPTION = C++ wrapper for gRPC
678 PC_CFLAGS =
679 PC_REQUIRES_PRIVATE = grpc $(PC_REQUIRES_GRPCXX)
680 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
681 PC_LIB = -lgrpc++
682 GRPCXX_PC_FILE := $(PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700683
Craig Tiller841c8802015-09-10 13:06:37 -0700684 # grpc++_unsecure .pc file
685 PC_NAME = gRPC++ unsecure
686 PC_DESCRIPTION = C++ wrapper for gRPC without SSL
687 PC_CFLAGS =
688 PC_REQUIRES_PRIVATE = grpc_unsecure $(PC_REQUIRES_GRPCXX)
689 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
690 PC_LIB = -lgrpc++
691 GRPCXX_UNSECURE_PC_FILE := $(PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700692
Craig Tiller841c8802015-09-10 13:06:37 -0700693 ifeq ($(MAKECMDGOALS),clean)
694 NO_DEPS = true
695 endif
nnoble69ac39f2014-12-12 15:43:38 -0800696
Craig Tiller841c8802015-09-10 13:06:37 -0700697 INSTALL_OK = false
698 ifeq ($(HAS_VALID_PROTOC),true)
699 ifeq ($(HAS_SYSTEM_PROTOBUF_VERIFY),true)
700 INSTALL_OK = true
701 endif
702 endif
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100703
Craig Tiller841c8802015-09-10 13:06:37 -0700704 .SECONDARY = %.pb.h %.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800705
Craig Tiller841c8802015-09-10 13:06:37 -0700706 ifeq ($(DEP_MISSING),)
707 all: static shared plugins\
708 % for tgt in targets:
709 % if tgt.build == 'all':
710 $(BINDIR)/$(CONFIG)/${tgt.name}\
711 % endif
712 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800713
Craig Tiller841c8802015-09-10 13:06:37 -0700714 dep_error:
715 @echo "You shouldn't see this message - all of your dependencies are correct."
716 else
717 all: dep_error git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800718
Craig Tiller841c8802015-09-10 13:06:37 -0700719 dep_error:
720 @echo
721 @echo "DEPENDENCY ERROR"
722 @echo
723 @echo "You are missing system dependencies that are essential to build grpc,"
724 @echo "and the third_party directory doesn't have them:"
725 @echo
726 @echo " $(DEP_MISSING)"
727 @echo
728 @echo "Installing the development packages for your system will solve"
729 @echo "this issue. Please consult INSTALL to get more information."
730 @echo
731 @echo "If you need information about why these tests failed, run:"
732 @echo
733 @echo " make run_dep_checks"
734 @echo
735 endif
nnoble69ac39f2014-12-12 15:43:38 -0800736
Craig Tiller841c8802015-09-10 13:06:37 -0700737 git_update:
738 ifeq ($(IS_GIT_FOLDER),true)
739 @echo "Additionally, since you are in a git clone, you can download the"
740 @echo "missing dependencies in third_party by running the following command:"
741 @echo
742 @echo " git submodule update --init"
743 @echo
744 endif
nnoble69ac39f2014-12-12 15:43:38 -0800745
Craig Tiller841c8802015-09-10 13:06:37 -0700746 openssl_dep_error: openssl_dep_message git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800747
Craig Tiller841c8802015-09-10 13:06:37 -0700748 protobuf_dep_error: protobuf_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800749
Craig Tiller841c8802015-09-10 13:06:37 -0700750 protoc_dep_error: protoc_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800751
Craig Tiller841c8802015-09-10 13:06:37 -0700752 openssl_dep_message:
753 @echo
754 @echo "DEPENDENCY ERROR"
755 @echo
Craig Tillerb79c1e12016-02-23 10:00:58 -0800756 @echo "The target you are trying to run requires an OpenSSL implementation."
757 @echo "Your system doesn't have one, and either the third_party directory"
758 @echo "doesn't have it, or your compiler can't build BoringSSL."
Craig Tiller841c8802015-09-10 13:06:37 -0700759 @echo
760 @echo "Please consult INSTALL to get more information."
761 @echo
762 @echo "If you need information about why these tests failed, run:"
763 @echo
764 @echo " make run_dep_checks"
765 @echo
nnoble69ac39f2014-12-12 15:43:38 -0800766
Craig Tiller841c8802015-09-10 13:06:37 -0700767 protobuf_dep_message:
768 @echo
769 @echo "DEPENDENCY ERROR"
770 @echo
771 @echo "The target you are trying to run requires protobuf 3.0.0+"
772 @echo "Your system doesn't have it, and neither does the third_party directory."
773 @echo
774 @echo "Please consult INSTALL to get more information."
775 @echo
776 @echo "If you need information about why these tests failed, run:"
777 @echo
778 @echo " make run_dep_checks"
779 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800780
Craig Tiller841c8802015-09-10 13:06:37 -0700781 protoc_dep_message:
782 @echo
783 @echo "DEPENDENCY ERROR"
784 @echo
785 @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
786 @echo "Your system doesn't have it, and neither does the third_party directory."
787 @echo
788 @echo "Please consult INSTALL to get more information."
789 @echo
790 @echo "If you need information about why these tests failed, run:"
791 @echo
792 @echo " make run_dep_checks"
793 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800794
Craig Tiller841c8802015-09-10 13:06:37 -0700795 systemtap_dep_error:
796 @echo
797 @echo "DEPENDENCY ERROR"
798 @echo
799 @echo "Under the '$(CONFIG)' configutation, the target you are trying "
800 @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other "
801 @echo "platforms such as Solaris and *BSD). "
802 @echo
803 @echo "Please consult INSTALL to get more information."
804 @echo
David Garcia Quintas8954e902015-04-29 09:46:33 -0700805
Craig Tiller841c8802015-09-10 13:06:37 -0700806 stop:
807 @false
nnoble69ac39f2014-12-12 15:43:38 -0800808
Craig Tiller841c8802015-09-10 13:06:37 -0700809 % for tgt in targets:
810 ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
811 % endfor
ctiller09cb6d52014-12-19 17:38:22 -0800812
Craig Tiller841c8802015-09-10 13:06:37 -0700813 run_dep_checks:
814 $(OPENSSL_ALPN_CHECK_CMD) || true
815 $(OPENSSL_NPN_CHECK_CMD) || true
816 $(ZLIB_CHECK_CMD) || true
817 $(PERFTOOLS_CHECK_CMD) || true
818 $(PROTOBUF_CHECK_CMD) || true
819 $(PROTOC_CHECK_VERSION_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800820
Craig Tiller841c8802015-09-10 13:06:37 -0700821 third_party/protobuf/configure:
822 $(E) "[AUTOGEN] Preparing protobuf"
823 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
Nicolas Noble53830622015-02-12 16:56:38 -0800824
Craig Tiller841c8802015-09-10 13:06:37 -0700825 $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
826 $(E) "[MAKE] Building protobuf"
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700827 $(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 -0700828 $(Q)$(MAKE) -C third_party/protobuf clean
829 $(Q)$(MAKE) -C third_party/protobuf
830 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
831 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
832 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
833 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
834 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800835
Craig Tiller841c8802015-09-10 13:06:37 -0700836 static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800837
Craig Tillereda85c62016-07-01 12:45:19 -0700838 static_c: pc_c pc_c_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700839 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100840 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700841 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
842 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
843 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100844 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700845 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800846
847
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100848 static_cxx: pc_cxx pc_cxx_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700849 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100850 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700851 % if lib.build == 'all' and lib.language == 'c++':
852 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
853 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100854 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700855 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800856
857
Craig Tiller841c8802015-09-10 13:06:37 -0700858 shared: shared_c shared_cxx
nnoble29e1d292014-12-01 10:27:40 -0800859
Craig Tillereda85c62016-07-01 12:45:19 -0700860 shared_c: pc_c pc_c_unsecure cache.mk\
Craig Tiller841c8802015-09-10 13:06:37 -0700861 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100862 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700863 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100864 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)\
Craig Tiller841c8802015-09-10 13:06:37 -0700865 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100866 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700867 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800868
Craig Tiller841c8802015-09-10 13:06:37 -0700869 shared_cxx: pc_cxx pc_cxx_unsecure cache.mk\
870 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100871 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700872 % if lib.build == 'all' and lib.language == 'c++':
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100873 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)\
Craig Tiller841c8802015-09-10 13:06:37 -0700874 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100875 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700876 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800877
878
Craig Tiller841c8802015-09-10 13:06:37 -0700879 shared_csharp: shared_c \
880 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100881 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700882 % if lib.build == 'all' and lib.language == 'csharp':
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100883 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)\
Craig Tiller841c8802015-09-10 13:06:37 -0700884 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100885 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700886 % endfor
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800887
Craig Tiller841c8802015-09-10 13:06:37 -0700888 grpc_csharp_ext: shared_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800889
Craig Tiller841c8802015-09-10 13:06:37 -0700890 plugins: $(PROTOC_PLUGINS)
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100891
Craig Tiller841c8802015-09-10 13:06:37 -0700892 privatelibs: privatelibs_c privatelibs_cxx
nnoble29e1d292014-12-01 10:27:40 -0800893
Craig Tiller841c8802015-09-10 13:06:37 -0700894 privatelibs_c: \
895 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100896 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800897 % 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 -0700898 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
899 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100900 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700901 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800902
Craig Tiller841c8802015-09-10 13:06:37 -0700903 pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc
murgatroid998faab232015-06-30 17:24:21 -0700904
Craig Tiller841c8802015-09-10 13:06:37 -0700905 pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -0700906
Craig Tiller841c8802015-09-10 13:06:37 -0700907 pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc
murgatroid998faab232015-06-30 17:24:21 -0700908
Craig Tiller841c8802015-09-10 13:06:37 -0700909 pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800910
vjpai20410922016-06-15 09:21:42 -0700911 ifeq ($(EMBED_OPENSSL),true)
Craig Tiller841c8802015-09-10 13:06:37 -0700912 privatelibs_cxx: \
913 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100914 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700915 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None):
916 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
917 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100918 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700919 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -0700920
vjpai20410922016-06-15 09:21:42 -0700921 else
922 privatelibs_cxx: \
923 % for lib in libs:
924 % if 'Makefile' in lib.get('build_system', ['Makefile']):
925 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None) and not lib.boringssl:
926 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
927 % endif
928 % endif
929 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -0700930
vjpai20410922016-06-15 09:21:42 -0700931 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800932
933
Craig Tillereda85c62016-07-01 12:45:19 -0700934 buildtests: buildtests_c buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -0800935
Craig Tiller3824b6e2015-12-09 11:19:59 -0800936 buildtests_c: privatelibs_c <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700937 % for tgt in targets:
938 % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -0800939 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700940 % endif
941 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800942
943
vjpai20410922016-06-15 09:21:42 -0700944 ifeq ($(EMBED_OPENSSL),true)
Craig Tillereda85c62016-07-01 12:45:19 -0700945 buildtests_cxx: privatelibs_cxx <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700946 % for tgt in targets:
947 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -0800948 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700949 % endif
950 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -0700951
vjpai20410922016-06-15 09:21:42 -0700952 else
Craig Tillereda85c62016-07-01 12:45:19 -0700953 buildtests_cxx: privatelibs_cxx <%text>\</%text>
vjpai20410922016-06-15 09:21:42 -0700954 % for tgt in targets:
955 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl:
956 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
957 % endif
958 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -0700959
vjpai20410922016-06-15 09:21:42 -0700960 endif
nnoble29e1d292014-12-01 10:27:40 -0800961
962
Craig Tillereda85c62016-07-01 12:45:19 -0700963 test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -0800964
Craig Tillereda85c62016-07-01 12:45:19 -0700965 flaky_test: flaky_test_c flaky_test_cxx
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +0200966
Craig Tiller841c8802015-09-10 13:06:37 -0700967 test_c: buildtests_c
968 % for tgt in targets:
969 % 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):
970 $(E) "[RUN] Testing ${tgt.name}"
971 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
972 % endif
973 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +0200974
975
Craig Tiller841c8802015-09-10 13:06:37 -0700976 flaky_test_c: buildtests_c
977 % for tgt in targets:
978 % 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):
979 $(E) "[RUN] Testing ${tgt.name}"
980 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
981 % endif
982 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800983
984
Craig Tillereda85c62016-07-01 12:45:19 -0700985 test_cxx: buildtests_cxx
Craig Tiller841c8802015-09-10 13:06:37 -0700986 % for tgt in targets:
987 % 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):
988 $(E) "[RUN] Testing ${tgt.name}"
989 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
990 % endif
991 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +0200992
993
Craig Tiller841c8802015-09-10 13:06:37 -0700994 flaky_test_cxx: buildtests_cxx
995 % for tgt in targets:
996 % 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):
997 $(E) "[RUN] Testing ${tgt.name}"
998 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
999 % endif
1000 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001001
1002
Craig Tiller841c8802015-09-10 13:06:37 -07001003 test_python: static_c
1004 $(E) "[RUN] Testing python code"
1005 $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
Nicolas "Pixel" Noble051a28f2015-03-17 22:54:54 +01001006
1007
Craig Tiller841c8802015-09-10 13:06:37 -07001008 tools: tools_c tools_cxx
Craig Tiller7552f0f2015-06-19 17:46:20 -07001009
1010
Craig Tiller841c8802015-09-10 13:06:37 -07001011 tools_c: privatelibs_c\
1012 % for tgt in targets:
1013 % if tgt.build == 'tool' and not tgt.language=='c++':
1014 $(BINDIR)/$(CONFIG)/${tgt.name}\
1015 % endif
1016 % endfor
Craig Tiller7552f0f2015-06-19 17:46:20 -07001017
1018
Craig Tiller841c8802015-09-10 13:06:37 -07001019 tools_cxx: privatelibs_cxx\
1020 % for tgt in targets:
1021 % if tgt.build == 'tool' and tgt.language=='c++':
1022 $(BINDIR)/$(CONFIG)/${tgt.name}\
1023 % endif
1024 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001025
1026
Craig Tiller841c8802015-09-10 13:06:37 -07001027 buildbenchmarks: privatelibs\
1028 % for tgt in targets:
1029 % if tgt.build == 'benchmark':
1030 $(BINDIR)/$(CONFIG)/${tgt.name}\
1031 % endif
1032 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001033
1034
Craig Tiller841c8802015-09-10 13:06:37 -07001035 benchmarks: buildbenchmarks
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001036
Craig Tiller841c8802015-09-10 13:06:37 -07001037 strip: strip-static strip-shared
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001038
Craig Tiller841c8802015-09-10 13:06:37 -07001039 strip-static: strip-static_c strip-static_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001040
Craig Tiller841c8802015-09-10 13:06:37 -07001041 strip-shared: strip-shared_c strip-shared_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001042
Nicolas Noble047b7272015-01-16 13:55:05 -08001043
Craig Tiller841c8802015-09-10 13:06:37 -07001044 # TODO(nnoble): the strip target is stripping in-place, instead
1045 # of copying files in a temporary folder.
1046 # This prevents proper debugging after running make install.
Nicolas Noble047b7272015-01-16 13:55:05 -08001047
Craig Tiller841c8802015-09-10 13:06:37 -07001048 strip-static_c: static_c
1049 ifeq ($(CONFIG),opt)
1050 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001051 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001052 % if lib.language == "c":
1053 % if lib.build == "all":
1054 % if not lib.get('external_deps', None):
1055 $(E) "[STRIP] Stripping lib${lib.name}.a"
1056 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1057 % endif
1058 % endif
1059 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001060 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001061 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001062 endif
nnoble85a49262014-12-08 18:14:03 -08001063
Craig Tiller841c8802015-09-10 13:06:37 -07001064 strip-static_cxx: static_cxx
1065 ifeq ($(CONFIG),opt)
1066 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001067 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001068 % if lib.language == "c++":
1069 % if lib.build == "all":
1070 $(E) "[STRIP] Stripping lib${lib.name}.a"
1071 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1072 % endif
1073 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001074 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001075 % endfor
1076 endif
Nicolas "Pixel" Noble4ef9b862015-08-14 19:35:24 +02001077
Craig Tiller841c8802015-09-10 13:06:37 -07001078 strip-shared_c: shared_c
1079 ifeq ($(CONFIG),opt)
1080 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001081 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001082 % if lib.language == "c":
1083 % if lib.build == "all":
1084 % if not lib.get('external_deps', None):
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001085 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)"
1086 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)
Craig Tiller841c8802015-09-10 13:06:37 -07001087 % endif
1088 % endif
1089 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001090 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001091 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001092 endif
nnoble85a49262014-12-08 18:14:03 -08001093
Craig Tiller841c8802015-09-10 13:06:37 -07001094 strip-shared_cxx: shared_cxx
1095 ifeq ($(CONFIG),opt)
1096 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001097 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001098 % if lib.language == "c++":
1099 % if lib.build == "all":
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001100 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)"
1101 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)
Craig Tiller841c8802015-09-10 13:06:37 -07001102 % endif
1103 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001104 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001105 % endfor
1106 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001107
Craig Tiller841c8802015-09-10 13:06:37 -07001108 strip-shared_csharp: shared_csharp
1109 ifeq ($(CONFIG),opt)
1110 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001111 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001112 % if lib.language == "csharp":
1113 % if lib.build == "all":
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001114 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)"
1115 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)
Craig Tiller841c8802015-09-10 13:06:37 -07001116 % endif
1117 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001118 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001119 % endfor
1120 endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001121
Craig Tiller841c8802015-09-10 13:06:37 -07001122 cache.mk::
1123 $(E) "[MAKE] Generating $@"
1124 $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@
murgatroid99aa521572015-07-10 14:49:12 -07001125
Craig Tiller841c8802015-09-10 13:06:37 -07001126 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc:
1127 $(E) "[MAKE] Generating $@"
1128 $(Q) mkdir -p $(@D)
1129 $(Q) echo "$(GRPC_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001130
Craig Tiller841c8802015-09-10 13:06:37 -07001131 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc:
1132 $(E) "[MAKE] Generating $@"
1133 $(Q) mkdir -p $(@D)
1134 $(Q) echo "$(GRPC_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001135
Craig Tiller841c8802015-09-10 13:06:37 -07001136 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc:
1137 $(E) "[MAKE] Generating $@"
1138 $(Q) mkdir -p $(@D)
1139 $(Q) echo "$(GRPCXX_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001140
Craig Tiller841c8802015-09-10 13:06:37 -07001141 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc:
1142 $(E) "[MAKE] Generating $@"
1143 $(Q) mkdir -p $(@D)
1144 $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001145
Craig Tiller841c8802015-09-10 13:06:37 -07001146 % for p in protos:
1147 ifeq ($(NO_PROTOC),true)
1148 $(GENDIR)/${p}.pb.cc: protoc_dep_error
1149 $(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error
1150 else
Craig Tiller1b4e3302015-12-17 16:35:00 -08001151 $(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 -07001152 $(E) "[PROTOC] Generating protobuf CC file from $<"
1153 $(Q) mkdir -p `dirname $@`
David Garcia Quintase68ed6f2016-06-17 12:49:14 -07001154 $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --cpp_out=$(GENDIR) $<
Nicolas "Pixel" Noble0caebbf2015-04-09 23:08:51 +02001155
Craig Tiller1b4e3302015-12-17 16:35:00 -08001156 $(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 -07001157 $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
1158 $(Q) mkdir -p `dirname $@`
Vijay Paicc7eb8e2016-07-19 19:03:55 -07001159 $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin $<
Craig Tiller841c8802015-09-10 13:06:37 -07001160 endif
nnoble72309c62014-12-12 11:42:26 -08001161
Craig Tiller841c8802015-09-10 13:06:37 -07001162 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001163
Craig Tiller841c8802015-09-10 13:06:37 -07001164 ifeq ($(CONFIG),stapprof)
1165 src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h
1166 ifeq ($(HAS_SYSTEMTAP),true)
1167 $(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d
1168 $(E) "[DTRACE] Compiling $<"
1169 $(Q) mkdir -p `dirname $@`
1170 $(Q) $(DTRACE) -C -h -s $< -o $@
1171 else
1172 $(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop
1173 endif
1174 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -07001175
Craig Tiller841c8802015-09-10 13:06:37 -07001176 $(OBJDIR)/$(CONFIG)/%.o : %.c
1177 $(E) "[C] Compiling $<"
1178 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001179 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001180
Craig Tiller841c8802015-09-10 13:06:37 -07001181 $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
1182 $(E) "[CXX] Compiling $<"
1183 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001184 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001185
Craig Tiller841c8802015-09-10 13:06:37 -07001186 $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
1187 $(E) "[HOSTCXX] Compiling $<"
1188 $(Q) mkdir -p `dirname $@`
1189 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -08001190
Craig Tiller841c8802015-09-10 13:06:37 -07001191 $(OBJDIR)/$(CONFIG)/%.o : %.cc
1192 $(E) "[CXX] Compiling $<"
1193 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001194 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001195
Craig Tiller841c8802015-09-10 13:06:37 -07001196 install: install_c install_cxx install-plugins install-certs verify-install
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001197
Craig Tiller841c8802015-09-10 13:06:37 -07001198 install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001199
Craig Tiller841c8802015-09-10 13:06:37 -07001200 install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
nnoble85a49262014-12-08 18:14:03 -08001201
Craig Tiller841c8802015-09-10 13:06:37 -07001202 install_csharp: install-shared_csharp install_c
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001203
Craig Tiller841c8802015-09-10 13:06:37 -07001204 install_grpc_csharp_ext: install_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001205
Craig Tiller841c8802015-09-10 13:06:37 -07001206 install-headers: install-headers_c install-headers_cxx
nnoble85a49262014-12-08 18:14:03 -08001207
Craig Tiller841c8802015-09-10 13:06:37 -07001208 install-headers_c:
1209 $(E) "[INSTALL] Installing public C headers"
1210 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1211 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001212
Craig Tiller841c8802015-09-10 13:06:37 -07001213 install-headers_cxx:
1214 $(E) "[INSTALL] Installing public C++ headers"
1215 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1216 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001217
Craig Tiller841c8802015-09-10 13:06:37 -07001218 install-static: install-static_c install-static_cxx
nnoble85a49262014-12-08 18:14:03 -08001219
Craig Tiller841c8802015-09-10 13:06:37 -07001220 install-static_c: static_c strip-static_c install-pkg-config_c
1221 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001222 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001223 % if lib.language == "c":
1224 % if lib.build == "all":
1225 % if not lib.get('external_deps', None):
1226 $(E) "[INSTALL] Installing lib${lib.name}.a"
1227 $(Q) $(INSTALL) -d $(prefix)/lib
1228 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1229 % endif
1230 % endif
1231 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001232 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001233 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001234
Craig Tiller841c8802015-09-10 13:06:37 -07001235 install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx
1236 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001237 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001238 % if lib.language == "c++":
1239 % if lib.build == "all":
1240 $(E) "[INSTALL] Installing lib${lib.name}.a"
1241 $(Q) $(INSTALL) -d $(prefix)/lib
1242 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1243 % endif
1244 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001245 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001246 % endfor
nnoble85a49262014-12-08 18:14:03 -08001247
Craig Tiller841c8802015-09-10 13:06:37 -07001248 <%def name="install_shared(lang_filter)">\
1249 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001250 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001251 % if lib.language == lang_filter:
1252 % if lib.build == "all":
1253 % if not lib.get('external_deps', None):
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001254 $(E) "[INSTALL] Installing $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)"
1255 $(Q) $(INSTALL) -d $(prefix)/lib
1256 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT) $(prefix)/lib/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)
Craig Tiller841c8802015-09-10 13:06:37 -07001257 ifeq ($(SYSTEM),MINGW32)
Craig Tiller841c8802015-09-10 13:06:37 -07001258 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001259 else ifneq ($(SYSTEM),Darwin)
Craig Tillerf008f062016-02-08 12:48:03 -08001260 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so.${settings.core_version.major}
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001261 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
Craig Tiller841c8802015-09-10 13:06:37 -07001262 endif
1263 % endif
1264 % endif
1265 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001266 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001267 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001268 ifneq ($(SYSTEM),MINGW32)
1269 ifneq ($(SYSTEM),Darwin)
1270 $(Q) ldconfig || true
1271 endif
1272 endif
1273 </%def>
nnoble85a49262014-12-08 18:14:03 -08001274
Craig Tiller841c8802015-09-10 13:06:37 -07001275 install-shared_c: shared_c strip-shared_c install-pkg-config_c
1276 ${install_shared("c")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001277
Craig Tiller841c8802015-09-10 13:06:37 -07001278 install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c install-pkg-config_cxx
1279 ${install_shared("c++")}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001280
Craig Tiller841c8802015-09-10 13:06:37 -07001281 install-shared_csharp: shared_csharp strip-shared_csharp
1282 ${install_shared("csharp")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001283
Craig Tiller841c8802015-09-10 13:06:37 -07001284 install-plugins: $(PROTOC_PLUGINS)
1285 ifeq ($(SYSTEM),MINGW32)
1286 $(Q) false
1287 else
1288 $(E) "[INSTALL] Installing grpc protoc plugins"
1289 % for tgt in targets:
1290 % if tgt.build == 'protoc':
1291 $(Q) $(INSTALL) -d $(prefix)/bin
1292 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
1293 % endif
1294 % endfor
1295 endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001296
Craig Tillereda85c62016-07-01 12:45:19 -07001297 install-pkg-config_c: pc_c pc_c_unsecure
Craig Tiller841c8802015-09-10 13:06:37 -07001298 $(E) "[INSTALL] Installing C pkg-config files"
1299 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
Craig Tiller841c8802015-09-10 13:06:37 -07001300 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(prefix)/lib/pkgconfig/grpc.pc
1301 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(prefix)/lib/pkgconfig/grpc_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -07001302
Craig Tiller841c8802015-09-10 13:06:37 -07001303 install-pkg-config_cxx: pc_cxx pc_cxx_unsecure
1304 $(E) "[INSTALL] Installing C++ pkg-config files"
1305 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
1306 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc $(prefix)/lib/pkgconfig/grpc++.pc
1307 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc $(prefix)/lib/pkgconfig/grpc++_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -07001308
Craig Tiller841c8802015-09-10 13:06:37 -07001309 install-certs: etc/roots.pem
1310 $(E) "[INSTALL] Installing root certificates"
1311 $(Q) $(INSTALL) -d $(prefix)/share/grpc
1312 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +01001313
Craig Tiller841c8802015-09-10 13:06:37 -07001314 verify-install:
1315 ifeq ($(INSTALL_OK),true)
1316 @echo "Your system looks ready to go."
1317 @echo
1318 else
murgatroid9973563262016-05-24 13:53:24 -07001319 @echo "Warning: it looks like protoc 3.0.0+ isn't installed on your system,"
1320 @echo "which means that you won't be able to compile .proto files for use"
1321 @echo "with gRPC."
Craig Tiller841c8802015-09-10 13:06:37 -07001322 @echo
murgatroid9973563262016-05-24 13:53:24 -07001323 @echo "If you are just using pre-compiled protocol buffers, or you otherwise"
1324 @echo "have no need to compile .proto files, you can ignore this."
Craig Tiller841c8802015-09-10 13:06:37 -07001325 @echo
murgatroid9973563262016-05-24 13:53:24 -07001326 @echo "If you do need protobuf for some reason, you can download and install"
1327 @echo "it from:"
Craig Tiller841c8802015-09-10 13:06:37 -07001328 @echo
1329 @echo " https://github.com/google/protobuf/releases"
1330 @echo
murgatroid9973563262016-05-24 13:53:24 -07001331 @echo "Once you've done so, you can re-run this check by doing:"
Craig Tiller841c8802015-09-10 13:06:37 -07001332 @echo
1333 @echo " make verify-install"
1334 endif
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +01001335
Craig Tiller841c8802015-09-10 13:06:37 -07001336 clean:
1337 $(E) "[CLEAN] Cleaning build directories."
1338 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001339
1340
Craig Tiller841c8802015-09-10 13:06:37 -07001341 # The various libraries
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001342
Craig Tiller841c8802015-09-10 13:06:37 -07001343 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001344 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001345 ${makelib(lib)}
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001346 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001347 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001348
1349
Craig Tiller841c8802015-09-10 13:06:37 -07001350 # All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001351
Craig Tiller841c8802015-09-10 13:06:37 -07001352 % for tgt in targets:
1353 ${maketarget(tgt)}
1354 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001355
Craig Tiller841c8802015-09-10 13:06:37 -07001356 <%def name="makelib(lib)">
1357 LIB${lib.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001358
Craig Tiller841c8802015-09-10 13:06:37 -07001359 % for src in lib.src:
1360 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001361
Craig Tiller841c8802015-09-10 13:06:37 -07001362 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001363
Craig Tiller841c8802015-09-10 13:06:37 -07001364 % if "public_headers" in lib:
1365 % if lib.language == "c++":
1366 PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001367
Craig Tiller841c8802015-09-10 13:06:37 -07001368 % else:
1369 PUBLIC_HEADERS_C += \\
nnoble85a49262014-12-08 18:14:03 -08001370
Craig Tiller841c8802015-09-10 13:06:37 -07001371 % endif
1372 % for hdr in lib.public_headers:
1373 ${hdr} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001374
Craig Tiller841c8802015-09-10 13:06:37 -07001375 % endfor
1376 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001377
Craig Tiller841c8802015-09-10 13:06:37 -07001378 LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001379
Nicolas "Pixel" Noble51b1aee2016-01-28 01:14:58 +01001380 % if lib.get('defaults', None):
1381 % for name, value in defaults.get(lib.defaults).iteritems():
1382 $(LIB${lib.name.upper()}_OBJS): ${name} += ${value}
1383 % endfor
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001384 % endif
1385
Craig Tiller841c8802015-09-10 13:06:37 -07001386 ## If the library requires OpenSSL, let's add some restrictions.
1387 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1388 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001389
Craig Tiller841c8802015-09-10 13:06:37 -07001390 # You can't build secure libraries if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001391
Craig Tiller841c8802015-09-10 13:06:37 -07001392 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001393
Craig Tiller841c8802015-09-10 13:06:37 -07001394 % if lib.build == "all":
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001395 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT): openssl_dep_error
Craig Tiller841c8802015-09-10 13:06:37 -07001396 % endif
nnoble5b7f32a2014-12-22 08:12:44 -08001397
Craig Tiller841c8802015-09-10 13:06:37 -07001398 else
nnoble69ac39f2014-12-12 15:43:38 -08001399
Craig Tiller841c8802015-09-10 13:06:37 -07001400 % if lib.language == 'c++':
1401 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001402
Craig Tiller841c8802015-09-10 13:06:37 -07001403 # 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 -08001404
Craig Tiller841c8802015-09-10 13:06:37 -07001405 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001406
Craig Tiller841c8802015-09-10 13:06:37 -07001407 % if lib.build == "all":
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001408 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT): protobuf_dep_error
Craig Tiller841c8802015-09-10 13:06:37 -07001409 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001410
Craig Tiller841c8802015-09-10 13:06:37 -07001411 else
1412 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001413
Craig Tiller841c8802015-09-10 13:06:37 -07001414 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
1415 ## The else here corresponds to the if secure earlier.
1416 % else:
1417 % if lib.language == 'c++':
1418 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001419
Craig Tiller841c8802015-09-10 13:06:37 -07001420 # 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 -08001421
Craig Tiller841c8802015-09-10 13:06:37 -07001422 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001423
Craig Tiller841c8802015-09-10 13:06:37 -07001424 % if lib.build == "all":
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001425 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT): protobuf_dep_error
Craig Tiller841c8802015-09-10 13:06:37 -07001426 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001427
Craig Tiller841c8802015-09-10 13:06:37 -07001428 else
Nicolas Noble53830622015-02-12 16:56:38 -08001429
Craig Tiller841c8802015-09-10 13:06:37 -07001430 % endif
Nicolas "Pixel" Nobled649c212016-01-27 20:27:30 +01001431 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: \
1432 % if lib.name != 'z':
1433 $(ZLIB_DEP) \
1434 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001435 % endif
1436 % if lib.language == 'c++':
1437 $(PROTOBUF_DEP)\
1438 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001439 $(LIB${lib.name.upper()}_OBJS) \
1440 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001441 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001442 $(ZLIB_MERGE_OBJS) \
1443 % if lib.get('secure', 'check') == True:
1444 $(OPENSSL_MERGE_OBJS) \
1445 % endif
1446 % endif
1447
Craig Tiller841c8802015-09-10 13:06:37 -07001448 $(E) "[AR] Creating $@"
1449 $(Q) mkdir -p `dirname $@`
1450 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Vijay Paicc7eb8e2016-07-19 19:03:55 -07001451 $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001452 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001453 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001454 $(ZLIB_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001455 % if lib.get('secure', 'check') == True:
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001456 $(OPENSSL_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001457 % endif
1458 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001459
Craig Tiller841c8802015-09-10 13:06:37 -07001460 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001461 $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tiller841c8802015-09-10 13:06:37 -07001462 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001463
Craig Tiller841c8802015-09-10 13:06:37 -07001464 <%
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001465
Craig Tiller841c8802015-09-10 13:06:37 -07001466 if lib.language == 'c++':
1467 ld = '$(LDXX)'
1468 else:
1469 ld = '$(LD)'
nnoble5b7f32a2014-12-22 08:12:44 -08001470
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001471 out_mingbase = '$(LIBDIR)/$(CONFIG)/' + lib.name + '$(SHARED_VERSION)'
1472 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name + '$(SHARED_VERSION)'
nnoble5b7f32a2014-12-22 08:12:44 -08001473
Craig Tiller841c8802015-09-10 13:06:37 -07001474 common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
nnoble5b7f32a2014-12-22 08:12:44 -08001475
Craig Tiller841c8802015-09-10 13:06:37 -07001476 libs = ''
1477 lib_deps = ' $(ZLIB_DEP)'
1478 mingw_libs = ''
1479 mingw_lib_deps = ' $(ZLIB_DEP)'
1480 if lib.language == 'c++':
1481 lib_deps += ' $(PROTOBUF_DEP)'
1482 mingw_lib_deps += ' $(PROTOBUF_DEP)'
Jan Tattermusch324140c2016-01-12 08:54:01 -08001483 if lib.get('deps_linkage', None) == 'static':
1484 for dep in lib.get('deps', []):
1485 lib_archive = '$(LIBDIR)/$(CONFIG)/lib' + dep + '.a'
1486 common = common + ' ' + lib_archive
1487 lib_deps = lib_deps + ' ' + lib_archive
1488 mingw_lib_deps = mingw_lib_deps + ' ' + lib_archive
1489 else:
1490 for dep in lib.get('deps', []):
1491 libs = libs + ' -l' + dep
1492 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
1493 mingw_libs = mingw_libs + ' -l' + dep + '-imp'
1494 mingw_lib_deps = mingw_lib_deps + ' $(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001495
Craig Tiller841c8802015-09-10 13:06:37 -07001496 security = lib.get('secure', 'check')
1497 if security == True:
1498 common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)'
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001499 common = common + ' $(ZLIB_MERGE_LIBS)'
Nicolas "Pixel" Noblea7c162c2015-07-24 20:21:51 +02001500
Craig Tiller841c8802015-09-10 13:06:37 -07001501 if security in [True, 'check']:
1502 for src in lib.src:
1503 if not proto_re.match(src):
1504 sources_that_need_openssl.add(src)
1505 else:
1506 for src in lib.src:
1507 sources_that_don_t_need_openssl.add(src)
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001508
Craig Tiller841c8802015-09-10 13:06:37 -07001509 if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1510 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1511 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001512
Craig Tiller841c8802015-09-10 13:06:37 -07001513 if lib.language == 'c++':
1514 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
Craig Tiller4bef7ce2016-02-02 08:38:43 -08001515
1516 ldflags = '$(LDFLAGS)'
1517 if lib.get('LDFLAGS', None):
1518 ldflags += ' ' + lib['LDFLAGS']
Craig Tiller841c8802015-09-10 13:06:37 -07001519 %>
nnoble5b7f32a2014-12-22 08:12:44 -08001520
Craig Tiller841c8802015-09-10 13:06:37 -07001521 % if lib.build == "all":
1522 ifeq ($(SYSTEM),MINGW32)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001523 ${out_mingbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Craig Tiller841c8802015-09-10 13:06:37 -07001524 $(E) "[LD] Linking $@"
1525 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +01001526 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared ${lib.name}.def -Wl,--output-def=${out_mingbase}.def -Wl,--out-implib=${out_libbase}-dll.a -o ${out_mingbase}.$(SHARED_EXT) ${common}${mingw_libs}
Craig Tiller841c8802015-09-10 13:06:37 -07001527 else
1528 ${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
1529 $(E) "[LD] Linking $@"
1530 $(Q) mkdir -p `dirname $@`
1531 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +01001532 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
Craig Tiller841c8802015-09-10 13:06:37 -07001533 else
Craig Tillerf008f062016-02-08 12:48:03 -08001534 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.core_version.major} -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
1535 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT) ${out_libbase}.so.${settings.core_version.major}
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001536 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT) ${out_libbase}.so
Craig Tiller841c8802015-09-10 13:06:37 -07001537 endif
1538 endif
1539 % endif
1540 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1541 ## If the lib was secure, we have to close the Makefile's if that tested
1542 ## the presence of OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001543
Craig Tiller841c8802015-09-10 13:06:37 -07001544 endif
1545 % endif
1546 % if lib.language == 'c++':
1547 ## If the lib was C++, we have to close the Makefile's if that tested
1548 ## the presence of protobuf 3.0.0+
nnoble69ac39f2014-12-12 15:43:38 -08001549
Craig Tiller841c8802015-09-10 13:06:37 -07001550 endif
1551 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001552
Craig Tiller841c8802015-09-10 13:06:37 -07001553 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1554 ifneq ($(NO_SECURE),true)
1555 % endif
1556 ifneq ($(NO_DEPS),true)
1557 -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
1558 endif
1559 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1560 endif
1561 % endif
1562 % for src in lib.src:
1563 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src):
1564 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))}
1565 % endif
1566 % endfor
1567 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001568
Craig Tiller841c8802015-09-10 13:06:37 -07001569 <%def name="maketarget(tgt)"><% has_no_sources = not tgt.src %>
1570 % if not has_no_sources:
1571 ${tgt.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001572
Craig Tiller841c8802015-09-10 13:06:37 -07001573 % for src in tgt.src:
1574 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001575
Craig Tiller841c8802015-09-10 13:06:37 -07001576 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001577
Craig Tiller841c8802015-09-10 13:06:37 -07001578 ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
1579 % endif
1580 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1581 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001582
Craig Tiller841c8802015-09-10 13:06:37 -07001583 # You can't build secure targets if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001584
Craig Tiller841c8802015-09-10 13:06:37 -07001585 $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001586
Craig Tiller841c8802015-09-10 13:06:37 -07001587 else
nnoble69ac39f2014-12-12 15:43:38 -08001588
Craig Tiller841c8802015-09-10 13:06:37 -07001589 % endif
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001590
1591 % if tgt.boringssl:
1592 # boringssl needs an override to ensure that it does not include
1593 # system openssl headers regardless of other configuration
1594 # we do so here with a target specific variable assignment
Craig Tiller78222f72016-05-10 09:55:38 -07001595 $(${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 -08001596 $(${tgt.name.upper()}_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS)
1597 $(${tgt.name.upper()}_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE
1598 % else:
1599 % endif
1600
Craig Tiller841c8802015-09-10 13:06:37 -07001601 ##
1602 ## We're not trying to add a dependency on building zlib and openssl here,
1603 ## as it's already done in the libraries. We're assuming that the build
1604 ## trickles down, and that a secure target requires a secure version of
1605 ## a library.
1606 ##
1607 ## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1608 ## I can live with that.
1609 ##
1610 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001611
Craig Tiller841c8802015-09-10 13:06:37 -07001612 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001613
Craig Tiller841c8802015-09-10 13:06:37 -07001614 # 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 -08001615
Craig Tiller841c8802015-09-10 13:06:37 -07001616 $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001617
Craig Tiller841c8802015-09-10 13:06:37 -07001618 else
Nicolas Noble53830622015-02-12 16:56:38 -08001619
Craig Tiller841c8802015-09-10 13:06:37 -07001620 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1621 % if not has_no_sources:
1622 $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
1623 % endif
1624 % else:
1625 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1626 % if not has_no_sources:
1627 $(${tgt.name.upper()}_OBJS)\
1628 % endif
1629 % endif
1630 % for dep in tgt.deps:
1631 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1632 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001633
Craig Tiller32173c52016-03-17 14:12:45 -07001634 % if tgt.language == "c++" or tgt.boringssl or tgt.build == 'fuzzer':
Craig Tiller841c8802015-09-10 13:06:37 -07001635 ## C++ targets specificies.
1636 % if tgt.build == 'protoc':
1637 $(E) "[HOSTLD] Linking $@"
1638 $(Q) mkdir -p `dirname $@`
1639 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) \
1640 % if not has_no_sources:
1641 $(${tgt.name.upper()}_OBJS)\
1642 % endif
1643 % else:
1644 $(E) "[LD] Linking $@"
1645 $(Q) mkdir -p `dirname $@`
1646 $(Q) $(LDXX) $(LDFLAGS) \
1647 % if not has_no_sources:
1648 $(${tgt.name.upper()}_OBJS)\
1649 % endif
1650 % endif
1651 % else:
1652 ## C-only targets specificities.
1653 $(E) "[LD] Linking $@"
1654 $(Q) mkdir -p `dirname $@`
1655 $(Q) $(LD) $(LDFLAGS) \
1656 % if not has_no_sources:
1657 $(${tgt.name.upper()}_OBJS)\
1658 % endif
1659 % endif
1660 % for dep in tgt.deps:
1661 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1662 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001663 % if tgt.language == "c++":
1664 % if tgt.build == 'protoc':
1665 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
1666 % else:
1667 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
1668 % endif
1669 % endif
1670 % if tgt.build == 'protoc':
1671 $(HOST_LDLIBS)\
1672 % else:
1673 $(LDLIBS)\
1674 % endif
1675 % if tgt.build == 'protoc':
1676 $(HOST_LDLIBS_PROTOC)\
1677 % elif tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1678 $(LDLIBS_SECURE)\
1679 % endif
1680 % if tgt.language == 'c++' and tgt.build == 'test':
1681 $(GTEST_LIB)\
1682 % elif tgt.language == 'c++' and tgt.build == 'benchmark':
1683 $(GTEST_LIB)\
1684 % endif
Craig Tiller32173c52016-03-17 14:12:45 -07001685 % if tgt.build == 'fuzzer':
1686 -lFuzzer\
1687 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001688 -o $(BINDIR)/$(CONFIG)/${tgt.name}
1689 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001690
Craig Tiller841c8802015-09-10 13:06:37 -07001691 endif
1692 % endif
1693 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001694
Craig Tiller841c8802015-09-10 13:06:37 -07001695 endif
1696 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001697
Craig Tiller841c8802015-09-10 13:06:37 -07001698 % for src in tgt.src:
1699 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
1700 % for dep in tgt.deps:
1701 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1702 % endfor
Craig Tillerf5371ef2015-01-12 16:40:18 -08001703
Craig Tillerab230452016-01-04 08:18:43 -08001704 % if tgt.language == 'c89':
1705 % for src in tgt.src:
Craig Tillerea21ca22016-01-04 12:34:29 -08001706 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o : ${src}
1707 $(E) "[C] Compiling $<"
1708 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001709 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -std=c89 -pedantic -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Craig Tillerab230452016-01-04 08:18:43 -08001710 % endfor
1711 % endif
1712
Craig Tiller841c8802015-09-10 13:06:37 -07001713 % endfor
1714 % if not has_no_sources:
1715 deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
1716 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001717
Craig Tiller841c8802015-09-10 13:06:37 -07001718 % if not has_no_sources:
1719 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1720 ifneq ($(NO_SECURE),true)
1721 % endif
1722 ifneq ($(NO_DEPS),true)
1723 -include $(${tgt.name.upper()}_OBJS:.o=.dep)
1724 endif
1725 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1726 endif
1727 % endif
1728 % endif
Nicolas "Pixel" Noble472bb682015-11-03 19:09:01 +01001729 % for src in tgt.src:
1730 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in tgt.src):
1731 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in tgt.src if proto_re.match(src2))}
1732 % endif
1733 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001734 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001735
Craig Tiller841c8802015-09-10 13:06:37 -07001736 ifneq ($(OPENSSL_DEP),)
1737 # This is to ensure the embedded OpenSSL is built beforehand, properly
1738 # installing headers to their final destination on the drive. We need this
1739 # otherwise parallel compilation will fail if a source is compiled first.
1740 % for src in sorted(sources_that_need_openssl):
1741 % if src not in sources_that_don_t_need_openssl:
1742 ${src}: $(OPENSSL_DEP)
1743 % endif
1744 % endfor
1745 endif
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001746
Craig Tiller841c8802015-09-10 13:06:37 -07001747 .PHONY: all strip tools \
1748 dep_error openssl_dep_error openssl_dep_message git_update stop \
1749 buildtests buildtests_c buildtests_cxx \
1750 test test_c test_cxx \
1751 install install_c install_cxx \
1752 install-headers install-headers_c install-headers_cxx \
1753 install-shared install-shared_c install-shared_cxx \
1754 install-static install-static_c install-static_cxx \
1755 strip strip-shared strip-static \
1756 strip_c strip-shared_c strip-static_c \
1757 strip_cxx strip-shared_cxx strip-static_cxx \
1758 dep_c dep_cxx bins_dep_c bins_dep_cxx \
1759 clean
Craig Tillerb79c1e12016-02-23 10:00:58 -08001760
1761 .PHONY: printvars
1762 printvars:
1763 @$(foreach V,$(sort $(.VARIABLES)), \
1764 $(if $(filter-out environment% default automatic, \
1765 $(origin $V)),$(warning $V=$($V) ($(value $V)))))