blob: 84c5402e2f1cc0b8640bb957a40ad7b9bc7f73f1 [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 Tiller8ad8a412015-02-25 08:36:40 -080097DEFINES_valgrind = _DEBUG DEBUG GRPC_TEST_SLOWDOWN_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 Tiller8ad8a412015-02-25 08:36:40 -0800107DEFINES_tsan = NDEBUG GRPC_TEST_SLOWDOWN_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 Tiller8ad8a412015-02-25 08:36:40 -0800117DEFINES_asan = NDEBUG GRPC_TEST_SLOWDOWN_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 Tiller8ad8a412015-02-25 08:36:40 -0800128DEFINES_msan = NDEBUG GRPC_TEST_SLOWDOWN_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 Tiller8ad8a412015-02-25 08:36:40 -0800139DEFINES_ubsan = NDEBUG GRPC_TEST_SLOWDOWN_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
163STRIP = strip --strip-unneeded
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100164INSTALL = install
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800165RM = rm -f
166
yangg102e4fe2015-01-06 16:02:50 -0800167ifndef VALID_CONFIG_$(CONFIG)
168$(error Invalid CONFIG value '$(CONFIG)')
169endif
170
Nicolas Noble047b7272015-01-16 13:55:05 -0800171
Craig Tillercf133f42015-02-26 14:05:56 -0800172# Detect if we can use C++11
173CXX11_CHECK_CMD = $(CXX) -std=c++11 -o /dev/null -c test/build/c++11.cc
174HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false)
175
Nicolas Noble047b7272015-01-16 13:55:05 -0800176# The HOST compiler settings are used to compile the protoc plugins.
177# In most cases, you won't have to change anything, but if you are
178# cross-compiling, you can override these variables from GNU make's
179# command line: make CC=cross-gcc HOST_CC=gcc
180
nnoble72309c62014-12-12 11:42:26 -0800181HOST_CC = $(CC)
182HOST_CXX = $(CXX)
183HOST_LD = $(LD)
184HOST_LDXX = $(LDXX)
185
ctillercab52e72015-01-06 13:10:23 -0800186CPPFLAGS += $(CPPFLAGS_$(CONFIG))
Nicolas "Pixel" Noble72743822015-02-20 20:59:29 +0100187DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
ctiller8cfebb92015-01-06 15:02:12 -0800188LDFLAGS += $(LDFLAGS_$(CONFIG))
ctillercab52e72015-01-06 13:10:23 -0800189
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800190CFLAGS += -std=c89 -pedantic
Craig Tillercf133f42015-02-26 14:05:56 -0800191ifeq ($(HAS_CXX11),true)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800192CXXFLAGS += -std=c++11
Craig Tillercf133f42015-02-26 14:05:56 -0800193else
194CXXFLAGS += -std=c++0x
195DEFINES += GRPC_OLD_CXX
196endif
Nicolas "Pixel" Noble213ed912015-01-30 02:11:35 +0100197CPPFLAGS += -g -fPIC -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
Craig Tiller96b49552015-01-21 16:29:01 -0800198LDFLAGS += -g -fPIC
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800199
Craig Tillerda224d62015-02-15 11:01:58 -0800200INCLUDES = . include $(GENDIR)
Craig Tiller96b49552015-01-21 16:29:01 -0800201ifeq ($(SYSTEM),Darwin)
vjpai7cc2c302015-02-18 12:33:37 -0800202INCLUDES += /usr/local/ssl/include /opt/local/include
Craig Tiller96b49552015-01-21 16:29:01 -0800203LIBS = m z
vjpai7cc2c302015-02-18 12:33:37 -0800204LDFLAGS += -L/usr/local/ssl/lib -L/opt/local/lib
Craig Tiller96b49552015-01-21 16:29:01 -0800205else
ctillerc008ae52015-01-07 15:33:00 -0800206LIBS = rt m z pthread
Craig Tiller96b49552015-01-21 16:29:01 -0800207LDFLAGS += -pthread
208endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800209
210ifneq ($(wildcard /usr/src/gtest/src/gtest-all.cc),)
211GTEST_LIB = /usr/src/gtest/src/gtest-all.cc -I/usr/src/gtest
212else
213GTEST_LIB = -lgtest
214endif
chenwa8fd44a2014-12-10 15:13:55 -0800215GTEST_LIB += -lgflags
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800216ifeq ($(V),1)
217E = @:
218Q =
219else
220E = @echo
221Q = @
222endif
223
224VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build}
225
226CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
227CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
228
229LDFLAGS += $(ARCH_FLAGS)
230LDLIBS += $(addprefix -l, $(LIBS))
231LDLIBSXX += $(addprefix -l, $(LIBSXX))
nnoble72309c62014-12-12 11:42:26 -0800232
233HOST_CPPFLAGS = $(CPPFLAGS)
234HOST_CFLAGS = $(CFLAGS)
235HOST_CXXFLAGS = $(CXXFLAGS)
236HOST_LDFLAGS = $(LDFLAGS)
237HOST_LDLIBS = $(LDLIBS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800238
nnoble69ac39f2014-12-12 15:43:38 -0800239
240# These are automatically computed variables.
241# There shouldn't be any need to change anything from now on.
242
nnoble5b7f32a2014-12-22 08:12:44 -0800243ifeq ($(SYSTEM),MINGW32)
244SHARED_EXT = dll
245endif
246ifeq ($(SYSTEM),Darwin)
247SHARED_EXT = dylib
248endif
249ifeq ($(SHARED_EXT),)
250SHARED_EXT = so.$(VERSION)
251endif
252
nnoble69ac39f2014-12-12 15:43:38 -0800253ifeq ($(wildcard .git),)
254IS_GIT_FOLDER = false
255else
256IS_GIT_FOLDER = true
257endif
258
nnoble7e012cf2014-12-22 17:53:44 -0800259OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/openssl-alpn.c -lssl -lcrypto -ldl $(LDFLAGS)
260ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/zlib.c -lz $(LDFLAGS)
Craig Tiller297fafa2015-01-15 15:46:39 -0800261PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/perftools.c -lprofiler $(LDFLAGS)
Nicolas Noble53830622015-02-12 16:56:38 -0800262PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o /dev/null test/build/protobuf.cc -lprotobuf $(LDFLAGS)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100263PROTOC_CMD = which protoc
Nicolas Noble53830622015-02-12 16:56:38 -0800264PROTOC_CHECK_CMD = protoc --version | grep -q libprotoc.3
Craig Tiller297fafa2015-01-15 15:46:39 -0800265
Craig Tiller50524cc2015-01-29 23:00:00 -0800266ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
Craig Tiller297fafa2015-01-15 15:46:39 -0800267HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
268ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
269DEFINES += GRPC_HAVE_PERFTOOLS
270LIBS += profiler
271endif
Craig Tiller50524cc2015-01-29 23:00:00 -0800272endif
nnoble69ac39f2014-12-12 15:43:38 -0800273
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100274HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
Craig Tillerc4da6b72015-01-15 08:01:14 -0800275ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
nnoble60825402014-12-15 14:43:51 -0800276HAS_SYSTEM_OPENSSL_ALPN = $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
277HAS_SYSTEM_ZLIB = $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100278HAS_SYSTEM_PROTOBUF = $(HAS_SYSTEM_PROTOBUF_VERIFY)
Craig Tillerc4da6b72015-01-15 08:01:14 -0800279else
280# override system libraries if the config requires a custom compiled library
281HAS_SYSTEM_OPENSSL_ALPN = false
282HAS_SYSTEM_ZLIB = false
Nicolas Noble53830622015-02-12 16:56:38 -0800283HAS_SYSTEM_PROTOBUF = false
Craig Tillerc4da6b72015-01-15 08:01:14 -0800284endif
nnoble69ac39f2014-12-12 15:43:38 -0800285
Yang Gao044fe222015-02-24 12:59:38 -0800286HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100287ifeq ($(HAS_PROTOC),true)
Nicolas Noble53830622015-02-12 16:56:38 -0800288HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100289else
290HAS_VALID_PROTOC = false
291endif
Nicolas Noble53830622015-02-12 16:56:38 -0800292
nnoble69ac39f2014-12-12 15:43:38 -0800293ifeq ($(wildcard third_party/openssl/ssl/ssl.h),)
294HAS_EMBEDDED_OPENSSL_ALPN = false
295else
296HAS_EMBEDDED_OPENSSL_ALPN = true
297endif
298
299ifeq ($(wildcard third_party/zlib/zlib.h),)
300HAS_EMBEDDED_ZLIB = false
301else
302HAS_EMBEDDED_ZLIB = true
303endif
304
Nicolas Noble53830622015-02-12 16:56:38 -0800305ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
306HAS_EMBEDDED_PROTOBUF = false
307ifneq ($(HAS_VALID_PROTOC),true)
308NO_PROTOC = true
309endif
310else
311HAS_EMBEDDED_PROTOBUF = true
312endif
313
nnoble69ac39f2014-12-12 15:43:38 -0800314ifeq ($(HAS_SYSTEM_ZLIB),false)
315ifeq ($(HAS_EMBEDDED_ZLIB),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800316ZLIB_DEP = $(LIBDIR)/$(CONFIG)/zlib/libz.a
nnoble69ac39f2014-12-12 15:43:38 -0800317CPPFLAGS += -Ithird_party/zlib
Craig Tillerda224d62015-02-15 11:01:58 -0800318LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib
nnoble69ac39f2014-12-12 15:43:38 -0800319else
320DEP_MISSING += zlib
321endif
322endif
323
324ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false)
325ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800326OPENSSL_DEP = $(LIBDIR)/$(CONFIG)/openssl/libssl.a
327OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/openssl/libssl.a $(LIBDIR)/$(CONFIG)/openssl/libcrypto.a
Craig Tillerec043032015-02-20 17:24:41 -0800328# need to prefix these to ensure overriding system libraries
329CPPFLAGS := -Ithird_party/openssl/include $(CPPFLAGS)
330LDFLAGS := -L$(LIBDIR)/$(CONFIG)/openssl $(LDFLAGS)
nnoble5b7f32a2014-12-22 08:12:44 -0800331LIBS_SECURE = dl
nnoble69ac39f2014-12-12 15:43:38 -0800332else
333NO_SECURE = true
334endif
nnoble5b7f32a2014-12-22 08:12:44 -0800335else
336LIBS_SECURE = ssl crypto dl
nnoble69ac39f2014-12-12 15:43:38 -0800337endif
338
nnoble5b7f32a2014-12-22 08:12:44 -0800339LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
340
Nicolas Noble53830622015-02-12 16:56:38 -0800341ifeq ($(HAS_SYSTEM_PROTOBUF),false)
342ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800343PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
Craig Tiller9ec95fa2015-02-20 20:36:21 -0800344CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
345LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
Craig Tiller61b910f2015-02-15 10:54:07 -0800346PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
Nicolas Noble53830622015-02-12 16:56:38 -0800347else
348NO_PROTOBUF = true
349endif
350else
351endif
352
353LIBS_PROTOBUF = protobuf
354LIBS_PROTOC = protoc protobuf
355
356LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
357HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
358
Craig Tiller12c82092015-01-15 08:45:56 -0800359ifeq ($(MAKECMDGOALS),clean)
nnoble69ac39f2014-12-12 15:43:38 -0800360NO_DEPS = true
361endif
362
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100363INSTALL_OK = false
364ifeq ($(HAS_VALID_PROTOC),true)
365ifeq ($(HAS_SYSTEM_PROTOBUF_VERIFY),true)
366INSTALL_OK = true
367endif
368endif
369
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800370.SECONDARY = %.pb.h %.pb.cc
371
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100372PROTOC_PLUGINS =\
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800373% for tgt in targets:
374% if tgt.build == 'protoc':
Craig Tiller61b910f2015-02-15 10:54:07 -0800375 $(BINDIR)/$(CONFIG)/${tgt.name}\
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800376% endif
377% endfor
378
nnoble69ac39f2014-12-12 15:43:38 -0800379ifeq ($(DEP_MISSING),)
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100380all: static shared plugins\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800381% for tgt in targets:
382% if tgt.build == 'all':
Craig Tiller61b910f2015-02-15 10:54:07 -0800383 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800384% endif
385% endfor
386
nnoble69ac39f2014-12-12 15:43:38 -0800387dep_error:
388 @echo "You shouldn't see this message - all of your dependencies are correct."
389else
390all: dep_error git_update stop
391
392dep_error:
393 @echo
394 @echo "DEPENDENCY ERROR"
395 @echo
396 @echo "You are missing system dependencies that are essential to build grpc,"
397 @echo "and the third_party directory doesn't have them:"
398 @echo
399 @echo " $(DEP_MISSING)"
400 @echo
401 @echo "Installing the development packages for your system will solve"
402 @echo "this issue. Please consult INSTALL to get more information."
403 @echo
404 @echo "If you need information about why these tests failed, run:"
405 @echo
406 @echo " make run_dep_checks"
407 @echo
408endif
409
410git_update:
411ifeq ($(IS_GIT_FOLDER),true)
412 @echo "Additionally, since you are in a git clone, you can download the"
413 @echo "missing dependencies in third_party by running the following command:"
414 @echo
ctiller64f29102014-12-15 10:40:59 -0800415 @echo " git submodule update --init"
nnoble69ac39f2014-12-12 15:43:38 -0800416 @echo
417endif
418
419openssl_dep_error: openssl_dep_message git_update stop
420
Nicolas Noble53830622015-02-12 16:56:38 -0800421protobuf_dep_error: protobuf_dep_message git_update stop
422
423protoc_dep_error: protoc_dep_message git_update stop
424
nnoble69ac39f2014-12-12 15:43:38 -0800425openssl_dep_message:
426 @echo
427 @echo "DEPENDENCY ERROR"
428 @echo
429 @echo "The target you are trying to run requires OpenSSL with ALPN support."
430 @echo "Your system doesn't have it, and neither does the third_party directory."
431 @echo
432 @echo "Please consult INSTALL to get more information."
433 @echo
434 @echo "If you need information about why these tests failed, run:"
435 @echo
436 @echo " make run_dep_checks"
437 @echo
438
Nicolas Noble53830622015-02-12 16:56:38 -0800439protobuf_dep_message:
440 @echo
441 @echo "DEPENDENCY ERROR"
442 @echo
443 @echo "The target you are trying to run requires protobuf 3.0.0+"
444 @echo "Your system doesn't have it, and neither does the third_party directory."
445 @echo
446 @echo "Please consult INSTALL to get more information."
447 @echo
448 @echo "If you need information about why these tests failed, run:"
449 @echo
450 @echo " make run_dep_checks"
451 @echo
452
453protoc_dep_message:
454 @echo
455 @echo "DEPENDENCY ERROR"
456 @echo
457 @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
458 @echo "Your system doesn't have it, and neither does the third_party directory."
459 @echo
460 @echo "Please consult INSTALL to get more information."
461 @echo
462 @echo "If you need information about why these tests failed, run:"
463 @echo
464 @echo " make run_dep_checks"
465 @echo
466
nnoble69ac39f2014-12-12 15:43:38 -0800467stop:
468 @false
469
ctiller09cb6d52014-12-19 17:38:22 -0800470% for tgt in targets:
Craig Tiller61b910f2015-02-15 10:54:07 -0800471${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
ctiller09cb6d52014-12-19 17:38:22 -0800472% endfor
473
nnoble69ac39f2014-12-12 15:43:38 -0800474run_dep_checks:
nnoble69ac39f2014-12-12 15:43:38 -0800475 $(OPENSSL_ALPN_CHECK_CMD) || true
476 $(ZLIB_CHECK_CMD) || true
Nicolas Noble53830622015-02-12 16:56:38 -0800477 $(PERFTOOLS_CHECK_CMD) || true
478 $(PROTOBUF_CHECK_CMD) || true
479 $(PROTOC_CHECK_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800480
Craig Tiller61b910f2015-02-15 10:54:07 -0800481$(LIBDIR)/$(CONFIG)/zlib/libz.a:
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100482 $(E) "[MAKE] Building zlib"
483 $(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="-fPIC -fvisibility=hidden $(CPPFLAGS_$(CONFIG))" ./configure --static)
484 $(Q)$(MAKE) -C third_party/zlib clean
485 $(Q)$(MAKE) -C third_party/zlib
Craig Tiller61b910f2015-02-15 10:54:07 -0800486 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/zlib
487 $(Q)cp third_party/zlib/libz.a $(LIBDIR)/$(CONFIG)/zlib
nnoble69ac39f2014-12-12 15:43:38 -0800488
Craig Tiller61b910f2015-02-15 10:54:07 -0800489$(LIBDIR)/$(CONFIG)/openssl/libssl.a:
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800490 $(E) "[MAKE] Building openssl for $(SYSTEM)"
491ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee567fa92015-02-20 07:10:21 +0100492 $(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 -0800493else
Nicolas "Pixel" Noblee567fa92015-02-20 07:10:21 +0100494 $(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 -0800495endif
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100496 $(Q)$(MAKE) -C third_party/openssl clean
497 $(Q)$(MAKE) -C third_party/openssl build_crypto build_ssl
Craig Tiller61b910f2015-02-15 10:54:07 -0800498 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/openssl
499 $(Q)cp third_party/openssl/libssl.a third_party/openssl/libcrypto.a $(LIBDIR)/$(CONFIG)/openssl
nnoble69ac39f2014-12-12 15:43:38 -0800500
Nicolas Noble53830622015-02-12 16:56:38 -0800501third_party/protobuf/configure:
502 $(E) "[AUTOGEN] Preparing protobuf"
503 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
504
Craig Tiller61b910f2015-02-15 10:54:07 -0800505$(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
Nicolas Noble53830622015-02-12 16:56:38 -0800506 $(E) "[MAKE] Building protobuf"
Craig Tillercf133f42015-02-26 14:05:56 -0800507ifeq ($(HAVE_CXX11),true)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100508 $(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 -0800509else
510 $(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)
511endif
Nicolas Noble53830622015-02-12 16:56:38 -0800512 $(Q)$(MAKE) -C third_party/protobuf clean
513 $(Q)$(MAKE) -C third_party/protobuf
Craig Tiller61b910f2015-02-15 10:54:07 -0800514 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
515 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
516 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
517 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
518 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800519
nnoble29e1d292014-12-01 10:27:40 -0800520static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800521
Craig Tiller12c82092015-01-15 08:45:56 -0800522static_c: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800523% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800524% if lib.build == 'all' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800525 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800526% endif
527% endfor
528
529
Craig Tiller12c82092015-01-15 08:45:56 -0800530static_cxx: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800531% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800532% if lib.build == 'all' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800533 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
nnoble29e1d292014-12-01 10:27:40 -0800534% endif
535% endfor
536
537
538shared: shared_c shared_cxx
539
Craig Tiller12c82092015-01-15 08:45:56 -0800540shared_c: \
nnoble29e1d292014-12-01 10:27:40 -0800541% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800542% if lib.build == 'all' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800543 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800544% endif
545% endfor
546
547
Craig Tiller12c82092015-01-15 08:45:56 -0800548shared_cxx: \
nnoble29e1d292014-12-01 10:27:40 -0800549% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800550% if lib.build == 'all' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800551 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
nnoble29e1d292014-12-01 10:27:40 -0800552% endif
553% endfor
554
555
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800556shared_csharp: shared_c \
557% for lib in libs:
558% if lib.build == 'all' and lib.language == 'csharp':
559 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
560% endif
561% endfor
562
563grpc_csharp_ext: shared_csharp
564
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100565plugins: $(PROTOC_PLUGINS)
566
nnoble29e1d292014-12-01 10:27:40 -0800567privatelibs: privatelibs_c privatelibs_cxx
568
Craig Tiller12c82092015-01-15 08:45:56 -0800569privatelibs_c: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800570% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800571% if lib.build == 'private' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800572 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800573% endif
574% endfor
575
576
Craig Tiller12c82092015-01-15 08:45:56 -0800577privatelibs_cxx: \
nnoble29e1d292014-12-01 10:27:40 -0800578% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800579% if lib.build == 'private' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800580 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800581% endif
582% endfor
583
584
nnoble29e1d292014-12-01 10:27:40 -0800585buildtests: buildtests_c buildtests_cxx
586
Craig Tiller12c82092015-01-15 08:45:56 -0800587buildtests_c: privatelibs_c\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800588% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800589% if tgt.build == 'test' and not tgt.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800590 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800591% endif
592% endfor
593
594
Craig Tiller12c82092015-01-15 08:45:56 -0800595buildtests_cxx: privatelibs_cxx\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800596% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800597% if tgt.build == 'test' and tgt.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800598 $(BINDIR)/$(CONFIG)/${tgt.name}\
nnoble29e1d292014-12-01 10:27:40 -0800599% endif
600% endfor
601
602
nnoble85a49262014-12-08 18:14:03 -0800603test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -0800604
nnoble85a49262014-12-08 18:14:03 -0800605test_c: buildtests_c
nnoble29e1d292014-12-01 10:27:40 -0800606% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800607% if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++':
nnoble29e1d292014-12-01 10:27:40 -0800608 $(E) "[RUN] Testing ${tgt.name}"
Craig Tillerda224d62015-02-15 11:01:58 -0800609 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
nnoble29e1d292014-12-01 10:27:40 -0800610% endif
611% endfor
612
613
nnoble85a49262014-12-08 18:14:03 -0800614test_cxx: buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -0800615% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800616% if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++':
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800617 $(E) "[RUN] Testing ${tgt.name}"
Craig Tillerda224d62015-02-15 11:01:58 -0800618 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800619% endif
620% endfor
621
622
623tools: privatelibs\
624% for tgt in targets:
625% if tgt.build == 'tool':
Craig Tiller61b910f2015-02-15 10:54:07 -0800626 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800627% endif
628% endfor
629
630
631buildbenchmarks: privatelibs\
632% for tgt in targets:
633% if tgt.build == 'benchmark':
Craig Tiller61b910f2015-02-15 10:54:07 -0800634 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800635% endif
636% endfor
637
638
639benchmarks: buildbenchmarks
640
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800641strip: strip-static strip-shared
642
nnoble20e2e3f2014-12-16 15:37:57 -0800643strip-static: strip-static_c strip-static_cxx
644
645strip-shared: strip-shared_c strip-shared_cxx
646
Nicolas Noble047b7272015-01-16 13:55:05 -0800647
648# TODO(nnoble): the strip target is stripping in-place, instead
649# of copying files in a temporary folder.
650# This prevents proper debugging after running make install.
651
nnoble85a49262014-12-08 18:14:03 -0800652strip-static_c: static_c
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100653ifeq ($(CONFIG),opt)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800654% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800655% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800656% if lib.build == "all":
657 $(E) "[STRIP] Stripping lib${lib.name}.a"
Craig Tiller61b910f2015-02-15 10:54:07 -0800658 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800659% endif
nnoble85a49262014-12-08 18:14:03 -0800660% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800661% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100662endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800663
nnoble85a49262014-12-08 18:14:03 -0800664strip-static_cxx: static_cxx
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100665ifeq ($(CONFIG),opt)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800666% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800667% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800668% if lib.build == "all":
669 $(E) "[STRIP] Stripping lib${lib.name}.a"
Craig Tiller61b910f2015-02-15 10:54:07 -0800670 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
nnoble85a49262014-12-08 18:14:03 -0800671% endif
672% endif
673% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100674endif
nnoble85a49262014-12-08 18:14:03 -0800675
676strip-shared_c: shared_c
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100677ifeq ($(CONFIG),opt)
nnoble85a49262014-12-08 18:14:03 -0800678% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800679% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800680% if lib.build == "all":
681 $(E) "[STRIP] Stripping lib${lib.name}.so"
Craig Tiller61b910f2015-02-15 10:54:07 -0800682 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800683% endif
nnoble85a49262014-12-08 18:14:03 -0800684% endif
685% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100686endif
nnoble85a49262014-12-08 18:14:03 -0800687
688strip-shared_cxx: shared_cxx
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100689ifeq ($(CONFIG),opt)
nnoble85a49262014-12-08 18:14:03 -0800690% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800691% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800692% if lib.build == "all":
693 $(E) "[STRIP] Stripping lib${lib.name}.so"
Craig Tiller61b910f2015-02-15 10:54:07 -0800694 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
nnoble85a49262014-12-08 18:14:03 -0800695% endif
696% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800697% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100698endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800699
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800700strip-shared_csharp: shared_csharp
701ifeq ($(CONFIG),opt)
702% for lib in libs:
703% if lib.language == "csharp":
704% if lib.build == "all":
705 $(E) "[STRIP] Stripping lib${lib.name}.so"
706 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
707% endif
708% endif
709% endfor
710endif
711
nnoble72309c62014-12-12 11:42:26 -0800712% for p in protos:
Nicolas Noble53830622015-02-12 16:56:38 -0800713ifeq ($(NO_PROTOC),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800714$(GENDIR)/${p}.pb.cc: protoc_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800715else
Craig Tiller61b910f2015-02-15 10:54:07 -0800716$(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800717 $(E) "[PROTOC] Generating protobuf CC file from $<"
718 $(Q) mkdir -p `dirname $@`
Vijay Pai850290f2015-02-19 09:59:44 -0800719 $(Q) $(PROTOC) --cpp_out=$(GENDIR) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $<
Nicolas Noble53830622015-02-12 16:56:38 -0800720endif
nnoble72309c62014-12-12 11:42:26 -0800721
722% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800723
Craig Tiller61b910f2015-02-15 10:54:07 -0800724$(OBJDIR)/$(CONFIG)/%.o : %.c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800725 $(E) "[C] Compiling $<"
726 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800727 $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800728
Craig Tiller61b910f2015-02-15 10:54:07 -0800729$(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800730 $(E) "[CXX] Compiling $<"
731 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800732 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800733
Craig Tiller61b910f2015-02-15 10:54:07 -0800734$(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
nnoble72309c62014-12-12 11:42:26 -0800735 $(E) "[HOSTCXX] Compiling $<"
736 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800737 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -0800738
Craig Tiller61b910f2015-02-15 10:54:07 -0800739$(OBJDIR)/$(CONFIG)/%.o : %.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800740 $(E) "[CXX] Compiling $<"
741 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800742 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800743
744
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +0100745install: install_c install_cxx install-plugins install-certs verify-install
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800746
nnoble85a49262014-12-08 18:14:03 -0800747install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800748
nnoble85a49262014-12-08 18:14:03 -0800749install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
750
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800751install_csharp: install-shared_csharp install_c
752
753install_grpc_csharp_ext: install_csharp
754
nnoble85a49262014-12-08 18:14:03 -0800755install-headers: install-headers_c install-headers_cxx
756
757install-headers_c:
758 $(E) "[INSTALL] Installing public C headers"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100759 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -0800760 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
761
762install-headers_cxx:
763 $(E) "[INSTALL] Installing public C++ headers"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100764 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -0800765 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
766
767install-static: install-static_c install-static_cxx
768
769install-static_c: static_c strip-static_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800770% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800771% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800772% if lib.build == "all":
773 $(E) "[INSTALL] Installing lib${lib.name}.a"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100774 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800775 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800776% endif
nnoble85a49262014-12-08 18:14:03 -0800777% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800778% endfor
779
nnoble85a49262014-12-08 18:14:03 -0800780install-static_cxx: static_cxx strip-static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800781% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800782% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800783% if lib.build == "all":
784 $(E) "[INSTALL] Installing lib${lib.name}.a"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100785 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800786 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
nnoble85a49262014-12-08 18:14:03 -0800787% endif
788% endif
789% endfor
790
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100791<%def name="install_shared(lang_filter)">\
nnoble85a49262014-12-08 18:14:03 -0800792% for lib in libs:
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100793% if lib.language == lang_filter:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800794% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -0800795ifeq ($(SYSTEM),MINGW32)
796 $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100797 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800798 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT)
799 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
nnoble5b7f32a2014-12-22 08:12:44 -0800800else
801 $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100802 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800803 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT)
nnoble5b7f32a2014-12-22 08:12:44 -0800804ifneq ($(SYSTEM),Darwin)
805 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
806endif
807endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800808% endif
nnoble85a49262014-12-08 18:14:03 -0800809% endif
810% endfor
nnoble5b7f32a2014-12-22 08:12:44 -0800811ifneq ($(SYSTEM),MINGW32)
812ifneq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblecc2b42a2015-02-20 00:42:21 +0100813 $(Q) ldconfig || true
nnoble5b7f32a2014-12-22 08:12:44 -0800814endif
815endif
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100816</%def>
nnoble85a49262014-12-08 18:14:03 -0800817
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100818install-shared_c: shared_c strip-shared_c
819${install_shared("c")}
820
821install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c
822${install_shared("c++")}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800823
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800824install-shared_csharp: shared_csharp strip-shared_csharp
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100825${install_shared("csharp")}
826
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100827install-plugins: $(PROTOC_PLUGINS)
828ifeq ($(SYSTEM),MINGW32)
829 $(Q) false
830else
831 $(E) "[INSTALL] Installing grpc protoc plugins"
832% for tgt in targets:
833% if tgt.build == 'protoc':
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100834 $(Q) $(INSTALL) -d $(prefix)/bin
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100835 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
836% endif
837% endfor
838endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800839
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +0100840install-certs: etc/roots.pem
841 $(E) "[INSTALL] Installing root certificates"
842 $(Q) $(INSTALL) -d $(prefix)/share/grpc
843 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
844
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100845verify-install:
Nicolas "Pixel" Noble2c23a722015-02-24 20:17:45 +0100846ifeq ($(INSTALL_OK),true)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100847 @echo "Your system looks ready to go."
848 @echo
849else
850 @echo "Your system doesn't have protoc 3.0.0+ installed. While this"
851 @echo "won't prevent grpc from working, you won't be able to compile"
852 @echo "and run any meaningful code with it."
853 @echo
854 @echo
855 @echo "Please download and install protobuf 3.0.0+ from:"
856 @echo
857 @echo " https://github.com/google/protobuf/releases"
858 @echo
859 @echo "Once you've done so, you can re-run this check by doing:"
860 @echo
861 @echo " make verify-install"
862endif
863
Craig Tiller3759e6f2015-01-15 08:13:11 -0800864clean:
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100865 $(E) "[CLEAN] Cleaning build directories."
Craig Tillerda224d62015-02-15 11:01:58 -0800866 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800867
868
869# The various libraries
870
871% for lib in libs:
872${makelib(lib)}
873% endfor
874
875
nnoble69ac39f2014-12-12 15:43:38 -0800876# All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800877
878% for tgt in targets:
879${maketarget(tgt)}
880% endfor
881
882<%def name="makelib(lib)">
883LIB${lib.name.upper()}_SRC = \\
884
885% for src in lib.src:
nnoble72309c62014-12-12 11:42:26 -0800886 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800887
888% endfor
889
890% if "public_headers" in lib:
Craig Tiller59140fc2015-01-18 10:12:17 -0800891% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800892PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800893
nnoble85a49262014-12-08 18:14:03 -0800894% else:
895PUBLIC_HEADERS_C += \\
896
897% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800898% for hdr in lib.public_headers:
899 ${hdr} \\
900
901% endfor
902% endif
903
Craig Tiller61b910f2015-02-15 10:54:07 -0800904LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800905
Nicolas Noble047b7272015-01-16 13:55:05 -0800906## If the library requires OpenSSL with ALPN, let's add some restrictions.
nnoble69ac39f2014-12-12 15:43:38 -0800907% if lib.get('secure', True):
nnoble69ac39f2014-12-12 15:43:38 -0800908ifeq ($(NO_SECURE),true)
909
Nicolas Noble047b7272015-01-16 13:55:05 -0800910# You can't build secure libraries if you don't have OpenSSL with ALPN.
911
Craig Tiller61b910f2015-02-15 10:54:07 -0800912$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -0800913
nnoble5b7f32a2014-12-22 08:12:44 -0800914% if lib.build == "all":
915ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -0800916$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -0800917else
Craig Tiller61b910f2015-02-15 10:54:07 -0800918$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -0800919endif
920% endif
921
nnoble69ac39f2014-12-12 15:43:38 -0800922else
923
Nicolas Noble53830622015-02-12 16:56:38 -0800924% if lib.language == 'c++':
925ifeq ($(NO_PROTOBUF),true)
926
927# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
928
Craig Tiller61b910f2015-02-15 10:54:07 -0800929$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800930
931% if lib.build == "all":
932ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -0800933$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800934else
Craig Tiller61b910f2015-02-15 10:54:07 -0800935$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800936endif
937% endif
938
939else
940% endif
941
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100942ifneq ($(OPENSSL_DEP),)
Nicolas Noble53830622015-02-12 16:56:38 -0800943# This is to ensure the embedded OpenSSL is built beforehand, properly
944# installing headers to their final destination on the drive. We need this
945# otherwise parallel compilation will fail if a source is compiled first.
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100946% for src in lib.src:
947${src}: $(OPENSSL_DEP)
948% endfor
949endif
950
Craig Tiller61b910f2015-02-15 10:54:07 -0800951$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
Nicolas Noble047b7272015-01-16 13:55:05 -0800952## The else here corresponds to the if secure earlier.
nnoble20e2e3f2014-12-16 15:37:57 -0800953% else:
Nicolas Noble53830622015-02-12 16:56:38 -0800954% if lib.language == 'c++':
955ifeq ($(NO_PROTOBUF),true)
956
957# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
958
Craig Tiller61b910f2015-02-15 10:54:07 -0800959$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800960
961% if lib.build == "all":
962ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -0800963$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800964else
Craig Tiller61b910f2015-02-15 10:54:07 -0800965$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800966endif
nnoble20e2e3f2014-12-16 15:37:57 -0800967% endif
Nicolas Noble53830622015-02-12 16:56:38 -0800968
969else
970
971% endif
Craig Tiller61b910f2015-02-15 10:54:07 -0800972$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP)\
Nicolas Noble53830622015-02-12 16:56:38 -0800973% endif
974% if lib.language == 'c++':
975 $(PROTOBUF_DEP)\
976% endif
977 $(LIB${lib.name.upper()}_OBJS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800978 $(E) "[AR] Creating $@"
nnoble85a49262014-12-08 18:14:03 -0800979 $(Q) mkdir -p `dirname $@`
Craig Tiller61b910f2015-02-15 10:54:07 -0800980 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
981 $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
nnoble20e2e3f2014-12-16 15:37:57 -0800982% if lib.get('baselib', False):
983% if lib.get('secure', True):
Craig Tillerf5371ef2015-01-12 16:40:18 -0800984 $(Q) rm -rf tmp-merge
nnoble20e2e3f2014-12-16 15:37:57 -0800985 $(Q) mkdir tmp-merge
Craig Tillerda224d62015-02-15 11:01:58 -0800986 $(Q) ( cd tmp-merge ; $(AR) x ../$(LIBDIR)/$(CONFIG)/lib${lib.name}.a )
nnoble20e2e3f2014-12-16 15:37:57 -0800987 $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge ; <%text>ar x ../$${l}</%text> ) ; done
Craig Tiller61b910f2015-02-15 10:54:07 -0800988 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge/__.SYMDEF*
989 $(Q) ar rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge/*
nnoble20e2e3f2014-12-16 15:37:57 -0800990 $(Q) rm -rf tmp-merge
991% endif
992% endif
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800993ifeq ($(SYSTEM),Darwin)
Craig Tiller61b910f2015-02-15 10:54:07 -0800994 $(Q) ranlib $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800995endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800996
nnoble5b7f32a2014-12-22 08:12:44 -0800997<%
Craig Tiller59140fc2015-01-18 10:12:17 -0800998 if lib.language == 'c++':
nnoble5b7f32a2014-12-22 08:12:44 -0800999 ld = '$(LDXX)'
1000 else:
1001 ld = '$(LD)'
1002
Craig Tillerda224d62015-02-15 11:01:58 -08001003 out_base = '$(LIBDIR)/$(CONFIG)/' + lib.name
1004 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name
nnoble5b7f32a2014-12-22 08:12:44 -08001005
1006 common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
1007
1008 libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +01001009 lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -08001010 mingw_libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +01001011 mingw_lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -08001012 for dep in lib.get('deps', []):
1013 libs = libs + ' -l' + dep
Craig Tiller61b910f2015-02-15 10:54:07 -08001014 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001015 mingw_libs = mingw_libs + ' -l' + dep + '-imp'
Craig Tillerda224d62015-02-15 11:01:58 -08001016 mingw_lib_deps = mingw_lib_deps + '$(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001017
1018 if lib.get('secure', True):
1019 common = common + ' $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS)'
1020 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1021 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001022
1023 if lib.language == 'c++':
1024 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
nnoble5b7f32a2014-12-22 08:12:44 -08001025%>
1026
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001027% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -08001028ifeq ($(SYSTEM),MINGW32)
1029${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001030 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -08001031 $(Q) mkdir -p `dirname $@`
Craig Tillerda224d62015-02-15 11:01:58 -08001032 $(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 -08001033else
1034${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
1035 $(E) "[LD] Linking $@"
1036 $(Q) mkdir -p `dirname $@`
1037ifeq ($(SYSTEM),Darwin)
Craig Tillerda224d62015-02-15 11:01:58 -08001038 $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
nnoble5b7f32a2014-12-22 08:12:44 -08001039else
Craig Tillerda224d62015-02-15 11:01:58 -08001040 $(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 +01001041 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major}
nnoble5b7f32a2014-12-22 08:12:44 -08001042 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so
1043endif
1044endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001045% endif
Nicolas Noble53830622015-02-12 16:56:38 -08001046% if lib.get('secure', True):
Nicolas Noble047b7272015-01-16 13:55:05 -08001047## If the lib was secure, we have to close the Makefile's if that tested
1048## the presence of an ALPN-capable OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001049
1050endif
1051% endif
1052% if lib.language == 'c++':
1053## If the lib was C++, we have to close the Makefile's if that tested
1054## the presence of protobuf 3.0.0+
nnoble69ac39f2014-12-12 15:43:38 -08001055
1056endif
1057% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001058
nnoble69ac39f2014-12-12 15:43:38 -08001059% if lib.get('secure', True):
1060ifneq ($(NO_SECURE),true)
1061% endif
1062ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -08001063-include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001064endif
nnoble69ac39f2014-12-12 15:43:38 -08001065% if lib.get('secure', True):
1066endif
1067% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001068
Craig Tiller27715ca2015-01-12 16:55:59 -08001069% for src in lib.src:
1070% if not proto_re.match(src):
Craig Tiller61b910f2015-02-15 10:54:07 -08001071$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
Craig Tiller27715ca2015-01-12 16:55:59 -08001072% for src2 in lib.src:
1073% if proto_re.match(src2):
1074 ${proto_to_cc(src2)}\
1075% endif
1076% endfor
1077% endif
1078
1079% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001080</%def>
1081
1082<%def name="maketarget(tgt)">
1083${tgt.name.upper()}_SRC = \\
1084
1085% for src in tgt.src:
nnoble72309c62014-12-12 11:42:26 -08001086 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001087
1088% endfor
1089
Craig Tiller61b910f2015-02-15 10:54:07 -08001090${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001091
nnoble69ac39f2014-12-12 15:43:38 -08001092% if tgt.get('secure', True):
1093ifeq ($(NO_SECURE),true)
1094
Nicolas Noble047b7272015-01-16 13:55:05 -08001095# You can't build secure targets if you don't have OpenSSL with ALPN.
1096
Craig Tiller61b910f2015-02-15 10:54:07 -08001097$(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001098
1099else
1100
1101% endif
Nicolas Noble047b7272015-01-16 13:55:05 -08001102##
1103## We're not trying to add a dependency on building zlib and openssl here,
1104## as it's already done in the libraries. We're assuming that the build
1105## trickles down, and that a secure target requires a secure version of
1106## a library.
1107##
1108## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1109## I can live with that.
1110##
Nicolas Noble53830622015-02-12 16:56:38 -08001111% if tgt.build == 'protoc':
1112
1113ifeq ($(NO_PROTOBUF),true)
1114
1115# You can't build the protoc plugins if you don't have protobuf 3.0.0+.
1116
Craig Tiller61b910f2015-02-15 10:54:07 -08001117$(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001118
1119else
1120
Craig Tiller61b910f2015-02-15 10:54:07 -08001121$(BINDIR)/$(CONFIG)/${tgt.name}: $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
Nicolas Noble53830622015-02-12 16:56:38 -08001122% else:
Craig Tiller61b910f2015-02-15 10:54:07 -08001123$(BINDIR)/$(CONFIG)/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
Nicolas Noble53830622015-02-12 16:56:38 -08001124% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001125% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001126 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001127% endfor
1128
Craig Tiller59140fc2015-01-18 10:12:17 -08001129% if tgt.language == "c++":
Nicolas Noble047b7272015-01-16 13:55:05 -08001130## C++ targets specificies.
nnoble72309c62014-12-12 11:42:26 -08001131% if tgt.build == 'protoc':
1132 $(E) "[HOSTLD] Linking $@"
1133 $(Q) mkdir -p `dirname $@`
1134 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(${tgt.name.upper()}_OBJS)\
1135% else:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001136 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -08001137 $(Q) mkdir -p `dirname $@`
nnoblec78b3402014-12-11 16:06:57 -08001138 $(Q) $(LDXX) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
nnoble72309c62014-12-12 11:42:26 -08001139% endif
nnoblec78b3402014-12-11 16:06:57 -08001140% if tgt.build == 'test':
1141 $(GTEST_LIB)\
1142% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001143% else:
Nicolas Noble047b7272015-01-16 13:55:05 -08001144## C-only targets specificities.
nnoble72309c62014-12-12 11:42:26 -08001145 $(E) "[LD] Linking $@"
1146 $(Q) mkdir -p `dirname $@`
nnoble5b7f32a2014-12-22 08:12:44 -08001147 $(Q) $(LD) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001148% endif
1149% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001150 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001151% endfor
Craig Tiller59140fc2015-01-18 10:12:17 -08001152% if tgt.language == "c++":
nnoble72309c62014-12-12 11:42:26 -08001153% if tgt.build == 'protoc':
Nicolas Noble53830622015-02-12 16:56:38 -08001154 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
nnoble72309c62014-12-12 11:42:26 -08001155% else:
Nicolas Noble53830622015-02-12 16:56:38 -08001156 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001157% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001158% endif
nnoblec78b3402014-12-11 16:06:57 -08001159% if tgt.build == 'protoc':
nnoble72309c62014-12-12 11:42:26 -08001160 $(HOST_LDLIBS)\
1161% else:
1162 $(LDLIBS)\
1163% endif
1164% if tgt.build == 'protoc':
1165 $(HOST_LDLIBS_PROTOC)\
1166% elif tgt.get('secure', True):
1167 $(LDLIBS_SECURE)\
nnoblec78b3402014-12-11 16:06:57 -08001168% endif
Craig Tiller61b910f2015-02-15 10:54:07 -08001169 -o $(BINDIR)/$(CONFIG)/${tgt.name}
Nicolas Noble53830622015-02-12 16:56:38 -08001170% if tgt.build == 'protoc':
1171
1172endif
1173% endif
nnoble69ac39f2014-12-12 15:43:38 -08001174% if tgt.get('secure', True):
1175
1176endif
1177% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001178
Craig Tillerf5371ef2015-01-12 16:40:18 -08001179% for src in tgt.src:
Craig Tiller61b910f2015-02-15 10:54:07 -08001180$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
Craig Tillerf5371ef2015-01-12 16:40:18 -08001181% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001182 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Craig Tillerf5371ef2015-01-12 16:40:18 -08001183% endfor
1184
1185% endfor
1186
Craig Tiller8f126a62015-01-15 08:50:19 -08001187deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001188
nnoble69ac39f2014-12-12 15:43:38 -08001189% if tgt.get('secure', True):
1190ifneq ($(NO_SECURE),true)
1191% endif
1192ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -08001193-include $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001194endif
nnoble69ac39f2014-12-12 15:43:38 -08001195% if tgt.get('secure', True):
1196endif
1197% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001198</%def>
1199
nnoble85a49262014-12-08 18:14:03 -08001200.PHONY: all strip tools \
nnoble69ac39f2014-12-12 15:43:38 -08001201dep_error openssl_dep_error openssl_dep_message git_update stop \
nnoble85a49262014-12-08 18:14:03 -08001202buildtests buildtests_c buildtests_cxx \
1203test test_c test_cxx \
1204install install_c install_cxx \
1205install-headers install-headers_c install-headers_cxx \
1206install-shared install-shared_c install-shared_cxx \
1207install-static install-static_c install-static_cxx \
1208strip strip-shared strip-static \
1209strip_c strip-shared_c strip-static_c \
1210strip_cxx strip-shared_cxx strip-static_cxx \
Craig Tillerf0afe502015-01-15 09:04:49 -08001211dep_c dep_cxx bins_dep_c bins_dep_cxx \
Craig Tiller12c82092015-01-15 08:45:56 -08001212clean
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001213