blob: 6315aab945ff12315b851ec42a22915dec838510 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001# GRPC global makefile
2# This currently builds C and C++ code.
Craig Tiller3b935482015-02-16 12:15:48 -08003
Craig Tillerd7f33352015-02-20 15:18:45 -08004# Copyright 2015, Google Inc.
Craig Tiller3b935482015-02-16 12:15:48 -08005# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are
9# met:
10#
11# * Redistributions of source code must retain the above copyright
12# notice, this list of conditions and the following disclaimer.
13# * Redistributions in binary form must reproduce the above
14# copyright notice, this list of conditions and the following disclaimer
15# in the documentation and/or other materials provided with the
16# distribution.
17# * Neither the name of Google Inc. nor the names of its
18# contributors may be used to endorse or promote products derived from
19# this software without specific prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080032<%!
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080033 import re
Craig Tillerf5371ef2015-01-12 16:40:18 -080034 import os
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080035
nnoblec87b1c52015-01-05 17:15:18 -080036 proto_re = re.compile('(.*)\\.proto')
nnoble72309c62014-12-12 11:42:26 -080037
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080038 def excluded(filename, exclude_res):
39 for r in exclude_res:
40 if r.match(filename):
41 return True
42 return False
nnoble72309c62014-12-12 11:42:26 -080043
44 def proto_to_cc(filename):
45 m = proto_re.match(filename)
46 if not m:
47 return filename
Craig Tillerda224d62015-02-15 11:01:58 -080048 return '$(GENDIR)/' + m.group(1) + '.pb.cc'
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080049%>
50
Craig Tiller96b49552015-01-21 16:29:01 -080051
52# Basic platform detection
53HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
54ifeq ($(SYSTEM),)
55SYSTEM = $(HOST_SYSTEM)
56endif
Nicolas Noblef8681182015-03-18 14:25:44 -070057ifeq ($(SYSTEM),MSYS)
58SYSTEM = MINGW32
59endif
Craig Tiller96b49552015-01-21 16:29:01 -080060
61
Craig Tiller61b910f2015-02-15 10:54:07 -080062ifndef BUILDDIR
63BUILDDIR = .
64endif
65
Nicolas Noblef8681182015-03-18 14:25:44 -070066HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false)
67HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false)
68HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false)
69
70ifeq ($(HAS_CC),true)
71DEFAULT_CC = cc
72DEFAULT_CXX = c++
73else
74ifeq ($(HAS_GCC),true)
75DEFAULT_CC = gcc
76DEFAULT_CXX = g++
77else
78ifeq ($(HAS_CLANG),true)
79DEFAULT_CC = clang
80DEFAULT_CXX = clang++
81else
82DEFAULT_CC = no_c_compiler
83DEFAULT_CXX = no_c++_compiler
84endif
85endif
86endif
87
88
Craig Tiller61b910f2015-02-15 10:54:07 -080089BINDIR = $(BUILDDIR)/bins
90OBJDIR = $(BUILDDIR)/objs
91LIBDIR = $(BUILDDIR)/libs
92GENDIR = $(BUILDDIR)/gens
93
ctiller8cfebb92015-01-06 15:02:12 -080094# Configurations
95
96VALID_CONFIG_opt = 1
Nicolas Noblef8681182015-03-18 14:25:44 -070097CC_opt = $(DEFAULT_CC)
98CXX_opt = $(DEFAULT_CXX)
99LD_opt = $(DEFAULT_CC)
100LDXX_opt = $(DEFAULT_CXX)
ctiller8cfebb92015-01-06 15:02:12 -0800101CPPFLAGS_opt = -O2
102LDFLAGS_opt =
103DEFINES_opt = NDEBUG
104
105VALID_CONFIG_dbg = 1
Nicolas Noblef8681182015-03-18 14:25:44 -0700106CC_dbg = $(DEFAULT_CC)
107CXX_dbg = $(DEFAULT_CXX)
108LD_dbg = $(DEFAULT_CC)
109LDXX_dbg = $(DEFAULT_CXX)
ctiller8cfebb92015-01-06 15:02:12 -0800110CPPFLAGS_dbg = -O0
111LDFLAGS_dbg =
112DEFINES_dbg = _DEBUG DEBUG
113
Vijay Paidc7110f2015-04-02 13:59:05 -0700114VALID_CONFIG_mutrace = 1
115CC_mutrace = $(DEFAULT_CC)
116CXX_mutrace = $(DEFAULT_CXX)
117LD_mutrace = $(DEFAULT_CC)
118LDXX_mutrace = $(DEFAULT_CXX)
119CPPFLAGS_mutrace = -O0
120LDFLAGS_mutrace = -rdynamic
121DEFINES_mutrace = _DEBUG DEBUG
122
Craig Tillerec0b8f32015-01-15 07:30:00 -0800123VALID_CONFIG_valgrind = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800124REQUIRE_CUSTOM_LIBRARIES_valgrind = 1
Nicolas Noblef8681182015-03-18 14:25:44 -0700125CC_valgrind = $(DEFAULT_CC)
126CXX_valgrind = $(DEFAULT_CXX)
127LD_valgrind = $(DEFAULT_CC)
128LDXX_valgrind = $(DEFAULT_CXX)
Craig Tillerec0b8f32015-01-15 07:30:00 -0800129CPPFLAGS_valgrind = -O0
130OPENSSL_CFLAGS_valgrind = -DPURIFY
131LDFLAGS_valgrind =
Craig Tillerf6901be2015-02-27 09:12:58 -0800132DEFINES_valgrind = _DEBUG DEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20
Craig Tillerec0b8f32015-01-15 07:30:00 -0800133
ctiller8cfebb92015-01-06 15:02:12 -0800134VALID_CONFIG_tsan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800135REQUIRE_CUSTOM_LIBRARIES_tsan = 1
ctiller8cfebb92015-01-06 15:02:12 -0800136CC_tsan = clang
137CXX_tsan = clang++
138LD_tsan = clang
139LDXX_tsan = clang++
140CPPFLAGS_tsan = -O1 -fsanitize=thread -fno-omit-frame-pointer
141LDFLAGS_tsan = -fsanitize=thread
Craig Tillerf6901be2015-02-27 09:12:58 -0800142DEFINES_tsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10
ctiller8cfebb92015-01-06 15:02:12 -0800143
144VALID_CONFIG_asan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800145REQUIRE_CUSTOM_LIBRARIES_asan = 1
ctiller8cfebb92015-01-06 15:02:12 -0800146CC_asan = clang
147CXX_asan = clang++
148LD_asan = clang
149LDXX_asan = clang++
150CPPFLAGS_asan = -O1 -fsanitize=address -fno-omit-frame-pointer
151LDFLAGS_asan = -fsanitize=address
Craig Tillerf6901be2015-02-27 09:12:58 -0800152DEFINES_asan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5
ctiller8cfebb92015-01-06 15:02:12 -0800153
154VALID_CONFIG_msan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -0800155REQUIRE_CUSTOM_LIBRARIES_msan = 1
ctiller8cfebb92015-01-06 15:02:12 -0800156CC_msan = clang
Nicolas "Pixel" Nobled66cba22015-02-14 02:59:12 +0100157CXX_msan = clang++-libc++
ctiller8cfebb92015-01-06 15:02:12 -0800158LD_msan = clang
Nicolas "Pixel" Nobled66cba22015-02-14 02:59:12 +0100159LDXX_msan = clang++-libc++
Craig Tilleracd62292015-02-16 11:12:28 -0800160CPPFLAGS_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 -0800161OPENSSL_CFLAGS_msan = -DPURIFY
Nicolas "Pixel" Nobled66cba22015-02-14 02:59:12 +0100162LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
Craig Tillerf6901be2015-02-27 09:12:58 -0800163DEFINES_msan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20
ctiller8cfebb92015-01-06 15:02:12 -0800164
Craig Tiller96bd5f62015-02-13 09:04:13 -0800165VALID_CONFIG_ubsan = 1
166REQUIRE_CUSTOM_LIBRARIES_ubsan = 1
167CC_ubsan = clang
168CXX_ubsan = clang++
169LD_ubsan = clang
170LDXX_ubsan = clang++
171CPPFLAGS_ubsan = -O1 -fsanitize=undefined -fno-omit-frame-pointer
172OPENSSL_CFLAGS_ubsan = -DPURIFY
Craig Tiller96bd5f62015-02-13 09:04:13 -0800173LDFLAGS_ubsan = -fsanitize=undefined
Craig Tillerf6901be2015-02-27 09:12:58 -0800174DEFINES_ubsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10
Craig Tiller96bd5f62015-02-13 09:04:13 -0800175
Craig Tiller699ba212015-01-13 17:02:20 -0800176VALID_CONFIG_gcov = 1
177CC_gcov = gcc
178CXX_gcov = g++
179LD_gcov = gcc
180LDXX_gcov = g++
181CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage
182LDFLAGS_gcov = -fprofile-arcs -ftest-coverage
183DEFINES_gcov = NDEBUG
184
Nicolas Noble047b7272015-01-16 13:55:05 -0800185
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800186# General settings.
187# You may want to change these depending on your system.
188
189prefix ?= /usr/local
190
191PROTOC = protoc
yangg102e4fe2015-01-06 16:02:50 -0800192CONFIG ?= opt
ctiller8cfebb92015-01-06 15:02:12 -0800193CC = $(CC_$(CONFIG))
194CXX = $(CXX_$(CONFIG))
195LD = $(LD_$(CONFIG))
196LDXX = $(LDXX_$(CONFIG))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800197AR = ar
Nicolas "Pixel" Nobled7631a42015-02-27 07:52:39 +0100198ifeq ($(SYSTEM),Linux)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800199STRIP = strip --strip-unneeded
Nicolas "Pixel" Nobled7631a42015-02-27 07:52:39 +0100200else
201ifeq ($(SYSTEM),Darwin)
202STRIP = strip -x
203else
204STRIP = strip
205endif
206endif
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100207INSTALL = install
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800208RM = rm -f
209
yangg102e4fe2015-01-06 16:02:50 -0800210ifndef VALID_CONFIG_$(CONFIG)
211$(error Invalid CONFIG value '$(CONFIG)')
212endif
213
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100214ifeq ($(SYSTEM),Linux)
215TMPOUT = /dev/null
216else
217TMPOUT = `mktemp /tmp/test-out-XXXXXX`
218endif
Nicolas Noble047b7272015-01-16 13:55:05 -0800219
Craig Tillercf133f42015-02-26 14:05:56 -0800220# Detect if we can use C++11
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100221CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc
Craig Tillercf133f42015-02-26 14:05:56 -0800222HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false)
223
Nicolas Noble047b7272015-01-16 13:55:05 -0800224# The HOST compiler settings are used to compile the protoc plugins.
225# In most cases, you won't have to change anything, but if you are
226# cross-compiling, you can override these variables from GNU make's
227# command line: make CC=cross-gcc HOST_CC=gcc
228
nnoble72309c62014-12-12 11:42:26 -0800229HOST_CC = $(CC)
230HOST_CXX = $(CXX)
231HOST_LD = $(LD)
232HOST_LDXX = $(LDXX)
233
ctillercab52e72015-01-06 13:10:23 -0800234CPPFLAGS += $(CPPFLAGS_$(CONFIG))
Nicolas "Pixel" Noble72743822015-02-20 20:59:29 +0100235DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
ctiller8cfebb92015-01-06 15:02:12 -0800236LDFLAGS += $(LDFLAGS_$(CONFIG))
ctillercab52e72015-01-06 13:10:23 -0800237
Craig Tiller86fa1c52015-02-27 09:57:58 -0800238ifdef EXTRA_DEFINES
Craig Tillerf5065c52015-02-27 16:17:39 -0800239DEFINES += $(EXTRA_DEFINES)
Craig Tiller86fa1c52015-02-27 09:57:58 -0800240endif
241
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800242CFLAGS += -std=c89 -pedantic
Craig Tillercf133f42015-02-26 14:05:56 -0800243ifeq ($(HAS_CXX11),true)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800244CXXFLAGS += -std=c++11
Craig Tillercf133f42015-02-26 14:05:56 -0800245else
246CXXFLAGS += -std=c++0x
Craig Tillercf133f42015-02-26 14:05:56 -0800247endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700248CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
249LDFLAGS += -g
250
251ifneq ($(SYSTEM),MINGW32)
252PIC_CPPFLAGS = -fPIC
253CPPFLAGS += -fPIC
254LDFLAGS += -fPIC
255endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800256
Craig Tillerda224d62015-02-15 11:01:58 -0800257INCLUDES = . include $(GENDIR)
Craig Tiller96b49552015-01-21 16:29:01 -0800258ifeq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100259ifneq ($(wildcard /usr/local/ssl/include),)
260INCLUDES += /usr/local/ssl/include
261endif
262ifneq ($(wildcard /opt/local/include),)
263INCLUDES += /opt/local/include
264endif
265ifneq ($(wildcard /usr/local/include),)
266INCLUDES += /usr/local/include
267endif
Craig Tiller96b49552015-01-21 16:29:01 -0800268LIBS = m z
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100269ifneq ($(wildcard /usr/local/ssl/lib),)
270LDFLAGS += -L/usr/local/ssl/lib
271endif
272ifneq ($(wildcard /opt/local/lib),)
273LDFLAGS += -L/opt/local/lib
274endif
275ifneq ($(wildcard /usr/local/lib),)
276LDFLAGS += -L/usr/local/lib
277endif
Nicolas Noblef8681182015-03-18 14:25:44 -0700278endif
279
280ifeq ($(SYSTEM),Linux)
ctillerc008ae52015-01-07 15:33:00 -0800281LIBS = rt m z pthread
Craig Tiller96b49552015-01-21 16:29:01 -0800282LDFLAGS += -pthread
283endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800284
Nicolas Noblef8681182015-03-18 14:25:44 -0700285ifeq ($(SYSTEM),MINGW32)
286LIBS = m z pthread
287LDFLAGS += -pthread
288endif
289
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800290ifneq ($(wildcard /usr/src/gtest/src/gtest-all.cc),)
291GTEST_LIB = /usr/src/gtest/src/gtest-all.cc -I/usr/src/gtest
292else
293GTEST_LIB = -lgtest
294endif
chenwa8fd44a2014-12-10 15:13:55 -0800295GTEST_LIB += -lgflags
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800296ifeq ($(V),1)
297E = @:
298Q =
299else
300E = @echo
301Q = @
302endif
303
304VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build}
305
306CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
307CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
308
309LDFLAGS += $(ARCH_FLAGS)
310LDLIBS += $(addprefix -l, $(LIBS))
311LDLIBSXX += $(addprefix -l, $(LIBSXX))
nnoble72309c62014-12-12 11:42:26 -0800312
313HOST_CPPFLAGS = $(CPPFLAGS)
314HOST_CFLAGS = $(CFLAGS)
315HOST_CXXFLAGS = $(CXXFLAGS)
316HOST_LDFLAGS = $(LDFLAGS)
317HOST_LDLIBS = $(LDLIBS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800318
nnoble69ac39f2014-12-12 15:43:38 -0800319
320# These are automatically computed variables.
321# There shouldn't be any need to change anything from now on.
322
nnoble5b7f32a2014-12-22 08:12:44 -0800323ifeq ($(SYSTEM),MINGW32)
324SHARED_EXT = dll
325endif
326ifeq ($(SYSTEM),Darwin)
327SHARED_EXT = dylib
328endif
329ifeq ($(SHARED_EXT),)
330SHARED_EXT = so.$(VERSION)
331endif
332
nnoble69ac39f2014-12-12 15:43:38 -0800333ifeq ($(wildcard .git),)
334IS_GIT_FOLDER = false
335else
336IS_GIT_FOLDER = true
337endif
338
Nicolas Noblef8681182015-03-18 14:25:44 -0700339ifeq ($(SYSTEM),Linux)
340OPENSSL_REQUIRES_DL = true
341endif
342
343ifeq ($(SYSTEM),Darwin)
344OPENSSL_REQUIRES_DL = true
345endif
346
347ifeq ($(SYSTEM),MINGW32)
348OPENSSL_LIBS = ssl32 eay32
349else
350OPENSSL_LIBS = ssl crypto
351endif
352
353OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
Nicolas "Pixel" Noblee758ed12015-03-11 22:51:39 +0100354ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
355PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
356PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
Nicolas Noblef8681182015-03-18 14:25:44 -0700357PROTOC_CMD = which protoc > /dev/null
Nicolas Noble53830622015-02-12 16:56:38 -0800358PROTOC_CHECK_CMD = protoc --version | grep -q libprotoc.3
Craig Tiller297fafa2015-01-15 15:46:39 -0800359
Nicolas Noblef8681182015-03-18 14:25:44 -0700360ifeq ($(OPENSSL_REQUIRES_DL),true)
361OPENSSL_ALPN_CHECK_CMD += -ldl
362endif
363
Craig Tiller50524cc2015-01-29 23:00:00 -0800364ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
Craig Tiller297fafa2015-01-15 15:46:39 -0800365HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
366ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
367DEFINES += GRPC_HAVE_PERFTOOLS
368LIBS += profiler
369endif
Craig Tiller50524cc2015-01-29 23:00:00 -0800370endif
nnoble69ac39f2014-12-12 15:43:38 -0800371
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100372HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
Craig Tillerc4da6b72015-01-15 08:01:14 -0800373ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
nnoble60825402014-12-15 14:43:51 -0800374HAS_SYSTEM_OPENSSL_ALPN = $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
375HAS_SYSTEM_ZLIB = $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100376HAS_SYSTEM_PROTOBUF = $(HAS_SYSTEM_PROTOBUF_VERIFY)
Craig Tillerc4da6b72015-01-15 08:01:14 -0800377else
378# override system libraries if the config requires a custom compiled library
379HAS_SYSTEM_OPENSSL_ALPN = false
380HAS_SYSTEM_ZLIB = false
Nicolas Noble53830622015-02-12 16:56:38 -0800381HAS_SYSTEM_PROTOBUF = false
Craig Tillerc4da6b72015-01-15 08:01:14 -0800382endif
nnoble69ac39f2014-12-12 15:43:38 -0800383
Nicolas Noblef8681182015-03-18 14:25:44 -0700384HAS_PROTOC = $(shell $(PROTOC_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100385ifeq ($(HAS_PROTOC),true)
Nicolas Noble53830622015-02-12 16:56:38 -0800386HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100387else
388HAS_VALID_PROTOC = false
389endif
Nicolas Noble53830622015-02-12 16:56:38 -0800390
nnoble69ac39f2014-12-12 15:43:38 -0800391ifeq ($(wildcard third_party/openssl/ssl/ssl.h),)
392HAS_EMBEDDED_OPENSSL_ALPN = false
393else
394HAS_EMBEDDED_OPENSSL_ALPN = true
395endif
396
397ifeq ($(wildcard third_party/zlib/zlib.h),)
398HAS_EMBEDDED_ZLIB = false
399else
400HAS_EMBEDDED_ZLIB = true
401endif
402
Nicolas Noble53830622015-02-12 16:56:38 -0800403ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
404HAS_EMBEDDED_PROTOBUF = false
405ifneq ($(HAS_VALID_PROTOC),true)
406NO_PROTOC = true
407endif
408else
409HAS_EMBEDDED_PROTOBUF = true
410endif
411
nnoble69ac39f2014-12-12 15:43:38 -0800412ifeq ($(HAS_SYSTEM_ZLIB),false)
413ifeq ($(HAS_EMBEDDED_ZLIB),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800414ZLIB_DEP = $(LIBDIR)/$(CONFIG)/zlib/libz.a
nnoble69ac39f2014-12-12 15:43:38 -0800415CPPFLAGS += -Ithird_party/zlib
Craig Tillerda224d62015-02-15 11:01:58 -0800416LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib
nnoble69ac39f2014-12-12 15:43:38 -0800417else
418DEP_MISSING += zlib
419endif
420endif
421
422ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false)
423ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800424OPENSSL_DEP = $(LIBDIR)/$(CONFIG)/openssl/libssl.a
425OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/openssl/libssl.a $(LIBDIR)/$(CONFIG)/openssl/libcrypto.a
Craig Tillerec043032015-02-20 17:24:41 -0800426# need to prefix these to ensure overriding system libraries
427CPPFLAGS := -Ithird_party/openssl/include $(CPPFLAGS)
428LDFLAGS := -L$(LIBDIR)/$(CONFIG)/openssl $(LDFLAGS)
Nicolas Noblef8681182015-03-18 14:25:44 -0700429ifeq ($(OPENSSL_REQUIRES_DL),true)
nnoble5b7f32a2014-12-22 08:12:44 -0800430LIBS_SECURE = dl
Nicolas Noblef8681182015-03-18 14:25:44 -0700431endif
nnoble69ac39f2014-12-12 15:43:38 -0800432else
433NO_SECURE = true
434endif
nnoble5b7f32a2014-12-22 08:12:44 -0800435else
Nicolas Noblef8681182015-03-18 14:25:44 -0700436LIBS_SECURE = $(OPENSSL_LIBS)
437ifeq ($(OPENSSL_REQUIRES_DL),true)
438LIBS_SECURE += dl
439endif
nnoble69ac39f2014-12-12 15:43:38 -0800440endif
441
nnoble5b7f32a2014-12-22 08:12:44 -0800442LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
443
Nicolas Noble53830622015-02-12 16:56:38 -0800444ifeq ($(HAS_SYSTEM_PROTOBUF),false)
445ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800446PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
Craig Tiller9ec95fa2015-02-20 20:36:21 -0800447CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
448LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
Craig Tiller61b910f2015-02-15 10:54:07 -0800449PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
Nicolas Noble53830622015-02-12 16:56:38 -0800450else
451NO_PROTOBUF = true
452endif
453else
454endif
455
456LIBS_PROTOBUF = protobuf
457LIBS_PROTOC = protoc protobuf
458
459LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
460HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
461
Craig Tiller12c82092015-01-15 08:45:56 -0800462ifeq ($(MAKECMDGOALS),clean)
nnoble69ac39f2014-12-12 15:43:38 -0800463NO_DEPS = true
464endif
465
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100466INSTALL_OK = false
467ifeq ($(HAS_VALID_PROTOC),true)
468ifeq ($(HAS_SYSTEM_PROTOBUF_VERIFY),true)
469INSTALL_OK = true
470endif
471endif
472
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800473.SECONDARY = %.pb.h %.pb.cc
474
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100475PROTOC_PLUGINS =\
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800476% for tgt in targets:
477% if tgt.build == 'protoc':
Craig Tiller61b910f2015-02-15 10:54:07 -0800478 $(BINDIR)/$(CONFIG)/${tgt.name}\
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800479% endif
480% endfor
481
nnoble69ac39f2014-12-12 15:43:38 -0800482ifeq ($(DEP_MISSING),)
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100483all: static shared plugins\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800484% for tgt in targets:
485% if tgt.build == 'all':
Craig Tiller61b910f2015-02-15 10:54:07 -0800486 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800487% endif
488% endfor
489
nnoble69ac39f2014-12-12 15:43:38 -0800490dep_error:
491 @echo "You shouldn't see this message - all of your dependencies are correct."
492else
493all: dep_error git_update stop
494
495dep_error:
496 @echo
497 @echo "DEPENDENCY ERROR"
498 @echo
499 @echo "You are missing system dependencies that are essential to build grpc,"
500 @echo "and the third_party directory doesn't have them:"
501 @echo
502 @echo " $(DEP_MISSING)"
503 @echo
504 @echo "Installing the development packages for your system will solve"
505 @echo "this issue. Please consult INSTALL to get more information."
506 @echo
507 @echo "If you need information about why these tests failed, run:"
508 @echo
509 @echo " make run_dep_checks"
510 @echo
511endif
512
513git_update:
514ifeq ($(IS_GIT_FOLDER),true)
515 @echo "Additionally, since you are in a git clone, you can download the"
516 @echo "missing dependencies in third_party by running the following command:"
517 @echo
ctiller64f29102014-12-15 10:40:59 -0800518 @echo " git submodule update --init"
nnoble69ac39f2014-12-12 15:43:38 -0800519 @echo
520endif
521
522openssl_dep_error: openssl_dep_message git_update stop
523
Nicolas Noble53830622015-02-12 16:56:38 -0800524protobuf_dep_error: protobuf_dep_message git_update stop
525
526protoc_dep_error: protoc_dep_message git_update stop
527
nnoble69ac39f2014-12-12 15:43:38 -0800528openssl_dep_message:
529 @echo
530 @echo "DEPENDENCY ERROR"
531 @echo
532 @echo "The target you are trying to run requires OpenSSL with ALPN support."
533 @echo "Your system doesn't have it, and neither does the third_party directory."
534 @echo
535 @echo "Please consult INSTALL to get more information."
536 @echo
537 @echo "If you need information about why these tests failed, run:"
538 @echo
539 @echo " make run_dep_checks"
540 @echo
541
Nicolas Noble53830622015-02-12 16:56:38 -0800542protobuf_dep_message:
543 @echo
544 @echo "DEPENDENCY ERROR"
545 @echo
546 @echo "The target you are trying to run requires protobuf 3.0.0+"
547 @echo "Your system doesn't have it, and neither does the third_party directory."
548 @echo
549 @echo "Please consult INSTALL to get more information."
550 @echo
551 @echo "If you need information about why these tests failed, run:"
552 @echo
553 @echo " make run_dep_checks"
554 @echo
555
556protoc_dep_message:
557 @echo
558 @echo "DEPENDENCY ERROR"
559 @echo
560 @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
561 @echo "Your system doesn't have it, and neither does the third_party directory."
562 @echo
563 @echo "Please consult INSTALL to get more information."
564 @echo
565 @echo "If you need information about why these tests failed, run:"
566 @echo
567 @echo " make run_dep_checks"
568 @echo
569
nnoble69ac39f2014-12-12 15:43:38 -0800570stop:
571 @false
572
ctiller09cb6d52014-12-19 17:38:22 -0800573% for tgt in targets:
Craig Tiller61b910f2015-02-15 10:54:07 -0800574${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
ctiller09cb6d52014-12-19 17:38:22 -0800575% endfor
576
nnoble69ac39f2014-12-12 15:43:38 -0800577run_dep_checks:
nnoble69ac39f2014-12-12 15:43:38 -0800578 $(OPENSSL_ALPN_CHECK_CMD) || true
579 $(ZLIB_CHECK_CMD) || true
Nicolas Noble53830622015-02-12 16:56:38 -0800580 $(PERFTOOLS_CHECK_CMD) || true
581 $(PROTOBUF_CHECK_CMD) || true
582 $(PROTOC_CHECK_CMD) || true
nnoble69ac39f2014-12-12 15:43:38 -0800583
Craig Tiller61b910f2015-02-15 10:54:07 -0800584$(LIBDIR)/$(CONFIG)/zlib/libz.a:
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100585 $(E) "[MAKE] Building zlib"
Nicolas Noblef8681182015-03-18 14:25:44 -0700586 $(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="$(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG))" ./configure --static)
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100587 $(Q)$(MAKE) -C third_party/zlib clean
588 $(Q)$(MAKE) -C third_party/zlib
Craig Tiller61b910f2015-02-15 10:54:07 -0800589 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/zlib
590 $(Q)cp third_party/zlib/libz.a $(LIBDIR)/$(CONFIG)/zlib
nnoble69ac39f2014-12-12 15:43:38 -0800591
Craig Tiller61b910f2015-02-15 10:54:07 -0800592$(LIBDIR)/$(CONFIG)/openssl/libssl.a:
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800593 $(E) "[MAKE] Building openssl for $(SYSTEM)"
594ifeq ($(SYSTEM),Darwin)
Nicolas Noblef8681182015-03-18 14:25:44 -0700595 $(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./Configure darwin64-x86_64-cc)
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800596else
Nicolas Noblef8681182015-03-18 14:25:44 -0700597ifeq ($(SYSTEM),MINGW32)
598 @echo "We currently don't have a good way to compile OpenSSL in-place under msys."
599 @echo "Please provide an ALPN-capable OpenSSL in your mingw32 system."
600 @echo
601 @echo "Note that you can find a compatible version of the libraries here:"
602 @echo
603 @echo "http://slproweb.com/products/Win32OpenSSL.html"
604 @echo
605 @echo "If you decide to install that one, take the full version. The light"
606 @echo "version only contains compiled DLLs, without the development files."
607 @echo
608 @echo "When installing, chose to copy the OpenSSL dlls to the OpenSSL binaries"
609 @echo "directory. This way we'll link to them directly."
610 @echo
611 @echo "You can then re-start the build the following way:"
612 @echo
613 @echo " CPPFLAGS=-I/c/OpenSSL-Win64/include LDFLAGS=-L/c/OpenSSL-Win64 make"
614 @false
615else
616 $(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./config no-asm $(OPENSSL_CONFIG_$(CONFIG)))
617endif
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800618endif
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100619 $(Q)$(MAKE) -C third_party/openssl clean
620 $(Q)$(MAKE) -C third_party/openssl build_crypto build_ssl
Craig Tiller61b910f2015-02-15 10:54:07 -0800621 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/openssl
622 $(Q)cp third_party/openssl/libssl.a third_party/openssl/libcrypto.a $(LIBDIR)/$(CONFIG)/openssl
nnoble69ac39f2014-12-12 15:43:38 -0800623
Nicolas Noble53830622015-02-12 16:56:38 -0800624third_party/protobuf/configure:
625 $(E) "[AUTOGEN] Preparing protobuf"
626 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
627
Craig Tiller61b910f2015-02-15 10:54:07 -0800628$(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
Nicolas Noble53830622015-02-12 16:56:38 -0800629 $(E) "[MAKE] Building protobuf"
Craig Tillercf133f42015-02-26 14:05:56 -0800630ifeq ($(HAVE_CXX11),true)
Nicolas Noblef8681182015-03-18 14:25:44 -0700631 $(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g" CXXFLAGS="-DLANG_CXX11 -std=c++11" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g" ./configure --disable-shared --enable-static)
Craig Tillercf133f42015-02-26 14:05:56 -0800632else
Nicolas Noblef8681182015-03-18 14:25:44 -0700633 $(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g" CXXFLAGS="-std=c++0x" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g" ./configure --disable-shared --enable-static)
Craig Tillercf133f42015-02-26 14:05:56 -0800634endif
Nicolas Noble53830622015-02-12 16:56:38 -0800635 $(Q)$(MAKE) -C third_party/protobuf clean
636 $(Q)$(MAKE) -C third_party/protobuf
Craig Tiller61b910f2015-02-15 10:54:07 -0800637 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
638 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
639 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
640 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
641 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
Nicolas Noble53830622015-02-12 16:56:38 -0800642
nnoble29e1d292014-12-01 10:27:40 -0800643static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800644
Craig Tiller12c82092015-01-15 08:45:56 -0800645static_c: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800646% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800647% if lib.build == 'all' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800648 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800649% endif
650% endfor
651
652
Craig Tiller12c82092015-01-15 08:45:56 -0800653static_cxx: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800654% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800655% if lib.build == 'all' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800656 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
nnoble29e1d292014-12-01 10:27:40 -0800657% endif
658% endfor
659
660
661shared: shared_c shared_cxx
662
Craig Tiller12c82092015-01-15 08:45:56 -0800663shared_c: \
nnoble29e1d292014-12-01 10:27:40 -0800664% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800665% if lib.build == 'all' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800666 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800667% endif
668% endfor
669
670
Craig Tiller12c82092015-01-15 08:45:56 -0800671shared_cxx: \
nnoble29e1d292014-12-01 10:27:40 -0800672% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800673% if lib.build == 'all' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800674 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
nnoble29e1d292014-12-01 10:27:40 -0800675% endif
676% endfor
677
678
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800679shared_csharp: shared_c \
680% for lib in libs:
681% if lib.build == 'all' and lib.language == 'csharp':
682 $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
683% endif
684% endfor
685
686grpc_csharp_ext: shared_csharp
687
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100688plugins: $(PROTOC_PLUGINS)
689
nnoble29e1d292014-12-01 10:27:40 -0800690privatelibs: privatelibs_c privatelibs_cxx
691
Craig Tiller12c82092015-01-15 08:45:56 -0800692privatelibs_c: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800693% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800694% if lib.build == 'private' and lib.language == 'c':
Craig Tiller61b910f2015-02-15 10:54:07 -0800695 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800696% endif
697% endfor
698
699
Craig Tiller12c82092015-01-15 08:45:56 -0800700privatelibs_cxx: \
nnoble29e1d292014-12-01 10:27:40 -0800701% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800702% if lib.build == 'private' and lib.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800703 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800704% endif
705% endfor
706
707
nnoble29e1d292014-12-01 10:27:40 -0800708buildtests: buildtests_c buildtests_cxx
709
Craig Tiller12c82092015-01-15 08:45:56 -0800710buildtests_c: privatelibs_c\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800711% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800712% if tgt.build == 'test' and not tgt.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800713 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800714% endif
715% endfor
716
717
Craig Tiller12c82092015-01-15 08:45:56 -0800718buildtests_cxx: privatelibs_cxx\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800719% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800720% if tgt.build == 'test' and tgt.language == 'c++':
Craig Tiller61b910f2015-02-15 10:54:07 -0800721 $(BINDIR)/$(CONFIG)/${tgt.name}\
nnoble29e1d292014-12-01 10:27:40 -0800722% endif
723% endfor
724
725
nnoble85a49262014-12-08 18:14:03 -0800726test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -0800727
nnoble85a49262014-12-08 18:14:03 -0800728test_c: buildtests_c
nnoble29e1d292014-12-01 10:27:40 -0800729% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800730% if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++':
nnoble29e1d292014-12-01 10:27:40 -0800731 $(E) "[RUN] Testing ${tgt.name}"
Craig Tillerda224d62015-02-15 11:01:58 -0800732 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
nnoble29e1d292014-12-01 10:27:40 -0800733% endif
734% endfor
735
736
nnoble85a49262014-12-08 18:14:03 -0800737test_cxx: buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -0800738% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800739% if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++':
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800740 $(E) "[RUN] Testing ${tgt.name}"
Craig Tillerda224d62015-02-15 11:01:58 -0800741 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800742% endif
743% endfor
744
745
Nicolas "Pixel" Noble051a28f2015-03-17 22:54:54 +0100746test_python: static_c
747 $(E) "[RUN] Testing python code"
748 $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
749
750
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800751tools: privatelibs\
752% for tgt in targets:
753% if tgt.build == 'tool':
Craig Tiller61b910f2015-02-15 10:54:07 -0800754 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800755% endif
756% endfor
757
758
759buildbenchmarks: privatelibs\
760% for tgt in targets:
761% if tgt.build == 'benchmark':
Craig Tiller61b910f2015-02-15 10:54:07 -0800762 $(BINDIR)/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800763% endif
764% endfor
765
766
767benchmarks: buildbenchmarks
768
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800769strip: strip-static strip-shared
770
nnoble20e2e3f2014-12-16 15:37:57 -0800771strip-static: strip-static_c strip-static_cxx
772
773strip-shared: strip-shared_c strip-shared_cxx
774
Nicolas Noble047b7272015-01-16 13:55:05 -0800775
776# TODO(nnoble): the strip target is stripping in-place, instead
777# of copying files in a temporary folder.
778# This prevents proper debugging after running make install.
779
nnoble85a49262014-12-08 18:14:03 -0800780strip-static_c: static_c
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100781ifeq ($(CONFIG),opt)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800782% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800783% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800784% if lib.build == "all":
785 $(E) "[STRIP] Stripping lib${lib.name}.a"
Craig Tiller61b910f2015-02-15 10:54:07 -0800786 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800787% endif
nnoble85a49262014-12-08 18:14:03 -0800788% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800789% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100790endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800791
nnoble85a49262014-12-08 18:14:03 -0800792strip-static_cxx: static_cxx
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100793ifeq ($(CONFIG),opt)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800794% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800795% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800796% if lib.build == "all":
797 $(E) "[STRIP] Stripping lib${lib.name}.a"
Craig Tiller61b910f2015-02-15 10:54:07 -0800798 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
nnoble85a49262014-12-08 18:14:03 -0800799% endif
800% endif
801% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100802endif
nnoble85a49262014-12-08 18:14:03 -0800803
804strip-shared_c: shared_c
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100805ifeq ($(CONFIG),opt)
nnoble85a49262014-12-08 18:14:03 -0800806% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800807% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800808% if lib.build == "all":
809 $(E) "[STRIP] Stripping lib${lib.name}.so"
Craig Tiller61b910f2015-02-15 10:54:07 -0800810 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800811% endif
nnoble85a49262014-12-08 18:14:03 -0800812% endif
813% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100814endif
nnoble85a49262014-12-08 18:14:03 -0800815
816strip-shared_cxx: shared_cxx
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100817ifeq ($(CONFIG),opt)
nnoble85a49262014-12-08 18:14:03 -0800818% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800819% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800820% if lib.build == "all":
821 $(E) "[STRIP] Stripping lib${lib.name}.so"
Craig Tiller61b910f2015-02-15 10:54:07 -0800822 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
nnoble85a49262014-12-08 18:14:03 -0800823% endif
824% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800825% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100826endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800827
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800828strip-shared_csharp: shared_csharp
829ifeq ($(CONFIG),opt)
830% for lib in libs:
831% if lib.language == "csharp":
832% if lib.build == "all":
833 $(E) "[STRIP] Stripping lib${lib.name}.so"
834 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
835% endif
836% endif
837% endfor
838endif
839
nnoble72309c62014-12-12 11:42:26 -0800840% for p in protos:
Nicolas Noble53830622015-02-12 16:56:38 -0800841ifeq ($(NO_PROTOC),true)
Craig Tiller61b910f2015-02-15 10:54:07 -0800842$(GENDIR)/${p}.pb.cc: protoc_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -0800843else
Craig Tiller61b910f2015-02-15 10:54:07 -0800844$(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800845 $(E) "[PROTOC] Generating protobuf CC file from $<"
846 $(Q) mkdir -p `dirname $@`
Vijay Pai850290f2015-02-19 09:59:44 -0800847 $(Q) $(PROTOC) --cpp_out=$(GENDIR) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $<
Nicolas Noble53830622015-02-12 16:56:38 -0800848endif
nnoble72309c62014-12-12 11:42:26 -0800849
850% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800851
Craig Tiller61b910f2015-02-15 10:54:07 -0800852$(OBJDIR)/$(CONFIG)/%.o : %.c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800853 $(E) "[C] Compiling $<"
854 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800855 $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800856
Craig Tiller61b910f2015-02-15 10:54:07 -0800857$(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800858 $(E) "[CXX] Compiling $<"
859 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800860 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800861
Craig Tiller61b910f2015-02-15 10:54:07 -0800862$(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
nnoble72309c62014-12-12 11:42:26 -0800863 $(E) "[HOSTCXX] Compiling $<"
864 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800865 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -0800866
Craig Tiller61b910f2015-02-15 10:54:07 -0800867$(OBJDIR)/$(CONFIG)/%.o : %.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800868 $(E) "[CXX] Compiling $<"
869 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800870 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800871
872
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +0100873install: install_c install_cxx install-plugins install-certs verify-install
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800874
nnoble85a49262014-12-08 18:14:03 -0800875install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800876
nnoble85a49262014-12-08 18:14:03 -0800877install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
878
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800879install_csharp: install-shared_csharp install_c
880
881install_grpc_csharp_ext: install_csharp
882
nnoble85a49262014-12-08 18:14:03 -0800883install-headers: install-headers_c install-headers_cxx
884
885install-headers_c:
886 $(E) "[INSTALL] Installing public C headers"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100887 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -0800888 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
889
890install-headers_cxx:
891 $(E) "[INSTALL] Installing public C++ headers"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100892 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
nnoble85a49262014-12-08 18:14:03 -0800893 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
894
895install-static: install-static_c install-static_cxx
896
897install-static_c: static_c strip-static_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800898% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800899% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800900% if lib.build == "all":
901 $(E) "[INSTALL] Installing lib${lib.name}.a"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100902 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800903 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800904% endif
nnoble85a49262014-12-08 18:14:03 -0800905% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800906% endfor
907
nnoble85a49262014-12-08 18:14:03 -0800908install-static_cxx: static_cxx strip-static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800909% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800910% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800911% if lib.build == "all":
912 $(E) "[INSTALL] Installing lib${lib.name}.a"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100913 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800914 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
nnoble85a49262014-12-08 18:14:03 -0800915% endif
916% endif
917% endfor
918
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100919<%def name="install_shared(lang_filter)">\
nnoble85a49262014-12-08 18:14:03 -0800920% for lib in libs:
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100921% if lib.language == lang_filter:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800922% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -0800923ifeq ($(SYSTEM),MINGW32)
924 $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100925 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800926 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT)
927 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
nnoble5b7f32a2014-12-22 08:12:44 -0800928else
929 $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)"
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100930 $(Q) $(INSTALL) -d $(prefix)/lib
Craig Tiller61b910f2015-02-15 10:54:07 -0800931 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT)
Masood Malekghassemid1be74f2015-04-07 16:23:09 -0700932ifneq ($(SYSTEM),Darwin)
Tim Emiola820e3d62015-04-10 09:11:50 -0700933 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so.${settings.version.major}
nnoble5b7f32a2014-12-22 08:12:44 -0800934 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
935endif
936endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800937% endif
nnoble85a49262014-12-08 18:14:03 -0800938% endif
939% endfor
nnoble5b7f32a2014-12-22 08:12:44 -0800940ifneq ($(SYSTEM),MINGW32)
941ifneq ($(SYSTEM),Darwin)
Nicolas "Pixel" Noblecc2b42a2015-02-20 00:42:21 +0100942 $(Q) ldconfig || true
nnoble5b7f32a2014-12-22 08:12:44 -0800943endif
944endif
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100945</%def>
nnoble85a49262014-12-08 18:14:03 -0800946
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100947install-shared_c: shared_c strip-shared_c
948${install_shared("c")}
949
950install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c
951${install_shared("c++")}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800952
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800953install-shared_csharp: shared_csharp strip-shared_csharp
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100954${install_shared("csharp")}
955
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100956install-plugins: $(PROTOC_PLUGINS)
957ifeq ($(SYSTEM),MINGW32)
958 $(Q) false
959else
960 $(E) "[INSTALL] Installing grpc protoc plugins"
961% for tgt in targets:
962% if tgt.build == 'protoc':
Nicolas "Pixel" Noble932d5d32015-02-21 02:15:34 +0100963 $(Q) $(INSTALL) -d $(prefix)/bin
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100964 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
965% endif
966% endfor
967endif
Jan Tattermusch2ec0b3e2015-02-18 15:03:12 -0800968
Nicolas "Pixel" Noble161ea232015-02-22 05:48:53 +0100969install-certs: etc/roots.pem
970 $(E) "[INSTALL] Installing root certificates"
971 $(Q) $(INSTALL) -d $(prefix)/share/grpc
972 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
973
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100974verify-install:
Nicolas "Pixel" Noble2c23a722015-02-24 20:17:45 +0100975ifeq ($(INSTALL_OK),true)
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100976 @echo "Your system looks ready to go."
977 @echo
978else
murgatroid99b6181362015-03-02 14:32:25 -0800979 @echo "We couldn't find protoc 3.0.0+ installed on your system. While this"
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100980 @echo "won't prevent grpc from working, you won't be able to compile"
981 @echo "and run any meaningful code with it."
982 @echo
983 @echo
984 @echo "Please download and install protobuf 3.0.0+ from:"
985 @echo
986 @echo " https://github.com/google/protobuf/releases"
987 @echo
murgatroid99b6181362015-03-02 14:32:25 -0800988 @echo "Once you've done so, or if you think this message is in error,"
989 @echo "you can re-run this check by doing:"
Nicolas "Pixel" Noble98ab9982015-02-21 04:22:16 +0100990 @echo
991 @echo " make verify-install"
992endif
993
Craig Tiller3759e6f2015-01-15 08:13:11 -0800994clean:
Nicolas "Pixel" Noble522d7122015-02-19 01:28:02 +0100995 $(E) "[CLEAN] Cleaning build directories."
Craig Tillerda224d62015-02-15 11:01:58 -0800996 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800997
998
999# The various libraries
1000
1001% for lib in libs:
1002${makelib(lib)}
1003% endfor
1004
1005
nnoble69ac39f2014-12-12 15:43:38 -08001006# All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001007
1008% for tgt in targets:
1009${maketarget(tgt)}
1010% endfor
1011
1012<%def name="makelib(lib)">
1013LIB${lib.name.upper()}_SRC = \\
1014
1015% for src in lib.src:
nnoble72309c62014-12-12 11:42:26 -08001016 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001017
1018% endfor
1019
1020% if "public_headers" in lib:
Craig Tiller59140fc2015-01-18 10:12:17 -08001021% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -08001022PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001023
nnoble85a49262014-12-08 18:14:03 -08001024% else:
1025PUBLIC_HEADERS_C += \\
1026
1027% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001028% for hdr in lib.public_headers:
1029 ${hdr} \\
1030
1031% endfor
1032% endif
1033
Craig Tiller61b910f2015-02-15 10:54:07 -08001034LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001035
Nicolas Noble047b7272015-01-16 13:55:05 -08001036## If the library requires OpenSSL with ALPN, let's add some restrictions.
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001037% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001038ifeq ($(NO_SECURE),true)
1039
Nicolas Noble047b7272015-01-16 13:55:05 -08001040# You can't build secure libraries if you don't have OpenSSL with ALPN.
1041
Craig Tiller61b910f2015-02-15 10:54:07 -08001042$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001043
nnoble5b7f32a2014-12-22 08:12:44 -08001044% if lib.build == "all":
1045ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -08001046$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -08001047else
Craig Tiller61b910f2015-02-15 10:54:07 -08001048$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -08001049endif
1050% endif
1051
nnoble69ac39f2014-12-12 15:43:38 -08001052else
1053
Nicolas Noble53830622015-02-12 16:56:38 -08001054% if lib.language == 'c++':
1055ifeq ($(NO_PROTOBUF),true)
1056
1057# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
1058
Craig Tiller61b910f2015-02-15 10:54:07 -08001059$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001060
1061% if lib.build == "all":
1062ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -08001063$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001064else
Craig Tiller61b910f2015-02-15 10:54:07 -08001065$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001066endif
1067% endif
1068
1069else
1070% endif
1071
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +01001072ifneq ($(OPENSSL_DEP),)
Nicolas Noble53830622015-02-12 16:56:38 -08001073# This is to ensure the embedded OpenSSL is built beforehand, properly
1074# installing headers to their final destination on the drive. We need this
1075# otherwise parallel compilation will fail if a source is compiled first.
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +01001076% for src in lib.src:
1077${src}: $(OPENSSL_DEP)
1078% endfor
1079endif
1080
Craig Tiller61b910f2015-02-15 10:54:07 -08001081$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
Nicolas Noble047b7272015-01-16 13:55:05 -08001082## The else here corresponds to the if secure earlier.
nnoble20e2e3f2014-12-16 15:37:57 -08001083% else:
Nicolas Noble53830622015-02-12 16:56:38 -08001084% if lib.language == 'c++':
1085ifeq ($(NO_PROTOBUF),true)
1086
1087# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
1088
Craig Tiller61b910f2015-02-15 10:54:07 -08001089$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001090
1091% if lib.build == "all":
1092ifeq ($(SYSTEM),MINGW32)
Craig Tiller61b910f2015-02-15 10:54:07 -08001093$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001094else
Craig Tiller61b910f2015-02-15 10:54:07 -08001095$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001096endif
nnoble20e2e3f2014-12-16 15:37:57 -08001097% endif
Nicolas Noble53830622015-02-12 16:56:38 -08001098
1099else
1100
1101% endif
Craig Tiller61b910f2015-02-15 10:54:07 -08001102$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP)\
Nicolas Noble53830622015-02-12 16:56:38 -08001103% endif
1104% if lib.language == 'c++':
1105 $(PROTOBUF_DEP)\
1106% endif
1107 $(LIB${lib.name.upper()}_OBJS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001108 $(E) "[AR] Creating $@"
nnoble85a49262014-12-08 18:14:03 -08001109 $(Q) mkdir -p `dirname $@`
Craig Tiller61b910f2015-02-15 10:54:07 -08001110 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
1111 $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
nnoble20e2e3f2014-12-16 15:37:57 -08001112% if lib.get('baselib', False):
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001113% if lib.get('secure', 'check') == 'yes':
Craig Tiller7ab4fee2015-02-24 08:15:53 -08001114 $(Q) rm -rf tmp-merge-${lib.name}
1115 $(Q) mkdir tmp-merge-${lib.name}
1116 $(Q) ( cd tmp-merge-${lib.name} ; $(AR) x ../$(LIBDIR)/$(CONFIG)/lib${lib.name}.a )
1117 $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge-${lib.name} ; <%text>ar x ../$${l}</%text> ) ; done
1118 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/__.SYMDEF*
1119 $(Q) ar rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/*
1120 $(Q) rm -rf tmp-merge-${lib.name}
nnoble20e2e3f2014-12-16 15:37:57 -08001121% endif
1122% endif
Craig Tillerb4ee3b52015-01-21 16:22:50 -08001123ifeq ($(SYSTEM),Darwin)
murgatroid99b6181362015-03-02 14:32:25 -08001124 $(Q) ranlib $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
Craig Tillerb4ee3b52015-01-21 16:22:50 -08001125endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001126
nnoble5b7f32a2014-12-22 08:12:44 -08001127<%
Craig Tiller59140fc2015-01-18 10:12:17 -08001128 if lib.language == 'c++':
nnoble5b7f32a2014-12-22 08:12:44 -08001129 ld = '$(LDXX)'
1130 else:
1131 ld = '$(LD)'
1132
Craig Tillerda224d62015-02-15 11:01:58 -08001133 out_base = '$(LIBDIR)/$(CONFIG)/' + lib.name
1134 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name
nnoble5b7f32a2014-12-22 08:12:44 -08001135
1136 common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
1137
1138 libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +01001139 lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -08001140 mingw_libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +01001141 mingw_lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -08001142 for dep in lib.get('deps', []):
1143 libs = libs + ' -l' + dep
Craig Tiller61b910f2015-02-15 10:54:07 -08001144 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001145 mingw_libs = mingw_libs + ' -l' + dep + '-imp'
Craig Tillerda224d62015-02-15 11:01:58 -08001146 mingw_lib_deps = mingw_lib_deps + '$(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -08001147
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001148 if lib.get('secure', 'check') == 'yes':
nnoble5b7f32a2014-12-22 08:12:44 -08001149 common = common + ' $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS)'
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001150
1151 if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble5b7f32a2014-12-22 08:12:44 -08001152 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
1153 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
Nicolas "Pixel" Nobledda049c2015-02-21 00:39:32 +01001154
1155 if lib.language == 'c++':
1156 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
nnoble5b7f32a2014-12-22 08:12:44 -08001157%>
1158
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001159% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -08001160ifeq ($(SYSTEM),MINGW32)
1161${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001162 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -08001163 $(Q) mkdir -p `dirname $@`
Craig Tillerda224d62015-02-15 11:01:58 -08001164 $(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 -08001165else
1166${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
1167 $(E) "[LD] Linking $@"
1168 $(Q) mkdir -p `dirname $@`
1169ifeq ($(SYSTEM),Darwin)
Masood Malekghassemid1be74f2015-04-07 16:23:09 -07001170 $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name lib${lib.name}.$(SHARED_EXT) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
nnoble5b7f32a2014-12-22 08:12:44 -08001171else
Craig Tillerda224d62015-02-15 11:01:58 -08001172 $(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 +01001173 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major}
nnoble5b7f32a2014-12-22 08:12:44 -08001174 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so
1175endif
1176endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001177% endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001178% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
Nicolas Noble047b7272015-01-16 13:55:05 -08001179## If the lib was secure, we have to close the Makefile's if that tested
1180## the presence of an ALPN-capable OpenSSL.
Nicolas Noble53830622015-02-12 16:56:38 -08001181
1182endif
1183% endif
1184% if lib.language == 'c++':
1185## If the lib was C++, we have to close the Makefile's if that tested
1186## the presence of protobuf 3.0.0+
nnoble69ac39f2014-12-12 15:43:38 -08001187
1188endif
1189% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001190
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001191% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001192ifneq ($(NO_SECURE),true)
1193% endif
1194ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -08001195-include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001196endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001197% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001198endif
1199% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001200
Craig Tiller27715ca2015-01-12 16:55:59 -08001201% for src in lib.src:
1202% if not proto_re.match(src):
Craig Tiller61b910f2015-02-15 10:54:07 -08001203$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
Craig Tiller27715ca2015-01-12 16:55:59 -08001204% for src2 in lib.src:
1205% if proto_re.match(src2):
1206 ${proto_to_cc(src2)}\
1207% endif
1208% endfor
1209% endif
1210
1211% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001212</%def>
1213
1214<%def name="maketarget(tgt)">
1215${tgt.name.upper()}_SRC = \\
1216
1217% for src in tgt.src:
nnoble72309c62014-12-12 11:42:26 -08001218 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001219
1220% endfor
1221
Craig Tiller61b910f2015-02-15 10:54:07 -08001222${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001223
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001224% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001225ifeq ($(NO_SECURE),true)
1226
Nicolas Noble047b7272015-01-16 13:55:05 -08001227# You can't build secure targets if you don't have OpenSSL with ALPN.
1228
Craig Tiller61b910f2015-02-15 10:54:07 -08001229$(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -08001230
1231else
1232
1233% endif
Nicolas Noble047b7272015-01-16 13:55:05 -08001234##
1235## We're not trying to add a dependency on building zlib and openssl here,
1236## as it's already done in the libraries. We're assuming that the build
1237## trickles down, and that a secure target requires a secure version of
1238## a library.
1239##
1240## That simplifies the codegen a bit, but prevents a fully defined Makefile.
1241## I can live with that.
1242##
Nicolas "Pixel" Noble18953e32015-02-27 02:41:11 +01001243% if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001244
1245ifeq ($(NO_PROTOBUF),true)
1246
Nicolas "Pixel" Noble18953e32015-02-27 02:41:11 +01001247# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+.
Nicolas Noble53830622015-02-12 16:56:38 -08001248
Craig Tiller61b910f2015-02-15 10:54:07 -08001249$(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
Nicolas Noble53830622015-02-12 16:56:38 -08001250
1251else
1252
Craig Tiller61b910f2015-02-15 10:54:07 -08001253$(BINDIR)/$(CONFIG)/${tgt.name}: $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
Nicolas Noble53830622015-02-12 16:56:38 -08001254% else:
Craig Tiller61b910f2015-02-15 10:54:07 -08001255$(BINDIR)/$(CONFIG)/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
Nicolas Noble53830622015-02-12 16:56:38 -08001256% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001257% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001258 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001259% endfor
1260
Craig Tiller59140fc2015-01-18 10:12:17 -08001261% if tgt.language == "c++":
Nicolas Noble047b7272015-01-16 13:55:05 -08001262## C++ targets specificies.
nnoble72309c62014-12-12 11:42:26 -08001263% if tgt.build == 'protoc':
1264 $(E) "[HOSTLD] Linking $@"
1265 $(Q) mkdir -p `dirname $@`
1266 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(${tgt.name.upper()}_OBJS)\
1267% else:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001268 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -08001269 $(Q) mkdir -p `dirname $@`
nnoblec78b3402014-12-11 16:06:57 -08001270 $(Q) $(LDXX) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
nnoble72309c62014-12-12 11:42:26 -08001271% endif
nnoblec78b3402014-12-11 16:06:57 -08001272% if tgt.build == 'test':
1273 $(GTEST_LIB)\
1274% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001275% else:
Nicolas Noble047b7272015-01-16 13:55:05 -08001276## C-only targets specificities.
nnoble72309c62014-12-12 11:42:26 -08001277 $(E) "[LD] Linking $@"
1278 $(Q) mkdir -p `dirname $@`
nnoble5b7f32a2014-12-22 08:12:44 -08001279 $(Q) $(LD) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001280% endif
1281% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001282 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001283% endfor
Craig Tiller59140fc2015-01-18 10:12:17 -08001284% if tgt.language == "c++":
nnoble72309c62014-12-12 11:42:26 -08001285% if tgt.build == 'protoc':
Nicolas Noble53830622015-02-12 16:56:38 -08001286 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
nnoble72309c62014-12-12 11:42:26 -08001287% else:
Nicolas Noble53830622015-02-12 16:56:38 -08001288 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001289% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001290% endif
nnoblec78b3402014-12-11 16:06:57 -08001291% if tgt.build == 'protoc':
nnoble72309c62014-12-12 11:42:26 -08001292 $(HOST_LDLIBS)\
1293% else:
1294 $(LDLIBS)\
1295% endif
1296% if tgt.build == 'protoc':
1297 $(HOST_LDLIBS_PROTOC)\
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001298% elif tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble72309c62014-12-12 11:42:26 -08001299 $(LDLIBS_SECURE)\
nnoblec78b3402014-12-11 16:06:57 -08001300% endif
Craig Tiller61b910f2015-02-15 10:54:07 -08001301 -o $(BINDIR)/$(CONFIG)/${tgt.name}
Nicolas "Pixel" Noble18953e32015-02-27 02:41:11 +01001302% if tgt.build == 'protoc' or tgt.language == 'c++':
Nicolas Noble53830622015-02-12 16:56:38 -08001303
1304endif
1305% endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001306% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001307
1308endif
1309% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001310
Craig Tillerf5371ef2015-01-12 16:40:18 -08001311% for src in tgt.src:
Craig Tiller61b910f2015-02-15 10:54:07 -08001312$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
Craig Tillerf5371ef2015-01-12 16:40:18 -08001313% for dep in tgt.deps:
Craig Tiller61b910f2015-02-15 10:54:07 -08001314 $(LIBDIR)/$(CONFIG)/lib${dep}.a\
Craig Tillerf5371ef2015-01-12 16:40:18 -08001315% endfor
1316
1317% endfor
1318
Craig Tiller8f126a62015-01-15 08:50:19 -08001319deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001320
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001321% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001322ifneq ($(NO_SECURE),true)
1323% endif
1324ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -08001325-include $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001326endif
Nicolas "Pixel" Noble061690d2015-03-06 22:58:58 +01001327% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
nnoble69ac39f2014-12-12 15:43:38 -08001328endif
1329% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001330</%def>
1331
nnoble85a49262014-12-08 18:14:03 -08001332.PHONY: all strip tools \
nnoble69ac39f2014-12-12 15:43:38 -08001333dep_error openssl_dep_error openssl_dep_message git_update stop \
nnoble85a49262014-12-08 18:14:03 -08001334buildtests buildtests_c buildtests_cxx \
1335test test_c test_cxx \
1336install install_c install_cxx \
1337install-headers install-headers_c install-headers_cxx \
1338install-shared install-shared_c install-shared_cxx \
1339install-static install-static_c install-static_cxx \
1340strip strip-shared strip-static \
1341strip_c strip-shared_c strip-static_c \
1342strip_cxx strip-shared_cxx strip-static_cxx \
Craig Tillerf0afe502015-01-15 09:04:49 -08001343dep_c dep_cxx bins_dep_c bins_dep_cxx \
Craig Tiller12c82092015-01-15 08:45:56 -08001344clean