blob: 926c908b66ff69ab8bca3ff02c16308ceba8599e [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.
Craig Tiller3b935482015-02-16 12:15:48 -08005
Craig Tillerd7f33352015-02-20 15:18:45 -08006# Copyright 2015, Google Inc.
Craig Tiller3b935482015-02-16 12:15:48 -08007# All rights reserved.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions are
11# met:
12#
13# * Redistributions of source code must retain the above copyright
14# notice, this list of conditions and the following disclaimer.
15# * Redistributions in binary form must reproduce the above
16# copyright notice, this list of conditions and the following disclaimer
17# in the documentation and/or other materials provided with the
18# distribution.
19# * Neither the name of Google Inc. nor the names of its
20# contributors may be used to endorse or promote products derived from
21# this software without specific prior written permission.
22#
23# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080034<%!
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080035 import re
Craig Tillerf5371ef2015-01-12 16:40:18 -080036 import os
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080037
nnoblec87b1c52015-01-05 17:15:18 -080038 proto_re = re.compile('(.*)\\.proto')
nnoble72309c62014-12-12 11:42:26 -080039
nnoble72309c62014-12-12 11:42:26 -080040 def proto_to_cc(filename):
41 m = proto_re.match(filename)
42 if not m:
43 return filename
Nicolas "Pixel" Noble0caebbf2015-04-09 23:08:51 +020044 return '$(GENDIR)/' + m.group(1) + '.pb.cc $(GENDIR)/' + m.group(1) + '.grpc.pb.cc'
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080045%>
46
Craig Tiller96b49552015-01-21 16:29:01 -080047
48# Basic platform detection
49HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
50ifeq ($(SYSTEM),)
51SYSTEM = $(HOST_SYSTEM)
52endif
Nicolas Noblef8681182015-03-18 14:25:44 -070053ifeq ($(SYSTEM),MSYS)
54SYSTEM = MINGW32
55endif
Craig Tiller96b49552015-01-21 16:29:01 -080056
57
Craig Tiller61b910f2015-02-15 10:54:07 -080058ifndef BUILDDIR
59BUILDDIR = .
60endif
61
Nicolas Noblef8681182015-03-18 14:25:44 -070062HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false)
63HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false)
64HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false)
65
66ifeq ($(HAS_CC),true)
67DEFAULT_CC = cc
68DEFAULT_CXX = c++
69else
70ifeq ($(HAS_GCC),true)
71DEFAULT_CC = gcc
72DEFAULT_CXX = g++
73else
74ifeq ($(HAS_CLANG),true)
75DEFAULT_CC = clang
76DEFAULT_CXX = clang++
77else
78DEFAULT_CC = no_c_compiler
79DEFAULT_CXX = no_c++_compiler
80endif
81endif
82endif
83
84
Craig Tiller61b910f2015-02-15 10:54:07 -080085BINDIR = $(BUILDDIR)/bins
86OBJDIR = $(BUILDDIR)/objs
87LIBDIR = $(BUILDDIR)/libs
88GENDIR = $(BUILDDIR)/gens
89
ctiller8cfebb92015-01-06 15:02:12 -080090# Configurations
91
92VALID_CONFIG_opt = 1
Nicolas Noblef8681182015-03-18 14:25:44 -070093CC_opt = $(DEFAULT_CC)
94CXX_opt = $(DEFAULT_CXX)
95LD_opt = $(DEFAULT_CC)
96LDXX_opt = $(DEFAULT_CXX)
ctiller8cfebb92015-01-06 15:02:12 -080097CPPFLAGS_opt = -O2
98LDFLAGS_opt =
99DEFINES_opt = NDEBUG
100
Vijay Paibc171132015-04-13 10:58:06 -0700101VALID_CONFIG_latprof = 1
102CC_latprof = $(DEFAULT_CC)
103CXX_latprof = $(DEFAULT_CXX)
104LD_latprof = $(DEFAULT_CC)
105LDXX_latprof = $(DEFAULT_CXX)
106CPPFLAGS_latprof = -O2 -DGRPC_LATENCY_PROFILER
107LDFLAGS_latprof =
108DEFINES_latprof = NDEBUG
109
ctiller8cfebb92015-01-06 15:02:12 -0800110VALID_CONFIG_dbg = 1
Nicolas Noblef8681182015-03-18 14:25:44 -0700111CC_dbg = $(DEFAULT_CC)
112CXX_dbg = $(DEFAULT_CXX)
113LD_dbg = $(DEFAULT_CC)
114LDXX_dbg = $(DEFAULT_CXX)
ctiller8cfebb92015-01-06 15:02:12 -0800115CPPFLAGS_dbg = -O0
116LDFLAGS_dbg =
117DEFINES_dbg = _DEBUG DEBUG
118
Vijay Paidc7110f2015-04-02 13:59:05 -0700119VALID_CONFIG_mutrace = 1
120CC_mutrace = $(DEFAULT_CC)
121CXX_mutrace = $(DEFAULT_CXX)
122LD_mutrace = $(DEFAULT_CC)
123LDXX_mutrace = $(DEFAULT_CXX)
124CPPFLAGS_mutrace = -O0
125LDFLAGS_mutrace = -rdynamic
126DEFINES_mutrace = _DEBUG DEBUG
127
Craig Tillerec0b8f32015-01-15 07:30:00 -0800128VALID_CONFIG_valgrind = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800129REQUIRE_CUSTOM_LIBRARIES_valgrind = 1
Nicolas Noblef8681182015-03-18 14:25:44 -0700130CC_valgrind = $(DEFAULT_CC)
131CXX_valgrind = $(DEFAULT_CXX)
132LD_valgrind = $(DEFAULT_CC)
133LDXX_valgrind = $(DEFAULT_CXX)
Craig Tillerec0b8f32015-01-15 07:30:00 -0800134CPPFLAGS_valgrind = -O0
135OPENSSL_CFLAGS_valgrind = -DPURIFY
136LDFLAGS_valgrind =
Craig Tillerf6901be2015-02-27 09:12:58 -0800137DEFINES_valgrind = _DEBUG DEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20
Craig Tillerec0b8f32015-01-15 07:30:00 -0800138
ctiller8cfebb92015-01-06 15:02:12 -0800139VALID_CONFIG_tsan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800140REQUIRE_CUSTOM_LIBRARIES_tsan = 1
ctiller8cfebb92015-01-06 15:02:12 -0800141CC_tsan = clang
142CXX_tsan = clang++
143LD_tsan = clang
144LDXX_tsan = clang++
145CPPFLAGS_tsan = -O1 -fsanitize=thread -fno-omit-frame-pointer
146LDFLAGS_tsan = -fsanitize=thread
Craig Tillerf6901be2015-02-27 09:12:58 -0800147DEFINES_tsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10
ctiller8cfebb92015-01-06 15:02:12 -0800148
149VALID_CONFIG_asan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800150REQUIRE_CUSTOM_LIBRARIES_asan = 1
ctiller8cfebb92015-01-06 15:02:12 -0800151CC_asan = clang
152CXX_asan = clang++
153LD_asan = clang
154LDXX_asan = clang++
155CPPFLAGS_asan = -O1 -fsanitize=address -fno-omit-frame-pointer
156LDFLAGS_asan = -fsanitize=address
Craig Tillerf6901be2015-02-27 09:12:58 -0800157DEFINES_asan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5
ctiller8cfebb92015-01-06 15:02:12 -0800158
159VALID_CONFIG_msan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800160REQUIRE_CUSTOM_LIBRARIES_msan = 1
ctiller8cfebb92015-01-06 15:02:12 -0800161CC_msan = clang
Nicolas "Pixel" Nobled66cba22015-02-14 02:59:12 +0100162CXX_msan = clang++-libc++
ctiller8cfebb92015-01-06 15:02:12 -0800163LD_msan = clang
Nicolas "Pixel" Nobled66cba22015-02-14 02:59:12 +0100164LDXX_msan = clang++-libc++
Craig Tilleracd62292015-02-16 11:12:28 -0800165CPPFLAGS_msan = -O1 -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 -0800166OPENSSL_CFLAGS_msan = -DPURIFY
Nicolas "Pixel" Nobled66cba22015-02-14 02:59:12 +0100167LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
Craig Tillerf6901be2015-02-27 09:12:58 -0800168DEFINES_msan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20
ctiller8cfebb92015-01-06 15:02:12 -0800169
Craig Tiller96bd5f62015-02-13 09:04:13 -0800170VALID_CONFIG_ubsan = 1
171REQUIRE_CUSTOM_LIBRARIES_ubsan = 1
172CC_ubsan = clang
173CXX_ubsan = clang++
174LD_ubsan = clang
175LDXX_ubsan = clang++
176CPPFLAGS_ubsan = -O1 -fsanitize=undefined -fno-omit-frame-pointer
177OPENSSL_CFLAGS_ubsan = -DPURIFY
Craig Tiller96bd5f62015-02-13 09:04:13 -0800178LDFLAGS_ubsan = -fsanitize=undefined
Craig Tillerf6901be2015-02-27 09:12:58 -0800179DEFINES_ubsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10
Craig Tiller96bd5f62015-02-13 09:04:13 -0800180
Craig Tiller699ba212015-01-13 17:02:20 -0800181VALID_CONFIG_gcov = 1
182CC_gcov = gcc
183CXX_gcov = g++
184LD_gcov = gcc
185LDXX_gcov = g++
186CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage
187LDFLAGS_gcov = -fprofile-arcs -ftest-coverage
188DEFINES_gcov = NDEBUG
189
Nicolas Noble047b7272015-01-16 13:55:05 -0800190
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800191# General settings.
192# You may want to change these depending on your system.
193
194prefix ?= /usr/local
195
196PROTOC = protoc
yangg102e4fe2015-01-06 16:02:50 -0800197CONFIG ?= opt
ctiller8cfebb92015-01-06 15:02:12 -0800198CC = $(CC_$(CONFIG))
199CXX = $(CXX_$(CONFIG))
200LD = $(LD_$(CONFIG))
201LDXX = $(LDXX_$(CONFIG))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800202AR = ar
Nicolas "Pixel" Nobled7631a42015-02-27 07:52:39 +0100203ifeq ($(SYSTEM),Linux)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800204STRIP = strip --strip-unneeded
Nicolas "Pixel" Nobled7631a42015-02-27 07:52:39 +0100205else
206ifeq ($(SYSTEM),Darwin)
207STRIP = strip -x
208else
209STRIP = strip
210endif
211endif
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100212INSTALL = install
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800213RM = rm -f
214
yangg102e4fe2015-01-06 16:02:50 -0800215ifndef VALID_CONFIG_$(CONFIG)
216$(error Invalid CONFIG value '$(CONFIG)')
217endif
218
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100219ifeq ($(SYSTEM),Linux)
220TMPOUT = /dev/null
221else
222TMPOUT = `mktemp /tmp/test-out-XXXXXX`
223endif
Nicolas Noble047b7272015-01-16 13:55:05 -0800224
Craig Tillercf133f42015-02-26 14:05:56 -0800225# Detect if we can use C++11
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100226CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc
Craig Tillercf133f42015-02-26 14:05:56 -0800227HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false)
228
Nicolas Noble047b7272015-01-16 13:55:05 -0800229# The HOST compiler settings are used to compile the protoc plugins.
230# In most cases, you won't have to change anything, but if you are
231# cross-compiling, you can override these variables from GNU make's
232# command line: make CC=cross-gcc HOST_CC=gcc
233
nnoble72309c62014-12-12 11:42:26 -0800234HOST_CC = $(CC)
235HOST_CXX = $(CXX)
236HOST_LD = $(LD)
237HOST_LDXX = $(LDXX)
238
ctillercab52e72015-01-06 13:10:23 -0800239CPPFLAGS += $(CPPFLAGS_$(CONFIG))
Nicolas "Pixel" Noble72743822015-02-20 20:59:29 +0100240DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
ctiller8cfebb92015-01-06 15:02:12 -0800241LDFLAGS += $(LDFLAGS_$(CONFIG))
ctillercab52e72015-01-06 13:10:23 -0800242
Craig Tiller86fa1c52015-02-27 09:57:58 -0800243ifdef EXTRA_DEFINES
Craig Tillerf5065c52015-02-27 16:17:39 -0800244DEFINES += $(EXTRA_DEFINES)
Craig Tiller86fa1c52015-02-27 09:57:58 -0800245endif
246
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800247CFLAGS += -std=c89 -pedantic
Craig Tillercf133f42015-02-26 14:05:56 -0800248ifeq ($(HAS_CXX11),true)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800249CXXFLAGS += -std=c++11
Craig Tillercf133f42015-02-26 14:05:56 -0800250else
251CXXFLAGS += -std=c++0x
Craig Tillercf133f42015-02-26 14:05:56 -0800252endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700253CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
254LDFLAGS += -g
255
256ifneq ($(SYSTEM),MINGW32)
257PIC_CPPFLAGS = -fPIC
258CPPFLAGS += -fPIC
259LDFLAGS += -fPIC
260endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800261
Craig Tillerda224d62015-02-15 11:01:58 -0800262INCLUDES = . include $(GENDIR)
Craig Tiller96b49552015-01-21 16:29:01 -0800263ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100264ifneq ($(wildcard /usr/local/ssl/include),)
265INCLUDES += /usr/local/ssl/include
266endif
267ifneq ($(wildcard /opt/local/include),)
268INCLUDES += /opt/local/include
269endif
270ifneq ($(wildcard /usr/local/include),)
271INCLUDES += /usr/local/include
272endif
Craig Tiller96b49552015-01-21 16:29:01 -0800273LIBS = m z
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100274ifneq ($(wildcard /usr/local/ssl/lib),)
275LDFLAGS += -L/usr/local/ssl/lib
276endif
277ifneq ($(wildcard /opt/local/lib),)
278LDFLAGS += -L/opt/local/lib
279endif
280ifneq ($(wildcard /usr/local/lib),)
281LDFLAGS += -L/usr/local/lib
282endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700283endif
284
285ifeq ($(SYSTEM),Linux)
ctillerc008ae52015-01-07 15:33:00 -0800286LIBS = rt m z pthread
Craig Tiller96b49552015-01-21 16:29:01 -0800287LDFLAGS += -pthread
288endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800289
Nicolas Noblef8681182015-03-18 14:25:44 -0700290ifeq ($(SYSTEM),MINGW32)
291LIBS = m z pthread
292LDFLAGS += -pthread
293endif
294
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800295ifneq ($(wildcard /usr/src/gtest/src/gtest-all.cc),)
296GTEST_LIB = /usr/src/gtest/src/gtest-all.cc -I/usr/src/gtest
297else
298GTEST_LIB = -lgtest
299endif
chenwa8fd44a2014-12-10 15:13:55 -0800300GTEST_LIB += -lgflags
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800301ifeq ($(V),1)
302E = @:
303Q =
304else
305E = @echo
306Q = @
307endif
308
309VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build}
310
311CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
312CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
313
314LDFLAGS += $(ARCH_FLAGS)
315LDLIBS += $(addprefix -l, $(LIBS))
316LDLIBSXX += $(addprefix -l, $(LIBSXX))
nnoble72309c62014-12-12 11:42:26 -0800317
318HOST_CPPFLAGS = $(CPPFLAGS)
319HOST_CFLAGS = $(CFLAGS)
320HOST_CXXFLAGS = $(CXXFLAGS)
321HOST_LDFLAGS = $(LDFLAGS)
322HOST_LDLIBS = $(LDLIBS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800323
nnoble69ac39f2014-12-12 15:43:38 -0800324
325# These are automatically computed variables.
326# There shouldn't be any need to change anything from now on.
327
nnoble5b7f32a2014-12-22 08:12:44 -0800328ifeq ($(SYSTEM),MINGW32)
329SHARED_EXT = dll
330endif
331ifeq ($(SYSTEM),Darwin)
332SHARED_EXT = dylib
333endif
334ifeq ($(SHARED_EXT),)
335SHARED_EXT = so.$(VERSION)
336endif
337
nnoble69ac39f2014-12-12 15:43:38 -0800338ifeq ($(wildcard .git),)
339IS_GIT_FOLDER = false
340else
341IS_GIT_FOLDER = true
342endif
343
Nicolas Noblef8681182015-03-18 14:25:44 -0700344ifeq ($(SYSTEM),Linux)
345OPENSSL_REQUIRES_DL = true
346endif
347
348ifeq ($(SYSTEM),Darwin)
349OPENSSL_REQUIRES_DL = true
350endif
351
352ifeq ($(SYSTEM),MINGW32)
353OPENSSL_LIBS = ssl32 eay32
354else
355OPENSSL_LIBS = ssl crypto
356endif
357
358OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100359ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
360PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
361PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
Nicolas Noblef8681182015-03-18 14:25:44 -0700362PROTOC_CMD = which protoc > /dev/null
Nicolas Noble53830622015-02-12 16:56:38 -0800363PROTOC_CHECK_CMD = protoc --version | grep -q libprotoc.3
Craig Tiller297fafa2015-01-15 15:46:39 -0800364
Nicolas Noblef8681182015-03-18 14:25:44 -0700365ifeq ($(OPENSSL_REQUIRES_DL),true)
366OPENSSL_ALPN_CHECK_CMD += -ldl
367endif
368
Craig Tiller50524cc2015-01-29 23:00:00 -0800369ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
Craig Tiller297fafa2015-01-15 15:46:39 -0800370HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
371ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
372DEFINES += GRPC_HAVE_PERFTOOLS
373LIBS += profiler
374endif
Craig Tiller50524cc2015-01-29 23:00:00 -0800375endif
nnoble69ac39f2014-12-12 15:43:38 -0800376
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100377HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
Craig Tillerc4da6b72015-01-15 08:01:14 -0800378ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
nnoble60825402014-12-15 14:43:51 -0800379HAS_SYSTEM_OPENSSL_ALPN = $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
380HAS_SYSTEM_ZLIB = $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100381HAS_SYSTEM_PROTOBUF = $(HAS_SYSTEM_PROTOBUF_VERIFY)
Craig Tillerc4da6b72015-01-15 08:01:14 -0800382else
383# override system libraries if the config requires a custom compiled library
384HAS_SYSTEM_OPENSSL_ALPN = false
385HAS_SYSTEM_ZLIB = false
Nicolas Noble53830622015-02-12 16:56:38 -0800386HAS_SYSTEM_PROTOBUF = false
Craig Tillerc4da6b72015-01-15 08:01:14 -0800387endif
nnoble69ac39f2014-12-12 15:43:38 -0800388
Nicolas Noblef8681182015-03-18 14:25:44 -0700389HAS_PROTOC = $(shell $(PROTOC_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100390ifeq ($(HAS_PROTOC),true)
Nicolas Noble53830622015-02-12 16:56:38 -0800391HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100392else
393HAS_VALID_PROTOC = false
394endif
Nicolas Noble53830622015-02-12 16:56:38 -0800395
nnoble69ac39f2014-12-12 15:43:38 -0800396ifeq ($(wildcard third_party/openssl/ssl/ssl.h),)
397HAS_EMBEDDED_OPENSSL_ALPN = false
398else
399HAS_EMBEDDED_OPENSSL_ALPN = true
400endif
401
402ifeq ($(wildcard third_party/zlib/zlib.h),)
403HAS_EMBEDDED_ZLIB = false
404else
405HAS_EMBEDDED_ZLIB = true
406endif
407
Nicolas Noble53830622015-02-12 16:56:38 -0800408ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
409HAS_EMBEDDED_PROTOBUF = false
410ifneq ($(HAS_VALID_PROTOC),true)
411NO_PROTOC = true
412endif
413else
414HAS_EMBEDDED_PROTOBUF = true
415endif
416
nnoble69ac39f2014-12-12 15:43:38 -0800417ifeq ($(HAS_SYSTEM_ZLIB),false)
418ifeq ($(HAS_EMBEDDED_ZLIB),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800419ZLIB_DEP = $(LIBDIR)/$(CONFIG)/zlib/libz.a
nnoble69ac39f2014-12-12 15:43:38 -0800420CPPFLAGS += -Ithird_party/zlib
Craig Tillerda224d62015-02-15 11:01:58 -0800421LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib
nnoble69ac39f2014-12-12 15:43:38 -0800422else
423DEP_MISSING += zlib
424endif
425endif
426
427ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false)
428ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800429OPENSSL_DEP = $(LIBDIR)/$(CONFIG)/openssl/libssl.a
430OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/openssl/libssl.a $(LIBDIR)/$(CONFIG)/openssl/libcrypto.a
Craig Tillerec043032015-02-20 17:24:41 -0800431# need to prefix these to ensure overriding system libraries
432CPPFLAGS := -Ithird_party/openssl/include $(CPPFLAGS)
433LDFLAGS := -L$(LIBDIR)/$(CONFIG)/openssl $(LDFLAGS)
Nicolas Noblef8681182015-03-18 14:25:44 -0700434ifeq ($(OPENSSL_REQUIRES_DL),true)
nnoble5b7f32a2014-12-22 08:12:44 -0800435LIBS_SECURE = dl
Nicolas Noblef8681182015-03-18 14:25:44 -0700436endif
nnoble69ac39f2014-12-12 15:43:38 -0800437else
438NO_SECURE = true
439endif
nnoble5b7f32a2014-12-22 08:12:44 -0800440else
Nicolas Noblef8681182015-03-18 14:25:44 -0700441LIBS_SECURE = $(OPENSSL_LIBS)
442ifeq ($(OPENSSL_REQUIRES_DL),true)
443LIBS_SECURE += dl
444endif
nnoble69ac39f2014-12-12 15:43:38 -0800445endif
446
nnoble5b7f32a2014-12-22 08:12:44 -0800447LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
448
Nicolas Noble53830622015-02-12 16:56:38 -0800449ifeq ($(HAS_SYSTEM_PROTOBUF),false)
450ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800451PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
Craig Tiller9ec95fa2015-02-20 20:36:21 -0800452CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
453LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
Craig Tiller61b910f2015-02-15 10:54:07 -0800454PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
Nicolas Noble53830622015-02-12 16:56:38 -0800455else
456NO_PROTOBUF = true
457endif
458else
459endif
460
461LIBS_PROTOBUF = protobuf
462LIBS_PROTOC = protoc protobuf
463
464LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
465HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
466
Craig Tiller12c82092015-01-15 08:45:56 -0800467ifeq ($(MAKECMDGOALS),clean)
nnoble69ac39f2014-12-12 15:43:38 -0800468NO_DEPS = true
469endif
470
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100471INSTALL_OK = false
472ifeq ($(HAS_VALID_PROTOC),true)
473ifeq ($(HAS_SYSTEM_PROTOBUF_VERIFY),true)
474INSTALL_OK = true
475endif
476endif
477
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800478.SECONDARY = %.pb.h %.pb.cc
479
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100480PROTOC_PLUGINS =\
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800481% for tgt in targets:
482% if tgt.build == 'protoc':
Craig Tiller61b910f2015-02-15 10:54:07 -0800483 $(BINDIR)/$(CONFIG)/${tgt.name}\
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800484% endif
485% endfor
486
nnoble69ac39f2014-12-12 15:43:38 -0800487ifeq ($(DEP_MISSING),)
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100488all: static shared plugins\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800489% for tgt in targets:
490% if tgt.build == 'all':
Craig Tiller61b910f2015-02-15 10:54:07 -0800491 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800492% endif
493% endfor
494
nnoble69ac39f2014-12-12 15:43:38 -0800495dep_error:
496 @echo "You shouldn't see this message - all of your dependencies are correct."
497else
498all: dep_error git_update stop
499
500dep_error:
501 @echo
502 @echo "DEPENDENCY ERROR"
503 @echo
504 @echo "You are missing system dependencies that are essential to build grpc,"
505 @echo "and the third_party directory doesn't have them:"
506 @echo
507 @echo " $(DEP_MISSING)"
508 @echo
509 @echo "Installing the development packages for your system will solve"
510 @echo "this issue. Please consult INSTALL to get more information."
511 @echo
512 @echo "If you need information about why these tests failed, run:"
513 @echo
514 @echo " make run_dep_checks"
515 @echo
516endif
517
518git_update:
519ifeq ($(IS_GIT_FOLDER),true)
520 @echo "Additionally, since you are in a git clone, you can download the"
521 @echo "missing dependencies in third_party by running the following command:"
522 @echo
ctiller64f29102014-12-15 10:40:59 -0800523 @echo " git submodule update --init"
nnoble69ac39f2014-12-12 15:43:38 -0800524 @echo
525endif
526
527openssl_dep_error: openssl_dep_message git_update stop
528
Nicolas Noble53830622015-02-12 16:56:38 -0800529protobuf_dep_error: protobuf_dep_message git_update stop
530
531protoc_dep_error: protoc_dep_message git_update stop
532
nnoble69ac39f2014-12-12 15:43:38 -0800533openssl_dep_message:
534 @echo
535 @echo "DEPENDENCY ERROR"
536 @echo
537 @echo "The target you are trying to run requires OpenSSL with ALPN support."
538 @echo "Your system doesn't have it, and neither does the third_party directory."
539 @echo
540 @echo "Please consult INSTALL to get more information."
541 @echo
542 @echo "If you need information about why these tests failed, run:"
543 @echo
544 @echo " make run_dep_checks"
545 @echo
546
Nicolas Noble53830622015-02-12 16:56:38 -0800547protobuf_dep_message:
548 @echo
549 @echo "DEPENDENCY ERROR"
550 @echo
551 @echo "The target you are trying to run requires protobuf 3.0.0+"
552 @echo "Your system doesn't have it, and neither does the third_party directory."
553 @echo
554 @echo "Please consult INSTALL to get more information."
555 @echo
556 @echo "If you need information about why these tests failed, run:"
557 @echo
558 @echo " make run_dep_checks"
559 @echo
560
561protoc_dep_message:
562 @echo
563 @echo "DEPENDENCY ERROR"
564 @echo
565 @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
566 @echo "Your system doesn't have it, and neither does the third_party directory."
567 @echo
568 @echo "Please consult INSTALL to get more information."
569 @echo
570 @echo "If you need information about why these tests failed, run:"
571 @echo
572 @echo " make run_dep_checks"
573 @echo
574
nnoble69ac39f2014-12-12 15:43:38 -0800575stop:
576 @false
577
ctiller09cb6d52014-12-19 17:38:22 -0800578% for tgt in targets:
Craig Tiller61b910f2015-02-15 10:54:07 -0800579${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
ctiller09cb6d52014-12-19 17:38:22 -0800580% endfor
581
nnoble69ac39f2014-12-12 15:43:38 -0800582run_dep_checks:
nnoble69ac39f2014-12-12 15:43:38 -0800583 $(OPENSSL_ALPN_CHECK_CMD) || true
584 $(ZLIB_CHECK_CMD) || true
Nicolas Noble53830622015-02-12 16:56:38 -0800585 $(PERFTOOLS_CHECK_CMD) || true
586 $(PROTOBUF_CHECK_CMD) || true
587 $(PROTOC_CHECK_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800588
Craig Tiller61b910f2015-02-15 10:54:07 -0800589$(LIBDIR)/$(CONFIG)/zlib/libz.a:
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100590 $(E) "[MAKE] Building zlib"
Nicolas Noblef8681182015-03-18 14:25:44 -0700591 $(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="$(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG))" ./configure --static)
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100592 $(Q)$(MAKE) -C third_party/zlib clean
593 $(Q)$(MAKE) -C third_party/zlib
Craig Tiller61b910f2015-02-15 10:54:07 -0800594 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/zlib
595 $(Q)cp third_party/zlib/libz.a $(LIBDIR)/$(CONFIG)/zlib
nnoble69ac39f2014-12-12 15:43:38 -0800596
Craig Tiller61b910f2015-02-15 10:54:07 -0800597$(LIBDIR)/$(CONFIG)/openssl/libssl.a:
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800598 $(E) "[MAKE] Building openssl for $(SYSTEM)"
599ifeq ($(SYSTEM),Darwin)
Nicolas Noblef8681182015-03-18 14:25:44 -0700600 $(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 -0800601else
Nicolas Noblef8681182015-03-18 14:25:44 -0700602ifeq ($(SYSTEM),MINGW32)
603 @echo "We currently don't have a good way to compile OpenSSL in-place under msys."
604 @echo "Please provide an ALPN-capable OpenSSL in your mingw32 system."
605 @echo
606 @echo "Note that you can find a compatible version of the libraries here:"
607 @echo
608 @echo "http://slproweb.com/products/Win32OpenSSL.html"
609 @echo
610 @echo "If you decide to install that one, take the full version. The light"
611 @echo "version only contains compiled DLLs, without the development files."
612 @echo
613 @echo "When installing, chose to copy the OpenSSL dlls to the OpenSSL binaries"
614 @echo "directory. This way we'll link to them directly."
615 @echo
616 @echo "You can then re-start the build the following way:"
617 @echo
618 @echo " CPPFLAGS=-I/c/OpenSSL-Win64/include LDFLAGS=-L/c/OpenSSL-Win64 make"
619 @false
620else
621 $(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./config no-asm $(OPENSSL_CONFIG_$(CONFIG)))
622endif
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800623endif
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100624 $(Q)$(MAKE) -C third_party/openssl clean
625 $(Q)$(MAKE) -C third_party/openssl build_crypto build_ssl
Craig Tiller61b910f2015-02-15 10:54:07 -0800626 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/openssl
627 $(Q)cp third_party/openssl/libssl.a third_party/openssl/libcrypto.a $(LIBDIR)/$(CONFIG)/openssl
nnoble69ac39f2014-12-12 15:43:38 -0800628
Nicolas Noble53830622015-02-12 16:56:38 -0800629third_party/protobuf/configure:
630 $(E) "[AUTOGEN] Preparing protobuf"
631 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
632
Craig Tiller61b910f2015-02-15 10:54:07 -0800633$(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
Nicolas Noble53830622015-02-12 16:56:38 -0800634 $(E) "[MAKE] Building protobuf"
Craig Tillercf133f42015-02-26 14:05:56 -0800635ifeq ($(HAVE_CXX11),true)
Nicolas Noblef8681182015-03-18 14:25:44 -0700636 $(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g" CXXFLAGS="-DLANG_CXX11 -std=c++11" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g" ./configure --disable-shared --enable-static)
Craig Tillercf133f42015-02-26 14:05:56 -0800637else
Nicolas Noblef8681182015-03-18 14:25:44 -0700638 $(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g" CXXFLAGS="-std=c++0x" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g" ./configure --disable-shared --enable-static)
Craig Tillercf133f42015-02-26 14:05:56 -0800639endif
Nicolas Noble53830622015-02-12 16:56:38 -0800640 $(Q)$(MAKE) -C third_party/protobuf clean
641 $(Q)$(MAKE) -C third_party/protobuf
Craig Tiller61b910f2015-02-15 10:54:07 -0800642 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
643 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
644 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
645 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
646 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800647
nnoble29e1d292014-12-01 10:27:40 -0800648static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800649
Craig Tiller12c82092015-01-15 08:45:56 -0800650static_c: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800651% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800652% if lib.build == 'all' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800653 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800654% endif
655% endfor
656
657
Craig Tiller12c82092015-01-15 08:45:56 -0800658static_cxx: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800659% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800660% if lib.build == 'all' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800661 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
nnoble29e1d292014-12-01 10:27:40 -0800662% endif
663% endfor
664
665
666shared: shared_c shared_cxx
667
Craig Tiller12c82092015-01-15 08:45:56 -0800668shared_c: \
nnoble29e1d292014-12-01 10:27:40 -0800669% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800670% if lib.build == 'all' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800671 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800672% endif
673% endfor
674
675
Craig Tiller12c82092015-01-15 08:45:56 -0800676shared_cxx: \
nnoble29e1d292014-12-01 10:27:40 -0800677% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800678% if lib.build == 'all' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800679 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
nnoble29e1d292014-12-01 10:27:40 -0800680% endif
681% endfor
682
683
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800684shared_csharp: shared_c \
685% for lib in libs:
686% if lib.build == 'all' and lib.language == 'csharp':
687 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
688% endif
689% endfor
690
691grpc_csharp_ext: shared_csharp
692
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100693plugins: $(PROTOC_PLUGINS)
694
nnoble29e1d292014-12-01 10:27:40 -0800695privatelibs: privatelibs_c privatelibs_cxx
696
Craig Tiller12c82092015-01-15 08:45:56 -0800697privatelibs_c: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800698% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800699% if lib.build == 'private' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800700 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800701% endif
702% endfor
703
704
Craig Tiller12c82092015-01-15 08:45:56 -0800705privatelibs_cxx: \
nnoble29e1d292014-12-01 10:27:40 -0800706% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800707% if lib.build == 'private' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800708 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800709% endif
710% endfor
711
712
nnoble29e1d292014-12-01 10:27:40 -0800713buildtests: buildtests_c buildtests_cxx
714
Craig Tiller12c82092015-01-15 08:45:56 -0800715buildtests_c: privatelibs_c\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800716% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800717% if tgt.build == 'test' and not tgt.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800718 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800719% endif
720% endfor
721
722
Craig Tiller12c82092015-01-15 08:45:56 -0800723buildtests_cxx: privatelibs_cxx\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800724% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800725% if tgt.build == 'test' and tgt.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800726 $(BINDIR)/$(CONFIG)/${tgt.name}\
nnoble29e1d292014-12-01 10:27:40 -0800727% endif
728% endfor
729
730
nnoble85a49262014-12-08 18:14:03 -0800731test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -0800732
nnoble85a49262014-12-08 18:14:03 -0800733test_c: buildtests_c
nnoble29e1d292014-12-01 10:27:40 -0800734% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800735% if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++':
nnoble29e1d292014-12-01 10:27:40 -0800736 $(E) "[RUN] Testing ${tgt.name}"
Craig Tillerda224d62015-02-15 11:01:58 -0800737 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
nnoble29e1d292014-12-01 10:27:40 -0800738% endif
739% endfor
740
741
nnoble85a49262014-12-08 18:14:03 -0800742test_cxx: buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -0800743% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800744% if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++':
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800745 $(E) "[RUN] Testing ${tgt.name}"
Craig Tillerda224d62015-02-15 11:01:58 -0800746 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800747% endif
748% endfor
749
750
Nicolas "Pixel" Noble051a28f2015-03-17 22:54:54 +0100751test_python: static_c
752 $(E) "[RUN] Testing python code"
753 $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
754
755
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800756tools: privatelibs\
757% for tgt in targets:
758% if tgt.build == 'tool':
Craig Tiller61b910f2015-02-15 10:54:07 -0800759 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800760% endif
761% endfor
762
763
764buildbenchmarks: privatelibs\
765% for tgt in targets:
766% if tgt.build == 'benchmark':
Craig Tiller61b910f2015-02-15 10:54:07 -0800767 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800768% endif
769% endfor
770
771
772benchmarks: buildbenchmarks
773
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800774strip: strip-static strip-shared
775
nnoble20e2e3f2014-12-16 15:37:57 -0800776strip-static: strip-static_c strip-static_cxx
777
778strip-shared: strip-shared_c strip-shared_cxx
779
Nicolas Noble047b7272015-01-16 13:55:05 -0800780
781# TODO(nnoble): the strip target is stripping in-place, instead
782# of copying files in a temporary folder.
783# This prevents proper debugging after running make install.
784
nnoble85a49262014-12-08 18:14:03 -0800785strip-static_c: static_c
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100786ifeq ($(CONFIG),opt)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800787% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800788% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800789% if lib.build == "all":
790 $(E) "[STRIP] Stripping lib${lib.name}.a"
Craig Tiller61b910f2015-02-15 10:54:07 -0800791 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800792% endif
nnoble85a49262014-12-08 18:14:03 -0800793% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800794% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100795endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800796
nnoble85a49262014-12-08 18:14:03 -0800797strip-static_cxx: static_cxx
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100798ifeq ($(CONFIG),opt)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800799% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800800% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800801% if lib.build == "all":
802 $(E) "[STRIP] Stripping lib${lib.name}.a"
Craig Tiller61b910f2015-02-15 10:54:07 -0800803 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
nnoble85a49262014-12-08 18:14:03 -0800804% endif
805% endif
806% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100807endif
nnoble85a49262014-12-08 18:14:03 -0800808
809strip-shared_c: shared_c
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100810ifeq ($(CONFIG),opt)
nnoble85a49262014-12-08 18:14:03 -0800811% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800812% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800813% if lib.build == "all":
814 $(E) "[STRIP] Stripping lib${lib.name}.so"
Craig Tiller61b910f2015-02-15 10:54:07 -0800815 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800816% endif
nnoble85a49262014-12-08 18:14:03 -0800817% endif
818% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100819endif
nnoble85a49262014-12-08 18:14:03 -0800820
821strip-shared_cxx: shared_cxx
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100822ifeq ($(CONFIG),opt)
nnoble85a49262014-12-08 18:14:03 -0800823% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800824% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800825% if lib.build == "all":
826 $(E) "[STRIP] Stripping lib${lib.name}.so"
Craig Tiller61b910f2015-02-15 10:54:07 -0800827 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
nnoble85a49262014-12-08 18:14:03 -0800828% endif
829% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800830% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100831endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800832
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800833strip-shared_csharp: shared_csharp
834ifeq ($(CONFIG),opt)
835% for lib in libs:
836% if lib.language == "csharp":
837% if lib.build == "all":
838 $(E) "[STRIP] Stripping lib${lib.name}.so"
839 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
840% endif
841% endif
842% endfor
843endif
844
nnoble72309c62014-12-12 11:42:26 -0800845% for p in protos:
Nicolas Noble53830622015-02-12 16:56:38 -0800846ifeq ($(NO_PROTOC),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800847$(GENDIR)/${p}.pb.cc: protoc_dep_error
Nicolas "Pixel" Noble0caebbf2015-04-09 23:08:51 +0200848$(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800849else
Craig Tiller61b910f2015-02-15 10:54:07 -0800850$(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800851 $(E) "[PROTOC] Generating protobuf CC file from $<"
852 $(Q) mkdir -p `dirname $@`
Nicolas "Pixel" Noble0caebbf2015-04-09 23:08:51 +0200853 $(Q) $(PROTOC) --cpp_out=$(GENDIR) $<
854
855$(GENDIR)/${p}.grpc.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
856 $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
857 $(Q) mkdir -p `dirname $@`
858 $(Q) $(PROTOC) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $<
Nicolas Noble53830622015-02-12 16:56:38 -0800859endif
nnoble72309c62014-12-12 11:42:26 -0800860
861% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800862
Craig Tiller61b910f2015-02-15 10:54:07 -0800863$(OBJDIR)/$(CONFIG)/%.o : %.c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800864 $(E) "[C] Compiling $<"
865 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800866 $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800867
Craig Tiller61b910f2015-02-15 10:54:07 -0800868$(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800869 $(E) "[CXX] Compiling $<"
870 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800871 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800872
Craig Tiller61b910f2015-02-15 10:54:07 -0800873$(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
nnoble72309c62014-12-12 11:42:26 -0800874 $(E) "[HOSTCXX] Compiling $<"
875 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800876 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -0800877
Craig Tiller61b910f2015-02-15 10:54:07 -0800878$(OBJDIR)/$(CONFIG)/%.o : %.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800879 $(E) "[CXX] Compiling $<"
880 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800881 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800882
883
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +0100884install: install_c install_cxx install-plugins install-certs verify-install
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800885
nnoble85a49262014-12-08 18:14:03 -0800886install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800887
nnoble85a49262014-12-08 18:14:03 -0800888install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
889
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800890install_csharp: install-shared_csharp install_c
891
892install_grpc_csharp_ext: install_csharp
893
nnoble85a49262014-12-08 18:14:03 -0800894install-headers: install-headers_c install-headers_cxx
895
896install-headers_c:
897 $(E) "[INSTALL] Installing public C headers"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100898 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -0800899 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
900
901install-headers_cxx:
902 $(E) "[INSTALL] Installing public C++ headers"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100903 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -0800904 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
905
906install-static: install-static_c install-static_cxx
907
908install-static_c: static_c strip-static_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800909% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800910% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800911% if lib.build == "all":
912 $(E) "[INSTALL] Installing lib${lib.name}.a"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100913 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800914 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800915% endif
nnoble85a49262014-12-08 18:14:03 -0800916% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800917% endfor
918
nnoble85a49262014-12-08 18:14:03 -0800919install-static_cxx: static_cxx strip-static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800920% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800921% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800922% if lib.build == "all":
923 $(E) "[INSTALL] Installing lib${lib.name}.a"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100924 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800925 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
nnoble85a49262014-12-08 18:14:03 -0800926% endif
927% endif
928% endfor
929
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100930<%def name="install_shared(lang_filter)">\
nnoble85a49262014-12-08 18:14:03 -0800931% for lib in libs:
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100932% if lib.language == lang_filter:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800933% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -0800934ifeq ($(SYSTEM),MINGW32)
935 $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100936 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800937 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT)
938 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
nnoble5b7f32a2014-12-22 08:12:44 -0800939else
940 $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100941 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800942 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT)
Masood Malekghassemid1be74f2015-04-07 16:23:09 -0700943ifneq ($(SYSTEM),Darwin)
Tim Emiola820e3d62015-04-10 09:11:50 -0700944 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so.${settings.version.major}
nnoble5b7f32a2014-12-22 08:12:44 -0800945 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
946endif
947endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800948% endif
nnoble85a49262014-12-08 18:14:03 -0800949% endif
950% endfor
nnoble5b7f32a2014-12-22 08:12:44 -0800951ifneq ($(SYSTEM),MINGW32)
952ifneq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblecc2b42a2015-02-20 00:42:21 +0100953 $(Q) ldconfig || true
nnoble5b7f32a2014-12-22 08:12:44 -0800954endif
955endif
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100956</%def>
nnoble85a49262014-12-08 18:14:03 -0800957
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100958install-shared_c: shared_c strip-shared_c
959${install_shared("c")}
960
961install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c
962${install_shared("c++")}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800963
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800964install-shared_csharp: shared_csharp strip-shared_csharp
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100965${install_shared("csharp")}
966
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100967install-plugins: $(PROTOC_PLUGINS)
968ifeq ($(SYSTEM),MINGW32)
969 $(Q) false
970else
971 $(E) "[INSTALL] Installing grpc protoc plugins"
972% for tgt in targets:
973% if tgt.build == 'protoc':
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100974 $(Q) $(INSTALL) -d $(prefix)/bin
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100975 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
976% endif
977% endfor
978endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800979
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +0100980install-certs: etc/roots.pem
981 $(E) "[INSTALL] Installing root certificates"
982 $(Q) $(INSTALL) -d $(prefix)/share/grpc
983 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
984
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100985verify-install:
Nicolas "Pixel" Noble2c23a722015-02-24 20:17:45 +0100986ifeq ($(INSTALL_OK),true)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100987 @echo "Your system looks ready to go."
988 @echo
989else
murgatroid99b6181362015-03-02 14:32:25 -0800990 @echo "We couldn't find protoc 3.0.0+ installed on your system. While this"
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100991 @echo "won't prevent grpc from working, you won't be able to compile"
992 @echo "and run any meaningful code with it."
993 @echo
994 @echo
995 @echo "Please download and install protobuf 3.0.0+ from:"
996 @echo
997 @echo " https://github.com/google/protobuf/releases"
998 @echo
murgatroid99b6181362015-03-02 14:32:25 -0800999 @echo "Once you've done so, or if you think this message is in error,"
1000 @echo "you can re-run this check by doing:"
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +01001001 @echo
1002 @echo " make verify-install"
1003endif
1004
Craig Tiller3759e6f2015-01-15 08:13:11 -08001005clean:
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +01001006 $(E) "[CLEAN] Cleaning build directories."
Craig Tillerda224d62015-02-15 11:01:58 -08001007 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001008
1009
1010# The various libraries
1011
1012% for lib in libs:
1013${makelib(lib)}
1014% endfor
1015
1016
nnoble69ac39f2014-12-12 15:43:38 -08001017# All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001018
1019% for tgt in targets:
1020${maketarget(tgt)}
1021% endfor
1022
1023<%def name="makelib(lib)">
1024LIB${lib.name.upper()}_SRC = \\
1025
1026% for src in lib.src:
nnoble72309c62014-12-12 11:42:26 -08001027 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001028
1029% endfor
1030
1031% if "public_headers" in lib:
Craig Tiller59140fc2015-01-18 10:12:17 -08001032% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -08001033PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001034
nnoble85a49262014-12-08 18:14:03 -08001035% else:
1036PUBLIC_HEADERS_C += \\
1037
1038% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001039% for hdr in lib.public_headers:
1040 ${hdr} \\
1041
1042% endfor
1043% endif
1044
Craig Tiller61b910f2015-02-15 10:54:07 -08001045LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001046
Nicolas Noble047b7272015-01-16 13:55:05 -08001047## If the library requires OpenSSL with ALPN, let's add some restrictions.
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001048% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001049ifeq ($(NO_SECURE),true)
1050
Nicolas Noble047b7272015-01-16 13:55:05 -08001051# You can't build secure libraries if you don't have OpenSSL with ALPN.
1052
Craig Tiller61b910f2015-02-15 10:54:07 -08001053$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001054
nnoble5b7f32a2014-12-22 08:12:44 -08001055% if lib.build == "all":
1056ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -08001057$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -08001058else
Craig Tiller61b910f2015-02-15 10:54:07 -08001059$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -08001060endif
1061% endif
1062
nnoble69ac39f2014-12-12 15:43:38 -08001063else
1064
Nicolas Noble53830622015-02-12 16:56:38 -08001065% if lib.language == 'c++':
1066ifeq ($(NO_PROTOBUF),true)
1067
1068# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
1069
Craig Tiller61b910f2015-02-15 10:54:07 -08001070$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001071
1072% if lib.build == "all":
1073ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -08001074$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001075else
Craig Tiller61b910f2015-02-15 10:54:07 -08001076$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001077endif
1078% endif
1079
1080else
1081% endif
1082
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +01001083ifneq ($(OPENSSL_DEP),)
Nicolas Noble53830622015-02-12 16:56:38 -08001084# This is to ensure the embedded OpenSSL is built beforehand, properly
1085# installing headers to their final destination on the drive. We need this
1086# otherwise parallel compilation will fail if a source is compiled first.
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +01001087% for src in lib.src:
1088${src}: $(OPENSSL_DEP)
1089% endfor
1090endif
1091
Craig Tiller61b910f2015-02-15 10:54:07 -08001092$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
Nicolas Noble047b7272015-01-16 13:55:05 -08001093## The else here corresponds to the if secure earlier.
nnoble20e2e3f2014-12-16 15:37:57 -08001094% else:
Nicolas Noble53830622015-02-12 16:56:38 -08001095% if lib.language == 'c++':
1096ifeq ($(NO_PROTOBUF),true)
1097
1098# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
1099
Craig Tiller61b910f2015-02-15 10:54:07 -08001100$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001101
1102% if lib.build == "all":
1103ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -08001104$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001105else
Craig Tiller61b910f2015-02-15 10:54:07 -08001106$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001107endif
nnoble20e2e3f2014-12-16 15:37:57 -08001108% endif
Nicolas Noble53830622015-02-12 16:56:38 -08001109
1110else
1111
1112% endif
Craig Tiller61b910f2015-02-15 10:54:07 -08001113$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP)\
Nicolas Noble53830622015-02-12 16:56:38 -08001114% endif
1115% if lib.language == 'c++':
1116 $(PROTOBUF_DEP)\
1117% endif
1118 $(LIB${lib.name.upper()}_OBJS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001119 $(E) "[AR] Creating $@"
nnoble85a49262014-12-08 18:14:03 -08001120 $(Q) mkdir -p `dirname $@`
Craig Tiller61b910f2015-02-15 10:54:07 -08001121 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1122 $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
nnoble20e2e3f2014-12-16 15:37:57 -08001123% if lib.get('baselib', False):
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001124% if lib.get('secure', 'check') == 'yes':
Craig Tiller7ab4fee2015-02-24 08:15:53 -08001125 $(Q) rm -rf tmp-merge-${lib.name}
1126 $(Q) mkdir tmp-merge-${lib.name}
1127 $(Q) ( cd tmp-merge-${lib.name} ; $(AR) x ../$(LIBDIR)/$(CONFIG)/lib${lib.name}.a )
1128 $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge-${lib.name} ; <%text>ar x ../$${l}</%text> ) ; done
1129 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/__.SYMDEF*
1130 $(Q) ar rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/*
1131 $(Q) rm -rf tmp-merge-${lib.name}
nnoble20e2e3f2014-12-16 15:37:57 -08001132% endif
1133% endif
Craig Tillerb4ee3b52015-01-21 16:22:50 -08001134ifeq ($(SYSTEM),Darwin)
murgatroid99b6181362015-03-02 14:32:25 -08001135 $(Q) ranlib $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tillerb4ee3b52015-01-21 16:22:50 -08001136endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001137
nnoble5b7f32a2014-12-22 08:12:44 -08001138<%
Craig Tiller59140fc2015-01-18 10:12:17 -08001139 if lib.language == 'c++':
nnoble5b7f32a2014-12-22 08:12:44 -08001140 ld = '$(LDXX)'
1141 else:
1142 ld = '$(LD)'
1143
Craig Tillerda224d62015-02-15 11:01:58 -08001144 out_base = '$(LIBDIR)/$(CONFIG)/' + lib.name
1145 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name
nnoble5b7f32a2014-12-22 08:12:44 -08001146
1147 common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
1148
1149 libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +01001150 lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -08001151 mingw_libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +01001152 mingw_lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -08001153 for dep in lib.get('deps', []):
1154 libs = libs + ' -l' + dep
Craig Tiller61b910f2015-02-15 10:54:07 -08001155 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001156 mingw_libs = mingw_libs + ' -l' + dep + '-imp'
Craig Tillerda224d62015-02-15 11:01:58 -08001157 mingw_lib_deps = mingw_lib_deps + '$(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001158
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001159 if lib.get('secure', 'check') == 'yes':
nnoble5b7f32a2014-12-22 08:12:44 -08001160 common = common + ' $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS)'
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001161
1162 if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble5b7f32a2014-12-22 08:12:44 -08001163 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1164 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001165
1166 if lib.language == 'c++':
1167 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
nnoble5b7f32a2014-12-22 08:12:44 -08001168%>
1169
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001170% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -08001171ifeq ($(SYSTEM),MINGW32)
1172${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001173 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -08001174 $(Q) mkdir -p `dirname $@`
Craig Tillerda224d62015-02-15 11:01:58 -08001175 $(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 -08001176else
1177${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
1178 $(E) "[LD] Linking $@"
1179 $(Q) mkdir -p `dirname $@`
1180ifeq ($(SYSTEM),Darwin)
Masood Malekghassemid1be74f2015-04-07 16:23:09 -07001181 $(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 -08001182else
Craig Tillerda224d62015-02-15 11:01:58 -08001183 $(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 +01001184 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major}
nnoble5b7f32a2014-12-22 08:12:44 -08001185 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so
1186endif
1187endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001188% endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001189% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
Nicolas Noble047b7272015-01-16 13:55:05 -08001190## If the lib was secure, we have to close the Makefile's if that tested
1191## the presence of an ALPN-capable OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001192
1193endif
1194% endif
1195% if lib.language == 'c++':
1196## If the lib was C++, we have to close the Makefile's if that tested
1197## the presence of protobuf 3.0.0+
nnoble69ac39f2014-12-12 15:43:38 -08001198
1199endif
1200% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001201
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001202% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001203ifneq ($(NO_SECURE),true)
1204% endif
1205ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -08001206-include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001207endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001208% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001209endif
1210% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001211
Craig Tiller27715ca2015-01-12 16:55:59 -08001212% for src in lib.src:
1213% if not proto_re.match(src):
Craig Tiller61b910f2015-02-15 10:54:07 -08001214$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
Craig Tiller27715ca2015-01-12 16:55:59 -08001215% for src2 in lib.src:
1216% if proto_re.match(src2):
1217 ${proto_to_cc(src2)}\
1218% endif
1219% endfor
1220% endif
1221
1222% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001223</%def>
1224
1225<%def name="maketarget(tgt)">
1226${tgt.name.upper()}_SRC = \\
1227
1228% for src in tgt.src:
nnoble72309c62014-12-12 11:42:26 -08001229 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001230
1231% endfor
1232
Craig Tiller61b910f2015-02-15 10:54:07 -08001233${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001234
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001235% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001236ifeq ($(NO_SECURE),true)
1237
Nicolas Noble047b7272015-01-16 13:55:05 -08001238# You can't build secure targets if you don't have OpenSSL with ALPN.
1239
Craig Tiller61b910f2015-02-15 10:54:07 -08001240$(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001241
1242else
1243
1244% endif
Nicolas Noble047b7272015-01-16 13:55:05 -08001245##
1246## We're not trying to add a dependency on building zlib and openssl here,
1247## as it's already done in the libraries. We're assuming that the build
1248## trickles down, and that a secure target requires a secure version of
1249## a library.
1250##
1251## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1252## I can live with that.
1253##
Nicolas "Pixel" Noble18953e32015-02-27 02:41:11 +01001254% if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001255
1256ifeq ($(NO_PROTOBUF),true)
1257
Nicolas "Pixel" Noble18953e32015-02-27 02:41:11 +01001258# 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 -08001259
Craig Tiller61b910f2015-02-15 10:54:07 -08001260$(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001261
1262else
1263
Craig Tiller61b910f2015-02-15 10:54:07 -08001264$(BINDIR)/$(CONFIG)/${tgt.name}: $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
Nicolas Noble53830622015-02-12 16:56:38 -08001265% else:
Craig Tiller61b910f2015-02-15 10:54:07 -08001266$(BINDIR)/$(CONFIG)/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
Nicolas Noble53830622015-02-12 16:56:38 -08001267% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001268% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001269 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001270% endfor
1271
Craig Tiller59140fc2015-01-18 10:12:17 -08001272% if tgt.language == "c++":
Nicolas Noble047b7272015-01-16 13:55:05 -08001273## C++ targets specificies.
nnoble72309c62014-12-12 11:42:26 -08001274% if tgt.build == 'protoc':
1275 $(E) "[HOSTLD] Linking $@"
1276 $(Q) mkdir -p `dirname $@`
1277 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(${tgt.name.upper()}_OBJS)\
1278% else:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001279 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -08001280 $(Q) mkdir -p `dirname $@`
nnoblec78b3402014-12-11 16:06:57 -08001281 $(Q) $(LDXX) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
nnoble72309c62014-12-12 11:42:26 -08001282% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001283% else:
Nicolas Noble047b7272015-01-16 13:55:05 -08001284## C-only targets specificities.
nnoble72309c62014-12-12 11:42:26 -08001285 $(E) "[LD] Linking $@"
1286 $(Q) mkdir -p `dirname $@`
nnoble5b7f32a2014-12-22 08:12:44 -08001287 $(Q) $(LD) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001288% endif
1289% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001290 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001291% endfor
Craig Tiller59140fc2015-01-18 10:12:17 -08001292% if tgt.language == "c++":
nnoble72309c62014-12-12 11:42:26 -08001293% if tgt.build == 'protoc':
Nicolas Noble53830622015-02-12 16:56:38 -08001294 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
nnoble72309c62014-12-12 11:42:26 -08001295% else:
Nicolas Noble53830622015-02-12 16:56:38 -08001296 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001297% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001298% endif
nnoblec78b3402014-12-11 16:06:57 -08001299% if tgt.build == 'protoc':
nnoble72309c62014-12-12 11:42:26 -08001300 $(HOST_LDLIBS)\
1301% else:
1302 $(LDLIBS)\
1303% endif
1304% if tgt.build == 'protoc':
1305 $(HOST_LDLIBS_PROTOC)\
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001306% elif tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble72309c62014-12-12 11:42:26 -08001307 $(LDLIBS_SECURE)\
nnoblec78b3402014-12-11 16:06:57 -08001308% endif
Yang Gaob0b518e2015-04-13 14:53:25 -07001309% if tgt.language == 'c++' and tgt.build == 'test':
1310 $(GTEST_LIB)\
1311% endif
Craig Tiller61b910f2015-02-15 10:54:07 -08001312 -o $(BINDIR)/$(CONFIG)/${tgt.name}
Nicolas "Pixel" Noble18953e32015-02-27 02:41:11 +01001313% if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001314
1315endif
1316% endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001317% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001318
1319endif
1320% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001321
Craig Tillerf5371ef2015-01-12 16:40:18 -08001322% for src in tgt.src:
Craig Tiller61b910f2015-02-15 10:54:07 -08001323$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
Craig Tillerf5371ef2015-01-12 16:40:18 -08001324% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001325 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Craig Tillerf5371ef2015-01-12 16:40:18 -08001326% endfor
1327
1328% endfor
1329
Craig Tiller8f126a62015-01-15 08:50:19 -08001330deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001331
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001332% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001333ifneq ($(NO_SECURE),true)
1334% endif
1335ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -08001336-include $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001337endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001338% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001339endif
1340% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001341</%def>
1342
nnoble85a49262014-12-08 18:14:03 -08001343.PHONY: all strip tools \
nnoble69ac39f2014-12-12 15:43:38 -08001344dep_error openssl_dep_error openssl_dep_message git_update stop \
nnoble85a49262014-12-08 18:14:03 -08001345buildtests buildtests_c buildtests_cxx \
1346test test_c test_cxx \
1347install install_c install_cxx \
1348install-headers install-headers_c install-headers_cxx \
1349install-shared install-shared_c install-shared_cxx \
1350install-static install-static_c install-static_cxx \
1351strip strip-shared strip-static \
1352strip_c strip-shared_c strip-static_c \
1353strip_cxx strip-shared_cxx strip-static_cxx \
Craig Tillerf0afe502015-01-15 09:04:49 -08001354dep_c dep_cxx bins_dep_c bins_dep_cxx \
Craig Tiller12c82092015-01-15 08:45:56 -08001355clean