blob: 0984a6d008ed6dadaa4af5953d43e33ea28706f7 [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
172# The HOST compiler settings are used to compile the protoc plugins.
173# In most cases, you won't have to change anything, but if you are
174# cross-compiling, you can override these variables from GNU make's
175# command line: make CC=cross-gcc HOST_CC=gcc
176
nnoble72309c62014-12-12 11:42:26 -0800177HOST_CC = $(CC)
178HOST_CXX = $(CXX)
179HOST_LD = $(LD)
180HOST_LDXX = $(LDXX)
181
ctillercab52e72015-01-06 13:10:23 -0800182CPPFLAGS += $(CPPFLAGS_$(CONFIG))
Nicolas "Pixel" Noble72743822015-02-20 20:59:29 +0100183DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
ctiller8cfebb92015-01-06 15:02:12 -0800184LDFLAGS += $(LDFLAGS_$(CONFIG))
ctillercab52e72015-01-06 13:10:23 -0800185
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800186CFLAGS += -std=c89 -pedantic
187CXXFLAGS += -std=c++11
Nicolas "Pixel" Noble213ed912015-01-30 02:11:35 +0100188CPPFLAGS += -g -fPIC -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
Craig Tiller96b49552015-01-21 16:29:01 -0800189LDFLAGS += -g -fPIC
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800190
Craig Tillerda224d62015-02-15 11:01:58 -0800191INCLUDES = . include $(GENDIR)
Craig Tiller96b49552015-01-21 16:29:01 -0800192ifeq ($(SYSTEM),Darwin)
vjpai7cc2c302015-02-18 12:33:37 -0800193INCLUDES += /usr/local/ssl/include /opt/local/include
Craig Tiller96b49552015-01-21 16:29:01 -0800194LIBS = m z
vjpai7cc2c302015-02-18 12:33:37 -0800195LDFLAGS += -L/usr/local/ssl/lib -L/opt/local/lib
Craig Tiller96b49552015-01-21 16:29:01 -0800196else
ctillerc008ae52015-01-07 15:33:00 -0800197LIBS = rt m z pthread
Craig Tiller96b49552015-01-21 16:29:01 -0800198LDFLAGS += -pthread
199endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800200
201ifneq ($(wildcard /usr/src/gtest/src/gtest-all.cc),)
202GTEST_LIB = /usr/src/gtest/src/gtest-all.cc -I/usr/src/gtest
203else
204GTEST_LIB = -lgtest
205endif
chenwa8fd44a2014-12-10 15:13:55 -0800206GTEST_LIB += -lgflags
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800207ifeq ($(V),1)
208E = @:
209Q =
210else
211E = @echo
212Q = @
213endif
214
215VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build}
216
217CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
218CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
219
220LDFLAGS += $(ARCH_FLAGS)
221LDLIBS += $(addprefix -l, $(LIBS))
222LDLIBSXX += $(addprefix -l, $(LIBSXX))
nnoble72309c62014-12-12 11:42:26 -0800223
224HOST_CPPFLAGS = $(CPPFLAGS)
225HOST_CFLAGS = $(CFLAGS)
226HOST_CXXFLAGS = $(CXXFLAGS)
227HOST_LDFLAGS = $(LDFLAGS)
228HOST_LDLIBS = $(LDLIBS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800229
nnoble69ac39f2014-12-12 15:43:38 -0800230
231# These are automatically computed variables.
232# There shouldn't be any need to change anything from now on.
233
nnoble5b7f32a2014-12-22 08:12:44 -0800234ifeq ($(SYSTEM),MINGW32)
235SHARED_EXT = dll
236endif
237ifeq ($(SYSTEM),Darwin)
238SHARED_EXT = dylib
239endif
240ifeq ($(SHARED_EXT),)
241SHARED_EXT = so.$(VERSION)
242endif
243
nnoble69ac39f2014-12-12 15:43:38 -0800244ifeq ($(wildcard .git),)
245IS_GIT_FOLDER = false
246else
247IS_GIT_FOLDER = true
248endif
249
nnoble7e012cf2014-12-22 17:53:44 -0800250OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/openssl-alpn.c -lssl -lcrypto -ldl $(LDFLAGS)
251ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/zlib.c -lz $(LDFLAGS)
Craig Tiller297fafa2015-01-15 15:46:39 -0800252PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/perftools.c -lprofiler $(LDFLAGS)
Nicolas Noble53830622015-02-12 16:56:38 -0800253PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o /dev/null test/build/protobuf.cc -lprotobuf $(LDFLAGS)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100254PROTOC_CMD = which protoc
Nicolas Noble53830622015-02-12 16:56:38 -0800255PROTOC_CHECK_CMD = protoc --version | grep -q libprotoc.3
Craig Tiller297fafa2015-01-15 15:46:39 -0800256
Craig Tiller50524cc2015-01-29 23:00:00 -0800257ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
Craig Tiller297fafa2015-01-15 15:46:39 -0800258HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
259ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
260DEFINES += GRPC_HAVE_PERFTOOLS
261LIBS += profiler
262endif
Craig Tiller50524cc2015-01-29 23:00:00 -0800263endif
nnoble69ac39f2014-12-12 15:43:38 -0800264
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100265HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
Craig Tillerc4da6b72015-01-15 08:01:14 -0800266ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
nnoble60825402014-12-15 14:43:51 -0800267HAS_SYSTEM_OPENSSL_ALPN = $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
268HAS_SYSTEM_ZLIB = $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100269HAS_SYSTEM_PROTOBUF = $(HAS_SYSTEM_PROTOBUF_VERIFY)
Craig Tillerc4da6b72015-01-15 08:01:14 -0800270else
271# override system libraries if the config requires a custom compiled library
272HAS_SYSTEM_OPENSSL_ALPN = false
273HAS_SYSTEM_ZLIB = false
Nicolas Noble53830622015-02-12 16:56:38 -0800274HAS_SYSTEM_PROTOBUF = false
Craig Tillerc4da6b72015-01-15 08:01:14 -0800275endif
nnoble69ac39f2014-12-12 15:43:38 -0800276
Yang Gao044fe222015-02-24 12:59:38 -0800277HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100278ifeq ($(HAS_PROTOC),true)
Nicolas Noble53830622015-02-12 16:56:38 -0800279HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100280else
281HAS_VALID_PROTOC = false
282endif
Nicolas Noble53830622015-02-12 16:56:38 -0800283
nnoble69ac39f2014-12-12 15:43:38 -0800284ifeq ($(wildcard third_party/openssl/ssl/ssl.h),)
285HAS_EMBEDDED_OPENSSL_ALPN = false
286else
287HAS_EMBEDDED_OPENSSL_ALPN = true
288endif
289
290ifeq ($(wildcard third_party/zlib/zlib.h),)
291HAS_EMBEDDED_ZLIB = false
292else
293HAS_EMBEDDED_ZLIB = true
294endif
295
Nicolas Noble53830622015-02-12 16:56:38 -0800296ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
297HAS_EMBEDDED_PROTOBUF = false
298ifneq ($(HAS_VALID_PROTOC),true)
299NO_PROTOC = true
300endif
301else
302HAS_EMBEDDED_PROTOBUF = true
303endif
304
nnoble69ac39f2014-12-12 15:43:38 -0800305ifeq ($(HAS_SYSTEM_ZLIB),false)
306ifeq ($(HAS_EMBEDDED_ZLIB),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800307ZLIB_DEP = $(LIBDIR)/$(CONFIG)/zlib/libz.a
nnoble69ac39f2014-12-12 15:43:38 -0800308CPPFLAGS += -Ithird_party/zlib
Craig Tillerda224d62015-02-15 11:01:58 -0800309LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib
nnoble69ac39f2014-12-12 15:43:38 -0800310else
311DEP_MISSING += zlib
312endif
313endif
314
315ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false)
316ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800317OPENSSL_DEP = $(LIBDIR)/$(CONFIG)/openssl/libssl.a
318OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/openssl/libssl.a $(LIBDIR)/$(CONFIG)/openssl/libcrypto.a
Craig Tillerec043032015-02-20 17:24:41 -0800319# need to prefix these to ensure overriding system libraries
320CPPFLAGS := -Ithird_party/openssl/include $(CPPFLAGS)
321LDFLAGS := -L$(LIBDIR)/$(CONFIG)/openssl $(LDFLAGS)
nnoble5b7f32a2014-12-22 08:12:44 -0800322LIBS_SECURE = dl
nnoble69ac39f2014-12-12 15:43:38 -0800323else
324NO_SECURE = true
325endif
nnoble5b7f32a2014-12-22 08:12:44 -0800326else
327LIBS_SECURE = ssl crypto dl
nnoble69ac39f2014-12-12 15:43:38 -0800328endif
329
nnoble5b7f32a2014-12-22 08:12:44 -0800330LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
331
Nicolas Noble53830622015-02-12 16:56:38 -0800332ifeq ($(HAS_SYSTEM_PROTOBUF),false)
333ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800334PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
Craig Tiller9ec95fa2015-02-20 20:36:21 -0800335CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
336LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
Craig Tiller61b910f2015-02-15 10:54:07 -0800337PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
Nicolas Noble53830622015-02-12 16:56:38 -0800338else
339NO_PROTOBUF = true
340endif
341else
342endif
343
344LIBS_PROTOBUF = protobuf
345LIBS_PROTOC = protoc protobuf
346
347LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
348HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
349
Craig Tiller12c82092015-01-15 08:45:56 -0800350ifeq ($(MAKECMDGOALS),clean)
nnoble69ac39f2014-12-12 15:43:38 -0800351NO_DEPS = true
352endif
353
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100354INSTALL_OK = false
355ifeq ($(HAS_VALID_PROTOC),true)
356ifeq ($(HAS_SYSTEM_PROTOBUF_VERIFY),true)
357INSTALL_OK = true
358endif
359endif
360
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800361.SECONDARY = %.pb.h %.pb.cc
362
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100363PROTOC_PLUGINS =\
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800364% for tgt in targets:
365% if tgt.build == 'protoc':
Craig Tiller61b910f2015-02-15 10:54:07 -0800366 $(BINDIR)/$(CONFIG)/${tgt.name}\
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800367% endif
368% endfor
369
nnoble69ac39f2014-12-12 15:43:38 -0800370ifeq ($(DEP_MISSING),)
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100371all: static shared plugins\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800372% for tgt in targets:
373% if tgt.build == 'all':
Craig Tiller61b910f2015-02-15 10:54:07 -0800374 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800375% endif
376% endfor
377
nnoble69ac39f2014-12-12 15:43:38 -0800378dep_error:
379 @echo "You shouldn't see this message - all of your dependencies are correct."
380else
381all: dep_error git_update stop
382
383dep_error:
384 @echo
385 @echo "DEPENDENCY ERROR"
386 @echo
387 @echo "You are missing system dependencies that are essential to build grpc,"
388 @echo "and the third_party directory doesn't have them:"
389 @echo
390 @echo " $(DEP_MISSING)"
391 @echo
392 @echo "Installing the development packages for your system will solve"
393 @echo "this issue. Please consult INSTALL to get more information."
394 @echo
395 @echo "If you need information about why these tests failed, run:"
396 @echo
397 @echo " make run_dep_checks"
398 @echo
399endif
400
401git_update:
402ifeq ($(IS_GIT_FOLDER),true)
403 @echo "Additionally, since you are in a git clone, you can download the"
404 @echo "missing dependencies in third_party by running the following command:"
405 @echo
ctiller64f29102014-12-15 10:40:59 -0800406 @echo " git submodule update --init"
nnoble69ac39f2014-12-12 15:43:38 -0800407 @echo
408endif
409
410openssl_dep_error: openssl_dep_message git_update stop
411
Nicolas Noble53830622015-02-12 16:56:38 -0800412protobuf_dep_error: protobuf_dep_message git_update stop
413
414protoc_dep_error: protoc_dep_message git_update stop
415
nnoble69ac39f2014-12-12 15:43:38 -0800416openssl_dep_message:
417 @echo
418 @echo "DEPENDENCY ERROR"
419 @echo
420 @echo "The target you are trying to run requires OpenSSL with ALPN support."
421 @echo "Your system doesn't have it, and neither does the third_party directory."
422 @echo
423 @echo "Please consult INSTALL to get more information."
424 @echo
425 @echo "If you need information about why these tests failed, run:"
426 @echo
427 @echo " make run_dep_checks"
428 @echo
429
Nicolas Noble53830622015-02-12 16:56:38 -0800430protobuf_dep_message:
431 @echo
432 @echo "DEPENDENCY ERROR"
433 @echo
434 @echo "The target you are trying to run requires protobuf 3.0.0+"
435 @echo "Your system doesn't have it, and neither does the third_party directory."
436 @echo
437 @echo "Please consult INSTALL to get more information."
438 @echo
439 @echo "If you need information about why these tests failed, run:"
440 @echo
441 @echo " make run_dep_checks"
442 @echo
443
444protoc_dep_message:
445 @echo
446 @echo "DEPENDENCY ERROR"
447 @echo
448 @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
449 @echo "Your system doesn't have it, and neither does the third_party directory."
450 @echo
451 @echo "Please consult INSTALL to get more information."
452 @echo
453 @echo "If you need information about why these tests failed, run:"
454 @echo
455 @echo " make run_dep_checks"
456 @echo
457
nnoble69ac39f2014-12-12 15:43:38 -0800458stop:
459 @false
460
ctiller09cb6d52014-12-19 17:38:22 -0800461% for tgt in targets:
Craig Tiller61b910f2015-02-15 10:54:07 -0800462${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
ctiller09cb6d52014-12-19 17:38:22 -0800463% endfor
464
nnoble69ac39f2014-12-12 15:43:38 -0800465run_dep_checks:
nnoble69ac39f2014-12-12 15:43:38 -0800466 $(OPENSSL_ALPN_CHECK_CMD) || true
467 $(ZLIB_CHECK_CMD) || true
Nicolas Noble53830622015-02-12 16:56:38 -0800468 $(PERFTOOLS_CHECK_CMD) || true
469 $(PROTOBUF_CHECK_CMD) || true
470 $(PROTOC_CHECK_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800471
Craig Tiller61b910f2015-02-15 10:54:07 -0800472$(LIBDIR)/$(CONFIG)/zlib/libz.a:
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100473 $(E) "[MAKE] Building zlib"
474 $(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="-fPIC -fvisibility=hidden $(CPPFLAGS_$(CONFIG))" ./configure --static)
475 $(Q)$(MAKE) -C third_party/zlib clean
476 $(Q)$(MAKE) -C third_party/zlib
Craig Tiller61b910f2015-02-15 10:54:07 -0800477 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/zlib
478 $(Q)cp third_party/zlib/libz.a $(LIBDIR)/$(CONFIG)/zlib
nnoble69ac39f2014-12-12 15:43:38 -0800479
Craig Tiller61b910f2015-02-15 10:54:07 -0800480$(LIBDIR)/$(CONFIG)/openssl/libssl.a:
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800481 $(E) "[MAKE] Building openssl for $(SYSTEM)"
482ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee567fa92015-02-20 07:10:21 +0100483 $(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 -0800484else
Nicolas "Pixel" Noblee567fa92015-02-20 07:10:21 +0100485 $(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 -0800486endif
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100487 $(Q)$(MAKE) -C third_party/openssl clean
488 $(Q)$(MAKE) -C third_party/openssl build_crypto build_ssl
Craig Tiller61b910f2015-02-15 10:54:07 -0800489 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/openssl
490 $(Q)cp third_party/openssl/libssl.a third_party/openssl/libcrypto.a $(LIBDIR)/$(CONFIG)/openssl
nnoble69ac39f2014-12-12 15:43:38 -0800491
Nicolas Noble53830622015-02-12 16:56:38 -0800492third_party/protobuf/configure:
493 $(E) "[AUTOGEN] Preparing protobuf"
494 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
495
Craig Tiller61b910f2015-02-15 10:54:07 -0800496$(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
Nicolas Noble53830622015-02-12 16:56:38 -0800497 $(E) "[MAKE] Building protobuf"
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100498 $(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)
Nicolas Noble53830622015-02-12 16:56:38 -0800499 $(Q)$(MAKE) -C third_party/protobuf clean
500 $(Q)$(MAKE) -C third_party/protobuf
Craig Tiller61b910f2015-02-15 10:54:07 -0800501 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
502 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
503 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
504 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
505 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800506
nnoble29e1d292014-12-01 10:27:40 -0800507static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800508
Craig Tiller12c82092015-01-15 08:45:56 -0800509static_c: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800510% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800511% if lib.build == 'all' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800512 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800513% endif
514% endfor
515
516
Craig Tiller12c82092015-01-15 08:45:56 -0800517static_cxx: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800518% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800519% if lib.build == 'all' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800520 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
nnoble29e1d292014-12-01 10:27:40 -0800521% endif
522% endfor
523
524
525shared: shared_c shared_cxx
526
Craig Tiller12c82092015-01-15 08:45:56 -0800527shared_c: \
nnoble29e1d292014-12-01 10:27:40 -0800528% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800529% if lib.build == 'all' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800530 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800531% endif
532% endfor
533
534
Craig Tiller12c82092015-01-15 08:45:56 -0800535shared_cxx: \
nnoble29e1d292014-12-01 10:27:40 -0800536% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800537% if lib.build == 'all' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800538 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
nnoble29e1d292014-12-01 10:27:40 -0800539% endif
540% endfor
541
542
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800543shared_csharp: shared_c \
544% for lib in libs:
545% if lib.build == 'all' and lib.language == 'csharp':
546 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
547% endif
548% endfor
549
550grpc_csharp_ext: shared_csharp
551
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100552plugins: $(PROTOC_PLUGINS)
553
nnoble29e1d292014-12-01 10:27:40 -0800554privatelibs: privatelibs_c privatelibs_cxx
555
Craig Tiller12c82092015-01-15 08:45:56 -0800556privatelibs_c: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800557% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800558% if lib.build == 'private' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800559 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800560% endif
561% endfor
562
563
Craig Tiller12c82092015-01-15 08:45:56 -0800564privatelibs_cxx: \
nnoble29e1d292014-12-01 10:27:40 -0800565% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800566% if lib.build == 'private' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800567 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800568% endif
569% endfor
570
571
nnoble29e1d292014-12-01 10:27:40 -0800572buildtests: buildtests_c buildtests_cxx
573
Craig Tiller12c82092015-01-15 08:45:56 -0800574buildtests_c: privatelibs_c\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800575% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800576% if tgt.build == 'test' and not tgt.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800577 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800578% endif
579% endfor
580
581
Craig Tiller12c82092015-01-15 08:45:56 -0800582buildtests_cxx: privatelibs_cxx\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800583% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800584% if tgt.build == 'test' and tgt.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800585 $(BINDIR)/$(CONFIG)/${tgt.name}\
nnoble29e1d292014-12-01 10:27:40 -0800586% endif
587% endfor
588
589
nnoble85a49262014-12-08 18:14:03 -0800590test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -0800591
nnoble85a49262014-12-08 18:14:03 -0800592test_c: buildtests_c
nnoble29e1d292014-12-01 10:27:40 -0800593% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800594% if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++':
nnoble29e1d292014-12-01 10:27:40 -0800595 $(E) "[RUN] Testing ${tgt.name}"
Craig Tillerda224d62015-02-15 11:01:58 -0800596 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
nnoble29e1d292014-12-01 10:27:40 -0800597% endif
598% endfor
599
600
nnoble85a49262014-12-08 18:14:03 -0800601test_cxx: buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -0800602% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800603% if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++':
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800604 $(E) "[RUN] Testing ${tgt.name}"
Craig Tillerda224d62015-02-15 11:01:58 -0800605 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800606% endif
607% endfor
608
609
610tools: privatelibs\
611% for tgt in targets:
612% if tgt.build == 'tool':
Craig Tiller61b910f2015-02-15 10:54:07 -0800613 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800614% endif
615% endfor
616
617
618buildbenchmarks: privatelibs\
619% for tgt in targets:
620% if tgt.build == 'benchmark':
Craig Tiller61b910f2015-02-15 10:54:07 -0800621 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800622% endif
623% endfor
624
625
626benchmarks: buildbenchmarks
627
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800628strip: strip-static strip-shared
629
nnoble20e2e3f2014-12-16 15:37:57 -0800630strip-static: strip-static_c strip-static_cxx
631
632strip-shared: strip-shared_c strip-shared_cxx
633
Nicolas Noble047b7272015-01-16 13:55:05 -0800634
635# TODO(nnoble): the strip target is stripping in-place, instead
636# of copying files in a temporary folder.
637# This prevents proper debugging after running make install.
638
nnoble85a49262014-12-08 18:14:03 -0800639strip-static_c: static_c
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100640ifeq ($(CONFIG),opt)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800641% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800642% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800643% if lib.build == "all":
644 $(E) "[STRIP] Stripping lib${lib.name}.a"
Craig Tiller61b910f2015-02-15 10:54:07 -0800645 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800646% endif
nnoble85a49262014-12-08 18:14:03 -0800647% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800648% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100649endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800650
nnoble85a49262014-12-08 18:14:03 -0800651strip-static_cxx: static_cxx
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100652ifeq ($(CONFIG),opt)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800653% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800654% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800655% if lib.build == "all":
656 $(E) "[STRIP] Stripping lib${lib.name}.a"
Craig Tiller61b910f2015-02-15 10:54:07 -0800657 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
nnoble85a49262014-12-08 18:14:03 -0800658% endif
659% endif
660% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100661endif
nnoble85a49262014-12-08 18:14:03 -0800662
663strip-shared_c: shared_c
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100664ifeq ($(CONFIG),opt)
nnoble85a49262014-12-08 18:14:03 -0800665% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800666% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800667% if lib.build == "all":
668 $(E) "[STRIP] Stripping lib${lib.name}.so"
Craig Tiller61b910f2015-02-15 10:54:07 -0800669 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800670% endif
nnoble85a49262014-12-08 18:14:03 -0800671% endif
672% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100673endif
nnoble85a49262014-12-08 18:14:03 -0800674
675strip-shared_cxx: shared_cxx
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100676ifeq ($(CONFIG),opt)
nnoble85a49262014-12-08 18:14:03 -0800677% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800678% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800679% if lib.build == "all":
680 $(E) "[STRIP] Stripping lib${lib.name}.so"
Craig Tiller61b910f2015-02-15 10:54:07 -0800681 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
nnoble85a49262014-12-08 18:14:03 -0800682% endif
683% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800684% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100685endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800686
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800687strip-shared_csharp: shared_csharp
688ifeq ($(CONFIG),opt)
689% for lib in libs:
690% if lib.language == "csharp":
691% if lib.build == "all":
692 $(E) "[STRIP] Stripping lib${lib.name}.so"
693 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
694% endif
695% endif
696% endfor
697endif
698
nnoble72309c62014-12-12 11:42:26 -0800699% for p in protos:
Nicolas Noble53830622015-02-12 16:56:38 -0800700ifeq ($(NO_PROTOC),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800701$(GENDIR)/${p}.pb.cc: protoc_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800702else
Craig Tiller61b910f2015-02-15 10:54:07 -0800703$(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800704 $(E) "[PROTOC] Generating protobuf CC file from $<"
705 $(Q) mkdir -p `dirname $@`
Vijay Pai850290f2015-02-19 09:59:44 -0800706 $(Q) $(PROTOC) --cpp_out=$(GENDIR) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $<
Nicolas Noble53830622015-02-12 16:56:38 -0800707endif
nnoble72309c62014-12-12 11:42:26 -0800708
709% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800710
Craig Tiller61b910f2015-02-15 10:54:07 -0800711$(OBJDIR)/$(CONFIG)/%.o : %.c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800712 $(E) "[C] Compiling $<"
713 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800714 $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800715
Craig Tiller61b910f2015-02-15 10:54:07 -0800716$(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800717 $(E) "[CXX] Compiling $<"
718 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800719 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800720
Craig Tiller61b910f2015-02-15 10:54:07 -0800721$(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
nnoble72309c62014-12-12 11:42:26 -0800722 $(E) "[HOSTCXX] Compiling $<"
723 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800724 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -0800725
Craig Tiller61b910f2015-02-15 10:54:07 -0800726$(OBJDIR)/$(CONFIG)/%.o : %.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800727 $(E) "[CXX] Compiling $<"
728 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800729 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800730
731
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +0100732install: install_c install_cxx install-plugins install-certs verify-install
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800733
nnoble85a49262014-12-08 18:14:03 -0800734install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800735
nnoble85a49262014-12-08 18:14:03 -0800736install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
737
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800738install_csharp: install-shared_csharp install_c
739
740install_grpc_csharp_ext: install_csharp
741
nnoble85a49262014-12-08 18:14:03 -0800742install-headers: install-headers_c install-headers_cxx
743
744install-headers_c:
745 $(E) "[INSTALL] Installing public C headers"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100746 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -0800747 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
748
749install-headers_cxx:
750 $(E) "[INSTALL] Installing public C++ headers"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100751 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -0800752 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
753
754install-static: install-static_c install-static_cxx
755
756install-static_c: static_c strip-static_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800757% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800758% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800759% if lib.build == "all":
760 $(E) "[INSTALL] Installing lib${lib.name}.a"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100761 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800762 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800763% endif
nnoble85a49262014-12-08 18:14:03 -0800764% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800765% endfor
766
nnoble85a49262014-12-08 18:14:03 -0800767install-static_cxx: static_cxx strip-static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800768% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800769% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800770% if lib.build == "all":
771 $(E) "[INSTALL] Installing lib${lib.name}.a"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100772 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800773 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
nnoble85a49262014-12-08 18:14:03 -0800774% endif
775% endif
776% endfor
777
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100778<%def name="install_shared(lang_filter)">\
nnoble85a49262014-12-08 18:14:03 -0800779% for lib in libs:
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100780% if lib.language == lang_filter:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800781% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -0800782ifeq ($(SYSTEM),MINGW32)
783 $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100784 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800785 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT)
786 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
nnoble5b7f32a2014-12-22 08:12:44 -0800787else
788 $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100789 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800790 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT)
nnoble5b7f32a2014-12-22 08:12:44 -0800791ifneq ($(SYSTEM),Darwin)
792 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
793endif
794endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800795% endif
nnoble85a49262014-12-08 18:14:03 -0800796% endif
797% endfor
nnoble5b7f32a2014-12-22 08:12:44 -0800798ifneq ($(SYSTEM),MINGW32)
799ifneq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblecc2b42a2015-02-20 00:42:21 +0100800 $(Q) ldconfig || true
nnoble5b7f32a2014-12-22 08:12:44 -0800801endif
802endif
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100803</%def>
nnoble85a49262014-12-08 18:14:03 -0800804
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100805install-shared_c: shared_c strip-shared_c
806${install_shared("c")}
807
808install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c
809${install_shared("c++")}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800810
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800811install-shared_csharp: shared_csharp strip-shared_csharp
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100812${install_shared("csharp")}
813
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100814install-plugins: $(PROTOC_PLUGINS)
815ifeq ($(SYSTEM),MINGW32)
816 $(Q) false
817else
818 $(E) "[INSTALL] Installing grpc protoc plugins"
819% for tgt in targets:
820% if tgt.build == 'protoc':
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100821 $(Q) $(INSTALL) -d $(prefix)/bin
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100822 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
823% endif
824% endfor
825endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800826
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +0100827install-certs: etc/roots.pem
828 $(E) "[INSTALL] Installing root certificates"
829 $(Q) $(INSTALL) -d $(prefix)/share/grpc
830 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
831
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100832verify-install:
Nicolas "Pixel" Noble2c23a722015-02-24 20:17:45 +0100833ifeq ($(INSTALL_OK),true)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100834 @echo "Your system looks ready to go."
835 @echo
836else
837 @echo "Your system doesn't have protoc 3.0.0+ installed. While this"
838 @echo "won't prevent grpc from working, you won't be able to compile"
839 @echo "and run any meaningful code with it."
840 @echo
841 @echo
842 @echo "Please download and install protobuf 3.0.0+ from:"
843 @echo
844 @echo " https://github.com/google/protobuf/releases"
845 @echo
846 @echo "Once you've done so, you can re-run this check by doing:"
847 @echo
848 @echo " make verify-install"
849endif
850
Craig Tiller3759e6f2015-01-15 08:13:11 -0800851clean:
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100852 $(E) "[CLEAN] Cleaning build directories."
Craig Tillerda224d62015-02-15 11:01:58 -0800853 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800854
855
856# The various libraries
857
858% for lib in libs:
859${makelib(lib)}
860% endfor
861
862
nnoble69ac39f2014-12-12 15:43:38 -0800863# All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800864
865% for tgt in targets:
866${maketarget(tgt)}
867% endfor
868
869<%def name="makelib(lib)">
870LIB${lib.name.upper()}_SRC = \\
871
872% for src in lib.src:
nnoble72309c62014-12-12 11:42:26 -0800873 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800874
875% endfor
876
877% if "public_headers" in lib:
Craig Tiller59140fc2015-01-18 10:12:17 -0800878% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800879PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800880
nnoble85a49262014-12-08 18:14:03 -0800881% else:
882PUBLIC_HEADERS_C += \\
883
884% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800885% for hdr in lib.public_headers:
886 ${hdr} \\
887
888% endfor
889% endif
890
Craig Tiller61b910f2015-02-15 10:54:07 -0800891LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800892
Nicolas Noble047b7272015-01-16 13:55:05 -0800893## If the library requires OpenSSL with ALPN, let's add some restrictions.
nnoble69ac39f2014-12-12 15:43:38 -0800894% if lib.get('secure', True):
nnoble69ac39f2014-12-12 15:43:38 -0800895ifeq ($(NO_SECURE),true)
896
Nicolas Noble047b7272015-01-16 13:55:05 -0800897# You can't build secure libraries if you don't have OpenSSL with ALPN.
898
Craig Tiller61b910f2015-02-15 10:54:07 -0800899$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -0800900
nnoble5b7f32a2014-12-22 08:12:44 -0800901% if lib.build == "all":
902ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -0800903$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -0800904else
Craig Tiller61b910f2015-02-15 10:54:07 -0800905$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -0800906endif
907% endif
908
nnoble69ac39f2014-12-12 15:43:38 -0800909else
910
Nicolas Noble53830622015-02-12 16:56:38 -0800911% if lib.language == 'c++':
912ifeq ($(NO_PROTOBUF),true)
913
914# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
915
Craig Tiller61b910f2015-02-15 10:54:07 -0800916$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800917
918% if lib.build == "all":
919ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -0800920$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800921else
Craig Tiller61b910f2015-02-15 10:54:07 -0800922$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800923endif
924% endif
925
926else
927% endif
928
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100929ifneq ($(OPENSSL_DEP),)
Nicolas Noble53830622015-02-12 16:56:38 -0800930# This is to ensure the embedded OpenSSL is built beforehand, properly
931# installing headers to their final destination on the drive. We need this
932# otherwise parallel compilation will fail if a source is compiled first.
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100933% for src in lib.src:
934${src}: $(OPENSSL_DEP)
935% endfor
936endif
937
Craig Tiller61b910f2015-02-15 10:54:07 -0800938$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
Nicolas Noble047b7272015-01-16 13:55:05 -0800939## The else here corresponds to the if secure earlier.
nnoble20e2e3f2014-12-16 15:37:57 -0800940% else:
Nicolas Noble53830622015-02-12 16:56:38 -0800941% if lib.language == 'c++':
942ifeq ($(NO_PROTOBUF),true)
943
944# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
945
Craig Tiller61b910f2015-02-15 10:54:07 -0800946$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800947
948% if lib.build == "all":
949ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -0800950$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800951else
Craig Tiller61b910f2015-02-15 10:54:07 -0800952$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800953endif
nnoble20e2e3f2014-12-16 15:37:57 -0800954% endif
Nicolas Noble53830622015-02-12 16:56:38 -0800955
956else
957
958% endif
Craig Tiller61b910f2015-02-15 10:54:07 -0800959$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP)\
Nicolas Noble53830622015-02-12 16:56:38 -0800960% endif
961% if lib.language == 'c++':
962 $(PROTOBUF_DEP)\
963% endif
964 $(LIB${lib.name.upper()}_OBJS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800965 $(E) "[AR] Creating $@"
nnoble85a49262014-12-08 18:14:03 -0800966 $(Q) mkdir -p `dirname $@`
Craig Tiller61b910f2015-02-15 10:54:07 -0800967 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
968 $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
nnoble20e2e3f2014-12-16 15:37:57 -0800969% if lib.get('baselib', False):
970% if lib.get('secure', True):
Craig Tillerf5371ef2015-01-12 16:40:18 -0800971 $(Q) rm -rf tmp-merge
nnoble20e2e3f2014-12-16 15:37:57 -0800972 $(Q) mkdir tmp-merge
Craig Tillerda224d62015-02-15 11:01:58 -0800973 $(Q) ( cd tmp-merge ; $(AR) x ../$(LIBDIR)/$(CONFIG)/lib${lib.name}.a )
nnoble20e2e3f2014-12-16 15:37:57 -0800974 $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge ; <%text>ar x ../$${l}</%text> ) ; done
Craig Tiller61b910f2015-02-15 10:54:07 -0800975 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge/__.SYMDEF*
976 $(Q) ar rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge/*
nnoble20e2e3f2014-12-16 15:37:57 -0800977 $(Q) rm -rf tmp-merge
978% endif
979% endif
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800980ifeq ($(SYSTEM),Darwin)
Craig Tiller61b910f2015-02-15 10:54:07 -0800981 $(Q) ranlib $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800982endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800983
nnoble5b7f32a2014-12-22 08:12:44 -0800984<%
Craig Tiller59140fc2015-01-18 10:12:17 -0800985 if lib.language == 'c++':
nnoble5b7f32a2014-12-22 08:12:44 -0800986 ld = '$(LDXX)'
987 else:
988 ld = '$(LD)'
989
Craig Tillerda224d62015-02-15 11:01:58 -0800990 out_base = '$(LIBDIR)/$(CONFIG)/' + lib.name
991 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name
nnoble5b7f32a2014-12-22 08:12:44 -0800992
993 common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
994
995 libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +0100996 lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -0800997 mingw_libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +0100998 mingw_lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -0800999 for dep in lib.get('deps', []):
1000 libs = libs + ' -l' + dep
Craig Tiller61b910f2015-02-15 10:54:07 -08001001 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001002 mingw_libs = mingw_libs + ' -l' + dep + '-imp'
Craig Tillerda224d62015-02-15 11:01:58 -08001003 mingw_lib_deps = mingw_lib_deps + '$(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001004
1005 if lib.get('secure', True):
1006 common = common + ' $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS)'
1007 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1008 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001009
1010 if lib.language == 'c++':
1011 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
nnoble5b7f32a2014-12-22 08:12:44 -08001012%>
1013
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001014% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -08001015ifeq ($(SYSTEM),MINGW32)
1016${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001017 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -08001018 $(Q) mkdir -p `dirname $@`
Craig Tillerda224d62015-02-15 11:01:58 -08001019 $(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 -08001020else
1021${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
1022 $(E) "[LD] Linking $@"
1023 $(Q) mkdir -p `dirname $@`
1024ifeq ($(SYSTEM),Darwin)
Craig Tillerda224d62015-02-15 11:01:58 -08001025 $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
nnoble5b7f32a2014-12-22 08:12:44 -08001026else
Craig Tillerda224d62015-02-15 11:01:58 -08001027 $(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 +01001028 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major}
nnoble5b7f32a2014-12-22 08:12:44 -08001029 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so
1030endif
1031endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001032% endif
Nicolas Noble53830622015-02-12 16:56:38 -08001033% if lib.get('secure', True):
Nicolas Noble047b7272015-01-16 13:55:05 -08001034## If the lib was secure, we have to close the Makefile's if that tested
1035## the presence of an ALPN-capable OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001036
1037endif
1038% endif
1039% if lib.language == 'c++':
1040## If the lib was C++, we have to close the Makefile's if that tested
1041## the presence of protobuf 3.0.0+
nnoble69ac39f2014-12-12 15:43:38 -08001042
1043endif
1044% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001045
nnoble69ac39f2014-12-12 15:43:38 -08001046% if lib.get('secure', True):
1047ifneq ($(NO_SECURE),true)
1048% endif
1049ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -08001050-include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001051endif
nnoble69ac39f2014-12-12 15:43:38 -08001052% if lib.get('secure', True):
1053endif
1054% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001055
Craig Tiller27715ca2015-01-12 16:55:59 -08001056% for src in lib.src:
1057% if not proto_re.match(src):
Craig Tiller61b910f2015-02-15 10:54:07 -08001058$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
Craig Tiller27715ca2015-01-12 16:55:59 -08001059% for src2 in lib.src:
1060% if proto_re.match(src2):
1061 ${proto_to_cc(src2)}\
1062% endif
1063% endfor
1064% endif
1065
1066% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001067</%def>
1068
1069<%def name="maketarget(tgt)">
1070${tgt.name.upper()}_SRC = \\
1071
1072% for src in tgt.src:
nnoble72309c62014-12-12 11:42:26 -08001073 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001074
1075% endfor
1076
Craig Tiller61b910f2015-02-15 10:54:07 -08001077${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001078
nnoble69ac39f2014-12-12 15:43:38 -08001079% if tgt.get('secure', True):
1080ifeq ($(NO_SECURE),true)
1081
Nicolas Noble047b7272015-01-16 13:55:05 -08001082# You can't build secure targets if you don't have OpenSSL with ALPN.
1083
Craig Tiller61b910f2015-02-15 10:54:07 -08001084$(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001085
1086else
1087
1088% endif
Nicolas Noble047b7272015-01-16 13:55:05 -08001089##
1090## We're not trying to add a dependency on building zlib and openssl here,
1091## as it's already done in the libraries. We're assuming that the build
1092## trickles down, and that a secure target requires a secure version of
1093## a library.
1094##
1095## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1096## I can live with that.
1097##
Nicolas Noble53830622015-02-12 16:56:38 -08001098% if tgt.build == 'protoc':
1099
1100ifeq ($(NO_PROTOBUF),true)
1101
1102# You can't build the protoc plugins if you don't have protobuf 3.0.0+.
1103
Craig Tiller61b910f2015-02-15 10:54:07 -08001104$(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001105
1106else
1107
Craig Tiller61b910f2015-02-15 10:54:07 -08001108$(BINDIR)/$(CONFIG)/${tgt.name}: $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
Nicolas Noble53830622015-02-12 16:56:38 -08001109% else:
Craig Tiller61b910f2015-02-15 10:54:07 -08001110$(BINDIR)/$(CONFIG)/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
Nicolas Noble53830622015-02-12 16:56:38 -08001111% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001112% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001113 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001114% endfor
1115
Craig Tiller59140fc2015-01-18 10:12:17 -08001116% if tgt.language == "c++":
Nicolas Noble047b7272015-01-16 13:55:05 -08001117## C++ targets specificies.
nnoble72309c62014-12-12 11:42:26 -08001118% if tgt.build == 'protoc':
1119 $(E) "[HOSTLD] Linking $@"
1120 $(Q) mkdir -p `dirname $@`
1121 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(${tgt.name.upper()}_OBJS)\
1122% else:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001123 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -08001124 $(Q) mkdir -p `dirname $@`
nnoblec78b3402014-12-11 16:06:57 -08001125 $(Q) $(LDXX) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
nnoble72309c62014-12-12 11:42:26 -08001126% endif
nnoblec78b3402014-12-11 16:06:57 -08001127% if tgt.build == 'test':
1128 $(GTEST_LIB)\
1129% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001130% else:
Nicolas Noble047b7272015-01-16 13:55:05 -08001131## C-only targets specificities.
nnoble72309c62014-12-12 11:42:26 -08001132 $(E) "[LD] Linking $@"
1133 $(Q) mkdir -p `dirname $@`
nnoble5b7f32a2014-12-22 08:12:44 -08001134 $(Q) $(LD) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001135% endif
1136% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001137 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001138% endfor
Craig Tiller59140fc2015-01-18 10:12:17 -08001139% if tgt.language == "c++":
nnoble72309c62014-12-12 11:42:26 -08001140% if tgt.build == 'protoc':
Nicolas Noble53830622015-02-12 16:56:38 -08001141 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
nnoble72309c62014-12-12 11:42:26 -08001142% else:
Nicolas Noble53830622015-02-12 16:56:38 -08001143 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001144% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001145% endif
nnoblec78b3402014-12-11 16:06:57 -08001146% if tgt.build == 'protoc':
nnoble72309c62014-12-12 11:42:26 -08001147 $(HOST_LDLIBS)\
1148% else:
1149 $(LDLIBS)\
1150% endif
1151% if tgt.build == 'protoc':
1152 $(HOST_LDLIBS_PROTOC)\
1153% elif tgt.get('secure', True):
1154 $(LDLIBS_SECURE)\
nnoblec78b3402014-12-11 16:06:57 -08001155% endif
Craig Tiller61b910f2015-02-15 10:54:07 -08001156 -o $(BINDIR)/$(CONFIG)/${tgt.name}
Nicolas Noble53830622015-02-12 16:56:38 -08001157% if tgt.build == 'protoc':
1158
1159endif
1160% endif
nnoble69ac39f2014-12-12 15:43:38 -08001161% if tgt.get('secure', True):
1162
1163endif
1164% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001165
Craig Tillerf5371ef2015-01-12 16:40:18 -08001166% for src in tgt.src:
Craig Tiller61b910f2015-02-15 10:54:07 -08001167$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
Craig Tillerf5371ef2015-01-12 16:40:18 -08001168% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001169 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Craig Tillerf5371ef2015-01-12 16:40:18 -08001170% endfor
1171
1172% endfor
1173
Craig Tiller8f126a62015-01-15 08:50:19 -08001174deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001175
nnoble69ac39f2014-12-12 15:43:38 -08001176% if tgt.get('secure', True):
1177ifneq ($(NO_SECURE),true)
1178% endif
1179ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -08001180-include $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001181endif
nnoble69ac39f2014-12-12 15:43:38 -08001182% if tgt.get('secure', True):
1183endif
1184% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001185</%def>
1186
nnoble85a49262014-12-08 18:14:03 -08001187.PHONY: all strip tools \
nnoble69ac39f2014-12-12 15:43:38 -08001188dep_error openssl_dep_error openssl_dep_message git_update stop \
nnoble85a49262014-12-08 18:14:03 -08001189buildtests buildtests_c buildtests_cxx \
1190test test_c test_cxx \
1191install install_c install_cxx \
1192install-headers install-headers_c install-headers_cxx \
1193install-shared install-shared_c install-shared_cxx \
1194install-static install-static_c install-static_cxx \
1195strip strip-shared strip-static \
1196strip_c strip-shared_c strip-static_c \
1197strip_cxx strip-shared_cxx strip-static_cxx \
Craig Tillerf0afe502015-01-15 09:04:49 -08001198dep_c dep_cxx bins_dep_c bins_dep_cxx \
Craig Tiller12c82092015-01-15 08:45:56 -08001199clean
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001200