blob: e84ceebf221e037cabfec0c904d6dcca95ecb7cb [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()
52 %>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080053
Craig Tiller96b49552015-01-21 16:29:01 -080054
Craig Tiller71a86042016-01-15 14:59:58 -080055 comma := ,
56
57
Craig Tiller841c8802015-09-10 13:06:37 -070058 # Basic platform detection
59 HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +010060 SYSTEM ?= $(HOST_SYSTEM)
Craig Tiller841c8802015-09-10 13:06:37 -070061 ifeq ($(SYSTEM),MSYS)
62 SYSTEM = MINGW32
63 endif
64 ifeq ($(SYSTEM),MINGW64)
65 SYSTEM = MINGW32
66 endif
Craig Tiller96b49552015-01-21 16:29:01 -080067
68
Nicolas "Pixel" Noble6dad9b02015-09-23 18:32:26 +020069 MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
Craig Tiller841c8802015-09-10 13:06:37 -070070 ifndef BUILDDIR
Nicolas "Pixel" Noble42b4c282015-09-17 23:57:08 +020071 BUILDDIR_ABSOLUTE = $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))
72 else
73 BUILDDIR_ABSOLUTE = $(abspath $(BUILDDIR))
Craig Tiller841c8802015-09-10 13:06:37 -070074 endif
Craig Tiller61b910f2015-02-15 10:54:07 -080075
Craig Tiller841c8802015-09-10 13:06:37 -070076 HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false)
77 HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false)
78 HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false)
Nicolas Noblef8681182015-03-18 14:25:44 -070079
Craig Tiller841c8802015-09-10 13:06:37 -070080 ifeq ($(HAS_CC),true)
81 DEFAULT_CC = cc
82 DEFAULT_CXX = c++
83 else
84 ifeq ($(HAS_GCC),true)
85 DEFAULT_CC = gcc
86 DEFAULT_CXX = g++
87 else
88 ifeq ($(HAS_CLANG),true)
89 DEFAULT_CC = clang
90 DEFAULT_CXX = clang++
91 else
92 DEFAULT_CC = no_c_compiler
93 DEFAULT_CXX = no_c++_compiler
94 endif
95 endif
96 endif
Nicolas Noblef8681182015-03-18 14:25:44 -070097
98
Nicolas "Pixel" Noble42b4c282015-09-17 23:57:08 +020099 BINDIR = $(BUILDDIR_ABSOLUTE)/bins
100 OBJDIR = $(BUILDDIR_ABSOLUTE)/objs
101 LIBDIR = $(BUILDDIR_ABSOLUTE)/libs
102 GENDIR = $(BUILDDIR_ABSOLUTE)/gens
Craig Tiller61b910f2015-02-15 10:54:07 -0800103
Craig Tiller841c8802015-09-10 13:06:37 -0700104 # Configurations
ctiller8cfebb92015-01-06 15:02:12 -0800105
Craig Tillera0f85172016-01-20 15:56:06 -0800106 % for name, args in configs.iteritems():
107 VALID_CONFIG_${name} = 1
108 % if args.get('compile_the_world', False):
109 REQUIRE_CUSTOM_LIBRARIES_${name} = 1
110 % endif
Craig Tilleraff3d502016-01-20 15:59:31 -0800111 % for tool, default in [('CC', 'CC'), ('CXX', 'CXX'), ('LD', 'CC'), ('LDXX', 'CXX')]:
Craig Tillera0f85172016-01-20 15:56:06 -0800112 ${tool}_${name} = ${args.get(tool, '$(DEFAULT_%s)' % default)}
113 % endfor
114 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES']:
115 % if args.get(arg, None) is not None:
116 ${arg}_${name} = ${args.get(arg)}
117 % endif
118 % endfor
119 % if args.get('timeout_multiplier', 1) != 1:
120 DEFINES_${name} += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=${args.timeout_multiplier}
121 % endif
ctiller8cfebb92015-01-06 15:02:12 -0800122
Craig Tillera0f85172016-01-20 15:56:06 -0800123 % endfor
Craig Tiller699ba212015-01-13 17:02:20 -0800124
Nicolas Noble047b7272015-01-16 13:55:05 -0800125
Craig Tiller841c8802015-09-10 13:06:37 -0700126 # General settings.
127 # You may want to change these depending on your system.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800128
Craig Tiller841c8802015-09-10 13:06:37 -0700129 prefix ?= /usr/local
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800130
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100131 PROTOC ?= protoc
132 DTRACE ?= dtrace
Craig Tiller841c8802015-09-10 13:06:37 -0700133 CONFIG ?= opt
Nicolas "Pixel" Noblefba36bc2016-01-27 03:24:03 +0100134 # Doing X ?= Y is the same as:
135 # ifeq ($(origin X), undefined)
136 # X = Y
137 # endif
138 # but some variables, such as CC, CXX, LD or AR, have defaults.
139 # So instead of using ?= on them, we need to check their origin.
140 # See:
141 # https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
142 # https://www.gnu.org/software/make/manual/html_node/Flavors.html#index-_003f_003d
143 # https://www.gnu.org/software/make/manual/html_node/Origin-Function.html
144 ifeq ($(origin CC), default)
145 CC = $(CC_$(CONFIG))
146 endif
147 ifeq ($(origin CXX), default)
148 CXX = $(CXX_$(CONFIG))
149 endif
150 ifeq ($(origin LD), default)
151 LD = $(LD_$(CONFIG))
152 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100153 LDXX ?= $(LDXX_$(CONFIG))
Craig Tiller841c8802015-09-10 13:06:37 -0700154 ifeq ($(SYSTEM),Linux)
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100155 ifeq ($(origin AR), default)
156 AR = ar rcs
157 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100158 STRIP ?= strip --strip-unneeded
Craig Tiller841c8802015-09-10 13:06:37 -0700159 else
160 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100161 ifeq ($(origin AR), default)
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100162 AR = libtool -no_warning_for_no_symbols -o
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100163 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100164 STRIP ?= strip -x
Craig Tiller841c8802015-09-10 13:06:37 -0700165 else
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100166 ifeq ($(origin AR), default)
167 AR = ar rcs
168 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100169 STRIP ?= strip
Craig Tiller841c8802015-09-10 13:06:37 -0700170 endif
171 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100172 INSTALL ?= install
173 RM ?= rm -f
174 PKG_CONFIG ?= pkg-config
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800175
Craig Tiller841c8802015-09-10 13:06:37 -0700176 ifndef VALID_CONFIG_$(CONFIG)
177 $(error Invalid CONFIG value '$(CONFIG)')
178 endif
yangg102e4fe2015-01-06 16:02:50 -0800179
Craig Tiller841c8802015-09-10 13:06:37 -0700180 ifeq ($(SYSTEM),Linux)
181 TMPOUT = /dev/null
182 else
183 TMPOUT = `mktemp /tmp/test-out-XXXXXX`
184 endif
Nicolas Noble047b7272015-01-16 13:55:05 -0800185
Craig Tiller841c8802015-09-10 13:06:37 -0700186 # Detect if we can use C++11
187 CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc
188 HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false)
Craig Tillercf133f42015-02-26 14:05:56 -0800189
Craig Tiller804b8552016-02-23 16:50:24 -0800190 CHECK_SHADOW_WORKS_CMD = $(CC) -std=c99 -Werror -Wshadow -o $(TMPOUT) -c test/build/shadow.c
191 HAS_WORKING_SHADOW = $(shell $(CHECK_SHADOW_WORKS_CMD) 2> /dev/null && echo true || echo false)
192 ifeq ($(HAS_WORKING_SHADOW),true)
193 W_SHADOW=-Wshadow
194 endif
195
Craig Tiller82f3f0d2016-01-25 11:27:42 -0800196 CHECK_NO_SHIFT_NEGATIVE_VALUE_CMD = $(CC) -std=c99 -Werror -Wno-shift-negative-value -o $(TMPOUT) -c test/build/empty.c
Craig Tiller16872b82016-01-25 10:55:20 -0800197 HAS_NO_SHIFT_NEGATIVE_VALUE = $(shell $(CHECK_NO_SHIFT_NEGATIVE_VALUE_CMD) 2> /dev/null && echo true || echo false)
198 ifeq ($(HAS_NO_SHIFT_NEGATIVE_VALUE),true)
199 W_NO_SHIFT_NEGATIVE_VALUE=-Wno-shift-negative-value
200 endif
201
Craig Tiller841c8802015-09-10 13:06:37 -0700202 # The HOST compiler settings are used to compile the protoc plugins.
203 # In most cases, you won't have to change anything, but if you are
204 # cross-compiling, you can override these variables from GNU make's
205 # command line: make CC=cross-gcc HOST_CC=gcc
Nicolas Noble047b7272015-01-16 13:55:05 -0800206
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100207 HOST_CC ?= $(CC)
208 HOST_CXX ?= $(CXX)
209 HOST_LD ?= $(LD)
210 HOST_LDXX ?= $(LDXX)
nnoble72309c62014-12-12 11:42:26 -0800211
Craig Tiller841c8802015-09-10 13:06:37 -0700212 ifdef EXTRA_DEFINES
213 DEFINES += $(EXTRA_DEFINES)
214 endif
Craig Tiller86fa1c52015-02-27 09:57:58 -0800215
Craig Tiller804b8552016-02-23 16:50:24 -0800216 CFLAGS += -std=c99 -Wsign-conversion -Wconversion $(W_SHADOW)
Craig Tiller841c8802015-09-10 13:06:37 -0700217 ifeq ($(HAS_CXX11),true)
218 CXXFLAGS += -std=c++11
219 else
220 CXXFLAGS += -std=c++0x
221 endif
Nicolas "Pixel" Noble51b1aee2016-01-28 01:14:58 +0100222 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES']:
223 % if defaults.get('global', []).get(arg, None) is not None:
224 ${arg} += ${defaults.get('global').get(arg)}
225 % endif
226 % endfor
Nicolas Noblef8681182015-03-18 14:25:44 -0700227
Craig Tiller841c8802015-09-10 13:06:37 -0700228 CPPFLAGS += $(CPPFLAGS_$(CONFIG))
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800229 CFLAGS += $(CFLAGS_$(CONFIG))
230 CXXFLAGS += $(CXXFLAGS_$(CONFIG))
Craig Tiller841c8802015-09-10 13:06:37 -0700231 DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
232 LDFLAGS += $(LDFLAGS_$(CONFIG))
Nicolas "Pixel" Noble482d7612015-07-16 23:43:30 +0200233
Craig Tiller841c8802015-09-10 13:06:37 -0700234 ifneq ($(SYSTEM),MINGW32)
235 PIC_CPPFLAGS = -fPIC
236 CPPFLAGS += -fPIC
237 LDFLAGS += -fPIC
238 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800239
Craig Tiller841c8802015-09-10 13:06:37 -0700240 INCLUDES = . include $(GENDIR)
241 LDFLAGS += -Llibs/$(CONFIG)
Nicolas "Pixel" Noble3adab742015-06-02 00:33:06 +0200242
Craig Tiller841c8802015-09-10 13:06:37 -0700243 ifeq ($(SYSTEM),Darwin)
244 ifneq ($(wildcard /usr/local/ssl/include),)
245 INCLUDES += /usr/local/ssl/include
246 endif
247 ifneq ($(wildcard /opt/local/include),)
248 INCLUDES += /opt/local/include
249 endif
250 ifneq ($(wildcard /usr/local/include),)
251 INCLUDES += /usr/local/include
252 endif
253 LIBS = m z
254 ifneq ($(wildcard /usr/local/ssl/lib),)
255 LDFLAGS += -L/usr/local/ssl/lib
256 endif
257 ifneq ($(wildcard /opt/local/lib),)
258 LDFLAGS += -L/opt/local/lib
259 endif
260 ifneq ($(wildcard /usr/local/lib),)
261 LDFLAGS += -L/usr/local/lib
262 endif
263 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700264
Craig Tiller841c8802015-09-10 13:06:37 -0700265 ifeq ($(SYSTEM),Linux)
Craig Tiller1b1e2382016-02-03 07:33:56 -0800266 LIBS = dl rt m pthread
Craig Tiller841c8802015-09-10 13:06:37 -0700267 LDFLAGS += -pthread
268 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800269
Craig Tiller841c8802015-09-10 13:06:37 -0700270 ifeq ($(SYSTEM),MINGW32)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100271 LIBS = m pthread ws2_32
Craig Tiller841c8802015-09-10 13:06:37 -0700272 LDFLAGS += -pthread
273 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700274
Craig Tiller841c8802015-09-10 13:06:37 -0700275 GTEST_LIB = -Ithird_party/googletest/include -Ithird_party/googletest third_party/googletest/src/gtest-all.cc
276 GTEST_LIB += -lgflags
277 ifeq ($(V),1)
278 E = @:
279 Q =
280 else
281 E = @echo
282 Q = @
283 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800284
Craig Tillerf008f062016-02-08 12:48:03 -0800285 VERSION = ${settings.core_version}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800286
Craig Tiller841c8802015-09-10 13:06:37 -0700287 CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
288 CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800289
Craig Tiller841c8802015-09-10 13:06:37 -0700290 LDFLAGS += $(ARCH_FLAGS)
291 LDLIBS += $(addprefix -l, $(LIBS))
292 LDLIBSXX += $(addprefix -l, $(LIBSXX))
nnoble72309c62014-12-12 11:42:26 -0800293
Craig Tiller841c8802015-09-10 13:06:37 -0700294 HOST_CPPFLAGS = $(CPPFLAGS)
295 HOST_CFLAGS = $(CFLAGS)
296 HOST_CXXFLAGS = $(CXXFLAGS)
297 HOST_LDFLAGS = $(LDFLAGS)
298 HOST_LDLIBS = $(LDLIBS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800299
Craig Tiller841c8802015-09-10 13:06:37 -0700300 # These are automatically computed variables.
301 # There shouldn't be any need to change anything from now on.
nnoble69ac39f2014-12-12 15:43:38 -0800302
Craig Tiller841c8802015-09-10 13:06:37 -0700303 -include cache.mk
murgatroid9924e2f4a2015-06-29 11:12:01 -0700304
Craig Tiller841c8802015-09-10 13:06:37 -0700305 CACHE_MK =
murgatroid99aa521572015-07-10 14:49:12 -0700306
Craig Tiller841c8802015-09-10 13:06:37 -0700307 HAS_PKG_CONFIG ?= $(shell command -v $(PKG_CONFIG) >/dev/null 2>&1 && echo true || echo false)
murgatroid99aa521572015-07-10 14:49:12 -0700308
Craig Tiller841c8802015-09-10 13:06:37 -0700309 ifeq ($(HAS_PKG_CONFIG), true)
310 CACHE_MK += HAS_PKG_CONFIG = true,
311 endif
nnoble69ac39f2014-12-12 15:43:38 -0800312
Craig Tiller841c8802015-09-10 13:06:37 -0700313 PC_TEMPLATE = prefix=$(prefix),\
314 exec_prefix=${'\$${prefix}'},\
315 includedir=${'\$${prefix}'}/include,\
316 libdir=${'\$${exec_prefix}'}/lib,\
317 ,\
318 Name: $(PC_NAME),\
319 Description: $(PC_DESCRIPTION),\
320 Version: $(VERSION),\
321 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
322 Requires.private: $(PC_REQUIRES_PRIVATE),\
323 Libs: -L${'\$${libdir}'} $(PC_LIB),\
324 Libs.private: $(PC_LIBS_PRIVATE)
murgatroid998faab232015-06-30 17:24:21 -0700325
Craig Tiller841c8802015-09-10 13:06:37 -0700326 ifeq ($(SYSTEM),MINGW32)
327 SHARED_EXT = dll
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100328 SHARED_PREFIX =
Craig Tillerf008f062016-02-08 12:48:03 -0800329 SHARED_VERSION = -${settings.core_version.major}
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100330 else ifeq ($(SYSTEM),Darwin)
Craig Tiller841c8802015-09-10 13:06:37 -0700331 SHARED_EXT = dylib
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100332 SHARED_PREFIX = lib
333 SHARED_VERSION =
334 else
Craig Tiller841c8802015-09-10 13:06:37 -0700335 SHARED_EXT = so.$(VERSION)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100336 SHARED_PREFIX = lib
337 SHARED_VERSION =
Craig Tiller841c8802015-09-10 13:06:37 -0700338 endif
nnoble5b7f32a2014-12-22 08:12:44 -0800339
Craig Tiller841c8802015-09-10 13:06:37 -0700340 ifeq ($(wildcard .git),)
341 IS_GIT_FOLDER = false
342 else
343 IS_GIT_FOLDER = true
344 endif
nnoble69ac39f2014-12-12 15:43:38 -0800345
Craig Tiller841c8802015-09-10 13:06:37 -0700346 ifeq ($(HAS_PKG_CONFIG),true)
347 OPENSSL_ALPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.2 openssl
348 OPENSSL_NPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.1 openssl
349 ZLIB_CHECK_CMD = $(PKG_CONFIG) --exists zlib
350 PROTOBUF_CHECK_CMD = $(PKG_CONFIG) --atleast-version=3.0.0-alpha-3 protobuf
351 else # HAS_PKG_CONFIG
murgatroid9924e2f4a2015-06-29 11:12:01 -0700352
Craig Tiller841c8802015-09-10 13:06:37 -0700353 ifeq ($(SYSTEM),MINGW32)
354 OPENSSL_LIBS = ssl32 eay32
355 else
356 OPENSSL_LIBS = ssl crypto
357 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700358
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100359 OPENSSL_ALPN_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
360 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 -0800361 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 +0100362 ZLIB_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
363 PROTOBUF_CHECK_CMD = $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
Craig Tiller297fafa2015-01-15 15:46:39 -0800364
Craig Tiller841c8802015-09-10 13:06:37 -0700365 endif # HAS_PKG_CONFIG
murgatroid9924e2f4a2015-06-29 11:12:01 -0700366
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100367 PERFTOOLS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
murgatroid996d9e4012015-07-08 10:22:45 -0700368
Craig Tiller841c8802015-09-10 13:06:37 -0700369 PROTOC_CHECK_CMD = which protoc > /dev/null
370 PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3
371 DTRACE_CHECK_CMD = which dtrace > /dev/null
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100372 SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS)
373 ZOOKEEPER_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/zookeeper.c $(LDFLAGS) -lzookeeper_mt
murgatroid9924e2f4a2015-06-29 11:12:01 -0700374
Craig Tiller841c8802015-09-10 13:06:37 -0700375 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
376 HAS_SYSTEM_PERFTOOLS ?= $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
377 ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
378 DEFINES += GRPC_HAVE_PERFTOOLS
379 LIBS += profiler
380 CACHE_MK += HAS_SYSTEM_PERFTOOLS = true,
381 endif
382 endif
nnoble69ac39f2014-12-12 15:43:38 -0800383
Craig Tiller841c8802015-09-10 13:06:37 -0700384 HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
385 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
386 HAS_SYSTEM_OPENSSL_ALPN ?= $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
387 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
388 HAS_SYSTEM_OPENSSL_NPN = true
389 CACHE_MK += HAS_SYSTEM_OPENSSL_ALPN = true,
390 else
391 HAS_SYSTEM_OPENSSL_NPN ?= $(shell $(OPENSSL_NPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
392 endif
393 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
394 CACHE_MK += HAS_SYSTEM_OPENSSL_NPN = true,
395 endif
396 HAS_SYSTEM_ZLIB ?= $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
397 ifeq ($(HAS_SYSTEM_ZLIB),true)
398 CACHE_MK += HAS_SYSTEM_ZLIB = true,
399 endif
400 HAS_SYSTEM_PROTOBUF ?= $(HAS_SYSTEM_PROTOBUF_VERIFY)
401 ifeq ($(HAS_SYSTEM_PROTOBUF),true)
402 CACHE_MK += HAS_SYSTEM_PROTOBUF = true,
403 endif
404 else
405 # override system libraries if the config requires a custom compiled library
406 HAS_SYSTEM_OPENSSL_ALPN = false
407 HAS_SYSTEM_OPENSSL_NPN = false
408 HAS_SYSTEM_ZLIB = false
409 HAS_SYSTEM_PROTOBUF = false
410 endif
nnoble69ac39f2014-12-12 15:43:38 -0800411
Craig Tiller841c8802015-09-10 13:06:37 -0700412 HAS_PROTOC ?= $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
413 ifeq ($(HAS_PROTOC),true)
414 CACHE_MK += HAS_PROTOC = true,
415 HAS_VALID_PROTOC ?= $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false)
416 ifeq ($(HAS_VALID_PROTOC),true)
417 CACHE_MK += HAS_VALID_PROTOC = true,
418 endif
419 else
420 HAS_VALID_PROTOC = false
421 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800422
Craig Tiller841c8802015-09-10 13:06:37 -0700423 # Check for Systemtap (https://sourceware.org/systemtap/), first by making sure <sys/sdt.h> is present
424 # in the system and secondly by checking for the "dtrace" binary (on Linux, this is part of the Systemtap
425 # distribution. It's part of the base system on BSD/Solaris machines).
426 ifndef HAS_SYSTEMTAP
427 HAS_SYSTEMTAP_HEADERS = $(shell $(SYSTEMTAP_HEADERS_CHECK_CMD) 2> /dev/null && echo true || echo false)
428 HAS_DTRACE = $(shell $(DTRACE_CHECK_CMD) 2> /dev/null && echo true || echo false)
429 HAS_SYSTEMTAP = false
430 ifeq ($(HAS_SYSTEMTAP_HEADERS),true)
431 ifeq ($(HAS_DTRACE),true)
432 HAS_SYSTEMTAP = true
433 endif
434 endif
435 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -0700436
Craig Tiller841c8802015-09-10 13:06:37 -0700437 ifeq ($(HAS_SYSTEMTAP),true)
438 CACHE_MK += HAS_SYSTEMTAP = true,
439 endif
nnoble69ac39f2014-12-12 15:43:38 -0800440
Craig Tiller841c8802015-09-10 13:06:37 -0700441 HAS_ZOOKEEPER = $(shell $(ZOOKEEPER_CHECK_CMD) 2> /dev/null && echo true || echo false)
Hongwei Wanga8cc4392015-07-16 17:37:47 -0700442
Craig Tiller841c8802015-09-10 13:06:37 -0700443 # Note that for testing purposes, one can do:
444 # make HAS_EMBEDDED_OPENSSL_ALPN=false
445 # to emulate the fact we do not have OpenSSL in the third_party folder.
Craig Tillerb79c1e12016-02-23 10:00:58 -0800446 ifneq ($(wildcard third_party/${openssl_fallback.extraction_dir}/libssl.a),)
447 HAS_EMBEDDED_OPENSSL_ALPN = third_party/${openssl_fallback.extraction_dir}
448 else ifeq ($(wildcard third_party/boringssl/include/openssl/ssl.h),)
Craig Tiller841c8802015-09-10 13:06:37 -0700449 HAS_EMBEDDED_OPENSSL_ALPN = false
450 else
Craig Tillerb79c1e12016-02-23 10:00:58 -0800451 CAN_COMPILE_EMBEDDED_OPENSSL ?= $(shell $(BORINGSSL_COMPILE_CHECK_CMD) 2> /dev/null && echo true || echo false)
452 HAS_EMBEDDED_OPENSSL_ALPN = $(CAN_COMPILE_EMBEDDED_OPENSSL)
Craig Tiller841c8802015-09-10 13:06:37 -0700453 endif
nnoble69ac39f2014-12-12 15:43:38 -0800454
Craig Tiller841c8802015-09-10 13:06:37 -0700455 ifeq ($(wildcard third_party/zlib/zlib.h),)
456 HAS_EMBEDDED_ZLIB = false
457 else
458 HAS_EMBEDDED_ZLIB = true
459 endif
nnoble69ac39f2014-12-12 15:43:38 -0800460
Craig Tiller841c8802015-09-10 13:06:37 -0700461 ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
462 HAS_EMBEDDED_PROTOBUF = false
463 ifneq ($(HAS_VALID_PROTOC),true)
464 NO_PROTOC = true
465 endif
466 else
467 HAS_EMBEDDED_PROTOBUF = true
468 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800469
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100470 PC_REQUIRES_GRPC =
Craig Tiller841c8802015-09-10 13:06:37 -0700471 PC_LIBS_GRPC =
murgatroid998faab232015-06-30 17:24:21 -0700472
Craig Tiller841c8802015-09-10 13:06:37 -0700473 ifeq ($(HAS_SYSTEM_ZLIB),false)
Craig Tiller3dca23a2016-01-21 11:44:55 -0800474 ifeq ($(HAS_EMBEDDED_ZLIB), true)
475 EMBED_ZLIB ?= true
Craig Tiller841c8802015-09-10 13:06:37 -0700476 else
477 DEP_MISSING += zlib
Craig Tiller3dca23a2016-01-21 11:44:55 -0800478 EMBED_ZLIB ?= broken
Craig Tiller841c8802015-09-10 13:06:37 -0700479 endif
480 else
Craig Tiller3dca23a2016-01-21 11:44:55 -0800481 EMBED_ZLIB ?= false
482 endif
483
484 ifeq ($(EMBED_ZLIB),true)
485 ZLIB_DEP = $(LIBDIR)/$(CONFIG)/libz.a
486 ZLIB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libz.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +0100487 ZLIB_MERGE_OBJS = $(LIBZ_OBJS)
Craig Tiller3dca23a2016-01-21 11:44:55 -0800488 CPPFLAGS += -Ithird_party/zlib
489 LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib
490 else
Craig Tiller841c8802015-09-10 13:06:37 -0700491 ifeq ($(HAS_PKG_CONFIG),true)
492 CPPFLAGS += $(shell $(PKG_CONFIG) --cflags zlib)
493 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L zlib)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800494 LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l zlib))
Craig Tiller841c8802015-09-10 13:06:37 -0700495 PC_REQUIRES_GRPC += zlib
496 else
497 PC_LIBS_GRPC += -lz
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800498 LIBS += z
Craig Tiller841c8802015-09-10 13:06:37 -0700499 endif
500 endif
nnoble69ac39f2014-12-12 15:43:38 -0800501
Craig Tiller841c8802015-09-10 13:06:37 -0700502 OPENSSL_PKG_CONFIG = false
murgatroid99da7a9942015-06-29 14:57:37 -0700503
Craig Tiller841c8802015-09-10 13:06:37 -0700504 PC_REQUIRES_SECURE =
505 PC_LIBS_SECURE =
murgatroid998faab232015-06-30 17:24:21 -0700506
Craig Tiller841c8802015-09-10 13:06:37 -0700507 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800508 EMBED_OPENSSL ?= false
509 NO_SECURE ?= false
510 else # HAS_SYSTEM_OPENSSL_ALPN=false
Craig Tillerb79c1e12016-02-23 10:00:58 -0800511 ifneq ($(HAS_EMBEDDED_OPENSSL_ALPN),false)
512 EMBED_OPENSSL ?= $(HAS_EMBEDDED_OPENSSL_ALPN)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800513 NO_SECURE ?= false
514 else # HAS_EMBEDDED_OPENSSL_ALPN=false
515 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
516 EMBED_OPENSSL ?= false
517 NO_SECURE ?= false
518 else
519 NO_SECURE ?= true
520 endif # HAS_SYSTEM_OPENSSL_NPN=true
521 endif # HAS_EMBEDDED_OPENSSL_ALPN
522 endif # HAS_SYSTEM_OPENSSL_ALPN
523
524 OPENSSL_DEP :=
525 OPENSSL_MERGE_LIBS :=
526 ifeq ($(NO_SECURE),false)
527 ifeq ($(EMBED_OPENSSL),true)
528 OPENSSL_DEP += $(LIBDIR)/$(CONFIG)/libboringssl.a
529 OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/libboringssl.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +0100530 OPENSSL_MERGE_OBJS += $(LIBBORINGSSL_OBJS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800531 # need to prefix these to ensure overriding system libraries
532 CPPFLAGS := -Ithird_party/boringssl/include $(CPPFLAGS)
Craig Tillerb79c1e12016-02-23 10:00:58 -0800533 else ifneq ($(EMBED_OPENSSL),false)
534 OPENSSL_DEP += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
535 OPENSSL_MERGE_LIBS += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
536 OPENSSL_MERGE_OBJS += $(wildcard $(EMBED_OPENSSL)/grpc_obj/*.o)
537 # need to prefix these to ensure overriding system libraries
538 CPPFLAGS := -I$(EMBED_OPENSSL)/include $(CPPFLAGS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800539 else # EMBED_OPENSSL=false
Craig Tiller841c8802015-09-10 13:06:37 -0700540 ifeq ($(HAS_PKG_CONFIG),true)
541 OPENSSL_PKG_CONFIG = true
542 PC_REQUIRES_SECURE = openssl
543 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags openssl) $(CPPFLAGS)
544 LDFLAGS_OPENSSL_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L openssl)
545 ifeq ($(SYSTEM),Linux)
546 ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),)
547 LDFLAGS_OPENSSL_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L openssl | sed s/L/Wl,-rpath,/)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800548 endif # LDFLAGS_OPENSSL_PKG_CONFIG=''
549 endif # System=Linux
Craig Tiller841c8802015-09-10 13:06:37 -0700550 LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800551 else # HAS_PKG_CONFIG=false
Craig Tiller841c8802015-09-10 13:06:37 -0700552 LIBS_SECURE = $(OPENSSL_LIBS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800553 endif # HAS_PKG_CONFIG
554 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
555 CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0
556 LIBS_SECURE = $(OPENSSL_LIBS)
557 endif # HAS_SYSTEM_OPENSSL_NPN
Craig Tiller841c8802015-09-10 13:06:37 -0700558 PC_LIBS_SECURE = $(addprefix -l, $(LIBS_SECURE))
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800559 endif # EMBED_OPENSSL
560 endif # NO_SECURE
nnoble69ac39f2014-12-12 15:43:38 -0800561
Craig Tiller841c8802015-09-10 13:06:37 -0700562 ifeq ($(OPENSSL_PKG_CONFIG),true)
563 LDLIBS_SECURE += $(shell $(PKG_CONFIG) --libs-only-l openssl)
564 else
565 LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
566 endif
nnoble5b7f32a2014-12-22 08:12:44 -0800567
Craig Tiller841c8802015-09-10 13:06:37 -0700568 # grpc .pc file
569 PC_NAME = gRPC
Craig Tillerda179ce2016-02-09 12:01:53 -0800570 PC_DESCRIPTION = high performance general RPC framework
571 PC_CFLAGS =
572 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC) $(PC_REQUIRES_SECURE)
Craig Tiller841c8802015-09-10 13:06:37 -0700573 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) $(PC_LIBS_SECURE)
574 PC_LIB = -lgrpc
575 GRPC_PC_FILE := $(PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700576
Craig Tiller4a67be42016-02-09 12:40:32 -0800577 # grpc_unsecure .pc file
Craig Tiller841c8802015-09-10 13:06:37 -0700578 PC_NAME = gRPC unsecure
Craig Tillerda179ce2016-02-09 12:01:53 -0800579 PC_DESCRIPTION = high performance general RPC framework without SSL
580 PC_CFLAGS =
581 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC)
Craig Tiller841c8802015-09-10 13:06:37 -0700582 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC)
583 PC_LIB = -lgrpc
584 GRPC_UNSECURE_PC_FILE := $(PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700585
Craig Tiller4a67be42016-02-09 12:40:32 -0800586 # grpc_zookeeper .pc file
Craig Tiller841c8802015-09-10 13:06:37 -0700587 PC_NAME = gRPC zookeeper
588 PC_DESCRIPTION = gRPC's zookeeper plugin
589 PC_CFLAGS =
590 PC_REQUIRES_PRIVATE =
591 PC_LIBS_PRIVATE = -lzookeeper_mt
592 GRPC_ZOOKEEPER_PC_FILE := $(PC_TEMPLATE)
Hongwei Wanga8cc4392015-07-16 17:37:47 -0700593
Craig Tiller841c8802015-09-10 13:06:37 -0700594 PROTOBUF_PKG_CONFIG = false
murgatroid99da7a9942015-06-29 14:57:37 -0700595
Craig Tiller841c8802015-09-10 13:06:37 -0700596 PC_REQUIRES_GRPCXX =
597 PC_LIBS_GRPCXX =
murgatroid998faab232015-06-30 17:24:21 -0700598
Craig Tiller841c8802015-09-10 13:06:37 -0700599 CPPFLAGS := -Ithird_party/googletest/include $(CPPFLAGS)
Craig Tiller16f6dac2015-08-24 17:00:04 -0700600
Craig Tiller841c8802015-09-10 13:06:37 -0700601 ifeq ($(HAS_SYSTEM_PROTOBUF),true)
602 ifeq ($(HAS_PKG_CONFIG),true)
603 PROTOBUF_PKG_CONFIG = true
604 PC_REQUIRES_GRPCXX = protobuf
605 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags protobuf) $(CPPFLAGS)
606 LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L protobuf)
607 ifeq ($(SYSTEM),Linux)
608 ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),)
609 LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L protobuf | sed s/L/Wl,-rpath,/)
610 endif
611 endif
612 else
613 PC_LIBS_GRPCXX = -lprotobuf
614 endif
615 else
616 ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
617 PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
618 CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
619 LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
620 PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
621 else
622 NO_PROTOBUF = true
623 endif
624 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800625
Craig Tiller841c8802015-09-10 13:06:37 -0700626 LIBS_PROTOBUF = protobuf
627 LIBS_PROTOC = protoc protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800628
Craig Tiller841c8802015-09-10 13:06:37 -0700629 HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
Nicolas Noble53830622015-02-12 16:56:38 -0800630
Craig Tiller841c8802015-09-10 13:06:37 -0700631 ifeq ($(PROTOBUF_PKG_CONFIG),true)
632 LDLIBS_PROTOBUF += $(shell $(PKG_CONFIG) --libs-only-l protobuf)
633 else
634 LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
635 endif
murgatroid9924e2f4a2015-06-29 11:12:01 -0700636
Craig Tiller841c8802015-09-10 13:06:37 -0700637 # grpc++ .pc file
638 PC_NAME = gRPC++
639 PC_DESCRIPTION = C++ wrapper for gRPC
640 PC_CFLAGS =
641 PC_REQUIRES_PRIVATE = grpc $(PC_REQUIRES_GRPCXX)
642 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
643 PC_LIB = -lgrpc++
644 GRPCXX_PC_FILE := $(PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700645
Craig Tiller841c8802015-09-10 13:06:37 -0700646 # grpc++_unsecure .pc file
647 PC_NAME = gRPC++ unsecure
648 PC_DESCRIPTION = C++ wrapper for gRPC without SSL
649 PC_CFLAGS =
650 PC_REQUIRES_PRIVATE = grpc_unsecure $(PC_REQUIRES_GRPCXX)
651 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
652 PC_LIB = -lgrpc++
653 GRPCXX_UNSECURE_PC_FILE := $(PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700654
Craig Tiller841c8802015-09-10 13:06:37 -0700655 ifeq ($(MAKECMDGOALS),clean)
656 NO_DEPS = true
657 endif
nnoble69ac39f2014-12-12 15:43:38 -0800658
Craig Tiller841c8802015-09-10 13:06:37 -0700659 INSTALL_OK = false
660 ifeq ($(HAS_VALID_PROTOC),true)
661 ifeq ($(HAS_SYSTEM_PROTOBUF_VERIFY),true)
662 INSTALL_OK = true
663 endif
664 endif
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100665
Craig Tiller841c8802015-09-10 13:06:37 -0700666 .SECONDARY = %.pb.h %.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800667
Craig Tiller841c8802015-09-10 13:06:37 -0700668 PROTOC_PLUGINS =\
669 % for tgt in targets:
670 % if tgt.build == 'protoc':
671 $(BINDIR)/$(CONFIG)/${tgt.name}\
672 % endif
673 % endfor
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800674
Craig Tiller841c8802015-09-10 13:06:37 -0700675 ifeq ($(DEP_MISSING),)
676 all: static shared plugins\
677 % for tgt in targets:
678 % if tgt.build == 'all':
679 $(BINDIR)/$(CONFIG)/${tgt.name}\
680 % endif
681 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800682
Craig Tiller841c8802015-09-10 13:06:37 -0700683 dep_error:
684 @echo "You shouldn't see this message - all of your dependencies are correct."
685 else
686 all: dep_error git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800687
Craig Tiller841c8802015-09-10 13:06:37 -0700688 dep_error:
689 @echo
690 @echo "DEPENDENCY ERROR"
691 @echo
692 @echo "You are missing system dependencies that are essential to build grpc,"
693 @echo "and the third_party directory doesn't have them:"
694 @echo
695 @echo " $(DEP_MISSING)"
696 @echo
697 @echo "Installing the development packages for your system will solve"
698 @echo "this issue. Please consult INSTALL to get more information."
699 @echo
700 @echo "If you need information about why these tests failed, run:"
701 @echo
702 @echo " make run_dep_checks"
703 @echo
704 endif
nnoble69ac39f2014-12-12 15:43:38 -0800705
Craig Tiller841c8802015-09-10 13:06:37 -0700706 git_update:
707 ifeq ($(IS_GIT_FOLDER),true)
708 @echo "Additionally, since you are in a git clone, you can download the"
709 @echo "missing dependencies in third_party by running the following command:"
710 @echo
711 @echo " git submodule update --init"
712 @echo
713 endif
nnoble69ac39f2014-12-12 15:43:38 -0800714
Craig Tiller841c8802015-09-10 13:06:37 -0700715 openssl_dep_error: openssl_dep_message git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800716
Craig Tiller841c8802015-09-10 13:06:37 -0700717 protobuf_dep_error: protobuf_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800718
Craig Tiller841c8802015-09-10 13:06:37 -0700719 protoc_dep_error: protoc_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800720
Craig Tiller841c8802015-09-10 13:06:37 -0700721 openssl_dep_message:
722 @echo
723 @echo "DEPENDENCY ERROR"
724 @echo
Craig Tillerb79c1e12016-02-23 10:00:58 -0800725 @echo "The target you are trying to run requires an OpenSSL implementation."
726 @echo "Your system doesn't have one, and either the third_party directory"
727 @echo "doesn't have it, or your compiler can't build BoringSSL."
Craig Tiller841c8802015-09-10 13:06:37 -0700728 @echo
729 @echo "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
nnoble69ac39f2014-12-12 15:43:38 -0800735
Craig Tiller841c8802015-09-10 13:06:37 -0700736 protobuf_dep_message:
737 @echo
738 @echo "DEPENDENCY ERROR"
739 @echo
740 @echo "The target you are trying to run requires protobuf 3.0.0+"
741 @echo "Your system doesn't have it, and neither does the third_party directory."
742 @echo
743 @echo "Please consult INSTALL to get more information."
744 @echo
745 @echo "If you need information about why these tests failed, run:"
746 @echo
747 @echo " make run_dep_checks"
748 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800749
Craig Tiller841c8802015-09-10 13:06:37 -0700750 protoc_dep_message:
751 @echo
752 @echo "DEPENDENCY ERROR"
753 @echo
754 @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
755 @echo "Your system doesn't have it, and neither does the third_party directory."
756 @echo
757 @echo "Please consult INSTALL to get more information."
758 @echo
759 @echo "If you need information about why these tests failed, run:"
760 @echo
761 @echo " make run_dep_checks"
762 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800763
Craig Tiller841c8802015-09-10 13:06:37 -0700764 systemtap_dep_error:
765 @echo
766 @echo "DEPENDENCY ERROR"
767 @echo
768 @echo "Under the '$(CONFIG)' configutation, the target you are trying "
769 @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other "
770 @echo "platforms such as Solaris and *BSD). "
771 @echo
772 @echo "Please consult INSTALL to get more information."
773 @echo
David Garcia Quintas8954e902015-04-29 09:46:33 -0700774
Craig Tiller841c8802015-09-10 13:06:37 -0700775 stop:
776 @false
nnoble69ac39f2014-12-12 15:43:38 -0800777
Craig Tiller841c8802015-09-10 13:06:37 -0700778 % for tgt in targets:
779 ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
780 % endfor
ctiller09cb6d52014-12-19 17:38:22 -0800781
Craig Tiller841c8802015-09-10 13:06:37 -0700782 run_dep_checks:
783 $(OPENSSL_ALPN_CHECK_CMD) || true
784 $(OPENSSL_NPN_CHECK_CMD) || true
785 $(ZLIB_CHECK_CMD) || true
786 $(PERFTOOLS_CHECK_CMD) || true
787 $(PROTOBUF_CHECK_CMD) || true
788 $(PROTOC_CHECK_VERSION_CMD) || true
789 $(ZOOKEEPER_CHECK_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800790
Craig Tiller841c8802015-09-10 13:06:37 -0700791 third_party/protobuf/configure:
792 $(E) "[AUTOGEN] Preparing protobuf"
793 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
Nicolas Noble53830622015-02-12 16:56:38 -0800794
Craig Tiller841c8802015-09-10 13:06:37 -0700795 $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
796 $(E) "[MAKE] Building protobuf"
797 $(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)
798 $(Q)$(MAKE) -C third_party/protobuf clean
799 $(Q)$(MAKE) -C third_party/protobuf
800 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
801 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
802 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
803 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
804 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800805
Craig Tiller841c8802015-09-10 13:06:37 -0700806 static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800807
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100808 static_c: pc_c pc_c_unsecure cache.mk pc_c_zookeeper\
Craig Tiller841c8802015-09-10 13:06:37 -0700809 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100810 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700811 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
812 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
813 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100814 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700815 % endfor
816 static_zookeeper_libs
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800817
818
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100819 static_cxx: pc_cxx pc_cxx_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700820 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100821 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700822 % if lib.build == 'all' and lib.language == 'c++':
823 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
824 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100825 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700826 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800827
828
Craig Tiller841c8802015-09-10 13:06:37 -0700829 shared: shared_c shared_cxx
nnoble29e1d292014-12-01 10:27:40 -0800830
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100831 shared_c: pc_c pc_c_unsecure cache.mk pc_c_zookeeper\
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):
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100835 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)\
Craig Tiller841c8802015-09-10 13:06:37 -0700836 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100837 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700838 % endfor
839 shared_zookeeper_libs
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800840
Craig Tiller841c8802015-09-10 13:06:37 -0700841 shared_cxx: pc_cxx pc_cxx_unsecure cache.mk\
842 % 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++':
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100845 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)\
Craig Tiller841c8802015-09-10 13:06:37 -0700846 % 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_csharp: shared_c \
852 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100853 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700854 % if lib.build == 'all' and lib.language == 'csharp':
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100855 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)\
Craig Tiller841c8802015-09-10 13:06:37 -0700856 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100857 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700858 % endfor
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800859
Craig Tiller841c8802015-09-10 13:06:37 -0700860 ifeq ($(HAS_ZOOKEEPER),true)
861 static_zookeeper_libs:\
862 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100863 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700864 % if lib.build == 'all' and lib.language == 'c' and 'zookeeper' in lib.get('external_deps', []):
865 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
866 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100867 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700868 % endfor
Hongwei Wanga8cc4392015-07-16 17:37:47 -0700869
Craig Tiller841c8802015-09-10 13:06:37 -0700870 shared_zookeeper_libs:\
871 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100872 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700873 % if lib.build == 'all' and lib.language == 'c' and 'zookeeper' in lib.get('external_deps', []):
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100874 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)\
Craig Tiller841c8802015-09-10 13:06:37 -0700875 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100876 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700877 % endfor
Hongwei Wanga8cc4392015-07-16 17:37:47 -0700878
Craig Tiller841c8802015-09-10 13:06:37 -0700879 else
Hongwei Wanga8cc4392015-07-16 17:37:47 -0700880
Craig Tiller841c8802015-09-10 13:06:37 -0700881 static_zookeeper_libs:
Hongwei Wanga8cc4392015-07-16 17:37:47 -0700882
Craig Tiller841c8802015-09-10 13:06:37 -0700883 shared_zookeeper_libs:
Hongwei Wanga8cc4392015-07-16 17:37:47 -0700884
Craig Tiller841c8802015-09-10 13:06:37 -0700885 endif
Hongwei Wanga8cc4392015-07-16 17:37:47 -0700886
Craig Tiller841c8802015-09-10 13:06:37 -0700887 grpc_csharp_ext: shared_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800888
Craig Tiller841c8802015-09-10 13:06:37 -0700889 plugins: $(PROTOC_PLUGINS)
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100890
Craig Tiller841c8802015-09-10 13:06:37 -0700891 privatelibs: privatelibs_c privatelibs_cxx
nnoble29e1d292014-12-01 10:27:40 -0800892
Craig Tiller841c8802015-09-10 13:06:37 -0700893 privatelibs_c: \
894 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100895 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800896 % 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 -0700897 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
898 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100899 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700900 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800901
Craig Tiller841c8802015-09-10 13:06:37 -0700902 pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc
murgatroid998faab232015-06-30 17:24:21 -0700903
Craig Tiller841c8802015-09-10 13:06:37 -0700904 pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -0700905
Craig Tiller841c8802015-09-10 13:06:37 -0700906 ifeq ($(HAS_ZOOKEEPER),true)
907 pc_c_zookeeper: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_zookeeper.pc
908 else
909 pc_c_zookeeper:
910 endif
Hongwei Wanga3780a82015-07-17 15:27:18 -0700911
Craig Tiller841c8802015-09-10 13:06:37 -0700912 pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc
murgatroid998faab232015-06-30 17:24:21 -0700913
Craig Tiller841c8802015-09-10 13:06:37 -0700914 pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800915
Craig Tiller841c8802015-09-10 13:06:37 -0700916 privatelibs_cxx: \
917 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100918 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700919 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None):
920 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
921 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100922 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700923 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800924
925
Craig Tiller841c8802015-09-10 13:06:37 -0700926 ifeq ($(HAS_ZOOKEEPER),true)
927 privatelibs_zookeeper: \
928 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100929 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700930 % if lib.build == 'private' and lib.language == 'c++' and zookeeper in lib.get('external_deps', []):
931 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
932 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100933 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700934 % endfor
Hongwei Wang8e04d412015-07-31 15:12:51 -0700935
Craig Tiller841c8802015-09-10 13:06:37 -0700936 else
937 privatelibs_zookeeper:
938 endif
Hongwei Wang8e04d412015-07-31 15:12:51 -0700939
940
Craig Tiller841c8802015-09-10 13:06:37 -0700941 buildtests: buildtests_c buildtests_cxx buildtests_zookeeper
nnoble29e1d292014-12-01 10:27:40 -0800942
Craig Tiller3824b6e2015-12-09 11:19:59 -0800943 buildtests_c: privatelibs_c <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700944 % for tgt in targets:
945 % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -0800946 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700947 % endif
948 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800949
950
Craig Tiller3824b6e2015-12-09 11:19:59 -0800951 buildtests_cxx: buildtests_zookeeper privatelibs_cxx <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700952 % for tgt in targets:
953 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -0800954 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700955 % endif
956 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800957
958
Craig Tiller841c8802015-09-10 13:06:37 -0700959 ifeq ($(HAS_ZOOKEEPER),true)
Craig Tiller3824b6e2015-12-09 11:19:59 -0800960 buildtests_zookeeper: privatelibs_zookeeper <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700961 % for tgt in targets:
962 % if tgt.build == 'test' and tgt.language == 'c++' and 'zookeeper' in tgt.get('external_deps', []):
Craig Tiller3824b6e2015-12-09 11:19:59 -0800963 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700964 % endif
965 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800966
Craig Tiller841c8802015-09-10 13:06:37 -0700967 else
968 buildtests_zookeeper:
969 endif
Hongwei Wang8e04d412015-07-31 15:12:51 -0700970
971
Craig Tiller841c8802015-09-10 13:06:37 -0700972 test: test_c test_cxx test_zookeeper
Hongwei Wang8e04d412015-07-31 15:12:51 -0700973
Craig Tiller841c8802015-09-10 13:06:37 -0700974 flaky_test: flaky_test_c flaky_test_cxx flaky_test_zookeeper
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +0200975
Craig Tiller841c8802015-09-10 13:06:37 -0700976 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 not 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
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +0200983
984
Craig Tiller841c8802015-09-10 13:06:37 -0700985 flaky_test_c: buildtests_c
986 % for tgt in targets:
987 % 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):
988 $(E) "[RUN] Testing ${tgt.name}"
989 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
990 % endif
991 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800992
993
Craig Tiller841c8802015-09-10 13:06:37 -0700994 test_cxx: test_zookeeper buildtests_cxx
995 % for tgt in targets:
996 % 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):
997 $(E) "[RUN] Testing ${tgt.name}"
998 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
999 % endif
1000 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001001
1002
Craig Tiller841c8802015-09-10 13:06:37 -07001003 flaky_test_cxx: buildtests_cxx
1004 % for tgt in targets:
1005 % 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):
1006 $(E) "[RUN] Testing ${tgt.name}"
1007 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1008 % endif
1009 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001010
1011
Craig Tiller841c8802015-09-10 13:06:37 -07001012 ifeq ($(HAS_ZOOKEEPER),true)
1013 test_zookeeper: buildtests_zookeeper
1014 % for tgt in targets:
1015 % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and not tgt.get('flaky', False) and 'zookeeper' in tgt.get('external_deps', []):
1016 $(E) "[RUN] Testing ${tgt.name}"
1017 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1018 % endif
1019 % endfor
Hongwei Wang8e04d412015-07-31 15:12:51 -07001020
1021
Craig Tiller841c8802015-09-10 13:06:37 -07001022 flaky_test_zookeeper: buildtests_zookeeper
1023 % for tgt in targets:
1024 % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and tgt.get('flaky', False) and 'zookeeper' in tgt.get('external_deps', []):
1025 $(E) "[RUN] Testing ${tgt.name}"
1026 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1027 % endif
1028 % endfor
Hongwei Wang8e04d412015-07-31 15:12:51 -07001029
Craig Tiller841c8802015-09-10 13:06:37 -07001030 else
1031 test_zookeeper:
1032 flaky_test_zookeeper:
1033 endif
Hongwei Wang8e04d412015-07-31 15:12:51 -07001034
1035
Craig Tiller841c8802015-09-10 13:06:37 -07001036 test_python: static_c
1037 $(E) "[RUN] Testing python code"
1038 $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
Nicolas "Pixel" Noble051a28f2015-03-17 22:54:54 +01001039
1040
Craig Tiller841c8802015-09-10 13:06:37 -07001041 tools: tools_c tools_cxx
Craig Tiller7552f0f2015-06-19 17:46:20 -07001042
1043
Craig Tiller841c8802015-09-10 13:06:37 -07001044 tools_c: privatelibs_c\
1045 % for tgt in targets:
1046 % if tgt.build == 'tool' and not tgt.language=='c++':
1047 $(BINDIR)/$(CONFIG)/${tgt.name}\
1048 % endif
1049 % endfor
Craig Tiller7552f0f2015-06-19 17:46:20 -07001050
1051
Craig Tiller841c8802015-09-10 13:06:37 -07001052 tools_cxx: privatelibs_cxx\
1053 % for tgt in targets:
1054 % if tgt.build == 'tool' and tgt.language=='c++':
1055 $(BINDIR)/$(CONFIG)/${tgt.name}\
1056 % endif
1057 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001058
1059
Craig Tiller841c8802015-09-10 13:06:37 -07001060 buildbenchmarks: privatelibs\
1061 % for tgt in targets:
1062 % if tgt.build == 'benchmark':
1063 $(BINDIR)/$(CONFIG)/${tgt.name}\
1064 % endif
1065 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001066
1067
Craig Tiller841c8802015-09-10 13:06:37 -07001068 benchmarks: buildbenchmarks
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001069
Craig Tiller841c8802015-09-10 13:06:37 -07001070 strip: strip-static strip-shared
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001071
Craig Tiller841c8802015-09-10 13:06:37 -07001072 strip-static: strip-static_c strip-static_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001073
Craig Tiller841c8802015-09-10 13:06:37 -07001074 strip-shared: strip-shared_c strip-shared_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001075
Nicolas Noble047b7272015-01-16 13:55:05 -08001076
Craig Tiller841c8802015-09-10 13:06:37 -07001077 # TODO(nnoble): the strip target is stripping in-place, instead
1078 # of copying files in a temporary folder.
1079 # This prevents proper debugging after running make install.
Nicolas Noble047b7272015-01-16 13:55:05 -08001080
Craig Tiller841c8802015-09-10 13:06:37 -07001081 strip-static_c: static_c
1082 ifeq ($(CONFIG),opt)
1083 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001084 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001085 % if lib.language == "c":
1086 % if lib.build == "all":
1087 % if not lib.get('external_deps', None):
1088 $(E) "[STRIP] Stripping lib${lib.name}.a"
1089 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1090 % endif
1091 % endif
1092 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001093 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001094 % endfor
1095 ifeq ($(HAS_ZOOKEEPER),true)
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":
1100 % if 'zookeeper' in lib.get('external_deps', []):
1101 $(E) "[STRIP] Stripping lib${lib.name}.a"
1102 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1103 % endif
1104 % endif
1105 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001106 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001107 % endfor
1108 endif
1109 endif
nnoble85a49262014-12-08 18:14:03 -08001110
Craig Tiller841c8802015-09-10 13:06:37 -07001111 strip-static_cxx: static_cxx
1112 ifeq ($(CONFIG),opt)
1113 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001114 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001115 % if lib.language == "c++":
1116 % if lib.build == "all":
1117 $(E) "[STRIP] Stripping lib${lib.name}.a"
1118 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1119 % endif
1120 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001121 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001122 % endfor
1123 endif
Nicolas "Pixel" Noble4ef9b862015-08-14 19:35:24 +02001124
Craig Tiller841c8802015-09-10 13:06:37 -07001125 strip-shared_c: shared_c
1126 ifeq ($(CONFIG),opt)
1127 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001128 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001129 % if lib.language == "c":
1130 % if lib.build == "all":
1131 % if not lib.get('external_deps', None):
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001132 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)"
1133 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)
Craig Tiller841c8802015-09-10 13:06:37 -07001134 % endif
1135 % endif
1136 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001137 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001138 % endfor
1139 ifeq ($(HAS_ZOOKEEPER),true)
1140 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001141 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001142 % if lib.language == "c":
1143 % if lib.build == "all":
1144 % if 'zookeeper' in lib.get('external_deps', []):
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001145 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)"
1146 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)
Craig Tiller841c8802015-09-10 13:06:37 -07001147 % endif
1148 % endif
1149 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001150 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001151 % endfor
1152 endif
1153 endif
nnoble85a49262014-12-08 18:14:03 -08001154
Craig Tiller841c8802015-09-10 13:06:37 -07001155 strip-shared_cxx: shared_cxx
1156 ifeq ($(CONFIG),opt)
1157 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001158 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001159 % if lib.language == "c++":
1160 % if lib.build == "all":
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001161 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)"
1162 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)
Craig Tiller841c8802015-09-10 13:06:37 -07001163 % endif
1164 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001165 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001166 % endfor
1167 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001168
Craig Tiller841c8802015-09-10 13:06:37 -07001169 strip-shared_csharp: shared_csharp
1170 ifeq ($(CONFIG),opt)
1171 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001172 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001173 % if lib.language == "csharp":
1174 % if lib.build == "all":
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001175 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)"
1176 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)
Craig Tiller841c8802015-09-10 13:06:37 -07001177 % endif
1178 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001179 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001180 % endfor
1181 endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001182
Craig Tiller841c8802015-09-10 13:06:37 -07001183 cache.mk::
1184 $(E) "[MAKE] Generating $@"
1185 $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@
murgatroid99aa521572015-07-10 14:49:12 -07001186
Craig Tiller841c8802015-09-10 13:06:37 -07001187 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc:
1188 $(E) "[MAKE] Generating $@"
1189 $(Q) mkdir -p $(@D)
1190 $(Q) echo "$(GRPC_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001191
Craig Tiller841c8802015-09-10 13:06:37 -07001192 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc:
1193 $(E) "[MAKE] Generating $@"
1194 $(Q) mkdir -p $(@D)
1195 $(Q) echo "$(GRPC_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001196
Craig Tiller841c8802015-09-10 13:06:37 -07001197 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_zookeeper.pc:
1198 $(E) "[MAKE] Generating $@"
1199 $(Q) mkdir -p $(@D)
1200 $(Q) echo -e "$(GRPC_ZOOKEEPER_PC_FILE)" >$@
Hongwei Wanga8cc4392015-07-16 17:37:47 -07001201
Craig Tiller841c8802015-09-10 13:06:37 -07001202 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc:
1203 $(E) "[MAKE] Generating $@"
1204 $(Q) mkdir -p $(@D)
1205 $(Q) echo "$(GRPCXX_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001206
Craig Tiller841c8802015-09-10 13:06:37 -07001207 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc:
1208 $(E) "[MAKE] Generating $@"
1209 $(Q) mkdir -p $(@D)
1210 $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001211
Craig Tiller841c8802015-09-10 13:06:37 -07001212 % for p in protos:
1213 ifeq ($(NO_PROTOC),true)
1214 $(GENDIR)/${p}.pb.cc: protoc_dep_error
1215 $(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error
1216 else
Craig Tiller1b4e3302015-12-17 16:35:00 -08001217 $(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 -07001218 $(E) "[PROTOC] Generating protobuf CC file from $<"
1219 $(Q) mkdir -p `dirname $@`
1220 $(Q) $(PROTOC) --cpp_out=$(GENDIR) $<
Nicolas "Pixel" Noble0caebbf2015-04-09 23:08:51 +02001221
Craig Tiller1b4e3302015-12-17 16:35:00 -08001222 $(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 -07001223 $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
1224 $(Q) mkdir -p `dirname $@`
1225 $(Q) $(PROTOC) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $<
1226 endif
nnoble72309c62014-12-12 11:42:26 -08001227
Craig Tiller841c8802015-09-10 13:06:37 -07001228 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001229
Craig Tiller841c8802015-09-10 13:06:37 -07001230 ifeq ($(CONFIG),stapprof)
1231 src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h
1232 ifeq ($(HAS_SYSTEMTAP),true)
1233 $(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d
1234 $(E) "[DTRACE] Compiling $<"
1235 $(Q) mkdir -p `dirname $@`
1236 $(Q) $(DTRACE) -C -h -s $< -o $@
1237 else
1238 $(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop
1239 endif
1240 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -07001241
Craig Tiller841c8802015-09-10 13:06:37 -07001242 $(OBJDIR)/$(CONFIG)/%.o : %.c
1243 $(E) "[C] Compiling $<"
1244 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001245 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001246
Craig Tiller841c8802015-09-10 13:06:37 -07001247 $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
1248 $(E) "[CXX] Compiling $<"
1249 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001250 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001251
Craig Tiller841c8802015-09-10 13:06:37 -07001252 $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
1253 $(E) "[HOSTCXX] Compiling $<"
1254 $(Q) mkdir -p `dirname $@`
1255 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -08001256
Craig Tiller841c8802015-09-10 13:06:37 -07001257 $(OBJDIR)/$(CONFIG)/%.o : %.cc
1258 $(E) "[CXX] Compiling $<"
1259 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001260 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001261
Craig Tiller841c8802015-09-10 13:06:37 -07001262 install: install_c install_cxx install-plugins install-certs verify-install
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001263
Craig Tiller841c8802015-09-10 13:06:37 -07001264 install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001265
Craig Tiller841c8802015-09-10 13:06:37 -07001266 install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
nnoble85a49262014-12-08 18:14:03 -08001267
Craig Tiller841c8802015-09-10 13:06:37 -07001268 install_csharp: install-shared_csharp install_c
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001269
Craig Tiller841c8802015-09-10 13:06:37 -07001270 install_grpc_csharp_ext: install_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001271
Craig Tiller841c8802015-09-10 13:06:37 -07001272 install-headers: install-headers_c install-headers_cxx
nnoble85a49262014-12-08 18:14:03 -08001273
Craig Tiller841c8802015-09-10 13:06:37 -07001274 install-headers_c:
1275 $(E) "[INSTALL] Installing public C headers"
1276 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1277 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001278
Craig Tiller841c8802015-09-10 13:06:37 -07001279 install-headers_cxx:
1280 $(E) "[INSTALL] Installing public C++ headers"
1281 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1282 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001283
Craig Tiller841c8802015-09-10 13:06:37 -07001284 install-static: install-static_c install-static_cxx
nnoble85a49262014-12-08 18:14:03 -08001285
Craig Tiller841c8802015-09-10 13:06:37 -07001286 install-static_c: static_c strip-static_c install-pkg-config_c
1287 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001288 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001289 % if lib.language == "c":
1290 % if lib.build == "all":
1291 % if not lib.get('external_deps', None):
1292 $(E) "[INSTALL] Installing lib${lib.name}.a"
1293 $(Q) $(INSTALL) -d $(prefix)/lib
1294 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1295 % endif
1296 % endif
1297 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001298 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001299 % endfor
1300 ifeq ($(HAS_ZOOKEEPER),true)
1301 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001302 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001303 % if lib.language == "c":
1304 % if lib.build == "all":
1305 % if 'zookeeper' in lib.get('external_deps', []):
1306 $(E) "[INSTALL] Installing lib${lib.name}.a"
1307 $(Q) $(INSTALL) -d $(prefix)/lib
1308 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1309 % endif
1310 % endif
1311 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001312 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001313 % endfor
1314 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001315
Craig Tiller841c8802015-09-10 13:06:37 -07001316 install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx
1317 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001318 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001319 % if lib.language == "c++":
1320 % if lib.build == "all":
1321 $(E) "[INSTALL] Installing lib${lib.name}.a"
1322 $(Q) $(INSTALL) -d $(prefix)/lib
1323 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1324 % endif
1325 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001326 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001327 % endfor
nnoble85a49262014-12-08 18:14:03 -08001328
Craig Tiller841c8802015-09-10 13:06:37 -07001329 <%def name="install_shared(lang_filter)">\
1330 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001331 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001332 % if lib.language == lang_filter:
1333 % if lib.build == "all":
1334 % if not lib.get('external_deps', None):
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001335 $(E) "[INSTALL] Installing $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)"
1336 $(Q) $(INSTALL) -d $(prefix)/lib
1337 $(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 -07001338 ifeq ($(SYSTEM),MINGW32)
Craig Tiller841c8802015-09-10 13:06:37 -07001339 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001340 else ifneq ($(SYSTEM),Darwin)
Craig Tillerf008f062016-02-08 12:48:03 -08001341 $(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 +01001342 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
Craig Tiller841c8802015-09-10 13:06:37 -07001343 endif
1344 % endif
1345 % endif
1346 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001347 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001348 % endfor
1349 ifeq ($(HAS_ZOOKEEPER),true)
1350 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001351 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001352 % if lib.language == lang_filter:
1353 % if lib.build == "all":
1354 % if 'zookeeper' in lib.get('external_deps', []):
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001355 $(E) "[INSTALL] Installing $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT)"
1356 $(Q) $(INSTALL) -d $(prefix)/lib
1357 $(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 -07001358 ifeq ($(SYSTEM),MINGW32)
Craig Tiller841c8802015-09-10 13:06:37 -07001359 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001360 else ifneq ($(SYSTEM),Darwin)
Craig Tillerf008f062016-02-08 12:48:03 -08001361 $(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 +01001362 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
Craig Tiller841c8802015-09-10 13:06:37 -07001363 endif
1364 % endif
1365 % endif
1366 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001367 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001368 % endfor
1369 endif
1370 ifneq ($(SYSTEM),MINGW32)
1371 ifneq ($(SYSTEM),Darwin)
1372 $(Q) ldconfig || true
1373 endif
1374 endif
1375 </%def>
nnoble85a49262014-12-08 18:14:03 -08001376
Craig Tiller841c8802015-09-10 13:06:37 -07001377 install-shared_c: shared_c strip-shared_c install-pkg-config_c
1378 ${install_shared("c")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001379
Craig Tiller841c8802015-09-10 13:06:37 -07001380 install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c install-pkg-config_cxx
1381 ${install_shared("c++")}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001382
Craig Tiller841c8802015-09-10 13:06:37 -07001383 install-shared_csharp: shared_csharp strip-shared_csharp
1384 ${install_shared("csharp")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001385
Craig Tiller841c8802015-09-10 13:06:37 -07001386 install-plugins: $(PROTOC_PLUGINS)
1387 ifeq ($(SYSTEM),MINGW32)
1388 $(Q) false
1389 else
1390 $(E) "[INSTALL] Installing grpc protoc plugins"
1391 % for tgt in targets:
1392 % if tgt.build == 'protoc':
1393 $(Q) $(INSTALL) -d $(prefix)/bin
1394 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
1395 % endif
1396 % endfor
1397 endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001398
yang-g2908d632016-02-04 09:46:51 -08001399 install-pkg-config_c: pc_c pc_c_unsecure pc_c_zookeeper
Craig Tiller841c8802015-09-10 13:06:37 -07001400 $(E) "[INSTALL] Installing C pkg-config files"
1401 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
Craig Tiller841c8802015-09-10 13:06:37 -07001402 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(prefix)/lib/pkgconfig/grpc.pc
1403 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(prefix)/lib/pkgconfig/grpc_unsecure.pc
1404 ifeq ($(HAS_ZOOKEEPER),true)
1405 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_zookeeper.pc $(prefix)/lib/pkgconfig/grpc_zookeeper.pc
1406 endif
murgatroid998faab232015-06-30 17:24:21 -07001407
Craig Tiller841c8802015-09-10 13:06:37 -07001408 install-pkg-config_cxx: pc_cxx pc_cxx_unsecure
1409 $(E) "[INSTALL] Installing C++ pkg-config files"
1410 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
1411 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc $(prefix)/lib/pkgconfig/grpc++.pc
1412 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc $(prefix)/lib/pkgconfig/grpc++_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -07001413
Craig Tiller841c8802015-09-10 13:06:37 -07001414 install-certs: etc/roots.pem
1415 $(E) "[INSTALL] Installing root certificates"
1416 $(Q) $(INSTALL) -d $(prefix)/share/grpc
1417 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +01001418
Craig Tiller841c8802015-09-10 13:06:37 -07001419 verify-install:
1420 ifeq ($(INSTALL_OK),true)
1421 @echo "Your system looks ready to go."
1422 @echo
1423 else
1424 @echo "We couldn't find protoc 3.0.0+ installed on your system. While this"
1425 @echo "won't prevent grpc from working, you won't be able to compile"
1426 @echo "and run any meaningful code with it."
1427 @echo
1428 @echo
1429 @echo "Please download and install protobuf 3.0.0+ from:"
1430 @echo
1431 @echo " https://github.com/google/protobuf/releases"
1432 @echo
1433 @echo "Once you've done so, or if you think this message is in error,"
1434 @echo "you can re-run this check by doing:"
1435 @echo
1436 @echo " make verify-install"
1437 endif
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +01001438
Craig Tiller841c8802015-09-10 13:06:37 -07001439 clean:
1440 $(E) "[CLEAN] Cleaning build directories."
1441 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001442
1443
Craig Tiller841c8802015-09-10 13:06:37 -07001444 # The various libraries
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001445
Craig Tiller841c8802015-09-10 13:06:37 -07001446 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001447 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001448 ${makelib(lib)}
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001449 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001450 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001451
1452
Craig Tiller841c8802015-09-10 13:06:37 -07001453 # All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001454
Craig Tiller841c8802015-09-10 13:06:37 -07001455 % for tgt in targets:
1456 ${maketarget(tgt)}
1457 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001458
Craig Tiller841c8802015-09-10 13:06:37 -07001459 <%def name="makelib(lib)">
1460 LIB${lib.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001461
Craig Tiller841c8802015-09-10 13:06:37 -07001462 % for src in lib.src:
1463 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001464
Craig Tiller841c8802015-09-10 13:06:37 -07001465 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001466
Craig Tiller841c8802015-09-10 13:06:37 -07001467 % if "public_headers" in lib:
1468 % if lib.language == "c++":
1469 PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001470
Craig Tiller841c8802015-09-10 13:06:37 -07001471 % else:
1472 PUBLIC_HEADERS_C += \\
nnoble85a49262014-12-08 18:14:03 -08001473
Craig Tiller841c8802015-09-10 13:06:37 -07001474 % endif
1475 % for hdr in lib.public_headers:
1476 ${hdr} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001477
Craig Tiller841c8802015-09-10 13:06:37 -07001478 % endfor
1479 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001480
Craig Tiller841c8802015-09-10 13:06:37 -07001481 LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001482
Nicolas "Pixel" Noble51b1aee2016-01-28 01:14:58 +01001483 % if lib.get('defaults', None):
1484 % for name, value in defaults.get(lib.defaults).iteritems():
1485 $(LIB${lib.name.upper()}_OBJS): ${name} += ${value}
1486 % endfor
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001487 % endif
1488
Craig Tiller841c8802015-09-10 13:06:37 -07001489 ## If the library requires OpenSSL, let's add some restrictions.
1490 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1491 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001492
Craig Tiller841c8802015-09-10 13:06:37 -07001493 # You can't build secure libraries if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001494
Craig Tiller841c8802015-09-10 13:06:37 -07001495 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001496
Craig Tiller841c8802015-09-10 13:06:37 -07001497 % if lib.build == "all":
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001498 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT): openssl_dep_error
Craig Tiller841c8802015-09-10 13:06:37 -07001499 % endif
nnoble5b7f32a2014-12-22 08:12:44 -08001500
Craig Tiller841c8802015-09-10 13:06:37 -07001501 else
nnoble69ac39f2014-12-12 15:43:38 -08001502
Craig Tiller841c8802015-09-10 13:06:37 -07001503 % if lib.language == 'c++':
1504 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001505
Craig Tiller841c8802015-09-10 13:06:37 -07001506 # 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 -08001507
Craig Tiller841c8802015-09-10 13:06:37 -07001508 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001509
Craig Tiller841c8802015-09-10 13:06:37 -07001510 % if lib.build == "all":
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001511 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT): protobuf_dep_error
Craig Tiller841c8802015-09-10 13:06:37 -07001512 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001513
Craig Tiller841c8802015-09-10 13:06:37 -07001514 else
1515 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001516
Craig Tiller841c8802015-09-10 13:06:37 -07001517 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
1518 ## The else here corresponds to the if secure earlier.
1519 % else:
1520 % if lib.language == 'c++':
1521 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001522
Craig Tiller841c8802015-09-10 13:06:37 -07001523 # 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 -08001524
Craig Tiller841c8802015-09-10 13:06:37 -07001525 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001526
Craig Tiller841c8802015-09-10 13:06:37 -07001527 % if lib.build == "all":
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001528 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT): protobuf_dep_error
Craig Tiller841c8802015-09-10 13:06:37 -07001529 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001530
Craig Tiller841c8802015-09-10 13:06:37 -07001531 else
Nicolas Noble53830622015-02-12 16:56:38 -08001532
Craig Tiller841c8802015-09-10 13:06:37 -07001533 % endif
Nicolas "Pixel" Nobled649c212016-01-27 20:27:30 +01001534 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: \
1535 % if lib.name != 'z':
1536 $(ZLIB_DEP) \
1537 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001538 % endif
1539 % if lib.language == 'c++':
1540 $(PROTOBUF_DEP)\
1541 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001542 $(LIB${lib.name.upper()}_OBJS) \
1543 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001544 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001545 $(ZLIB_MERGE_OBJS) \
1546 % if lib.get('secure', 'check') == True:
1547 $(OPENSSL_MERGE_OBJS) \
1548 % endif
1549 % endif
1550
Craig Tiller841c8802015-09-10 13:06:37 -07001551 $(E) "[AR] Creating $@"
1552 $(Q) mkdir -p `dirname $@`
1553 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001554 $(Q) $(AR) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001555 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001556 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001557 $(ZLIB_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001558 % if lib.get('secure', 'check') == True:
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001559 $(OPENSSL_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001560 % endif
1561 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001562
Craig Tiller841c8802015-09-10 13:06:37 -07001563 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001564 $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tiller841c8802015-09-10 13:06:37 -07001565 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001566
Craig Tiller841c8802015-09-10 13:06:37 -07001567 <%
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001568
Craig Tiller841c8802015-09-10 13:06:37 -07001569 if lib.language == 'c++':
1570 ld = '$(LDXX)'
1571 else:
1572 ld = '$(LD)'
nnoble5b7f32a2014-12-22 08:12:44 -08001573
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001574 out_mingbase = '$(LIBDIR)/$(CONFIG)/' + lib.name + '$(SHARED_VERSION)'
1575 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name + '$(SHARED_VERSION)'
nnoble5b7f32a2014-12-22 08:12:44 -08001576
Craig Tiller841c8802015-09-10 13:06:37 -07001577 common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
nnoble5b7f32a2014-12-22 08:12:44 -08001578
Craig Tiller841c8802015-09-10 13:06:37 -07001579 libs = ''
1580 lib_deps = ' $(ZLIB_DEP)'
1581 mingw_libs = ''
1582 mingw_lib_deps = ' $(ZLIB_DEP)'
1583 if lib.language == 'c++':
1584 lib_deps += ' $(PROTOBUF_DEP)'
1585 mingw_lib_deps += ' $(PROTOBUF_DEP)'
Jan Tattermusch324140c2016-01-12 08:54:01 -08001586 if lib.get('deps_linkage', None) == 'static':
1587 for dep in lib.get('deps', []):
1588 lib_archive = '$(LIBDIR)/$(CONFIG)/lib' + dep + '.a'
1589 common = common + ' ' + lib_archive
1590 lib_deps = lib_deps + ' ' + lib_archive
1591 mingw_lib_deps = mingw_lib_deps + ' ' + lib_archive
1592 else:
1593 for dep in lib.get('deps', []):
1594 libs = libs + ' -l' + dep
1595 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
1596 mingw_libs = mingw_libs + ' -l' + dep + '-imp'
1597 mingw_lib_deps = mingw_lib_deps + ' $(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001598
Craig Tiller841c8802015-09-10 13:06:37 -07001599 security = lib.get('secure', 'check')
1600 if security == True:
1601 common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)'
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001602 common = common + ' $(ZLIB_MERGE_LIBS)'
Nicolas "Pixel" Noblea7c162c2015-07-24 20:21:51 +02001603
Craig Tiller841c8802015-09-10 13:06:37 -07001604 if security in [True, 'check']:
1605 for src in lib.src:
1606 if not proto_re.match(src):
1607 sources_that_need_openssl.add(src)
1608 else:
1609 for src in lib.src:
1610 sources_that_don_t_need_openssl.add(src)
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001611
Craig Tiller841c8802015-09-10 13:06:37 -07001612 if 'zookeeper' in lib.get('external_deps', []):
1613 libs = libs + ' -lzookeeper_mt'
Hongwei Wanga8cc4392015-07-16 17:37:47 -07001614
Craig Tiller841c8802015-09-10 13:06:37 -07001615 if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1616 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1617 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001618
Craig Tiller841c8802015-09-10 13:06:37 -07001619 if lib.language == 'c++':
1620 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
Craig Tiller4bef7ce2016-02-02 08:38:43 -08001621
1622 ldflags = '$(LDFLAGS)'
1623 if lib.get('LDFLAGS', None):
1624 ldflags += ' ' + lib['LDFLAGS']
Craig Tiller841c8802015-09-10 13:06:37 -07001625 %>
nnoble5b7f32a2014-12-22 08:12:44 -08001626
Craig Tiller841c8802015-09-10 13:06:37 -07001627 % if lib.build == "all":
1628 ifeq ($(SYSTEM),MINGW32)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001629 ${out_mingbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Craig Tiller841c8802015-09-10 13:06:37 -07001630 $(E) "[LD] Linking $@"
1631 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +01001632 $(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 -07001633 else
1634 ${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
1635 $(E) "[LD] Linking $@"
1636 $(Q) mkdir -p `dirname $@`
1637 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +01001638 $(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 -07001639 else
Craig Tillerf008f062016-02-08 12:48:03 -08001640 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.core_version.major} -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
1641 $(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 +01001642 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT) ${out_libbase}.so
Craig Tiller841c8802015-09-10 13:06:37 -07001643 endif
1644 endif
1645 % endif
1646 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1647 ## If the lib was secure, we have to close the Makefile's if that tested
1648 ## the presence of OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001649
Craig Tiller841c8802015-09-10 13:06:37 -07001650 endif
1651 % endif
1652 % if lib.language == 'c++':
1653 ## If the lib was C++, we have to close the Makefile's if that tested
1654 ## the presence of protobuf 3.0.0+
nnoble69ac39f2014-12-12 15:43:38 -08001655
Craig Tiller841c8802015-09-10 13:06:37 -07001656 endif
1657 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001658
Craig Tiller841c8802015-09-10 13:06:37 -07001659 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1660 ifneq ($(NO_SECURE),true)
1661 % endif
1662 ifneq ($(NO_DEPS),true)
1663 -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
1664 endif
1665 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1666 endif
1667 % endif
1668 % for src in lib.src:
1669 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src):
1670 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))}
1671 % endif
1672 % endfor
1673 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001674
Craig Tiller841c8802015-09-10 13:06:37 -07001675 <%def name="maketarget(tgt)"><% has_no_sources = not tgt.src %>
1676 % if not has_no_sources:
1677 ${tgt.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001678
Craig Tiller841c8802015-09-10 13:06:37 -07001679 % for src in tgt.src:
1680 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001681
Craig Tiller841c8802015-09-10 13:06:37 -07001682 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001683
Craig Tiller841c8802015-09-10 13:06:37 -07001684 ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
1685 % endif
1686 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1687 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001688
Craig Tiller841c8802015-09-10 13:06:37 -07001689 # You can't build secure targets if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001690
Craig Tiller841c8802015-09-10 13:06:37 -07001691 $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001692
Craig Tiller841c8802015-09-10 13:06:37 -07001693 else
nnoble69ac39f2014-12-12 15:43:38 -08001694
Craig Tiller841c8802015-09-10 13:06:37 -07001695 % endif
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001696
1697 % if tgt.boringssl:
1698 # boringssl needs an override to ensure that it does not include
1699 # system openssl headers regardless of other configuration
1700 # we do so here with a target specific variable assignment
1701 $(${tgt.name.upper()}_OBJS): CFLAGS := -Ithird_party/boringssl/include $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value
1702 $(${tgt.name.upper()}_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS)
1703 $(${tgt.name.upper()}_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE
1704 % else:
1705 % endif
1706
Craig Tiller841c8802015-09-10 13:06:37 -07001707 ##
1708 ## We're not trying to add a dependency on building zlib and openssl here,
1709 ## as it's already done in the libraries. We're assuming that the build
1710 ## trickles down, and that a secure target requires a secure version of
1711 ## a library.
1712 ##
1713 ## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1714 ## I can live with that.
1715 ##
1716 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001717
Craig Tiller841c8802015-09-10 13:06:37 -07001718 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001719
Craig Tiller841c8802015-09-10 13:06:37 -07001720 # 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 -08001721
Craig Tiller841c8802015-09-10 13:06:37 -07001722 $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001723
Craig Tiller841c8802015-09-10 13:06:37 -07001724 else
Nicolas Noble53830622015-02-12 16:56:38 -08001725
Craig Tiller841c8802015-09-10 13:06:37 -07001726 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1727 % if not has_no_sources:
1728 $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
1729 % endif
1730 % else:
1731 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1732 % if not has_no_sources:
1733 $(${tgt.name.upper()}_OBJS)\
1734 % endif
1735 % endif
1736 % for dep in tgt.deps:
1737 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1738 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001739
Craig Tiller32173c52016-03-17 14:12:45 -07001740 % if tgt.language == "c++" or tgt.boringssl or tgt.build == 'fuzzer':
Craig Tiller841c8802015-09-10 13:06:37 -07001741 ## C++ targets specificies.
1742 % if tgt.build == 'protoc':
1743 $(E) "[HOSTLD] Linking $@"
1744 $(Q) mkdir -p `dirname $@`
1745 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) \
1746 % if not has_no_sources:
1747 $(${tgt.name.upper()}_OBJS)\
1748 % endif
1749 % else:
1750 $(E) "[LD] Linking $@"
1751 $(Q) mkdir -p `dirname $@`
1752 $(Q) $(LDXX) $(LDFLAGS) \
1753 % if not has_no_sources:
1754 $(${tgt.name.upper()}_OBJS)\
1755 % endif
1756 % endif
1757 % else:
1758 ## C-only targets specificities.
1759 $(E) "[LD] Linking $@"
1760 $(Q) mkdir -p `dirname $@`
1761 $(Q) $(LD) $(LDFLAGS) \
1762 % if not has_no_sources:
1763 $(${tgt.name.upper()}_OBJS)\
1764 % endif
1765 % endif
1766 % for dep in tgt.deps:
1767 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1768 % endfor
1769 % if 'zookeeper' in tgt.get('external_deps', []):
1770 -lzookeeper_mt\
1771 % endif
1772 % if tgt.language == "c++":
1773 % if tgt.build == 'protoc':
1774 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
1775 % else:
1776 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
1777 % endif
1778 % endif
1779 % if tgt.build == 'protoc':
1780 $(HOST_LDLIBS)\
1781 % else:
1782 $(LDLIBS)\
1783 % endif
1784 % if tgt.build == 'protoc':
1785 $(HOST_LDLIBS_PROTOC)\
1786 % elif tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1787 $(LDLIBS_SECURE)\
1788 % endif
1789 % if tgt.language == 'c++' and tgt.build == 'test':
1790 $(GTEST_LIB)\
1791 % elif tgt.language == 'c++' and tgt.build == 'benchmark':
1792 $(GTEST_LIB)\
1793 % endif
Craig Tiller32173c52016-03-17 14:12:45 -07001794 % if tgt.build == 'fuzzer':
1795 -lFuzzer\
1796 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001797 -o $(BINDIR)/$(CONFIG)/${tgt.name}
1798 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001799
Craig Tiller841c8802015-09-10 13:06:37 -07001800 endif
1801 % endif
1802 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001803
Craig Tiller841c8802015-09-10 13:06:37 -07001804 endif
1805 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001806
Craig Tiller841c8802015-09-10 13:06:37 -07001807 % for src in tgt.src:
1808 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
1809 % for dep in tgt.deps:
1810 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1811 % endfor
Craig Tillerf5371ef2015-01-12 16:40:18 -08001812
Craig Tillerab230452016-01-04 08:18:43 -08001813 % if tgt.language == 'c89':
1814 % for src in tgt.src:
Craig Tillerea21ca22016-01-04 12:34:29 -08001815 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o : ${src}
1816 $(E) "[C] Compiling $<"
1817 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001818 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -std=c89 -pedantic -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Craig Tillerab230452016-01-04 08:18:43 -08001819 % endfor
1820 % endif
1821
Craig Tiller841c8802015-09-10 13:06:37 -07001822 % endfor
1823 % if not has_no_sources:
1824 deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
1825 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001826
Craig Tiller841c8802015-09-10 13:06:37 -07001827 % if not has_no_sources:
1828 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1829 ifneq ($(NO_SECURE),true)
1830 % endif
1831 ifneq ($(NO_DEPS),true)
1832 -include $(${tgt.name.upper()}_OBJS:.o=.dep)
1833 endif
1834 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1835 endif
1836 % endif
1837 % endif
Nicolas "Pixel" Noble472bb682015-11-03 19:09:01 +01001838 % for src in tgt.src:
1839 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in tgt.src):
1840 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in tgt.src if proto_re.match(src2))}
1841 % endif
1842 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001843 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001844
Craig Tiller841c8802015-09-10 13:06:37 -07001845 ifneq ($(OPENSSL_DEP),)
1846 # This is to ensure the embedded OpenSSL is built beforehand, properly
1847 # installing headers to their final destination on the drive. We need this
1848 # otherwise parallel compilation will fail if a source is compiled first.
1849 % for src in sorted(sources_that_need_openssl):
1850 % if src not in sources_that_don_t_need_openssl:
1851 ${src}: $(OPENSSL_DEP)
1852 % endif
1853 % endfor
1854 endif
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001855
Craig Tiller841c8802015-09-10 13:06:37 -07001856 .PHONY: all strip tools \
1857 dep_error openssl_dep_error openssl_dep_message git_update stop \
1858 buildtests buildtests_c buildtests_cxx \
1859 test test_c test_cxx \
1860 install install_c install_cxx \
1861 install-headers install-headers_c install-headers_cxx \
1862 install-shared install-shared_c install-shared_cxx \
1863 install-static install-static_c install-static_cxx \
1864 strip strip-shared strip-static \
1865 strip_c strip-shared_c strip-static_c \
1866 strip_cxx strip-shared_cxx strip-static_cxx \
1867 dep_c dep_cxx bins_dep_c bins_dep_cxx \
1868 clean
Craig Tillerb79c1e12016-02-23 10:00:58 -08001869
1870 .PHONY: printvars
1871 printvars:
1872 @$(foreach V,$(sort $(.VARIABLES)), \
1873 $(if $(filter-out environment% default automatic, \
1874 $(origin $V)),$(warning $V=$($V) ($(value $V)))))