blob: e0dab0291e2eea57a71c1a0b45e337a6f80088e4 [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
Jan Tattermusch4d5c3102017-06-07 10:23:56 +020010 # Copyright 2015 gRPC authors.
Craig Tiller841c8802015-09-10 13:06:37 -070011 #
Jan Tattermusch4d5c3102017-06-07 10:23:56 +020012 # Licensed under the Apache License, Version 2.0 (the "License");
13 # you may not use this file except in compliance with the License.
14 # You may obtain a copy of the License at
Craig Tiller841c8802015-09-10 13:06:37 -070015 #
Jan Tattermusch4d5c3102017-06-07 10:23:56 +020016 # http://www.apache.org/licenses/LICENSE-2.0
Craig Tiller841c8802015-09-10 13:06:37 -070017 #
Jan Tattermusch4d5c3102017-06-07 10:23:56 +020018 # Unless required by applicable law or agreed to in writing, software
19 # distributed under the License is distributed on an "AS IS" BASIS,
20 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 # See the License for the specific language governing permissions and
22 # limitations under the License.
Craig Tiller841c8802015-09-10 13:06:37 -070023 <%!
24 import re
25 import os
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080026
Craig Tiller841c8802015-09-10 13:06:37 -070027 proto_re = re.compile('(.*)\\.proto')
nnoble72309c62014-12-12 11:42:26 -080028
Craig Tiller841c8802015-09-10 13:06:37 -070029 def proto_to_cc(filename):
30 m = proto_re.match(filename)
31 if not m:
32 return filename
33 return '$(GENDIR)/' + m.group(1) + '.pb.cc $(GENDIR)/' + m.group(1) + '.grpc.pb.cc'
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +020034
Craig Tiller841c8802015-09-10 13:06:37 -070035 sources_that_need_openssl = set()
36 sources_that_don_t_need_openssl = set()
Craig Tiller78222f72016-05-10 09:55:38 -070037
38 # warnings we'd like, but that dont exist in all compilers
39 PREFERRED_WARNINGS=['shadow', 'extra-semi']
40 CHECK_WARNINGS=PREFERRED_WARNINGS + ['no-shift-negative-value']
41
42 def warning_var(fmt, warning):
43 return fmt % warning.replace('-', '_').upper()
44
45 def neg_warning(warning):
46 if warning[0:3] == 'no-':
47 return warning[3:]
48 else:
49 return 'no-' + warning
Craig Tiller38b99e92016-09-15 16:18:09 -070050
51 lang_to_var = {
52 'c': 'CORE',
53 'c++': 'CPP',
54 'csharp': 'CSHARP'
55 }
Craig Tiller841c8802015-09-10 13:06:37 -070056 %>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080057
Craig Tiller96b49552015-01-21 16:29:01 -080058
Craig Tiller71a86042016-01-15 14:59:58 -080059 comma := ,
60
61
Craig Tiller841c8802015-09-10 13:06:37 -070062 # Basic platform detection
63 HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +010064 SYSTEM ?= $(HOST_SYSTEM)
Craig Tiller841c8802015-09-10 13:06:37 -070065 ifeq ($(SYSTEM),MSYS)
66 SYSTEM = MINGW32
67 endif
68 ifeq ($(SYSTEM),MINGW64)
69 SYSTEM = MINGW32
70 endif
Craig Tiller96b49552015-01-21 16:29:01 -080071
72
Nicolas "Pixel" Noble6dad9b02015-09-23 18:32:26 +020073 MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
Craig Tiller841c8802015-09-10 13:06:37 -070074 ifndef BUILDDIR
Nicolas "Pixel" Noble42b4c282015-09-17 23:57:08 +020075 BUILDDIR_ABSOLUTE = $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))
76 else
77 BUILDDIR_ABSOLUTE = $(abspath $(BUILDDIR))
Craig Tiller841c8802015-09-10 13:06:37 -070078 endif
Craig Tiller61b910f2015-02-15 10:54:07 -080079
Craig Tiller841c8802015-09-10 13:06:37 -070080 HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false)
81 HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false)
82 HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false)
Nicolas Noblef8681182015-03-18 14:25:44 -070083
Craig Tiller841c8802015-09-10 13:06:37 -070084 ifeq ($(HAS_CC),true)
85 DEFAULT_CC = cc
86 DEFAULT_CXX = c++
87 else
88 ifeq ($(HAS_GCC),true)
89 DEFAULT_CC = gcc
90 DEFAULT_CXX = g++
91 else
92 ifeq ($(HAS_CLANG),true)
93 DEFAULT_CC = clang
94 DEFAULT_CXX = clang++
95 else
96 DEFAULT_CC = no_c_compiler
97 DEFAULT_CXX = no_c++_compiler
98 endif
99 endif
100 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700101
102
Nicolas "Pixel" Noble42b4c282015-09-17 23:57:08 +0200103 BINDIR = $(BUILDDIR_ABSOLUTE)/bins
104 OBJDIR = $(BUILDDIR_ABSOLUTE)/objs
105 LIBDIR = $(BUILDDIR_ABSOLUTE)/libs
106 GENDIR = $(BUILDDIR_ABSOLUTE)/gens
Craig Tiller61b910f2015-02-15 10:54:07 -0800107
Craig Tiller841c8802015-09-10 13:06:37 -0700108 # Configurations
ctiller8cfebb92015-01-06 15:02:12 -0800109
Craig Tillera0f85172016-01-20 15:56:06 -0800110 % for name, args in configs.iteritems():
111 VALID_CONFIG_${name} = 1
112 % if args.get('compile_the_world', False):
113 REQUIRE_CUSTOM_LIBRARIES_${name} = 1
114 % endif
Craig Tilleraff3d502016-01-20 15:59:31 -0800115 % for tool, default in [('CC', 'CC'), ('CXX', 'CXX'), ('LD', 'CC'), ('LDXX', 'CXX')]:
Craig Tillera0f85172016-01-20 15:56:06 -0800116 ${tool}_${name} = ${args.get(tool, '$(DEFAULT_%s)' % default)}
117 % endfor
118 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES']:
119 % if args.get(arg, None) is not None:
120 ${arg}_${name} = ${args.get(arg)}
121 % endif
122 % endfor
ctiller8cfebb92015-01-06 15:02:12 -0800123
Craig Tillera0f85172016-01-20 15:56:06 -0800124 % endfor
Craig Tiller699ba212015-01-13 17:02:20 -0800125
Nicolas Noble047b7272015-01-16 13:55:05 -0800126
Craig Tiller841c8802015-09-10 13:06:37 -0700127 # General settings.
128 # You may want to change these depending on your system.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800129
Craig Tiller841c8802015-09-10 13:06:37 -0700130 prefix ?= /usr/local
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800131
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100132 PROTOC ?= protoc
133 DTRACE ?= dtrace
Craig Tiller841c8802015-09-10 13:06:37 -0700134 CONFIG ?= opt
Nicolas "Pixel" Noblefba36bc2016-01-27 03:24:03 +0100135 # Doing X ?= Y is the same as:
136 # ifeq ($(origin X), undefined)
137 # X = Y
138 # endif
139 # but some variables, such as CC, CXX, LD or AR, have defaults.
140 # So instead of using ?= on them, we need to check their origin.
141 # See:
142 # https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
143 # https://www.gnu.org/software/make/manual/html_node/Flavors.html#index-_003f_003d
144 # https://www.gnu.org/software/make/manual/html_node/Origin-Function.html
145 ifeq ($(origin CC), default)
146 CC = $(CC_$(CONFIG))
147 endif
148 ifeq ($(origin CXX), default)
149 CXX = $(CXX_$(CONFIG))
150 endif
151 ifeq ($(origin LD), default)
152 LD = $(LD_$(CONFIG))
153 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100154 LDXX ?= $(LDXX_$(CONFIG))
Craig Tiller841c8802015-09-10 13:06:37 -0700155 ifeq ($(SYSTEM),Linux)
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100156 ifeq ($(origin AR), default)
157 AR = ar rcs
158 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100159 STRIP ?= strip --strip-unneeded
Craig Tiller841c8802015-09-10 13:06:37 -0700160 else
161 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100162 ifeq ($(origin AR), default)
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100163 AR = libtool -no_warning_for_no_symbols -o
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100164 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100165 STRIP ?= strip -x
Craig Tiller841c8802015-09-10 13:06:37 -0700166 else
Mario Emmenlauer1643c042016-12-12 23:12:47 +0100167 ifeq ($(SYSTEM),MINGW32)
168 ifeq ($(origin AR), default)
169 AR = ar rcs
170 endif
171 STRIP ?= strip --strip-unneeded
172 else
Nicolas "Pixel" Noble6e72dae2016-02-03 04:23:08 +0100173 ifeq ($(origin AR), default)
174 AR = ar rcs
175 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100176 STRIP ?= strip
Craig Tiller841c8802015-09-10 13:06:37 -0700177 endif
178 endif
Mario Emmenlauer1643c042016-12-12 23:12:47 +0100179 endif
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100180 INSTALL ?= install
181 RM ?= rm -f
182 PKG_CONFIG ?= pkg-config
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800183
Craig Tiller841c8802015-09-10 13:06:37 -0700184 ifndef VALID_CONFIG_$(CONFIG)
185 $(error Invalid CONFIG value '$(CONFIG)')
186 endif
yangg102e4fe2015-01-06 16:02:50 -0800187
Craig Tiller841c8802015-09-10 13:06:37 -0700188 ifeq ($(SYSTEM),Linux)
189 TMPOUT = /dev/null
190 else
191 TMPOUT = `mktemp /tmp/test-out-XXXXXX`
192 endif
Nicolas Noble047b7272015-01-16 13:55:05 -0800193
Craig Tiller78222f72016-05-10 09:55:38 -0700194 %for warning in CHECK_WARNINGS:
195 ${warning_var('CHECK_%s_WORKS_CMD', warning)} = $(CC) -std=c99 -Werror -W${warning} -o $(TMPOUT) -c test/build/${warning}.c
196 ${warning_var('HAS_WORKING_%s', warning)} = $(shell $(${warning_var('CHECK_%s_WORKS_CMD', warning)}) 2> /dev/null && echo true || echo false)
197 ifeq ($(${warning_var('HAS_WORKING_%s', warning)}),true)
198 ${warning_var('W_%s', warning)}=-W${warning}
199 ${warning_var('NO_W_%s', warning)}=-W${neg_warning(warning)}
Craig Tiller804b8552016-02-23 16:50:24 -0800200 endif
Craig Tiller78222f72016-05-10 09:55:38 -0700201 %endfor
Craig Tiller16872b82016-01-25 10:55:20 -0800202
Craig Tiller841c8802015-09-10 13:06:37 -0700203 # The HOST compiler settings are used to compile the protoc plugins.
204 # In most cases, you won't have to change anything, but if you are
205 # cross-compiling, you can override these variables from GNU make's
206 # command line: make CC=cross-gcc HOST_CC=gcc
Nicolas Noble047b7272015-01-16 13:55:05 -0800207
Nicolas "Pixel" Noble1a8eb852016-01-26 22:33:19 +0100208 HOST_CC ?= $(CC)
209 HOST_CXX ?= $(CXX)
210 HOST_LD ?= $(LD)
211 HOST_LDXX ?= $(LDXX)
nnoble72309c62014-12-12 11:42:26 -0800212
Craig Tiller78222f72016-05-10 09:55:38 -0700213 CFLAGS += -std=c99 -Wsign-conversion -Wconversion ${' '.join(warning_var('$(W_%s)', warning) for warning in PREFERRED_WARNINGS)}
Craig Tiller841c8802015-09-10 13:06:37 -0700214 CXXFLAGS += -std=c++11
Ken Paysonf8d6fb72017-06-15 17:32:49 -0700215 ifeq ($(SYSTEM),Darwin)
216 CXXFLAGS += -stdlib=libc++
217 endif
ncteisenf9d7c272017-11-06 20:32:57 -0800218 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'COREFLAGS', 'LDFLAGS', 'DEFINES']:
Nicolas "Pixel" Noble51b1aee2016-01-28 01:14:58 +0100219 % if defaults.get('global', []).get(arg, None) is not None:
220 ${arg} += ${defaults.get('global').get(arg)}
221 % endif
222 % endfor
Nicolas Noblef8681182015-03-18 14:25:44 -0700223
Yihua Zhang04fb58e2018-03-08 06:49:24 -0800224 DEFINES += PB_FIELD_16BIT
225
Craig Tiller841c8802015-09-10 13:06:37 -0700226 CPPFLAGS += $(CPPFLAGS_$(CONFIG))
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800227 CFLAGS += $(CFLAGS_$(CONFIG))
228 CXXFLAGS += $(CXXFLAGS_$(CONFIG))
Craig Tiller841c8802015-09-10 13:06:37 -0700229 DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
230 LDFLAGS += $(LDFLAGS_$(CONFIG))
Nicolas "Pixel" Noble482d7612015-07-16 23:43:30 +0200231
Craig Tiller841c8802015-09-10 13:06:37 -0700232 ifneq ($(SYSTEM),MINGW32)
233 PIC_CPPFLAGS = -fPIC
234 CPPFLAGS += -fPIC
235 LDFLAGS += -fPIC
236 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800237
Craig Tiller841c8802015-09-10 13:06:37 -0700238 INCLUDES = . include $(GENDIR)
239 LDFLAGS += -Llibs/$(CONFIG)
Nicolas "Pixel" Noble3adab742015-06-02 00:33:06 +0200240
Craig Tiller841c8802015-09-10 13:06:37 -0700241 ifeq ($(SYSTEM),Darwin)
242 ifneq ($(wildcard /usr/local/ssl/include),)
243 INCLUDES += /usr/local/ssl/include
244 endif
245 ifneq ($(wildcard /opt/local/include),)
246 INCLUDES += /opt/local/include
247 endif
248 ifneq ($(wildcard /usr/local/include),)
249 INCLUDES += /usr/local/include
250 endif
251 LIBS = m z
252 ifneq ($(wildcard /usr/local/ssl/lib),)
253 LDFLAGS += -L/usr/local/ssl/lib
254 endif
255 ifneq ($(wildcard /opt/local/lib),)
256 LDFLAGS += -L/opt/local/lib
257 endif
258 ifneq ($(wildcard /usr/local/lib),)
259 LDFLAGS += -L/usr/local/lib
260 endif
261 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700262
Craig Tiller841c8802015-09-10 13:06:37 -0700263 ifeq ($(SYSTEM),Linux)
Craig Tiller1b1e2382016-02-03 07:33:56 -0800264 LIBS = dl rt m pthread
Craig Tiller841c8802015-09-10 13:06:37 -0700265 LDFLAGS += -pthread
266 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800267
Craig Tiller841c8802015-09-10 13:06:37 -0700268 ifeq ($(SYSTEM),MINGW32)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100269 LIBS = m pthread ws2_32
Craig Tiller841c8802015-09-10 13:06:37 -0700270 LDFLAGS += -pthread
271 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700272
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700273 #
274 # The steps for cross-compiling are as follows:
275 # First, clone and make install of grpc using the native compilers for the host.
276 # Also, install protoc (e.g., from a package like apt-get)
277 # Then clone a fresh grpc for the actual cross-compiled build
278 # Set the environment variable GRPC_CROSS_COMPILE to true
279 # Set CC, CXX, LD, LDXX, AR, and STRIP to the cross-compiling binaries
280 # Also set PROTOBUF_CONFIG_OPTS to indicate cross-compilation to protobuf (e.g.,
281 # PROTOBUF_CONFIG_OPTS="--host=arm-linux --with-protoc=/usr/local/bin/protoc" )
282 # Set HAS_PKG_CONFIG=false
283 # To build tests, go to third_party/gflags and follow its ccmake instructions
284 # Make sure that you enable building shared libraries and set your prefix to
285 # something useful like /usr/local/cross
286 # You will also need to set GRPC_CROSS_LDOPTS and GRPC_CROSS_AROPTS to hold
287 # additional required arguments for LD and AR (examples below)
288 # Then you can do a make from the cross-compiling fresh clone!
289 #
290 ifeq ($(GRPC_CROSS_COMPILE),true)
291 LDFLAGS += $(GRPC_CROSS_LDOPTS) # e.g. -L/usr/local/lib -L/usr/local/cross/lib
292 AROPTS = $(GRPC_CROSS_AROPTS) # e.g., rc --target=elf32-little
293 USE_BUILT_PROTOC = false
294 endif
295
Mahak Mukhifb059a22017-04-18 14:40:00 -0700296 GTEST_LIB = -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googletest third_party/googletest/googletest/src/gtest-all.cc -Ithird_party/googletest/googlemock/include -Ithird_party/googletest/googlemock third_party/googletest/googlemock/src/gmock-all.cc
Craig Tiller841c8802015-09-10 13:06:37 -0700297 GTEST_LIB += -lgflags
298 ifeq ($(V),1)
299 E = @:
300 Q =
301 else
302 E = @echo
303 Q = @
304 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800305
Craig Tiller38b99e92016-09-15 16:18:09 -0700306 CORE_VERSION = ${settings.core_version}
307 CPP_VERSION = ${settings.cpp_version}
308 CSHARP_VERSION = ${settings.csharp_version}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800309
Craig Tiller841c8802015-09-10 13:06:37 -0700310 CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
311 CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800312
Craig Tiller841c8802015-09-10 13:06:37 -0700313 LDFLAGS += $(ARCH_FLAGS)
314 LDLIBS += $(addprefix -l, $(LIBS))
315 LDLIBSXX += $(addprefix -l, $(LIBSXX))
nnoble72309c62014-12-12 11:42:26 -0800316
murgatroid99c36f6ea2016-10-03 09:24:09 -0700317
318 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES', 'LDLIBS']:
319 ${arg} += $(EXTRA_${arg})
320 % endfor
321
Craig Tiller841c8802015-09-10 13:06:37 -0700322 HOST_CPPFLAGS = $(CPPFLAGS)
323 HOST_CFLAGS = $(CFLAGS)
324 HOST_CXXFLAGS = $(CXXFLAGS)
325 HOST_LDFLAGS = $(LDFLAGS)
326 HOST_LDLIBS = $(LDLIBS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800327
Craig Tiller841c8802015-09-10 13:06:37 -0700328 # These are automatically computed variables.
329 # There shouldn't be any need to change anything from now on.
nnoble69ac39f2014-12-12 15:43:38 -0800330
Craig Tiller841c8802015-09-10 13:06:37 -0700331 -include cache.mk
murgatroid9924e2f4a2015-06-29 11:12:01 -0700332
Craig Tiller841c8802015-09-10 13:06:37 -0700333 CACHE_MK =
murgatroid99aa521572015-07-10 14:49:12 -0700334
Craig Tiller841c8802015-09-10 13:06:37 -0700335 HAS_PKG_CONFIG ?= $(shell command -v $(PKG_CONFIG) >/dev/null 2>&1 && echo true || echo false)
murgatroid99aa521572015-07-10 14:49:12 -0700336
Craig Tiller841c8802015-09-10 13:06:37 -0700337 ifeq ($(HAS_PKG_CONFIG), true)
338 CACHE_MK += HAS_PKG_CONFIG = true,
339 endif
nnoble69ac39f2014-12-12 15:43:38 -0800340
Craig Tiller38b99e92016-09-15 16:18:09 -0700341 CORE_PC_TEMPLATE = prefix=$(prefix),\
Craig Tiller841c8802015-09-10 13:06:37 -0700342 exec_prefix=${'\$${prefix}'},\
343 includedir=${'\$${prefix}'}/include,\
344 libdir=${'\$${exec_prefix}'}/lib,\
345 ,\
346 Name: $(PC_NAME),\
347 Description: $(PC_DESCRIPTION),\
Craig Tiller38b99e92016-09-15 16:18:09 -0700348 Version: $(CORE_VERSION),\
349 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
350 Requires.private: $(PC_REQUIRES_PRIVATE),\
351 Libs: -L${'\$${libdir}'} $(PC_LIB),\
352 Libs.private: $(PC_LIBS_PRIVATE)
353
354 CPP_PC_TEMPLATE = prefix=$(prefix),\
355 exec_prefix=${'\$${prefix}'},\
356 includedir=${'\$${prefix}'}/include,\
357 libdir=${'\$${exec_prefix}'}/lib,\
358 ,\
359 Name: $(PC_NAME),\
360 Description: $(PC_DESCRIPTION),\
361 Version: $(CPP_VERSION),\
362 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
363 Requires.private: $(PC_REQUIRES_PRIVATE),\
364 Libs: -L${'\$${libdir}'} $(PC_LIB),\
365 Libs.private: $(PC_LIBS_PRIVATE)
366
367 CSHARP_PC_TEMPLATE = prefix=$(prefix),\
368 exec_prefix=${'\$${prefix}'},\
369 includedir=${'\$${prefix}'}/include,\
370 libdir=${'\$${exec_prefix}'}/lib,\
371 ,\
372 Name: $(PC_NAME),\
373 Description: $(PC_DESCRIPTION),\
374 Version: $(CSHARP_VERSION),\
Craig Tiller841c8802015-09-10 13:06:37 -0700375 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
376 Requires.private: $(PC_REQUIRES_PRIVATE),\
377 Libs: -L${'\$${libdir}'} $(PC_LIB),\
378 Libs.private: $(PC_LIBS_PRIVATE)
murgatroid998faab232015-06-30 17:24:21 -0700379
Craig Tiller841c8802015-09-10 13:06:37 -0700380 ifeq ($(SYSTEM),MINGW32)
Mario Emmenlauer121d2892016-12-12 23:49:27 +0100381 EXECUTABLE_SUFFIX = .exe
Craig Tiller38b99e92016-09-15 16:18:09 -0700382 SHARED_EXT_CORE = dll
383 SHARED_EXT_CPP = dll
384 SHARED_EXT_CSHARP = dll
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100385 SHARED_PREFIX =
Craig Tiller27f70842016-09-15 16:21:54 -0700386 SHARED_VERSION_CORE = -${settings.core_version.major}
387 SHARED_VERSION_CPP = -${settings.cpp_version.major}
388 SHARED_VERSION_CSHARP = -${settings.csharp_version.major}
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100389 else ifeq ($(SYSTEM),Darwin)
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800390 EXECUTABLE_SUFFIX =
Craig Tiller38b99e92016-09-15 16:18:09 -0700391 SHARED_EXT_CORE = dylib
392 SHARED_EXT_CPP = dylib
393 SHARED_EXT_CSHARP = dylib
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100394 SHARED_PREFIX = lib
Craig Tiller27f70842016-09-15 16:21:54 -0700395 SHARED_VERSION_CORE =
396 SHARED_VERSION_CPP =
397 SHARED_VERSION_CSHARP =
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100398 else
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800399 EXECUTABLE_SUFFIX =
Craig Tiller38b99e92016-09-15 16:18:09 -0700400 SHARED_EXT_CORE = so.$(CORE_VERSION)
401 SHARED_EXT_CPP = so.$(CPP_VERSION)
402 SHARED_EXT_CSHARP = so.$(CSHARP_VERSION)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100403 SHARED_PREFIX = lib
Craig Tiller27f70842016-09-15 16:21:54 -0700404 SHARED_VERSION_CORE =
405 SHARED_VERSION_CPP =
406 SHARED_VERSION_CSHARP =
Craig Tiller841c8802015-09-10 13:06:37 -0700407 endif
nnoble5b7f32a2014-12-22 08:12:44 -0800408
Craig Tiller841c8802015-09-10 13:06:37 -0700409 ifeq ($(wildcard .git),)
410 IS_GIT_FOLDER = false
411 else
412 IS_GIT_FOLDER = true
413 endif
nnoble69ac39f2014-12-12 15:43:38 -0800414
Craig Tiller841c8802015-09-10 13:06:37 -0700415 ifeq ($(HAS_PKG_CONFIG),true)
416 OPENSSL_ALPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.2 openssl
417 OPENSSL_NPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.1 openssl
418 ZLIB_CHECK_CMD = $(PKG_CONFIG) --exists zlib
Yuchen Zengd4df55e2016-08-15 16:41:18 -0700419 PROTOBUF_CHECK_CMD = $(PKG_CONFIG) --atleast-version=3.0.0 protobuf
Yuchen Zengf8b6d6f2017-06-02 15:36:25 -0700420 CARES_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.11.0 libcares
Craig Tiller841c8802015-09-10 13:06:37 -0700421 else # HAS_PKG_CONFIG
murgatroid9924e2f4a2015-06-29 11:12:01 -0700422
Craig Tiller841c8802015-09-10 13:06:37 -0700423 ifeq ($(SYSTEM),MINGW32)
424 OPENSSL_LIBS = ssl32 eay32
425 else
426 OPENSSL_LIBS = ssl crypto
427 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700428
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100429 OPENSSL_ALPN_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
430 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 -0800431 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 +0100432 ZLIB_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
433 PROTOBUF_CHECK_CMD = $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700434 CARES_CHECK_CMD = $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $(TMPOUT) test/build/c-ares.c -lcares $(LDFLAGS)
Craig Tiller297fafa2015-01-15 15:46:39 -0800435
Craig Tiller841c8802015-09-10 13:06:37 -0700436 endif # HAS_PKG_CONFIG
murgatroid9924e2f4a2015-06-29 11:12:01 -0700437
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100438 PERFTOOLS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
murgatroid996d9e4012015-07-08 10:22:45 -0700439
Craig Tiller841c8802015-09-10 13:06:37 -0700440 PROTOC_CHECK_CMD = which protoc > /dev/null
441 PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3
442 DTRACE_CHECK_CMD = which dtrace > /dev/null
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100443 SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS)
murgatroid9924e2f4a2015-06-29 11:12:01 -0700444
Craig Tiller841c8802015-09-10 13:06:37 -0700445 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
446 HAS_SYSTEM_PERFTOOLS ?= $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
447 ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
448 DEFINES += GRPC_HAVE_PERFTOOLS
449 LIBS += profiler
450 CACHE_MK += HAS_SYSTEM_PERFTOOLS = true,
451 endif
452 endif
nnoble69ac39f2014-12-12 15:43:38 -0800453
Craig Tiller841c8802015-09-10 13:06:37 -0700454 HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
455 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
456 HAS_SYSTEM_OPENSSL_ALPN ?= $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
457 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
458 HAS_SYSTEM_OPENSSL_NPN = true
459 CACHE_MK += HAS_SYSTEM_OPENSSL_ALPN = true,
460 else
461 HAS_SYSTEM_OPENSSL_NPN ?= $(shell $(OPENSSL_NPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
462 endif
463 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
464 CACHE_MK += HAS_SYSTEM_OPENSSL_NPN = true,
465 endif
466 HAS_SYSTEM_ZLIB ?= $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
467 ifeq ($(HAS_SYSTEM_ZLIB),true)
468 CACHE_MK += HAS_SYSTEM_ZLIB = true,
469 endif
470 HAS_SYSTEM_PROTOBUF ?= $(HAS_SYSTEM_PROTOBUF_VERIFY)
471 ifeq ($(HAS_SYSTEM_PROTOBUF),true)
472 CACHE_MK += HAS_SYSTEM_PROTOBUF = true,
473 endif
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700474 HAS_SYSTEM_CARES ?= $(shell $(CARES_CHECK_CMD) 2> /dev/null && echo true || echo false)
475 ifeq ($(HAS_SYSTEM_CARES),true)
476 CACHE_MK += HAS_SYSTEM_CARES = true,
477 endif
Craig Tiller841c8802015-09-10 13:06:37 -0700478 else
479 # override system libraries if the config requires a custom compiled library
480 HAS_SYSTEM_OPENSSL_ALPN = false
481 HAS_SYSTEM_OPENSSL_NPN = false
482 HAS_SYSTEM_ZLIB = false
483 HAS_SYSTEM_PROTOBUF = false
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700484 HAS_SYSTEM_CARES = false
Craig Tiller841c8802015-09-10 13:06:37 -0700485 endif
nnoble69ac39f2014-12-12 15:43:38 -0800486
Craig Tiller841c8802015-09-10 13:06:37 -0700487 HAS_PROTOC ?= $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
488 ifeq ($(HAS_PROTOC),true)
489 CACHE_MK += HAS_PROTOC = true,
490 HAS_VALID_PROTOC ?= $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false)
491 ifeq ($(HAS_VALID_PROTOC),true)
492 CACHE_MK += HAS_VALID_PROTOC = true,
493 endif
494 else
495 HAS_VALID_PROTOC = false
496 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800497
Craig Tiller841c8802015-09-10 13:06:37 -0700498 # Check for Systemtap (https://sourceware.org/systemtap/), first by making sure <sys/sdt.h> is present
499 # in the system and secondly by checking for the "dtrace" binary (on Linux, this is part of the Systemtap
500 # distribution. It's part of the base system on BSD/Solaris machines).
501 ifndef HAS_SYSTEMTAP
502 HAS_SYSTEMTAP_HEADERS = $(shell $(SYSTEMTAP_HEADERS_CHECK_CMD) 2> /dev/null && echo true || echo false)
503 HAS_DTRACE = $(shell $(DTRACE_CHECK_CMD) 2> /dev/null && echo true || echo false)
504 HAS_SYSTEMTAP = false
505 ifeq ($(HAS_SYSTEMTAP_HEADERS),true)
506 ifeq ($(HAS_DTRACE),true)
507 HAS_SYSTEMTAP = true
508 endif
509 endif
510 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -0700511
Craig Tiller841c8802015-09-10 13:06:37 -0700512 ifeq ($(HAS_SYSTEMTAP),true)
513 CACHE_MK += HAS_SYSTEMTAP = true,
514 endif
nnoble69ac39f2014-12-12 15:43:38 -0800515
Craig Tiller841c8802015-09-10 13:06:37 -0700516 # Note that for testing purposes, one can do:
517 # make HAS_EMBEDDED_OPENSSL_ALPN=false
518 # to emulate the fact we do not have OpenSSL in the third_party folder.
Craig Tillerb79c1e12016-02-23 10:00:58 -0800519 ifneq ($(wildcard third_party/${openssl_fallback.extraction_dir}/libssl.a),)
520 HAS_EMBEDDED_OPENSSL_ALPN = third_party/${openssl_fallback.extraction_dir}
521 else ifeq ($(wildcard third_party/boringssl/include/openssl/ssl.h),)
Craig Tiller841c8802015-09-10 13:06:37 -0700522 HAS_EMBEDDED_OPENSSL_ALPN = false
523 else
Craig Tillerb79c1e12016-02-23 10:00:58 -0800524 CAN_COMPILE_EMBEDDED_OPENSSL ?= $(shell $(BORINGSSL_COMPILE_CHECK_CMD) 2> /dev/null && echo true || echo false)
525 HAS_EMBEDDED_OPENSSL_ALPN = $(CAN_COMPILE_EMBEDDED_OPENSSL)
Craig Tiller841c8802015-09-10 13:06:37 -0700526 endif
nnoble69ac39f2014-12-12 15:43:38 -0800527
Craig Tiller841c8802015-09-10 13:06:37 -0700528 ifeq ($(wildcard third_party/zlib/zlib.h),)
529 HAS_EMBEDDED_ZLIB = false
530 else
531 HAS_EMBEDDED_ZLIB = true
532 endif
nnoble69ac39f2014-12-12 15:43:38 -0800533
Craig Tiller841c8802015-09-10 13:06:37 -0700534 ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
535 HAS_EMBEDDED_PROTOBUF = false
536 ifneq ($(HAS_VALID_PROTOC),true)
537 NO_PROTOC = true
538 endif
539 else
540 HAS_EMBEDDED_PROTOBUF = true
541 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800542
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800543 ifeq ($(wildcard third_party/cares/cares/ares.h),)
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700544 HAS_EMBEDDED_CARES = false
545 else
546 HAS_EMBEDDED_CARES = true
547 endif
548
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100549 PC_REQUIRES_GRPC =
Craig Tiller841c8802015-09-10 13:06:37 -0700550 PC_LIBS_GRPC =
murgatroid998faab232015-06-30 17:24:21 -0700551
Craig Tiller841c8802015-09-10 13:06:37 -0700552 ifeq ($(HAS_SYSTEM_ZLIB),false)
Craig Tiller3dca23a2016-01-21 11:44:55 -0800553 ifeq ($(HAS_EMBEDDED_ZLIB), true)
554 EMBED_ZLIB ?= true
Craig Tiller841c8802015-09-10 13:06:37 -0700555 else
556 DEP_MISSING += zlib
Craig Tiller3dca23a2016-01-21 11:44:55 -0800557 EMBED_ZLIB ?= broken
Craig Tiller841c8802015-09-10 13:06:37 -0700558 endif
559 else
Craig Tiller3dca23a2016-01-21 11:44:55 -0800560 EMBED_ZLIB ?= false
561 endif
562
563 ifeq ($(EMBED_ZLIB),true)
564 ZLIB_DEP = $(LIBDIR)/$(CONFIG)/libz.a
565 ZLIB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libz.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +0100566 ZLIB_MERGE_OBJS = $(LIBZ_OBJS)
Craig Tiller3dca23a2016-01-21 11:44:55 -0800567 CPPFLAGS += -Ithird_party/zlib
Craig Tiller3dca23a2016-01-21 11:44:55 -0800568 else
Craig Tiller841c8802015-09-10 13:06:37 -0700569 ifeq ($(HAS_PKG_CONFIG),true)
570 CPPFLAGS += $(shell $(PKG_CONFIG) --cflags zlib)
571 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L zlib)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800572 LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l zlib))
Craig Tiller841c8802015-09-10 13:06:37 -0700573 PC_REQUIRES_GRPC += zlib
574 else
575 PC_LIBS_GRPC += -lz
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800576 LIBS += z
Craig Tiller841c8802015-09-10 13:06:37 -0700577 endif
578 endif
nnoble69ac39f2014-12-12 15:43:38 -0800579
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700580 CARES_PKG_CONFIG = false
581
Yuchen Zengb1b21152016-08-12 11:27:30 -0700582 ifeq ($(HAS_SYSTEM_CARES),false)
583 ifeq ($(HAS_EMBEDDED_CARES), true)
584 EMBED_CARES ?= true
585 else
586 DEP_MISSING += cares
587 EMBED_CARES ?= broken
588 endif
589 else
590 EMBED_CARES ?= false
591 endif
592
Alexander Polcyn690dde62017-10-18 00:20:33 -0700593 ADDRESS_SORTING_DEP = $(LIBDIR)/$(CONFIG)/libaddress_sorting.a
594 ADDRESS_SORTING_MERGE_OBJS = $(LIBADDRESS_SORTING_OBJS)
595 ADDRESS_SORTING_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libaddress_sorting.a
596 CPPFLAGS := -Ithird_party/address_sorting $(CPPFLAGS)
597
Yuchen Zengb1b21152016-08-12 11:27:30 -0700598 ifeq ($(EMBED_CARES),true)
Yuchen Zeng15141a62016-08-17 18:56:04 -0700599 CARES_DEP = $(LIBDIR)/$(CONFIG)/libares.a
600 CARES_MERGE_OBJS = $(LIBARES_OBJS)
601 CARES_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libares.a
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800602 CPPFLAGS := -Ithird_party/cares -Ithird_party/cares/cares $(CPPFLAGS)
Yuchen Zengb1b21152016-08-12 11:27:30 -0700603 else
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700604 ifeq ($(HAS_PKG_CONFIG),true)
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700605 PC_REQUIRES_GRPC += libcares
606 CPPFLAGS += $(shell $(PKG_CONFIG) --cflags libcares)
Yuchen Zengdf2a7b72016-08-18 14:57:03 -0700607 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libcares)
608 LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l libcares))
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700609 else
610 PC_LIBS_GRPC += -lcares
Yuchen Zengdf2a7b72016-08-18 14:57:03 -0700611 LIBS += cares
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700612 endif
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700613 endif
614
Craig Tiller841c8802015-09-10 13:06:37 -0700615 OPENSSL_PKG_CONFIG = false
murgatroid99da7a9942015-06-29 14:57:37 -0700616
Craig Tiller841c8802015-09-10 13:06:37 -0700617 PC_REQUIRES_SECURE =
618 PC_LIBS_SECURE =
murgatroid998faab232015-06-30 17:24:21 -0700619
Craig Tiller841c8802015-09-10 13:06:37 -0700620 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800621 EMBED_OPENSSL ?= false
622 NO_SECURE ?= false
623 else # HAS_SYSTEM_OPENSSL_ALPN=false
Craig Tillerb79c1e12016-02-23 10:00:58 -0800624 ifneq ($(HAS_EMBEDDED_OPENSSL_ALPN),false)
625 EMBED_OPENSSL ?= $(HAS_EMBEDDED_OPENSSL_ALPN)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800626 NO_SECURE ?= false
627 else # HAS_EMBEDDED_OPENSSL_ALPN=false
628 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
629 EMBED_OPENSSL ?= false
630 NO_SECURE ?= false
631 else
632 NO_SECURE ?= true
633 endif # HAS_SYSTEM_OPENSSL_NPN=true
634 endif # HAS_EMBEDDED_OPENSSL_ALPN
635 endif # HAS_SYSTEM_OPENSSL_ALPN
636
637 OPENSSL_DEP :=
638 OPENSSL_MERGE_LIBS :=
639 ifeq ($(NO_SECURE),false)
640 ifeq ($(EMBED_OPENSSL),true)
641 OPENSSL_DEP += $(LIBDIR)/$(CONFIG)/libboringssl.a
642 OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/libboringssl.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +0100643 OPENSSL_MERGE_OBJS += $(LIBBORINGSSL_OBJS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800644 # need to prefix these to ensure overriding system libraries
645 CPPFLAGS := -Ithird_party/boringssl/include $(CPPFLAGS)
Craig Tillerb79c1e12016-02-23 10:00:58 -0800646 else ifneq ($(EMBED_OPENSSL),false)
647 OPENSSL_DEP += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
648 OPENSSL_MERGE_LIBS += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
649 OPENSSL_MERGE_OBJS += $(wildcard $(EMBED_OPENSSL)/grpc_obj/*.o)
650 # need to prefix these to ensure overriding system libraries
651 CPPFLAGS := -I$(EMBED_OPENSSL)/include $(CPPFLAGS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800652 else # EMBED_OPENSSL=false
Craig Tiller841c8802015-09-10 13:06:37 -0700653 ifeq ($(HAS_PKG_CONFIG),true)
654 OPENSSL_PKG_CONFIG = true
655 PC_REQUIRES_SECURE = openssl
656 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags openssl) $(CPPFLAGS)
657 LDFLAGS_OPENSSL_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L openssl)
658 ifeq ($(SYSTEM),Linux)
659 ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),)
660 LDFLAGS_OPENSSL_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L openssl | sed s/L/Wl,-rpath,/)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800661 endif # LDFLAGS_OPENSSL_PKG_CONFIG=''
662 endif # System=Linux
Craig Tiller841c8802015-09-10 13:06:37 -0700663 LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800664 else # HAS_PKG_CONFIG=false
Craig Tiller841c8802015-09-10 13:06:37 -0700665 LIBS_SECURE = $(OPENSSL_LIBS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800666 endif # HAS_PKG_CONFIG
667 ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
668 CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0
669 LIBS_SECURE = $(OPENSSL_LIBS)
670 endif # HAS_SYSTEM_OPENSSL_NPN
Craig Tiller841c8802015-09-10 13:06:37 -0700671 PC_LIBS_SECURE = $(addprefix -l, $(LIBS_SECURE))
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800672 endif # EMBED_OPENSSL
673 endif # NO_SECURE
nnoble69ac39f2014-12-12 15:43:38 -0800674
Craig Tiller841c8802015-09-10 13:06:37 -0700675 ifeq ($(OPENSSL_PKG_CONFIG),true)
676 LDLIBS_SECURE += $(shell $(PKG_CONFIG) --libs-only-l openssl)
677 else
678 LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
679 endif
nnoble5b7f32a2014-12-22 08:12:44 -0800680
Craig Tiller841c8802015-09-10 13:06:37 -0700681 # grpc .pc file
682 PC_NAME = gRPC
Craig Tillerda179ce2016-02-09 12:01:53 -0800683 PC_DESCRIPTION = high performance general RPC framework
684 PC_CFLAGS =
685 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC) $(PC_REQUIRES_SECURE)
Craig Tiller841c8802015-09-10 13:06:37 -0700686 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) $(PC_LIBS_SECURE)
687 PC_LIB = -lgrpc
Craig Tiller38b99e92016-09-15 16:18:09 -0700688 GRPC_PC_FILE := $(CORE_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700689
Craig Tiller4a67be42016-02-09 12:40:32 -0800690 # grpc_unsecure .pc file
Craig Tiller841c8802015-09-10 13:06:37 -0700691 PC_NAME = gRPC unsecure
Craig Tillerda179ce2016-02-09 12:01:53 -0800692 PC_DESCRIPTION = high performance general RPC framework without SSL
693 PC_CFLAGS =
694 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC)
Craig Tiller841c8802015-09-10 13:06:37 -0700695 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC)
696 PC_LIB = -lgrpc
Craig Tiller38b99e92016-09-15 16:18:09 -0700697 GRPC_UNSECURE_PC_FILE := $(CORE_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700698
Craig Tiller841c8802015-09-10 13:06:37 -0700699 PROTOBUF_PKG_CONFIG = false
murgatroid99da7a9942015-06-29 14:57:37 -0700700
Craig Tiller841c8802015-09-10 13:06:37 -0700701 PC_REQUIRES_GRPCXX =
702 PC_LIBS_GRPCXX =
murgatroid998faab232015-06-30 17:24:21 -0700703
Mahak Mukhifb059a22017-04-18 14:40:00 -0700704 CPPFLAGS := -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googlemock/include $(CPPFLAGS)
Craig Tiller16f6dac2015-08-24 17:00:04 -0700705
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700706 PROTOC_PLUGINS_ALL =\
707 % for tgt in targets:
708 % if tgt.build == 'protoc':
709 $(BINDIR)/$(CONFIG)/${tgt.name}\
710 % endif
711 % endfor
712
713 PROTOC_PLUGINS_DIR = $(BINDIR)/$(CONFIG)
714
Craig Tiller841c8802015-09-10 13:06:37 -0700715 ifeq ($(HAS_SYSTEM_PROTOBUF),true)
716 ifeq ($(HAS_PKG_CONFIG),true)
717 PROTOBUF_PKG_CONFIG = true
718 PC_REQUIRES_GRPCXX = protobuf
719 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags protobuf) $(CPPFLAGS)
720 LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L protobuf)
721 ifeq ($(SYSTEM),Linux)
722 ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),)
723 LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L protobuf | sed s/L/Wl,-rpath,/)
724 endif
725 endif
726 else
727 PC_LIBS_GRPCXX = -lprotobuf
728 endif
Nicolas "Pixel" Noblef7fbdd42016-07-25 20:31:22 +0200729 PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
Craig Tiller841c8802015-09-10 13:06:37 -0700730 else
731 ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
732 PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
733 CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
734 LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700735 ifneq ($(USE_BUILT_PROTOC),false)
Craig Tiller841c8802015-09-10 13:06:37 -0700736 PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700737 PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
738 else
739 PROTOC_PLUGINS =
740 PROTOC_PLUGINS_DIR = $(prefix)/bin
741 endif
Craig Tiller841c8802015-09-10 13:06:37 -0700742 else
743 NO_PROTOBUF = true
744 endif
745 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800746
Craig Tiller841c8802015-09-10 13:06:37 -0700747 LIBS_PROTOBUF = protobuf
748 LIBS_PROTOC = protoc protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800749
Craig Tiller841c8802015-09-10 13:06:37 -0700750 HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
Nicolas Noble53830622015-02-12 16:56:38 -0800751
Craig Tiller841c8802015-09-10 13:06:37 -0700752 ifeq ($(PROTOBUF_PKG_CONFIG),true)
753 LDLIBS_PROTOBUF += $(shell $(PKG_CONFIG) --libs-only-l protobuf)
754 else
755 LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
756 endif
murgatroid9924e2f4a2015-06-29 11:12:01 -0700757
Craig Tiller841c8802015-09-10 13:06:37 -0700758 # grpc++ .pc file
759 PC_NAME = gRPC++
760 PC_DESCRIPTION = C++ wrapper for gRPC
761 PC_CFLAGS =
762 PC_REQUIRES_PRIVATE = grpc $(PC_REQUIRES_GRPCXX)
763 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
764 PC_LIB = -lgrpc++
Craig Tiller38b99e92016-09-15 16:18:09 -0700765 GRPCXX_PC_FILE := $(CPP_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700766
Craig Tiller841c8802015-09-10 13:06:37 -0700767 # grpc++_unsecure .pc file
768 PC_NAME = gRPC++ unsecure
769 PC_DESCRIPTION = C++ wrapper for gRPC without SSL
770 PC_CFLAGS =
771 PC_REQUIRES_PRIVATE = grpc_unsecure $(PC_REQUIRES_GRPCXX)
772 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
773 PC_LIB = -lgrpc++
Craig Tiller38b99e92016-09-15 16:18:09 -0700774 GRPCXX_UNSECURE_PC_FILE := $(CPP_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700775
Craig Tiller841c8802015-09-10 13:06:37 -0700776 ifeq ($(MAKECMDGOALS),clean)
777 NO_DEPS = true
778 endif
nnoble69ac39f2014-12-12 15:43:38 -0800779
Craig Tiller841c8802015-09-10 13:06:37 -0700780 .SECONDARY = %.pb.h %.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800781
Craig Tiller841c8802015-09-10 13:06:37 -0700782 ifeq ($(DEP_MISSING),)
783 all: static shared plugins\
784 % for tgt in targets:
785 % if tgt.build == 'all':
786 $(BINDIR)/$(CONFIG)/${tgt.name}\
787 % endif
788 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800789
Craig Tiller841c8802015-09-10 13:06:37 -0700790 dep_error:
791 @echo "You shouldn't see this message - all of your dependencies are correct."
792 else
793 all: dep_error git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800794
Craig Tiller841c8802015-09-10 13:06:37 -0700795 dep_error:
796 @echo
797 @echo "DEPENDENCY ERROR"
798 @echo
799 @echo "You are missing system dependencies that are essential to build grpc,"
800 @echo "and the third_party directory doesn't have them:"
801 @echo
802 @echo " $(DEP_MISSING)"
803 @echo
804 @echo "Installing the development packages for your system will solve"
805 @echo "this issue. Please consult INSTALL to get more information."
806 @echo
807 @echo "If you need information about why these tests failed, run:"
808 @echo
809 @echo " make run_dep_checks"
810 @echo
811 endif
nnoble69ac39f2014-12-12 15:43:38 -0800812
Craig Tiller841c8802015-09-10 13:06:37 -0700813 git_update:
814 ifeq ($(IS_GIT_FOLDER),true)
815 @echo "Additionally, since you are in a git clone, you can download the"
816 @echo "missing dependencies in third_party by running the following command:"
817 @echo
818 @echo " git submodule update --init"
819 @echo
820 endif
nnoble69ac39f2014-12-12 15:43:38 -0800821
Craig Tiller841c8802015-09-10 13:06:37 -0700822 openssl_dep_error: openssl_dep_message git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800823
Craig Tiller841c8802015-09-10 13:06:37 -0700824 protobuf_dep_error: protobuf_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800825
Craig Tiller841c8802015-09-10 13:06:37 -0700826 protoc_dep_error: protoc_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800827
Craig Tiller841c8802015-09-10 13:06:37 -0700828 openssl_dep_message:
829 @echo
830 @echo "DEPENDENCY ERROR"
831 @echo
Craig Tillerb79c1e12016-02-23 10:00:58 -0800832 @echo "The target you are trying to run requires an OpenSSL implementation."
833 @echo "Your system doesn't have one, and either the third_party directory"
834 @echo "doesn't have it, or your compiler can't build BoringSSL."
Craig Tiller841c8802015-09-10 13:06:37 -0700835 @echo
836 @echo "Please consult INSTALL to get more information."
837 @echo
838 @echo "If you need information about why these tests failed, run:"
839 @echo
840 @echo " make run_dep_checks"
841 @echo
nnoble69ac39f2014-12-12 15:43:38 -0800842
Craig Tiller841c8802015-09-10 13:06:37 -0700843 protobuf_dep_message:
844 @echo
845 @echo "DEPENDENCY ERROR"
846 @echo
847 @echo "The target you are trying to run requires protobuf 3.0.0+"
848 @echo "Your system doesn't have it, and neither does the third_party directory."
849 @echo
850 @echo "Please consult INSTALL to get more information."
851 @echo
852 @echo "If you need information about why these tests failed, run:"
853 @echo
854 @echo " make run_dep_checks"
855 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800856
Craig Tiller841c8802015-09-10 13:06:37 -0700857 protoc_dep_message:
858 @echo
859 @echo "DEPENDENCY ERROR"
860 @echo
861 @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
862 @echo "Your system doesn't have it, and neither does the third_party directory."
863 @echo
864 @echo "Please consult INSTALL to get more information."
865 @echo
866 @echo "If you need information about why these tests failed, run:"
867 @echo
868 @echo " make run_dep_checks"
869 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800870
Craig Tiller841c8802015-09-10 13:06:37 -0700871 systemtap_dep_error:
872 @echo
873 @echo "DEPENDENCY ERROR"
874 @echo
875 @echo "Under the '$(CONFIG)' configutation, the target you are trying "
876 @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other "
877 @echo "platforms such as Solaris and *BSD). "
878 @echo
879 @echo "Please consult INSTALL to get more information."
880 @echo
David Garcia Quintas8954e902015-04-29 09:46:33 -0700881
Craig Tiller841c8802015-09-10 13:06:37 -0700882 stop:
883 @false
nnoble69ac39f2014-12-12 15:43:38 -0800884
Craig Tiller841c8802015-09-10 13:06:37 -0700885 % for tgt in targets:
886 ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
887 % endfor
ctiller09cb6d52014-12-19 17:38:22 -0800888
Craig Tiller841c8802015-09-10 13:06:37 -0700889 run_dep_checks:
890 $(OPENSSL_ALPN_CHECK_CMD) || true
891 $(OPENSSL_NPN_CHECK_CMD) || true
892 $(ZLIB_CHECK_CMD) || true
893 $(PERFTOOLS_CHECK_CMD) || true
894 $(PROTOBUF_CHECK_CMD) || true
895 $(PROTOC_CHECK_VERSION_CMD) || true
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700896 $(CARES_CHECK_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800897
Craig Tiller841c8802015-09-10 13:06:37 -0700898 third_party/protobuf/configure:
899 $(E) "[AUTOGEN] Preparing protobuf"
900 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
Nicolas Noble53830622015-02-12 16:56:38 -0800901
Craig Tiller841c8802015-09-10 13:06:37 -0700902 $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
903 $(E) "[MAKE] Building protobuf"
Vijay Pai52338fb2018-01-11 00:25:00 -0800904 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700905 $(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g $(PROTOBUF_LDFLAGS_EXTRA)" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g $(PROTOBUF_CPPFLAGS_EXTRA)" ./configure --disable-shared --enable-static $(PROTOBUF_CONFIG_OPTS))
Craig Tiller841c8802015-09-10 13:06:37 -0700906 $(Q)$(MAKE) -C third_party/protobuf clean
907 $(Q)$(MAKE) -C third_party/protobuf
Craig Tiller841c8802015-09-10 13:06:37 -0700908 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
909 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
910 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
911 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800912
Craig Tiller841c8802015-09-10 13:06:37 -0700913 static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800914
Craig Tillereda85c62016-07-01 12:45:19 -0700915 static_c: pc_c pc_c_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700916 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100917 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700918 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
919 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
920 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100921 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700922 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800923
924
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100925 static_cxx: pc_cxx pc_cxx_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700926 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100927 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700928 % if lib.build == 'all' and lib.language == 'c++':
929 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
930 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100931 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700932 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800933
934
Craig Tiller841c8802015-09-10 13:06:37 -0700935 shared: shared_c shared_cxx
nnoble29e1d292014-12-01 10:27:40 -0800936
Craig Tillereda85c62016-07-01 12:45:19 -0700937 shared_c: pc_c pc_c_unsecure cache.mk\
Craig Tiller841c8802015-09-10 13:06:37 -0700938 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100939 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700940 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -0700941 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)\
Craig Tiller841c8802015-09-10 13:06:37 -0700942 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100943 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700944 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800945
Craig Tiller841c8802015-09-10 13:06:37 -0700946 shared_cxx: pc_cxx pc_cxx_unsecure cache.mk\
947 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100948 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700949 % if lib.build == 'all' and lib.language == 'c++':
Craig Tiller27f70842016-09-15 16:21:54 -0700950 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)\
Craig Tiller841c8802015-09-10 13:06:37 -0700951 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100952 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700953 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800954
955
Craig Tiller841c8802015-09-10 13:06:37 -0700956 shared_csharp: shared_c \
957 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100958 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700959 % if lib.build == 'all' and lib.language == 'csharp':
Craig Tiller27f70842016-09-15 16:21:54 -0700960 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)\
Craig Tiller841c8802015-09-10 13:06:37 -0700961 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100962 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700963 % endfor
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800964
Craig Tiller841c8802015-09-10 13:06:37 -0700965 grpc_csharp_ext: shared_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800966
Craig Tiller841c8802015-09-10 13:06:37 -0700967 plugins: $(PROTOC_PLUGINS)
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100968
Craig Tiller841c8802015-09-10 13:06:37 -0700969 privatelibs: privatelibs_c privatelibs_cxx
nnoble29e1d292014-12-01 10:27:40 -0800970
Craig Tiller841c8802015-09-10 13:06:37 -0700971 privatelibs_c: \
972 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100973 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800974 % 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 -0700975 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
976 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100977 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700978 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800979
Craig Tiller841c8802015-09-10 13:06:37 -0700980 pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc
murgatroid998faab232015-06-30 17:24:21 -0700981
Craig Tiller841c8802015-09-10 13:06:37 -0700982 pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -0700983
Craig Tiller841c8802015-09-10 13:06:37 -0700984 pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc
murgatroid998faab232015-06-30 17:24:21 -0700985
Craig Tiller841c8802015-09-10 13:06:37 -0700986 pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800987
vjpai20410922016-06-15 09:21:42 -0700988 ifeq ($(EMBED_OPENSSL),true)
Craig Tiller841c8802015-09-10 13:06:37 -0700989 privatelibs_cxx: \
990 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100991 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700992 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None):
993 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
994 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100995 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700996 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -0700997
vjpai20410922016-06-15 09:21:42 -0700998 else
999 privatelibs_cxx: \
1000 % for lib in libs:
1001 % if 'Makefile' in lib.get('build_system', ['Makefile']):
1002 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None) and not lib.boringssl:
1003 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
1004 % endif
1005 % endif
1006 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -07001007
vjpai20410922016-06-15 09:21:42 -07001008 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001009
1010
Craig Tillereda85c62016-07-01 12:45:19 -07001011 buildtests: buildtests_c buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -08001012
Craig Tiller3824b6e2015-12-09 11:19:59 -08001013 buildtests_c: privatelibs_c <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001014 % for tgt in targets:
1015 % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -08001016 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001017 % endif
1018 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001019
1020
vjpai20410922016-06-15 09:21:42 -07001021 ifeq ($(EMBED_OPENSSL),true)
Craig Tillereda85c62016-07-01 12:45:19 -07001022 buildtests_cxx: privatelibs_cxx <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001023 % for tgt in targets:
1024 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -08001025 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001026 % endif
1027 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -07001028
vjpai20410922016-06-15 09:21:42 -07001029 else
Craig Tillereda85c62016-07-01 12:45:19 -07001030 buildtests_cxx: privatelibs_cxx <%text>\</%text>
vjpai20410922016-06-15 09:21:42 -07001031 % for tgt in targets:
1032 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl:
1033 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
1034 % endif
1035 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -07001036
vjpai20410922016-06-15 09:21:42 -07001037 endif
nnoble29e1d292014-12-01 10:27:40 -08001038
1039
Craig Tillereda85c62016-07-01 12:45:19 -07001040 test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -08001041
Craig Tillereda85c62016-07-01 12:45:19 -07001042 flaky_test: flaky_test_c flaky_test_cxx
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001043
Craig Tiller841c8802015-09-10 13:06:37 -07001044 test_c: buildtests_c
1045 % for tgt in targets:
1046 % 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):
1047 $(E) "[RUN] Testing ${tgt.name}"
1048 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1049 % endif
1050 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001051
1052
Craig Tiller841c8802015-09-10 13:06:37 -07001053 flaky_test_c: buildtests_c
1054 % for tgt in targets:
1055 % 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):
1056 $(E) "[RUN] Testing ${tgt.name}"
1057 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1058 % endif
1059 % endfor
nnoble29e1d292014-12-01 10:27:40 -08001060
1061
Craig Tillereda85c62016-07-01 12:45:19 -07001062 test_cxx: buildtests_cxx
Craig Tiller841c8802015-09-10 13:06:37 -07001063 % for tgt in targets:
1064 % 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):
1065 $(E) "[RUN] Testing ${tgt.name}"
1066 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1067 % endif
1068 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001069
1070
Craig Tiller841c8802015-09-10 13:06:37 -07001071 flaky_test_cxx: buildtests_cxx
1072 % for tgt in targets:
1073 % 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):
1074 $(E) "[RUN] Testing ${tgt.name}"
1075 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1076 % endif
1077 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001078
1079
Craig Tiller841c8802015-09-10 13:06:37 -07001080 test_python: static_c
1081 $(E) "[RUN] Testing python code"
1082 $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
Nicolas "Pixel" Noble051a28f2015-03-17 22:54:54 +01001083
1084
Craig Tiller841c8802015-09-10 13:06:37 -07001085 tools: tools_c tools_cxx
Craig Tiller7552f0f2015-06-19 17:46:20 -07001086
1087
Craig Tiller841c8802015-09-10 13:06:37 -07001088 tools_c: privatelibs_c\
1089 % for tgt in targets:
1090 % if tgt.build == 'tool' and not tgt.language=='c++':
1091 $(BINDIR)/$(CONFIG)/${tgt.name}\
1092 % endif
1093 % endfor
Craig Tiller7552f0f2015-06-19 17:46:20 -07001094
1095
Craig Tiller841c8802015-09-10 13:06:37 -07001096 tools_cxx: privatelibs_cxx\
1097 % for tgt in targets:
1098 % if tgt.build == 'tool' and tgt.language=='c++':
1099 $(BINDIR)/$(CONFIG)/${tgt.name}\
1100 % endif
1101 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001102
1103
Craig Tiller841c8802015-09-10 13:06:37 -07001104 buildbenchmarks: privatelibs\
1105 % for tgt in targets:
1106 % if tgt.build == 'benchmark':
1107 $(BINDIR)/$(CONFIG)/${tgt.name}\
1108 % endif
1109 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001110
1111
Craig Tiller841c8802015-09-10 13:06:37 -07001112 benchmarks: buildbenchmarks
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001113
Craig Tiller841c8802015-09-10 13:06:37 -07001114 strip: strip-static strip-shared
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001115
Craig Tiller841c8802015-09-10 13:06:37 -07001116 strip-static: strip-static_c strip-static_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001117
Craig Tiller841c8802015-09-10 13:06:37 -07001118 strip-shared: strip-shared_c strip-shared_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001119
Nicolas Noble047b7272015-01-16 13:55:05 -08001120
Craig Tiller841c8802015-09-10 13:06:37 -07001121 # TODO(nnoble): the strip target is stripping in-place, instead
1122 # of copying files in a temporary folder.
1123 # This prevents proper debugging after running make install.
Nicolas Noble047b7272015-01-16 13:55:05 -08001124
Craig Tiller841c8802015-09-10 13:06:37 -07001125 strip-static_c: static_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):
1132 $(E) "[STRIP] Stripping lib${lib.name}.a"
1133 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1134 % endif
1135 % endif
1136 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001137 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001138 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001139 endif
nnoble85a49262014-12-08 18:14:03 -08001140
Craig Tiller841c8802015-09-10 13:06:37 -07001141 strip-static_cxx: static_cxx
1142 ifeq ($(CONFIG),opt)
1143 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001144 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001145 % if lib.language == "c++":
1146 % if lib.build == "all":
1147 $(E) "[STRIP] Stripping lib${lib.name}.a"
1148 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1149 % endif
1150 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001151 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001152 % endfor
1153 endif
Nicolas "Pixel" Noble4ef9b862015-08-14 19:35:24 +02001154
Craig Tiller841c8802015-09-10 13:06:37 -07001155 strip-shared_c: shared_c
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":
1161 % if not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -07001162 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)"
1163 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)
Craig Tiller841c8802015-09-10 13:06:37 -07001164 % endif
1165 % endif
1166 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001167 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001168 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001169 endif
nnoble85a49262014-12-08 18:14:03 -08001170
Craig Tiller841c8802015-09-10 13:06:37 -07001171 strip-shared_cxx: shared_cxx
1172 ifeq ($(CONFIG),opt)
1173 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001174 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001175 % if lib.language == "c++":
1176 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001177 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)"
1178 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)
Craig Tiller841c8802015-09-10 13:06:37 -07001179 % endif
1180 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001181 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001182 % endfor
1183 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001184
Craig Tiller841c8802015-09-10 13:06:37 -07001185 strip-shared_csharp: shared_csharp
1186 ifeq ($(CONFIG),opt)
1187 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001188 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001189 % if lib.language == "csharp":
1190 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001191 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)"
1192 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)
Craig Tiller841c8802015-09-10 13:06:37 -07001193 % endif
1194 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001195 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001196 % endfor
1197 endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001198
Craig Tiller841c8802015-09-10 13:06:37 -07001199 cache.mk::
1200 $(E) "[MAKE] Generating $@"
1201 $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@
murgatroid99aa521572015-07-10 14:49:12 -07001202
Craig Tiller841c8802015-09-10 13:06:37 -07001203 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc:
1204 $(E) "[MAKE] Generating $@"
1205 $(Q) mkdir -p $(@D)
1206 $(Q) echo "$(GRPC_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001207
Craig Tiller841c8802015-09-10 13:06:37 -07001208 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc:
1209 $(E) "[MAKE] Generating $@"
1210 $(Q) mkdir -p $(@D)
1211 $(Q) echo "$(GRPC_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001212
Craig Tiller841c8802015-09-10 13:06:37 -07001213 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc:
1214 $(E) "[MAKE] Generating $@"
1215 $(Q) mkdir -p $(@D)
1216 $(Q) echo "$(GRPCXX_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001217
Craig Tiller841c8802015-09-10 13:06:37 -07001218 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc:
1219 $(E) "[MAKE] Generating $@"
1220 $(Q) mkdir -p $(@D)
1221 $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001222
Craig Tiller841c8802015-09-10 13:06:37 -07001223 % for p in protos:
1224 ifeq ($(NO_PROTOC),true)
1225 $(GENDIR)/${p}.pb.cc: protoc_dep_error
1226 $(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error
1227 else
Mahak Mukhifb059a22017-04-18 14:40:00 -07001228 <%
1229 pluginflags=""
1230 %>
1231 % if p in ["src/proto/grpc/testing/compiler_test", "src/proto/grpc/testing/echo"]:
1232 <%
1233 pluginflags="generate_mock_code=true:"
1234 %>
1235 % endif
Craig Tiller1b4e3302015-12-17 16:35:00 -08001236 $(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 -07001237 $(E) "[PROTOC] Generating protobuf CC file from $<"
1238 $(Q) mkdir -p `dirname $@`
David Garcia Quintase68ed6f2016-06-17 12:49:14 -07001239 $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --cpp_out=$(GENDIR) $<
Nicolas "Pixel" Noble0caebbf2015-04-09 23:08:51 +02001240
Vijay Paie00f2a32017-07-31 01:04:45 -07001241 $(GENDIR)/${p}.grpc.pb.cc: ${p}.proto $(GENDIR)/${p}.pb.cc $(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 -07001242 $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
1243 $(Q) mkdir -p `dirname $@`
Mahak Mukhifb059a22017-04-18 14:40:00 -07001244 $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=${pluginflags}$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $<
Craig Tiller841c8802015-09-10 13:06:37 -07001245 endif
nnoble72309c62014-12-12 11:42:26 -08001246
Craig Tiller841c8802015-09-10 13:06:37 -07001247 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001248
Craig Tiller841c8802015-09-10 13:06:37 -07001249 ifeq ($(CONFIG),stapprof)
1250 src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h
1251 ifeq ($(HAS_SYSTEMTAP),true)
1252 $(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d
1253 $(E) "[DTRACE] Compiling $<"
1254 $(Q) mkdir -p `dirname $@`
1255 $(Q) $(DTRACE) -C -h -s $< -o $@
1256 else
1257 $(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop
1258 endif
1259 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -07001260
Craig Tiller841c8802015-09-10 13:06:37 -07001261 $(OBJDIR)/$(CONFIG)/%.o : %.c
1262 $(E) "[C] Compiling $<"
1263 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001264 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001265
Craig Tiller841c8802015-09-10 13:06:37 -07001266 $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
1267 $(E) "[CXX] Compiling $<"
1268 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001269 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001270
Craig Tiller841c8802015-09-10 13:06:37 -07001271 $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
1272 $(E) "[HOSTCXX] Compiling $<"
1273 $(Q) mkdir -p `dirname $@`
1274 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -08001275
ncteisenf9d7c272017-11-06 20:32:57 -08001276 $(OBJDIR)/$(CONFIG)/src/core/%.o : src/core/%.cc
1277 $(E) "[CXX] Compiling $<"
1278 $(Q) mkdir -p `dirname $@`
1279 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
1280
1281 $(OBJDIR)/$(CONFIG)/test/core/%.o : test/core/%.cc
1282 $(E) "[CXX] Compiling $<"
1283 $(Q) mkdir -p `dirname $@`
1284 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
1285
Craig Tiller841c8802015-09-10 13:06:37 -07001286 $(OBJDIR)/$(CONFIG)/%.o : %.cc
1287 $(E) "[CXX] Compiling $<"
1288 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001289 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001290
murgatroid99a3c55352016-08-10 13:41:31 -07001291 install: install_c install_cxx install-plugins install-certs
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001292
Craig Tiller841c8802015-09-10 13:06:37 -07001293 install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001294
Craig Tiller841c8802015-09-10 13:06:37 -07001295 install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
nnoble85a49262014-12-08 18:14:03 -08001296
Craig Tiller841c8802015-09-10 13:06:37 -07001297 install_csharp: install-shared_csharp install_c
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001298
Craig Tiller841c8802015-09-10 13:06:37 -07001299 install_grpc_csharp_ext: install_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001300
Craig Tiller841c8802015-09-10 13:06:37 -07001301 install-headers: install-headers_c install-headers_cxx
nnoble85a49262014-12-08 18:14:03 -08001302
Craig Tiller841c8802015-09-10 13:06:37 -07001303 install-headers_c:
1304 $(E) "[INSTALL] Installing public C headers"
1305 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1306 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001307
Craig Tiller841c8802015-09-10 13:06:37 -07001308 install-headers_cxx:
1309 $(E) "[INSTALL] Installing public C++ headers"
1310 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1311 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001312
Craig Tiller841c8802015-09-10 13:06:37 -07001313 install-static: install-static_c install-static_cxx
nnoble85a49262014-12-08 18:14:03 -08001314
Craig Tiller841c8802015-09-10 13:06:37 -07001315 install-static_c: static_c strip-static_c install-pkg-config_c
1316 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001317 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001318 % if lib.language == "c":
1319 % if lib.build == "all":
1320 % if not lib.get('external_deps', None):
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
1326 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001327 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001328 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001329
Craig Tiller841c8802015-09-10 13:06:37 -07001330 install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx
1331 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001332 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001333 % if lib.language == "c++":
1334 % if lib.build == "all":
1335 $(E) "[INSTALL] Installing lib${lib.name}.a"
1336 $(Q) $(INSTALL) -d $(prefix)/lib
1337 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1338 % endif
1339 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001340 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001341 % endfor
nnoble85a49262014-12-08 18:14:03 -08001342
Craig Tiller841c8802015-09-10 13:06:37 -07001343 <%def name="install_shared(lang_filter)">\
1344 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001345 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001346 % if lib.language == lang_filter:
1347 % if lib.build == "all":
1348 % if not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -07001349 $(E) "[INSTALL] Installing $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]})"
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001350 $(Q) $(INSTALL) -d $(prefix)/lib
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001351 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) $(prefix)/lib/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]})
Craig Tiller841c8802015-09-10 13:06:37 -07001352 ifeq ($(SYSTEM),MINGW32)
Mario Emmenlauer44b2d082017-01-13 12:35:49 +01001353 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]})-dll.a $(prefix)/lib/lib${lib.name}.a
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +01001354 else ifneq ($(SYSTEM),Darwin)
Craig Tiller27f70842016-09-15 16:21:54 -07001355 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) $(prefix)/lib/lib${lib.name}.so.${settings.core_version.major}
1356 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) $(prefix)/lib/lib${lib.name}.so
Craig Tiller841c8802015-09-10 13:06:37 -07001357 endif
1358 % endif
1359 % endif
1360 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001361 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001362 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001363 ifneq ($(SYSTEM),MINGW32)
1364 ifneq ($(SYSTEM),Darwin)
1365 $(Q) ldconfig || true
1366 endif
1367 endif
1368 </%def>
nnoble85a49262014-12-08 18:14:03 -08001369
Craig Tiller841c8802015-09-10 13:06:37 -07001370 install-shared_c: shared_c strip-shared_c install-pkg-config_c
1371 ${install_shared("c")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001372
Craig Tiller841c8802015-09-10 13:06:37 -07001373 install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c install-pkg-config_cxx
1374 ${install_shared("c++")}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001375
Craig Tiller841c8802015-09-10 13:06:37 -07001376 install-shared_csharp: shared_csharp strip-shared_csharp
1377 ${install_shared("csharp")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001378
Craig Tiller841c8802015-09-10 13:06:37 -07001379 install-plugins: $(PROTOC_PLUGINS)
Craig Tiller841c8802015-09-10 13:06:37 -07001380 $(E) "[INSTALL] Installing grpc protoc plugins"
1381 % for tgt in targets:
1382 % if tgt.build == 'protoc':
1383 $(Q) $(INSTALL) -d $(prefix)/bin
1384 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
1385 % endif
1386 % endfor
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001387
Tobias Jungel5e176d52018-01-23 10:30:55 +01001388 install-grpc-cli: grpc_cli
1389 $(E) "[INSTALL] Installing grpc cli"
1390 $(Q) $(INSTALL) -d $(prefix)/bin
1391 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/grpc_cli $(prefix)/bin/grpc_cli
1392
Craig Tillereda85c62016-07-01 12:45:19 -07001393 install-pkg-config_c: pc_c pc_c_unsecure
Craig Tiller841c8802015-09-10 13:06:37 -07001394 $(E) "[INSTALL] Installing C pkg-config files"
1395 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
ncteisenbddedb92017-12-20 13:49:46 -05001396 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(prefix)/lib/pkgconfig/grpc.pc
1397 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(prefix)/lib/pkgconfig/grpc_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -07001398
Craig Tiller841c8802015-09-10 13:06:37 -07001399 install-pkg-config_cxx: pc_cxx pc_cxx_unsecure
1400 $(E) "[INSTALL] Installing C++ pkg-config files"
1401 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
ncteisenbddedb92017-12-20 13:49:46 -05001402 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc $(prefix)/lib/pkgconfig/grpc++.pc
1403 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc $(prefix)/lib/pkgconfig/grpc++_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -07001404
Craig Tiller841c8802015-09-10 13:06:37 -07001405 install-certs: etc/roots.pem
1406 $(E) "[INSTALL] Installing root certificates"
1407 $(Q) $(INSTALL) -d $(prefix)/share/grpc
1408 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +01001409
Craig Tiller841c8802015-09-10 13:06:37 -07001410 clean:
1411 $(E) "[CLEAN] Cleaning build directories."
1412 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001413
1414
Craig Tiller841c8802015-09-10 13:06:37 -07001415 # The various libraries
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001416
Craig Tiller841c8802015-09-10 13:06:37 -07001417 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001418 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001419 ${makelib(lib)}
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001420 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001421 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001422
1423
Craig Tiller841c8802015-09-10 13:06:37 -07001424 # All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001425
Craig Tiller841c8802015-09-10 13:06:37 -07001426 % for tgt in targets:
1427 ${maketarget(tgt)}
1428 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001429
Craig Tiller841c8802015-09-10 13:06:37 -07001430 <%def name="makelib(lib)">
1431 LIB${lib.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001432
Craig Tiller841c8802015-09-10 13:06:37 -07001433 % for src in lib.src:
1434 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001435
Craig Tiller841c8802015-09-10 13:06:37 -07001436 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001437
Craig Tiller841c8802015-09-10 13:06:37 -07001438 % if "public_headers" in lib:
1439 % if lib.language == "c++":
1440 PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001441
Craig Tiller841c8802015-09-10 13:06:37 -07001442 % else:
1443 PUBLIC_HEADERS_C += \\
nnoble85a49262014-12-08 18:14:03 -08001444
Craig Tiller841c8802015-09-10 13:06:37 -07001445 % endif
1446 % for hdr in lib.public_headers:
1447 ${hdr} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001448
Craig Tiller841c8802015-09-10 13:06:37 -07001449 % endfor
1450 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001451
Craig Tiller841c8802015-09-10 13:06:37 -07001452 LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001453
Nicolas "Pixel" Noble51b1aee2016-01-28 01:14:58 +01001454 % if lib.get('defaults', None):
1455 % for name, value in defaults.get(lib.defaults).iteritems():
1456 $(LIB${lib.name.upper()}_OBJS): ${name} += ${value}
1457 % endfor
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001458 % endif
1459
Craig Tiller841c8802015-09-10 13:06:37 -07001460 ## If the library requires OpenSSL, let's add some restrictions.
1461 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1462 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001463
Craig Tiller841c8802015-09-10 13:06:37 -07001464 # You can't build secure libraries if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001465
Craig Tiller841c8802015-09-10 13:06:37 -07001466 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001467
Craig Tiller841c8802015-09-10 13:06:37 -07001468 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001469 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}): openssl_dep_error
Craig Tiller841c8802015-09-10 13:06:37 -07001470 % endif
nnoble5b7f32a2014-12-22 08:12:44 -08001471
Craig Tiller841c8802015-09-10 13:06:37 -07001472 else
nnoble69ac39f2014-12-12 15:43:38 -08001473
Craig Tiller841c8802015-09-10 13:06:37 -07001474 % if lib.language == 'c++':
1475 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001476
Craig Tiller841c8802015-09-10 13:06:37 -07001477 # 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 -08001478
Craig Tiller841c8802015-09-10 13:06:37 -07001479 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001480
Craig Tiller841c8802015-09-10 13:06:37 -07001481 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001482 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}): protobuf_dep_error
Craig Tiller841c8802015-09-10 13:06:37 -07001483 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001484
Craig Tiller841c8802015-09-10 13:06:37 -07001485 else
1486 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001487
Alexander Polcyn690dde62017-10-18 00:20:33 -07001488 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP)\
Craig Tiller841c8802015-09-10 13:06:37 -07001489 ## The else here corresponds to the if secure earlier.
1490 % else:
1491 % if lib.language == 'c++':
1492 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001493
Craig Tiller841c8802015-09-10 13:06:37 -07001494 # 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 -08001495
Craig Tiller841c8802015-09-10 13:06:37 -07001496 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001497
Craig Tiller841c8802015-09-10 13:06:37 -07001498 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001499 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}): protobuf_dep_error
Craig Tiller841c8802015-09-10 13:06:37 -07001500 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001501
Craig Tiller841c8802015-09-10 13:06:37 -07001502 else
Nicolas Noble53830622015-02-12 16:56:38 -08001503
Craig Tiller841c8802015-09-10 13:06:37 -07001504 % endif
Yuchen Zeng78f9f942016-08-05 18:21:57 -07001505 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: \
Nicolas "Pixel" Nobled649c212016-01-27 20:27:30 +01001506 % if lib.name != 'z':
1507 $(ZLIB_DEP) \
1508 % endif
Yuchen Zeng15141a62016-08-17 18:56:04 -07001509 % if lib.name != 'ares':
1510 $(CARES_DEP) \
Yuchen Zengf64bf282016-08-11 21:21:32 -07001511 % endif
Alexander Polcyn690dde62017-10-18 00:20:33 -07001512 % if lib.name != 'address_sorting':
1513 $(ADDRESS_SORTING_DEP) \
1514 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001515 % endif
1516 % if lib.language == 'c++':
1517 $(PROTOBUF_DEP)\
1518 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001519 $(LIB${lib.name.upper()}_OBJS) \
1520 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001521 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001522 $(ZLIB_MERGE_OBJS) \
Yuchen Zeng15141a62016-08-17 18:56:04 -07001523 $(CARES_MERGE_OBJS) \
Alexander Polcyn690dde62017-10-18 00:20:33 -07001524 $(ADDRESS_SORTING_MERGE_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001525 % if lib.get('secure', 'check') == True:
1526 $(OPENSSL_MERGE_OBJS) \
1527 % endif
1528 % endif
1529
Craig Tiller841c8802015-09-10 13:06:37 -07001530 $(E) "[AR] Creating $@"
1531 $(Q) mkdir -p `dirname $@`
1532 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Vijay Paicc7eb8e2016-07-19 19:03:55 -07001533 $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001534 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001535 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001536 $(ZLIB_MERGE_OBJS) \
Yuchen Zeng15141a62016-08-17 18:56:04 -07001537 $(CARES_MERGE_OBJS) \
Alexander Polcyn690dde62017-10-18 00:20:33 -07001538 $(ADDRESS_SORTING_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001539 % if lib.get('secure', 'check') == True:
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001540 $(OPENSSL_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001541 % endif
1542 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001543
Craig Tiller841c8802015-09-10 13:06:37 -07001544 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001545 $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tiller841c8802015-09-10 13:06:37 -07001546 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001547
Craig Tiller841c8802015-09-10 13:06:37 -07001548 <%
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001549
Craig Tiller841c8802015-09-10 13:06:37 -07001550 if lib.language == 'c++':
1551 ld = '$(LDXX)'
1552 else:
1553 ld = '$(LD)'
nnoble5b7f32a2014-12-22 08:12:44 -08001554
Craig Tiller40c8fba2016-09-15 16:29:09 -07001555 out_mingbase = '$(LIBDIR)/$(CONFIG)/' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
1556 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
nnoble5b7f32a2014-12-22 08:12:44 -08001557
Nicolas "Pixel" Noble8087d702017-02-01 02:23:50 +01001558 common = '$(LIB' + lib.name.upper() + '_OBJS)'
nnoble5b7f32a2014-12-22 08:12:44 -08001559
Craig Tillerd7b1bdf2016-11-04 16:20:13 -07001560 link_libs = ''
Alexander Polcyn690dde62017-10-18 00:20:33 -07001561 lib_deps = ' $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP)'
Craig Tiller841c8802015-09-10 13:06:37 -07001562 mingw_libs = ''
Alexander Polcyn690dde62017-10-18 00:20:33 -07001563 mingw_lib_deps = ' $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP)'
Craig Tiller841c8802015-09-10 13:06:37 -07001564 if lib.language == 'c++':
1565 lib_deps += ' $(PROTOBUF_DEP)'
1566 mingw_lib_deps += ' $(PROTOBUF_DEP)'
Jan Tattermusch324140c2016-01-12 08:54:01 -08001567 if lib.get('deps_linkage', None) == 'static':
1568 for dep in lib.get('deps', []):
1569 lib_archive = '$(LIBDIR)/$(CONFIG)/lib' + dep + '.a'
1570 common = common + ' ' + lib_archive
1571 lib_deps = lib_deps + ' ' + lib_archive
1572 mingw_lib_deps = mingw_lib_deps + ' ' + lib_archive
1573 else:
1574 for dep in lib.get('deps', []):
Craig Tillerd7b1bdf2016-11-04 16:20:13 -07001575 dep_lib = None
1576 for dl in libs:
1577 if dl.name == dep:
1578 dep_lib = dl
1579 assert dep_lib, 'lib %s not found (in %s)' % (dep, lib.name)
1580 link_libs = link_libs + ' -l' + dep
1581 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT_' + lang_to_var[dep_lib.language] + ')'
Mario Emmenlauer44b2d082017-01-13 12:35:49 +01001582 mingw_libs = mingw_libs + ' -l' + dep + '$(SHARED_VERSION_' + lang_to_var[dep_lib.language] + ')-dll'
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001583 mingw_lib_deps = mingw_lib_deps + ' $(LIBDIR)/$(CONFIG)/' + dep + '$(SHARED_VERSION_' + lang_to_var[dep_lib.language] + ').$(SHARED_EXT_' + lang_to_var[dep_lib.language] + ')'
nnoble5b7f32a2014-12-22 08:12:44 -08001584
Craig Tiller841c8802015-09-10 13:06:37 -07001585 security = lib.get('secure', 'check')
1586 if security == True:
1587 common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)'
Alexander Polcyn690dde62017-10-18 00:20:33 -07001588 common = common + ' $(ZLIB_MERGE_LIBS) $(CARES_MERGE_LIBS) $(ADDRESS_SORTING_MERGE_LIBS)'
Nicolas "Pixel" Noblea7c162c2015-07-24 20:21:51 +02001589
Craig Tiller841c8802015-09-10 13:06:37 -07001590 if security in [True, 'check']:
1591 for src in lib.src:
1592 if not proto_re.match(src):
1593 sources_that_need_openssl.add(src)
1594 else:
1595 for src in lib.src:
1596 sources_that_don_t_need_openssl.add(src)
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001597
Craig Tiller841c8802015-09-10 13:06:37 -07001598 if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1599 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1600 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001601
Craig Tiller841c8802015-09-10 13:06:37 -07001602 if lib.language == 'c++':
1603 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
Craig Tiller4bef7ce2016-02-02 08:38:43 -08001604
1605 ldflags = '$(LDFLAGS)'
1606 if lib.get('LDFLAGS', None):
1607 ldflags += ' ' + lib['LDFLAGS']
Nicolas "Pixel" Noble8087d702017-02-01 02:23:50 +01001608
1609 common = common + ' $(LDLIBS)'
Craig Tiller841c8802015-09-10 13:06:37 -07001610 %>
nnoble5b7f32a2014-12-22 08:12:44 -08001611
Craig Tiller841c8802015-09-10 13:06:37 -07001612 % if lib.build == "all":
1613 ifeq ($(SYSTEM),MINGW32)
Craig Tiller38b99e92016-09-15 16:18:09 -07001614 ${out_mingbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Craig Tiller841c8802015-09-10 13:06:37 -07001615 $(E) "[LD] Linking $@"
1616 $(Q) mkdir -p `dirname $@`
Mario Emmenlauer294dc2f2016-12-13 00:07:12 +01001617 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=${out_mingbase}.def -Wl,--out-implib=${out_libbase}-dll.a -o ${out_mingbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${mingw_libs}
Craig Tiller841c8802015-09-10 13:06:37 -07001618 else
Craig Tiller38b99e92016-09-15 16:18:09 -07001619 ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
Craig Tiller841c8802015-09-10 13:06:37 -07001620 $(E) "[LD] Linking $@"
1621 $(Q) mkdir -p `dirname $@`
1622 ifeq ($(SYSTEM),Darwin)
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001623 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) -dynamiclib -o ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${link_libs}
Craig Tiller841c8802015-09-10 13:06:37 -07001624 else
murgatroid99d166e382017-03-24 10:03:10 -07001625 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.get(lang_to_var[lib.language].lower() + '_version').major} -o ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${link_libs}
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001626 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) ${out_libbase}.so.${settings.get(lang_to_var[lib.language].lower() + '_version').major}
1627 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) ${out_libbase}.so
Craig Tiller841c8802015-09-10 13:06:37 -07001628 endif
1629 endif
1630 % endif
1631 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1632 ## If the lib was secure, we have to close the Makefile's if that tested
1633 ## the presence of OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001634
Craig Tiller841c8802015-09-10 13:06:37 -07001635 endif
1636 % endif
1637 % if lib.language == 'c++':
1638 ## If the lib was C++, we have to close the Makefile's if that tested
1639 ## the presence of protobuf 3.0.0+
nnoble69ac39f2014-12-12 15:43:38 -08001640
Craig Tiller841c8802015-09-10 13:06:37 -07001641 endif
1642 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001643
Craig Tiller841c8802015-09-10 13:06:37 -07001644 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1645 ifneq ($(NO_SECURE),true)
1646 % endif
1647 ifneq ($(NO_DEPS),true)
1648 -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
1649 endif
1650 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1651 endif
1652 % endif
1653 % for src in lib.src:
1654 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src):
1655 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))}
1656 % endif
1657 % endfor
1658 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001659
Craig Tiller841c8802015-09-10 13:06:37 -07001660 <%def name="maketarget(tgt)"><% has_no_sources = not tgt.src %>
1661 % if not has_no_sources:
1662 ${tgt.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001663
Craig Tiller841c8802015-09-10 13:06:37 -07001664 % for src in tgt.src:
1665 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001666
Craig Tiller841c8802015-09-10 13:06:37 -07001667 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001668
Craig Tiller841c8802015-09-10 13:06:37 -07001669 ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
1670 % endif
1671 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1672 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001673
Craig Tiller841c8802015-09-10 13:06:37 -07001674 # You can't build secure targets if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001675
Craig Tiller841c8802015-09-10 13:06:37 -07001676 $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001677
Craig Tiller841c8802015-09-10 13:06:37 -07001678 else
nnoble69ac39f2014-12-12 15:43:38 -08001679
Craig Tiller841c8802015-09-10 13:06:37 -07001680 % endif
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001681
1682 % if tgt.boringssl:
1683 # boringssl needs an override to ensure that it does not include
1684 # system openssl headers regardless of other configuration
1685 # we do so here with a target specific variable assignment
Craig Tiller78222f72016-05-10 09:55:38 -07001686 $(${tgt.name.upper()}_OBJS): CFLAGS := -Ithird_party/boringssl/include $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value $(NO_W_EXTRA_SEMI)
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001687 $(${tgt.name.upper()}_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS)
1688 $(${tgt.name.upper()}_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE
1689 % else:
1690 % endif
1691
Craig Tiller841c8802015-09-10 13:06:37 -07001692 ##
1693 ## We're not trying to add a dependency on building zlib and openssl here,
1694 ## as it's already done in the libraries. We're assuming that the build
1695 ## trickles down, and that a secure target requires a secure version of
1696 ## a library.
1697 ##
1698 ## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1699 ## I can live with that.
1700 ##
1701 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001702
Craig Tiller841c8802015-09-10 13:06:37 -07001703 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001704
Craig Tiller841c8802015-09-10 13:06:37 -07001705 # 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 -08001706
Craig Tiller841c8802015-09-10 13:06:37 -07001707 $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001708
Craig Tiller841c8802015-09-10 13:06:37 -07001709 else
Nicolas Noble53830622015-02-12 16:56:38 -08001710
Craig Tiller841c8802015-09-10 13:06:37 -07001711 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1712 % if not has_no_sources:
1713 $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
1714 % endif
1715 % else:
1716 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1717 % if not has_no_sources:
1718 $(${tgt.name.upper()}_OBJS)\
1719 % endif
1720 % endif
1721 % for dep in tgt.deps:
1722 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1723 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001724
Craig Tiller32173c52016-03-17 14:12:45 -07001725 % if tgt.language == "c++" or tgt.boringssl or tgt.build == 'fuzzer':
Craig Tiller841c8802015-09-10 13:06:37 -07001726 ## C++ targets specificies.
1727 % if tgt.build == 'protoc':
1728 $(E) "[HOSTLD] Linking $@"
1729 $(Q) mkdir -p `dirname $@`
1730 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) \
1731 % if not has_no_sources:
1732 $(${tgt.name.upper()}_OBJS)\
1733 % endif
1734 % else:
1735 $(E) "[LD] Linking $@"
1736 $(Q) mkdir -p `dirname $@`
1737 $(Q) $(LDXX) $(LDFLAGS) \
1738 % if not has_no_sources:
1739 $(${tgt.name.upper()}_OBJS)\
1740 % endif
1741 % endif
1742 % else:
1743 ## C-only targets specificities.
1744 $(E) "[LD] Linking $@"
1745 $(Q) mkdir -p `dirname $@`
1746 $(Q) $(LD) $(LDFLAGS) \
1747 % if not has_no_sources:
1748 $(${tgt.name.upper()}_OBJS)\
1749 % endif
1750 % endif
1751 % for dep in tgt.deps:
1752 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1753 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001754 % if tgt.language == "c++":
1755 % if tgt.build == 'protoc':
1756 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
1757 % else:
1758 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
1759 % endif
1760 % endif
1761 % if tgt.build == 'protoc':
1762 $(HOST_LDLIBS)\
1763 % else:
1764 $(LDLIBS)\
1765 % endif
1766 % if tgt.build == 'protoc':
1767 $(HOST_LDLIBS_PROTOC)\
1768 % elif tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1769 $(LDLIBS_SECURE)\
1770 % endif
1771 % if tgt.language == 'c++' and tgt.build == 'test':
1772 $(GTEST_LIB)\
1773 % elif tgt.language == 'c++' and tgt.build == 'benchmark':
1774 $(GTEST_LIB)\
1775 % endif
Craig Tiller32173c52016-03-17 14:12:45 -07001776 % if tgt.build == 'fuzzer':
1777 -lFuzzer\
1778 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001779 -o $(BINDIR)/$(CONFIG)/${tgt.name}
1780 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001781
Craig Tiller841c8802015-09-10 13:06:37 -07001782 endif
1783 % endif
1784 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001785
Craig Tiller841c8802015-09-10 13:06:37 -07001786 endif
1787 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001788
Craig Tiller19f3ea22017-02-17 15:17:05 -08001789 % if tgt.get('defaults', None):
1790 % for name, value in defaults.get(tgt.defaults).iteritems():
1791 $(${tgt.name.upper()}_OBJS): ${name} += ${value}
1792 % endfor
1793 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001794 % for src in tgt.src:
1795 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
1796 % for dep in tgt.deps:
1797 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1798 % endfor
Craig Tillerf5371ef2015-01-12 16:40:18 -08001799
Craig Tillerab230452016-01-04 08:18:43 -08001800 % if tgt.language == 'c89':
1801 % for src in tgt.src:
Craig Tillerea21ca22016-01-04 12:34:29 -08001802 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o : ${src}
1803 $(E) "[C] Compiling $<"
1804 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001805 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -std=c89 -pedantic -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Craig Tillerab230452016-01-04 08:18:43 -08001806 % endfor
1807 % endif
1808
Craig Tiller841c8802015-09-10 13:06:37 -07001809 % endfor
1810 % if not has_no_sources:
1811 deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
1812 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001813
Craig Tiller841c8802015-09-10 13:06:37 -07001814 % if not has_no_sources:
1815 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1816 ifneq ($(NO_SECURE),true)
1817 % endif
1818 ifneq ($(NO_DEPS),true)
1819 -include $(${tgt.name.upper()}_OBJS:.o=.dep)
1820 endif
1821 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1822 endif
1823 % endif
1824 % endif
Nicolas "Pixel" Noble472bb682015-11-03 19:09:01 +01001825 % for src in tgt.src:
1826 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in tgt.src):
1827 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in tgt.src if proto_re.match(src2))}
1828 % endif
1829 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001830 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001831
Craig Tiller841c8802015-09-10 13:06:37 -07001832 ifneq ($(OPENSSL_DEP),)
1833 # This is to ensure the embedded OpenSSL is built beforehand, properly
1834 # installing headers to their final destination on the drive. We need this
1835 # otherwise parallel compilation will fail if a source is compiled first.
1836 % for src in sorted(sources_that_need_openssl):
1837 % if src not in sources_that_don_t_need_openssl:
1838 ${src}: $(OPENSSL_DEP)
1839 % endif
1840 % endfor
1841 endif
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001842
Craig Tiller841c8802015-09-10 13:06:37 -07001843 .PHONY: all strip tools \
1844 dep_error openssl_dep_error openssl_dep_message git_update stop \
1845 buildtests buildtests_c buildtests_cxx \
1846 test test_c test_cxx \
1847 install install_c install_cxx \
1848 install-headers install-headers_c install-headers_cxx \
1849 install-shared install-shared_c install-shared_cxx \
1850 install-static install-static_c install-static_cxx \
1851 strip strip-shared strip-static \
1852 strip_c strip-shared_c strip-static_c \
1853 strip_cxx strip-shared_cxx strip-static_cxx \
1854 dep_c dep_cxx bins_dep_c bins_dep_cxx \
1855 clean
Craig Tillerb79c1e12016-02-23 10:00:58 -08001856
1857 .PHONY: printvars
1858 printvars:
1859 @$(foreach V,$(sort $(.VARIABLES)), \
1860 $(if $(filter-out environment% default automatic, \
1861 $(origin $V)),$(warning $V=$($V) ($(value $V)))))