blob: 4a04af122ddd4f744ed2b18dc3c6eb29e8ec779e [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
Craig Tiller841c8802015-09-10 13:06:37 -0700224 CPPFLAGS += $(CPPFLAGS_$(CONFIG))
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800225 CFLAGS += $(CFLAGS_$(CONFIG))
226 CXXFLAGS += $(CXXFLAGS_$(CONFIG))
Craig Tiller841c8802015-09-10 13:06:37 -0700227 DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
228 LDFLAGS += $(LDFLAGS_$(CONFIG))
Nicolas "Pixel" Noble482d7612015-07-16 23:43:30 +0200229
Craig Tiller841c8802015-09-10 13:06:37 -0700230 ifneq ($(SYSTEM),MINGW32)
231 PIC_CPPFLAGS = -fPIC
232 CPPFLAGS += -fPIC
233 LDFLAGS += -fPIC
234 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800235
Craig Tiller841c8802015-09-10 13:06:37 -0700236 INCLUDES = . include $(GENDIR)
237 LDFLAGS += -Llibs/$(CONFIG)
Nicolas "Pixel" Noble3adab742015-06-02 00:33:06 +0200238
Craig Tiller841c8802015-09-10 13:06:37 -0700239 ifeq ($(SYSTEM),Darwin)
240 ifneq ($(wildcard /usr/local/ssl/include),)
241 INCLUDES += /usr/local/ssl/include
242 endif
243 ifneq ($(wildcard /opt/local/include),)
244 INCLUDES += /opt/local/include
245 endif
246 ifneq ($(wildcard /usr/local/include),)
247 INCLUDES += /usr/local/include
248 endif
249 LIBS = m z
250 ifneq ($(wildcard /usr/local/ssl/lib),)
251 LDFLAGS += -L/usr/local/ssl/lib
252 endif
253 ifneq ($(wildcard /opt/local/lib),)
254 LDFLAGS += -L/opt/local/lib
255 endif
256 ifneq ($(wildcard /usr/local/lib),)
257 LDFLAGS += -L/usr/local/lib
258 endif
259 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700260
Craig Tiller841c8802015-09-10 13:06:37 -0700261 ifeq ($(SYSTEM),Linux)
Craig Tiller1b1e2382016-02-03 07:33:56 -0800262 LIBS = dl rt m pthread
Craig Tiller841c8802015-09-10 13:06:37 -0700263 LDFLAGS += -pthread
264 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800265
Craig Tiller841c8802015-09-10 13:06:37 -0700266 ifeq ($(SYSTEM),MINGW32)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100267 LIBS = m pthread ws2_32
Craig Tiller841c8802015-09-10 13:06:37 -0700268 LDFLAGS += -pthread
269 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700270
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700271 #
272 # The steps for cross-compiling are as follows:
273 # First, clone and make install of grpc using the native compilers for the host.
274 # Also, install protoc (e.g., from a package like apt-get)
275 # Then clone a fresh grpc for the actual cross-compiled build
276 # Set the environment variable GRPC_CROSS_COMPILE to true
277 # Set CC, CXX, LD, LDXX, AR, and STRIP to the cross-compiling binaries
278 # Also set PROTOBUF_CONFIG_OPTS to indicate cross-compilation to protobuf (e.g.,
279 # PROTOBUF_CONFIG_OPTS="--host=arm-linux --with-protoc=/usr/local/bin/protoc" )
280 # Set HAS_PKG_CONFIG=false
281 # To build tests, go to third_party/gflags and follow its ccmake instructions
282 # Make sure that you enable building shared libraries and set your prefix to
283 # something useful like /usr/local/cross
284 # You will also need to set GRPC_CROSS_LDOPTS and GRPC_CROSS_AROPTS to hold
285 # additional required arguments for LD and AR (examples below)
286 # Then you can do a make from the cross-compiling fresh clone!
287 #
288 ifeq ($(GRPC_CROSS_COMPILE),true)
289 LDFLAGS += $(GRPC_CROSS_LDOPTS) # e.g. -L/usr/local/lib -L/usr/local/cross/lib
290 AROPTS = $(GRPC_CROSS_AROPTS) # e.g., rc --target=elf32-little
291 USE_BUILT_PROTOC = false
292 endif
293
Mahak Mukhifb059a22017-04-18 14:40:00 -0700294 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 -0700295 GTEST_LIB += -lgflags
296 ifeq ($(V),1)
297 E = @:
298 Q =
299 else
300 E = @echo
301 Q = @
302 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800303
Craig Tiller38b99e92016-09-15 16:18:09 -0700304 CORE_VERSION = ${settings.core_version}
305 CPP_VERSION = ${settings.cpp_version}
306 CSHARP_VERSION = ${settings.csharp_version}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800307
Craig Tiller841c8802015-09-10 13:06:37 -0700308 CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
309 CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800310
Craig Tiller841c8802015-09-10 13:06:37 -0700311 LDFLAGS += $(ARCH_FLAGS)
312 LDLIBS += $(addprefix -l, $(LIBS))
313 LDLIBSXX += $(addprefix -l, $(LIBSXX))
nnoble72309c62014-12-12 11:42:26 -0800314
murgatroid99c36f6ea2016-10-03 09:24:09 -0700315
316 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES', 'LDLIBS']:
317 ${arg} += $(EXTRA_${arg})
318 % endfor
319
Craig Tiller841c8802015-09-10 13:06:37 -0700320 HOST_CPPFLAGS = $(CPPFLAGS)
321 HOST_CFLAGS = $(CFLAGS)
322 HOST_CXXFLAGS = $(CXXFLAGS)
323 HOST_LDFLAGS = $(LDFLAGS)
324 HOST_LDLIBS = $(LDLIBS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800325
Craig Tiller841c8802015-09-10 13:06:37 -0700326 # These are automatically computed variables.
327 # There shouldn't be any need to change anything from now on.
nnoble69ac39f2014-12-12 15:43:38 -0800328
Craig Tiller841c8802015-09-10 13:06:37 -0700329 -include cache.mk
murgatroid9924e2f4a2015-06-29 11:12:01 -0700330
Craig Tiller841c8802015-09-10 13:06:37 -0700331 CACHE_MK =
murgatroid99aa521572015-07-10 14:49:12 -0700332
Craig Tiller841c8802015-09-10 13:06:37 -0700333 HAS_PKG_CONFIG ?= $(shell command -v $(PKG_CONFIG) >/dev/null 2>&1 && echo true || echo false)
murgatroid99aa521572015-07-10 14:49:12 -0700334
Craig Tiller841c8802015-09-10 13:06:37 -0700335 ifeq ($(HAS_PKG_CONFIG), true)
336 CACHE_MK += HAS_PKG_CONFIG = true,
337 endif
nnoble69ac39f2014-12-12 15:43:38 -0800338
Craig Tiller38b99e92016-09-15 16:18:09 -0700339 CORE_PC_TEMPLATE = prefix=$(prefix),\
Craig Tiller841c8802015-09-10 13:06:37 -0700340 exec_prefix=${'\$${prefix}'},\
341 includedir=${'\$${prefix}'}/include,\
342 libdir=${'\$${exec_prefix}'}/lib,\
343 ,\
344 Name: $(PC_NAME),\
345 Description: $(PC_DESCRIPTION),\
Craig Tiller38b99e92016-09-15 16:18:09 -0700346 Version: $(CORE_VERSION),\
347 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
348 Requires.private: $(PC_REQUIRES_PRIVATE),\
349 Libs: -L${'\$${libdir}'} $(PC_LIB),\
350 Libs.private: $(PC_LIBS_PRIVATE)
351
352 CPP_PC_TEMPLATE = prefix=$(prefix),\
353 exec_prefix=${'\$${prefix}'},\
354 includedir=${'\$${prefix}'}/include,\
355 libdir=${'\$${exec_prefix}'}/lib,\
356 ,\
357 Name: $(PC_NAME),\
358 Description: $(PC_DESCRIPTION),\
359 Version: $(CPP_VERSION),\
360 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
361 Requires.private: $(PC_REQUIRES_PRIVATE),\
362 Libs: -L${'\$${libdir}'} $(PC_LIB),\
363 Libs.private: $(PC_LIBS_PRIVATE)
364
365 CSHARP_PC_TEMPLATE = prefix=$(prefix),\
366 exec_prefix=${'\$${prefix}'},\
367 includedir=${'\$${prefix}'}/include,\
368 libdir=${'\$${exec_prefix}'}/lib,\
369 ,\
370 Name: $(PC_NAME),\
371 Description: $(PC_DESCRIPTION),\
372 Version: $(CSHARP_VERSION),\
Craig Tiller841c8802015-09-10 13:06:37 -0700373 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
374 Requires.private: $(PC_REQUIRES_PRIVATE),\
375 Libs: -L${'\$${libdir}'} $(PC_LIB),\
376 Libs.private: $(PC_LIBS_PRIVATE)
murgatroid998faab232015-06-30 17:24:21 -0700377
Craig Tiller841c8802015-09-10 13:06:37 -0700378 ifeq ($(SYSTEM),MINGW32)
Mario Emmenlauer121d2892016-12-12 23:49:27 +0100379 EXECUTABLE_SUFFIX = .exe
Craig Tiller38b99e92016-09-15 16:18:09 -0700380 SHARED_EXT_CORE = dll
381 SHARED_EXT_CPP = dll
382 SHARED_EXT_CSHARP = dll
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100383 SHARED_PREFIX =
Craig Tiller27f70842016-09-15 16:21:54 -0700384 SHARED_VERSION_CORE = -${settings.core_version.major}
385 SHARED_VERSION_CPP = -${settings.cpp_version.major}
386 SHARED_VERSION_CSHARP = -${settings.csharp_version.major}
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100387 else ifeq ($(SYSTEM),Darwin)
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800388 EXECUTABLE_SUFFIX =
Craig Tiller38b99e92016-09-15 16:18:09 -0700389 SHARED_EXT_CORE = dylib
390 SHARED_EXT_CPP = dylib
391 SHARED_EXT_CSHARP = dylib
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100392 SHARED_PREFIX = lib
Craig Tiller27f70842016-09-15 16:21:54 -0700393 SHARED_VERSION_CORE =
394 SHARED_VERSION_CPP =
395 SHARED_VERSION_CSHARP =
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100396 else
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800397 EXECUTABLE_SUFFIX =
Craig Tiller38b99e92016-09-15 16:18:09 -0700398 SHARED_EXT_CORE = so.$(CORE_VERSION)
399 SHARED_EXT_CPP = so.$(CPP_VERSION)
400 SHARED_EXT_CSHARP = so.$(CSHARP_VERSION)
Nicolas "Pixel" Noblec4e57e32016-01-30 21:05:35 +0100401 SHARED_PREFIX = lib
Craig Tiller27f70842016-09-15 16:21:54 -0700402 SHARED_VERSION_CORE =
403 SHARED_VERSION_CPP =
404 SHARED_VERSION_CSHARP =
Craig Tiller841c8802015-09-10 13:06:37 -0700405 endif
nnoble5b7f32a2014-12-22 08:12:44 -0800406
Craig Tiller841c8802015-09-10 13:06:37 -0700407 ifeq ($(wildcard .git),)
408 IS_GIT_FOLDER = false
409 else
410 IS_GIT_FOLDER = true
411 endif
nnoble69ac39f2014-12-12 15:43:38 -0800412
Craig Tiller841c8802015-09-10 13:06:37 -0700413 ifeq ($(HAS_PKG_CONFIG),true)
414 OPENSSL_ALPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.2 openssl
Craig Tiller841c8802015-09-10 13:06:37 -0700415 ZLIB_CHECK_CMD = $(PKG_CONFIG) --exists zlib
Srini Polavarapucdc0e282018-03-26 18:16:15 -0700416 PROTOBUF_CHECK_CMD = $(PKG_CONFIG) --atleast-version=3.5.0 protobuf
Yuchen Zengf8b6d6f2017-06-02 15:36:25 -0700417 CARES_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.11.0 libcares
Craig Tiller841c8802015-09-10 13:06:37 -0700418 else # HAS_PKG_CONFIG
murgatroid9924e2f4a2015-06-29 11:12:01 -0700419
Craig Tiller841c8802015-09-10 13:06:37 -0700420 ifeq ($(SYSTEM),MINGW32)
421 OPENSSL_LIBS = ssl32 eay32
422 else
423 OPENSSL_LIBS = ssl crypto
424 endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700425
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100426 OPENSSL_ALPN_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
Craig Tillerb79c1e12016-02-23 10:00:58 -0800427 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 +0100428 ZLIB_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
429 PROTOBUF_CHECK_CMD = $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700430 CARES_CHECK_CMD = $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $(TMPOUT) test/build/c-ares.c -lcares $(LDFLAGS)
Craig Tiller297fafa2015-01-15 15:46:39 -0800431
Craig Tiller841c8802015-09-10 13:06:37 -0700432 endif # HAS_PKG_CONFIG
murgatroid9924e2f4a2015-06-29 11:12:01 -0700433
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100434 PERFTOOLS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
murgatroid996d9e4012015-07-08 10:22:45 -0700435
Craig Tiller841c8802015-09-10 13:06:37 -0700436 PROTOC_CHECK_CMD = which protoc > /dev/null
437 PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3
438 DTRACE_CHECK_CMD = which dtrace > /dev/null
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +0100439 SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS)
murgatroid9924e2f4a2015-06-29 11:12:01 -0700440
Craig Tiller841c8802015-09-10 13:06:37 -0700441 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
442 HAS_SYSTEM_PERFTOOLS ?= $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
443 ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
444 DEFINES += GRPC_HAVE_PERFTOOLS
445 LIBS += profiler
446 CACHE_MK += HAS_SYSTEM_PERFTOOLS = true,
447 endif
448 endif
nnoble69ac39f2014-12-12 15:43:38 -0800449
Craig Tiller841c8802015-09-10 13:06:37 -0700450 HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
451 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
452 HAS_SYSTEM_OPENSSL_ALPN ?= $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
453 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
Craig Tiller841c8802015-09-10 13:06:37 -0700454 CACHE_MK += HAS_SYSTEM_OPENSSL_ALPN = true,
Craig Tiller841c8802015-09-10 13:06:37 -0700455 endif
456 HAS_SYSTEM_ZLIB ?= $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
457 ifeq ($(HAS_SYSTEM_ZLIB),true)
458 CACHE_MK += HAS_SYSTEM_ZLIB = true,
459 endif
460 HAS_SYSTEM_PROTOBUF ?= $(HAS_SYSTEM_PROTOBUF_VERIFY)
461 ifeq ($(HAS_SYSTEM_PROTOBUF),true)
462 CACHE_MK += HAS_SYSTEM_PROTOBUF = true,
463 endif
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700464 HAS_SYSTEM_CARES ?= $(shell $(CARES_CHECK_CMD) 2> /dev/null && echo true || echo false)
465 ifeq ($(HAS_SYSTEM_CARES),true)
466 CACHE_MK += HAS_SYSTEM_CARES = true,
467 endif
Craig Tiller841c8802015-09-10 13:06:37 -0700468 else
469 # override system libraries if the config requires a custom compiled library
470 HAS_SYSTEM_OPENSSL_ALPN = false
Craig Tiller841c8802015-09-10 13:06:37 -0700471 HAS_SYSTEM_ZLIB = false
472 HAS_SYSTEM_PROTOBUF = false
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700473 HAS_SYSTEM_CARES = false
Craig Tiller841c8802015-09-10 13:06:37 -0700474 endif
nnoble69ac39f2014-12-12 15:43:38 -0800475
Craig Tiller841c8802015-09-10 13:06:37 -0700476 HAS_PROTOC ?= $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
477 ifeq ($(HAS_PROTOC),true)
478 CACHE_MK += HAS_PROTOC = true,
479 HAS_VALID_PROTOC ?= $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false)
480 ifeq ($(HAS_VALID_PROTOC),true)
481 CACHE_MK += HAS_VALID_PROTOC = true,
482 endif
483 else
484 HAS_VALID_PROTOC = false
485 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800486
Craig Tiller841c8802015-09-10 13:06:37 -0700487 # Check for Systemtap (https://sourceware.org/systemtap/), first by making sure <sys/sdt.h> is present
488 # in the system and secondly by checking for the "dtrace" binary (on Linux, this is part of the Systemtap
489 # distribution. It's part of the base system on BSD/Solaris machines).
490 ifndef HAS_SYSTEMTAP
491 HAS_SYSTEMTAP_HEADERS = $(shell $(SYSTEMTAP_HEADERS_CHECK_CMD) 2> /dev/null && echo true || echo false)
492 HAS_DTRACE = $(shell $(DTRACE_CHECK_CMD) 2> /dev/null && echo true || echo false)
493 HAS_SYSTEMTAP = false
494 ifeq ($(HAS_SYSTEMTAP_HEADERS),true)
495 ifeq ($(HAS_DTRACE),true)
496 HAS_SYSTEMTAP = true
497 endif
498 endif
499 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -0700500
Craig Tiller841c8802015-09-10 13:06:37 -0700501 ifeq ($(HAS_SYSTEMTAP),true)
502 CACHE_MK += HAS_SYSTEMTAP = true,
503 endif
nnoble69ac39f2014-12-12 15:43:38 -0800504
Craig Tiller841c8802015-09-10 13:06:37 -0700505 # Note that for testing purposes, one can do:
506 # make HAS_EMBEDDED_OPENSSL_ALPN=false
507 # to emulate the fact we do not have OpenSSL in the third_party folder.
Craig Tillerb79c1e12016-02-23 10:00:58 -0800508 ifneq ($(wildcard third_party/${openssl_fallback.extraction_dir}/libssl.a),)
509 HAS_EMBEDDED_OPENSSL_ALPN = third_party/${openssl_fallback.extraction_dir}
510 else ifeq ($(wildcard third_party/boringssl/include/openssl/ssl.h),)
Craig Tiller841c8802015-09-10 13:06:37 -0700511 HAS_EMBEDDED_OPENSSL_ALPN = false
512 else
Craig Tillerb79c1e12016-02-23 10:00:58 -0800513 CAN_COMPILE_EMBEDDED_OPENSSL ?= $(shell $(BORINGSSL_COMPILE_CHECK_CMD) 2> /dev/null && echo true || echo false)
514 HAS_EMBEDDED_OPENSSL_ALPN = $(CAN_COMPILE_EMBEDDED_OPENSSL)
Craig Tiller841c8802015-09-10 13:06:37 -0700515 endif
nnoble69ac39f2014-12-12 15:43:38 -0800516
Craig Tiller841c8802015-09-10 13:06:37 -0700517 ifeq ($(wildcard third_party/zlib/zlib.h),)
518 HAS_EMBEDDED_ZLIB = false
519 else
520 HAS_EMBEDDED_ZLIB = true
521 endif
nnoble69ac39f2014-12-12 15:43:38 -0800522
Craig Tiller841c8802015-09-10 13:06:37 -0700523 ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
524 HAS_EMBEDDED_PROTOBUF = false
525 ifneq ($(HAS_VALID_PROTOC),true)
526 NO_PROTOC = true
527 endif
528 else
529 HAS_EMBEDDED_PROTOBUF = true
530 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800531
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800532 ifeq ($(wildcard third_party/cares/cares/ares.h),)
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700533 HAS_EMBEDDED_CARES = false
534 else
535 HAS_EMBEDDED_CARES = true
536 endif
537
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100538 PC_REQUIRES_GRPC =
Craig Tiller841c8802015-09-10 13:06:37 -0700539 PC_LIBS_GRPC =
murgatroid998faab232015-06-30 17:24:21 -0700540
Craig Tiller841c8802015-09-10 13:06:37 -0700541 ifeq ($(HAS_SYSTEM_ZLIB),false)
Craig Tiller3dca23a2016-01-21 11:44:55 -0800542 ifeq ($(HAS_EMBEDDED_ZLIB), true)
543 EMBED_ZLIB ?= true
Craig Tiller841c8802015-09-10 13:06:37 -0700544 else
545 DEP_MISSING += zlib
Craig Tiller3dca23a2016-01-21 11:44:55 -0800546 EMBED_ZLIB ?= broken
Craig Tiller841c8802015-09-10 13:06:37 -0700547 endif
548 else
Craig Tiller3dca23a2016-01-21 11:44:55 -0800549 EMBED_ZLIB ?= false
550 endif
551
552 ifeq ($(EMBED_ZLIB),true)
553 ZLIB_DEP = $(LIBDIR)/$(CONFIG)/libz.a
554 ZLIB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libz.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +0100555 ZLIB_MERGE_OBJS = $(LIBZ_OBJS)
Craig Tiller3dca23a2016-01-21 11:44:55 -0800556 CPPFLAGS += -Ithird_party/zlib
Craig Tiller3dca23a2016-01-21 11:44:55 -0800557 else
Craig Tiller841c8802015-09-10 13:06:37 -0700558 ifeq ($(HAS_PKG_CONFIG),true)
559 CPPFLAGS += $(shell $(PKG_CONFIG) --cflags zlib)
560 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L zlib)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800561 LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l zlib))
Craig Tiller841c8802015-09-10 13:06:37 -0700562 PC_REQUIRES_GRPC += zlib
563 else
564 PC_LIBS_GRPC += -lz
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800565 LIBS += z
Craig Tiller841c8802015-09-10 13:06:37 -0700566 endif
567 endif
nnoble69ac39f2014-12-12 15:43:38 -0800568
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700569 CARES_PKG_CONFIG = false
570
Yuchen Zengb1b21152016-08-12 11:27:30 -0700571 ifeq ($(HAS_SYSTEM_CARES),false)
572 ifeq ($(HAS_EMBEDDED_CARES), true)
573 EMBED_CARES ?= true
574 else
575 DEP_MISSING += cares
576 EMBED_CARES ?= broken
577 endif
578 else
579 EMBED_CARES ?= false
580 endif
581
Alexander Polcyn690dde62017-10-18 00:20:33 -0700582 ADDRESS_SORTING_DEP = $(LIBDIR)/$(CONFIG)/libaddress_sorting.a
583 ADDRESS_SORTING_MERGE_OBJS = $(LIBADDRESS_SORTING_OBJS)
584 ADDRESS_SORTING_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libaddress_sorting.a
Alex Polcyn77f64f72018-03-01 19:22:53 +0000585 CPPFLAGS := -Ithird_party/address_sorting/include $(CPPFLAGS)
Alexander Polcyn690dde62017-10-18 00:20:33 -0700586
Yuchen Zengb1b21152016-08-12 11:27:30 -0700587 ifeq ($(EMBED_CARES),true)
Yuchen Zeng15141a62016-08-17 18:56:04 -0700588 CARES_DEP = $(LIBDIR)/$(CONFIG)/libares.a
589 CARES_MERGE_OBJS = $(LIBARES_OBJS)
590 CARES_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libares.a
Yuchen Zeng6694bb02017-01-23 17:09:51 -0800591 CPPFLAGS := -Ithird_party/cares -Ithird_party/cares/cares $(CPPFLAGS)
Yuchen Zengb1b21152016-08-12 11:27:30 -0700592 else
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700593 ifeq ($(HAS_PKG_CONFIG),true)
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700594 PC_REQUIRES_GRPC += libcares
595 CPPFLAGS += $(shell $(PKG_CONFIG) --cflags libcares)
Yuchen Zengdf2a7b72016-08-18 14:57:03 -0700596 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libcares)
597 LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l libcares))
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700598 else
599 PC_LIBS_GRPC += -lcares
Yuchen Zengdf2a7b72016-08-18 14:57:03 -0700600 LIBS += cares
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700601 endif
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700602 endif
603
Craig Tiller841c8802015-09-10 13:06:37 -0700604 OPENSSL_PKG_CONFIG = false
murgatroid99da7a9942015-06-29 14:57:37 -0700605
Craig Tiller841c8802015-09-10 13:06:37 -0700606 PC_REQUIRES_SECURE =
607 PC_LIBS_SECURE =
murgatroid998faab232015-06-30 17:24:21 -0700608
Craig Tiller841c8802015-09-10 13:06:37 -0700609 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800610 EMBED_OPENSSL ?= false
611 NO_SECURE ?= false
612 else # HAS_SYSTEM_OPENSSL_ALPN=false
Craig Tillerb79c1e12016-02-23 10:00:58 -0800613 ifneq ($(HAS_EMBEDDED_OPENSSL_ALPN),false)
614 EMBED_OPENSSL ?= $(HAS_EMBEDDED_OPENSSL_ALPN)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800615 NO_SECURE ?= false
616 else # HAS_EMBEDDED_OPENSSL_ALPN=false
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800617 NO_SECURE ?= true
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800618 endif # HAS_EMBEDDED_OPENSSL_ALPN
619 endif # HAS_SYSTEM_OPENSSL_ALPN
620
621 OPENSSL_DEP :=
622 OPENSSL_MERGE_LIBS :=
623 ifeq ($(NO_SECURE),false)
624 ifeq ($(EMBED_OPENSSL),true)
625 OPENSSL_DEP += $(LIBDIR)/$(CONFIG)/libboringssl.a
626 OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/libboringssl.a
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +0100627 OPENSSL_MERGE_OBJS += $(LIBBORINGSSL_OBJS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800628 # need to prefix these to ensure overriding system libraries
629 CPPFLAGS := -Ithird_party/boringssl/include $(CPPFLAGS)
Craig Tillerb79c1e12016-02-23 10:00:58 -0800630 else ifneq ($(EMBED_OPENSSL),false)
631 OPENSSL_DEP += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
632 OPENSSL_MERGE_LIBS += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
633 OPENSSL_MERGE_OBJS += $(wildcard $(EMBED_OPENSSL)/grpc_obj/*.o)
634 # need to prefix these to ensure overriding system libraries
635 CPPFLAGS := -I$(EMBED_OPENSSL)/include $(CPPFLAGS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800636 else # EMBED_OPENSSL=false
Craig Tiller841c8802015-09-10 13:06:37 -0700637 ifeq ($(HAS_PKG_CONFIG),true)
638 OPENSSL_PKG_CONFIG = true
639 PC_REQUIRES_SECURE = openssl
640 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags openssl) $(CPPFLAGS)
641 LDFLAGS_OPENSSL_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L openssl)
642 ifeq ($(SYSTEM),Linux)
643 ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),)
644 LDFLAGS_OPENSSL_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L openssl | sed s/L/Wl,-rpath,/)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800645 endif # LDFLAGS_OPENSSL_PKG_CONFIG=''
646 endif # System=Linux
Craig Tiller841c8802015-09-10 13:06:37 -0700647 LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800648 else # HAS_PKG_CONFIG=false
Craig Tiller841c8802015-09-10 13:06:37 -0700649 LIBS_SECURE = $(OPENSSL_LIBS)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800650 endif # HAS_PKG_CONFIG
Nicolas "Pixel" Noble494d65d2018-05-15 00:06:04 +0200651 ifeq ($(DISABLE_ALPN),true)
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800652 CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0
653 LIBS_SECURE = $(OPENSSL_LIBS)
Nicolas "Pixel" Noble494d65d2018-05-15 00:06:04 +0200654 endif # DISABLE_ALPN
Craig Tiller841c8802015-09-10 13:06:37 -0700655 PC_LIBS_SECURE = $(addprefix -l, $(LIBS_SECURE))
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800656 endif # EMBED_OPENSSL
657 endif # NO_SECURE
nnoble69ac39f2014-12-12 15:43:38 -0800658
Craig Tiller841c8802015-09-10 13:06:37 -0700659 ifeq ($(OPENSSL_PKG_CONFIG),true)
660 LDLIBS_SECURE += $(shell $(PKG_CONFIG) --libs-only-l openssl)
661 else
662 LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
663 endif
nnoble5b7f32a2014-12-22 08:12:44 -0800664
Craig Tiller841c8802015-09-10 13:06:37 -0700665 # grpc .pc file
666 PC_NAME = gRPC
Craig Tillerda179ce2016-02-09 12:01:53 -0800667 PC_DESCRIPTION = high performance general RPC framework
668 PC_CFLAGS =
669 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC) $(PC_REQUIRES_SECURE)
Craig Tiller841c8802015-09-10 13:06:37 -0700670 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) $(PC_LIBS_SECURE)
671 PC_LIB = -lgrpc
Craig Tiller38b99e92016-09-15 16:18:09 -0700672 GRPC_PC_FILE := $(CORE_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700673
Craig Tiller4a67be42016-02-09 12:40:32 -0800674 # grpc_unsecure .pc file
Craig Tiller841c8802015-09-10 13:06:37 -0700675 PC_NAME = gRPC unsecure
Craig Tillerda179ce2016-02-09 12:01:53 -0800676 PC_DESCRIPTION = high performance general RPC framework without SSL
677 PC_CFLAGS =
678 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC)
Craig Tiller841c8802015-09-10 13:06:37 -0700679 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC)
680 PC_LIB = -lgrpc
Craig Tiller38b99e92016-09-15 16:18:09 -0700681 GRPC_UNSECURE_PC_FILE := $(CORE_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700682
Craig Tiller841c8802015-09-10 13:06:37 -0700683 PROTOBUF_PKG_CONFIG = false
murgatroid99da7a9942015-06-29 14:57:37 -0700684
Craig Tiller841c8802015-09-10 13:06:37 -0700685 PC_REQUIRES_GRPCXX =
686 PC_LIBS_GRPCXX =
murgatroid998faab232015-06-30 17:24:21 -0700687
Mahak Mukhifb059a22017-04-18 14:40:00 -0700688 CPPFLAGS := -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googlemock/include $(CPPFLAGS)
Craig Tiller16f6dac2015-08-24 17:00:04 -0700689
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700690 PROTOC_PLUGINS_ALL =\
691 % for tgt in targets:
692 % if tgt.build == 'protoc':
693 $(BINDIR)/$(CONFIG)/${tgt.name}\
694 % endif
695 % endfor
696
697 PROTOC_PLUGINS_DIR = $(BINDIR)/$(CONFIG)
698
Craig Tiller841c8802015-09-10 13:06:37 -0700699 ifeq ($(HAS_SYSTEM_PROTOBUF),true)
700 ifeq ($(HAS_PKG_CONFIG),true)
701 PROTOBUF_PKG_CONFIG = true
702 PC_REQUIRES_GRPCXX = protobuf
703 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags protobuf) $(CPPFLAGS)
704 LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L protobuf)
705 ifeq ($(SYSTEM),Linux)
706 ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),)
707 LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L protobuf | sed s/L/Wl,-rpath,/)
708 endif
709 endif
710 else
711 PC_LIBS_GRPCXX = -lprotobuf
712 endif
Nicolas "Pixel" Noblef7fbdd42016-07-25 20:31:22 +0200713 PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
Craig Tiller841c8802015-09-10 13:06:37 -0700714 else
715 ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
716 PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
717 CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
718 LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700719 ifneq ($(USE_BUILT_PROTOC),false)
Craig Tiller841c8802015-09-10 13:06:37 -0700720 PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700721 PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
722 else
723 PROTOC_PLUGINS =
724 PROTOC_PLUGINS_DIR = $(prefix)/bin
725 endif
Craig Tiller841c8802015-09-10 13:06:37 -0700726 else
727 NO_PROTOBUF = true
728 endif
729 endif
Nicolas Noble53830622015-02-12 16:56:38 -0800730
Craig Tiller841c8802015-09-10 13:06:37 -0700731 LIBS_PROTOBUF = protobuf
732 LIBS_PROTOC = protoc protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800733
Craig Tiller841c8802015-09-10 13:06:37 -0700734 HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
Nicolas Noble53830622015-02-12 16:56:38 -0800735
Craig Tiller841c8802015-09-10 13:06:37 -0700736 ifeq ($(PROTOBUF_PKG_CONFIG),true)
737 LDLIBS_PROTOBUF += $(shell $(PKG_CONFIG) --libs-only-l protobuf)
738 else
739 LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
740 endif
murgatroid9924e2f4a2015-06-29 11:12:01 -0700741
Craig Tiller841c8802015-09-10 13:06:37 -0700742 # grpc++ .pc file
743 PC_NAME = gRPC++
744 PC_DESCRIPTION = C++ wrapper for gRPC
745 PC_CFLAGS =
746 PC_REQUIRES_PRIVATE = grpc $(PC_REQUIRES_GRPCXX)
747 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
748 PC_LIB = -lgrpc++
Craig Tiller38b99e92016-09-15 16:18:09 -0700749 GRPCXX_PC_FILE := $(CPP_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700750
Craig Tiller841c8802015-09-10 13:06:37 -0700751 # grpc++_unsecure .pc file
752 PC_NAME = gRPC++ unsecure
753 PC_DESCRIPTION = C++ wrapper for gRPC without SSL
754 PC_CFLAGS =
755 PC_REQUIRES_PRIVATE = grpc_unsecure $(PC_REQUIRES_GRPCXX)
756 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
757 PC_LIB = -lgrpc++
Craig Tiller38b99e92016-09-15 16:18:09 -0700758 GRPCXX_UNSECURE_PC_FILE := $(CPP_PC_TEMPLATE)
murgatroid998faab232015-06-30 17:24:21 -0700759
Craig Tiller841c8802015-09-10 13:06:37 -0700760 ifeq ($(MAKECMDGOALS),clean)
761 NO_DEPS = true
762 endif
nnoble69ac39f2014-12-12 15:43:38 -0800763
Craig Tiller841c8802015-09-10 13:06:37 -0700764 .SECONDARY = %.pb.h %.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800765
Craig Tiller841c8802015-09-10 13:06:37 -0700766 ifeq ($(DEP_MISSING),)
767 all: static shared plugins\
768 % for tgt in targets:
769 % if tgt.build == 'all':
770 $(BINDIR)/$(CONFIG)/${tgt.name}\
771 % endif
772 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800773
Craig Tiller841c8802015-09-10 13:06:37 -0700774 dep_error:
775 @echo "You shouldn't see this message - all of your dependencies are correct."
776 else
777 all: dep_error git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800778
Craig Tiller841c8802015-09-10 13:06:37 -0700779 dep_error:
780 @echo
781 @echo "DEPENDENCY ERROR"
782 @echo
783 @echo "You are missing system dependencies that are essential to build grpc,"
784 @echo "and the third_party directory doesn't have them:"
785 @echo
786 @echo " $(DEP_MISSING)"
787 @echo
788 @echo "Installing the development packages for your system will solve"
789 @echo "this issue. Please consult INSTALL to get more information."
790 @echo
791 @echo "If you need information about why these tests failed, run:"
792 @echo
793 @echo " make run_dep_checks"
794 @echo
795 endif
nnoble69ac39f2014-12-12 15:43:38 -0800796
Craig Tiller841c8802015-09-10 13:06:37 -0700797 git_update:
798 ifeq ($(IS_GIT_FOLDER),true)
799 @echo "Additionally, since you are in a git clone, you can download the"
800 @echo "missing dependencies in third_party by running the following command:"
801 @echo
802 @echo " git submodule update --init"
803 @echo
804 endif
nnoble69ac39f2014-12-12 15:43:38 -0800805
Craig Tiller841c8802015-09-10 13:06:37 -0700806 openssl_dep_error: openssl_dep_message git_update stop
nnoble69ac39f2014-12-12 15:43:38 -0800807
Craig Tiller841c8802015-09-10 13:06:37 -0700808 protobuf_dep_error: protobuf_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800809
Craig Tiller841c8802015-09-10 13:06:37 -0700810 protoc_dep_error: protoc_dep_message git_update stop
Nicolas Noble53830622015-02-12 16:56:38 -0800811
Craig Tiller841c8802015-09-10 13:06:37 -0700812 openssl_dep_message:
813 @echo
814 @echo "DEPENDENCY ERROR"
815 @echo
Craig Tillerb79c1e12016-02-23 10:00:58 -0800816 @echo "The target you are trying to run requires an OpenSSL implementation."
817 @echo "Your system doesn't have one, and either the third_party directory"
818 @echo "doesn't have it, or your compiler can't build BoringSSL."
Craig Tiller841c8802015-09-10 13:06:37 -0700819 @echo
820 @echo "Please consult INSTALL to get more information."
821 @echo
822 @echo "If you need information about why these tests failed, run:"
823 @echo
824 @echo " make run_dep_checks"
825 @echo
nnoble69ac39f2014-12-12 15:43:38 -0800826
Craig Tiller841c8802015-09-10 13:06:37 -0700827 protobuf_dep_message:
828 @echo
829 @echo "DEPENDENCY ERROR"
830 @echo
Srini Polavarapucdc0e282018-03-26 18:16:15 -0700831 @echo "The target you are trying to run requires protobuf 3.5.0+"
Craig Tiller841c8802015-09-10 13:06:37 -0700832 @echo "Your system doesn't have it, and neither does the third_party directory."
833 @echo
834 @echo "Please consult INSTALL to get more information."
835 @echo
836 @echo "If you need information about why these tests failed, run:"
837 @echo
838 @echo " make run_dep_checks"
839 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800840
Craig Tiller841c8802015-09-10 13:06:37 -0700841 protoc_dep_message:
842 @echo
843 @echo "DEPENDENCY ERROR"
844 @echo
Srini Polavarapucdc0e282018-03-26 18:16:15 -0700845 @echo "The target you are trying to run requires protobuf-compiler 3.5.0+"
Craig Tiller841c8802015-09-10 13:06:37 -0700846 @echo "Your system doesn't have it, and neither does the third_party directory."
847 @echo
848 @echo "Please consult INSTALL to get more information."
849 @echo
850 @echo "If you need information about why these tests failed, run:"
851 @echo
852 @echo " make run_dep_checks"
853 @echo
Nicolas Noble53830622015-02-12 16:56:38 -0800854
Craig Tiller841c8802015-09-10 13:06:37 -0700855 systemtap_dep_error:
856 @echo
857 @echo "DEPENDENCY ERROR"
858 @echo
859 @echo "Under the '$(CONFIG)' configutation, the target you are trying "
860 @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other "
861 @echo "platforms such as Solaris and *BSD). "
862 @echo
863 @echo "Please consult INSTALL to get more information."
864 @echo
David Garcia Quintas8954e902015-04-29 09:46:33 -0700865
Craig Tiller841c8802015-09-10 13:06:37 -0700866 stop:
867 @false
nnoble69ac39f2014-12-12 15:43:38 -0800868
Craig Tiller841c8802015-09-10 13:06:37 -0700869 % for tgt in targets:
870 ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
871 % endfor
ctiller09cb6d52014-12-19 17:38:22 -0800872
Craig Tiller841c8802015-09-10 13:06:37 -0700873 run_dep_checks:
874 $(OPENSSL_ALPN_CHECK_CMD) || true
Craig Tiller841c8802015-09-10 13:06:37 -0700875 $(ZLIB_CHECK_CMD) || true
876 $(PERFTOOLS_CHECK_CMD) || true
877 $(PROTOBUF_CHECK_CMD) || true
878 $(PROTOC_CHECK_VERSION_CMD) || true
Yuchen Zeng9b5aa632016-07-26 19:09:56 -0700879 $(CARES_CHECK_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800880
Craig Tiller841c8802015-09-10 13:06:37 -0700881 third_party/protobuf/configure:
882 $(E) "[AUTOGEN] Preparing protobuf"
883 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
Nicolas Noble53830622015-02-12 16:56:38 -0800884
Craig Tiller841c8802015-09-10 13:06:37 -0700885 $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
886 $(E) "[MAKE] Building protobuf"
Vijay Pai52338fb2018-01-11 00:25:00 -0800887 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
Vijay Paicc7eb8e2016-07-19 19:03:55 -0700888 $(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 -0700889 $(Q)$(MAKE) -C third_party/protobuf clean
890 $(Q)$(MAKE) -C third_party/protobuf
Craig Tiller841c8802015-09-10 13:06:37 -0700891 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
892 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
893 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
894 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800895
Craig Tiller841c8802015-09-10 13:06:37 -0700896 static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800897
Craig Tillereda85c62016-07-01 12:45:19 -0700898 static_c: pc_c pc_c_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700899 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100900 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700901 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
902 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
903 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100904 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700905 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800906
907
Nicolas "Pixel" Noble09121792016-01-30 09:01:53 +0100908 static_cxx: pc_cxx pc_cxx_unsecure cache.mk \
Craig Tiller841c8802015-09-10 13:06:37 -0700909 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100910 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700911 % if lib.build == 'all' and lib.language == 'c++':
912 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
913 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100914 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700915 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800916
917
Craig Tiller841c8802015-09-10 13:06:37 -0700918 shared: shared_c shared_cxx
nnoble29e1d292014-12-01 10:27:40 -0800919
Craig Tillereda85c62016-07-01 12:45:19 -0700920 shared_c: pc_c pc_c_unsecure cache.mk\
Craig Tiller841c8802015-09-10 13:06:37 -0700921 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100922 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700923 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -0700924 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)\
Craig Tiller841c8802015-09-10 13:06:37 -0700925 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100926 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700927 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800928
Craig Tiller841c8802015-09-10 13:06:37 -0700929 shared_cxx: pc_cxx pc_cxx_unsecure cache.mk\
930 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100931 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700932 % if lib.build == 'all' and lib.language == 'c++':
Craig Tiller27f70842016-09-15 16:21:54 -0700933 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)\
Craig Tiller841c8802015-09-10 13:06:37 -0700934 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100935 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700936 % endfor
nnoble29e1d292014-12-01 10:27:40 -0800937
938
Craig Tiller841c8802015-09-10 13:06:37 -0700939 shared_csharp: shared_c \
940 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100941 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700942 % if lib.build == 'all' and lib.language == 'csharp':
Craig Tiller27f70842016-09-15 16:21:54 -0700943 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)\
Craig Tiller841c8802015-09-10 13:06:37 -0700944 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100945 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700946 % endfor
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800947
Craig Tiller841c8802015-09-10 13:06:37 -0700948 grpc_csharp_ext: shared_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800949
Craig Tiller841c8802015-09-10 13:06:37 -0700950 plugins: $(PROTOC_PLUGINS)
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100951
Craig Tiller841c8802015-09-10 13:06:37 -0700952 privatelibs: privatelibs_c privatelibs_cxx
nnoble29e1d292014-12-01 10:27:40 -0800953
Craig Tiller841c8802015-09-10 13:06:37 -0700954 privatelibs_c: \
955 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100956 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller0fe5ee72015-12-22 12:50:36 -0800957 % 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 -0700958 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
959 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100960 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700961 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800962
Craig Tiller841c8802015-09-10 13:06:37 -0700963 pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc
murgatroid998faab232015-06-30 17:24:21 -0700964
Craig Tiller841c8802015-09-10 13:06:37 -0700965 pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -0700966
Craig Tiller841c8802015-09-10 13:06:37 -0700967 pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc
murgatroid998faab232015-06-30 17:24:21 -0700968
Craig Tiller841c8802015-09-10 13:06:37 -0700969 pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800970
vjpai20410922016-06-15 09:21:42 -0700971 ifeq ($(EMBED_OPENSSL),true)
Craig Tiller841c8802015-09-10 13:06:37 -0700972 privatelibs_cxx: \
973 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100974 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -0700975 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None):
976 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
977 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +0100978 % endif
Craig Tiller841c8802015-09-10 13:06:37 -0700979 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -0700980
vjpai20410922016-06-15 09:21:42 -0700981 else
982 privatelibs_cxx: \
983 % for lib in libs:
984 % if 'Makefile' in lib.get('build_system', ['Makefile']):
985 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None) and not lib.boringssl:
986 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
987 % endif
988 % endif
989 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -0700990
vjpai20410922016-06-15 09:21:42 -0700991 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800992
993
Craig Tillereda85c62016-07-01 12:45:19 -0700994 buildtests: buildtests_c buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -0800995
Craig Tiller3824b6e2015-12-09 11:19:59 -0800996 buildtests_c: privatelibs_c <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -0700997 % for tgt in targets:
998 % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -0800999 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001000 % endif
1001 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001002
1003
vjpai20410922016-06-15 09:21:42 -07001004 ifeq ($(EMBED_OPENSSL),true)
Craig Tillereda85c62016-07-01 12:45:19 -07001005 buildtests_cxx: privatelibs_cxx <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001006 % for tgt in targets:
1007 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None):
Craig Tiller3824b6e2015-12-09 11:19:59 -08001008 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
Craig Tiller841c8802015-09-10 13:06:37 -07001009 % endif
1010 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -07001011
vjpai20410922016-06-15 09:21:42 -07001012 else
Craig Tillereda85c62016-07-01 12:45:19 -07001013 buildtests_cxx: privatelibs_cxx <%text>\</%text>
vjpai20410922016-06-15 09:21:42 -07001014 % for tgt in targets:
1015 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl:
1016 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
1017 % endif
1018 % endfor
Craig Tillereda85c62016-07-01 12:45:19 -07001019
vjpai20410922016-06-15 09:21:42 -07001020 endif
nnoble29e1d292014-12-01 10:27:40 -08001021
1022
Craig Tillereda85c62016-07-01 12:45:19 -07001023 test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -08001024
Craig Tillereda85c62016-07-01 12:45:19 -07001025 flaky_test: flaky_test_c flaky_test_cxx
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001026
Craig Tiller841c8802015-09-10 13:06:37 -07001027 test_c: buildtests_c
1028 % for tgt in targets:
1029 % 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):
1030 $(E) "[RUN] Testing ${tgt.name}"
1031 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1032 % endif
1033 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001034
1035
Craig Tiller841c8802015-09-10 13:06:37 -07001036 flaky_test_c: buildtests_c
1037 % for tgt in targets:
1038 % 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):
1039 $(E) "[RUN] Testing ${tgt.name}"
1040 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1041 % endif
1042 % endfor
nnoble29e1d292014-12-01 10:27:40 -08001043
1044
Craig Tillereda85c62016-07-01 12:45:19 -07001045 test_cxx: buildtests_cxx
Craig Tiller841c8802015-09-10 13:06:37 -07001046 % for tgt in targets:
1047 % 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):
1048 $(E) "[RUN] Testing ${tgt.name}"
1049 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1050 % endif
1051 % endfor
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +02001052
1053
Craig Tiller841c8802015-09-10 13:06:37 -07001054 flaky_test_cxx: buildtests_cxx
1055 % for tgt in targets:
1056 % 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):
1057 $(E) "[RUN] Testing ${tgt.name}"
1058 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
1059 % endif
1060 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001061
1062
Craig Tiller841c8802015-09-10 13:06:37 -07001063 test_python: static_c
1064 $(E) "[RUN] Testing python code"
1065 $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
Nicolas "Pixel" Noble051a28f2015-03-17 22:54:54 +01001066
1067
Craig Tiller841c8802015-09-10 13:06:37 -07001068 tools: tools_c tools_cxx
Craig Tiller7552f0f2015-06-19 17:46:20 -07001069
1070
Craig Tiller841c8802015-09-10 13:06:37 -07001071 tools_c: privatelibs_c\
1072 % for tgt in targets:
1073 % if tgt.build == 'tool' and not tgt.language=='c++':
1074 $(BINDIR)/$(CONFIG)/${tgt.name}\
1075 % endif
1076 % endfor
Craig Tiller7552f0f2015-06-19 17:46:20 -07001077
1078
Craig Tiller841c8802015-09-10 13:06:37 -07001079 tools_cxx: privatelibs_cxx\
1080 % for tgt in targets:
1081 % if tgt.build == 'tool' and tgt.language=='c++':
1082 $(BINDIR)/$(CONFIG)/${tgt.name}\
1083 % endif
1084 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001085
1086
Craig Tiller841c8802015-09-10 13:06:37 -07001087 buildbenchmarks: privatelibs\
1088 % for tgt in targets:
1089 % if tgt.build == 'benchmark':
1090 $(BINDIR)/$(CONFIG)/${tgt.name}\
1091 % endif
1092 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001093
1094
Craig Tiller841c8802015-09-10 13:06:37 -07001095 benchmarks: buildbenchmarks
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001096
Craig Tiller841c8802015-09-10 13:06:37 -07001097 strip: strip-static strip-shared
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001098
Craig Tiller841c8802015-09-10 13:06:37 -07001099 strip-static: strip-static_c strip-static_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001100
Craig Tiller841c8802015-09-10 13:06:37 -07001101 strip-shared: strip-shared_c strip-shared_cxx
nnoble20e2e3f2014-12-16 15:37:57 -08001102
Nicolas Noble047b7272015-01-16 13:55:05 -08001103
Craig Tiller841c8802015-09-10 13:06:37 -07001104 # TODO(nnoble): the strip target is stripping in-place, instead
1105 # of copying files in a temporary folder.
1106 # This prevents proper debugging after running make install.
Nicolas Noble047b7272015-01-16 13:55:05 -08001107
Craig Tiller841c8802015-09-10 13:06:37 -07001108 strip-static_c: static_c
1109 ifeq ($(CONFIG),opt)
1110 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001111 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001112 % if lib.language == "c":
1113 % if lib.build == "all":
1114 % if not lib.get('external_deps', None):
1115 $(E) "[STRIP] Stripping lib${lib.name}.a"
1116 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1117 % endif
1118 % endif
1119 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001120 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001121 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001122 endif
nnoble85a49262014-12-08 18:14:03 -08001123
Craig Tiller841c8802015-09-10 13:06:37 -07001124 strip-static_cxx: static_cxx
1125 ifeq ($(CONFIG),opt)
1126 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001127 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001128 % if lib.language == "c++":
1129 % if lib.build == "all":
1130 $(E) "[STRIP] Stripping lib${lib.name}.a"
1131 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1132 % endif
1133 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001134 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001135 % endfor
1136 endif
Nicolas "Pixel" Noble4ef9b862015-08-14 19:35:24 +02001137
Craig Tiller841c8802015-09-10 13:06:37 -07001138 strip-shared_c: shared_c
1139 ifeq ($(CONFIG),opt)
1140 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001141 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001142 % if lib.language == "c":
1143 % if lib.build == "all":
1144 % if not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -07001145 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)"
1146 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)
Craig Tiller841c8802015-09-10 13:06:37 -07001147 % endif
1148 % endif
1149 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001150 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001151 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001152 endif
nnoble85a49262014-12-08 18:14:03 -08001153
Craig Tiller841c8802015-09-10 13:06:37 -07001154 strip-shared_cxx: shared_cxx
1155 ifeq ($(CONFIG),opt)
1156 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001157 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001158 % if lib.language == "c++":
1159 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001160 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)"
1161 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)
Craig Tiller841c8802015-09-10 13:06:37 -07001162 % endif
1163 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001164 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001165 % endfor
1166 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001167
Craig Tiller841c8802015-09-10 13:06:37 -07001168 strip-shared_csharp: shared_csharp
1169 ifeq ($(CONFIG),opt)
1170 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001171 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001172 % if lib.language == "csharp":
1173 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001174 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)"
1175 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)
Craig Tiller841c8802015-09-10 13:06:37 -07001176 % endif
1177 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001178 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001179 % endfor
1180 endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001181
Craig Tiller841c8802015-09-10 13:06:37 -07001182 cache.mk::
1183 $(E) "[MAKE] Generating $@"
1184 $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@
murgatroid99aa521572015-07-10 14:49:12 -07001185
Craig Tiller841c8802015-09-10 13:06:37 -07001186 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc:
1187 $(E) "[MAKE] Generating $@"
1188 $(Q) mkdir -p $(@D)
1189 $(Q) echo "$(GRPC_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001190
Craig Tiller841c8802015-09-10 13:06:37 -07001191 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc:
1192 $(E) "[MAKE] Generating $@"
1193 $(Q) mkdir -p $(@D)
1194 $(Q) echo "$(GRPC_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001195
Craig Tiller841c8802015-09-10 13:06:37 -07001196 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc:
1197 $(E) "[MAKE] Generating $@"
1198 $(Q) mkdir -p $(@D)
1199 $(Q) echo "$(GRPCXX_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001200
Craig Tiller841c8802015-09-10 13:06:37 -07001201 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc:
1202 $(E) "[MAKE] Generating $@"
1203 $(Q) mkdir -p $(@D)
1204 $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@
murgatroid998faab232015-06-30 17:24:21 -07001205
Craig Tiller841c8802015-09-10 13:06:37 -07001206 % for p in protos:
1207 ifeq ($(NO_PROTOC),true)
1208 $(GENDIR)/${p}.pb.cc: protoc_dep_error
1209 $(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error
1210 else
Mahak Mukhifb059a22017-04-18 14:40:00 -07001211 <%
1212 pluginflags=""
1213 %>
1214 % if p in ["src/proto/grpc/testing/compiler_test", "src/proto/grpc/testing/echo"]:
1215 <%
1216 pluginflags="generate_mock_code=true:"
1217 %>
1218 % endif
Craig Tiller1b4e3302015-12-17 16:35:00 -08001219 $(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 -07001220 $(E) "[PROTOC] Generating protobuf CC file from $<"
1221 $(Q) mkdir -p `dirname $@`
David Garcia Quintase68ed6f2016-06-17 12:49:14 -07001222 $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --cpp_out=$(GENDIR) $<
Nicolas "Pixel" Noble0caebbf2015-04-09 23:08:51 +02001223
Vijay Paie00f2a32017-07-31 01:04:45 -07001224 $(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 -07001225 $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
1226 $(Q) mkdir -p `dirname $@`
Mahak Mukhifb059a22017-04-18 14:40:00 -07001227 $(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 -07001228 endif
nnoble72309c62014-12-12 11:42:26 -08001229
Craig Tiller841c8802015-09-10 13:06:37 -07001230 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001231
Craig Tiller841c8802015-09-10 13:06:37 -07001232 ifeq ($(CONFIG),stapprof)
1233 src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h
1234 ifeq ($(HAS_SYSTEMTAP),true)
1235 $(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d
1236 $(E) "[DTRACE] Compiling $<"
1237 $(Q) mkdir -p `dirname $@`
1238 $(Q) $(DTRACE) -C -h -s $< -o $@
1239 else
1240 $(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop
1241 endif
1242 endif
David Garcia Quintas611b7362015-04-27 15:49:31 -07001243
Craig Tiller841c8802015-09-10 13:06:37 -07001244 $(OBJDIR)/$(CONFIG)/%.o : %.c
1245 $(E) "[C] Compiling $<"
1246 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001247 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001248
Craig Tiller841c8802015-09-10 13:06:37 -07001249 $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
1250 $(E) "[CXX] Compiling $<"
1251 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001252 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001253
Craig Tiller841c8802015-09-10 13:06:37 -07001254 $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
1255 $(E) "[HOSTCXX] Compiling $<"
1256 $(Q) mkdir -p `dirname $@`
1257 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -08001258
ncteisenf9d7c272017-11-06 20:32:57 -08001259 $(OBJDIR)/$(CONFIG)/src/core/%.o : src/core/%.cc
1260 $(E) "[CXX] Compiling $<"
1261 $(Q) mkdir -p `dirname $@`
1262 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
1263
1264 $(OBJDIR)/$(CONFIG)/test/core/%.o : test/core/%.cc
1265 $(E) "[CXX] Compiling $<"
1266 $(Q) mkdir -p `dirname $@`
1267 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
1268
Craig Tiller841c8802015-09-10 13:06:37 -07001269 $(OBJDIR)/$(CONFIG)/%.o : %.cc
1270 $(E) "[CXX] Compiling $<"
1271 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001272 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001273
murgatroid99a3c55352016-08-10 13:41:31 -07001274 install: install_c install_cxx install-plugins install-certs
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001275
Craig Tiller841c8802015-09-10 13:06:37 -07001276 install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001277
Craig Tiller841c8802015-09-10 13:06:37 -07001278 install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
nnoble85a49262014-12-08 18:14:03 -08001279
Craig Tiller841c8802015-09-10 13:06:37 -07001280 install_csharp: install-shared_csharp install_c
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001281
Craig Tiller841c8802015-09-10 13:06:37 -07001282 install_grpc_csharp_ext: install_csharp
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001283
Craig Tiller841c8802015-09-10 13:06:37 -07001284 install-headers: install-headers_c install-headers_cxx
nnoble85a49262014-12-08 18:14:03 -08001285
Craig Tiller841c8802015-09-10 13:06:37 -07001286 install-headers_c:
1287 $(E) "[INSTALL] Installing public C headers"
1288 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1289 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001290
Craig Tiller841c8802015-09-10 13:06:37 -07001291 install-headers_cxx:
1292 $(E) "[INSTALL] Installing public C++ headers"
1293 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
1294 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001295
Craig Tiller841c8802015-09-10 13:06:37 -07001296 install-static: install-static_c install-static_cxx
nnoble85a49262014-12-08 18:14:03 -08001297
Craig Tiller841c8802015-09-10 13:06:37 -07001298 install-static_c: static_c strip-static_c install-pkg-config_c
1299 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001300 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001301 % if lib.language == "c":
1302 % if lib.build == "all":
1303 % if not lib.get('external_deps', None):
1304 $(E) "[INSTALL] Installing lib${lib.name}.a"
1305 $(Q) $(INSTALL) -d $(prefix)/lib
1306 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1307 % endif
1308 % endif
1309 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001310 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001311 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001312
Craig Tiller841c8802015-09-10 13:06:37 -07001313 install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx
1314 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001315 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001316 % if lib.language == "c++":
1317 % if lib.build == "all":
1318 $(E) "[INSTALL] Installing lib${lib.name}.a"
1319 $(Q) $(INSTALL) -d $(prefix)/lib
1320 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
1321 % endif
1322 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001323 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001324 % endfor
nnoble85a49262014-12-08 18:14:03 -08001325
Craig Tiller841c8802015-09-10 13:06:37 -07001326 <%def name="install_shared(lang_filter)">\
1327 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001328 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001329 % if lib.language == lang_filter:
1330 % if lib.build == "all":
1331 % if not lib.get('external_deps', None):
Craig Tiller27f70842016-09-15 16:21:54 -07001332 $(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 +01001333 $(Q) $(INSTALL) -d $(prefix)/lib
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001334 $(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 -07001335 ifeq ($(SYSTEM),MINGW32)
Mario Emmenlauer44b2d082017-01-13 12:35:49 +01001336 $(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 +01001337 else ifneq ($(SYSTEM),Darwin)
Craig Tiller27f70842016-09-15 16:21:54 -07001338 $(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}
1339 $(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 -07001340 endif
1341 % endif
1342 % endif
1343 % endif
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001344 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001345 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001346 ifneq ($(SYSTEM),MINGW32)
1347 ifneq ($(SYSTEM),Darwin)
1348 $(Q) ldconfig || true
1349 endif
1350 endif
1351 </%def>
nnoble85a49262014-12-08 18:14:03 -08001352
Craig Tiller841c8802015-09-10 13:06:37 -07001353 install-shared_c: shared_c strip-shared_c install-pkg-config_c
1354 ${install_shared("c")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001355
Craig Tiller841c8802015-09-10 13:06:37 -07001356 install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c install-pkg-config_cxx
1357 ${install_shared("c++")}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001358
Craig Tiller841c8802015-09-10 13:06:37 -07001359 install-shared_csharp: shared_csharp strip-shared_csharp
1360 ${install_shared("csharp")}
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001361
Craig Tiller841c8802015-09-10 13:06:37 -07001362 install-plugins: $(PROTOC_PLUGINS)
Craig Tiller841c8802015-09-10 13:06:37 -07001363 $(E) "[INSTALL] Installing grpc protoc plugins"
1364 % for tgt in targets:
1365 % if tgt.build == 'protoc':
1366 $(Q) $(INSTALL) -d $(prefix)/bin
1367 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
1368 % endif
1369 % endfor
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001370
Tobias Jungel5e176d52018-01-23 10:30:55 +01001371 install-grpc-cli: grpc_cli
1372 $(E) "[INSTALL] Installing grpc cli"
1373 $(Q) $(INSTALL) -d $(prefix)/bin
1374 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/grpc_cli $(prefix)/bin/grpc_cli
1375
Craig Tillereda85c62016-07-01 12:45:19 -07001376 install-pkg-config_c: pc_c pc_c_unsecure
Craig Tiller841c8802015-09-10 13:06:37 -07001377 $(E) "[INSTALL] Installing C pkg-config files"
1378 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
ncteisenbddedb92017-12-20 13:49:46 -05001379 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(prefix)/lib/pkgconfig/grpc.pc
1380 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(prefix)/lib/pkgconfig/grpc_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -07001381
Craig Tiller841c8802015-09-10 13:06:37 -07001382 install-pkg-config_cxx: pc_cxx pc_cxx_unsecure
1383 $(E) "[INSTALL] Installing C++ pkg-config files"
1384 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
ncteisenbddedb92017-12-20 13:49:46 -05001385 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc $(prefix)/lib/pkgconfig/grpc++.pc
1386 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc $(prefix)/lib/pkgconfig/grpc++_unsecure.pc
murgatroid998faab232015-06-30 17:24:21 -07001387
Craig Tiller841c8802015-09-10 13:06:37 -07001388 install-certs: etc/roots.pem
1389 $(E) "[INSTALL] Installing root certificates"
1390 $(Q) $(INSTALL) -d $(prefix)/share/grpc
1391 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +01001392
Craig Tiller841c8802015-09-10 13:06:37 -07001393 clean:
1394 $(E) "[CLEAN] Cleaning build directories."
1395 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001396
1397
Craig Tiller841c8802015-09-10 13:06:37 -07001398 # The various libraries
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001399
Craig Tiller841c8802015-09-10 13:06:37 -07001400 % for lib in libs:
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001401 % if 'Makefile' in lib.get('build_system', ['Makefile']):
Craig Tiller841c8802015-09-10 13:06:37 -07001402 ${makelib(lib)}
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001403 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001404 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001405
1406
Craig Tiller841c8802015-09-10 13:06:37 -07001407 # All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001408
Craig Tiller841c8802015-09-10 13:06:37 -07001409 % for tgt in targets:
1410 ${maketarget(tgt)}
1411 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001412
Craig Tiller841c8802015-09-10 13:06:37 -07001413 <%def name="makelib(lib)">
1414 LIB${lib.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001415
Craig Tiller841c8802015-09-10 13:06:37 -07001416 % for src in lib.src:
1417 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001418
Craig Tiller841c8802015-09-10 13:06:37 -07001419 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001420
Craig Tiller841c8802015-09-10 13:06:37 -07001421 % if "public_headers" in lib:
1422 % if lib.language == "c++":
1423 PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001424
Craig Tiller841c8802015-09-10 13:06:37 -07001425 % else:
1426 PUBLIC_HEADERS_C += \\
nnoble85a49262014-12-08 18:14:03 -08001427
Craig Tiller841c8802015-09-10 13:06:37 -07001428 % endif
1429 % for hdr in lib.public_headers:
1430 ${hdr} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001431
Craig Tiller841c8802015-09-10 13:06:37 -07001432 % endfor
1433 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001434
Craig Tiller841c8802015-09-10 13:06:37 -07001435 LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001436
Nicolas "Pixel" Noble51b1aee2016-01-28 01:14:58 +01001437 % if lib.get('defaults', None):
1438 % for name, value in defaults.get(lib.defaults).iteritems():
1439 $(LIB${lib.name.upper()}_OBJS): ${name} += ${value}
1440 % endfor
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001441 % endif
1442
Craig Tiller841c8802015-09-10 13:06:37 -07001443 ## If the library requires OpenSSL, let's add some restrictions.
1444 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1445 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001446
Craig Tiller841c8802015-09-10 13:06:37 -07001447 # You can't build secure libraries if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001448
Craig Tiller841c8802015-09-10 13:06:37 -07001449 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001450
Craig Tiller841c8802015-09-10 13:06:37 -07001451 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001452 $(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 -07001453 % endif
nnoble5b7f32a2014-12-22 08:12:44 -08001454
Craig Tiller841c8802015-09-10 13:06:37 -07001455 else
nnoble69ac39f2014-12-12 15:43:38 -08001456
Craig Tiller841c8802015-09-10 13:06:37 -07001457 % if lib.language == 'c++':
1458 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001459
Craig Tiller841c8802015-09-10 13:06:37 -07001460 # 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 -08001461
Craig Tiller841c8802015-09-10 13:06:37 -07001462 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001463
Craig Tiller841c8802015-09-10 13:06:37 -07001464 % if lib.build == "all":
Craig Tiller27f70842016-09-15 16:21:54 -07001465 $(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 -07001466 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001467
Craig Tiller841c8802015-09-10 13:06:37 -07001468 else
1469 % endif
Nicolas Noble53830622015-02-12 16:56:38 -08001470
Alexander Polcyn690dde62017-10-18 00:20:33 -07001471 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP)\
Craig Tiller841c8802015-09-10 13:06:37 -07001472 ## The else here corresponds to the if secure earlier.
1473 % else:
1474 % 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
Nicolas Noble53830622015-02-12 16:56:38 -08001486
Craig Tiller841c8802015-09-10 13:06:37 -07001487 % endif
Yuchen Zeng78f9f942016-08-05 18:21:57 -07001488 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: \
Alexander Polcyn80f9c2a2018-05-16 20:15:16 -07001489 % if lib.name not in ['z', 'ares', 'address_sorting']:
Nicolas "Pixel" Nobled649c212016-01-27 20:27:30 +01001490 $(ZLIB_DEP) \
Yuchen Zeng15141a62016-08-17 18:56:04 -07001491 $(CARES_DEP) \
Alexander Polcyn690dde62017-10-18 00:20:33 -07001492 $(ADDRESS_SORTING_DEP) \
1493 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001494 % endif
1495 % if lib.language == 'c++':
1496 $(PROTOBUF_DEP)\
1497 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001498 $(LIB${lib.name.upper()}_OBJS) \
1499 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001500 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001501 $(ZLIB_MERGE_OBJS) \
Yuchen Zeng15141a62016-08-17 18:56:04 -07001502 $(CARES_MERGE_OBJS) \
Alexander Polcyn690dde62017-10-18 00:20:33 -07001503 $(ADDRESS_SORTING_MERGE_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001504 % if lib.get('secure', 'check') == True:
1505 $(OPENSSL_MERGE_OBJS) \
1506 % endif
1507 % endif
1508
Craig Tiller841c8802015-09-10 13:06:37 -07001509 $(E) "[AR] Creating $@"
1510 $(Q) mkdir -p `dirname $@`
1511 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Vijay Paicc7eb8e2016-07-19 19:03:55 -07001512 $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001513 % if lib.get('baselib', False):
Craig Tiller1298afd2016-02-09 12:29:17 -08001514 $(LIBGPR_OBJS) \
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001515 $(ZLIB_MERGE_OBJS) \
Yuchen Zeng15141a62016-08-17 18:56:04 -07001516 $(CARES_MERGE_OBJS) \
Alexander Polcyn690dde62017-10-18 00:20:33 -07001517 $(ADDRESS_SORTING_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001518 % if lib.get('secure', 'check') == True:
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001519 $(OPENSSL_MERGE_OBJS) \
Craig Tiller841c8802015-09-10 13:06:37 -07001520 % endif
1521 % endif
Nicolas "Pixel" Noblef51a9012016-02-03 07:39:43 +01001522
Craig Tiller841c8802015-09-10 13:06:37 -07001523 ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee0dbd3f2016-02-23 00:21:38 +01001524 $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tiller841c8802015-09-10 13:06:37 -07001525 endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001526
Craig Tiller841c8802015-09-10 13:06:37 -07001527 <%
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001528
Craig Tiller841c8802015-09-10 13:06:37 -07001529 if lib.language == 'c++':
1530 ld = '$(LDXX)'
1531 else:
1532 ld = '$(LD)'
nnoble5b7f32a2014-12-22 08:12:44 -08001533
Craig Tiller40c8fba2016-09-15 16:29:09 -07001534 out_mingbase = '$(LIBDIR)/$(CONFIG)/' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
1535 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
nnoble5b7f32a2014-12-22 08:12:44 -08001536
Nicolas "Pixel" Noble8087d702017-02-01 02:23:50 +01001537 common = '$(LIB' + lib.name.upper() + '_OBJS)'
nnoble5b7f32a2014-12-22 08:12:44 -08001538
Craig Tillerd7b1bdf2016-11-04 16:20:13 -07001539 link_libs = ''
Alexander Polcyn690dde62017-10-18 00:20:33 -07001540 lib_deps = ' $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP)'
Craig Tiller841c8802015-09-10 13:06:37 -07001541 mingw_libs = ''
Alexander Polcyn690dde62017-10-18 00:20:33 -07001542 mingw_lib_deps = ' $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP)'
Craig Tiller841c8802015-09-10 13:06:37 -07001543 if lib.language == 'c++':
1544 lib_deps += ' $(PROTOBUF_DEP)'
1545 mingw_lib_deps += ' $(PROTOBUF_DEP)'
Jan Tattermusch324140c2016-01-12 08:54:01 -08001546 if lib.get('deps_linkage', None) == 'static':
1547 for dep in lib.get('deps', []):
1548 lib_archive = '$(LIBDIR)/$(CONFIG)/lib' + dep + '.a'
1549 common = common + ' ' + lib_archive
1550 lib_deps = lib_deps + ' ' + lib_archive
1551 mingw_lib_deps = mingw_lib_deps + ' ' + lib_archive
1552 else:
1553 for dep in lib.get('deps', []):
Craig Tillerd7b1bdf2016-11-04 16:20:13 -07001554 dep_lib = None
1555 for dl in libs:
1556 if dl.name == dep:
1557 dep_lib = dl
1558 assert dep_lib, 'lib %s not found (in %s)' % (dep, lib.name)
1559 link_libs = link_libs + ' -l' + dep
1560 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT_' + lang_to_var[dep_lib.language] + ')'
Mario Emmenlauer44b2d082017-01-13 12:35:49 +01001561 mingw_libs = mingw_libs + ' -l' + dep + '$(SHARED_VERSION_' + lang_to_var[dep_lib.language] + ')-dll'
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001562 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 -08001563
Craig Tiller841c8802015-09-10 13:06:37 -07001564 security = lib.get('secure', 'check')
1565 if security == True:
1566 common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)'
Alexander Polcyn690dde62017-10-18 00:20:33 -07001567 common = common + ' $(ZLIB_MERGE_LIBS) $(CARES_MERGE_LIBS) $(ADDRESS_SORTING_MERGE_LIBS)'
Nicolas "Pixel" Noblea7c162c2015-07-24 20:21:51 +02001568
Craig Tiller841c8802015-09-10 13:06:37 -07001569 if security in [True, 'check']:
1570 for src in lib.src:
1571 if not proto_re.match(src):
1572 sources_that_need_openssl.add(src)
1573 else:
1574 for src in lib.src:
1575 sources_that_don_t_need_openssl.add(src)
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001576
Craig Tiller841c8802015-09-10 13:06:37 -07001577 if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1578 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1579 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001580
Craig Tiller841c8802015-09-10 13:06:37 -07001581 if lib.language == 'c++':
1582 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
Craig Tiller4bef7ce2016-02-02 08:38:43 -08001583
1584 ldflags = '$(LDFLAGS)'
1585 if lib.get('LDFLAGS', None):
1586 ldflags += ' ' + lib['LDFLAGS']
Nicolas "Pixel" Noble8087d702017-02-01 02:23:50 +01001587
1588 common = common + ' $(LDLIBS)'
Craig Tiller841c8802015-09-10 13:06:37 -07001589 %>
nnoble5b7f32a2014-12-22 08:12:44 -08001590
Craig Tiller841c8802015-09-10 13:06:37 -07001591 % if lib.build == "all":
1592 ifeq ($(SYSTEM),MINGW32)
Craig Tiller38b99e92016-09-15 16:18:09 -07001593 ${out_mingbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Craig Tiller841c8802015-09-10 13:06:37 -07001594 $(E) "[LD] Linking $@"
1595 $(Q) mkdir -p `dirname $@`
Mario Emmenlauer294dc2f2016-12-13 00:07:12 +01001596 $(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 -07001597 else
Craig Tiller38b99e92016-09-15 16:18:09 -07001598 ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
Craig Tiller841c8802015-09-10 13:06:37 -07001599 $(E) "[LD] Linking $@"
1600 $(Q) mkdir -p `dirname $@`
1601 ifeq ($(SYSTEM),Darwin)
Mario Emmenlauer8e883b22017-01-12 11:45:52 +01001602 $(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 -07001603 else
murgatroid99d166e382017-03-24 10:03:10 -07001604 $(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 +01001605 $(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}
1606 $(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 -07001607 endif
1608 endif
1609 % endif
1610 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1611 ## If the lib was secure, we have to close the Makefile's if that tested
1612 ## the presence of OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001613
Craig Tiller841c8802015-09-10 13:06:37 -07001614 endif
1615 % endif
1616 % if lib.language == 'c++':
1617 ## If the lib was C++, we have to close the Makefile's if that tested
Srini Polavarapucdc0e282018-03-26 18:16:15 -07001618 ## the presence of protobuf 3.5.0+
nnoble69ac39f2014-12-12 15:43:38 -08001619
Craig Tiller841c8802015-09-10 13:06:37 -07001620 endif
1621 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001622
Craig Tiller841c8802015-09-10 13:06:37 -07001623 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1624 ifneq ($(NO_SECURE),true)
1625 % endif
1626 ifneq ($(NO_DEPS),true)
1627 -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
1628 endif
1629 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
1630 endif
1631 % endif
1632 % for src in lib.src:
1633 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src):
1634 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))}
1635 % endif
1636 % endfor
1637 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001638
Craig Tiller841c8802015-09-10 13:06:37 -07001639 <%def name="maketarget(tgt)"><% has_no_sources = not tgt.src %>
1640 % if not has_no_sources:
1641 ${tgt.name.upper()}_SRC = \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001642
Craig Tiller841c8802015-09-10 13:06:37 -07001643 % for src in tgt.src:
1644 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001645
Craig Tiller841c8802015-09-10 13:06:37 -07001646 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001647
Craig Tiller841c8802015-09-10 13:06:37 -07001648 ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
1649 % endif
1650 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1651 ifeq ($(NO_SECURE),true)
nnoble69ac39f2014-12-12 15:43:38 -08001652
Craig Tiller841c8802015-09-10 13:06:37 -07001653 # You can't build secure targets if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001654
Craig Tiller841c8802015-09-10 13:06:37 -07001655 $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001656
Craig Tiller841c8802015-09-10 13:06:37 -07001657 else
nnoble69ac39f2014-12-12 15:43:38 -08001658
Craig Tiller841c8802015-09-10 13:06:37 -07001659 % endif
Craig Tiller0fe5ee72015-12-22 12:50:36 -08001660
1661 % if tgt.boringssl:
1662 # boringssl needs an override to ensure that it does not include
1663 # system openssl headers regardless of other configuration
1664 # we do so here with a target specific variable assignment
Craig Tiller78222f72016-05-10 09:55:38 -07001665 $(${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 -08001666 $(${tgt.name.upper()}_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS)
1667 $(${tgt.name.upper()}_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE
1668 % else:
1669 % endif
1670
Craig Tiller841c8802015-09-10 13:06:37 -07001671 ##
1672 ## We're not trying to add a dependency on building zlib and openssl here,
1673 ## as it's already done in the libraries. We're assuming that the build
1674 ## trickles down, and that a secure target requires a secure version of
1675 ## a library.
1676 ##
1677 ## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1678 ## I can live with that.
1679 ##
1680 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001681
Craig Tiller841c8802015-09-10 13:06:37 -07001682 ifeq ($(NO_PROTOBUF),true)
Nicolas Noble53830622015-02-12 16:56:38 -08001683
Srini Polavarapucdc0e282018-03-26 18:16:15 -07001684 # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.5.0+.
Nicolas Noble53830622015-02-12 16:56:38 -08001685
Craig Tiller841c8802015-09-10 13:06:37 -07001686 $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001687
Craig Tiller841c8802015-09-10 13:06:37 -07001688 else
Nicolas Noble53830622015-02-12 16:56:38 -08001689
Craig Tiller841c8802015-09-10 13:06:37 -07001690 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1691 % if not has_no_sources:
1692 $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
1693 % endif
1694 % else:
1695 $(BINDIR)/$(CONFIG)/${tgt.name}: \
1696 % if not has_no_sources:
1697 $(${tgt.name.upper()}_OBJS)\
1698 % endif
1699 % endif
1700 % for dep in tgt.deps:
1701 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1702 % endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001703
Craig Tiller32173c52016-03-17 14:12:45 -07001704 % if tgt.language == "c++" or tgt.boringssl or tgt.build == 'fuzzer':
Craig Tiller841c8802015-09-10 13:06:37 -07001705 ## C++ targets specificies.
1706 % if tgt.build == 'protoc':
1707 $(E) "[HOSTLD] Linking $@"
1708 $(Q) mkdir -p `dirname $@`
1709 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) \
1710 % if not has_no_sources:
1711 $(${tgt.name.upper()}_OBJS)\
1712 % endif
1713 % else:
1714 $(E) "[LD] Linking $@"
1715 $(Q) mkdir -p `dirname $@`
1716 $(Q) $(LDXX) $(LDFLAGS) \
1717 % if not has_no_sources:
1718 $(${tgt.name.upper()}_OBJS)\
1719 % endif
1720 % endif
1721 % else:
1722 ## C-only targets specificities.
1723 $(E) "[LD] Linking $@"
1724 $(Q) mkdir -p `dirname $@`
1725 $(Q) $(LD) $(LDFLAGS) \
1726 % if not has_no_sources:
1727 $(${tgt.name.upper()}_OBJS)\
1728 % endif
1729 % endif
1730 % for dep in tgt.deps:
1731 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1732 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001733 % if tgt.language == "c++":
1734 % if tgt.build == 'protoc':
1735 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
1736 % else:
1737 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
1738 % endif
1739 % endif
1740 % if tgt.build == 'protoc':
1741 $(HOST_LDLIBS)\
1742 % else:
1743 $(LDLIBS)\
1744 % endif
1745 % if tgt.build == 'protoc':
1746 $(HOST_LDLIBS_PROTOC)\
1747 % elif tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1748 $(LDLIBS_SECURE)\
1749 % endif
1750 % if tgt.language == 'c++' and tgt.build == 'test':
1751 $(GTEST_LIB)\
1752 % elif tgt.language == 'c++' and tgt.build == 'benchmark':
1753 $(GTEST_LIB)\
1754 % endif
Craig Tiller32173c52016-03-17 14:12:45 -07001755 % if tgt.build == 'fuzzer':
1756 -lFuzzer\
1757 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001758 -o $(BINDIR)/$(CONFIG)/${tgt.name}
1759 % if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001760
Craig Tiller841c8802015-09-10 13:06:37 -07001761 endif
1762 % endif
1763 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001764
Craig Tiller841c8802015-09-10 13:06:37 -07001765 endif
1766 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001767
Craig Tiller19f3ea22017-02-17 15:17:05 -08001768 % if tgt.get('defaults', None):
1769 % for name, value in defaults.get(tgt.defaults).iteritems():
1770 $(${tgt.name.upper()}_OBJS): ${name} += ${value}
1771 % endfor
1772 % endif
Craig Tiller841c8802015-09-10 13:06:37 -07001773 % for src in tgt.src:
1774 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
1775 % for dep in tgt.deps:
1776 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
1777 % endfor
Craig Tillerf5371ef2015-01-12 16:40:18 -08001778
Craig Tillerab230452016-01-04 08:18:43 -08001779 % if tgt.language == 'c89':
1780 % for src in tgt.src:
Craig Tillerea21ca22016-01-04 12:34:29 -08001781 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o : ${src}
1782 $(E) "[C] Compiling $<"
1783 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble45000342016-01-28 05:04:45 +01001784 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -std=c89 -pedantic -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Craig Tillerab230452016-01-04 08:18:43 -08001785 % endfor
1786 % endif
1787
Craig Tiller841c8802015-09-10 13:06:37 -07001788 % endfor
1789 % if not has_no_sources:
1790 deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
1791 % endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001792
Craig Tiller841c8802015-09-10 13:06:37 -07001793 % if not has_no_sources:
1794 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1795 ifneq ($(NO_SECURE),true)
1796 % endif
1797 ifneq ($(NO_DEPS),true)
1798 -include $(${tgt.name.upper()}_OBJS:.o=.dep)
1799 endif
1800 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
1801 endif
1802 % endif
1803 % endif
Nicolas "Pixel" Noble472bb682015-11-03 19:09:01 +01001804 % for src in tgt.src:
1805 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in tgt.src):
1806 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in tgt.src if proto_re.match(src2))}
1807 % endif
1808 % endfor
Craig Tiller841c8802015-09-10 13:06:37 -07001809 </%def>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001810
Craig Tiller841c8802015-09-10 13:06:37 -07001811 ifneq ($(OPENSSL_DEP),)
1812 # This is to ensure the embedded OpenSSL is built beforehand, properly
1813 # installing headers to their final destination on the drive. We need this
1814 # otherwise parallel compilation will fail if a source is compiled first.
1815 % for src in sorted(sources_that_need_openssl):
1816 % if src not in sources_that_don_t_need_openssl:
1817 ${src}: $(OPENSSL_DEP)
1818 % endif
1819 % endfor
1820 endif
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001821
Craig Tiller841c8802015-09-10 13:06:37 -07001822 .PHONY: all strip tools \
1823 dep_error openssl_dep_error openssl_dep_message git_update stop \
1824 buildtests buildtests_c buildtests_cxx \
1825 test test_c test_cxx \
1826 install install_c install_cxx \
1827 install-headers install-headers_c install-headers_cxx \
1828 install-shared install-shared_c install-shared_cxx \
1829 install-static install-static_c install-static_cxx \
1830 strip strip-shared strip-static \
1831 strip_c strip-shared_c strip-static_c \
1832 strip_cxx strip-shared_cxx strip-static_cxx \
1833 dep_c dep_cxx bins_dep_c bins_dep_cxx \
1834 clean
Craig Tillerb79c1e12016-02-23 10:00:58 -08001835
1836 .PHONY: printvars
1837 printvars:
1838 @$(foreach V,$(sort $(.VARIABLES)), \
1839 $(if $(filter-out environment% default automatic, \
1840 $(origin $V)),$(warning $V=$($V) ($(value $V)))))