blob: 60416525f8b9fc937105d495592be3f46c7297b5 [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
4# Copyright 2014, Google Inc.
5# 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 =
97DEFINES_valgrind = _DEBUG DEBUG
98
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
107DEFINES_tsan = NDEBUG
108
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
117DEFINES_asan = NDEBUG
118
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
ctiller8cfebb92015-01-06 15:02:12 -0800128DEFINES_msan = NDEBUG
129
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
139DEFINES_ubsan = NDEBUG
140
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
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100277HAS_PROTOC = $(shell $(PROTOC_CMD) && echo true || echo false)
278ifeq ($(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
Nicolas Noble53830622015-02-12 16:56:38 -0800335CPPFLAGS += -Ithird_party/protobuf/src
Craig Tillerda224d62015-02-15 11:01:58 -0800336LDFLAGS += -L$(LIBDIR)/$(CONFIG)/protobuf
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" Noble98ab9982015-02-21 04:22:16 +0100732install: install_c install_cxx install-plugins 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" Noble98ab9982015-02-21 04:22:16 +0100827verify-install:
828ifeq ($(SYSTEM_OK),true)
829 @echo "Your system looks ready to go."
830 @echo
831else
832 @echo "Your system doesn't have protoc 3.0.0+ installed. While this"
833 @echo "won't prevent grpc from working, you won't be able to compile"
834 @echo "and run any meaningful code with it."
835 @echo
836 @echo
837 @echo "Please download and install protobuf 3.0.0+ from:"
838 @echo
839 @echo " https://github.com/google/protobuf/releases"
840 @echo
841 @echo "Once you've done so, you can re-run this check by doing:"
842 @echo
843 @echo " make verify-install"
844endif
845
Craig Tiller3759e6f2015-01-15 08:13:11 -0800846clean:
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100847 $(E) "[CLEAN] Cleaning build directories."
Craig Tillerda224d62015-02-15 11:01:58 -0800848 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800849
850
851# The various libraries
852
853% for lib in libs:
854${makelib(lib)}
855% endfor
856
857
nnoble69ac39f2014-12-12 15:43:38 -0800858# All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800859
860% for tgt in targets:
861${maketarget(tgt)}
862% endfor
863
864<%def name="makelib(lib)">
865LIB${lib.name.upper()}_SRC = \\
866
867% for src in lib.src:
nnoble72309c62014-12-12 11:42:26 -0800868 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800869
870% endfor
871
872% if "public_headers" in lib:
Craig Tiller59140fc2015-01-18 10:12:17 -0800873% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800874PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800875
nnoble85a49262014-12-08 18:14:03 -0800876% else:
877PUBLIC_HEADERS_C += \\
878
879% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800880% for hdr in lib.public_headers:
881 ${hdr} \\
882
883% endfor
884% endif
885
Craig Tiller61b910f2015-02-15 10:54:07 -0800886LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800887
Nicolas Noble047b7272015-01-16 13:55:05 -0800888## If the library requires OpenSSL with ALPN, let's add some restrictions.
nnoble69ac39f2014-12-12 15:43:38 -0800889% if lib.get('secure', True):
nnoble69ac39f2014-12-12 15:43:38 -0800890ifeq ($(NO_SECURE),true)
891
Nicolas Noble047b7272015-01-16 13:55:05 -0800892# You can't build secure libraries if you don't have OpenSSL with ALPN.
893
Craig Tiller61b910f2015-02-15 10:54:07 -0800894$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -0800895
nnoble5b7f32a2014-12-22 08:12:44 -0800896% if lib.build == "all":
897ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -0800898$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -0800899else
Craig Tiller61b910f2015-02-15 10:54:07 -0800900$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -0800901endif
902% endif
903
nnoble69ac39f2014-12-12 15:43:38 -0800904else
905
Nicolas Noble53830622015-02-12 16:56:38 -0800906% if lib.language == 'c++':
907ifeq ($(NO_PROTOBUF),true)
908
909# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
910
Craig Tiller61b910f2015-02-15 10:54:07 -0800911$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800912
913% if lib.build == "all":
914ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -0800915$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800916else
Craig Tiller61b910f2015-02-15 10:54:07 -0800917$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800918endif
919% endif
920
921else
922% endif
923
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100924ifneq ($(OPENSSL_DEP),)
Nicolas Noble53830622015-02-12 16:56:38 -0800925# This is to ensure the embedded OpenSSL is built beforehand, properly
926# installing headers to their final destination on the drive. We need this
927# otherwise parallel compilation will fail if a source is compiled first.
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100928% for src in lib.src:
929${src}: $(OPENSSL_DEP)
930% endfor
931endif
932
Craig Tiller61b910f2015-02-15 10:54:07 -0800933$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
Nicolas Noble047b7272015-01-16 13:55:05 -0800934## The else here corresponds to the if secure earlier.
nnoble20e2e3f2014-12-16 15:37:57 -0800935% else:
Nicolas Noble53830622015-02-12 16:56:38 -0800936% if lib.language == 'c++':
937ifeq ($(NO_PROTOBUF),true)
938
939# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
940
Craig Tiller61b910f2015-02-15 10:54:07 -0800941$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800942
943% if lib.build == "all":
944ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -0800945$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800946else
Craig Tiller61b910f2015-02-15 10:54:07 -0800947$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800948endif
nnoble20e2e3f2014-12-16 15:37:57 -0800949% endif
Nicolas Noble53830622015-02-12 16:56:38 -0800950
951else
952
953% endif
Craig Tiller61b910f2015-02-15 10:54:07 -0800954$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP)\
Nicolas Noble53830622015-02-12 16:56:38 -0800955% endif
956% if lib.language == 'c++':
957 $(PROTOBUF_DEP)\
958% endif
959 $(LIB${lib.name.upper()}_OBJS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800960 $(E) "[AR] Creating $@"
nnoble85a49262014-12-08 18:14:03 -0800961 $(Q) mkdir -p `dirname $@`
Craig Tiller61b910f2015-02-15 10:54:07 -0800962 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
963 $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
nnoble20e2e3f2014-12-16 15:37:57 -0800964% if lib.get('baselib', False):
965% if lib.get('secure', True):
Craig Tillerf5371ef2015-01-12 16:40:18 -0800966 $(Q) rm -rf tmp-merge
nnoble20e2e3f2014-12-16 15:37:57 -0800967 $(Q) mkdir tmp-merge
Craig Tillerda224d62015-02-15 11:01:58 -0800968 $(Q) ( cd tmp-merge ; $(AR) x ../$(LIBDIR)/$(CONFIG)/lib${lib.name}.a )
nnoble20e2e3f2014-12-16 15:37:57 -0800969 $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge ; <%text>ar x ../$${l}</%text> ) ; done
Craig Tiller61b910f2015-02-15 10:54:07 -0800970 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge/__.SYMDEF*
971 $(Q) ar rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge/*
nnoble20e2e3f2014-12-16 15:37:57 -0800972 $(Q) rm -rf tmp-merge
973% endif
974% endif
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800975ifeq ($(SYSTEM),Darwin)
Craig Tiller61b910f2015-02-15 10:54:07 -0800976 $(Q) ranlib $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800977endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800978
nnoble5b7f32a2014-12-22 08:12:44 -0800979<%
Craig Tiller59140fc2015-01-18 10:12:17 -0800980 if lib.language == 'c++':
nnoble5b7f32a2014-12-22 08:12:44 -0800981 ld = '$(LDXX)'
982 else:
983 ld = '$(LD)'
984
Craig Tillerda224d62015-02-15 11:01:58 -0800985 out_base = '$(LIBDIR)/$(CONFIG)/' + lib.name
986 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name
nnoble5b7f32a2014-12-22 08:12:44 -0800987
988 common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
989
990 libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +0100991 lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -0800992 mingw_libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +0100993 mingw_lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -0800994 for dep in lib.get('deps', []):
995 libs = libs + ' -l' + dep
Craig Tiller61b910f2015-02-15 10:54:07 -0800996 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -0800997 mingw_libs = mingw_libs + ' -l' + dep + '-imp'
Craig Tillerda224d62015-02-15 11:01:58 -0800998 mingw_lib_deps = mingw_lib_deps + '$(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -0800999
1000 if lib.get('secure', True):
1001 common = common + ' $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS)'
1002 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1003 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001004
1005 if lib.language == 'c++':
1006 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
nnoble5b7f32a2014-12-22 08:12:44 -08001007%>
1008
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001009% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -08001010ifeq ($(SYSTEM),MINGW32)
1011${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001012 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -08001013 $(Q) mkdir -p `dirname $@`
Craig Tillerda224d62015-02-15 11:01:58 -08001014 $(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 -08001015else
1016${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
1017 $(E) "[LD] Linking $@"
1018 $(Q) mkdir -p `dirname $@`
1019ifeq ($(SYSTEM),Darwin)
Craig Tillerda224d62015-02-15 11:01:58 -08001020 $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
nnoble5b7f32a2014-12-22 08:12:44 -08001021else
Craig Tillerda224d62015-02-15 11:01:58 -08001022 $(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 +01001023 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major}
nnoble5b7f32a2014-12-22 08:12:44 -08001024 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so
1025endif
1026endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001027% endif
Nicolas Noble53830622015-02-12 16:56:38 -08001028% if lib.get('secure', True):
Nicolas Noble047b7272015-01-16 13:55:05 -08001029## If the lib was secure, we have to close the Makefile's if that tested
1030## the presence of an ALPN-capable OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001031
1032endif
1033% endif
1034% if lib.language == 'c++':
1035## If the lib was C++, we have to close the Makefile's if that tested
1036## the presence of protobuf 3.0.0+
nnoble69ac39f2014-12-12 15:43:38 -08001037
1038endif
1039% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001040
nnoble69ac39f2014-12-12 15:43:38 -08001041% if lib.get('secure', True):
1042ifneq ($(NO_SECURE),true)
1043% endif
1044ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -08001045-include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001046endif
nnoble69ac39f2014-12-12 15:43:38 -08001047% if lib.get('secure', True):
1048endif
1049% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001050
Craig Tiller27715ca2015-01-12 16:55:59 -08001051% for src in lib.src:
1052% if not proto_re.match(src):
Craig Tiller61b910f2015-02-15 10:54:07 -08001053$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
Craig Tiller27715ca2015-01-12 16:55:59 -08001054% for src2 in lib.src:
1055% if proto_re.match(src2):
1056 ${proto_to_cc(src2)}\
1057% endif
1058% endfor
1059% endif
1060
1061% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001062</%def>
1063
1064<%def name="maketarget(tgt)">
1065${tgt.name.upper()}_SRC = \\
1066
1067% for src in tgt.src:
nnoble72309c62014-12-12 11:42:26 -08001068 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001069
1070% endfor
1071
Craig Tiller61b910f2015-02-15 10:54:07 -08001072${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001073
nnoble69ac39f2014-12-12 15:43:38 -08001074% if tgt.get('secure', True):
1075ifeq ($(NO_SECURE),true)
1076
Nicolas Noble047b7272015-01-16 13:55:05 -08001077# You can't build secure targets if you don't have OpenSSL with ALPN.
1078
Craig Tiller61b910f2015-02-15 10:54:07 -08001079$(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001080
1081else
1082
1083% endif
Nicolas Noble047b7272015-01-16 13:55:05 -08001084##
1085## We're not trying to add a dependency on building zlib and openssl here,
1086## as it's already done in the libraries. We're assuming that the build
1087## trickles down, and that a secure target requires a secure version of
1088## a library.
1089##
1090## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1091## I can live with that.
1092##
Nicolas Noble53830622015-02-12 16:56:38 -08001093% if tgt.build == 'protoc':
1094
1095ifeq ($(NO_PROTOBUF),true)
1096
1097# You can't build the protoc plugins if you don't have protobuf 3.0.0+.
1098
Craig Tiller61b910f2015-02-15 10:54:07 -08001099$(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001100
1101else
1102
Craig Tiller61b910f2015-02-15 10:54:07 -08001103$(BINDIR)/$(CONFIG)/${tgt.name}: $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
Nicolas Noble53830622015-02-12 16:56:38 -08001104% else:
Craig Tiller61b910f2015-02-15 10:54:07 -08001105$(BINDIR)/$(CONFIG)/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
Nicolas Noble53830622015-02-12 16:56:38 -08001106% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001107% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001108 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001109% endfor
1110
Craig Tiller59140fc2015-01-18 10:12:17 -08001111% if tgt.language == "c++":
Nicolas Noble047b7272015-01-16 13:55:05 -08001112## C++ targets specificies.
nnoble72309c62014-12-12 11:42:26 -08001113% if tgt.build == 'protoc':
1114 $(E) "[HOSTLD] Linking $@"
1115 $(Q) mkdir -p `dirname $@`
1116 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(${tgt.name.upper()}_OBJS)\
1117% else:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001118 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -08001119 $(Q) mkdir -p `dirname $@`
nnoblec78b3402014-12-11 16:06:57 -08001120 $(Q) $(LDXX) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
nnoble72309c62014-12-12 11:42:26 -08001121% endif
nnoblec78b3402014-12-11 16:06:57 -08001122% if tgt.build == 'test':
1123 $(GTEST_LIB)\
1124% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001125% else:
Nicolas Noble047b7272015-01-16 13:55:05 -08001126## C-only targets specificities.
nnoble72309c62014-12-12 11:42:26 -08001127 $(E) "[LD] Linking $@"
1128 $(Q) mkdir -p `dirname $@`
nnoble5b7f32a2014-12-22 08:12:44 -08001129 $(Q) $(LD) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001130% endif
1131% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001132 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001133% endfor
Craig Tiller59140fc2015-01-18 10:12:17 -08001134% if tgt.language == "c++":
nnoble72309c62014-12-12 11:42:26 -08001135% if tgt.build == 'protoc':
Nicolas Noble53830622015-02-12 16:56:38 -08001136 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
nnoble72309c62014-12-12 11:42:26 -08001137% else:
Nicolas Noble53830622015-02-12 16:56:38 -08001138 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001139% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001140% endif
nnoblec78b3402014-12-11 16:06:57 -08001141% if tgt.build == 'protoc':
nnoble72309c62014-12-12 11:42:26 -08001142 $(HOST_LDLIBS)\
1143% else:
1144 $(LDLIBS)\
1145% endif
1146% if tgt.build == 'protoc':
1147 $(HOST_LDLIBS_PROTOC)\
1148% elif tgt.get('secure', True):
1149 $(LDLIBS_SECURE)\
nnoblec78b3402014-12-11 16:06:57 -08001150% endif
Craig Tiller61b910f2015-02-15 10:54:07 -08001151 -o $(BINDIR)/$(CONFIG)/${tgt.name}
Nicolas Noble53830622015-02-12 16:56:38 -08001152% if tgt.build == 'protoc':
1153
1154endif
1155% endif
nnoble69ac39f2014-12-12 15:43:38 -08001156% if tgt.get('secure', True):
1157
1158endif
1159% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001160
Craig Tillerf5371ef2015-01-12 16:40:18 -08001161% for src in tgt.src:
Craig Tiller61b910f2015-02-15 10:54:07 -08001162$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
Craig Tillerf5371ef2015-01-12 16:40:18 -08001163% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001164 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Craig Tillerf5371ef2015-01-12 16:40:18 -08001165% endfor
1166
1167% endfor
1168
Craig Tiller8f126a62015-01-15 08:50:19 -08001169deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001170
nnoble69ac39f2014-12-12 15:43:38 -08001171% if tgt.get('secure', True):
1172ifneq ($(NO_SECURE),true)
1173% endif
1174ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -08001175-include $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001176endif
nnoble69ac39f2014-12-12 15:43:38 -08001177% if tgt.get('secure', True):
1178endif
1179% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001180</%def>
1181
nnoble85a49262014-12-08 18:14:03 -08001182.PHONY: all strip tools \
nnoble69ac39f2014-12-12 15:43:38 -08001183dep_error openssl_dep_error openssl_dep_message git_update stop \
nnoble85a49262014-12-08 18:14:03 -08001184buildtests buildtests_c buildtests_cxx \
1185test test_c test_cxx \
1186install install_c install_cxx \
1187install-headers install-headers_c install-headers_cxx \
1188install-shared install-shared_c install-shared_cxx \
1189install-static install-static_c install-static_cxx \
1190strip strip-shared strip-static \
1191strip_c strip-shared_c strip-static_c \
1192strip_cxx strip-shared_cxx strip-static_cxx \
Craig Tillerf0afe502015-01-15 09:04:49 -08001193dep_c dep_cxx bins_dep_c bins_dep_cxx \
Craig Tiller12c82092015-01-15 08:45:56 -08001194clean
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001195