blob: e6a28d16bce0563235f3a8b650f0b23fdabcf52a [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
Yuchen Zengd4df55e2016-08-15 16:41:18 -0700383 PROTOBUF_CHECK_CMD = $(PKG_CONFIG) --atleast-version=3.0.0 protobuf
Craig Tiller841c8802015-09-10 13:06:37 -0700384 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 .SECONDARY = %.pb.h %.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800698
Craig Tiller841c8802015-09-10 13:06:37 -0700699 ifeq ($(DEP_MISSING),)
700 all: static shared plugins\
701 % for tgt in targets:
702 % if tgt.build == 'all':
703 $(BINDIR)/$(CONFIG)/${tgt.name}\
704 % endif
705 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800706
Craig Tiller841c8802015-09-10 13:06:37 -0700707 dep_error:
708 @echo "You shouldn't see this message - all of your dependencies are correct."
709 else
710 all: dep_error git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800711
Craig Tiller841c8802015-09-10 13:06:37 -0700712 dep_error:
713 @echo
714 @echo "DEPENDENCY ERROR"
715 @echo
716 @echo "You are missing system dependencies that are essential to build grpc,"
717 @echo "and the third_party directory doesn't have them:"
718 @echo
719 @echo " $(DEP_MISSING)"
720 @echo
721 @echo "Installing the development packages for your system will solve"
722 @echo "this issue. Please consult INSTALL to get more information."
723 @echo
724 @echo "If you need information about why these tests failed, run:"
725 @echo
726 @echo " make run_dep_checks"
727 @echo
728 endif
nnoble69ac39f2014-12-12 15:43:38 -0800729
Craig Tiller841c8802015-09-10 13:06:37 -0700730 git_update:
731 ifeq ($(IS_GIT_FOLDER),true)
732 @echo "Additionally, since you are in a git clone, you can download the"
733 @echo "missing dependencies in third_party by running the following command:"
734 @echo
735 @echo " git submodule update --init"
736 @echo
737 endif
nnoble69ac39f2014-12-12 15:43:38 -0800738
Craig Tiller841c8802015-09-10 13:06:37 -0700739 openssl_dep_error: openssl_dep_message git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800740
Craig Tiller841c8802015-09-10 13:06:37 -0700741 protobuf_dep_error: protobuf_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800742
Craig Tiller841c8802015-09-10 13:06:37 -0700743 protoc_dep_error: protoc_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800744
Craig Tiller841c8802015-09-10 13:06:37 -0700745 openssl_dep_message:
746 @echo
747 @echo "DEPENDENCY ERROR"
748 @echo
Craig Tillerb79c1e12016-02-23 10:00:58 -0800749 @echo "The target you are trying to run requires an OpenSSL implementation."
750 @echo "Your system doesn't have one, and either the third_party directory"
751 @echo "doesn't have it, or your compiler can't build BoringSSL."
Craig Tiller841c8802015-09-10 13:06:37 -0700752 @echo
753 @echo "Please consult INSTALL to get more information."
754 @echo
755 @echo "If you need information about why these tests failed, run:"
756 @echo
757 @echo " make run_dep_checks"
758 @echo
nnoble69ac39f2014-12-12 15:43:38 -0800759
Craig Tiller841c8802015-09-10 13:06:37 -0700760 protobuf_dep_message:
761 @echo
762 @echo "DEPENDENCY ERROR"
763 @echo
764 @echo "The target you are trying to run requires protobuf 3.0.0+"
765 @echo "Your system doesn't have it, and neither does the third_party directory."
766 @echo
767 @echo "Please consult INSTALL to get more information."
768 @echo
769 @echo "If you need information about why these tests failed, run:"
770 @echo
771 @echo " make run_dep_checks"
772 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800773
Craig Tiller841c8802015-09-10 13:06:37 -0700774 protoc_dep_message:
775 @echo
776 @echo "DEPENDENCY ERROR"
777 @echo
778 @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
779 @echo "Your system doesn't have it, and neither does the third_party directory."
780 @echo
781 @echo "Please consult INSTALL to get more information."
782 @echo
783 @echo "If you need information about why these tests failed, run:"
784 @echo
785 @echo " make run_dep_checks"
786 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800787
Craig Tiller841c8802015-09-10 13:06:37 -0700788 systemtap_dep_error:
789 @echo
790 @echo "DEPENDENCY ERROR"
791 @echo
792 @echo "Under the '$(CONFIG)' configutation, the target you are trying "
793 @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other "
794 @echo "platforms such as Solaris and *BSD). "
795 @echo
796 @echo "Please consult INSTALL to get more information."
797 @echo
David Garcia Quintas8954e902015-04-29 09:46:33 -0700798
Craig Tiller841c8802015-09-10 13:06:37 -0700799 stop:
800 @false
nnoble69ac39f2014-12-12 15:43:38 -0800801
Craig Tiller841c8802015-09-10 13:06:37 -0700802 % for tgt in targets:
803 ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
804 % endfor
ctiller09cb6d52014-12-19 17:38:22 -0800805
Craig Tiller841c8802015-09-10 13:06:37 -0700806 run_dep_checks:
807 $(OPENSSL_ALPN_CHECK_CMD) || true
808 $(OPENSSL_NPN_CHECK_CMD) || true
809 $(ZLIB_CHECK_CMD) || true
810 $(PERFTOOLS_CHECK_CMD) || true
811 $(PROTOBUF_CHECK_CMD) || true
812 $(PROTOC_CHECK_VERSION_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800813
Craig Tiller841c8802015-09-10 13:06:37 -0700814 third_party/protobuf/configure:
815 $(E) "[AUTOGEN] Preparing protobuf"
816 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
Nicolas Noble53830622015-02-12 16:56:38 -0800817
Craig Tiller841c8802015-09-10 13:06:37 -0700818 $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
819 $(E) "[MAKE] Building protobuf"
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700820 $(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 -0700821 $(Q)$(MAKE) -C third_party/protobuf clean
822 $(Q)$(MAKE) -C third_party/protobuf
823 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
824 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
825 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
826 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
827 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800828
Craig Tiller841c8802015-09-10 13:06:37 -0700829 static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800830
Craig Tillereda85c62016-07-01 12:45:19 -0700831 static_c: pc_c pc_c_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700832 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100833 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700834 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
835 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
836 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100837 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700838 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800839
840
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100841 static_cxx: pc_cxx pc_cxx_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700842 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100843 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700844 % if lib.build == 'all' and lib.language == 'c++':
845 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
846 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100847 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700848 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800849
850
Craig Tiller841c8802015-09-10 13:06:37 -0700851 shared: shared_c shared_cxx
nnoble29e1d292014-12-01 10:27:40 -0800852
Craig Tillereda85c62016-07-01 12:45:19 -0700853 shared_c: pc_c pc_c_unsecure cache.mk\
Craig Tiller841c8802015-09-10 13:06:37 -0700854 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100855 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700856 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100857 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)\
Craig Tiller841c8802015-09-10 13:06:37 -0700858 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100859 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700860 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800861
Craig Tiller841c8802015-09-10 13:06:37 -0700862 shared_cxx: pc_cxx pc_cxx_unsecure cache.mk\
863 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100864 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700865 % if lib.build == 'all' and lib.language == 'c++':
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100866 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)\
Craig Tiller841c8802015-09-10 13:06:37 -0700867 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100868 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700869 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800870
871
Craig Tiller841c8802015-09-10 13:06:37 -0700872 shared_csharp: shared_c \
873 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100874 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700875 % if lib.build == 'all' and lib.language == 'csharp':
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100876 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)\
Craig Tiller841c8802015-09-10 13:06:37 -0700877 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100878 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700879 % endfor
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800880
Craig Tiller841c8802015-09-10 13:06:37 -0700881 grpc_csharp_ext: shared_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800882
Craig Tiller841c8802015-09-10 13:06:37 -0700883 plugins: $(PROTOC_PLUGINS)
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100884
Craig Tiller841c8802015-09-10 13:06:37 -0700885 privatelibs: privatelibs_c privatelibs_cxx
nnoble29e1d292014-12-01 10:27:40 -0800886
Craig Tiller841c8802015-09-10 13:06:37 -0700887 privatelibs_c: \
888 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100889 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800890 % 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 -0700891 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
892 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100893 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700894 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800895
Craig Tiller841c8802015-09-10 13:06:37 -0700896 pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc
murgatroid998faab232015-06-30 17:24:21 -0700897
Craig Tiller841c8802015-09-10 13:06:37 -0700898 pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -0700899
Craig Tiller841c8802015-09-10 13:06:37 -0700900 pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc
murgatroid998faab232015-06-30 17:24:21 -0700901
Craig Tiller841c8802015-09-10 13:06:37 -0700902 pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800903
vjpai20410922016-06-15 09:21:42 -0700904 ifeq ($(EMBED_OPENSSL),true)
Craig Tiller841c8802015-09-10 13:06:37 -0700905 privatelibs_cxx: \
906 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100907 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700908 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None):
909 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
910 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100911 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700912 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -0700913
vjpai20410922016-06-15 09:21:42 -0700914 else
915 privatelibs_cxx: \
916 % for lib in libs:
917 % if 'Makefile' in lib.get('build_system', ['Makefile']):
918 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None) and not lib.boringssl:
919 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
920 % endif
921 % endif
922 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -0700923
vjpai20410922016-06-15 09:21:42 -0700924 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800925
926
Craig Tillereda85c62016-07-01 12:45:19 -0700927 buildtests: buildtests_c buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -0800928
Craig Tiller3824b6e2015-12-09 11:19:59 -0800929 buildtests_c: privatelibs_c <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700930 % for tgt in targets:
931 % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -0800932 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700933 % endif
934 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800935
936
vjpai20410922016-06-15 09:21:42 -0700937 ifeq ($(EMBED_OPENSSL),true)
Craig Tillereda85c62016-07-01 12:45:19 -0700938 buildtests_cxx: privatelibs_cxx <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700939 % for tgt in targets:
940 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -0800941 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700942 % endif
943 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -0700944
vjpai20410922016-06-15 09:21:42 -0700945 else
Craig Tillereda85c62016-07-01 12:45:19 -0700946 buildtests_cxx: privatelibs_cxx <%text>\</%text>
vjpai20410922016-06-15 09:21:42 -0700947 % for tgt in targets:
948 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl:
949 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
950 % endif
951 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -0700952
vjpai20410922016-06-15 09:21:42 -0700953 endif
nnoble29e1d292014-12-01 10:27:40 -0800954
955
Craig Tillereda85c62016-07-01 12:45:19 -0700956 test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -0800957
Craig Tillereda85c62016-07-01 12:45:19 -0700958 flaky_test: flaky_test_c flaky_test_cxx
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +0200959
Craig Tiller841c8802015-09-10 13:06:37 -0700960 test_c: buildtests_c
961 % for tgt in targets:
962 % 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):
963 $(E) "[RUN] Testing ${tgt.name}"
964 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
965 % endif
966 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +0200967
968
Craig Tiller841c8802015-09-10 13:06:37 -0700969 flaky_test_c: buildtests_c
970 % for tgt in targets:
971 % 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):
972 $(E) "[RUN] Testing ${tgt.name}"
973 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
974 % endif
975 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800976
977
Craig Tillereda85c62016-07-01 12:45:19 -0700978 test_cxx: buildtests_cxx
Craig Tiller841c8802015-09-10 13:06:37 -0700979 % for tgt in targets:
980 % 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):
981 $(E) "[RUN] Testing ${tgt.name}"
982 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
983 % endif
984 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +0200985
986
Craig Tiller841c8802015-09-10 13:06:37 -0700987 flaky_test_cxx: buildtests_cxx
988 % for tgt in targets:
989 % 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):
990 $(E) "[RUN] Testing ${tgt.name}"
991 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
992 % endif
993 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800994
995
Craig Tiller841c8802015-09-10 13:06:37 -0700996 test_python: static_c
997 $(E) "[RUN] Testing python code"
998 $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
Nicolas "Pixel" Noble051a28f2015-03-17 22:54:54 +0100999
1000
Craig Tiller841c8802015-09-10 13:06:37 -07001001 tools: tools_c tools_cxx
Craig Tiller7552f0f2015-06-19 17:46:20 -07001002
1003
Craig Tiller841c8802015-09-10 13:06:37 -07001004 tools_c: privatelibs_c\
1005 % for tgt in targets:
1006 % if tgt.build == 'tool' and not tgt.language=='c++':
1007 $(BINDIR)/$(CONFIG)/${tgt.name}\
1008 % endif
1009 % endfor
Craig Tiller7552f0f2015-06-19 17:46:20 -07001010
1011
Craig Tiller841c8802015-09-10 13:06:37 -07001012 tools_cxx: privatelibs_cxx\
1013 % for tgt in targets:
1014 % if tgt.build == 'tool' and tgt.language=='c++':
1015 $(BINDIR)/$(CONFIG)/${tgt.name}\
1016 % endif
1017 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001018
1019
Craig Tiller841c8802015-09-10 13:06:37 -07001020 buildbenchmarks: privatelibs\
1021 % for tgt in targets:
1022 % if tgt.build == 'benchmark':
1023 $(BINDIR)/$(CONFIG)/${tgt.name}\
1024 % endif
1025 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001026
1027
Craig Tiller841c8802015-09-10 13:06:37 -07001028 benchmarks: buildbenchmarks
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001029
Craig Tiller841c8802015-09-10 13:06:37 -07001030 strip: strip-static strip-shared
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001031
Craig Tiller841c8802015-09-10 13:06:37 -07001032 strip-static: strip-static_c strip-static_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001033
Craig Tiller841c8802015-09-10 13:06:37 -07001034 strip-shared: strip-shared_c strip-shared_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001035
Nicolas Noble047b7272015-01-16 13:55:05 -08001036
Craig Tiller841c8802015-09-10 13:06:37 -07001037 # TODO(nnoble): the strip target is stripping in-place, instead
1038 # of copying files in a temporary folder.
1039 # This prevents proper debugging after running make install.
Nicolas Noble047b7272015-01-16 13:55:05 -08001040
Craig Tiller841c8802015-09-10 13:06:37 -07001041 strip-static_c: static_c
1042 ifeq ($(CONFIG),opt)
1043 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001044 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001045 % if lib.language == "c":
1046 % if lib.build == "all":
1047 % if not lib.get('external_deps', None):
1048 $(E) "[STRIP] Stripping lib${lib.name}.a"
1049 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1050 % endif
1051 % endif
1052 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001053 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001054 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001055 endif
nnoble85a49262014-12-08 18:14:03 -08001056
Craig Tiller841c8802015-09-10 13:06:37 -07001057 strip-static_cxx: static_cxx
1058 ifeq ($(CONFIG),opt)
1059 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001060 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001061 % if lib.language == "c++":
1062 % if lib.build == "all":
1063 $(E) "[STRIP] Stripping lib${lib.name}.a"
1064 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1065 % endif
1066 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001067 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001068 % endfor
1069 endif
Nicolas "Pixel" Noble4ef9b862015-08-14 19:35:24 +02001070
Craig Tiller841c8802015-09-10 13:06:37 -07001071 strip-shared_c: shared_c
1072 ifeq ($(CONFIG),opt)
1073 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001074 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001075 % if lib.language == "c":
1076 % if lib.build == "all":
1077 % if not lib.get('external_deps', None):
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001078 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)"
1079 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)
Craig Tiller841c8802015-09-10 13:06:37 -07001080 % endif
1081 % endif
1082 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001083 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001084 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001085 endif
nnoble85a49262014-12-08 18:14:03 -08001086
Craig Tiller841c8802015-09-10 13:06:37 -07001087 strip-shared_cxx: shared_cxx
1088 ifeq ($(CONFIG),opt)
1089 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001090 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001091 % if lib.language == "c++":
1092 % if lib.build == "all":
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001093 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)"
1094 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)
Craig Tiller841c8802015-09-10 13:06:37 -07001095 % endif
1096 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001097 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001098 % endfor
1099 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001100
Craig Tiller841c8802015-09-10 13:06:37 -07001101 strip-shared_csharp: shared_csharp
1102 ifeq ($(CONFIG),opt)
1103 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001104 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001105 % if lib.language == "csharp":
1106 % if lib.build == "all":
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001107 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)"
1108 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)
Craig Tiller841c8802015-09-10 13:06:37 -07001109 % endif
1110 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001111 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001112 % endfor
1113 endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001114
Craig Tiller841c8802015-09-10 13:06:37 -07001115 cache.mk::
1116 $(E) "[MAKE] Generating $@"
1117 $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@
murgatroid99aa521572015-07-10 14:49:12 -07001118
Craig Tiller841c8802015-09-10 13:06:37 -07001119 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc:
1120 $(E) "[MAKE] Generating $@"
1121 $(Q) mkdir -p $(@D)
1122 $(Q) echo "$(GRPC_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001123
Craig Tiller841c8802015-09-10 13:06:37 -07001124 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc:
1125 $(E) "[MAKE] Generating $@"
1126 $(Q) mkdir -p $(@D)
1127 $(Q) echo "$(GRPC_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001128
Craig Tiller841c8802015-09-10 13:06:37 -07001129 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc:
1130 $(E) "[MAKE] Generating $@"
1131 $(Q) mkdir -p $(@D)
1132 $(Q) echo "$(GRPCXX_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001133
Craig Tiller841c8802015-09-10 13:06:37 -07001134 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc:
1135 $(E) "[MAKE] Generating $@"
1136 $(Q) mkdir -p $(@D)
1137 $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001138
Craig Tiller841c8802015-09-10 13:06:37 -07001139 % for p in protos:
1140 ifeq ($(NO_PROTOC),true)
1141 $(GENDIR)/${p}.pb.cc: protoc_dep_error
1142 $(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error
1143 else
Craig Tiller1b4e3302015-12-17 16:35:00 -08001144 $(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 -07001145 $(E) "[PROTOC] Generating protobuf CC file from $<"
1146 $(Q) mkdir -p `dirname $@`
David Garcia Quintase68ed6f2016-06-17 12:49:14 -07001147 $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --cpp_out=$(GENDIR) $<
Nicolas "Pixel" Noble0caebbf2015-04-09 23:08:51 +02001148
Craig Tiller1b4e3302015-12-17 16:35:00 -08001149 $(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 -07001150 $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
1151 $(Q) mkdir -p `dirname $@`
Vijay Paicc7eb8e2016-07-19 19:03:55 -07001152 $(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 -07001153 endif
nnoble72309c62014-12-12 11:42:26 -08001154
Craig Tiller841c8802015-09-10 13:06:37 -07001155 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001156
Craig Tiller841c8802015-09-10 13:06:37 -07001157 ifeq ($(CONFIG),stapprof)
1158 src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h
1159 ifeq ($(HAS_SYSTEMTAP),true)
1160 $(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d
1161 $(E) "[DTRACE] Compiling $<"
1162 $(Q) mkdir -p `dirname $@`
1163 $(Q) $(DTRACE) -C -h -s $< -o $@
1164 else
1165 $(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop
1166 endif
1167 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -07001168
Craig Tiller841c8802015-09-10 13:06:37 -07001169 $(OBJDIR)/$(CONFIG)/%.o : %.c
1170 $(E) "[C] Compiling $<"
1171 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001172 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001173
Craig Tiller841c8802015-09-10 13:06:37 -07001174 $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
1175 $(E) "[CXX] Compiling $<"
1176 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001177 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001178
Craig Tiller841c8802015-09-10 13:06:37 -07001179 $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
1180 $(E) "[HOSTCXX] Compiling $<"
1181 $(Q) mkdir -p `dirname $@`
1182 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -08001183
Craig Tiller841c8802015-09-10 13:06:37 -07001184 $(OBJDIR)/$(CONFIG)/%.o : %.cc
1185 $(E) "[CXX] Compiling $<"
1186 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001187 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001188
murgatroid99a3c55352016-08-10 13:41:31 -07001189 install: install_c install_cxx install-plugins install-certs
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001190
Craig Tiller841c8802015-09-10 13:06:37 -07001191 install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001192
Craig Tiller841c8802015-09-10 13:06:37 -07001193 install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
nnoble85a49262014-12-08 18:14:03 -08001194
Craig Tiller841c8802015-09-10 13:06:37 -07001195 install_csharp: install-shared_csharp install_c
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001196
Craig Tiller841c8802015-09-10 13:06:37 -07001197 install_grpc_csharp_ext: install_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001198
Craig Tiller841c8802015-09-10 13:06:37 -07001199 install-headers: install-headers_c install-headers_cxx
nnoble85a49262014-12-08 18:14:03 -08001200
Craig Tiller841c8802015-09-10 13:06:37 -07001201 install-headers_c:
1202 $(E) "[INSTALL] Installing public C headers"
1203 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1204 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001205
Craig Tiller841c8802015-09-10 13:06:37 -07001206 install-headers_cxx:
1207 $(E) "[INSTALL] Installing public C++ headers"
1208 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1209 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001210
Craig Tiller841c8802015-09-10 13:06:37 -07001211 install-static: install-static_c install-static_cxx
nnoble85a49262014-12-08 18:14:03 -08001212
Craig Tiller841c8802015-09-10 13:06:37 -07001213 install-static_c: static_c strip-static_c install-pkg-config_c
1214 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001215 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001216 % if lib.language == "c":
1217 % if lib.build == "all":
1218 % if not lib.get('external_deps', None):
1219 $(E) "[INSTALL] Installing lib${lib.name}.a"
1220 $(Q) $(INSTALL) -d $(prefix)/lib
1221 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1222 % endif
1223 % endif
1224 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001225 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001226 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001227
Craig Tiller841c8802015-09-10 13:06:37 -07001228 install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx
1229 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001230 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001231 % if lib.language == "c++":
1232 % if lib.build == "all":
1233 $(E) "[INSTALL] Installing lib${lib.name}.a"
1234 $(Q) $(INSTALL) -d $(prefix)/lib
1235 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1236 % endif
1237 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001238 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001239 % endfor
nnoble85a49262014-12-08 18:14:03 -08001240
Craig Tiller841c8802015-09-10 13:06:37 -07001241 <%def name="install_shared(lang_filter)">\
1242 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001243 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001244 % if lib.language == lang_filter:
1245 % if lib.build == "all":
1246 % if not lib.get('external_deps', None):
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001247 $(E) "[INSTALL] Installing $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)"
1248 $(Q) $(INSTALL) -d $(prefix)/lib
1249 $(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 -07001250 ifeq ($(SYSTEM),MINGW32)
Craig Tiller841c8802015-09-10 13:06:37 -07001251 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001252 else ifneq ($(SYSTEM),Darwin)
Craig Tillerf008f062016-02-08 12:48:03 -08001253 $(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 +01001254 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
Craig Tiller841c8802015-09-10 13:06:37 -07001255 endif
1256 % endif
1257 % endif
1258 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001259 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001260 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001261 ifneq ($(SYSTEM),MINGW32)
1262 ifneq ($(SYSTEM),Darwin)
1263 $(Q) ldconfig || true
1264 endif
1265 endif
1266 </%def>
nnoble85a49262014-12-08 18:14:03 -08001267
Craig Tiller841c8802015-09-10 13:06:37 -07001268 install-shared_c: shared_c strip-shared_c install-pkg-config_c
1269 ${install_shared("c")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001270
Craig Tiller841c8802015-09-10 13:06:37 -07001271 install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c install-pkg-config_cxx
1272 ${install_shared("c++")}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001273
Craig Tiller841c8802015-09-10 13:06:37 -07001274 install-shared_csharp: shared_csharp strip-shared_csharp
1275 ${install_shared("csharp")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001276
Craig Tiller841c8802015-09-10 13:06:37 -07001277 install-plugins: $(PROTOC_PLUGINS)
1278 ifeq ($(SYSTEM),MINGW32)
1279 $(Q) false
1280 else
1281 $(E) "[INSTALL] Installing grpc protoc plugins"
1282 % for tgt in targets:
1283 % if tgt.build == 'protoc':
1284 $(Q) $(INSTALL) -d $(prefix)/bin
1285 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
1286 % endif
1287 % endfor
1288 endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001289
Craig Tillereda85c62016-07-01 12:45:19 -07001290 install-pkg-config_c: pc_c pc_c_unsecure
Craig Tiller841c8802015-09-10 13:06:37 -07001291 $(E) "[INSTALL] Installing C pkg-config files"
1292 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
Craig Tiller841c8802015-09-10 13:06:37 -07001293 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(prefix)/lib/pkgconfig/grpc.pc
1294 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(prefix)/lib/pkgconfig/grpc_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -07001295
Craig Tiller841c8802015-09-10 13:06:37 -07001296 install-pkg-config_cxx: pc_cxx pc_cxx_unsecure
1297 $(E) "[INSTALL] Installing C++ pkg-config files"
1298 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
1299 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc $(prefix)/lib/pkgconfig/grpc++.pc
1300 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc $(prefix)/lib/pkgconfig/grpc++_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -07001301
Craig Tiller841c8802015-09-10 13:06:37 -07001302 install-certs: etc/roots.pem
1303 $(E) "[INSTALL] Installing root certificates"
1304 $(Q) $(INSTALL) -d $(prefix)/share/grpc
1305 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +01001306
Craig Tiller841c8802015-09-10 13:06:37 -07001307 clean:
1308 $(E) "[CLEAN] Cleaning build directories."
1309 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001310
1311
Craig Tiller841c8802015-09-10 13:06:37 -07001312 # The various libraries
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001313
Craig Tiller841c8802015-09-10 13:06:37 -07001314 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001315 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001316 ${makelib(lib)}
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001317 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001318 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001319
1320
Craig Tiller841c8802015-09-10 13:06:37 -07001321 # All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001322
Craig Tiller841c8802015-09-10 13:06:37 -07001323 % for tgt in targets:
1324 ${maketarget(tgt)}
1325 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001326
Craig Tiller841c8802015-09-10 13:06:37 -07001327 <%def name="makelib(lib)">
1328 LIB${lib.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001329
Craig Tiller841c8802015-09-10 13:06:37 -07001330 % for src in lib.src:
1331 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001332
Craig Tiller841c8802015-09-10 13:06:37 -07001333 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001334
Craig Tiller841c8802015-09-10 13:06:37 -07001335 % if "public_headers" in lib:
1336 % if lib.language == "c++":
1337 PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001338
Craig Tiller841c8802015-09-10 13:06:37 -07001339 % else:
1340 PUBLIC_HEADERS_C += \\
nnoble85a49262014-12-08 18:14:03 -08001341
Craig Tiller841c8802015-09-10 13:06:37 -07001342 % endif
1343 % for hdr in lib.public_headers:
1344 ${hdr} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001345
Craig Tiller841c8802015-09-10 13:06:37 -07001346 % endfor
1347 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001348
Craig Tiller841c8802015-09-10 13:06:37 -07001349 LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001350
Nicolas "Pixel" Noble51b1aee2016-01-28 01:14:58 +01001351 % if lib.get('defaults', None):
1352 % for name, value in defaults.get(lib.defaults).iteritems():
1353 $(LIB${lib.name.upper()}_OBJS): ${name} += ${value}
1354 % endfor
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001355 % endif
1356
Craig Tiller841c8802015-09-10 13:06:37 -07001357 ## If the library requires OpenSSL, let's add some restrictions.
1358 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1359 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001360
Craig Tiller841c8802015-09-10 13:06:37 -07001361 # You can't build secure libraries if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001362
Craig Tiller841c8802015-09-10 13:06:37 -07001363 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001364
Craig Tiller841c8802015-09-10 13:06:37 -07001365 % if lib.build == "all":
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001366 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT): openssl_dep_error
Craig Tiller841c8802015-09-10 13:06:37 -07001367 % endif
nnoble5b7f32a2014-12-22 08:12:44 -08001368
Craig Tiller841c8802015-09-10 13:06:37 -07001369 else
nnoble69ac39f2014-12-12 15:43:38 -08001370
Craig Tiller841c8802015-09-10 13:06:37 -07001371 % if lib.language == 'c++':
1372 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001373
Craig Tiller841c8802015-09-10 13:06:37 -07001374 # 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 -08001375
Craig Tiller841c8802015-09-10 13:06:37 -07001376 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001377
Craig Tiller841c8802015-09-10 13:06:37 -07001378 % if lib.build == "all":
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001379 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT): protobuf_dep_error
Craig Tiller841c8802015-09-10 13:06:37 -07001380 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001381
Craig Tiller841c8802015-09-10 13:06:37 -07001382 else
1383 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001384
Craig Tiller841c8802015-09-10 13:06:37 -07001385 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
1386 ## The else here corresponds to the if secure earlier.
1387 % else:
1388 % if lib.language == 'c++':
1389 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001390
Craig Tiller841c8802015-09-10 13:06:37 -07001391 # 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 -08001392
Craig Tiller841c8802015-09-10 13:06:37 -07001393 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001394
Craig Tiller841c8802015-09-10 13:06:37 -07001395 % if lib.build == "all":
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001396 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT): protobuf_dep_error
Craig Tiller841c8802015-09-10 13:06:37 -07001397 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001398
Craig Tiller841c8802015-09-10 13:06:37 -07001399 else
Nicolas Noble53830622015-02-12 16:56:38 -08001400
Craig Tiller841c8802015-09-10 13:06:37 -07001401 % endif
Nicolas "Pixel" Nobled649c212016-01-27 20:27:30 +01001402 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: \
1403 % if lib.name != 'z':
1404 $(ZLIB_DEP) \
1405 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001406 % endif
1407 % if lib.language == 'c++':
1408 $(PROTOBUF_DEP)\
1409 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001410 $(LIB${lib.name.upper()}_OBJS) \
1411 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001412 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001413 $(ZLIB_MERGE_OBJS) \
1414 % if lib.get('secure', 'check') == True:
1415 $(OPENSSL_MERGE_OBJS) \
1416 % endif
1417 % endif
1418
Craig Tiller841c8802015-09-10 13:06:37 -07001419 $(E) "[AR] Creating $@"
1420 $(Q) mkdir -p `dirname $@`
1421 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Vijay Paicc7eb8e2016-07-19 19:03:55 -07001422 $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001423 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001424 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001425 $(ZLIB_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001426 % if lib.get('secure', 'check') == True:
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001427 $(OPENSSL_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001428 % endif
1429 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001430
Craig Tiller841c8802015-09-10 13:06:37 -07001431 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001432 $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tiller841c8802015-09-10 13:06:37 -07001433 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001434
Craig Tiller841c8802015-09-10 13:06:37 -07001435 <%
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001436
Craig Tiller841c8802015-09-10 13:06:37 -07001437 if lib.language == 'c++':
1438 ld = '$(LDXX)'
1439 else:
1440 ld = '$(LD)'
nnoble5b7f32a2014-12-22 08:12:44 -08001441
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001442 out_mingbase = '$(LIBDIR)/$(CONFIG)/' + lib.name + '$(SHARED_VERSION)'
1443 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name + '$(SHARED_VERSION)'
nnoble5b7f32a2014-12-22 08:12:44 -08001444
Craig Tiller841c8802015-09-10 13:06:37 -07001445 common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
nnoble5b7f32a2014-12-22 08:12:44 -08001446
Craig Tiller841c8802015-09-10 13:06:37 -07001447 libs = ''
1448 lib_deps = ' $(ZLIB_DEP)'
1449 mingw_libs = ''
1450 mingw_lib_deps = ' $(ZLIB_DEP)'
1451 if lib.language == 'c++':
1452 lib_deps += ' $(PROTOBUF_DEP)'
1453 mingw_lib_deps += ' $(PROTOBUF_DEP)'
Jan Tattermusch324140c2016-01-12 08:54:01 -08001454 if lib.get('deps_linkage', None) == 'static':
1455 for dep in lib.get('deps', []):
1456 lib_archive = '$(LIBDIR)/$(CONFIG)/lib' + dep + '.a'
1457 common = common + ' ' + lib_archive
1458 lib_deps = lib_deps + ' ' + lib_archive
1459 mingw_lib_deps = mingw_lib_deps + ' ' + lib_archive
1460 else:
1461 for dep in lib.get('deps', []):
1462 libs = libs + ' -l' + dep
1463 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
1464 mingw_libs = mingw_libs + ' -l' + dep + '-imp'
1465 mingw_lib_deps = mingw_lib_deps + ' $(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001466
Craig Tiller841c8802015-09-10 13:06:37 -07001467 security = lib.get('secure', 'check')
1468 if security == True:
1469 common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)'
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001470 common = common + ' $(ZLIB_MERGE_LIBS)'
Nicolas "Pixel" Noblea7c162c2015-07-24 20:21:51 +02001471
Craig Tiller841c8802015-09-10 13:06:37 -07001472 if security in [True, 'check']:
1473 for src in lib.src:
1474 if not proto_re.match(src):
1475 sources_that_need_openssl.add(src)
1476 else:
1477 for src in lib.src:
1478 sources_that_don_t_need_openssl.add(src)
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001479
Craig Tiller841c8802015-09-10 13:06:37 -07001480 if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1481 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1482 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001483
Craig Tiller841c8802015-09-10 13:06:37 -07001484 if lib.language == 'c++':
1485 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
Craig Tiller4bef7ce2016-02-02 08:38:43 -08001486
1487 ldflags = '$(LDFLAGS)'
1488 if lib.get('LDFLAGS', None):
1489 ldflags += ' ' + lib['LDFLAGS']
Craig Tiller841c8802015-09-10 13:06:37 -07001490 %>
nnoble5b7f32a2014-12-22 08:12:44 -08001491
Craig Tiller841c8802015-09-10 13:06:37 -07001492 % if lib.build == "all":
1493 ifeq ($(SYSTEM),MINGW32)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001494 ${out_mingbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Craig Tiller841c8802015-09-10 13:06:37 -07001495 $(E) "[LD] Linking $@"
1496 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +01001497 $(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 -07001498 else
1499 ${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
1500 $(E) "[LD] Linking $@"
1501 $(Q) mkdir -p `dirname $@`
1502 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +01001503 $(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 -07001504 else
Craig Tillerf008f062016-02-08 12:48:03 -08001505 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.core_version.major} -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
1506 $(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 +01001507 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT) ${out_libbase}.so
Craig Tiller841c8802015-09-10 13:06:37 -07001508 endif
1509 endif
1510 % endif
1511 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1512 ## If the lib was secure, we have to close the Makefile's if that tested
1513 ## the presence of OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001514
Craig Tiller841c8802015-09-10 13:06:37 -07001515 endif
1516 % endif
1517 % if lib.language == 'c++':
1518 ## If the lib was C++, we have to close the Makefile's if that tested
1519 ## the presence of protobuf 3.0.0+
nnoble69ac39f2014-12-12 15:43:38 -08001520
Craig Tiller841c8802015-09-10 13:06:37 -07001521 endif
1522 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001523
Craig Tiller841c8802015-09-10 13:06:37 -07001524 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1525 ifneq ($(NO_SECURE),true)
1526 % endif
1527 ifneq ($(NO_DEPS),true)
1528 -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
1529 endif
1530 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1531 endif
1532 % endif
1533 % for src in lib.src:
1534 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src):
1535 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))}
1536 % endif
1537 % endfor
1538 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001539
Craig Tiller841c8802015-09-10 13:06:37 -07001540 <%def name="maketarget(tgt)"><% has_no_sources = not tgt.src %>
1541 % if not has_no_sources:
1542 ${tgt.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001543
Craig Tiller841c8802015-09-10 13:06:37 -07001544 % for src in tgt.src:
1545 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001546
Craig Tiller841c8802015-09-10 13:06:37 -07001547 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001548
Craig Tiller841c8802015-09-10 13:06:37 -07001549 ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
1550 % endif
1551 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1552 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001553
Craig Tiller841c8802015-09-10 13:06:37 -07001554 # You can't build secure targets if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001555
Craig Tiller841c8802015-09-10 13:06:37 -07001556 $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001557
Craig Tiller841c8802015-09-10 13:06:37 -07001558 else
nnoble69ac39f2014-12-12 15:43:38 -08001559
Craig Tiller841c8802015-09-10 13:06:37 -07001560 % endif
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001561
1562 % if tgt.boringssl:
1563 # boringssl needs an override to ensure that it does not include
1564 # system openssl headers regardless of other configuration
1565 # we do so here with a target specific variable assignment
Craig Tiller78222f72016-05-10 09:55:38 -07001566 $(${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 -08001567 $(${tgt.name.upper()}_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS)
1568 $(${tgt.name.upper()}_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE
1569 % else:
1570 % endif
1571
Craig Tiller841c8802015-09-10 13:06:37 -07001572 ##
1573 ## We're not trying to add a dependency on building zlib and openssl here,
1574 ## as it's already done in the libraries. We're assuming that the build
1575 ## trickles down, and that a secure target requires a secure version of
1576 ## a library.
1577 ##
1578 ## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1579 ## I can live with that.
1580 ##
1581 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001582
Craig Tiller841c8802015-09-10 13:06:37 -07001583 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001584
Craig Tiller841c8802015-09-10 13:06:37 -07001585 # 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 -08001586
Craig Tiller841c8802015-09-10 13:06:37 -07001587 $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001588
Craig Tiller841c8802015-09-10 13:06:37 -07001589 else
Nicolas Noble53830622015-02-12 16:56:38 -08001590
Craig Tiller841c8802015-09-10 13:06:37 -07001591 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1592 % if not has_no_sources:
1593 $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
1594 % endif
1595 % else:
1596 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1597 % if not has_no_sources:
1598 $(${tgt.name.upper()}_OBJS)\
1599 % endif
1600 % endif
1601 % for dep in tgt.deps:
1602 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1603 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001604
Craig Tiller32173c52016-03-17 14:12:45 -07001605 % if tgt.language == "c++" or tgt.boringssl or tgt.build == 'fuzzer':
Craig Tiller841c8802015-09-10 13:06:37 -07001606 ## C++ targets specificies.
1607 % if tgt.build == 'protoc':
1608 $(E) "[HOSTLD] Linking $@"
1609 $(Q) mkdir -p `dirname $@`
1610 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) \
1611 % if not has_no_sources:
1612 $(${tgt.name.upper()}_OBJS)\
1613 % endif
1614 % else:
1615 $(E) "[LD] Linking $@"
1616 $(Q) mkdir -p `dirname $@`
1617 $(Q) $(LDXX) $(LDFLAGS) \
1618 % if not has_no_sources:
1619 $(${tgt.name.upper()}_OBJS)\
1620 % endif
1621 % endif
1622 % else:
1623 ## C-only targets specificities.
1624 $(E) "[LD] Linking $@"
1625 $(Q) mkdir -p `dirname $@`
1626 $(Q) $(LD) $(LDFLAGS) \
1627 % if not has_no_sources:
1628 $(${tgt.name.upper()}_OBJS)\
1629 % endif
1630 % endif
1631 % for dep in tgt.deps:
1632 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1633 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001634 % if tgt.language == "c++":
1635 % if tgt.build == 'protoc':
1636 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
1637 % else:
1638 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
1639 % endif
1640 % endif
1641 % if tgt.build == 'protoc':
1642 $(HOST_LDLIBS)\
1643 % else:
1644 $(LDLIBS)\
1645 % endif
1646 % if tgt.build == 'protoc':
1647 $(HOST_LDLIBS_PROTOC)\
1648 % elif tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1649 $(LDLIBS_SECURE)\
1650 % endif
1651 % if tgt.language == 'c++' and tgt.build == 'test':
1652 $(GTEST_LIB)\
1653 % elif tgt.language == 'c++' and tgt.build == 'benchmark':
1654 $(GTEST_LIB)\
1655 % endif
Craig Tiller32173c52016-03-17 14:12:45 -07001656 % if tgt.build == 'fuzzer':
1657 -lFuzzer\
1658 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001659 -o $(BINDIR)/$(CONFIG)/${tgt.name}
1660 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001661
Craig Tiller841c8802015-09-10 13:06:37 -07001662 endif
1663 % endif
1664 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001665
Craig Tiller841c8802015-09-10 13:06:37 -07001666 endif
1667 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001668
Craig Tiller841c8802015-09-10 13:06:37 -07001669 % for src in tgt.src:
1670 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
1671 % for dep in tgt.deps:
1672 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1673 % endfor
Craig Tillerf5371ef2015-01-12 16:40:18 -08001674
Craig Tillerab230452016-01-04 08:18:43 -08001675 % if tgt.language == 'c89':
1676 % for src in tgt.src:
Craig Tillerea21ca22016-01-04 12:34:29 -08001677 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o : ${src}
1678 $(E) "[C] Compiling $<"
1679 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001680 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -std=c89 -pedantic -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Craig Tillerab230452016-01-04 08:18:43 -08001681 % endfor
1682 % endif
1683
Craig Tiller841c8802015-09-10 13:06:37 -07001684 % endfor
1685 % if not has_no_sources:
1686 deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
1687 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001688
Craig Tiller841c8802015-09-10 13:06:37 -07001689 % if not has_no_sources:
1690 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1691 ifneq ($(NO_SECURE),true)
1692 % endif
1693 ifneq ($(NO_DEPS),true)
1694 -include $(${tgt.name.upper()}_OBJS:.o=.dep)
1695 endif
1696 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1697 endif
1698 % endif
1699 % endif
Nicolas "Pixel" Noble472bb682015-11-03 19:09:01 +01001700 % for src in tgt.src:
1701 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in tgt.src):
1702 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in tgt.src if proto_re.match(src2))}
1703 % endif
1704 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001705 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001706
Craig Tiller841c8802015-09-10 13:06:37 -07001707 ifneq ($(OPENSSL_DEP),)
1708 # This is to ensure the embedded OpenSSL is built beforehand, properly
1709 # installing headers to their final destination on the drive. We need this
1710 # otherwise parallel compilation will fail if a source is compiled first.
1711 % for src in sorted(sources_that_need_openssl):
1712 % if src not in sources_that_don_t_need_openssl:
1713 ${src}: $(OPENSSL_DEP)
1714 % endif
1715 % endfor
1716 endif
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001717
Craig Tiller841c8802015-09-10 13:06:37 -07001718 .PHONY: all strip tools \
1719 dep_error openssl_dep_error openssl_dep_message git_update stop \
1720 buildtests buildtests_c buildtests_cxx \
1721 test test_c test_cxx \
1722 install install_c install_cxx \
1723 install-headers install-headers_c install-headers_cxx \
1724 install-shared install-shared_c install-shared_cxx \
1725 install-static install-static_c install-static_cxx \
1726 strip strip-shared strip-static \
1727 strip_c strip-shared_c strip-static_c \
1728 strip_cxx strip-shared_cxx strip-static_cxx \
1729 dep_c dep_cxx bins_dep_c bins_dep_cxx \
1730 clean
Craig Tillerb79c1e12016-02-23 10:00:58 -08001731
1732 .PHONY: printvars
1733 printvars:
1734 @$(foreach V,$(sort $(.VARIABLES)), \
1735 $(if $(filter-out environment% default automatic, \
1736 $(origin $V)),$(warning $V=$($V) ($(value $V)))))