blob: 36d11425df425345314173e4860080cf1b3f61f0 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001# GRPC global makefile
2# This currently builds C and C++ code.
Craig Tiller3b935482015-02-16 12:15:48 -08003
Craig Tillerd7f33352015-02-20 15:18:45 -08004# Copyright 2015, Google Inc.
Craig Tiller3b935482015-02-16 12:15:48 -08005# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are
9# met:
10#
11# * Redistributions of source code must retain the above copyright
12# notice, this list of conditions and the following disclaimer.
13# * Redistributions in binary form must reproduce the above
14# copyright notice, this list of conditions and the following disclaimer
15# in the documentation and/or other materials provided with the
16# distribution.
17# * Neither the name of Google Inc. nor the names of its
18# contributors may be used to endorse or promote products derived from
19# this software without specific prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080032<%!
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080033 import re
Craig Tillerf5371ef2015-01-12 16:40:18 -080034 import os
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080035
nnoblec87b1c52015-01-05 17:15:18 -080036 proto_re = re.compile('(.*)\\.proto')
nnoble72309c62014-12-12 11:42:26 -080037
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080038 def excluded(filename, exclude_res):
39 for r in exclude_res:
40 if r.match(filename):
41 return True
42 return False
nnoble72309c62014-12-12 11:42:26 -080043
44 def proto_to_cc(filename):
45 m = proto_re.match(filename)
46 if not m:
47 return filename
Craig Tillerda224d62015-02-15 11:01:58 -080048 return '$(GENDIR)/' + m.group(1) + '.pb.cc'
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080049%>
50
Craig Tiller96b49552015-01-21 16:29:01 -080051
52# Basic platform detection
53HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
54ifeq ($(SYSTEM),)
55SYSTEM = $(HOST_SYSTEM)
56endif
Nicolas Noblef8681182015-03-18 14:25:44 -070057ifeq ($(SYSTEM),MSYS)
58SYSTEM = MINGW32
59endif
Craig Tiller96b49552015-01-21 16:29:01 -080060
61
Craig Tiller61b910f2015-02-15 10:54:07 -080062ifndef BUILDDIR
63BUILDDIR = .
64endif
65
Nicolas Noblef8681182015-03-18 14:25:44 -070066HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false)
67HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false)
68HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false)
69
70ifeq ($(HAS_CC),true)
71DEFAULT_CC = cc
72DEFAULT_CXX = c++
73else
74ifeq ($(HAS_GCC),true)
75DEFAULT_CC = gcc
76DEFAULT_CXX = g++
77else
78ifeq ($(HAS_CLANG),true)
79DEFAULT_CC = clang
80DEFAULT_CXX = clang++
81else
82DEFAULT_CC = no_c_compiler
83DEFAULT_CXX = no_c++_compiler
84endif
85endif
86endif
87
88
Craig Tiller61b910f2015-02-15 10:54:07 -080089BINDIR = $(BUILDDIR)/bins
90OBJDIR = $(BUILDDIR)/objs
91LIBDIR = $(BUILDDIR)/libs
92GENDIR = $(BUILDDIR)/gens
93
ctiller8cfebb92015-01-06 15:02:12 -080094# Configurations
95
96VALID_CONFIG_opt = 1
Nicolas Noblef8681182015-03-18 14:25:44 -070097CC_opt = $(DEFAULT_CC)
98CXX_opt = $(DEFAULT_CXX)
99LD_opt = $(DEFAULT_CC)
100LDXX_opt = $(DEFAULT_CXX)
ctiller8cfebb92015-01-06 15:02:12 -0800101CPPFLAGS_opt = -O2
102LDFLAGS_opt =
103DEFINES_opt = NDEBUG
104
105VALID_CONFIG_dbg = 1
Nicolas Noblef8681182015-03-18 14:25:44 -0700106CC_dbg = $(DEFAULT_CC)
107CXX_dbg = $(DEFAULT_CXX)
108LD_dbg = $(DEFAULT_CC)
109LDXX_dbg = $(DEFAULT_CXX)
ctiller8cfebb92015-01-06 15:02:12 -0800110CPPFLAGS_dbg = -O0
111LDFLAGS_dbg =
112DEFINES_dbg = _DEBUG DEBUG
113
Craig Tillerec0b8f32015-01-15 07:30:00 -0800114VALID_CONFIG_valgrind = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800115REQUIRE_CUSTOM_LIBRARIES_valgrind = 1
Nicolas Noblef8681182015-03-18 14:25:44 -0700116CC_valgrind = $(DEFAULT_CC)
117CXX_valgrind = $(DEFAULT_CXX)
118LD_valgrind = $(DEFAULT_CC)
119LDXX_valgrind = $(DEFAULT_CXX)
Craig Tillerec0b8f32015-01-15 07:30:00 -0800120CPPFLAGS_valgrind = -O0
121OPENSSL_CFLAGS_valgrind = -DPURIFY
122LDFLAGS_valgrind =
Craig Tillerf6901be2015-02-27 09:12:58 -0800123DEFINES_valgrind = _DEBUG DEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20
Craig Tillerec0b8f32015-01-15 07:30:00 -0800124
ctiller8cfebb92015-01-06 15:02:12 -0800125VALID_CONFIG_tsan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800126REQUIRE_CUSTOM_LIBRARIES_tsan = 1
ctiller8cfebb92015-01-06 15:02:12 -0800127CC_tsan = clang
128CXX_tsan = clang++
129LD_tsan = clang
130LDXX_tsan = clang++
131CPPFLAGS_tsan = -O1 -fsanitize=thread -fno-omit-frame-pointer
132LDFLAGS_tsan = -fsanitize=thread
Craig Tillerf6901be2015-02-27 09:12:58 -0800133DEFINES_tsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10
ctiller8cfebb92015-01-06 15:02:12 -0800134
135VALID_CONFIG_asan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800136REQUIRE_CUSTOM_LIBRARIES_asan = 1
ctiller8cfebb92015-01-06 15:02:12 -0800137CC_asan = clang
138CXX_asan = clang++
139LD_asan = clang
140LDXX_asan = clang++
141CPPFLAGS_asan = -O1 -fsanitize=address -fno-omit-frame-pointer
142LDFLAGS_asan = -fsanitize=address
Craig Tillerf6901be2015-02-27 09:12:58 -0800143DEFINES_asan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5
ctiller8cfebb92015-01-06 15:02:12 -0800144
145VALID_CONFIG_msan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800146REQUIRE_CUSTOM_LIBRARIES_msan = 1
ctiller8cfebb92015-01-06 15:02:12 -0800147CC_msan = clang
Nicolas "Pixel" Nobled66cba22015-02-14 02:59:12 +0100148CXX_msan = clang++-libc++
ctiller8cfebb92015-01-06 15:02:12 -0800149LD_msan = clang
Nicolas "Pixel" Nobled66cba22015-02-14 02:59:12 +0100150LDXX_msan = clang++-libc++
Craig Tilleracd62292015-02-16 11:12:28 -0800151CPPFLAGS_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 -0800152OPENSSL_CFLAGS_msan = -DPURIFY
Nicolas "Pixel" Nobled66cba22015-02-14 02:59:12 +0100153LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
Craig Tillerf6901be2015-02-27 09:12:58 -0800154DEFINES_msan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20
ctiller8cfebb92015-01-06 15:02:12 -0800155
Craig Tiller96bd5f62015-02-13 09:04:13 -0800156VALID_CONFIG_ubsan = 1
157REQUIRE_CUSTOM_LIBRARIES_ubsan = 1
158CC_ubsan = clang
159CXX_ubsan = clang++
160LD_ubsan = clang
161LDXX_ubsan = clang++
162CPPFLAGS_ubsan = -O1 -fsanitize=undefined -fno-omit-frame-pointer
163OPENSSL_CFLAGS_ubsan = -DPURIFY
Craig Tiller96bd5f62015-02-13 09:04:13 -0800164LDFLAGS_ubsan = -fsanitize=undefined
Craig Tillerf6901be2015-02-27 09:12:58 -0800165DEFINES_ubsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10
Craig Tiller96bd5f62015-02-13 09:04:13 -0800166
Craig Tiller699ba212015-01-13 17:02:20 -0800167VALID_CONFIG_gcov = 1
168CC_gcov = gcc
169CXX_gcov = g++
170LD_gcov = gcc
171LDXX_gcov = g++
172CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage
173LDFLAGS_gcov = -fprofile-arcs -ftest-coverage
174DEFINES_gcov = NDEBUG
175
Nicolas Noble047b7272015-01-16 13:55:05 -0800176
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800177# General settings.
178# You may want to change these depending on your system.
179
180prefix ?= /usr/local
181
182PROTOC = protoc
yangg102e4fe2015-01-06 16:02:50 -0800183CONFIG ?= opt
ctiller8cfebb92015-01-06 15:02:12 -0800184CC = $(CC_$(CONFIG))
185CXX = $(CXX_$(CONFIG))
186LD = $(LD_$(CONFIG))
187LDXX = $(LDXX_$(CONFIG))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800188AR = ar
Nicolas "Pixel" Nobled7631a42015-02-27 07:52:39 +0100189ifeq ($(SYSTEM),Linux)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800190STRIP = strip --strip-unneeded
Nicolas "Pixel" Nobled7631a42015-02-27 07:52:39 +0100191else
192ifeq ($(SYSTEM),Darwin)
193STRIP = strip -x
194else
195STRIP = strip
196endif
197endif
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100198INSTALL = install
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800199RM = rm -f
200
yangg102e4fe2015-01-06 16:02:50 -0800201ifndef VALID_CONFIG_$(CONFIG)
202$(error Invalid CONFIG value '$(CONFIG)')
203endif
204
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100205ifeq ($(SYSTEM),Linux)
206TMPOUT = /dev/null
207else
208TMPOUT = `mktemp /tmp/test-out-XXXXXX`
209endif
Nicolas Noble047b7272015-01-16 13:55:05 -0800210
Craig Tillercf133f42015-02-26 14:05:56 -0800211# Detect if we can use C++11
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100212CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc
Craig Tillercf133f42015-02-26 14:05:56 -0800213HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false)
214
Nicolas Noble047b7272015-01-16 13:55:05 -0800215# The HOST compiler settings are used to compile the protoc plugins.
216# In most cases, you won't have to change anything, but if you are
217# cross-compiling, you can override these variables from GNU make's
218# command line: make CC=cross-gcc HOST_CC=gcc
219
nnoble72309c62014-12-12 11:42:26 -0800220HOST_CC = $(CC)
221HOST_CXX = $(CXX)
222HOST_LD = $(LD)
223HOST_LDXX = $(LDXX)
224
ctillercab52e72015-01-06 13:10:23 -0800225CPPFLAGS += $(CPPFLAGS_$(CONFIG))
Nicolas "Pixel" Noble72743822015-02-20 20:59:29 +0100226DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
ctiller8cfebb92015-01-06 15:02:12 -0800227LDFLAGS += $(LDFLAGS_$(CONFIG))
ctillercab52e72015-01-06 13:10:23 -0800228
Craig Tiller86fa1c52015-02-27 09:57:58 -0800229ifdef EXTRA_DEFINES
Craig Tillerf5065c52015-02-27 16:17:39 -0800230DEFINES += $(EXTRA_DEFINES)
Craig Tiller86fa1c52015-02-27 09:57:58 -0800231endif
232
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800233CFLAGS += -std=c89 -pedantic
Craig Tillercf133f42015-02-26 14:05:56 -0800234ifeq ($(HAS_CXX11),true)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800235CXXFLAGS += -std=c++11
Craig Tillercf133f42015-02-26 14:05:56 -0800236else
237CXXFLAGS += -std=c++0x
238DEFINES += GRPC_OLD_CXX
239endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700240CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
241LDFLAGS += -g
242
243ifneq ($(SYSTEM),MINGW32)
244PIC_CPPFLAGS = -fPIC
245CPPFLAGS += -fPIC
246LDFLAGS += -fPIC
247endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800248
Craig Tillerda224d62015-02-15 11:01:58 -0800249INCLUDES = . include $(GENDIR)
Craig Tiller96b49552015-01-21 16:29:01 -0800250ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100251ifneq ($(wildcard /usr/local/ssl/include),)
252INCLUDES += /usr/local/ssl/include
253endif
254ifneq ($(wildcard /opt/local/include),)
255INCLUDES += /opt/local/include
256endif
257ifneq ($(wildcard /usr/local/include),)
258INCLUDES += /usr/local/include
259endif
Craig Tiller96b49552015-01-21 16:29:01 -0800260LIBS = m z
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100261ifneq ($(wildcard /usr/local/ssl/lib),)
262LDFLAGS += -L/usr/local/ssl/lib
263endif
264ifneq ($(wildcard /opt/local/lib),)
265LDFLAGS += -L/opt/local/lib
266endif
267ifneq ($(wildcard /usr/local/lib),)
268LDFLAGS += -L/usr/local/lib
269endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700270endif
271
272ifeq ($(SYSTEM),Linux)
ctillerc008ae52015-01-07 15:33:00 -0800273LIBS = rt m z pthread
Craig Tiller96b49552015-01-21 16:29:01 -0800274LDFLAGS += -pthread
275endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800276
Nicolas Noblef8681182015-03-18 14:25:44 -0700277ifeq ($(SYSTEM),MINGW32)
278LIBS = m z pthread
279LDFLAGS += -pthread
280endif
281
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800282ifneq ($(wildcard /usr/src/gtest/src/gtest-all.cc),)
283GTEST_LIB = /usr/src/gtest/src/gtest-all.cc -I/usr/src/gtest
284else
285GTEST_LIB = -lgtest
286endif
chenwa8fd44a2014-12-10 15:13:55 -0800287GTEST_LIB += -lgflags
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800288ifeq ($(V),1)
289E = @:
290Q =
291else
292E = @echo
293Q = @
294endif
295
296VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build}
297
298CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
299CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
300
301LDFLAGS += $(ARCH_FLAGS)
302LDLIBS += $(addprefix -l, $(LIBS))
303LDLIBSXX += $(addprefix -l, $(LIBSXX))
nnoble72309c62014-12-12 11:42:26 -0800304
305HOST_CPPFLAGS = $(CPPFLAGS)
306HOST_CFLAGS = $(CFLAGS)
307HOST_CXXFLAGS = $(CXXFLAGS)
308HOST_LDFLAGS = $(LDFLAGS)
309HOST_LDLIBS = $(LDLIBS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800310
nnoble69ac39f2014-12-12 15:43:38 -0800311
312# These are automatically computed variables.
313# There shouldn't be any need to change anything from now on.
314
nnoble5b7f32a2014-12-22 08:12:44 -0800315ifeq ($(SYSTEM),MINGW32)
316SHARED_EXT = dll
317endif
318ifeq ($(SYSTEM),Darwin)
319SHARED_EXT = dylib
320endif
321ifeq ($(SHARED_EXT),)
322SHARED_EXT = so.$(VERSION)
323endif
324
nnoble69ac39f2014-12-12 15:43:38 -0800325ifeq ($(wildcard .git),)
326IS_GIT_FOLDER = false
327else
328IS_GIT_FOLDER = true
329endif
330
Nicolas Noblef8681182015-03-18 14:25:44 -0700331ifeq ($(SYSTEM),Linux)
332OPENSSL_REQUIRES_DL = true
333endif
334
335ifeq ($(SYSTEM),Darwin)
336OPENSSL_REQUIRES_DL = true
337endif
338
339ifeq ($(SYSTEM),MINGW32)
340OPENSSL_LIBS = ssl32 eay32
341else
342OPENSSL_LIBS = ssl crypto
343endif
344
345OPENSSL_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 +0100346ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
347PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
348PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
Nicolas Noblef8681182015-03-18 14:25:44 -0700349PROTOC_CMD = which protoc > /dev/null
Nicolas Noble53830622015-02-12 16:56:38 -0800350PROTOC_CHECK_CMD = protoc --version | grep -q libprotoc.3
Craig Tiller297fafa2015-01-15 15:46:39 -0800351
Nicolas Noblef8681182015-03-18 14:25:44 -0700352ifeq ($(OPENSSL_REQUIRES_DL),true)
353OPENSSL_ALPN_CHECK_CMD += -ldl
354endif
355
Craig Tiller50524cc2015-01-29 23:00:00 -0800356ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
Craig Tiller297fafa2015-01-15 15:46:39 -0800357HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
358ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
359DEFINES += GRPC_HAVE_PERFTOOLS
360LIBS += profiler
361endif
Craig Tiller50524cc2015-01-29 23:00:00 -0800362endif
nnoble69ac39f2014-12-12 15:43:38 -0800363
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100364HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
Craig Tillerc4da6b72015-01-15 08:01:14 -0800365ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
nnoble60825402014-12-15 14:43:51 -0800366HAS_SYSTEM_OPENSSL_ALPN = $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
367HAS_SYSTEM_ZLIB = $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100368HAS_SYSTEM_PROTOBUF = $(HAS_SYSTEM_PROTOBUF_VERIFY)
Craig Tillerc4da6b72015-01-15 08:01:14 -0800369else
370# override system libraries if the config requires a custom compiled library
371HAS_SYSTEM_OPENSSL_ALPN = false
372HAS_SYSTEM_ZLIB = false
Nicolas Noble53830622015-02-12 16:56:38 -0800373HAS_SYSTEM_PROTOBUF = false
Craig Tillerc4da6b72015-01-15 08:01:14 -0800374endif
nnoble69ac39f2014-12-12 15:43:38 -0800375
Nicolas Noblef8681182015-03-18 14:25:44 -0700376HAS_PROTOC = $(shell $(PROTOC_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100377ifeq ($(HAS_PROTOC),true)
Nicolas Noble53830622015-02-12 16:56:38 -0800378HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100379else
380HAS_VALID_PROTOC = false
381endif
Nicolas Noble53830622015-02-12 16:56:38 -0800382
nnoble69ac39f2014-12-12 15:43:38 -0800383ifeq ($(wildcard third_party/openssl/ssl/ssl.h),)
384HAS_EMBEDDED_OPENSSL_ALPN = false
385else
386HAS_EMBEDDED_OPENSSL_ALPN = true
387endif
388
389ifeq ($(wildcard third_party/zlib/zlib.h),)
390HAS_EMBEDDED_ZLIB = false
391else
392HAS_EMBEDDED_ZLIB = true
393endif
394
Nicolas Noble53830622015-02-12 16:56:38 -0800395ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
396HAS_EMBEDDED_PROTOBUF = false
397ifneq ($(HAS_VALID_PROTOC),true)
398NO_PROTOC = true
399endif
400else
401HAS_EMBEDDED_PROTOBUF = true
402endif
403
nnoble69ac39f2014-12-12 15:43:38 -0800404ifeq ($(HAS_SYSTEM_ZLIB),false)
405ifeq ($(HAS_EMBEDDED_ZLIB),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800406ZLIB_DEP = $(LIBDIR)/$(CONFIG)/zlib/libz.a
nnoble69ac39f2014-12-12 15:43:38 -0800407CPPFLAGS += -Ithird_party/zlib
Craig Tillerda224d62015-02-15 11:01:58 -0800408LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib
nnoble69ac39f2014-12-12 15:43:38 -0800409else
410DEP_MISSING += zlib
411endif
412endif
413
414ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false)
415ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800416OPENSSL_DEP = $(LIBDIR)/$(CONFIG)/openssl/libssl.a
417OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/openssl/libssl.a $(LIBDIR)/$(CONFIG)/openssl/libcrypto.a
Craig Tillerec043032015-02-20 17:24:41 -0800418# need to prefix these to ensure overriding system libraries
419CPPFLAGS := -Ithird_party/openssl/include $(CPPFLAGS)
420LDFLAGS := -L$(LIBDIR)/$(CONFIG)/openssl $(LDFLAGS)
Nicolas Noblef8681182015-03-18 14:25:44 -0700421ifeq ($(OPENSSL_REQUIRES_DL),true)
nnoble5b7f32a2014-12-22 08:12:44 -0800422LIBS_SECURE = dl
Nicolas Noblef8681182015-03-18 14:25:44 -0700423endif
nnoble69ac39f2014-12-12 15:43:38 -0800424else
425NO_SECURE = true
426endif
nnoble5b7f32a2014-12-22 08:12:44 -0800427else
Nicolas Noblef8681182015-03-18 14:25:44 -0700428LIBS_SECURE = $(OPENSSL_LIBS)
429ifeq ($(OPENSSL_REQUIRES_DL),true)
430LIBS_SECURE += dl
431endif
nnoble69ac39f2014-12-12 15:43:38 -0800432endif
433
nnoble5b7f32a2014-12-22 08:12:44 -0800434LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
435
Nicolas Noble53830622015-02-12 16:56:38 -0800436ifeq ($(HAS_SYSTEM_PROTOBUF),false)
437ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800438PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
Craig Tiller9ec95fa2015-02-20 20:36:21 -0800439CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
440LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
Craig Tiller61b910f2015-02-15 10:54:07 -0800441PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
Nicolas Noble53830622015-02-12 16:56:38 -0800442else
443NO_PROTOBUF = true
444endif
445else
446endif
447
448LIBS_PROTOBUF = protobuf
449LIBS_PROTOC = protoc protobuf
450
451LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
452HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
453
Craig Tiller12c82092015-01-15 08:45:56 -0800454ifeq ($(MAKECMDGOALS),clean)
nnoble69ac39f2014-12-12 15:43:38 -0800455NO_DEPS = true
456endif
457
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100458INSTALL_OK = false
459ifeq ($(HAS_VALID_PROTOC),true)
460ifeq ($(HAS_SYSTEM_PROTOBUF_VERIFY),true)
461INSTALL_OK = true
462endif
463endif
464
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800465.SECONDARY = %.pb.h %.pb.cc
466
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100467PROTOC_PLUGINS =\
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800468% for tgt in targets:
469% if tgt.build == 'protoc':
Craig Tiller61b910f2015-02-15 10:54:07 -0800470 $(BINDIR)/$(CONFIG)/${tgt.name}\
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800471% endif
472% endfor
473
nnoble69ac39f2014-12-12 15:43:38 -0800474ifeq ($(DEP_MISSING),)
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100475all: static shared plugins\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800476% for tgt in targets:
477% if tgt.build == 'all':
Craig Tiller61b910f2015-02-15 10:54:07 -0800478 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800479% endif
480% endfor
481
nnoble69ac39f2014-12-12 15:43:38 -0800482dep_error:
483 @echo "You shouldn't see this message - all of your dependencies are correct."
484else
485all: dep_error git_update stop
486
487dep_error:
488 @echo
489 @echo "DEPENDENCY ERROR"
490 @echo
491 @echo "You are missing system dependencies that are essential to build grpc,"
492 @echo "and the third_party directory doesn't have them:"
493 @echo
494 @echo " $(DEP_MISSING)"
495 @echo
496 @echo "Installing the development packages for your system will solve"
497 @echo "this issue. Please consult INSTALL to get more information."
498 @echo
499 @echo "If you need information about why these tests failed, run:"
500 @echo
501 @echo " make run_dep_checks"
502 @echo
503endif
504
505git_update:
506ifeq ($(IS_GIT_FOLDER),true)
507 @echo "Additionally, since you are in a git clone, you can download the"
508 @echo "missing dependencies in third_party by running the following command:"
509 @echo
ctiller64f29102014-12-15 10:40:59 -0800510 @echo " git submodule update --init"
nnoble69ac39f2014-12-12 15:43:38 -0800511 @echo
512endif
513
514openssl_dep_error: openssl_dep_message git_update stop
515
Nicolas Noble53830622015-02-12 16:56:38 -0800516protobuf_dep_error: protobuf_dep_message git_update stop
517
518protoc_dep_error: protoc_dep_message git_update stop
519
nnoble69ac39f2014-12-12 15:43:38 -0800520openssl_dep_message:
521 @echo
522 @echo "DEPENDENCY ERROR"
523 @echo
524 @echo "The target you are trying to run requires OpenSSL with ALPN support."
525 @echo "Your system doesn't have it, and neither does the third_party directory."
526 @echo
527 @echo "Please consult INSTALL to get more information."
528 @echo
529 @echo "If you need information about why these tests failed, run:"
530 @echo
531 @echo " make run_dep_checks"
532 @echo
533
Nicolas Noble53830622015-02-12 16:56:38 -0800534protobuf_dep_message:
535 @echo
536 @echo "DEPENDENCY ERROR"
537 @echo
538 @echo "The target you are trying to run requires protobuf 3.0.0+"
539 @echo "Your system doesn't have it, and neither does the third_party directory."
540 @echo
541 @echo "Please consult INSTALL to get more information."
542 @echo
543 @echo "If you need information about why these tests failed, run:"
544 @echo
545 @echo " make run_dep_checks"
546 @echo
547
548protoc_dep_message:
549 @echo
550 @echo "DEPENDENCY ERROR"
551 @echo
552 @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
553 @echo "Your system doesn't have it, and neither does the third_party directory."
554 @echo
555 @echo "Please consult INSTALL to get more information."
556 @echo
557 @echo "If you need information about why these tests failed, run:"
558 @echo
559 @echo " make run_dep_checks"
560 @echo
561
nnoble69ac39f2014-12-12 15:43:38 -0800562stop:
563 @false
564
ctiller09cb6d52014-12-19 17:38:22 -0800565% for tgt in targets:
Craig Tiller61b910f2015-02-15 10:54:07 -0800566${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
ctiller09cb6d52014-12-19 17:38:22 -0800567% endfor
568
nnoble69ac39f2014-12-12 15:43:38 -0800569run_dep_checks:
nnoble69ac39f2014-12-12 15:43:38 -0800570 $(OPENSSL_ALPN_CHECK_CMD) || true
571 $(ZLIB_CHECK_CMD) || true
Nicolas Noble53830622015-02-12 16:56:38 -0800572 $(PERFTOOLS_CHECK_CMD) || true
573 $(PROTOBUF_CHECK_CMD) || true
574 $(PROTOC_CHECK_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800575
Craig Tiller61b910f2015-02-15 10:54:07 -0800576$(LIBDIR)/$(CONFIG)/zlib/libz.a:
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100577 $(E) "[MAKE] Building zlib"
Nicolas Noblef8681182015-03-18 14:25:44 -0700578 $(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="$(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG))" ./configure --static)
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100579 $(Q)$(MAKE) -C third_party/zlib clean
580 $(Q)$(MAKE) -C third_party/zlib
Craig Tiller61b910f2015-02-15 10:54:07 -0800581 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/zlib
582 $(Q)cp third_party/zlib/libz.a $(LIBDIR)/$(CONFIG)/zlib
nnoble69ac39f2014-12-12 15:43:38 -0800583
Craig Tiller61b910f2015-02-15 10:54:07 -0800584$(LIBDIR)/$(CONFIG)/openssl/libssl.a:
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800585 $(E) "[MAKE] Building openssl for $(SYSTEM)"
586ifeq ($(SYSTEM),Darwin)
Nicolas Noblef8681182015-03-18 14:25:44 -0700587 $(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 -0800588else
Nicolas Noblef8681182015-03-18 14:25:44 -0700589ifeq ($(SYSTEM),MINGW32)
590 @echo "We currently don't have a good way to compile OpenSSL in-place under msys."
591 @echo "Please provide an ALPN-capable OpenSSL in your mingw32 system."
592 @echo
593 @echo "Note that you can find a compatible version of the libraries here:"
594 @echo
595 @echo "http://slproweb.com/products/Win32OpenSSL.html"
596 @echo
597 @echo "If you decide to install that one, take the full version. The light"
598 @echo "version only contains compiled DLLs, without the development files."
599 @echo
600 @echo "When installing, chose to copy the OpenSSL dlls to the OpenSSL binaries"
601 @echo "directory. This way we'll link to them directly."
602 @echo
603 @echo "You can then re-start the build the following way:"
604 @echo
605 @echo " CPPFLAGS=-I/c/OpenSSL-Win64/include LDFLAGS=-L/c/OpenSSL-Win64 make"
606 @false
607else
608 $(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./config no-asm $(OPENSSL_CONFIG_$(CONFIG)))
609endif
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800610endif
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100611 $(Q)$(MAKE) -C third_party/openssl clean
612 $(Q)$(MAKE) -C third_party/openssl build_crypto build_ssl
Craig Tiller61b910f2015-02-15 10:54:07 -0800613 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/openssl
614 $(Q)cp third_party/openssl/libssl.a third_party/openssl/libcrypto.a $(LIBDIR)/$(CONFIG)/openssl
nnoble69ac39f2014-12-12 15:43:38 -0800615
Nicolas Noble53830622015-02-12 16:56:38 -0800616third_party/protobuf/configure:
617 $(E) "[AUTOGEN] Preparing protobuf"
618 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
619
Craig Tiller61b910f2015-02-15 10:54:07 -0800620$(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
Nicolas Noble53830622015-02-12 16:56:38 -0800621 $(E) "[MAKE] Building protobuf"
Craig Tillercf133f42015-02-26 14:05:56 -0800622ifeq ($(HAVE_CXX11),true)
Nicolas Noblef8681182015-03-18 14:25:44 -0700623 $(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 -0800624else
Nicolas Noblef8681182015-03-18 14:25:44 -0700625 $(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 -0800626endif
Nicolas Noble53830622015-02-12 16:56:38 -0800627 $(Q)$(MAKE) -C third_party/protobuf clean
628 $(Q)$(MAKE) -C third_party/protobuf
Craig Tiller61b910f2015-02-15 10:54:07 -0800629 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
630 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
631 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
632 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
633 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800634
nnoble29e1d292014-12-01 10:27:40 -0800635static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800636
Craig Tiller12c82092015-01-15 08:45:56 -0800637static_c: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800638% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800639% if lib.build == 'all' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800640 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800641% endif
642% endfor
643
644
Craig Tiller12c82092015-01-15 08:45:56 -0800645static_cxx: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800646% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800647% if lib.build == 'all' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800648 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
nnoble29e1d292014-12-01 10:27:40 -0800649% endif
650% endfor
651
652
653shared: shared_c shared_cxx
654
Craig Tiller12c82092015-01-15 08:45:56 -0800655shared_c: \
nnoble29e1d292014-12-01 10:27:40 -0800656% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800657% if lib.build == 'all' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800658 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800659% endif
660% endfor
661
662
Craig Tiller12c82092015-01-15 08:45:56 -0800663shared_cxx: \
nnoble29e1d292014-12-01 10:27:40 -0800664% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800665% if lib.build == 'all' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800666 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
nnoble29e1d292014-12-01 10:27:40 -0800667% endif
668% endfor
669
670
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800671shared_csharp: shared_c \
672% for lib in libs:
673% if lib.build == 'all' and lib.language == 'csharp':
674 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
675% endif
676% endfor
677
678grpc_csharp_ext: shared_csharp
679
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100680plugins: $(PROTOC_PLUGINS)
681
nnoble29e1d292014-12-01 10:27:40 -0800682privatelibs: privatelibs_c privatelibs_cxx
683
Craig Tiller12c82092015-01-15 08:45:56 -0800684privatelibs_c: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800685% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800686% if lib.build == 'private' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800687 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800688% endif
689% endfor
690
691
Craig Tiller12c82092015-01-15 08:45:56 -0800692privatelibs_cxx: \
nnoble29e1d292014-12-01 10:27:40 -0800693% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800694% if lib.build == 'private' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800695 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800696% endif
697% endfor
698
699
nnoble29e1d292014-12-01 10:27:40 -0800700buildtests: buildtests_c buildtests_cxx
701
Craig Tiller12c82092015-01-15 08:45:56 -0800702buildtests_c: privatelibs_c\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800703% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800704% if tgt.build == 'test' and not tgt.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800705 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800706% endif
707% endfor
708
709
Craig Tiller12c82092015-01-15 08:45:56 -0800710buildtests_cxx: privatelibs_cxx\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800711% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800712% if tgt.build == 'test' and tgt.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800713 $(BINDIR)/$(CONFIG)/${tgt.name}\
nnoble29e1d292014-12-01 10:27:40 -0800714% endif
715% endfor
716
717
nnoble85a49262014-12-08 18:14:03 -0800718test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -0800719
nnoble85a49262014-12-08 18:14:03 -0800720test_c: buildtests_c
nnoble29e1d292014-12-01 10:27:40 -0800721% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800722% if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++':
nnoble29e1d292014-12-01 10:27:40 -0800723 $(E) "[RUN] Testing ${tgt.name}"
Craig Tillerda224d62015-02-15 11:01:58 -0800724 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
nnoble29e1d292014-12-01 10:27:40 -0800725% endif
726% endfor
727
728
nnoble85a49262014-12-08 18:14:03 -0800729test_cxx: buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -0800730% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800731% if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++':
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800732 $(E) "[RUN] Testing ${tgt.name}"
Craig Tillerda224d62015-02-15 11:01:58 -0800733 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800734% endif
735% endfor
736
737
Nicolas "Pixel" Noble051a28f2015-03-17 22:54:54 +0100738test_python: static_c
739 $(E) "[RUN] Testing python code"
740 $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
741
742
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800743tools: privatelibs\
744% for tgt in targets:
745% if tgt.build == 'tool':
Craig Tiller61b910f2015-02-15 10:54:07 -0800746 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800747% endif
748% endfor
749
750
751buildbenchmarks: privatelibs\
752% for tgt in targets:
753% if tgt.build == 'benchmark':
Craig Tiller61b910f2015-02-15 10:54:07 -0800754 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800755% endif
756% endfor
757
758
759benchmarks: buildbenchmarks
760
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800761strip: strip-static strip-shared
762
nnoble20e2e3f2014-12-16 15:37:57 -0800763strip-static: strip-static_c strip-static_cxx
764
765strip-shared: strip-shared_c strip-shared_cxx
766
Nicolas Noble047b7272015-01-16 13:55:05 -0800767
768# TODO(nnoble): the strip target is stripping in-place, instead
769# of copying files in a temporary folder.
770# This prevents proper debugging after running make install.
771
nnoble85a49262014-12-08 18:14:03 -0800772strip-static_c: static_c
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100773ifeq ($(CONFIG),opt)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800774% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800775% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800776% if lib.build == "all":
777 $(E) "[STRIP] Stripping lib${lib.name}.a"
Craig Tiller61b910f2015-02-15 10:54:07 -0800778 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800779% endif
nnoble85a49262014-12-08 18:14:03 -0800780% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800781% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100782endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800783
nnoble85a49262014-12-08 18:14:03 -0800784strip-static_cxx: static_cxx
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100785ifeq ($(CONFIG),opt)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800786% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800787% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800788% if lib.build == "all":
789 $(E) "[STRIP] Stripping lib${lib.name}.a"
Craig Tiller61b910f2015-02-15 10:54:07 -0800790 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
nnoble85a49262014-12-08 18:14:03 -0800791% endif
792% endif
793% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100794endif
nnoble85a49262014-12-08 18:14:03 -0800795
796strip-shared_c: shared_c
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100797ifeq ($(CONFIG),opt)
nnoble85a49262014-12-08 18:14:03 -0800798% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800799% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800800% if lib.build == "all":
801 $(E) "[STRIP] Stripping lib${lib.name}.so"
Craig Tiller61b910f2015-02-15 10:54:07 -0800802 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800803% endif
nnoble85a49262014-12-08 18:14:03 -0800804% endif
805% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100806endif
nnoble85a49262014-12-08 18:14:03 -0800807
808strip-shared_cxx: shared_cxx
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100809ifeq ($(CONFIG),opt)
nnoble85a49262014-12-08 18:14:03 -0800810% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800811% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800812% if lib.build == "all":
813 $(E) "[STRIP] Stripping lib${lib.name}.so"
Craig Tiller61b910f2015-02-15 10:54:07 -0800814 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
nnoble85a49262014-12-08 18:14:03 -0800815% endif
816% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800817% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100818endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800819
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800820strip-shared_csharp: shared_csharp
821ifeq ($(CONFIG),opt)
822% for lib in libs:
823% if lib.language == "csharp":
824% if lib.build == "all":
825 $(E) "[STRIP] Stripping lib${lib.name}.so"
826 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
827% endif
828% endif
829% endfor
830endif
831
nnoble72309c62014-12-12 11:42:26 -0800832% for p in protos:
Nicolas Noble53830622015-02-12 16:56:38 -0800833ifeq ($(NO_PROTOC),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800834$(GENDIR)/${p}.pb.cc: protoc_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800835else
Craig Tiller61b910f2015-02-15 10:54:07 -0800836$(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800837 $(E) "[PROTOC] Generating protobuf CC file from $<"
838 $(Q) mkdir -p `dirname $@`
Vijay Pai850290f2015-02-19 09:59:44 -0800839 $(Q) $(PROTOC) --cpp_out=$(GENDIR) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $<
Nicolas Noble53830622015-02-12 16:56:38 -0800840endif
nnoble72309c62014-12-12 11:42:26 -0800841
842% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800843
Craig Tiller61b910f2015-02-15 10:54:07 -0800844$(OBJDIR)/$(CONFIG)/%.o : %.c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800845 $(E) "[C] Compiling $<"
846 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800847 $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800848
Craig Tiller61b910f2015-02-15 10:54:07 -0800849$(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800850 $(E) "[CXX] Compiling $<"
851 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800852 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800853
Craig Tiller61b910f2015-02-15 10:54:07 -0800854$(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
nnoble72309c62014-12-12 11:42:26 -0800855 $(E) "[HOSTCXX] Compiling $<"
856 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800857 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -0800858
Craig Tiller61b910f2015-02-15 10:54:07 -0800859$(OBJDIR)/$(CONFIG)/%.o : %.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800860 $(E) "[CXX] Compiling $<"
861 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800862 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800863
864
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +0100865install: install_c install_cxx install-plugins install-certs verify-install
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800866
nnoble85a49262014-12-08 18:14:03 -0800867install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800868
nnoble85a49262014-12-08 18:14:03 -0800869install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
870
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800871install_csharp: install-shared_csharp install_c
872
873install_grpc_csharp_ext: install_csharp
874
nnoble85a49262014-12-08 18:14:03 -0800875install-headers: install-headers_c install-headers_cxx
876
877install-headers_c:
878 $(E) "[INSTALL] Installing public C headers"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100879 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -0800880 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
881
882install-headers_cxx:
883 $(E) "[INSTALL] Installing public C++ headers"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100884 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -0800885 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
886
887install-static: install-static_c install-static_cxx
888
889install-static_c: static_c strip-static_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800890% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800891% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800892% if lib.build == "all":
893 $(E) "[INSTALL] Installing lib${lib.name}.a"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100894 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800895 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800896% endif
nnoble85a49262014-12-08 18:14:03 -0800897% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800898% endfor
899
nnoble85a49262014-12-08 18:14:03 -0800900install-static_cxx: static_cxx strip-static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800901% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800902% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800903% if lib.build == "all":
904 $(E) "[INSTALL] Installing lib${lib.name}.a"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100905 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800906 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
nnoble85a49262014-12-08 18:14:03 -0800907% endif
908% endif
909% endfor
910
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100911<%def name="install_shared(lang_filter)">\
nnoble85a49262014-12-08 18:14:03 -0800912% for lib in libs:
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100913% if lib.language == lang_filter:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800914% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -0800915ifeq ($(SYSTEM),MINGW32)
916 $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100917 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800918 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT)
919 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
nnoble5b7f32a2014-12-22 08:12:44 -0800920else
Nicolas "Pixel" Noble716b5fe2015-03-11 22:35:57 +0100921ifneq ($(SYSTEM),Darwin)
nnoble5b7f32a2014-12-22 08:12:44 -0800922 $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100923 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800924 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT)
nnoble5b7f32a2014-12-22 08:12:44 -0800925 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
926endif
927endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800928% endif
nnoble85a49262014-12-08 18:14:03 -0800929% endif
930% endfor
nnoble5b7f32a2014-12-22 08:12:44 -0800931ifneq ($(SYSTEM),MINGW32)
932ifneq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblecc2b42a2015-02-20 00:42:21 +0100933 $(Q) ldconfig || true
nnoble5b7f32a2014-12-22 08:12:44 -0800934endif
935endif
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100936</%def>
nnoble85a49262014-12-08 18:14:03 -0800937
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100938install-shared_c: shared_c strip-shared_c
939${install_shared("c")}
940
941install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c
942${install_shared("c++")}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800943
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800944install-shared_csharp: shared_csharp strip-shared_csharp
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100945${install_shared("csharp")}
946
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100947install-plugins: $(PROTOC_PLUGINS)
948ifeq ($(SYSTEM),MINGW32)
949 $(Q) false
950else
951 $(E) "[INSTALL] Installing grpc protoc plugins"
952% for tgt in targets:
953% if tgt.build == 'protoc':
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100954 $(Q) $(INSTALL) -d $(prefix)/bin
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100955 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
956% endif
957% endfor
958endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800959
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +0100960install-certs: etc/roots.pem
961 $(E) "[INSTALL] Installing root certificates"
962 $(Q) $(INSTALL) -d $(prefix)/share/grpc
963 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
964
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100965verify-install:
Nicolas "Pixel" Noble2c23a722015-02-24 20:17:45 +0100966ifeq ($(INSTALL_OK),true)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100967 @echo "Your system looks ready to go."
968 @echo
969else
murgatroid99b6181362015-03-02 14:32:25 -0800970 @echo "We couldn't find protoc 3.0.0+ installed on your system. While this"
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100971 @echo "won't prevent grpc from working, you won't be able to compile"
972 @echo "and run any meaningful code with it."
973 @echo
974 @echo
975 @echo "Please download and install protobuf 3.0.0+ from:"
976 @echo
977 @echo " https://github.com/google/protobuf/releases"
978 @echo
murgatroid99b6181362015-03-02 14:32:25 -0800979 @echo "Once you've done so, or if you think this message is in error,"
980 @echo "you can re-run this check by doing:"
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100981 @echo
982 @echo " make verify-install"
983endif
984
Craig Tiller3759e6f2015-01-15 08:13:11 -0800985clean:
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100986 $(E) "[CLEAN] Cleaning build directories."
Craig Tillerda224d62015-02-15 11:01:58 -0800987 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800988
989
990# The various libraries
991
992% for lib in libs:
993${makelib(lib)}
994% endfor
995
996
nnoble69ac39f2014-12-12 15:43:38 -0800997# All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800998
999% for tgt in targets:
1000${maketarget(tgt)}
1001% endfor
1002
1003<%def name="makelib(lib)">
1004LIB${lib.name.upper()}_SRC = \\
1005
1006% for src in lib.src:
nnoble72309c62014-12-12 11:42:26 -08001007 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001008
1009% endfor
1010
1011% if "public_headers" in lib:
Craig Tiller59140fc2015-01-18 10:12:17 -08001012% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -08001013PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001014
nnoble85a49262014-12-08 18:14:03 -08001015% else:
1016PUBLIC_HEADERS_C += \\
1017
1018% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001019% for hdr in lib.public_headers:
1020 ${hdr} \\
1021
1022% endfor
1023% endif
1024
Craig Tiller61b910f2015-02-15 10:54:07 -08001025LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001026
Nicolas Noble047b7272015-01-16 13:55:05 -08001027## If the library requires OpenSSL with ALPN, let's add some restrictions.
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001028% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001029ifeq ($(NO_SECURE),true)
1030
Nicolas Noble047b7272015-01-16 13:55:05 -08001031# You can't build secure libraries if you don't have OpenSSL with ALPN.
1032
Craig Tiller61b910f2015-02-15 10:54:07 -08001033$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001034
nnoble5b7f32a2014-12-22 08:12:44 -08001035% if lib.build == "all":
1036ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -08001037$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -08001038else
Craig Tiller61b910f2015-02-15 10:54:07 -08001039$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -08001040endif
1041% endif
1042
nnoble69ac39f2014-12-12 15:43:38 -08001043else
1044
Nicolas Noble53830622015-02-12 16:56:38 -08001045% if lib.language == 'c++':
1046ifeq ($(NO_PROTOBUF),true)
1047
1048# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
1049
Craig Tiller61b910f2015-02-15 10:54:07 -08001050$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001051
1052% if lib.build == "all":
1053ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -08001054$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001055else
Craig Tiller61b910f2015-02-15 10:54:07 -08001056$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001057endif
1058% endif
1059
1060else
1061% endif
1062
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +01001063ifneq ($(OPENSSL_DEP),)
Nicolas Noble53830622015-02-12 16:56:38 -08001064# This is to ensure the embedded OpenSSL is built beforehand, properly
1065# installing headers to their final destination on the drive. We need this
1066# otherwise parallel compilation will fail if a source is compiled first.
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +01001067% for src in lib.src:
1068${src}: $(OPENSSL_DEP)
1069% endfor
1070endif
1071
Craig Tiller61b910f2015-02-15 10:54:07 -08001072$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
Nicolas Noble047b7272015-01-16 13:55:05 -08001073## The else here corresponds to the if secure earlier.
nnoble20e2e3f2014-12-16 15:37:57 -08001074% else:
Nicolas Noble53830622015-02-12 16:56:38 -08001075% if lib.language == 'c++':
1076ifeq ($(NO_PROTOBUF),true)
1077
1078# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
1079
Craig Tiller61b910f2015-02-15 10:54:07 -08001080$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001081
1082% if lib.build == "all":
1083ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -08001084$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001085else
Craig Tiller61b910f2015-02-15 10:54:07 -08001086$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001087endif
nnoble20e2e3f2014-12-16 15:37:57 -08001088% endif
Nicolas Noble53830622015-02-12 16:56:38 -08001089
1090else
1091
1092% endif
Craig Tiller61b910f2015-02-15 10:54:07 -08001093$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP)\
Nicolas Noble53830622015-02-12 16:56:38 -08001094% endif
1095% if lib.language == 'c++':
1096 $(PROTOBUF_DEP)\
1097% endif
1098 $(LIB${lib.name.upper()}_OBJS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001099 $(E) "[AR] Creating $@"
nnoble85a49262014-12-08 18:14:03 -08001100 $(Q) mkdir -p `dirname $@`
Craig Tiller61b910f2015-02-15 10:54:07 -08001101 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1102 $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
nnoble20e2e3f2014-12-16 15:37:57 -08001103% if lib.get('baselib', False):
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001104% if lib.get('secure', 'check') == 'yes':
Craig Tiller7ab4fee2015-02-24 08:15:53 -08001105 $(Q) rm -rf tmp-merge-${lib.name}
1106 $(Q) mkdir tmp-merge-${lib.name}
1107 $(Q) ( cd tmp-merge-${lib.name} ; $(AR) x ../$(LIBDIR)/$(CONFIG)/lib${lib.name}.a )
1108 $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge-${lib.name} ; <%text>ar x ../$${l}</%text> ) ; done
1109 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/__.SYMDEF*
1110 $(Q) ar rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/*
1111 $(Q) rm -rf tmp-merge-${lib.name}
nnoble20e2e3f2014-12-16 15:37:57 -08001112% endif
1113% endif
Craig Tillerb4ee3b52015-01-21 16:22:50 -08001114ifeq ($(SYSTEM),Darwin)
murgatroid99b6181362015-03-02 14:32:25 -08001115 $(Q) ranlib $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tillerb4ee3b52015-01-21 16:22:50 -08001116endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001117
nnoble5b7f32a2014-12-22 08:12:44 -08001118<%
Craig Tiller59140fc2015-01-18 10:12:17 -08001119 if lib.language == 'c++':
nnoble5b7f32a2014-12-22 08:12:44 -08001120 ld = '$(LDXX)'
1121 else:
1122 ld = '$(LD)'
1123
Craig Tillerda224d62015-02-15 11:01:58 -08001124 out_base = '$(LIBDIR)/$(CONFIG)/' + lib.name
1125 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name
nnoble5b7f32a2014-12-22 08:12:44 -08001126
1127 common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
1128
1129 libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +01001130 lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -08001131 mingw_libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +01001132 mingw_lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -08001133 for dep in lib.get('deps', []):
1134 libs = libs + ' -l' + dep
Craig Tiller61b910f2015-02-15 10:54:07 -08001135 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001136 mingw_libs = mingw_libs + ' -l' + dep + '-imp'
Craig Tillerda224d62015-02-15 11:01:58 -08001137 mingw_lib_deps = mingw_lib_deps + '$(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001138
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001139 if lib.get('secure', 'check') == 'yes':
nnoble5b7f32a2014-12-22 08:12:44 -08001140 common = common + ' $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS)'
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001141
1142 if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble5b7f32a2014-12-22 08:12:44 -08001143 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1144 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001145
1146 if lib.language == 'c++':
1147 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
nnoble5b7f32a2014-12-22 08:12:44 -08001148%>
1149
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001150% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -08001151ifeq ($(SYSTEM),MINGW32)
1152${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001153 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -08001154 $(Q) mkdir -p `dirname $@`
Craig Tillerda224d62015-02-15 11:01:58 -08001155 $(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 -08001156else
1157${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
1158 $(E) "[LD] Linking $@"
1159 $(Q) mkdir -p `dirname $@`
1160ifeq ($(SYSTEM),Darwin)
Craig Tillerda224d62015-02-15 11:01:58 -08001161 $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
nnoble5b7f32a2014-12-22 08:12:44 -08001162else
Craig Tillerda224d62015-02-15 11:01:58 -08001163 $(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 +01001164 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major}
nnoble5b7f32a2014-12-22 08:12:44 -08001165 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so
1166endif
1167endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001168% endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001169% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
Nicolas Noble047b7272015-01-16 13:55:05 -08001170## If the lib was secure, we have to close the Makefile's if that tested
1171## the presence of an ALPN-capable OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001172
1173endif
1174% endif
1175% if lib.language == 'c++':
1176## If the lib was C++, we have to close the Makefile's if that tested
1177## the presence of protobuf 3.0.0+
nnoble69ac39f2014-12-12 15:43:38 -08001178
1179endif
1180% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001181
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001182% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001183ifneq ($(NO_SECURE),true)
1184% endif
1185ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -08001186-include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001187endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001188% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001189endif
1190% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001191
Craig Tiller27715ca2015-01-12 16:55:59 -08001192% for src in lib.src:
1193% if not proto_re.match(src):
Craig Tiller61b910f2015-02-15 10:54:07 -08001194$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
Craig Tiller27715ca2015-01-12 16:55:59 -08001195% for src2 in lib.src:
1196% if proto_re.match(src2):
1197 ${proto_to_cc(src2)}\
1198% endif
1199% endfor
1200% endif
1201
1202% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001203</%def>
1204
1205<%def name="maketarget(tgt)">
1206${tgt.name.upper()}_SRC = \\
1207
1208% for src in tgt.src:
nnoble72309c62014-12-12 11:42:26 -08001209 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001210
1211% endfor
1212
Craig Tiller61b910f2015-02-15 10:54:07 -08001213${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001214
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001215% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001216ifeq ($(NO_SECURE),true)
1217
Nicolas Noble047b7272015-01-16 13:55:05 -08001218# You can't build secure targets if you don't have OpenSSL with ALPN.
1219
Craig Tiller61b910f2015-02-15 10:54:07 -08001220$(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001221
1222else
1223
1224% endif
Nicolas Noble047b7272015-01-16 13:55:05 -08001225##
1226## We're not trying to add a dependency on building zlib and openssl here,
1227## as it's already done in the libraries. We're assuming that the build
1228## trickles down, and that a secure target requires a secure version of
1229## a library.
1230##
1231## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1232## I can live with that.
1233##
Nicolas "Pixel" Noble18953e32015-02-27 02:41:11 +01001234% if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001235
1236ifeq ($(NO_PROTOBUF),true)
1237
Nicolas "Pixel" Noble18953e32015-02-27 02:41:11 +01001238# 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 -08001239
Craig Tiller61b910f2015-02-15 10:54:07 -08001240$(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001241
1242else
1243
Craig Tiller61b910f2015-02-15 10:54:07 -08001244$(BINDIR)/$(CONFIG)/${tgt.name}: $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
Nicolas Noble53830622015-02-12 16:56:38 -08001245% else:
Craig Tiller61b910f2015-02-15 10:54:07 -08001246$(BINDIR)/$(CONFIG)/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
Nicolas Noble53830622015-02-12 16:56:38 -08001247% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001248% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001249 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001250% endfor
1251
Craig Tiller59140fc2015-01-18 10:12:17 -08001252% if tgt.language == "c++":
Nicolas Noble047b7272015-01-16 13:55:05 -08001253## C++ targets specificies.
nnoble72309c62014-12-12 11:42:26 -08001254% if tgt.build == 'protoc':
1255 $(E) "[HOSTLD] Linking $@"
1256 $(Q) mkdir -p `dirname $@`
1257 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(${tgt.name.upper()}_OBJS)\
1258% else:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001259 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -08001260 $(Q) mkdir -p `dirname $@`
nnoblec78b3402014-12-11 16:06:57 -08001261 $(Q) $(LDXX) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
nnoble72309c62014-12-12 11:42:26 -08001262% endif
nnoblec78b3402014-12-11 16:06:57 -08001263% if tgt.build == 'test':
1264 $(GTEST_LIB)\
1265% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001266% else:
Nicolas Noble047b7272015-01-16 13:55:05 -08001267## C-only targets specificities.
nnoble72309c62014-12-12 11:42:26 -08001268 $(E) "[LD] Linking $@"
1269 $(Q) mkdir -p `dirname $@`
nnoble5b7f32a2014-12-22 08:12:44 -08001270 $(Q) $(LD) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001271% endif
1272% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001273 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001274% endfor
Craig Tiller59140fc2015-01-18 10:12:17 -08001275% if tgt.language == "c++":
nnoble72309c62014-12-12 11:42:26 -08001276% if tgt.build == 'protoc':
Nicolas Noble53830622015-02-12 16:56:38 -08001277 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
nnoble72309c62014-12-12 11:42:26 -08001278% else:
Nicolas Noble53830622015-02-12 16:56:38 -08001279 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001280% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001281% endif
nnoblec78b3402014-12-11 16:06:57 -08001282% if tgt.build == 'protoc':
nnoble72309c62014-12-12 11:42:26 -08001283 $(HOST_LDLIBS)\
1284% else:
1285 $(LDLIBS)\
1286% endif
1287% if tgt.build == 'protoc':
1288 $(HOST_LDLIBS_PROTOC)\
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001289% elif tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble72309c62014-12-12 11:42:26 -08001290 $(LDLIBS_SECURE)\
nnoblec78b3402014-12-11 16:06:57 -08001291% endif
Craig Tiller61b910f2015-02-15 10:54:07 -08001292 -o $(BINDIR)/$(CONFIG)/${tgt.name}
Nicolas "Pixel" Noble18953e32015-02-27 02:41:11 +01001293% if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001294
1295endif
1296% endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001297% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001298
1299endif
1300% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001301
Craig Tillerf5371ef2015-01-12 16:40:18 -08001302% for src in tgt.src:
Craig Tiller61b910f2015-02-15 10:54:07 -08001303$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
Craig Tillerf5371ef2015-01-12 16:40:18 -08001304% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001305 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Craig Tillerf5371ef2015-01-12 16:40:18 -08001306% endfor
1307
1308% endfor
1309
Craig Tiller8f126a62015-01-15 08:50:19 -08001310deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001311
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001312% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001313ifneq ($(NO_SECURE),true)
1314% endif
1315ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -08001316-include $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001317endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001318% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001319endif
1320% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001321</%def>
1322
nnoble85a49262014-12-08 18:14:03 -08001323.PHONY: all strip tools \
nnoble69ac39f2014-12-12 15:43:38 -08001324dep_error openssl_dep_error openssl_dep_message git_update stop \
nnoble85a49262014-12-08 18:14:03 -08001325buildtests buildtests_c buildtests_cxx \
1326test test_c test_cxx \
1327install install_c install_cxx \
1328install-headers install-headers_c install-headers_cxx \
1329install-shared install-shared_c install-shared_cxx \
1330install-static install-static_c install-static_cxx \
1331strip strip-shared strip-static \
1332strip_c strip-shared_c strip-static_c \
1333strip_cxx strip-shared_cxx strip-static_cxx \
Craig Tillerf0afe502015-01-15 09:04:49 -08001334dep_c dep_cxx bins_dep_c bins_dep_cxx \
Craig Tiller12c82092015-01-15 08:45:56 -08001335clean