blob: 26b514762f35a210bb37c5c5455fd23a7f2fa453 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001# GRPC global makefile
2# This currently builds C and C++ code.
Nicolas "Pixel" Nobled49893d2015-04-21 04:57:45 +02003# This file has been automatically generated from a template file.
4# Please look at the templates directory instead.
murgatroid99c241d2c2015-06-22 11:19:57 -07005# This file can be regenerated from the template by running
6# tools/buildgen/generate_projects.sh
Craig Tiller3b935482015-02-16 12:15:48 -08007
Craig Tillerd7f33352015-02-20 15:18:45 -08008# Copyright 2015, Google Inc.
Craig Tiller3b935482015-02-16 12:15:48 -08009# All rights reserved.
10#
11# Redistribution and use in source and binary forms, with or without
12# modification, are permitted provided that the following conditions are
13# met:
14#
15# * Redistributions of source code must retain the above copyright
16# notice, this list of conditions and the following disclaimer.
17# * Redistributions in binary form must reproduce the above
18# copyright notice, this list of conditions and the following disclaimer
19# in the documentation and/or other materials provided with the
20# distribution.
21# * Neither the name of Google Inc. nor the names of its
22# contributors may be used to endorse or promote products derived from
23# this software without specific prior written permission.
24#
25# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080036<%!
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080037 import re
Craig Tillerf5371ef2015-01-12 16:40:18 -080038 import os
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080039
nnoblec87b1c52015-01-05 17:15:18 -080040 proto_re = re.compile('(.*)\\.proto')
nnoble72309c62014-12-12 11:42:26 -080041
nnoble72309c62014-12-12 11:42:26 -080042 def proto_to_cc(filename):
43 m = proto_re.match(filename)
44 if not m:
45 return filename
Nicolas "Pixel" Noble0caebbf2015-04-09 23:08:51 +020046 return '$(GENDIR)/' + m.group(1) + '.pb.cc $(GENDIR)/' + m.group(1) + '.grpc.pb.cc'
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +020047
48 sources_that_need_openssl = set()
49 sources_that_don_t_need_openssl = set()
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080050%>
51
Craig Tiller96b49552015-01-21 16:29:01 -080052
53# Basic platform detection
54HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
55ifeq ($(SYSTEM),)
56SYSTEM = $(HOST_SYSTEM)
57endif
Nicolas Noblef8681182015-03-18 14:25:44 -070058ifeq ($(SYSTEM),MSYS)
59SYSTEM = MINGW32
60endif
Nicolas "Pixel" Noble5fc1adf2015-05-10 22:20:31 +020061ifeq ($(SYSTEM),MINGW64)
62SYSTEM = MINGW32
63endif
Craig Tiller96b49552015-01-21 16:29:01 -080064
65
Craig Tiller61b910f2015-02-15 10:54:07 -080066ifndef BUILDDIR
67BUILDDIR = .
68endif
69
Nicolas Noblef8681182015-03-18 14:25:44 -070070HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false)
71HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false)
72HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false)
73
74ifeq ($(HAS_CC),true)
75DEFAULT_CC = cc
76DEFAULT_CXX = c++
77else
78ifeq ($(HAS_GCC),true)
79DEFAULT_CC = gcc
80DEFAULT_CXX = g++
81else
82ifeq ($(HAS_CLANG),true)
83DEFAULT_CC = clang
84DEFAULT_CXX = clang++
85else
86DEFAULT_CC = no_c_compiler
87DEFAULT_CXX = no_c++_compiler
88endif
89endif
90endif
91
92
Craig Tiller61b910f2015-02-15 10:54:07 -080093BINDIR = $(BUILDDIR)/bins
94OBJDIR = $(BUILDDIR)/objs
95LIBDIR = $(BUILDDIR)/libs
96GENDIR = $(BUILDDIR)/gens
97
ctiller8cfebb92015-01-06 15:02:12 -080098# Configurations
99
100VALID_CONFIG_opt = 1
Nicolas Noblef8681182015-03-18 14:25:44 -0700101CC_opt = $(DEFAULT_CC)
102CXX_opt = $(DEFAULT_CXX)
103LD_opt = $(DEFAULT_CC)
104LDXX_opt = $(DEFAULT_CXX)
ctiller8cfebb92015-01-06 15:02:12 -0800105CPPFLAGS_opt = -O2
106LDFLAGS_opt =
107DEFINES_opt = NDEBUG
108
David Garcia Quintas8954e902015-04-29 09:46:33 -0700109VALID_CONFIG_basicprof = 1
110CC_basicprof = $(DEFAULT_CC)
111CXX_basicprof = $(DEFAULT_CXX)
112LD_basicprof = $(DEFAULT_CC)
113LDXX_basicprof = $(DEFAULT_CXX)
Craig Tiller113d1692015-05-01 15:26:15 -0700114CPPFLAGS_basicprof = -O2 -DGRPC_BASIC_PROFILER -DGRPC_TIMERS_RDTSC
David Garcia Quintas8954e902015-04-29 09:46:33 -0700115LDFLAGS_basicprof =
116DEFINES_basicprof = NDEBUG
117
118VALID_CONFIG_stapprof = 1
119CC_stapprof = $(DEFAULT_CC)
120CXX_stapprof = $(DEFAULT_CXX)
121LD_stapprof = $(DEFAULT_CC)
122LDXX_stapprof = $(DEFAULT_CXX)
123CPPFLAGS_stapprof = -O2 -DGRPC_STAP_PROFILER
124LDFLAGS_stapprof =
125DEFINES_stapprof = NDEBUG
Vijay Paibc171132015-04-13 10:58:06 -0700126
ctiller8cfebb92015-01-06 15:02:12 -0800127VALID_CONFIG_dbg = 1
Nicolas Noblef8681182015-03-18 14:25:44 -0700128CC_dbg = $(DEFAULT_CC)
129CXX_dbg = $(DEFAULT_CXX)
130LD_dbg = $(DEFAULT_CC)
131LDXX_dbg = $(DEFAULT_CXX)
ctiller8cfebb92015-01-06 15:02:12 -0800132CPPFLAGS_dbg = -O0
133LDFLAGS_dbg =
134DEFINES_dbg = _DEBUG DEBUG
135
Vijay Paidc7110f2015-04-02 13:59:05 -0700136VALID_CONFIG_mutrace = 1
137CC_mutrace = $(DEFAULT_CC)
138CXX_mutrace = $(DEFAULT_CXX)
139LD_mutrace = $(DEFAULT_CC)
140LDXX_mutrace = $(DEFAULT_CXX)
141CPPFLAGS_mutrace = -O0
142LDFLAGS_mutrace = -rdynamic
143DEFINES_mutrace = _DEBUG DEBUG
144
Craig Tillerec0b8f32015-01-15 07:30:00 -0800145VALID_CONFIG_valgrind = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800146REQUIRE_CUSTOM_LIBRARIES_valgrind = 1
Nicolas Noblef8681182015-03-18 14:25:44 -0700147CC_valgrind = $(DEFAULT_CC)
148CXX_valgrind = $(DEFAULT_CXX)
149LD_valgrind = $(DEFAULT_CC)
150LDXX_valgrind = $(DEFAULT_CXX)
Craig Tillerec0b8f32015-01-15 07:30:00 -0800151CPPFLAGS_valgrind = -O0
152OPENSSL_CFLAGS_valgrind = -DPURIFY
153LDFLAGS_valgrind =
Craig Tillerf6901be2015-02-27 09:12:58 -0800154DEFINES_valgrind = _DEBUG DEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20
Craig Tillerec0b8f32015-01-15 07:30:00 -0800155
ctiller8cfebb92015-01-06 15:02:12 -0800156VALID_CONFIG_tsan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800157REQUIRE_CUSTOM_LIBRARIES_tsan = 1
ctiller8cfebb92015-01-06 15:02:12 -0800158CC_tsan = clang
159CXX_tsan = clang++
160LD_tsan = clang
161LDXX_tsan = clang++
Craig Tiller5c0f97d2015-05-29 08:42:16 -0700162CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer
ctiller8cfebb92015-01-06 15:02:12 -0800163LDFLAGS_tsan = -fsanitize=thread
Craig Tillerf6901be2015-02-27 09:12:58 -0800164DEFINES_tsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10
ctiller8cfebb92015-01-06 15:02:12 -0800165
166VALID_CONFIG_asan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800167REQUIRE_CUSTOM_LIBRARIES_asan = 1
ctiller8cfebb92015-01-06 15:02:12 -0800168CC_asan = clang
169CXX_asan = clang++
170LD_asan = clang
171LDXX_asan = clang++
Craig Tiller6902ad22015-04-16 08:01:49 -0700172CPPFLAGS_asan = -O0 -fsanitize=address -fno-omit-frame-pointer
ctiller8cfebb92015-01-06 15:02:12 -0800173LDFLAGS_asan = -fsanitize=address
Craig Tillerd6cc19e2015-07-01 10:05:00 -0700174DEFINES_asan = GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3
ctiller8cfebb92015-01-06 15:02:12 -0800175
176VALID_CONFIG_msan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800177REQUIRE_CUSTOM_LIBRARIES_msan = 1
ctiller8cfebb92015-01-06 15:02:12 -0800178CC_msan = clang
Nicolas "Pixel" Nobled66cba22015-02-14 02:59:12 +0100179CXX_msan = clang++-libc++
ctiller8cfebb92015-01-06 15:02:12 -0800180LD_msan = clang
Nicolas "Pixel" Nobled66cba22015-02-14 02:59:12 +0100181LDXX_msan = clang++-libc++
Craig Tiller6902ad22015-04-16 08:01:49 -0700182CPPFLAGS_msan = -O0 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
Craig Tillerec0b8f32015-01-15 07:30:00 -0800183OPENSSL_CFLAGS_msan = -DPURIFY
Nicolas "Pixel" Nobled66cba22015-02-14 02:59:12 +0100184LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
Craig Tillerd6cc19e2015-07-01 10:05:00 -0700185DEFINES_msan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=4
ctiller8cfebb92015-01-06 15:02:12 -0800186
Craig Tiller96bd5f62015-02-13 09:04:13 -0800187VALID_CONFIG_ubsan = 1
188REQUIRE_CUSTOM_LIBRARIES_ubsan = 1
189CC_ubsan = clang
190CXX_ubsan = clang++
191LD_ubsan = clang
192LDXX_ubsan = clang++
193CPPFLAGS_ubsan = -O1 -fsanitize=undefined -fno-omit-frame-pointer
194OPENSSL_CFLAGS_ubsan = -DPURIFY
Craig Tiller96bd5f62015-02-13 09:04:13 -0800195LDFLAGS_ubsan = -fsanitize=undefined
Craig Tillerd6cc19e2015-07-01 10:05:00 -0700196DEFINES_ubsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3
Craig Tiller96bd5f62015-02-13 09:04:13 -0800197
Craig Tiller699ba212015-01-13 17:02:20 -0800198VALID_CONFIG_gcov = 1
199CC_gcov = gcc
200CXX_gcov = g++
201LD_gcov = gcc
202LDXX_gcov = g++
203CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage
204LDFLAGS_gcov = -fprofile-arcs -ftest-coverage
Craig Tiller2e4a7dc2015-04-30 09:22:31 -0700205DEFINES_gcov = _DEBUG DEBUG
Craig Tiller699ba212015-01-13 17:02:20 -0800206
Nicolas Noble047b7272015-01-16 13:55:05 -0800207
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800208# General settings.
209# You may want to change these depending on your system.
210
211prefix ?= /usr/local
212
213PROTOC = protoc
David Garcia Quintas611b7362015-04-27 15:49:31 -0700214DTRACE = dtrace
yangg102e4fe2015-01-06 16:02:50 -0800215CONFIG ?= opt
ctiller8cfebb92015-01-06 15:02:12 -0800216CC = $(CC_$(CONFIG))
217CXX = $(CXX_$(CONFIG))
218LD = $(LD_$(CONFIG))
219LDXX = $(LDXX_$(CONFIG))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800220AR = ar
Nicolas "Pixel" Nobled7631a42015-02-27 07:52:39 +0100221ifeq ($(SYSTEM),Linux)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800222STRIP = strip --strip-unneeded
Nicolas "Pixel" Nobled7631a42015-02-27 07:52:39 +0100223else
224ifeq ($(SYSTEM),Darwin)
225STRIP = strip -x
226else
227STRIP = strip
228endif
229endif
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100230INSTALL = install
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800231RM = rm -f
232
yangg102e4fe2015-01-06 16:02:50 -0800233ifndef VALID_CONFIG_$(CONFIG)
234$(error Invalid CONFIG value '$(CONFIG)')
235endif
236
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100237ifeq ($(SYSTEM),Linux)
238TMPOUT = /dev/null
239else
240TMPOUT = `mktemp /tmp/test-out-XXXXXX`
241endif
Nicolas Noble047b7272015-01-16 13:55:05 -0800242
Craig Tillercf133f42015-02-26 14:05:56 -0800243# Detect if we can use C++11
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100244CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc
Craig Tillercf133f42015-02-26 14:05:56 -0800245HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false)
246
Nicolas Noble047b7272015-01-16 13:55:05 -0800247# The HOST compiler settings are used to compile the protoc plugins.
248# In most cases, you won't have to change anything, but if you are
249# cross-compiling, you can override these variables from GNU make's
250# command line: make CC=cross-gcc HOST_CC=gcc
251
nnoble72309c62014-12-12 11:42:26 -0800252HOST_CC = $(CC)
253HOST_CXX = $(CXX)
254HOST_LD = $(LD)
255HOST_LDXX = $(LDXX)
256
ctillercab52e72015-01-06 13:10:23 -0800257CPPFLAGS += $(CPPFLAGS_$(CONFIG))
Nicolas "Pixel" Noble72743822015-02-20 20:59:29 +0100258DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
ctiller8cfebb92015-01-06 15:02:12 -0800259LDFLAGS += $(LDFLAGS_$(CONFIG))
ctillercab52e72015-01-06 13:10:23 -0800260
Craig Tiller86fa1c52015-02-27 09:57:58 -0800261ifdef EXTRA_DEFINES
Craig Tillerf5065c52015-02-27 16:17:39 -0800262DEFINES += $(EXTRA_DEFINES)
Craig Tiller86fa1c52015-02-27 09:57:58 -0800263endif
264
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800265CFLAGS += -std=c89 -pedantic
Craig Tillercf133f42015-02-26 14:05:56 -0800266ifeq ($(HAS_CXX11),true)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800267CXXFLAGS += -std=c++11
Craig Tillercf133f42015-02-26 14:05:56 -0800268else
269CXXFLAGS += -std=c++0x
Craig Tillercf133f42015-02-26 14:05:56 -0800270endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700271CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
272LDFLAGS += -g
273
274ifneq ($(SYSTEM),MINGW32)
275PIC_CPPFLAGS = -fPIC
276CPPFLAGS += -fPIC
277LDFLAGS += -fPIC
278endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800279
Craig Tillerda224d62015-02-15 11:01:58 -0800280INCLUDES = . include $(GENDIR)
Nicolas "Pixel" Noble3adab742015-06-02 00:33:06 +0200281LDFLAGS += -Llibs/$(CONFIG)
282
Craig Tiller96b49552015-01-21 16:29:01 -0800283ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100284ifneq ($(wildcard /usr/local/ssl/include),)
285INCLUDES += /usr/local/ssl/include
286endif
287ifneq ($(wildcard /opt/local/include),)
288INCLUDES += /opt/local/include
289endif
290ifneq ($(wildcard /usr/local/include),)
291INCLUDES += /usr/local/include
292endif
Craig Tiller96b49552015-01-21 16:29:01 -0800293LIBS = m z
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100294ifneq ($(wildcard /usr/local/ssl/lib),)
295LDFLAGS += -L/usr/local/ssl/lib
296endif
297ifneq ($(wildcard /opt/local/lib),)
298LDFLAGS += -L/opt/local/lib
299endif
300ifneq ($(wildcard /usr/local/lib),)
301LDFLAGS += -L/usr/local/lib
302endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700303endif
304
305ifeq ($(SYSTEM),Linux)
ctillerc008ae52015-01-07 15:33:00 -0800306LIBS = rt m z pthread
Craig Tiller96b49552015-01-21 16:29:01 -0800307LDFLAGS += -pthread
308endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800309
Nicolas Noblef8681182015-03-18 14:25:44 -0700310ifeq ($(SYSTEM),MINGW32)
311LIBS = m z pthread
312LDFLAGS += -pthread
313endif
314
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800315ifneq ($(wildcard /usr/src/gtest/src/gtest-all.cc),)
316GTEST_LIB = /usr/src/gtest/src/gtest-all.cc -I/usr/src/gtest
317else
318GTEST_LIB = -lgtest
319endif
chenwa8fd44a2014-12-10 15:13:55 -0800320GTEST_LIB += -lgflags
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800321ifeq ($(V),1)
322E = @:
323Q =
324else
325E = @echo
326Q = @
327endif
328
329VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build}
330
331CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
332CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
333
334LDFLAGS += $(ARCH_FLAGS)
335LDLIBS += $(addprefix -l, $(LIBS))
336LDLIBSXX += $(addprefix -l, $(LIBSXX))
nnoble72309c62014-12-12 11:42:26 -0800337
338HOST_CPPFLAGS = $(CPPFLAGS)
339HOST_CFLAGS = $(CFLAGS)
340HOST_CXXFLAGS = $(CXXFLAGS)
341HOST_LDFLAGS = $(LDFLAGS)
342HOST_LDLIBS = $(LDLIBS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800343
nnoble69ac39f2014-12-12 15:43:38 -0800344
345# These are automatically computed variables.
346# There shouldn't be any need to change anything from now on.
347
murgatroid9924e2f4a2015-06-29 11:12:01 -0700348HAS_PKG_CONFIG = $(shell command -v pkg-config >/dev/null 2>&1 && echo true || echo false)
349
murgatroid998faab232015-06-30 17:24:21 -0700350PC_TEMPLATE = prefix=$(prefix)\n\
351exec_prefix=${'\$${prefix}'}\n\
352includedir=${'\$${prefix}'}/include\n\
353libdir=${'\$${exec_prefix}'}/lib\n\
354\n\
355Name: $(PC_NAME)\n\
356Description: $(PC_DESCRIPTION)\n\
357Version: $(VERSION)\n\
358Cflags: -I${'\$${includedir}'} $(PC_CFLAGS)\n\
359Requires.private: $(PC_REQUIRES_PRIVATE)\n\
360Libs: -L${'\$${libdir}'}\n\
361Libs.private: $(PC_LIBS_PRIVATE)
362
363# gpr .pc file
murgatroid99dbc0caf2015-07-01 12:59:49 -0700364PC_NAME = gRPC Portable Runtime
365PC_DESCRIPTION = gRPC Portable Runtime
murgatroid99c34a3a62015-07-01 10:35:33 -0700366PC_CFLAGS = -pthread
murgatroid998faab232015-06-30 17:24:21 -0700367PC_REQUIRES_PRIVATE =
murgatroid99c34a3a62015-07-01 10:35:33 -0700368PC_LIBS_PRIVATE = -lpthread
murgatroid998faab232015-06-30 17:24:21 -0700369ifeq ($(SYSTEM),Darwin)
murgatroid99c34a3a62015-07-01 10:35:33 -0700370PC_LIBS_PRIVATE += -lrt
murgatroid998faab232015-06-30 17:24:21 -0700371endif
372GPR_PC_FILE := $(PC_TEMPLATE)
373
nnoble5b7f32a2014-12-22 08:12:44 -0800374ifeq ($(SYSTEM),MINGW32)
375SHARED_EXT = dll
376endif
377ifeq ($(SYSTEM),Darwin)
378SHARED_EXT = dylib
379endif
380ifeq ($(SHARED_EXT),)
381SHARED_EXT = so.$(VERSION)
382endif
383
nnoble69ac39f2014-12-12 15:43:38 -0800384ifeq ($(wildcard .git),)
385IS_GIT_FOLDER = false
386else
387IS_GIT_FOLDER = true
388endif
389
Nicolas Noblef8681182015-03-18 14:25:44 -0700390ifeq ($(SYSTEM),Linux)
391OPENSSL_REQUIRES_DL = true
392endif
393
394ifeq ($(SYSTEM),Darwin)
395OPENSSL_REQUIRES_DL = true
396endif
397
murgatroid9924e2f4a2015-06-29 11:12:01 -0700398ifeq ($(HAS_PKG_CONFIG),true)
399OPENSSL_ALPN_CHECK_CMD = pkg-config --atleast-version=1.0.2 openssl
Nicolas "Pixel" Noblebe2d3a32015-06-30 19:48:47 +0200400OPENSSL_NPN_CHECK_CMD = pkg-config --alteast-version=1.0.1 openssl
murgatroid9924e2f4a2015-06-29 11:12:01 -0700401ZLIB_CHECK_CMD = pkg-config --exists zlib
murgatroid9924e2f4a2015-06-29 11:12:01 -0700402PROTOBUF_CHECK_CMD = pkg-config --atleast-version=3.0.0-alpha-3 protobuf
403else # HAS_PKG_CONFIG
404
Nicolas Noblef8681182015-03-18 14:25:44 -0700405ifeq ($(SYSTEM),MINGW32)
406OPENSSL_LIBS = ssl32 eay32
407else
408OPENSSL_LIBS = ssl crypto
409endif
410
411OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
Nicolas "Pixel" Noble4cc8c8a2015-06-23 02:37:49 +0200412OPENSSL_NPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/openssl-npn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100413ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100414PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
Craig Tiller297fafa2015-01-15 15:46:39 -0800415
Nicolas Noblef8681182015-03-18 14:25:44 -0700416ifeq ($(OPENSSL_REQUIRES_DL),true)
417OPENSSL_ALPN_CHECK_CMD += -ldl
Nicolas "Pixel" Noble4cc8c8a2015-06-23 02:37:49 +0200418OPENSSL_NPN_CHECK_CMD += -ldl
Nicolas Noblef8681182015-03-18 14:25:44 -0700419endif
420
murgatroid9924e2f4a2015-06-29 11:12:01 -0700421endif # HAS_PKG_CONFIG
422
murgatroid996d9e4012015-07-08 10:22:45 -0700423PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
424
murgatroid9924e2f4a2015-06-29 11:12:01 -0700425PROTOC_CHECK_CMD = which protoc > /dev/null
426PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3
427DTRACE_CHECK_CMD = which dtrace > /dev/null
428SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS)
429
Craig Tiller50524cc2015-01-29 23:00:00 -0800430ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
Craig Tiller297fafa2015-01-15 15:46:39 -0800431HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
432ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
433DEFINES += GRPC_HAVE_PERFTOOLS
434LIBS += profiler
435endif
Craig Tiller50524cc2015-01-29 23:00:00 -0800436endif
nnoble69ac39f2014-12-12 15:43:38 -0800437
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100438HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
Craig Tillerc4da6b72015-01-15 08:01:14 -0800439ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
nnoble60825402014-12-15 14:43:51 -0800440HAS_SYSTEM_OPENSSL_ALPN = $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble4cc8c8a2015-06-23 02:37:49 +0200441ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
442HAS_SYSTEM_OPENSSL_NPN = true
443else
444HAS_SYSTEM_OPENSSL_NPN = $(shell $(OPENSSL_NPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
445endif
nnoble60825402014-12-15 14:43:51 -0800446HAS_SYSTEM_ZLIB = $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100447HAS_SYSTEM_PROTOBUF = $(HAS_SYSTEM_PROTOBUF_VERIFY)
Craig Tillerc4da6b72015-01-15 08:01:14 -0800448else
449# override system libraries if the config requires a custom compiled library
450HAS_SYSTEM_OPENSSL_ALPN = false
Nicolas "Pixel" Noble4cc8c8a2015-06-23 02:37:49 +0200451HAS_SYSTEM_OPENSSL_NPN = false
Craig Tillerc4da6b72015-01-15 08:01:14 -0800452HAS_SYSTEM_ZLIB = false
Nicolas Noble53830622015-02-12 16:56:38 -0800453HAS_SYSTEM_PROTOBUF = false
Craig Tillerc4da6b72015-01-15 08:01:14 -0800454endif
nnoble69ac39f2014-12-12 15:43:38 -0800455
David Garcia Quintasf5fcafd2015-04-24 16:12:54 -0700456HAS_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100457ifeq ($(HAS_PROTOC),true)
David Garcia Quintasf5fcafd2015-04-24 16:12:54 -0700458HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100459else
460HAS_VALID_PROTOC = false
461endif
Nicolas Noble53830622015-02-12 16:56:38 -0800462
David Garcia Quintas611b7362015-04-27 15:49:31 -0700463# Check for Systemtap (https://sourceware.org/systemtap/), first by making sure <sys/sdt.h> is present
464# in the system and secondly by checking for the "dtrace" binary (on Linux, this is part of the Systemtap
465# distribution. It's part of the base system on BSD/Solaris machines).
466HAS_SYSTEMTAP_HEADERS = $(shell $(SYSTEMTAP_HEADERS_CHECK_CMD) 2> /dev/null && echo true || echo false)
467HAS_DTRACE = $(shell $(DTRACE_CHECK_CMD) 2> /dev/null && echo true || echo false)
468HAS_SYSTEMTAP = false
469ifeq ($(HAS_SYSTEMTAP_HEADERS),true)
470ifeq ($(HAS_DTRACE),true)
471HAS_SYSTEMTAP = true
David Garcia Quintas611b7362015-04-27 15:49:31 -0700472endif
473endif
474
Nicolas "Pixel" Noble4cc8c8a2015-06-23 02:37:49 +0200475# Note that for testing purposes, one can do:
476# make HAS_EMBEDDED_OPENSSL_ALPN=false
477# to emulate the fact we do not have OpenSSL in the third_party folder.
nnoble69ac39f2014-12-12 15:43:38 -0800478ifeq ($(wildcard third_party/openssl/ssl/ssl.h),)
479HAS_EMBEDDED_OPENSSL_ALPN = false
480else
481HAS_EMBEDDED_OPENSSL_ALPN = true
482endif
483
484ifeq ($(wildcard third_party/zlib/zlib.h),)
485HAS_EMBEDDED_ZLIB = false
486else
487HAS_EMBEDDED_ZLIB = true
488endif
489
Nicolas Noble53830622015-02-12 16:56:38 -0800490ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
491HAS_EMBEDDED_PROTOBUF = false
492ifneq ($(HAS_VALID_PROTOC),true)
493NO_PROTOC = true
494endif
495else
496HAS_EMBEDDED_PROTOBUF = true
497endif
498
murgatroid998faab232015-06-30 17:24:21 -0700499PC_REQUIRES_GRPC = gpr
500PC_LIBS_GRPC =
501
nnoble69ac39f2014-12-12 15:43:38 -0800502ifeq ($(HAS_SYSTEM_ZLIB),false)
503ifeq ($(HAS_EMBEDDED_ZLIB),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800504ZLIB_DEP = $(LIBDIR)/$(CONFIG)/zlib/libz.a
nnoble69ac39f2014-12-12 15:43:38 -0800505CPPFLAGS += -Ithird_party/zlib
Craig Tillerda224d62015-02-15 11:01:58 -0800506LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib
nnoble69ac39f2014-12-12 15:43:38 -0800507else
508DEP_MISSING += zlib
509endif
murgatroid9924e2f4a2015-06-29 11:12:01 -0700510else
511ifeq ($(HAS_PKG_CONFIG),true)
512CPPFLAGS += $(shell pkg-config --cflags zlib)
513LDFLAGS += $(shell pkg-config --libs-only-L zlib)
murgatroid998faab232015-06-30 17:24:21 -0700514PC_REQUIRES_GRPC += zlib
515else
516PC_LIBS_GRPC += -lz
murgatroid9924e2f4a2015-06-29 11:12:01 -0700517endif
nnoble69ac39f2014-12-12 15:43:38 -0800518endif
519
murgatroid99da7a9942015-06-29 14:57:37 -0700520OPENSSL_PKG_CONFIG = false
521
murgatroid998faab232015-06-30 17:24:21 -0700522PC_REQUIRES_SECURE =
523PC_LIBS_SECURE =
524
murgatroid99da7a9942015-06-29 14:57:37 -0700525ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
526ifeq ($(HAS_PKG_CONFIG),true)
527OPENSSL_PKG_CONFIG = true
murgatroid998faab232015-06-30 17:24:21 -0700528PC_REQUIRES_SECURE = openssl
murgatroid99da7a9942015-06-29 14:57:37 -0700529CPPFLAGS := $(shell pkg-config --cflags openssl) $(CPPFLAGS)
530LDFLAGS_OPENSSL_PKG_CONFIG = $(shell pkg-config --libs-only-L openssl)
531ifeq ($(SYSTEM),Linux)
532ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),)
533LDFLAGS_OPENSSL_PKG_CONFIG += $(shell pkg-config --libs-only-L openssl | sed s/L/Wl,-rpath,/)
534endif
535endif
536LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS)
537else
538LIBS_SECURE = $(OPENSSL_LIBS)
539ifeq ($(OPENSSL_REQUIRES_DL),true)
540LIBS_SECURE += dl
murgatroid998faab232015-06-30 17:24:21 -0700541PC_LIBS_SECURE = $(addprefix -l, $(LIBS_SECURE))
murgatroid99da7a9942015-06-29 14:57:37 -0700542endif
543endif
544else
nnoble69ac39f2014-12-12 15:43:38 -0800545ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true)
Nicolas "Pixel" Noble4cc8c8a2015-06-23 02:37:49 +0200546USE_SYSTEM_OPENSSL = false
Craig Tiller61b910f2015-02-15 10:54:07 -0800547OPENSSL_DEP = $(LIBDIR)/$(CONFIG)/openssl/libssl.a
548OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/openssl/libssl.a $(LIBDIR)/$(CONFIG)/openssl/libcrypto.a
Craig Tillerec043032015-02-20 17:24:41 -0800549# need to prefix these to ensure overriding system libraries
550CPPFLAGS := -Ithird_party/openssl/include $(CPPFLAGS)
551LDFLAGS := -L$(LIBDIR)/$(CONFIG)/openssl $(LDFLAGS)
Nicolas Noblef8681182015-03-18 14:25:44 -0700552ifeq ($(OPENSSL_REQUIRES_DL),true)
nnoble5b7f32a2014-12-22 08:12:44 -0800553LIBS_SECURE = dl
Nicolas Noblef8681182015-03-18 14:25:44 -0700554endif
nnoble69ac39f2014-12-12 15:43:38 -0800555else
Nicolas "Pixel" Noble4cc8c8a2015-06-23 02:37:49 +0200556ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
557USE_SYSTEM_OPENSSL = true
558CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0
559LIBS_SECURE = $(OPENSSL_LIBS)
560ifeq ($(OPENSSL_REQUIRES_DL),true)
561LIBS_SECURE += dl
nnoble69ac39f2014-12-12 15:43:38 -0800562endif
nnoble5b7f32a2014-12-22 08:12:44 -0800563else
nnoble69ac39f2014-12-12 15:43:38 -0800564NO_SECURE = true
565endif
murgatroid9924e2f4a2015-06-29 11:12:01 -0700566endif
Nicolas "Pixel" Noblebe2d3a32015-06-30 19:48:47 +0200567endif
nnoble69ac39f2014-12-12 15:43:38 -0800568
murgatroid99da7a9942015-06-29 14:57:37 -0700569ifeq ($(OPENSSL_PKG_CONFIG),true)
murgatroid9924e2f4a2015-06-29 11:12:01 -0700570LDLIBS_SECURE += $(shell pkg-config --libs-only-l openssl)
571else
nnoble5b7f32a2014-12-22 08:12:44 -0800572LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
murgatroid9924e2f4a2015-06-29 11:12:01 -0700573endif
nnoble5b7f32a2014-12-22 08:12:44 -0800574
murgatroid998faab232015-06-30 17:24:21 -0700575# grpc .pc file
576PC_NAME = gRPC
577PC_DESCRIPTION = high performance general RPC framework
578PC_CFLAGS =
579PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC) $(PC_REQUIRES_SECURE)
580PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) $(PC_LIBS_SECURE)
581GRPC_PC_FILE := $(PC_TEMPLATE)
582
583# gprc_unsecure .pc file
584PC_NAME = gRPC unsecure
585PC_DESCRIPTION = high performance general RPC framework without SSL
586PC_CFLAGS =
587PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC)
588PC_LIBS_PRIVATE = $(PC_LIBS_GRPC)
589GRPC_UNSECURE_PC_FILE := $(PC_TEMPLATE)
590
murgatroid99da7a9942015-06-29 14:57:37 -0700591PROTOBUF_PKG_CONFIG = false
592
murgatroid998faab232015-06-30 17:24:21 -0700593PC_REQUIRES_GRPCXX =
594PC_LIBS_GRPCXX =
595
murgatroid99da7a9942015-06-29 14:57:37 -0700596ifeq ($(HAS_SYSTEM_PROTOBUF),true)
597ifeq ($(HAS_PKG_CONFIG),true)
598PROTOBUF_PKG_CONFIG = true
murgatroid998faab232015-06-30 17:24:21 -0700599PC_REQUIRES_GRPCXX = protobuf
murgatroid99da7a9942015-06-29 14:57:37 -0700600CPPFLAGS := $(shell pkg-config --cflags protobuf) $(CPPFLAGS)
601LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell pkg-config --libs-only-L protobuf)
602ifeq ($(SYSTEM),Linux)
603ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),)
604LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell pkg-config --libs-only-L protobuf | sed s/L/Wl,-rpath,/)
605endif
606endif
murgatroid998faab232015-06-30 17:24:21 -0700607else
608PC_LIBS_GRPCXX = -lprotobuf
murgatroid99da7a9942015-06-29 14:57:37 -0700609endif
610else
Nicolas Noble53830622015-02-12 16:56:38 -0800611ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800612PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
Craig Tiller9ec95fa2015-02-20 20:36:21 -0800613CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
614LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
Craig Tiller61b910f2015-02-15 10:54:07 -0800615PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
Nicolas Noble53830622015-02-12 16:56:38 -0800616else
617NO_PROTOBUF = true
618endif
Nicolas Noble53830622015-02-12 16:56:38 -0800619endif
620
621LIBS_PROTOBUF = protobuf
622LIBS_PROTOC = protoc protobuf
623
Nicolas Noble53830622015-02-12 16:56:38 -0800624HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
625
murgatroid99da7a9942015-06-29 14:57:37 -0700626ifeq ($(PROTOBUF_PKG_CONFIG),true)
murgatroid9924e2f4a2015-06-29 11:12:01 -0700627LDLIBS_PROTOBUF += $(shell pkg-config --libs-only-l protobuf)
628else
629LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
630endif
631
murgatroid998faab232015-06-30 17:24:21 -0700632# grpc++ .pc file
633PC_NAME = gRPC++
634PC_DESCRIPTION = C++ wrapper for gRPC
635PC_CFLAGS =
636PC_REQUIRES_PRIVATE = grpc $(PC_REQUIRES_GRPCXX)
637PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
638GRPCXX_PC_FILE := $(PC_TEMPLATE)
639
640# grpc++_unsecure .pc file
641PC_NAME = gRPC++ unsecure
642PC_DESCRIPTION = C++ wrapper for gRPC without SSL
643PC_CFLAGS =
644PC_REQUIRES_PRIVATE = grpc_unsecure $(PC_REQUIRES_GRPCXX)
645PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
646GRPCXX_UNSECURE_PC_FILE := $(PC_TEMPLATE)
647
Craig Tiller12c82092015-01-15 08:45:56 -0800648ifeq ($(MAKECMDGOALS),clean)
nnoble69ac39f2014-12-12 15:43:38 -0800649NO_DEPS = true
650endif
651
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100652INSTALL_OK = false
653ifeq ($(HAS_VALID_PROTOC),true)
654ifeq ($(HAS_SYSTEM_PROTOBUF_VERIFY),true)
655INSTALL_OK = true
656endif
657endif
658
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800659.SECONDARY = %.pb.h %.pb.cc
660
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100661PROTOC_PLUGINS =\
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800662% for tgt in targets:
663% if tgt.build == 'protoc':
Craig Tiller61b910f2015-02-15 10:54:07 -0800664 $(BINDIR)/$(CONFIG)/${tgt.name}\
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800665% endif
666% endfor
667
nnoble69ac39f2014-12-12 15:43:38 -0800668ifeq ($(DEP_MISSING),)
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100669all: static shared plugins\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800670% for tgt in targets:
671% if tgt.build == 'all':
Craig Tiller61b910f2015-02-15 10:54:07 -0800672 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800673% endif
674% endfor
675
nnoble69ac39f2014-12-12 15:43:38 -0800676dep_error:
677 @echo "You shouldn't see this message - all of your dependencies are correct."
678else
679all: dep_error git_update stop
680
681dep_error:
682 @echo
683 @echo "DEPENDENCY ERROR"
684 @echo
685 @echo "You are missing system dependencies that are essential to build grpc,"
686 @echo "and the third_party directory doesn't have them:"
687 @echo
688 @echo " $(DEP_MISSING)"
689 @echo
690 @echo "Installing the development packages for your system will solve"
691 @echo "this issue. Please consult INSTALL to get more information."
692 @echo
693 @echo "If you need information about why these tests failed, run:"
694 @echo
695 @echo " make run_dep_checks"
696 @echo
697endif
698
699git_update:
700ifeq ($(IS_GIT_FOLDER),true)
701 @echo "Additionally, since you are in a git clone, you can download the"
702 @echo "missing dependencies in third_party by running the following command:"
703 @echo
ctiller64f29102014-12-15 10:40:59 -0800704 @echo " git submodule update --init"
nnoble69ac39f2014-12-12 15:43:38 -0800705 @echo
706endif
707
708openssl_dep_error: openssl_dep_message git_update stop
709
Nicolas Noble53830622015-02-12 16:56:38 -0800710protobuf_dep_error: protobuf_dep_message git_update stop
711
712protoc_dep_error: protoc_dep_message git_update stop
713
nnoble69ac39f2014-12-12 15:43:38 -0800714openssl_dep_message:
715 @echo
716 @echo "DEPENDENCY ERROR"
717 @echo
Nicolas "Pixel" Noble4cc8c8a2015-06-23 02:37:49 +0200718 @echo "The target you are trying to run requires OpenSSL."
nnoble69ac39f2014-12-12 15:43:38 -0800719 @echo "Your system doesn't have it, and neither does the third_party directory."
720 @echo
721 @echo "Please consult INSTALL to get more information."
722 @echo
723 @echo "If you need information about why these tests failed, run:"
724 @echo
725 @echo " make run_dep_checks"
726 @echo
727
Nicolas Noble53830622015-02-12 16:56:38 -0800728protobuf_dep_message:
729 @echo
730 @echo "DEPENDENCY ERROR"
731 @echo
732 @echo "The target you are trying to run requires protobuf 3.0.0+"
733 @echo "Your system doesn't have it, and neither does the third_party directory."
734 @echo
735 @echo "Please consult INSTALL to get more information."
736 @echo
737 @echo "If you need information about why these tests failed, run:"
738 @echo
739 @echo " make run_dep_checks"
740 @echo
741
742protoc_dep_message:
743 @echo
744 @echo "DEPENDENCY ERROR"
745 @echo
746 @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
747 @echo "Your system doesn't have it, and neither does the third_party directory."
748 @echo
749 @echo "Please consult INSTALL to get more information."
750 @echo
751 @echo "If you need information about why these tests failed, run:"
752 @echo
753 @echo " make run_dep_checks"
754 @echo
755
David Garcia Quintas8954e902015-04-29 09:46:33 -0700756systemtap_dep_error:
757 @echo
758 @echo "DEPENDENCY ERROR"
759 @echo
760 @echo "Under the '$(CONFIG)' configutation, the target you are trying "
761 @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other "
762 @echo "platforms such as Solaris and *BSD). "
763 @echo
764 @echo "Please consult INSTALL to get more information."
765 @echo
766
nnoble69ac39f2014-12-12 15:43:38 -0800767stop:
768 @false
769
ctiller09cb6d52014-12-19 17:38:22 -0800770% for tgt in targets:
Craig Tiller61b910f2015-02-15 10:54:07 -0800771${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
ctiller09cb6d52014-12-19 17:38:22 -0800772% endfor
773
nnoble69ac39f2014-12-12 15:43:38 -0800774run_dep_checks:
nnoble69ac39f2014-12-12 15:43:38 -0800775 $(OPENSSL_ALPN_CHECK_CMD) || true
Nicolas "Pixel" Noble4cc8c8a2015-06-23 02:37:49 +0200776 $(OPENSSL_NPN_CHECK_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800777 $(ZLIB_CHECK_CMD) || true
Nicolas Noble53830622015-02-12 16:56:38 -0800778 $(PERFTOOLS_CHECK_CMD) || true
779 $(PROTOBUF_CHECK_CMD) || true
David Garcia Quintasf5fcafd2015-04-24 16:12:54 -0700780 $(PROTOC_CHECK_VERSION_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800781
Craig Tiller61b910f2015-02-15 10:54:07 -0800782$(LIBDIR)/$(CONFIG)/zlib/libz.a:
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100783 $(E) "[MAKE] Building zlib"
Nicolas Noblef8681182015-03-18 14:25:44 -0700784 $(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="$(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG))" ./configure --static)
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100785 $(Q)$(MAKE) -C third_party/zlib clean
786 $(Q)$(MAKE) -C third_party/zlib
Craig Tiller61b910f2015-02-15 10:54:07 -0800787 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/zlib
788 $(Q)cp third_party/zlib/libz.a $(LIBDIR)/$(CONFIG)/zlib
nnoble69ac39f2014-12-12 15:43:38 -0800789
Craig Tiller61b910f2015-02-15 10:54:07 -0800790$(LIBDIR)/$(CONFIG)/openssl/libssl.a:
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800791 $(E) "[MAKE] Building openssl for $(SYSTEM)"
792ifeq ($(SYSTEM),Darwin)
Nicolas Noblef8681182015-03-18 14:25:44 -0700793 $(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./Configure darwin64-x86_64-cc)
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800794else
Nicolas Noblef8681182015-03-18 14:25:44 -0700795ifeq ($(SYSTEM),MINGW32)
796 @echo "We currently don't have a good way to compile OpenSSL in-place under msys."
Nicolas "Pixel" Noble4cc8c8a2015-06-23 02:37:49 +0200797 @echo "Please provide a OpenSSL in your mingw32 system."
Nicolas Noblef8681182015-03-18 14:25:44 -0700798 @echo
799 @echo "Note that you can find a compatible version of the libraries here:"
800 @echo
801 @echo "http://slproweb.com/products/Win32OpenSSL.html"
802 @echo
803 @echo "If you decide to install that one, take the full version. The light"
804 @echo "version only contains compiled DLLs, without the development files."
805 @echo
806 @echo "When installing, chose to copy the OpenSSL dlls to the OpenSSL binaries"
807 @echo "directory. This way we'll link to them directly."
808 @echo
809 @echo "You can then re-start the build the following way:"
810 @echo
811 @echo " CPPFLAGS=-I/c/OpenSSL-Win64/include LDFLAGS=-L/c/OpenSSL-Win64 make"
812 @false
813else
814 $(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./config no-asm $(OPENSSL_CONFIG_$(CONFIG)))
815endif
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800816endif
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100817 $(Q)$(MAKE) -C third_party/openssl clean
Jan Tattermuschc9c83cf2015-06-17 13:42:34 -0700818 $(Q)(unset CPPFLAGS; $(MAKE) -C third_party/openssl build_crypto build_ssl)
Craig Tiller61b910f2015-02-15 10:54:07 -0800819 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/openssl
820 $(Q)cp third_party/openssl/libssl.a third_party/openssl/libcrypto.a $(LIBDIR)/$(CONFIG)/openssl
nnoble69ac39f2014-12-12 15:43:38 -0800821
Nicolas Noble53830622015-02-12 16:56:38 -0800822third_party/protobuf/configure:
823 $(E) "[AUTOGEN] Preparing protobuf"
824 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
825
Craig Tiller61b910f2015-02-15 10:54:07 -0800826$(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
Nicolas Noble53830622015-02-12 16:56:38 -0800827 $(E) "[MAKE] Building protobuf"
Nicolas "Pixel" Noblee0953b72015-05-21 05:05:17 +0200828 $(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g" ./configure --disable-shared --enable-static)
Nicolas Noble53830622015-02-12 16:56:38 -0800829 $(Q)$(MAKE) -C third_party/protobuf clean
830 $(Q)$(MAKE) -C third_party/protobuf
Craig Tiller61b910f2015-02-15 10:54:07 -0800831 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
832 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
833 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
834 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
835 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800836
nnoble29e1d292014-12-01 10:27:40 -0800837static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800838
murgatroid998faab232015-06-30 17:24:21 -0700839static_c: pc_c pc_c_unsecure \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800840% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800841% if lib.build == 'all' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800842 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800843% endif
844% endfor
845
846
murgatroid998faab232015-06-30 17:24:21 -0700847static_cxx: pc_cxx pc_cxx_unsecure pc_gpr\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800848% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800849% if lib.build == 'all' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800850 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
nnoble29e1d292014-12-01 10:27:40 -0800851% endif
852% endfor
853
854
855shared: shared_c shared_cxx
856
murgatroid998faab232015-06-30 17:24:21 -0700857shared_c: pc_c pc_c_unsecure pc_gpr\
nnoble29e1d292014-12-01 10:27:40 -0800858% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800859% if lib.build == 'all' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800860 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800861% endif
862% endfor
863
864
murgatroid998faab232015-06-30 17:24:21 -0700865shared_cxx: pc_cxx pc_cxx_unsecure \
nnoble29e1d292014-12-01 10:27:40 -0800866% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800867% if lib.build == 'all' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800868 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
nnoble29e1d292014-12-01 10:27:40 -0800869% endif
870% endfor
871
872
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800873shared_csharp: shared_c \
874% for lib in libs:
875% if lib.build == 'all' and lib.language == 'csharp':
876 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
877% endif
878% endfor
879
880grpc_csharp_ext: shared_csharp
881
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100882plugins: $(PROTOC_PLUGINS)
883
nnoble29e1d292014-12-01 10:27:40 -0800884privatelibs: privatelibs_c privatelibs_cxx
885
Craig Tiller12c82092015-01-15 08:45:56 -0800886privatelibs_c: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800887% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800888% if lib.build == 'private' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800889 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800890% endif
891% endfor
892
murgatroid998faab232015-06-30 17:24:21 -0700893pc_gpr: $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc
894
895pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc
896
897pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc
898
899pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc
900
901pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800902
Craig Tiller12c82092015-01-15 08:45:56 -0800903privatelibs_cxx: \
nnoble29e1d292014-12-01 10:27:40 -0800904% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800905% if lib.build == 'private' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800906 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800907% endif
908% endfor
909
910
nnoble29e1d292014-12-01 10:27:40 -0800911buildtests: buildtests_c buildtests_cxx
912
Craig Tiller12c82092015-01-15 08:45:56 -0800913buildtests_c: privatelibs_c\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800914% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800915% if tgt.build == 'test' and not tgt.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800916 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800917% endif
918% endfor
919
920
Craig Tiller12c82092015-01-15 08:45:56 -0800921buildtests_cxx: privatelibs_cxx\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800922% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800923% if tgt.build == 'test' and tgt.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800924 $(BINDIR)/$(CONFIG)/${tgt.name}\
nnoble29e1d292014-12-01 10:27:40 -0800925% endif
926% endfor
927
928
nnoble85a49262014-12-08 18:14:03 -0800929test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -0800930
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +0200931flaky_test: flaky_test_c flaky_test_cxx
932
nnoble85a49262014-12-08 18:14:03 -0800933test_c: buildtests_c
nnoble29e1d292014-12-01 10:27:40 -0800934% for tgt in targets:
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +0200935% if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++' and not tgt.get('flaky', False):
936 $(E) "[RUN] Testing ${tgt.name}"
937 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
938% endif
939% endfor
940
941
942flaky_test_c: buildtests_c
943% for tgt in targets:
944% if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++' and tgt.get('flaky', False):
nnoble29e1d292014-12-01 10:27:40 -0800945 $(E) "[RUN] Testing ${tgt.name}"
Craig Tillerda224d62015-02-15 11:01:58 -0800946 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
nnoble29e1d292014-12-01 10:27:40 -0800947% endif
948% endfor
949
950
nnoble85a49262014-12-08 18:14:03 -0800951test_cxx: buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -0800952% for tgt in targets:
Nicolas "Pixel" Noble4251d562015-05-22 19:43:39 +0200953% if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and not tgt.get('flaky', False):
954 $(E) "[RUN] Testing ${tgt.name}"
955 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
956% endif
957% endfor
958
959
960flaky_test_cxx: buildtests_cxx
961% for tgt in targets:
962% if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and tgt.get('flaky', False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800963 $(E) "[RUN] Testing ${tgt.name}"
Craig Tillerda224d62015-02-15 11:01:58 -0800964 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800965% endif
966% endfor
967
968
Nicolas "Pixel" Noble051a28f2015-03-17 22:54:54 +0100969test_python: static_c
970 $(E) "[RUN] Testing python code"
971 $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
972
973
Craig Tiller7552f0f2015-06-19 17:46:20 -0700974tools: tools_c tools_cxx
975
976
977tools_c: privatelibs_c\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800978% for tgt in targets:
Craig Tiller7552f0f2015-06-19 17:46:20 -0700979% if tgt.build == 'tool' and not tgt.language=='c++':
980 $(BINDIR)/$(CONFIG)/${tgt.name}\
981% endif
982% endfor
983
984
985tools_cxx: privatelibs_cxx\
986% for tgt in targets:
987% if tgt.build == 'tool' and tgt.language=='c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800988 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800989% endif
990% endfor
991
992
993buildbenchmarks: privatelibs\
994% for tgt in targets:
995% if tgt.build == 'benchmark':
Craig Tiller61b910f2015-02-15 10:54:07 -0800996 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800997% endif
998% endfor
999
1000
1001benchmarks: buildbenchmarks
1002
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001003strip: strip-static strip-shared
1004
nnoble20e2e3f2014-12-16 15:37:57 -08001005strip-static: strip-static_c strip-static_cxx
1006
1007strip-shared: strip-shared_c strip-shared_cxx
1008
Nicolas Noble047b7272015-01-16 13:55:05 -08001009
1010# TODO(nnoble): the strip target is stripping in-place, instead
1011# of copying files in a temporary folder.
1012# This prevents proper debugging after running make install.
1013
nnoble85a49262014-12-08 18:14:03 -08001014strip-static_c: static_c
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +01001015ifeq ($(CONFIG),opt)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001016% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -08001017% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001018% if lib.build == "all":
1019 $(E) "[STRIP] Stripping lib${lib.name}.a"
Craig Tiller61b910f2015-02-15 10:54:07 -08001020 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001021% endif
nnoble85a49262014-12-08 18:14:03 -08001022% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001023% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +01001024endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001025
nnoble85a49262014-12-08 18:14:03 -08001026strip-static_cxx: static_cxx
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +01001027ifeq ($(CONFIG),opt)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001028% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -08001029% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -08001030% if lib.build == "all":
1031 $(E) "[STRIP] Stripping lib${lib.name}.a"
Craig Tiller61b910f2015-02-15 10:54:07 -08001032 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
nnoble85a49262014-12-08 18:14:03 -08001033% endif
1034% endif
1035% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +01001036endif
nnoble85a49262014-12-08 18:14:03 -08001037
1038strip-shared_c: shared_c
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +01001039ifeq ($(CONFIG),opt)
nnoble85a49262014-12-08 18:14:03 -08001040% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -08001041% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001042% if lib.build == "all":
1043 $(E) "[STRIP] Stripping lib${lib.name}.so"
Craig Tiller61b910f2015-02-15 10:54:07 -08001044 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001045% endif
nnoble85a49262014-12-08 18:14:03 -08001046% endif
1047% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +01001048endif
nnoble85a49262014-12-08 18:14:03 -08001049
1050strip-shared_cxx: shared_cxx
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +01001051ifeq ($(CONFIG),opt)
nnoble85a49262014-12-08 18:14:03 -08001052% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -08001053% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -08001054% if lib.build == "all":
1055 $(E) "[STRIP] Stripping lib${lib.name}.so"
Craig Tiller61b910f2015-02-15 10:54:07 -08001056 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
nnoble85a49262014-12-08 18:14:03 -08001057% endif
1058% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001059% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +01001060endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001061
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001062strip-shared_csharp: shared_csharp
1063ifeq ($(CONFIG),opt)
1064% for lib in libs:
1065% if lib.language == "csharp":
1066% if lib.build == "all":
1067 $(E) "[STRIP] Stripping lib${lib.name}.so"
1068 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
1069% endif
1070% endif
1071% endfor
1072endif
1073
murgatroid998faab232015-06-30 17:24:21 -07001074$(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc:
1075 $(E) "[MAKE] Generating $@"
1076 $(Q) mkdir -p $(@D)
1077 $(Q) echo -e "$(GPR_PC_FILE)" >$@
1078
1079$(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc:
1080 $(E) "[MAKE] Generating $@"
1081 $(Q) mkdir -p $(@D)
1082 $(Q) echo -e "$(GRPC_PC_FILE)" >$@
1083
1084$(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc:
1085 $(E) "[MAKE] Generating $@"
1086 $(Q) mkdir -p $(@D)
1087 $(Q) echo -e "$(GRPC_UNSECURE_PC_FILE)" >$@
1088
1089$(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc:
1090 $(E) "[MAKE] Generating $@"
1091 $(Q) mkdir -p $(@D)
1092 $(Q) echo -e "$(GRPCXX_PC_FILE)" >$@
1093
1094$(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc:
1095 $(E) "[MAKE] Generating $@"
1096 $(Q) mkdir -p $(@D)
1097 $(Q) echo -e "$(GRPCXX_UNSECURE_PC_FILE)" >$@
1098
nnoble72309c62014-12-12 11:42:26 -08001099% for p in protos:
Nicolas Noble53830622015-02-12 16:56:38 -08001100ifeq ($(NO_PROTOC),true)
Craig Tiller61b910f2015-02-15 10:54:07 -08001101$(GENDIR)/${p}.pb.cc: protoc_dep_error
Nicolas "Pixel" Noble0caebbf2015-04-09 23:08:51 +02001102$(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001103else
Craig Tiller61b910f2015-02-15 10:54:07 -08001104$(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001105 $(E) "[PROTOC] Generating protobuf CC file from $<"
1106 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble0caebbf2015-04-09 23:08:51 +02001107 $(Q) $(PROTOC) --cpp_out=$(GENDIR) $<
1108
1109$(GENDIR)/${p}.grpc.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
1110 $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
1111 $(Q) mkdir -p `dirname $@`
1112 $(Q) $(PROTOC) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $<
Nicolas Noble53830622015-02-12 16:56:38 -08001113endif
nnoble72309c62014-12-12 11:42:26 -08001114
1115% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001116
David Garcia Quintasbbc0b772015-04-29 14:10:05 -07001117ifeq ($(CONFIG),stapprof)
1118src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h
David Garcia Quintas611b7362015-04-27 15:49:31 -07001119ifeq ($(HAS_SYSTEMTAP),true)
1120$(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d
1121 $(E) "[DTRACE] Compiling $<"
1122 $(Q) mkdir -p `dirname $@`
1123 $(Q) $(DTRACE) -C -h -s $< -o $@
David Garcia Quintas8954e902015-04-29 09:46:33 -07001124else
1125$(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop
1126endif
David Garcia Quintas611b7362015-04-27 15:49:31 -07001127endif
1128
Craig Tiller61b910f2015-02-15 10:54:07 -08001129$(OBJDIR)/$(CONFIG)/%.o : %.c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001130 $(E) "[C] Compiling $<"
1131 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -08001132 $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001133
Craig Tiller61b910f2015-02-15 10:54:07 -08001134$(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001135 $(E) "[CXX] Compiling $<"
1136 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -08001137 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001138
Craig Tiller61b910f2015-02-15 10:54:07 -08001139$(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
nnoble72309c62014-12-12 11:42:26 -08001140 $(E) "[HOSTCXX] Compiling $<"
1141 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -08001142 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -08001143
Craig Tiller61b910f2015-02-15 10:54:07 -08001144$(OBJDIR)/$(CONFIG)/%.o : %.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001145 $(E) "[CXX] Compiling $<"
1146 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -08001147 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001148
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +01001149install: install_c install_cxx install-plugins install-certs verify-install
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001150
nnoble85a49262014-12-08 18:14:03 -08001151install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001152
nnoble85a49262014-12-08 18:14:03 -08001153install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
1154
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001155install_csharp: install-shared_csharp install_c
1156
1157install_grpc_csharp_ext: install_csharp
1158
nnoble85a49262014-12-08 18:14:03 -08001159install-headers: install-headers_c install-headers_cxx
1160
1161install-headers_c:
1162 $(E) "[INSTALL] Installing public C headers"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +01001163 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001164 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
1165
1166install-headers_cxx:
1167 $(E) "[INSTALL] Installing public C++ headers"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +01001168 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -08001169 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
1170
1171install-static: install-static_c install-static_cxx
1172
murgatroid998faab232015-06-30 17:24:21 -07001173install-static_c: static_c strip-static_c install-pkg-config_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001174% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -08001175% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001176% if lib.build == "all":
1177 $(E) "[INSTALL] Installing lib${lib.name}.a"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +01001178 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -08001179 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001180% endif
nnoble85a49262014-12-08 18:14:03 -08001181% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001182% endfor
1183
murgatroid998faab232015-06-30 17:24:21 -07001184install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001185% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -08001186% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -08001187% if lib.build == "all":
1188 $(E) "[INSTALL] Installing lib${lib.name}.a"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +01001189 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -08001190 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
nnoble85a49262014-12-08 18:14:03 -08001191% endif
1192% endif
1193% endfor
1194
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001195<%def name="install_shared(lang_filter)">\
nnoble85a49262014-12-08 18:14:03 -08001196% for lib in libs:
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001197% if lib.language == lang_filter:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001198% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -08001199ifeq ($(SYSTEM),MINGW32)
1200 $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +01001201 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -08001202 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT)
1203 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
nnoble5b7f32a2014-12-22 08:12:44 -08001204else
1205 $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +01001206 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -08001207 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT)
Masood Malekghassemid1be74f2015-04-07 16:23:09 -07001208ifneq ($(SYSTEM),Darwin)
Tim Emiola820e3d62015-04-10 09:11:50 -07001209 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so.${settings.version.major}
nnoble5b7f32a2014-12-22 08:12:44 -08001210 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
1211endif
1212endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001213% endif
nnoble85a49262014-12-08 18:14:03 -08001214% endif
1215% endfor
nnoble5b7f32a2014-12-22 08:12:44 -08001216ifneq ($(SYSTEM),MINGW32)
1217ifneq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblecc2b42a2015-02-20 00:42:21 +01001218 $(Q) ldconfig || true
nnoble5b7f32a2014-12-22 08:12:44 -08001219endif
1220endif
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001221</%def>
nnoble85a49262014-12-08 18:14:03 -08001222
murgatroid998faab232015-06-30 17:24:21 -07001223install-shared_c: shared_c strip-shared_c install-pkg-config_c
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001224${install_shared("c")}
1225
murgatroid998faab232015-06-30 17:24:21 -07001226install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c install-pkg-config_cxx
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001227${install_shared("c++")}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001228
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001229install-shared_csharp: shared_csharp strip-shared_csharp
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001230${install_shared("csharp")}
1231
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001232install-plugins: $(PROTOC_PLUGINS)
1233ifeq ($(SYSTEM),MINGW32)
1234 $(Q) false
1235else
1236 $(E) "[INSTALL] Installing grpc protoc plugins"
1237% for tgt in targets:
1238% if tgt.build == 'protoc':
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +01001239 $(Q) $(INSTALL) -d $(prefix)/bin
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001240 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
1241% endif
1242% endfor
1243endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -08001244
murgatroid998faab232015-06-30 17:24:21 -07001245install-pkg-config_c: pc_gpr pc_c pc_c_unsecure
1246 $(E) "[INSTALL] Installing C pkg-config files"
1247 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
1248 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc $(prefix)/lib/pkgconfig/gpr.pc
1249 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(prefix)/lib/pkgconfig/grpc.pc
1250 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(prefix)/lib/pkgconfig/grpc_unsecure.pc
1251
1252install-pkg-config_cxx: pc_cxx pc_cxx_unsecure
1253 $(E) "[INSTALL] Installing C++ pkg-config files"
1254 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
1255 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc $(prefix)/lib/pkgconfig/grpc++.pc
1256 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc $(prefix)/lib/pkgconfig/grpc++_unsecure.pc
1257
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +01001258install-certs: etc/roots.pem
1259 $(E) "[INSTALL] Installing root certificates"
1260 $(Q) $(INSTALL) -d $(prefix)/share/grpc
1261 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
1262
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +01001263verify-install:
Nicolas "Pixel" Noble2c23a722015-02-24 20:17:45 +01001264ifeq ($(INSTALL_OK),true)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +01001265 @echo "Your system looks ready to go."
1266 @echo
1267else
murgatroid99b6181362015-03-02 14:32:25 -08001268 @echo "We couldn't find protoc 3.0.0+ installed on your system. While this"
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +01001269 @echo "won't prevent grpc from working, you won't be able to compile"
1270 @echo "and run any meaningful code with it."
1271 @echo
1272 @echo
1273 @echo "Please download and install protobuf 3.0.0+ from:"
1274 @echo
1275 @echo " https://github.com/google/protobuf/releases"
1276 @echo
murgatroid99b6181362015-03-02 14:32:25 -08001277 @echo "Once you've done so, or if you think this message is in error,"
1278 @echo "you can re-run this check by doing:"
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +01001279 @echo
1280 @echo " make verify-install"
1281endif
1282
Craig Tiller3759e6f2015-01-15 08:13:11 -08001283clean:
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001284 $(E) "[CLEAN] Cleaning build directories."
Craig Tillerda224d62015-02-15 11:01:58 -08001285 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001286
1287
1288# The various libraries
1289
1290% for lib in libs:
1291${makelib(lib)}
1292% endfor
1293
1294
nnoble69ac39f2014-12-12 15:43:38 -08001295# All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001296
1297% for tgt in targets:
1298${maketarget(tgt)}
1299% endfor
1300
1301<%def name="makelib(lib)">
1302LIB${lib.name.upper()}_SRC = \\
1303
1304% for src in lib.src:
nnoble72309c62014-12-12 11:42:26 -08001305 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001306
1307% endfor
1308
1309% if "public_headers" in lib:
Craig Tiller59140fc2015-01-18 10:12:17 -08001310% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -08001311PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001312
nnoble85a49262014-12-08 18:14:03 -08001313% else:
1314PUBLIC_HEADERS_C += \\
1315
1316% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001317% for hdr in lib.public_headers:
1318 ${hdr} \\
1319
1320% endfor
1321% endif
1322
Craig Tiller61b910f2015-02-15 10:54:07 -08001323LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001324
Nicolas "Pixel" Noble4cc8c8a2015-06-23 02:37:49 +02001325## If the library requires OpenSSL, let's add some restrictions.
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001326% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001327ifeq ($(NO_SECURE),true)
1328
Nicolas "Pixel" Noble4cc8c8a2015-06-23 02:37:49 +02001329# You can't build secure libraries if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001330
Craig Tiller61b910f2015-02-15 10:54:07 -08001331$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001332
nnoble5b7f32a2014-12-22 08:12:44 -08001333% if lib.build == "all":
1334ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -08001335$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -08001336else
Craig Tiller61b910f2015-02-15 10:54:07 -08001337$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -08001338endif
1339% endif
1340
nnoble69ac39f2014-12-12 15:43:38 -08001341else
1342
Nicolas Noble53830622015-02-12 16:56:38 -08001343% if lib.language == 'c++':
1344ifeq ($(NO_PROTOBUF),true)
1345
1346# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
1347
Craig Tiller61b910f2015-02-15 10:54:07 -08001348$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001349
1350% if lib.build == "all":
1351ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -08001352$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001353else
Craig Tiller61b910f2015-02-15 10:54:07 -08001354$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001355endif
1356% endif
1357
1358else
1359% endif
1360
Craig Tiller61b910f2015-02-15 10:54:07 -08001361$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
Nicolas Noble047b7272015-01-16 13:55:05 -08001362## The else here corresponds to the if secure earlier.
nnoble20e2e3f2014-12-16 15:37:57 -08001363% else:
Nicolas Noble53830622015-02-12 16:56:38 -08001364% if lib.language == 'c++':
1365ifeq ($(NO_PROTOBUF),true)
1366
1367# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
1368
Craig Tiller61b910f2015-02-15 10:54:07 -08001369$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001370
1371% if lib.build == "all":
1372ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -08001373$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001374else
Craig Tiller61b910f2015-02-15 10:54:07 -08001375$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001376endif
nnoble20e2e3f2014-12-16 15:37:57 -08001377% endif
Nicolas Noble53830622015-02-12 16:56:38 -08001378
1379else
1380
1381% endif
Craig Tiller61b910f2015-02-15 10:54:07 -08001382$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP)\
Nicolas Noble53830622015-02-12 16:56:38 -08001383% endif
1384% if lib.language == 'c++':
1385 $(PROTOBUF_DEP)\
1386% endif
1387 $(LIB${lib.name.upper()}_OBJS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001388 $(E) "[AR] Creating $@"
nnoble85a49262014-12-08 18:14:03 -08001389 $(Q) mkdir -p `dirname $@`
Craig Tiller61b910f2015-02-15 10:54:07 -08001390 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1391 $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
nnoble20e2e3f2014-12-16 15:37:57 -08001392% if lib.get('baselib', False):
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001393% if lib.get('secure', 'check') == 'yes':
Craig Tiller7ab4fee2015-02-24 08:15:53 -08001394 $(Q) rm -rf tmp-merge-${lib.name}
1395 $(Q) mkdir tmp-merge-${lib.name}
1396 $(Q) ( cd tmp-merge-${lib.name} ; $(AR) x ../$(LIBDIR)/$(CONFIG)/lib${lib.name}.a )
1397 $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge-${lib.name} ; <%text>ar x ../$${l}</%text> ) ; done
1398 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/__.SYMDEF*
1399 $(Q) ar rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/*
1400 $(Q) rm -rf tmp-merge-${lib.name}
nnoble20e2e3f2014-12-16 15:37:57 -08001401% endif
1402% endif
Craig Tillerb4ee3b52015-01-21 16:22:50 -08001403ifeq ($(SYSTEM),Darwin)
murgatroid99b6181362015-03-02 14:32:25 -08001404 $(Q) ranlib $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tillerb4ee3b52015-01-21 16:22:50 -08001405endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001406
nnoble5b7f32a2014-12-22 08:12:44 -08001407<%
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001408
Craig Tiller59140fc2015-01-18 10:12:17 -08001409 if lib.language == 'c++':
nnoble5b7f32a2014-12-22 08:12:44 -08001410 ld = '$(LDXX)'
1411 else:
1412 ld = '$(LD)'
1413
Craig Tillerda224d62015-02-15 11:01:58 -08001414 out_base = '$(LIBDIR)/$(CONFIG)/' + lib.name
1415 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name
nnoble5b7f32a2014-12-22 08:12:44 -08001416
1417 common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
1418
1419 libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +01001420 lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -08001421 mingw_libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +01001422 mingw_lib_deps = ' $(ZLIB_DEP)'
Michael Berlinbf2e7f02015-05-01 16:17:01 -07001423 if lib.language == 'c++':
1424 lib_deps += ' $(PROTOBUF_DEP)'
1425 mingw_lib_deps += ' $(PROTOBUF_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -08001426 for dep in lib.get('deps', []):
1427 libs = libs + ' -l' + dep
Craig Tiller61b910f2015-02-15 10:54:07 -08001428 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001429 mingw_libs = mingw_libs + ' -l' + dep + '-imp'
Michael Berlin53513922015-05-01 16:14:15 -07001430 mingw_lib_deps = mingw_lib_deps + ' $(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001431
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001432 if lib.get('secure', 'check') == 'yes':
Nicolas "Pixel" Noble945b4132015-06-02 20:13:40 +02001433 common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)'
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001434 for src in lib.src:
1435 sources_that_need_openssl.add(src)
1436 else:
1437 for src in lib.src:
1438 sources_that_don_t_need_openssl.add(src)
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001439
1440 if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble5b7f32a2014-12-22 08:12:44 -08001441 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1442 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001443
1444 if lib.language == 'c++':
1445 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
nnoble5b7f32a2014-12-22 08:12:44 -08001446%>
1447
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001448% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -08001449ifeq ($(SYSTEM),MINGW32)
1450${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001451 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -08001452 $(Q) mkdir -p `dirname $@`
Craig Tillerda224d62015-02-15 11:01:58 -08001453 $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=${out_base}.def -Wl,--out-implib=${out_libbase}-imp.a -o ${out_base}.$(SHARED_EXT) ${common}${mingw_libs}
nnoble5b7f32a2014-12-22 08:12:44 -08001454else
1455${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
1456 $(E) "[LD] Linking $@"
1457 $(Q) mkdir -p `dirname $@`
1458ifeq ($(SYSTEM),Darwin)
Masood Malekghassemid1be74f2015-04-07 16:23:09 -07001459 $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name lib${lib.name}.$(SHARED_EXT) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
nnoble5b7f32a2014-12-22 08:12:44 -08001460else
Craig Tillerda224d62015-02-15 11:01:58 -08001461 $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
Nicolas "Pixel" Nobled8f8b6b2015-01-29 21:29:43 +01001462 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major}
nnoble5b7f32a2014-12-22 08:12:44 -08001463 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so
1464endif
1465endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001466% endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001467% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
Nicolas Noble047b7272015-01-16 13:55:05 -08001468## If the lib was secure, we have to close the Makefile's if that tested
Nicolas "Pixel" Noble4cc8c8a2015-06-23 02:37:49 +02001469## the presence of OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001470
1471endif
1472% endif
1473% if lib.language == 'c++':
1474## If the lib was C++, we have to close the Makefile's if that tested
1475## the presence of protobuf 3.0.0+
nnoble69ac39f2014-12-12 15:43:38 -08001476
1477endif
1478% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001479
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001480% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001481ifneq ($(NO_SECURE),true)
1482% endif
1483ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -08001484-include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001485endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001486% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001487endif
1488% endif
Craig Tiller27715ca2015-01-12 16:55:59 -08001489% for src in lib.src:
Craig Tillerd896fa52015-04-24 14:30:09 -07001490% if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src):
Craig Tiller04f81562015-04-24 14:34:30 -07001491$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))}
Craig Tiller27715ca2015-01-12 16:55:59 -08001492% endif
Craig Tiller27715ca2015-01-12 16:55:59 -08001493% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001494</%def>
1495
Nicolas "Pixel" Nobleadaa1002015-04-29 08:56:01 +02001496<%def name="maketarget(tgt)"><% has_no_sources = not tgt.src %>
1497% if not has_no_sources:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001498${tgt.name.upper()}_SRC = \\
1499
1500% for src in tgt.src:
nnoble72309c62014-12-12 11:42:26 -08001501 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001502
1503% endfor
1504
Craig Tiller61b910f2015-02-15 10:54:07 -08001505${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
Nicolas "Pixel" Nobleadaa1002015-04-29 08:56:01 +02001506% endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001507% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001508ifeq ($(NO_SECURE),true)
1509
Nicolas "Pixel" Noble4cc8c8a2015-06-23 02:37:49 +02001510# You can't build secure targets if you don't have OpenSSL.
Nicolas Noble047b7272015-01-16 13:55:05 -08001511
Craig Tiller61b910f2015-02-15 10:54:07 -08001512$(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001513
1514else
1515
1516% endif
Nicolas Noble047b7272015-01-16 13:55:05 -08001517##
1518## We're not trying to add a dependency on building zlib and openssl here,
1519## as it's already done in the libraries. We're assuming that the build
1520## trickles down, and that a secure target requires a secure version of
1521## a library.
1522##
1523## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1524## I can live with that.
1525##
Nicolas "Pixel" Noble18953e32015-02-27 02:41:11 +01001526% if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001527
1528ifeq ($(NO_PROTOBUF),true)
1529
Nicolas "Pixel" Noble18953e32015-02-27 02:41:11 +01001530# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+.
Nicolas Noble53830622015-02-12 16:56:38 -08001531
Craig Tiller61b910f2015-02-15 10:54:07 -08001532$(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001533
1534else
1535
Nicolas "Pixel" Nobleadaa1002015-04-29 08:56:01 +02001536$(BINDIR)/$(CONFIG)/${tgt.name}: \
1537% if not has_no_sources:
1538$(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
1539% endif
Nicolas Noble53830622015-02-12 16:56:38 -08001540% else:
Nicolas "Pixel" Nobleadaa1002015-04-29 08:56:01 +02001541$(BINDIR)/$(CONFIG)/${tgt.name}: \
1542% if not has_no_sources:
1543$(${tgt.name.upper()}_OBJS)\
1544% endif
Nicolas Noble53830622015-02-12 16:56:38 -08001545% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001546% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001547 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001548% endfor
1549
Craig Tiller59140fc2015-01-18 10:12:17 -08001550% if tgt.language == "c++":
Nicolas Noble047b7272015-01-16 13:55:05 -08001551## C++ targets specificies.
nnoble72309c62014-12-12 11:42:26 -08001552% if tgt.build == 'protoc':
1553 $(E) "[HOSTLD] Linking $@"
1554 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Nobleadaa1002015-04-29 08:56:01 +02001555 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) \
1556% if not has_no_sources:
1557$(${tgt.name.upper()}_OBJS)\
1558% endif
nnoble72309c62014-12-12 11:42:26 -08001559% else:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001560 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -08001561 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Nobleadaa1002015-04-29 08:56:01 +02001562 $(Q) $(LDXX) $(LDFLAGS) \
1563% if not has_no_sources:
1564$(${tgt.name.upper()}_OBJS)\
1565% endif
nnoble72309c62014-12-12 11:42:26 -08001566% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001567% else:
Nicolas Noble047b7272015-01-16 13:55:05 -08001568## C-only targets specificities.
nnoble72309c62014-12-12 11:42:26 -08001569 $(E) "[LD] Linking $@"
1570 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Nobleadaa1002015-04-29 08:56:01 +02001571 $(Q) $(LD) $(LDFLAGS) \
1572% if not has_no_sources:
1573$(${tgt.name.upper()}_OBJS)\
1574% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001575% endif
1576% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001577 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001578% endfor
Craig Tiller59140fc2015-01-18 10:12:17 -08001579% if tgt.language == "c++":
nnoble72309c62014-12-12 11:42:26 -08001580% if tgt.build == 'protoc':
Nicolas Noble53830622015-02-12 16:56:38 -08001581 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
nnoble72309c62014-12-12 11:42:26 -08001582% else:
Nicolas Noble53830622015-02-12 16:56:38 -08001583 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001584% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001585% endif
nnoblec78b3402014-12-11 16:06:57 -08001586% if tgt.build == 'protoc':
nnoble72309c62014-12-12 11:42:26 -08001587 $(HOST_LDLIBS)\
1588% else:
1589 $(LDLIBS)\
1590% endif
1591% if tgt.build == 'protoc':
1592 $(HOST_LDLIBS_PROTOC)\
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001593% elif tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble72309c62014-12-12 11:42:26 -08001594 $(LDLIBS_SECURE)\
nnoblec78b3402014-12-11 16:06:57 -08001595% endif
Yang Gaob0b518e2015-04-13 14:53:25 -07001596% if tgt.language == 'c++' and tgt.build == 'test':
1597 $(GTEST_LIB)\
David Garcia Quintasaa52d0a2015-05-14 19:04:23 -07001598% elif tgt.language == 'c++' and tgt.build == 'benchmark':
1599 $(GTEST_LIB)\
Yang Gaob0b518e2015-04-13 14:53:25 -07001600% endif
Craig Tiller61b910f2015-02-15 10:54:07 -08001601 -o $(BINDIR)/$(CONFIG)/${tgt.name}
Nicolas "Pixel" Noble18953e32015-02-27 02:41:11 +01001602% if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001603
1604endif
1605% endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001606% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001607
1608endif
1609% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001610
Craig Tillerf5371ef2015-01-12 16:40:18 -08001611% for src in tgt.src:
Craig Tiller61b910f2015-02-15 10:54:07 -08001612$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
Craig Tillerf5371ef2015-01-12 16:40:18 -08001613% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001614 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Craig Tillerf5371ef2015-01-12 16:40:18 -08001615% endfor
1616
1617% endfor
Nicolas "Pixel" Nobleadaa1002015-04-29 08:56:01 +02001618% if not has_no_sources:
Craig Tiller8f126a62015-01-15 08:50:19 -08001619deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas "Pixel" Nobleadaa1002015-04-29 08:56:01 +02001620% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001621
Nicolas "Pixel" Nobleadaa1002015-04-29 08:56:01 +02001622% if not has_no_sources:
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001623% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001624ifneq ($(NO_SECURE),true)
1625% endif
1626ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -08001627-include $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001628endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001629% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001630endif
1631% endif
Nicolas "Pixel" Nobleadaa1002015-04-29 08:56:01 +02001632% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001633</%def>
1634
Nicolas "Pixel" Noble010f1e72015-04-23 02:23:49 +02001635ifneq ($(OPENSSL_DEP),)
1636# This is to ensure the embedded OpenSSL is built beforehand, properly
1637# installing headers to their final destination on the drive. We need this
1638# otherwise parallel compilation will fail if a source is compiled first.
1639% for src in sorted(sources_that_need_openssl):
1640% if src not in sources_that_don_t_need_openssl:
1641${src}: $(OPENSSL_DEP)
1642% endif
1643% endfor
1644endif
1645
nnoble85a49262014-12-08 18:14:03 -08001646.PHONY: all strip tools \
nnoble69ac39f2014-12-12 15:43:38 -08001647dep_error openssl_dep_error openssl_dep_message git_update stop \
nnoble85a49262014-12-08 18:14:03 -08001648buildtests buildtests_c buildtests_cxx \
1649test test_c test_cxx \
1650install install_c install_cxx \
1651install-headers install-headers_c install-headers_cxx \
1652install-shared install-shared_c install-shared_cxx \
1653install-static install-static_c install-static_cxx \
1654strip strip-shared strip-static \
1655strip_c strip-shared_c strip-static_c \
1656strip_cxx strip-shared_cxx strip-static_cxx \
Craig Tillerf0afe502015-01-15 09:04:49 -08001657dep_c dep_cxx bins_dep_c bins_dep_cxx \
Craig Tiller12c82092015-01-15 08:45:56 -08001658clean