blob: a69c7a7f2f1cf6689d34665c9a23ac24851af196 [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
57
58
Craig Tiller61b910f2015-02-15 10:54:07 -080059ifndef BUILDDIR
60BUILDDIR = .
61endif
62
63BINDIR = $(BUILDDIR)/bins
64OBJDIR = $(BUILDDIR)/objs
65LIBDIR = $(BUILDDIR)/libs
66GENDIR = $(BUILDDIR)/gens
67
ctiller8cfebb92015-01-06 15:02:12 -080068# Configurations
69
70VALID_CONFIG_opt = 1
71CC_opt = gcc
72CXX_opt = g++
73LD_opt = gcc
74LDXX_opt = g++
75CPPFLAGS_opt = -O2
76LDFLAGS_opt =
77DEFINES_opt = NDEBUG
78
79VALID_CONFIG_dbg = 1
80CC_dbg = gcc
81CXX_dbg = g++
82LD_dbg = gcc
83LDXX_dbg = g++
84CPPFLAGS_dbg = -O0
85LDFLAGS_dbg =
86DEFINES_dbg = _DEBUG DEBUG
87
Craig Tillerec0b8f32015-01-15 07:30:00 -080088VALID_CONFIG_valgrind = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -080089REQUIRE_CUSTOM_LIBRARIES_valgrind = 1
Craig Tillerec0b8f32015-01-15 07:30:00 -080090CC_valgrind = gcc
91CXX_valgrind = g++
92LD_valgrind = gcc
93LDXX_valgrind = g++
94CPPFLAGS_valgrind = -O0
95OPENSSL_CFLAGS_valgrind = -DPURIFY
96LDFLAGS_valgrind =
Craig Tillerf6901be2015-02-27 09:12:58 -080097DEFINES_valgrind = _DEBUG DEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20
Craig Tillerec0b8f32015-01-15 07:30:00 -080098
ctiller8cfebb92015-01-06 15:02:12 -080099VALID_CONFIG_tsan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800100REQUIRE_CUSTOM_LIBRARIES_tsan = 1
ctiller8cfebb92015-01-06 15:02:12 -0800101CC_tsan = clang
102CXX_tsan = clang++
103LD_tsan = clang
104LDXX_tsan = clang++
105CPPFLAGS_tsan = -O1 -fsanitize=thread -fno-omit-frame-pointer
106LDFLAGS_tsan = -fsanitize=thread
Craig Tillerf6901be2015-02-27 09:12:58 -0800107DEFINES_tsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10
ctiller8cfebb92015-01-06 15:02:12 -0800108
109VALID_CONFIG_asan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800110REQUIRE_CUSTOM_LIBRARIES_asan = 1
ctiller8cfebb92015-01-06 15:02:12 -0800111CC_asan = clang
112CXX_asan = clang++
113LD_asan = clang
114LDXX_asan = clang++
115CPPFLAGS_asan = -O1 -fsanitize=address -fno-omit-frame-pointer
116LDFLAGS_asan = -fsanitize=address
Craig Tillerf6901be2015-02-27 09:12:58 -0800117DEFINES_asan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5
ctiller8cfebb92015-01-06 15:02:12 -0800118
119VALID_CONFIG_msan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800120REQUIRE_CUSTOM_LIBRARIES_msan = 1
ctiller8cfebb92015-01-06 15:02:12 -0800121CC_msan = clang
Nicolas "Pixel" Nobled66cba22015-02-14 02:59:12 +0100122CXX_msan = clang++-libc++
ctiller8cfebb92015-01-06 15:02:12 -0800123LD_msan = clang
Nicolas "Pixel" Nobled66cba22015-02-14 02:59:12 +0100124LDXX_msan = clang++-libc++
Craig Tilleracd62292015-02-16 11:12:28 -0800125CPPFLAGS_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 -0800126OPENSSL_CFLAGS_msan = -DPURIFY
Nicolas "Pixel" Nobled66cba22015-02-14 02:59:12 +0100127LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
Craig Tillerf6901be2015-02-27 09:12:58 -0800128DEFINES_msan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20
ctiller8cfebb92015-01-06 15:02:12 -0800129
Craig Tiller96bd5f62015-02-13 09:04:13 -0800130VALID_CONFIG_ubsan = 1
131REQUIRE_CUSTOM_LIBRARIES_ubsan = 1
132CC_ubsan = clang
133CXX_ubsan = clang++
134LD_ubsan = clang
135LDXX_ubsan = clang++
136CPPFLAGS_ubsan = -O1 -fsanitize=undefined -fno-omit-frame-pointer
137OPENSSL_CFLAGS_ubsan = -DPURIFY
Craig Tiller96bd5f62015-02-13 09:04:13 -0800138LDFLAGS_ubsan = -fsanitize=undefined
Craig Tillerf6901be2015-02-27 09:12:58 -0800139DEFINES_ubsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10
Craig Tiller96bd5f62015-02-13 09:04:13 -0800140
Craig Tiller699ba212015-01-13 17:02:20 -0800141VALID_CONFIG_gcov = 1
142CC_gcov = gcc
143CXX_gcov = g++
144LD_gcov = gcc
145LDXX_gcov = g++
146CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage
147LDFLAGS_gcov = -fprofile-arcs -ftest-coverage
148DEFINES_gcov = NDEBUG
149
Nicolas Noble047b7272015-01-16 13:55:05 -0800150
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800151# General settings.
152# You may want to change these depending on your system.
153
154prefix ?= /usr/local
155
156PROTOC = protoc
yangg102e4fe2015-01-06 16:02:50 -0800157CONFIG ?= opt
ctiller8cfebb92015-01-06 15:02:12 -0800158CC = $(CC_$(CONFIG))
159CXX = $(CXX_$(CONFIG))
160LD = $(LD_$(CONFIG))
161LDXX = $(LDXX_$(CONFIG))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800162AR = ar
Nicolas "Pixel" Nobled7631a42015-02-27 07:52:39 +0100163ifeq ($(SYSTEM),Linux)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800164STRIP = strip --strip-unneeded
Nicolas "Pixel" Nobled7631a42015-02-27 07:52:39 +0100165else
166ifeq ($(SYSTEM),Darwin)
167STRIP = strip -x
168else
169STRIP = strip
170endif
171endif
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100172INSTALL = install
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800173RM = rm -f
174
yangg102e4fe2015-01-06 16:02:50 -0800175ifndef VALID_CONFIG_$(CONFIG)
176$(error Invalid CONFIG value '$(CONFIG)')
177endif
178
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100179ifeq ($(SYSTEM),Linux)
180TMPOUT = /dev/null
181else
182TMPOUT = `mktemp /tmp/test-out-XXXXXX`
183endif
Nicolas Noble047b7272015-01-16 13:55:05 -0800184
Craig Tillercf133f42015-02-26 14:05:56 -0800185# Detect if we can use C++11
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100186CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc
Craig Tillercf133f42015-02-26 14:05:56 -0800187HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false)
188
Nicolas Noble047b7272015-01-16 13:55:05 -0800189# The HOST compiler settings are used to compile the protoc plugins.
190# In most cases, you won't have to change anything, but if you are
191# cross-compiling, you can override these variables from GNU make's
192# command line: make CC=cross-gcc HOST_CC=gcc
193
nnoble72309c62014-12-12 11:42:26 -0800194HOST_CC = $(CC)
195HOST_CXX = $(CXX)
196HOST_LD = $(LD)
197HOST_LDXX = $(LDXX)
198
ctillercab52e72015-01-06 13:10:23 -0800199CPPFLAGS += $(CPPFLAGS_$(CONFIG))
Nicolas "Pixel" Noble72743822015-02-20 20:59:29 +0100200DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
ctiller8cfebb92015-01-06 15:02:12 -0800201LDFLAGS += $(LDFLAGS_$(CONFIG))
ctillercab52e72015-01-06 13:10:23 -0800202
Craig Tiller86fa1c52015-02-27 09:57:58 -0800203ifdef EXTRA_DEFINES
Craig Tillerf5065c52015-02-27 16:17:39 -0800204DEFINES += $(EXTRA_DEFINES)
Craig Tiller86fa1c52015-02-27 09:57:58 -0800205endif
206
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800207CFLAGS += -std=c89 -pedantic
Craig Tillercf133f42015-02-26 14:05:56 -0800208ifeq ($(HAS_CXX11),true)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800209CXXFLAGS += -std=c++11
Craig Tillercf133f42015-02-26 14:05:56 -0800210else
211CXXFLAGS += -std=c++0x
212DEFINES += GRPC_OLD_CXX
213endif
Nicolas "Pixel" Noble213ed912015-01-30 02:11:35 +0100214CPPFLAGS += -g -fPIC -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
Craig Tiller96b49552015-01-21 16:29:01 -0800215LDFLAGS += -g -fPIC
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800216
Craig Tillerda224d62015-02-15 11:01:58 -0800217INCLUDES = . include $(GENDIR)
Craig Tiller96b49552015-01-21 16:29:01 -0800218ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100219ifneq ($(wildcard /usr/local/ssl/include),)
220INCLUDES += /usr/local/ssl/include
221endif
222ifneq ($(wildcard /opt/local/include),)
223INCLUDES += /opt/local/include
224endif
225ifneq ($(wildcard /usr/local/include),)
226INCLUDES += /usr/local/include
227endif
Craig Tiller96b49552015-01-21 16:29:01 -0800228LIBS = m z
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100229ifneq ($(wildcard /usr/local/ssl/lib),)
230LDFLAGS += -L/usr/local/ssl/lib
231endif
232ifneq ($(wildcard /opt/local/lib),)
233LDFLAGS += -L/opt/local/lib
234endif
235ifneq ($(wildcard /usr/local/lib),)
236LDFLAGS += -L/usr/local/lib
237endif
Craig Tiller96b49552015-01-21 16:29:01 -0800238else
ctillerc008ae52015-01-07 15:33:00 -0800239LIBS = rt m z pthread
Craig Tiller96b49552015-01-21 16:29:01 -0800240LDFLAGS += -pthread
241endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800242
243ifneq ($(wildcard /usr/src/gtest/src/gtest-all.cc),)
244GTEST_LIB = /usr/src/gtest/src/gtest-all.cc -I/usr/src/gtest
245else
246GTEST_LIB = -lgtest
247endif
chenwa8fd44a2014-12-10 15:13:55 -0800248GTEST_LIB += -lgflags
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800249ifeq ($(V),1)
250E = @:
251Q =
252else
253E = @echo
254Q = @
255endif
256
257VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build}
258
259CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
260CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
261
262LDFLAGS += $(ARCH_FLAGS)
263LDLIBS += $(addprefix -l, $(LIBS))
264LDLIBSXX += $(addprefix -l, $(LIBSXX))
nnoble72309c62014-12-12 11:42:26 -0800265
266HOST_CPPFLAGS = $(CPPFLAGS)
267HOST_CFLAGS = $(CFLAGS)
268HOST_CXXFLAGS = $(CXXFLAGS)
269HOST_LDFLAGS = $(LDFLAGS)
270HOST_LDLIBS = $(LDLIBS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800271
nnoble69ac39f2014-12-12 15:43:38 -0800272
273# These are automatically computed variables.
274# There shouldn't be any need to change anything from now on.
275
nnoble5b7f32a2014-12-22 08:12:44 -0800276ifeq ($(SYSTEM),MINGW32)
277SHARED_EXT = dll
278endif
279ifeq ($(SYSTEM),Darwin)
280SHARED_EXT = dylib
281endif
282ifeq ($(SHARED_EXT),)
283SHARED_EXT = so.$(VERSION)
284endif
285
nnoble69ac39f2014-12-12 15:43:38 -0800286ifeq ($(wildcard .git),)
287IS_GIT_FOLDER = false
288else
289IS_GIT_FOLDER = true
290endif
291
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100292OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c -lssl -lcrypto -ldl $(LDFLAGS)
293ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
294PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
295PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100296PROTOC_CMD = which protoc
Nicolas Noble53830622015-02-12 16:56:38 -0800297PROTOC_CHECK_CMD = protoc --version | grep -q libprotoc.3
Craig Tiller297fafa2015-01-15 15:46:39 -0800298
Craig Tiller50524cc2015-01-29 23:00:00 -0800299ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
Craig Tiller297fafa2015-01-15 15:46:39 -0800300HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
301ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
302DEFINES += GRPC_HAVE_PERFTOOLS
303LIBS += profiler
304endif
Craig Tiller50524cc2015-01-29 23:00:00 -0800305endif
nnoble69ac39f2014-12-12 15:43:38 -0800306
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100307HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
Craig Tillerc4da6b72015-01-15 08:01:14 -0800308ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
nnoble60825402014-12-15 14:43:51 -0800309HAS_SYSTEM_OPENSSL_ALPN = $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
310HAS_SYSTEM_ZLIB = $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100311HAS_SYSTEM_PROTOBUF = $(HAS_SYSTEM_PROTOBUF_VERIFY)
Craig Tillerc4da6b72015-01-15 08:01:14 -0800312else
313# override system libraries if the config requires a custom compiled library
314HAS_SYSTEM_OPENSSL_ALPN = false
315HAS_SYSTEM_ZLIB = false
Nicolas Noble53830622015-02-12 16:56:38 -0800316HAS_SYSTEM_PROTOBUF = false
Craig Tillerc4da6b72015-01-15 08:01:14 -0800317endif
nnoble69ac39f2014-12-12 15:43:38 -0800318
Yang Gao044fe222015-02-24 12:59:38 -0800319HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100320ifeq ($(HAS_PROTOC),true)
Nicolas Noble53830622015-02-12 16:56:38 -0800321HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100322else
323HAS_VALID_PROTOC = false
324endif
Nicolas Noble53830622015-02-12 16:56:38 -0800325
nnoble69ac39f2014-12-12 15:43:38 -0800326ifeq ($(wildcard third_party/openssl/ssl/ssl.h),)
327HAS_EMBEDDED_OPENSSL_ALPN = false
328else
329HAS_EMBEDDED_OPENSSL_ALPN = true
330endif
331
332ifeq ($(wildcard third_party/zlib/zlib.h),)
333HAS_EMBEDDED_ZLIB = false
334else
335HAS_EMBEDDED_ZLIB = true
336endif
337
Nicolas Noble53830622015-02-12 16:56:38 -0800338ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
339HAS_EMBEDDED_PROTOBUF = false
340ifneq ($(HAS_VALID_PROTOC),true)
341NO_PROTOC = true
342endif
343else
344HAS_EMBEDDED_PROTOBUF = true
345endif
346
nnoble69ac39f2014-12-12 15:43:38 -0800347ifeq ($(HAS_SYSTEM_ZLIB),false)
348ifeq ($(HAS_EMBEDDED_ZLIB),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800349ZLIB_DEP = $(LIBDIR)/$(CONFIG)/zlib/libz.a
nnoble69ac39f2014-12-12 15:43:38 -0800350CPPFLAGS += -Ithird_party/zlib
Craig Tillerda224d62015-02-15 11:01:58 -0800351LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib
nnoble69ac39f2014-12-12 15:43:38 -0800352else
353DEP_MISSING += zlib
354endif
355endif
356
357ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false)
358ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800359OPENSSL_DEP = $(LIBDIR)/$(CONFIG)/openssl/libssl.a
360OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/openssl/libssl.a $(LIBDIR)/$(CONFIG)/openssl/libcrypto.a
Craig Tillerec043032015-02-20 17:24:41 -0800361# need to prefix these to ensure overriding system libraries
362CPPFLAGS := -Ithird_party/openssl/include $(CPPFLAGS)
363LDFLAGS := -L$(LIBDIR)/$(CONFIG)/openssl $(LDFLAGS)
nnoble5b7f32a2014-12-22 08:12:44 -0800364LIBS_SECURE = dl
nnoble69ac39f2014-12-12 15:43:38 -0800365else
366NO_SECURE = true
367endif
nnoble5b7f32a2014-12-22 08:12:44 -0800368else
369LIBS_SECURE = ssl crypto dl
nnoble69ac39f2014-12-12 15:43:38 -0800370endif
371
nnoble5b7f32a2014-12-22 08:12:44 -0800372LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
373
Nicolas Noble53830622015-02-12 16:56:38 -0800374ifeq ($(HAS_SYSTEM_PROTOBUF),false)
375ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800376PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
Craig Tiller9ec95fa2015-02-20 20:36:21 -0800377CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
378LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
Craig Tiller61b910f2015-02-15 10:54:07 -0800379PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
Nicolas Noble53830622015-02-12 16:56:38 -0800380else
381NO_PROTOBUF = true
382endif
383else
384endif
385
386LIBS_PROTOBUF = protobuf
387LIBS_PROTOC = protoc protobuf
388
389LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
390HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
391
Craig Tiller12c82092015-01-15 08:45:56 -0800392ifeq ($(MAKECMDGOALS),clean)
nnoble69ac39f2014-12-12 15:43:38 -0800393NO_DEPS = true
394endif
395
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100396INSTALL_OK = false
397ifeq ($(HAS_VALID_PROTOC),true)
398ifeq ($(HAS_SYSTEM_PROTOBUF_VERIFY),true)
399INSTALL_OK = true
400endif
401endif
402
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800403.SECONDARY = %.pb.h %.pb.cc
404
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100405PROTOC_PLUGINS =\
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800406% for tgt in targets:
407% if tgt.build == 'protoc':
Craig Tiller61b910f2015-02-15 10:54:07 -0800408 $(BINDIR)/$(CONFIG)/${tgt.name}\
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800409% endif
410% endfor
411
nnoble69ac39f2014-12-12 15:43:38 -0800412ifeq ($(DEP_MISSING),)
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100413all: static shared plugins\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800414% for tgt in targets:
415% if tgt.build == 'all':
Craig Tiller61b910f2015-02-15 10:54:07 -0800416 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800417% endif
418% endfor
419
nnoble69ac39f2014-12-12 15:43:38 -0800420dep_error:
421 @echo "You shouldn't see this message - all of your dependencies are correct."
422else
423all: dep_error git_update stop
424
425dep_error:
426 @echo
427 @echo "DEPENDENCY ERROR"
428 @echo
429 @echo "You are missing system dependencies that are essential to build grpc,"
430 @echo "and the third_party directory doesn't have them:"
431 @echo
432 @echo " $(DEP_MISSING)"
433 @echo
434 @echo "Installing the development packages for your system will solve"
435 @echo "this issue. Please consult INSTALL to get more information."
436 @echo
437 @echo "If you need information about why these tests failed, run:"
438 @echo
439 @echo " make run_dep_checks"
440 @echo
441endif
442
443git_update:
444ifeq ($(IS_GIT_FOLDER),true)
445 @echo "Additionally, since you are in a git clone, you can download the"
446 @echo "missing dependencies in third_party by running the following command:"
447 @echo
ctiller64f29102014-12-15 10:40:59 -0800448 @echo " git submodule update --init"
nnoble69ac39f2014-12-12 15:43:38 -0800449 @echo
450endif
451
452openssl_dep_error: openssl_dep_message git_update stop
453
Nicolas Noble53830622015-02-12 16:56:38 -0800454protobuf_dep_error: protobuf_dep_message git_update stop
455
456protoc_dep_error: protoc_dep_message git_update stop
457
nnoble69ac39f2014-12-12 15:43:38 -0800458openssl_dep_message:
459 @echo
460 @echo "DEPENDENCY ERROR"
461 @echo
462 @echo "The target you are trying to run requires OpenSSL with ALPN support."
463 @echo "Your system doesn't have it, and neither does the third_party directory."
464 @echo
465 @echo "Please consult INSTALL to get more information."
466 @echo
467 @echo "If you need information about why these tests failed, run:"
468 @echo
469 @echo " make run_dep_checks"
470 @echo
471
Nicolas Noble53830622015-02-12 16:56:38 -0800472protobuf_dep_message:
473 @echo
474 @echo "DEPENDENCY ERROR"
475 @echo
476 @echo "The target you are trying to run requires protobuf 3.0.0+"
477 @echo "Your system doesn't have it, and neither does the third_party directory."
478 @echo
479 @echo "Please consult INSTALL to get more information."
480 @echo
481 @echo "If you need information about why these tests failed, run:"
482 @echo
483 @echo " make run_dep_checks"
484 @echo
485
486protoc_dep_message:
487 @echo
488 @echo "DEPENDENCY ERROR"
489 @echo
490 @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
491 @echo "Your system doesn't have it, and neither does the third_party directory."
492 @echo
493 @echo "Please consult INSTALL to get more information."
494 @echo
495 @echo "If you need information about why these tests failed, run:"
496 @echo
497 @echo " make run_dep_checks"
498 @echo
499
nnoble69ac39f2014-12-12 15:43:38 -0800500stop:
501 @false
502
ctiller09cb6d52014-12-19 17:38:22 -0800503% for tgt in targets:
Craig Tiller61b910f2015-02-15 10:54:07 -0800504${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
ctiller09cb6d52014-12-19 17:38:22 -0800505% endfor
506
nnoble69ac39f2014-12-12 15:43:38 -0800507run_dep_checks:
nnoble69ac39f2014-12-12 15:43:38 -0800508 $(OPENSSL_ALPN_CHECK_CMD) || true
509 $(ZLIB_CHECK_CMD) || true
Nicolas Noble53830622015-02-12 16:56:38 -0800510 $(PERFTOOLS_CHECK_CMD) || true
511 $(PROTOBUF_CHECK_CMD) || true
512 $(PROTOC_CHECK_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800513
Craig Tiller61b910f2015-02-15 10:54:07 -0800514$(LIBDIR)/$(CONFIG)/zlib/libz.a:
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100515 $(E) "[MAKE] Building zlib"
516 $(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="-fPIC -fvisibility=hidden $(CPPFLAGS_$(CONFIG))" ./configure --static)
517 $(Q)$(MAKE) -C third_party/zlib clean
518 $(Q)$(MAKE) -C third_party/zlib
Craig Tiller61b910f2015-02-15 10:54:07 -0800519 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/zlib
520 $(Q)cp third_party/zlib/libz.a $(LIBDIR)/$(CONFIG)/zlib
nnoble69ac39f2014-12-12 15:43:38 -0800521
Craig Tiller61b910f2015-02-15 10:54:07 -0800522$(LIBDIR)/$(CONFIG)/openssl/libssl.a:
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800523 $(E) "[MAKE] Building openssl for $(SYSTEM)"
524ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee567fa92015-02-20 07:10:21 +0100525 $(Q)(cd third_party/openssl ; CC="$(CC) -fPIC -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./Configure darwin64-x86_64-cc)
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800526else
Nicolas "Pixel" Noblee567fa92015-02-20 07:10:21 +0100527 $(Q)(cd third_party/openssl ; CC="$(CC) -fPIC -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./config no-asm $(OPENSSL_CONFIG_$(CONFIG)))
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800528endif
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100529 $(Q)$(MAKE) -C third_party/openssl clean
530 $(Q)$(MAKE) -C third_party/openssl build_crypto build_ssl
Craig Tiller61b910f2015-02-15 10:54:07 -0800531 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/openssl
532 $(Q)cp third_party/openssl/libssl.a third_party/openssl/libcrypto.a $(LIBDIR)/$(CONFIG)/openssl
nnoble69ac39f2014-12-12 15:43:38 -0800533
Nicolas Noble53830622015-02-12 16:56:38 -0800534third_party/protobuf/configure:
535 $(E) "[AUTOGEN] Preparing protobuf"
536 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
537
Craig Tiller61b910f2015-02-15 10:54:07 -0800538$(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
Nicolas Noble53830622015-02-12 16:56:38 -0800539 $(E) "[MAKE] Building protobuf"
Craig Tillercf133f42015-02-26 14:05:56 -0800540ifeq ($(HAVE_CXX11),true)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100541 $(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g" CXXFLAGS="-DLANG_CXX11 -std=c++11" CPPFLAGS="-fPIC $(CPPFLAGS_$(CONFIG)) -g" ./configure --disable-shared --enable-static)
Craig Tillercf133f42015-02-26 14:05:56 -0800542else
543 $(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g" CXXFLAGS="-std=c++0x" CPPFLAGS="-fPIC $(CPPFLAGS_$(CONFIG)) -g" ./configure --disable-shared --enable-static)
544endif
Nicolas Noble53830622015-02-12 16:56:38 -0800545 $(Q)$(MAKE) -C third_party/protobuf clean
546 $(Q)$(MAKE) -C third_party/protobuf
Craig Tiller61b910f2015-02-15 10:54:07 -0800547 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
548 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
549 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
550 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
551 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800552
nnoble29e1d292014-12-01 10:27:40 -0800553static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800554
Craig Tiller12c82092015-01-15 08:45:56 -0800555static_c: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800556% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800557% if lib.build == 'all' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800558 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800559% endif
560% endfor
561
562
Craig Tiller12c82092015-01-15 08:45:56 -0800563static_cxx: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800564% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800565% if lib.build == 'all' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800566 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
nnoble29e1d292014-12-01 10:27:40 -0800567% endif
568% endfor
569
570
571shared: shared_c shared_cxx
572
Craig Tiller12c82092015-01-15 08:45:56 -0800573shared_c: \
nnoble29e1d292014-12-01 10:27:40 -0800574% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800575% if lib.build == 'all' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800576 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800577% endif
578% endfor
579
580
Craig Tiller12c82092015-01-15 08:45:56 -0800581shared_cxx: \
nnoble29e1d292014-12-01 10:27:40 -0800582% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800583% if lib.build == 'all' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800584 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
nnoble29e1d292014-12-01 10:27:40 -0800585% endif
586% endfor
587
588
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800589shared_csharp: shared_c \
590% for lib in libs:
591% if lib.build == 'all' and lib.language == 'csharp':
592 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
593% endif
594% endfor
595
596grpc_csharp_ext: shared_csharp
597
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100598plugins: $(PROTOC_PLUGINS)
599
nnoble29e1d292014-12-01 10:27:40 -0800600privatelibs: privatelibs_c privatelibs_cxx
601
Craig Tiller12c82092015-01-15 08:45:56 -0800602privatelibs_c: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800603% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800604% if lib.build == 'private' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800605 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800606% endif
607% endfor
608
609
Craig Tiller12c82092015-01-15 08:45:56 -0800610privatelibs_cxx: \
nnoble29e1d292014-12-01 10:27:40 -0800611% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800612% if lib.build == 'private' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800613 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800614% endif
615% endfor
616
617
nnoble29e1d292014-12-01 10:27:40 -0800618buildtests: buildtests_c buildtests_cxx
619
Craig Tiller12c82092015-01-15 08:45:56 -0800620buildtests_c: privatelibs_c\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800621% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800622% if tgt.build == 'test' and not tgt.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800623 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800624% endif
625% endfor
626
627
Craig Tiller12c82092015-01-15 08:45:56 -0800628buildtests_cxx: privatelibs_cxx\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800629% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800630% if tgt.build == 'test' and tgt.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800631 $(BINDIR)/$(CONFIG)/${tgt.name}\
nnoble29e1d292014-12-01 10:27:40 -0800632% endif
633% endfor
634
635
nnoble85a49262014-12-08 18:14:03 -0800636test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -0800637
nnoble85a49262014-12-08 18:14:03 -0800638test_c: buildtests_c
nnoble29e1d292014-12-01 10:27:40 -0800639% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800640% if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++':
nnoble29e1d292014-12-01 10:27:40 -0800641 $(E) "[RUN] Testing ${tgt.name}"
Craig Tillerda224d62015-02-15 11:01:58 -0800642 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
nnoble29e1d292014-12-01 10:27:40 -0800643% endif
644% endfor
645
646
nnoble85a49262014-12-08 18:14:03 -0800647test_cxx: buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -0800648% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800649% if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++':
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800650 $(E) "[RUN] Testing ${tgt.name}"
Craig Tillerda224d62015-02-15 11:01:58 -0800651 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800652% endif
653% endfor
654
655
656tools: privatelibs\
657% for tgt in targets:
658% if tgt.build == 'tool':
Craig Tiller61b910f2015-02-15 10:54:07 -0800659 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800660% endif
661% endfor
662
663
664buildbenchmarks: privatelibs\
665% for tgt in targets:
666% if tgt.build == 'benchmark':
Craig Tiller61b910f2015-02-15 10:54:07 -0800667 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800668% endif
669% endfor
670
671
672benchmarks: buildbenchmarks
673
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800674strip: strip-static strip-shared
675
nnoble20e2e3f2014-12-16 15:37:57 -0800676strip-static: strip-static_c strip-static_cxx
677
678strip-shared: strip-shared_c strip-shared_cxx
679
Nicolas Noble047b7272015-01-16 13:55:05 -0800680
681# TODO(nnoble): the strip target is stripping in-place, instead
682# of copying files in a temporary folder.
683# This prevents proper debugging after running make install.
684
nnoble85a49262014-12-08 18:14:03 -0800685strip-static_c: static_c
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100686ifeq ($(CONFIG),opt)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800687% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800688% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800689% if lib.build == "all":
690 $(E) "[STRIP] Stripping lib${lib.name}.a"
Craig Tiller61b910f2015-02-15 10:54:07 -0800691 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800692% endif
nnoble85a49262014-12-08 18:14:03 -0800693% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800694% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100695endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800696
nnoble85a49262014-12-08 18:14:03 -0800697strip-static_cxx: static_cxx
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100698ifeq ($(CONFIG),opt)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800699% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800700% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800701% if lib.build == "all":
702 $(E) "[STRIP] Stripping lib${lib.name}.a"
Craig Tiller61b910f2015-02-15 10:54:07 -0800703 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
nnoble85a49262014-12-08 18:14:03 -0800704% endif
705% endif
706% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100707endif
nnoble85a49262014-12-08 18:14:03 -0800708
709strip-shared_c: shared_c
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100710ifeq ($(CONFIG),opt)
nnoble85a49262014-12-08 18:14:03 -0800711% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800712% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800713% if lib.build == "all":
714 $(E) "[STRIP] Stripping lib${lib.name}.so"
Craig Tiller61b910f2015-02-15 10:54:07 -0800715 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800716% endif
nnoble85a49262014-12-08 18:14:03 -0800717% endif
718% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100719endif
nnoble85a49262014-12-08 18:14:03 -0800720
721strip-shared_cxx: shared_cxx
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100722ifeq ($(CONFIG),opt)
nnoble85a49262014-12-08 18:14:03 -0800723% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800724% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800725% if lib.build == "all":
726 $(E) "[STRIP] Stripping lib${lib.name}.so"
Craig Tiller61b910f2015-02-15 10:54:07 -0800727 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
nnoble85a49262014-12-08 18:14:03 -0800728% endif
729% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800730% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100731endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800732
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800733strip-shared_csharp: shared_csharp
734ifeq ($(CONFIG),opt)
735% for lib in libs:
736% if lib.language == "csharp":
737% if lib.build == "all":
738 $(E) "[STRIP] Stripping lib${lib.name}.so"
739 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
740% endif
741% endif
742% endfor
743endif
744
nnoble72309c62014-12-12 11:42:26 -0800745% for p in protos:
Nicolas Noble53830622015-02-12 16:56:38 -0800746ifeq ($(NO_PROTOC),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800747$(GENDIR)/${p}.pb.cc: protoc_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800748else
Craig Tiller61b910f2015-02-15 10:54:07 -0800749$(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800750 $(E) "[PROTOC] Generating protobuf CC file from $<"
751 $(Q) mkdir -p `dirname $@`
Vijay Pai850290f2015-02-19 09:59:44 -0800752 $(Q) $(PROTOC) --cpp_out=$(GENDIR) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $<
Nicolas Noble53830622015-02-12 16:56:38 -0800753endif
nnoble72309c62014-12-12 11:42:26 -0800754
755% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800756
Craig Tiller61b910f2015-02-15 10:54:07 -0800757$(OBJDIR)/$(CONFIG)/%.o : %.c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800758 $(E) "[C] Compiling $<"
759 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800760 $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800761
Craig Tiller61b910f2015-02-15 10:54:07 -0800762$(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800763 $(E) "[CXX] Compiling $<"
764 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800765 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800766
Craig Tiller61b910f2015-02-15 10:54:07 -0800767$(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
nnoble72309c62014-12-12 11:42:26 -0800768 $(E) "[HOSTCXX] Compiling $<"
769 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800770 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -0800771
Craig Tiller61b910f2015-02-15 10:54:07 -0800772$(OBJDIR)/$(CONFIG)/%.o : %.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800773 $(E) "[CXX] Compiling $<"
774 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800775 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800776
777
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +0100778install: install_c install_cxx install-plugins install-certs verify-install
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800779
nnoble85a49262014-12-08 18:14:03 -0800780install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800781
nnoble85a49262014-12-08 18:14:03 -0800782install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
783
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800784install_csharp: install-shared_csharp install_c
785
786install_grpc_csharp_ext: install_csharp
787
nnoble85a49262014-12-08 18:14:03 -0800788install-headers: install-headers_c install-headers_cxx
789
790install-headers_c:
791 $(E) "[INSTALL] Installing public C headers"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100792 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -0800793 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
794
795install-headers_cxx:
796 $(E) "[INSTALL] Installing public C++ headers"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100797 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -0800798 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
799
800install-static: install-static_c install-static_cxx
801
802install-static_c: static_c strip-static_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800803% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800804% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800805% if lib.build == "all":
806 $(E) "[INSTALL] Installing lib${lib.name}.a"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100807 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800808 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800809% endif
nnoble85a49262014-12-08 18:14:03 -0800810% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800811% endfor
812
nnoble85a49262014-12-08 18:14:03 -0800813install-static_cxx: static_cxx strip-static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800814% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800815% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800816% if lib.build == "all":
817 $(E) "[INSTALL] Installing lib${lib.name}.a"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100818 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800819 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
nnoble85a49262014-12-08 18:14:03 -0800820% endif
821% endif
822% endfor
823
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100824<%def name="install_shared(lang_filter)">\
nnoble85a49262014-12-08 18:14:03 -0800825% for lib in libs:
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100826% if lib.language == lang_filter:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800827% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -0800828ifeq ($(SYSTEM),MINGW32)
829 $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100830 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800831 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT)
832 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
nnoble5b7f32a2014-12-22 08:12:44 -0800833else
Nicolas "Pixel" Noble716b5fe2015-03-11 22:35:57 +0100834ifneq ($(SYSTEM),Darwin)
nnoble5b7f32a2014-12-22 08:12:44 -0800835 $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100836 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800837 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT)
nnoble5b7f32a2014-12-22 08:12:44 -0800838 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
839endif
840endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800841% endif
nnoble85a49262014-12-08 18:14:03 -0800842% endif
843% endfor
nnoble5b7f32a2014-12-22 08:12:44 -0800844ifneq ($(SYSTEM),MINGW32)
845ifneq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblecc2b42a2015-02-20 00:42:21 +0100846 $(Q) ldconfig || true
nnoble5b7f32a2014-12-22 08:12:44 -0800847endif
848endif
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100849</%def>
nnoble85a49262014-12-08 18:14:03 -0800850
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100851install-shared_c: shared_c strip-shared_c
852${install_shared("c")}
853
854install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c
855${install_shared("c++")}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800856
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800857install-shared_csharp: shared_csharp strip-shared_csharp
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100858${install_shared("csharp")}
859
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100860install-plugins: $(PROTOC_PLUGINS)
861ifeq ($(SYSTEM),MINGW32)
862 $(Q) false
863else
864 $(E) "[INSTALL] Installing grpc protoc plugins"
865% for tgt in targets:
866% if tgt.build == 'protoc':
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100867 $(Q) $(INSTALL) -d $(prefix)/bin
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100868 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
869% endif
870% endfor
871endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800872
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +0100873install-certs: etc/roots.pem
874 $(E) "[INSTALL] Installing root certificates"
875 $(Q) $(INSTALL) -d $(prefix)/share/grpc
876 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
877
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100878verify-install:
Nicolas "Pixel" Noble2c23a722015-02-24 20:17:45 +0100879ifeq ($(INSTALL_OK),true)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100880 @echo "Your system looks ready to go."
881 @echo
882else
murgatroid99b6181362015-03-02 14:32:25 -0800883 @echo "We couldn't find protoc 3.0.0+ installed on your system. While this"
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100884 @echo "won't prevent grpc from working, you won't be able to compile"
885 @echo "and run any meaningful code with it."
886 @echo
887 @echo
888 @echo "Please download and install protobuf 3.0.0+ from:"
889 @echo
890 @echo " https://github.com/google/protobuf/releases"
891 @echo
murgatroid99b6181362015-03-02 14:32:25 -0800892 @echo "Once you've done so, or if you think this message is in error,"
893 @echo "you can re-run this check by doing:"
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100894 @echo
895 @echo " make verify-install"
896endif
897
Craig Tiller3759e6f2015-01-15 08:13:11 -0800898clean:
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100899 $(E) "[CLEAN] Cleaning build directories."
Craig Tillerda224d62015-02-15 11:01:58 -0800900 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800901
902
903# The various libraries
904
905% for lib in libs:
906${makelib(lib)}
907% endfor
908
909
nnoble69ac39f2014-12-12 15:43:38 -0800910# All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800911
912% for tgt in targets:
913${maketarget(tgt)}
914% endfor
915
916<%def name="makelib(lib)">
917LIB${lib.name.upper()}_SRC = \\
918
919% for src in lib.src:
nnoble72309c62014-12-12 11:42:26 -0800920 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800921
922% endfor
923
924% if "public_headers" in lib:
Craig Tiller59140fc2015-01-18 10:12:17 -0800925% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800926PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800927
nnoble85a49262014-12-08 18:14:03 -0800928% else:
929PUBLIC_HEADERS_C += \\
930
931% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800932% for hdr in lib.public_headers:
933 ${hdr} \\
934
935% endfor
936% endif
937
Craig Tiller61b910f2015-02-15 10:54:07 -0800938LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800939
Nicolas Noble047b7272015-01-16 13:55:05 -0800940## If the library requires OpenSSL with ALPN, let's add some restrictions.
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +0100941% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -0800942ifeq ($(NO_SECURE),true)
943
Nicolas Noble047b7272015-01-16 13:55:05 -0800944# You can't build secure libraries if you don't have OpenSSL with ALPN.
945
Craig Tiller61b910f2015-02-15 10:54:07 -0800946$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -0800947
nnoble5b7f32a2014-12-22 08:12:44 -0800948% if lib.build == "all":
949ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -0800950$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -0800951else
Craig Tiller61b910f2015-02-15 10:54:07 -0800952$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -0800953endif
954% endif
955
nnoble69ac39f2014-12-12 15:43:38 -0800956else
957
Nicolas Noble53830622015-02-12 16:56:38 -0800958% if lib.language == 'c++':
959ifeq ($(NO_PROTOBUF),true)
960
961# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
962
Craig Tiller61b910f2015-02-15 10:54:07 -0800963$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800964
965% if lib.build == "all":
966ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -0800967$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800968else
Craig Tiller61b910f2015-02-15 10:54:07 -0800969$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800970endif
971% endif
972
973else
974% endif
975
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100976ifneq ($(OPENSSL_DEP),)
Nicolas Noble53830622015-02-12 16:56:38 -0800977# This is to ensure the embedded OpenSSL is built beforehand, properly
978# installing headers to their final destination on the drive. We need this
979# otherwise parallel compilation will fail if a source is compiled first.
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100980% for src in lib.src:
981${src}: $(OPENSSL_DEP)
982% endfor
983endif
984
Craig Tiller61b910f2015-02-15 10:54:07 -0800985$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
Nicolas Noble047b7272015-01-16 13:55:05 -0800986## The else here corresponds to the if secure earlier.
nnoble20e2e3f2014-12-16 15:37:57 -0800987% else:
Nicolas Noble53830622015-02-12 16:56:38 -0800988% if lib.language == 'c++':
989ifeq ($(NO_PROTOBUF),true)
990
991# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
992
Craig Tiller61b910f2015-02-15 10:54:07 -0800993$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800994
995% if lib.build == "all":
996ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -0800997$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800998else
Craig Tiller61b910f2015-02-15 10:54:07 -0800999$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001000endif
nnoble20e2e3f2014-12-16 15:37:57 -08001001% endif
Nicolas Noble53830622015-02-12 16:56:38 -08001002
1003else
1004
1005% endif
Craig Tiller61b910f2015-02-15 10:54:07 -08001006$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP)\
Nicolas Noble53830622015-02-12 16:56:38 -08001007% endif
1008% if lib.language == 'c++':
1009 $(PROTOBUF_DEP)\
1010% endif
1011 $(LIB${lib.name.upper()}_OBJS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001012 $(E) "[AR] Creating $@"
nnoble85a49262014-12-08 18:14:03 -08001013 $(Q) mkdir -p `dirname $@`
Craig Tiller61b910f2015-02-15 10:54:07 -08001014 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1015 $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
nnoble20e2e3f2014-12-16 15:37:57 -08001016% if lib.get('baselib', False):
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001017% if lib.get('secure', 'check') == 'yes':
Craig Tiller7ab4fee2015-02-24 08:15:53 -08001018 $(Q) rm -rf tmp-merge-${lib.name}
1019 $(Q) mkdir tmp-merge-${lib.name}
1020 $(Q) ( cd tmp-merge-${lib.name} ; $(AR) x ../$(LIBDIR)/$(CONFIG)/lib${lib.name}.a )
1021 $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge-${lib.name} ; <%text>ar x ../$${l}</%text> ) ; done
1022 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/__.SYMDEF*
1023 $(Q) ar rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/*
1024 $(Q) rm -rf tmp-merge-${lib.name}
nnoble20e2e3f2014-12-16 15:37:57 -08001025% endif
1026% endif
Craig Tillerb4ee3b52015-01-21 16:22:50 -08001027ifeq ($(SYSTEM),Darwin)
murgatroid99b6181362015-03-02 14:32:25 -08001028 $(Q) ranlib $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tillerb4ee3b52015-01-21 16:22:50 -08001029endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001030
nnoble5b7f32a2014-12-22 08:12:44 -08001031<%
Craig Tiller59140fc2015-01-18 10:12:17 -08001032 if lib.language == 'c++':
nnoble5b7f32a2014-12-22 08:12:44 -08001033 ld = '$(LDXX)'
1034 else:
1035 ld = '$(LD)'
1036
Craig Tillerda224d62015-02-15 11:01:58 -08001037 out_base = '$(LIBDIR)/$(CONFIG)/' + lib.name
1038 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name
nnoble5b7f32a2014-12-22 08:12:44 -08001039
1040 common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
1041
1042 libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +01001043 lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -08001044 mingw_libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +01001045 mingw_lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -08001046 for dep in lib.get('deps', []):
1047 libs = libs + ' -l' + dep
Craig Tiller61b910f2015-02-15 10:54:07 -08001048 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001049 mingw_libs = mingw_libs + ' -l' + dep + '-imp'
Craig Tillerda224d62015-02-15 11:01:58 -08001050 mingw_lib_deps = mingw_lib_deps + '$(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001051
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001052 if lib.get('secure', 'check') == 'yes':
nnoble5b7f32a2014-12-22 08:12:44 -08001053 common = common + ' $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS)'
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001054
1055 if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble5b7f32a2014-12-22 08:12:44 -08001056 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1057 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001058
1059 if lib.language == 'c++':
1060 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
nnoble5b7f32a2014-12-22 08:12:44 -08001061%>
1062
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001063% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -08001064ifeq ($(SYSTEM),MINGW32)
1065${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001066 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -08001067 $(Q) mkdir -p `dirname $@`
Craig Tillerda224d62015-02-15 11:01:58 -08001068 $(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 -08001069else
1070${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
1071 $(E) "[LD] Linking $@"
1072 $(Q) mkdir -p `dirname $@`
1073ifeq ($(SYSTEM),Darwin)
Craig Tillerda224d62015-02-15 11:01:58 -08001074 $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
nnoble5b7f32a2014-12-22 08:12:44 -08001075else
Craig Tillerda224d62015-02-15 11:01:58 -08001076 $(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 +01001077 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major}
nnoble5b7f32a2014-12-22 08:12:44 -08001078 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so
1079endif
1080endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001081% endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001082% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
Nicolas Noble047b7272015-01-16 13:55:05 -08001083## If the lib was secure, we have to close the Makefile's if that tested
1084## the presence of an ALPN-capable OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001085
1086endif
1087% endif
1088% if lib.language == 'c++':
1089## If the lib was C++, we have to close the Makefile's if that tested
1090## the presence of protobuf 3.0.0+
nnoble69ac39f2014-12-12 15:43:38 -08001091
1092endif
1093% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001094
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001095% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001096ifneq ($(NO_SECURE),true)
1097% endif
1098ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -08001099-include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001100endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001101% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001102endif
1103% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001104
Craig Tiller27715ca2015-01-12 16:55:59 -08001105% for src in lib.src:
1106% if not proto_re.match(src):
Craig Tiller61b910f2015-02-15 10:54:07 -08001107$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
Craig Tiller27715ca2015-01-12 16:55:59 -08001108% for src2 in lib.src:
1109% if proto_re.match(src2):
1110 ${proto_to_cc(src2)}\
1111% endif
1112% endfor
1113% endif
1114
1115% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001116</%def>
1117
1118<%def name="maketarget(tgt)">
1119${tgt.name.upper()}_SRC = \\
1120
1121% for src in tgt.src:
nnoble72309c62014-12-12 11:42:26 -08001122 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001123
1124% endfor
1125
Craig Tiller61b910f2015-02-15 10:54:07 -08001126${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001127
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001128% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001129ifeq ($(NO_SECURE),true)
1130
Nicolas Noble047b7272015-01-16 13:55:05 -08001131# You can't build secure targets if you don't have OpenSSL with ALPN.
1132
Craig Tiller61b910f2015-02-15 10:54:07 -08001133$(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001134
1135else
1136
1137% endif
Nicolas Noble047b7272015-01-16 13:55:05 -08001138##
1139## We're not trying to add a dependency on building zlib and openssl here,
1140## as it's already done in the libraries. We're assuming that the build
1141## trickles down, and that a secure target requires a secure version of
1142## a library.
1143##
1144## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1145## I can live with that.
1146##
Nicolas "Pixel" Noble18953e32015-02-27 02:41:11 +01001147% if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001148
1149ifeq ($(NO_PROTOBUF),true)
1150
Nicolas "Pixel" Noble18953e32015-02-27 02:41:11 +01001151# 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 -08001152
Craig Tiller61b910f2015-02-15 10:54:07 -08001153$(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001154
1155else
1156
Craig Tiller61b910f2015-02-15 10:54:07 -08001157$(BINDIR)/$(CONFIG)/${tgt.name}: $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
Nicolas Noble53830622015-02-12 16:56:38 -08001158% else:
Craig Tiller61b910f2015-02-15 10:54:07 -08001159$(BINDIR)/$(CONFIG)/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
Nicolas Noble53830622015-02-12 16:56:38 -08001160% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001161% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001162 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001163% endfor
1164
Craig Tiller59140fc2015-01-18 10:12:17 -08001165% if tgt.language == "c++":
Nicolas Noble047b7272015-01-16 13:55:05 -08001166## C++ targets specificies.
nnoble72309c62014-12-12 11:42:26 -08001167% if tgt.build == 'protoc':
1168 $(E) "[HOSTLD] Linking $@"
1169 $(Q) mkdir -p `dirname $@`
1170 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(${tgt.name.upper()}_OBJS)\
1171% else:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001172 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -08001173 $(Q) mkdir -p `dirname $@`
nnoblec78b3402014-12-11 16:06:57 -08001174 $(Q) $(LDXX) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
nnoble72309c62014-12-12 11:42:26 -08001175% endif
nnoblec78b3402014-12-11 16:06:57 -08001176% if tgt.build == 'test':
1177 $(GTEST_LIB)\
1178% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001179% else:
Nicolas Noble047b7272015-01-16 13:55:05 -08001180## C-only targets specificities.
nnoble72309c62014-12-12 11:42:26 -08001181 $(E) "[LD] Linking $@"
1182 $(Q) mkdir -p `dirname $@`
nnoble5b7f32a2014-12-22 08:12:44 -08001183 $(Q) $(LD) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001184% endif
1185% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001186 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001187% endfor
Craig Tiller59140fc2015-01-18 10:12:17 -08001188% if tgt.language == "c++":
nnoble72309c62014-12-12 11:42:26 -08001189% if tgt.build == 'protoc':
Nicolas Noble53830622015-02-12 16:56:38 -08001190 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
nnoble72309c62014-12-12 11:42:26 -08001191% else:
Nicolas Noble53830622015-02-12 16:56:38 -08001192 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001193% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001194% endif
nnoblec78b3402014-12-11 16:06:57 -08001195% if tgt.build == 'protoc':
nnoble72309c62014-12-12 11:42:26 -08001196 $(HOST_LDLIBS)\
1197% else:
1198 $(LDLIBS)\
1199% endif
1200% if tgt.build == 'protoc':
1201 $(HOST_LDLIBS_PROTOC)\
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001202% elif tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble72309c62014-12-12 11:42:26 -08001203 $(LDLIBS_SECURE)\
nnoblec78b3402014-12-11 16:06:57 -08001204% endif
Craig Tiller61b910f2015-02-15 10:54:07 -08001205 -o $(BINDIR)/$(CONFIG)/${tgt.name}
Nicolas "Pixel" Noble18953e32015-02-27 02:41:11 +01001206% if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001207
1208endif
1209% endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001210% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001211
1212endif
1213% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001214
Craig Tillerf5371ef2015-01-12 16:40:18 -08001215% for src in tgt.src:
Craig Tiller61b910f2015-02-15 10:54:07 -08001216$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
Craig Tillerf5371ef2015-01-12 16:40:18 -08001217% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001218 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Craig Tillerf5371ef2015-01-12 16:40:18 -08001219% endfor
1220
1221% endfor
1222
Craig Tiller8f126a62015-01-15 08:50:19 -08001223deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001224
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001225% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001226ifneq ($(NO_SECURE),true)
1227% endif
1228ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -08001229-include $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001230endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001231% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001232endif
1233% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001234</%def>
1235
nnoble85a49262014-12-08 18:14:03 -08001236.PHONY: all strip tools \
nnoble69ac39f2014-12-12 15:43:38 -08001237dep_error openssl_dep_error openssl_dep_message git_update stop \
nnoble85a49262014-12-08 18:14:03 -08001238buildtests buildtests_c buildtests_cxx \
1239test test_c test_cxx \
1240install install_c install_cxx \
1241install-headers install-headers_c install-headers_cxx \
1242install-shared install-shared_c install-shared_cxx \
1243install-static install-static_c install-static_cxx \
1244strip strip-shared strip-static \
1245strip_c strip-shared_c strip-static_c \
1246strip_cxx strip-shared_cxx strip-static_cxx \
Craig Tillerf0afe502015-01-15 09:04:49 -08001247dep_c dep_cxx bins_dep_c bins_dep_cxx \
Craig Tiller12c82092015-01-15 08:45:56 -08001248clean