blob: c34949cf2a7a2d48dff50caea2920823f5634eae [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001# GRPC global makefile
2# This currently builds C and C++ code.
3<%!
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 import re
Craig Tillerf5371ef2015-01-12 16:40:18 -08005 import os
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08006
nnoblec87b1c52015-01-05 17:15:18 -08007 proto_re = re.compile('(.*)\\.proto')
nnoble72309c62014-12-12 11:42:26 -08008
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08009 def excluded(filename, exclude_res):
10 for r in exclude_res:
11 if r.match(filename):
12 return True
13 return False
nnoble72309c62014-12-12 11:42:26 -080014
15 def proto_to_cc(filename):
16 m = proto_re.match(filename)
17 if not m:
18 return filename
19 return 'gens/' + m.group(1) + '.pb.cc'
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080020%>
21
Craig Tiller96b49552015-01-21 16:29:01 -080022
23# Basic platform detection
24HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
25ifeq ($(SYSTEM),)
26SYSTEM = $(HOST_SYSTEM)
27endif
28
29
ctiller8cfebb92015-01-06 15:02:12 -080030# Configurations
31
32VALID_CONFIG_opt = 1
33CC_opt = gcc
34CXX_opt = g++
35LD_opt = gcc
36LDXX_opt = g++
37CPPFLAGS_opt = -O2
38LDFLAGS_opt =
39DEFINES_opt = NDEBUG
40
41VALID_CONFIG_dbg = 1
42CC_dbg = gcc
43CXX_dbg = g++
44LD_dbg = gcc
45LDXX_dbg = g++
46CPPFLAGS_dbg = -O0
47LDFLAGS_dbg =
48DEFINES_dbg = _DEBUG DEBUG
49
Craig Tillerec0b8f32015-01-15 07:30:00 -080050VALID_CONFIG_valgrind = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -080051REQUIRE_CUSTOM_LIBRARIES_valgrind = 1
Craig Tillerec0b8f32015-01-15 07:30:00 -080052CC_valgrind = gcc
53CXX_valgrind = g++
54LD_valgrind = gcc
55LDXX_valgrind = g++
56CPPFLAGS_valgrind = -O0
57OPENSSL_CFLAGS_valgrind = -DPURIFY
58LDFLAGS_valgrind =
59DEFINES_valgrind = _DEBUG DEBUG
60
ctiller8cfebb92015-01-06 15:02:12 -080061VALID_CONFIG_tsan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -080062REQUIRE_CUSTOM_LIBRARIES_tsan = 1
ctiller8cfebb92015-01-06 15:02:12 -080063CC_tsan = clang
64CXX_tsan = clang++
65LD_tsan = clang
66LDXX_tsan = clang++
67CPPFLAGS_tsan = -O1 -fsanitize=thread -fno-omit-frame-pointer
Craig Tillerec0b8f32015-01-15 07:30:00 -080068OPENSSL_CONFIG_tsan = no-asm
ctiller8cfebb92015-01-06 15:02:12 -080069LDFLAGS_tsan = -fsanitize=thread
70DEFINES_tsan = NDEBUG
71
72VALID_CONFIG_asan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -080073REQUIRE_CUSTOM_LIBRARIES_asan = 1
ctiller8cfebb92015-01-06 15:02:12 -080074CC_asan = clang
75CXX_asan = clang++
76LD_asan = clang
77LDXX_asan = clang++
78CPPFLAGS_asan = -O1 -fsanitize=address -fno-omit-frame-pointer
Craig Tillerec0b8f32015-01-15 07:30:00 -080079OPENSSL_CONFIG_asan = no-asm
ctiller8cfebb92015-01-06 15:02:12 -080080LDFLAGS_asan = -fsanitize=address
81DEFINES_asan = NDEBUG
82
83VALID_CONFIG_msan = 1
Craig Tillerc4da6b72015-01-15 08:01:14 -080084REQUIRE_CUSTOM_LIBRARIES_msan = 1
ctiller8cfebb92015-01-06 15:02:12 -080085CC_msan = clang
86CXX_msan = clang++
87LD_msan = clang
88LDXX_msan = clang++
89CPPFLAGS_msan = -O1 -fsanitize=memory -fno-omit-frame-pointer
Craig Tillerec0b8f32015-01-15 07:30:00 -080090OPENSSL_CFLAGS_msan = -DPURIFY
91OPENSSL_CONFIG_msan = no-asm
ctiller8cfebb92015-01-06 15:02:12 -080092LDFLAGS_msan = -fsanitize=memory
93DEFINES_msan = NDEBUG
94
Craig Tiller699ba212015-01-13 17:02:20 -080095VALID_CONFIG_gcov = 1
96CC_gcov = gcc
97CXX_gcov = g++
98LD_gcov = gcc
99LDXX_gcov = g++
100CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage
101LDFLAGS_gcov = -fprofile-arcs -ftest-coverage
102DEFINES_gcov = NDEBUG
103
Nicolas Noble047b7272015-01-16 13:55:05 -0800104
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800105# General settings.
106# You may want to change these depending on your system.
107
108prefix ?= /usr/local
109
110PROTOC = protoc
yangg102e4fe2015-01-06 16:02:50 -0800111CONFIG ?= opt
ctiller8cfebb92015-01-06 15:02:12 -0800112CC = $(CC_$(CONFIG))
113CXX = $(CXX_$(CONFIG))
114LD = $(LD_$(CONFIG))
115LDXX = $(LDXX_$(CONFIG))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800116AR = ar
117STRIP = strip --strip-unneeded
118INSTALL = install -D
119RM = rm -f
120
yangg102e4fe2015-01-06 16:02:50 -0800121ifndef VALID_CONFIG_$(CONFIG)
122$(error Invalid CONFIG value '$(CONFIG)')
123endif
124
Nicolas Noble047b7272015-01-16 13:55:05 -0800125
126# The HOST compiler settings are used to compile the protoc plugins.
127# In most cases, you won't have to change anything, but if you are
128# cross-compiling, you can override these variables from GNU make's
129# command line: make CC=cross-gcc HOST_CC=gcc
130
nnoble72309c62014-12-12 11:42:26 -0800131HOST_CC = $(CC)
132HOST_CXX = $(CXX)
133HOST_LD = $(LD)
134HOST_LDXX = $(LDXX)
135
ctillercab52e72015-01-06 13:10:23 -0800136CPPFLAGS += $(CPPFLAGS_$(CONFIG))
137DEFINES += $(DEFINES_$(CONFIG))
ctiller8cfebb92015-01-06 15:02:12 -0800138LDFLAGS += $(LDFLAGS_$(CONFIG))
ctillercab52e72015-01-06 13:10:23 -0800139
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800140CFLAGS += -std=c89 -pedantic
141CXXFLAGS += -std=c++11
Nicolas "Pixel" Noble213ed912015-01-30 02:11:35 +0100142CPPFLAGS += -g -fPIC -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
Craig Tiller96b49552015-01-21 16:29:01 -0800143LDFLAGS += -g -fPIC
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800144
145INCLUDES = . include gens
Craig Tiller96b49552015-01-21 16:29:01 -0800146ifeq ($(SYSTEM),Darwin)
147LIBS = m z
148else
ctillerc008ae52015-01-07 15:33:00 -0800149LIBS = rt m z pthread
Craig Tiller96b49552015-01-21 16:29:01 -0800150LDFLAGS += -pthread
151endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800152LIBSXX = protobuf
nnoblec78b3402014-12-11 16:06:57 -0800153LIBS_PROTOC = protoc protobuf
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800154
155ifneq ($(wildcard /usr/src/gtest/src/gtest-all.cc),)
156GTEST_LIB = /usr/src/gtest/src/gtest-all.cc -I/usr/src/gtest
157else
158GTEST_LIB = -lgtest
159endif
chenwa8fd44a2014-12-10 15:13:55 -0800160GTEST_LIB += -lgflags
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800161ifeq ($(V),1)
162E = @:
163Q =
164else
165E = @echo
166Q = @
167endif
168
169VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build}
170
171CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
172CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
173
174LDFLAGS += $(ARCH_FLAGS)
175LDLIBS += $(addprefix -l, $(LIBS))
176LDLIBSXX += $(addprefix -l, $(LIBSXX))
nnoble72309c62014-12-12 11:42:26 -0800177HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
178
179HOST_CPPFLAGS = $(CPPFLAGS)
180HOST_CFLAGS = $(CFLAGS)
181HOST_CXXFLAGS = $(CXXFLAGS)
182HOST_LDFLAGS = $(LDFLAGS)
183HOST_LDLIBS = $(LDLIBS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800184
nnoble69ac39f2014-12-12 15:43:38 -0800185
186# These are automatically computed variables.
187# There shouldn't be any need to change anything from now on.
188
nnoble5b7f32a2014-12-22 08:12:44 -0800189ifeq ($(SYSTEM),MINGW32)
190SHARED_EXT = dll
191endif
192ifeq ($(SYSTEM),Darwin)
193SHARED_EXT = dylib
194endif
195ifeq ($(SHARED_EXT),)
196SHARED_EXT = so.$(VERSION)
197endif
198
nnoble69ac39f2014-12-12 15:43:38 -0800199ifeq ($(wildcard .git),)
200IS_GIT_FOLDER = false
201else
202IS_GIT_FOLDER = true
203endif
204
nnoble7e012cf2014-12-22 17:53:44 -0800205OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/openssl-alpn.c -lssl -lcrypto -ldl $(LDFLAGS)
206ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/zlib.c -lz $(LDFLAGS)
Craig Tiller297fafa2015-01-15 15:46:39 -0800207PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/perftools.c -lprofiler $(LDFLAGS)
208
Craig Tiller50524cc2015-01-29 23:00:00 -0800209ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
Craig Tiller297fafa2015-01-15 15:46:39 -0800210HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
211ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
212DEFINES += GRPC_HAVE_PERFTOOLS
213LIBS += profiler
214endif
Craig Tiller50524cc2015-01-29 23:00:00 -0800215endif
nnoble69ac39f2014-12-12 15:43:38 -0800216
Craig Tillerc4da6b72015-01-15 08:01:14 -0800217ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
nnoble60825402014-12-15 14:43:51 -0800218HAS_SYSTEM_OPENSSL_ALPN = $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
219HAS_SYSTEM_ZLIB = $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
Craig Tillerc4da6b72015-01-15 08:01:14 -0800220else
221# override system libraries if the config requires a custom compiled library
222HAS_SYSTEM_OPENSSL_ALPN = false
223HAS_SYSTEM_ZLIB = false
224endif
nnoble69ac39f2014-12-12 15:43:38 -0800225
nnoble69ac39f2014-12-12 15:43:38 -0800226ifeq ($(wildcard third_party/openssl/ssl/ssl.h),)
227HAS_EMBEDDED_OPENSSL_ALPN = false
228else
229HAS_EMBEDDED_OPENSSL_ALPN = true
230endif
231
232ifeq ($(wildcard third_party/zlib/zlib.h),)
233HAS_EMBEDDED_ZLIB = false
234else
235HAS_EMBEDDED_ZLIB = true
236endif
237
nnoble69ac39f2014-12-12 15:43:38 -0800238ifeq ($(HAS_SYSTEM_ZLIB),false)
239ifeq ($(HAS_EMBEDDED_ZLIB),true)
Craig Tiller3ccae022015-01-15 07:47:29 -0800240ZLIB_DEP = libs/$(CONFIG)/zlib/libz.a
nnoble69ac39f2014-12-12 15:43:38 -0800241CPPFLAGS += -Ithird_party/zlib
242LDFLAGS += -Lthird_party/zlib
243else
244DEP_MISSING += zlib
245endif
246endif
247
248ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false)
249ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true)
Craig Tillerec0b8f32015-01-15 07:30:00 -0800250OPENSSL_DEP = libs/$(CONFIG)/openssl/libssl.a
251OPENSSL_MERGE_LIBS += libs/$(CONFIG)/openssl/libssl.a libs/$(CONFIG)/openssl/libcrypto.a
nnoble69ac39f2014-12-12 15:43:38 -0800252CPPFLAGS += -Ithird_party/openssl/include
Craig Tillerec0b8f32015-01-15 07:30:00 -0800253LDFLAGS += -Llibs/$(CONFIG)/openssl
nnoble5b7f32a2014-12-22 08:12:44 -0800254LIBS_SECURE = dl
nnoble69ac39f2014-12-12 15:43:38 -0800255else
256NO_SECURE = true
257endif
nnoble5b7f32a2014-12-22 08:12:44 -0800258else
259LIBS_SECURE = ssl crypto dl
nnoble69ac39f2014-12-12 15:43:38 -0800260endif
261
nnoble5b7f32a2014-12-22 08:12:44 -0800262LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
263
Craig Tiller12c82092015-01-15 08:45:56 -0800264ifeq ($(MAKECMDGOALS),clean)
nnoble69ac39f2014-12-12 15:43:38 -0800265NO_DEPS = true
266endif
267
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800268.SECONDARY = %.pb.h %.pb.cc
269
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800270PROTOC_PLUGINS=\
271% for tgt in targets:
272% if tgt.build == 'protoc':
273 bins/$(CONFIG)/${tgt.name}\
274% endif
275% endfor
276
nnoble69ac39f2014-12-12 15:43:38 -0800277ifeq ($(DEP_MISSING),)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800278all: static shared\
279% for tgt in targets:
280% if tgt.build == 'all':
ctillercab52e72015-01-06 13:10:23 -0800281 bins/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800282% endif
283% endfor
284
nnoble69ac39f2014-12-12 15:43:38 -0800285dep_error:
286 @echo "You shouldn't see this message - all of your dependencies are correct."
287else
288all: dep_error git_update stop
289
290dep_error:
291 @echo
292 @echo "DEPENDENCY ERROR"
293 @echo
294 @echo "You are missing system dependencies that are essential to build grpc,"
295 @echo "and the third_party directory doesn't have them:"
296 @echo
297 @echo " $(DEP_MISSING)"
298 @echo
299 @echo "Installing the development packages for your system will solve"
300 @echo "this issue. Please consult INSTALL to get more information."
301 @echo
302 @echo "If you need information about why these tests failed, run:"
303 @echo
304 @echo " make run_dep_checks"
305 @echo
306endif
307
308git_update:
309ifeq ($(IS_GIT_FOLDER),true)
310 @echo "Additionally, since you are in a git clone, you can download the"
311 @echo "missing dependencies in third_party by running the following command:"
312 @echo
ctiller64f29102014-12-15 10:40:59 -0800313 @echo " git submodule update --init"
nnoble69ac39f2014-12-12 15:43:38 -0800314 @echo
315endif
316
317openssl_dep_error: openssl_dep_message git_update stop
318
319openssl_dep_message:
320 @echo
321 @echo "DEPENDENCY ERROR"
322 @echo
323 @echo "The target you are trying to run requires OpenSSL with ALPN support."
324 @echo "Your system doesn't have it, and neither does the third_party directory."
325 @echo
326 @echo "Please consult INSTALL to get more information."
327 @echo
328 @echo "If you need information about why these tests failed, run:"
329 @echo
330 @echo " make run_dep_checks"
331 @echo
332
333stop:
334 @false
335
ctiller09cb6d52014-12-19 17:38:22 -0800336% for tgt in targets:
ctillercab52e72015-01-06 13:10:23 -0800337${tgt.name}: bins/$(CONFIG)/${tgt.name}
ctiller09cb6d52014-12-19 17:38:22 -0800338% endfor
339
nnoble69ac39f2014-12-12 15:43:38 -0800340run_dep_checks:
nnoble69ac39f2014-12-12 15:43:38 -0800341 $(OPENSSL_ALPN_CHECK_CMD) || true
342 $(ZLIB_CHECK_CMD) || true
343
Craig Tiller3ccae022015-01-15 07:47:29 -0800344libs/$(CONFIG)/zlib/libz.a:
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100345 $(E) "[MAKE] Building zlib"
346 $(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="-fPIC -fvisibility=hidden $(CPPFLAGS_$(CONFIG))" ./configure --static)
347 $(Q)$(MAKE) -C third_party/zlib clean
348 $(Q)$(MAKE) -C third_party/zlib
349 $(Q)mkdir -p libs/$(CONFIG)/zlib
350 $(Q)cp third_party/zlib/libz.a libs/$(CONFIG)/zlib
nnoble69ac39f2014-12-12 15:43:38 -0800351
Craig Tillerec0b8f32015-01-15 07:30:00 -0800352libs/$(CONFIG)/openssl/libssl.a:
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800353 $(E) "[MAKE] Building openssl for $(SYSTEM)"
354ifeq ($(SYSTEM),Darwin)
355 $(Q)(cd third_party/openssl ; CC="$(CC) -fPIC -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./Configure darwin64-x86_64-cc $(OPENSSL_CONFIG_$(CONFIG)))
356else
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100357 $(Q)(cd third_party/openssl ; CC="$(CC) -fPIC -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./config $(OPENSSL_CONFIG_$(CONFIG)))
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800358endif
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100359 $(Q)$(MAKE) -C third_party/openssl clean
360 $(Q)$(MAKE) -C third_party/openssl build_crypto build_ssl
361 $(Q)mkdir -p libs/$(CONFIG)/openssl
362 $(Q)cp third_party/openssl/libssl.a third_party/openssl/libcrypto.a libs/$(CONFIG)/openssl
nnoble69ac39f2014-12-12 15:43:38 -0800363
nnoble29e1d292014-12-01 10:27:40 -0800364static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800365
Craig Tiller12c82092015-01-15 08:45:56 -0800366static_c: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800367% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800368% if lib.build == 'all' and lib.language == 'c':
ctillercab52e72015-01-06 13:10:23 -0800369 libs/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800370% endif
371% endfor
372
373
Craig Tiller12c82092015-01-15 08:45:56 -0800374static_cxx: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800375% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800376% if lib.build == 'all' and lib.language == 'c++':
ctillercab52e72015-01-06 13:10:23 -0800377 libs/$(CONFIG)/lib${lib.name}.a\
nnoble29e1d292014-12-01 10:27:40 -0800378% endif
379% endfor
380
381
382shared: shared_c shared_cxx
383
Craig Tiller12c82092015-01-15 08:45:56 -0800384shared_c: \
nnoble29e1d292014-12-01 10:27:40 -0800385% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800386% if lib.build == 'all' and lib.language == 'c':
ctillercab52e72015-01-06 13:10:23 -0800387 libs/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800388% endif
389% endfor
390
391
Craig Tiller12c82092015-01-15 08:45:56 -0800392shared_cxx: \
nnoble29e1d292014-12-01 10:27:40 -0800393% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800394% if lib.build == 'all' and lib.language == 'c++':
ctillercab52e72015-01-06 13:10:23 -0800395 libs/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
nnoble29e1d292014-12-01 10:27:40 -0800396% endif
397% endfor
398
399
400privatelibs: privatelibs_c privatelibs_cxx
401
Craig Tiller12c82092015-01-15 08:45:56 -0800402privatelibs_c: \
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800403% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800404% if lib.build == 'private' and lib.language == 'c':
ctillercab52e72015-01-06 13:10:23 -0800405 libs/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800406% endif
407% endfor
408
409
Craig Tiller12c82092015-01-15 08:45:56 -0800410privatelibs_cxx: \
nnoble29e1d292014-12-01 10:27:40 -0800411% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800412% if lib.build == 'private' and lib.language == 'c++':
ctillercab52e72015-01-06 13:10:23 -0800413 libs/$(CONFIG)/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800414% endif
415% endfor
416
417
nnoble29e1d292014-12-01 10:27:40 -0800418buildtests: buildtests_c buildtests_cxx
419
Craig Tiller12c82092015-01-15 08:45:56 -0800420buildtests_c: privatelibs_c\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800421% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800422% if tgt.build == 'test' and not tgt.language == 'c++':
ctillercab52e72015-01-06 13:10:23 -0800423 bins/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800424% endif
425% endfor
426
427
Craig Tiller12c82092015-01-15 08:45:56 -0800428buildtests_cxx: privatelibs_cxx\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800429% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800430% if tgt.build == 'test' and tgt.language == 'c++':
Craig Tillerf5371ef2015-01-12 16:40:18 -0800431 bins/$(CONFIG)/${tgt.name}\
nnoble29e1d292014-12-01 10:27:40 -0800432% endif
433% endfor
434
435
nnoble85a49262014-12-08 18:14:03 -0800436test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -0800437
nnoble85a49262014-12-08 18:14:03 -0800438test_c: buildtests_c
nnoble29e1d292014-12-01 10:27:40 -0800439% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800440% if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++':
nnoble29e1d292014-12-01 10:27:40 -0800441 $(E) "[RUN] Testing ${tgt.name}"
ctillercab52e72015-01-06 13:10:23 -0800442 $(Q) ./bins/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
nnoble29e1d292014-12-01 10:27:40 -0800443% endif
444% endfor
445
446
nnoble85a49262014-12-08 18:14:03 -0800447test_cxx: buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -0800448% for tgt in targets:
Craig Tiller59140fc2015-01-18 10:12:17 -0800449% if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++':
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800450 $(E) "[RUN] Testing ${tgt.name}"
ctillercab52e72015-01-06 13:10:23 -0800451 $(Q) ./bins/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800452% endif
453% endfor
454
455
456tools: privatelibs\
457% for tgt in targets:
458% if tgt.build == 'tool':
ctillercab52e72015-01-06 13:10:23 -0800459 bins/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800460% endif
461% endfor
462
463
464buildbenchmarks: privatelibs\
465% for tgt in targets:
466% if tgt.build == 'benchmark':
ctillercab52e72015-01-06 13:10:23 -0800467 bins/$(CONFIG)/${tgt.name}\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800468% endif
469% endfor
470
471
472benchmarks: buildbenchmarks
473
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800474strip: strip-static strip-shared
475
nnoble20e2e3f2014-12-16 15:37:57 -0800476strip-static: strip-static_c strip-static_cxx
477
478strip-shared: strip-shared_c strip-shared_cxx
479
Nicolas Noble047b7272015-01-16 13:55:05 -0800480
481# TODO(nnoble): the strip target is stripping in-place, instead
482# of copying files in a temporary folder.
483# This prevents proper debugging after running make install.
484
nnoble85a49262014-12-08 18:14:03 -0800485strip-static_c: static_c
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100486ifeq ($(CONFIG),opt)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800487% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800488% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800489% if lib.build == "all":
490 $(E) "[STRIP] Stripping lib${lib.name}.a"
ctillercab52e72015-01-06 13:10:23 -0800491 $(Q) $(STRIP) libs/$(CONFIG)/lib${lib.name}.a
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800492% endif
nnoble85a49262014-12-08 18:14:03 -0800493% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800494% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100495endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800496
nnoble85a49262014-12-08 18:14:03 -0800497strip-static_cxx: static_cxx
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100498ifeq ($(CONFIG),opt)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800499% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800500% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800501% if lib.build == "all":
502 $(E) "[STRIP] Stripping lib${lib.name}.a"
ctillercab52e72015-01-06 13:10:23 -0800503 $(Q) $(STRIP) libs/$(CONFIG)/lib${lib.name}.a
nnoble85a49262014-12-08 18:14:03 -0800504% endif
505% endif
506% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100507endif
nnoble85a49262014-12-08 18:14:03 -0800508
509strip-shared_c: shared_c
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100510ifeq ($(CONFIG),opt)
nnoble85a49262014-12-08 18:14:03 -0800511% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800512% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800513% if lib.build == "all":
514 $(E) "[STRIP] Stripping lib${lib.name}.so"
ctillercab52e72015-01-06 13:10:23 -0800515 $(Q) $(STRIP) libs/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800516% endif
nnoble85a49262014-12-08 18:14:03 -0800517% endif
518% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100519endif
nnoble85a49262014-12-08 18:14:03 -0800520
521strip-shared_cxx: shared_cxx
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100522ifeq ($(CONFIG),opt)
nnoble85a49262014-12-08 18:14:03 -0800523% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800524% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800525% if lib.build == "all":
526 $(E) "[STRIP] Stripping lib${lib.name}.so"
ctillercab52e72015-01-06 13:10:23 -0800527 $(Q) $(STRIP) libs/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
nnoble85a49262014-12-08 18:14:03 -0800528% endif
529% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800530% endfor
Nicolas "Pixel" Noble3a2551c2015-01-29 21:33:32 +0100531endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800532
nnoble72309c62014-12-12 11:42:26 -0800533% for p in protos:
Craig Tillerf58b9ef2015-01-15 09:09:12 -0800534gens/${p}.pb.cc: ${p}.proto $(PROTOC_PLUGINS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800535 $(E) "[PROTOC] Generating protobuf CC file from $<"
536 $(Q) mkdir -p `dirname $@`
ctillercab52e72015-01-06 13:10:23 -0800537 $(Q) $(PROTOC) --cpp_out=gens --grpc_out=gens --plugin=protoc-gen-grpc=bins/$(CONFIG)/cpp_plugin $<
nnoble72309c62014-12-12 11:42:26 -0800538
539% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800540
ctillercab52e72015-01-06 13:10:23 -0800541objs/$(CONFIG)/%.o : %.c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800542 $(E) "[C] Compiling $<"
543 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800544 $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800545
ctillercab52e72015-01-06 13:10:23 -0800546objs/$(CONFIG)/%.o : gens/%.pb.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800547 $(E) "[CXX] Compiling $<"
548 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800549 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800550
ctillercab52e72015-01-06 13:10:23 -0800551objs/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
nnoble72309c62014-12-12 11:42:26 -0800552 $(E) "[HOSTCXX] Compiling $<"
553 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800554 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
nnoble72309c62014-12-12 11:42:26 -0800555
ctillercab52e72015-01-06 13:10:23 -0800556objs/$(CONFIG)/%.o : %.cc
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800557 $(E) "[CXX] Compiling $<"
558 $(Q) mkdir -p `dirname $@`
Craig Tiller12c82092015-01-15 08:45:56 -0800559 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800560
561
nnoble85a49262014-12-08 18:14:03 -0800562install: install_c install_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800563
nnoble85a49262014-12-08 18:14:03 -0800564install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800565
nnoble85a49262014-12-08 18:14:03 -0800566install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
567
568install-headers: install-headers_c install-headers_cxx
569
570install-headers_c:
571 $(E) "[INSTALL] Installing public C headers"
572 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
573
574install-headers_cxx:
575 $(E) "[INSTALL] Installing public C++ headers"
576 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
577
578install-static: install-static_c install-static_cxx
579
580install-static_c: static_c strip-static_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800581% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800582% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800583% if lib.build == "all":
584 $(E) "[INSTALL] Installing lib${lib.name}.a"
ctillercab52e72015-01-06 13:10:23 -0800585 $(Q) $(INSTALL) libs/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800586% endif
nnoble85a49262014-12-08 18:14:03 -0800587% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800588% endfor
589
nnoble85a49262014-12-08 18:14:03 -0800590install-static_cxx: static_cxx strip-static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800591% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800592% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800593% if lib.build == "all":
594 $(E) "[INSTALL] Installing lib${lib.name}.a"
ctillercab52e72015-01-06 13:10:23 -0800595 $(Q) $(INSTALL) libs/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
nnoble85a49262014-12-08 18:14:03 -0800596% endif
597% endif
598% endfor
599
600install-shared_c: shared_c strip-shared_c
601% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800602% if lib.language == "c":
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800603% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -0800604ifeq ($(SYSTEM),MINGW32)
605 $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)"
ctillercab52e72015-01-06 13:10:23 -0800606 $(Q) $(INSTALL) libs/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT)
607 $(Q) $(INSTALL) libs/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
nnoble5b7f32a2014-12-22 08:12:44 -0800608else
609 $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)"
ctillercab52e72015-01-06 13:10:23 -0800610 $(Q) $(INSTALL) libs/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT)
nnoble5b7f32a2014-12-22 08:12:44 -0800611ifneq ($(SYSTEM),Darwin)
612 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
613endif
614endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800615% endif
nnoble85a49262014-12-08 18:14:03 -0800616% endif
617% endfor
nnoble5b7f32a2014-12-22 08:12:44 -0800618ifneq ($(SYSTEM),MINGW32)
619ifneq ($(SYSTEM),Darwin)
620 $(Q) ldconfig
621endif
622endif
nnoble85a49262014-12-08 18:14:03 -0800623
624install-shared_cxx: shared_cxx strip-shared_cxx
625% for lib in libs:
Craig Tiller59140fc2015-01-18 10:12:17 -0800626% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800627% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -0800628ifeq ($(SYSTEM),MINGW32)
629 $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)"
ctillercab52e72015-01-06 13:10:23 -0800630 $(Q) $(INSTALL) libs/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT)
631 $(Q) $(INSTALL) libs/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
nnoble5b7f32a2014-12-22 08:12:44 -0800632else
633 $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)"
ctillercab52e72015-01-06 13:10:23 -0800634 $(Q) $(INSTALL) libs/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT)
nnoble5b7f32a2014-12-22 08:12:44 -0800635ifneq ($(SYSTEM),Darwin)
636 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
637endif
638endif
nnoble85a49262014-12-08 18:14:03 -0800639% endif
640% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800641% endfor
nnoble5b7f32a2014-12-22 08:12:44 -0800642ifneq ($(SYSTEM),MINGW32)
643ifneq ($(SYSTEM),Darwin)
644 $(Q) ldconfig
645endif
646endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800647
Craig Tiller3759e6f2015-01-15 08:13:11 -0800648clean:
Craig Tiller12c82092015-01-15 08:45:56 -0800649 $(Q) $(RM) -rf objs libs bins gens
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800650
651
652# The various libraries
653
654% for lib in libs:
655${makelib(lib)}
656% endfor
657
658
nnoble69ac39f2014-12-12 15:43:38 -0800659# All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800660
661% for tgt in targets:
662${maketarget(tgt)}
663% endfor
664
665<%def name="makelib(lib)">
666LIB${lib.name.upper()}_SRC = \\
667
668% for src in lib.src:
nnoble72309c62014-12-12 11:42:26 -0800669 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800670
671% endfor
672
673% if "public_headers" in lib:
Craig Tiller59140fc2015-01-18 10:12:17 -0800674% if lib.language == "c++":
nnoble85a49262014-12-08 18:14:03 -0800675PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800676
nnoble85a49262014-12-08 18:14:03 -0800677% else:
678PUBLIC_HEADERS_C += \\
679
680% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800681% for hdr in lib.public_headers:
682 ${hdr} \\
683
684% endfor
685% endif
686
ctillercab52e72015-01-06 13:10:23 -0800687LIB${lib.name.upper()}_OBJS = $(addprefix objs/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800688
Nicolas Noble047b7272015-01-16 13:55:05 -0800689## If the library requires OpenSSL with ALPN, let's add some restrictions.
nnoble69ac39f2014-12-12 15:43:38 -0800690% if lib.get('secure', True):
nnoble69ac39f2014-12-12 15:43:38 -0800691ifeq ($(NO_SECURE),true)
692
Nicolas Noble047b7272015-01-16 13:55:05 -0800693# You can't build secure libraries if you don't have OpenSSL with ALPN.
694
ctillercab52e72015-01-06 13:10:23 -0800695libs/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -0800696
nnoble5b7f32a2014-12-22 08:12:44 -0800697% if lib.build == "all":
698ifeq ($(SYSTEM),MINGW32)
ctillercab52e72015-01-06 13:10:23 -0800699libs/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -0800700else
ctillercab52e72015-01-06 13:10:23 -0800701libs/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error
nnoble5b7f32a2014-12-22 08:12:44 -0800702endif
703% endif
704
nnoble69ac39f2014-12-12 15:43:38 -0800705else
706
Nicolas "Pixel" Noble17f2b592015-01-16 07:09:10 +0100707ifneq ($(OPENSSL_DEP),)
708% for src in lib.src:
709${src}: $(OPENSSL_DEP)
710% endfor
711endif
712
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +0100713libs/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(LIB${lib.name.upper()}_OBJS)
Nicolas Noble047b7272015-01-16 13:55:05 -0800714## The else here corresponds to the if secure earlier.
nnoble20e2e3f2014-12-16 15:37:57 -0800715% else:
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +0100716libs/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(LIB${lib.name.upper()}_OBJS)
nnoble20e2e3f2014-12-16 15:37:57 -0800717% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800718 $(E) "[AR] Creating $@"
nnoble85a49262014-12-08 18:14:03 -0800719 $(Q) mkdir -p `dirname $@`
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800720 $(Q) rm -f libs/$(CONFIG)/lib${lib.name}.a
ctillercab52e72015-01-06 13:10:23 -0800721 $(Q) $(AR) rcs libs/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
nnoble20e2e3f2014-12-16 15:37:57 -0800722% if lib.get('baselib', False):
723% if lib.get('secure', True):
Craig Tillerf5371ef2015-01-12 16:40:18 -0800724 $(Q) rm -rf tmp-merge
nnoble20e2e3f2014-12-16 15:37:57 -0800725 $(Q) mkdir tmp-merge
ctillercab52e72015-01-06 13:10:23 -0800726 $(Q) ( cd tmp-merge ; $(AR) x ../libs/$(CONFIG)/lib${lib.name}.a )
nnoble20e2e3f2014-12-16 15:37:57 -0800727 $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge ; <%text>ar x ../$${l}</%text> ) ; done
ctillercab52e72015-01-06 13:10:23 -0800728 $(Q) rm -f libs/$(CONFIG)/lib${lib.name}.a tmp-merge/__.SYMDEF*
729 $(Q) ar rcs libs/$(CONFIG)/lib${lib.name}.a tmp-merge/*
nnoble20e2e3f2014-12-16 15:37:57 -0800730 $(Q) rm -rf tmp-merge
731% endif
732% endif
Craig Tillerb4ee3b52015-01-21 16:22:50 -0800733ifeq ($(SYSTEM),Darwin)
734 $(Q) ranlib libs/$(CONFIG)/lib${lib.name}.a
735endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800736
nnoble5b7f32a2014-12-22 08:12:44 -0800737<%
Craig Tiller59140fc2015-01-18 10:12:17 -0800738 if lib.language == 'c++':
nnoble5b7f32a2014-12-22 08:12:44 -0800739 ld = '$(LDXX)'
740 else:
741 ld = '$(LD)'
742
ctillercab52e72015-01-06 13:10:23 -0800743 out_base = 'libs/$(CONFIG)/' + lib.name
744 out_libbase = 'libs/$(CONFIG)/lib' + lib.name
nnoble5b7f32a2014-12-22 08:12:44 -0800745
746 common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
747
748 libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +0100749 lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -0800750 mingw_libs = ''
Nicolas "Pixel" Noble85bf09b2015-01-15 18:22:40 +0100751 mingw_lib_deps = ' $(ZLIB_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -0800752 for dep in lib.get('deps', []):
753 libs = libs + ' -l' + dep
Craig Tillera614caa2015-01-15 09:33:21 -0800754 lib_deps = lib_deps + ' libs/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -0800755 mingw_libs = mingw_libs + ' -l' + dep + '-imp'
ctillercab52e72015-01-06 13:10:23 -0800756 mingw_lib_deps = mingw_lib_deps + 'libs/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
nnoble5b7f32a2014-12-22 08:12:44 -0800757
758 if lib.get('secure', True):
759 common = common + ' $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS)'
760 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
761 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
nnoble5b7f32a2014-12-22 08:12:44 -0800762%>
763
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800764% if lib.build == "all":
nnoble5b7f32a2014-12-22 08:12:44 -0800765ifeq ($(SYSTEM),MINGW32)
766${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800767 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -0800768 $(Q) mkdir -p `dirname $@`
ctillercab52e72015-01-06 13:10:23 -0800769 $(Q) ${ld} $(LDFLAGS) -Llibs/$(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 -0800770else
771${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
772 $(E) "[LD] Linking $@"
773 $(Q) mkdir -p `dirname $@`
774ifeq ($(SYSTEM),Darwin)
ctillercab52e72015-01-06 13:10:23 -0800775 $(Q) ${ld} $(LDFLAGS) -Llibs/$(CONFIG) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
nnoble5b7f32a2014-12-22 08:12:44 -0800776else
ctillercab52e72015-01-06 13:10:23 -0800777 $(Q) ${ld} $(LDFLAGS) -Llibs/$(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 +0100778 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major}
nnoble5b7f32a2014-12-22 08:12:44 -0800779 $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so
780endif
781endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800782% endif
783
Nicolas Noble047b7272015-01-16 13:55:05 -0800784## If the lib was secure, we have to close the Makefile's if that tested
785## the presence of an ALPN-capable OpenSSL.
nnoble69ac39f2014-12-12 15:43:38 -0800786% if lib.get('secure', True):
787
788endif
789% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800790
nnoble69ac39f2014-12-12 15:43:38 -0800791% if lib.get('secure', True):
792ifneq ($(NO_SECURE),true)
793% endif
794ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -0800795-include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800796endif
nnoble69ac39f2014-12-12 15:43:38 -0800797% if lib.get('secure', True):
798endif
799% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800800
Craig Tiller27715ca2015-01-12 16:55:59 -0800801% for src in lib.src:
802% if not proto_re.match(src):
803objs/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
804% for src2 in lib.src:
805% if proto_re.match(src2):
806 ${proto_to_cc(src2)}\
807% endif
808% endfor
809% endif
810
811% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800812</%def>
813
814<%def name="maketarget(tgt)">
815${tgt.name.upper()}_SRC = \\
816
817% for src in tgt.src:
nnoble72309c62014-12-12 11:42:26 -0800818 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800819
820% endfor
821
ctillercab52e72015-01-06 13:10:23 -0800822${tgt.name.upper()}_OBJS = $(addprefix objs/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800823
nnoble69ac39f2014-12-12 15:43:38 -0800824% if tgt.get('secure', True):
825ifeq ($(NO_SECURE),true)
826
Nicolas Noble047b7272015-01-16 13:55:05 -0800827# You can't build secure targets if you don't have OpenSSL with ALPN.
828
ctillercab52e72015-01-06 13:10:23 -0800829bins/$(CONFIG)/${tgt.name}: openssl_dep_error
nnoble69ac39f2014-12-12 15:43:38 -0800830
831else
832
833% endif
Nicolas Noble047b7272015-01-16 13:55:05 -0800834##
835## We're not trying to add a dependency on building zlib and openssl here,
836## as it's already done in the libraries. We're assuming that the build
837## trickles down, and that a secure target requires a secure version of
838## a library.
839##
840## That simplifies the codegen a bit, but prevents a fully defined Makefile.
841## I can live with that.
842##
ctillercab52e72015-01-06 13:10:23 -0800843bins/$(CONFIG)/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800844% for dep in tgt.deps:
ctillercab52e72015-01-06 13:10:23 -0800845 libs/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800846% endfor
847
Craig Tiller59140fc2015-01-18 10:12:17 -0800848% if tgt.language == "c++":
Nicolas Noble047b7272015-01-16 13:55:05 -0800849## C++ targets specificies.
nnoble72309c62014-12-12 11:42:26 -0800850% if tgt.build == 'protoc':
851 $(E) "[HOSTLD] Linking $@"
852 $(Q) mkdir -p `dirname $@`
853 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(${tgt.name.upper()}_OBJS)\
854% else:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800855 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -0800856 $(Q) mkdir -p `dirname $@`
nnoblec78b3402014-12-11 16:06:57 -0800857 $(Q) $(LDXX) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
nnoble72309c62014-12-12 11:42:26 -0800858% endif
nnoblec78b3402014-12-11 16:06:57 -0800859% if tgt.build == 'test':
860 $(GTEST_LIB)\
861% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800862% else:
Nicolas Noble047b7272015-01-16 13:55:05 -0800863## C-only targets specificities.
nnoble72309c62014-12-12 11:42:26 -0800864 $(E) "[LD] Linking $@"
865 $(Q) mkdir -p `dirname $@`
nnoble5b7f32a2014-12-22 08:12:44 -0800866 $(Q) $(LD) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800867% endif
868% for dep in tgt.deps:
ctillercab52e72015-01-06 13:10:23 -0800869 libs/$(CONFIG)/lib${dep}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800870% endfor
Craig Tiller59140fc2015-01-18 10:12:17 -0800871% if tgt.language == "c++":
nnoble72309c62014-12-12 11:42:26 -0800872% if tgt.build == 'protoc':
873 $(HOST_LDLIBSXX)\
874% else:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800875 $(LDLIBSXX)\
876% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800877% endif
nnoblec78b3402014-12-11 16:06:57 -0800878% if tgt.build == 'protoc':
nnoble72309c62014-12-12 11:42:26 -0800879 $(HOST_LDLIBS)\
880% else:
881 $(LDLIBS)\
882% endif
883% if tgt.build == 'protoc':
884 $(HOST_LDLIBS_PROTOC)\
885% elif tgt.get('secure', True):
886 $(LDLIBS_SECURE)\
nnoblec78b3402014-12-11 16:06:57 -0800887% endif
ctillercab52e72015-01-06 13:10:23 -0800888 -o bins/$(CONFIG)/${tgt.name}
nnoble69ac39f2014-12-12 15:43:38 -0800889% if tgt.get('secure', True):
890
891endif
892% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800893
Craig Tillerf5371ef2015-01-12 16:40:18 -0800894% for src in tgt.src:
895objs/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
896% for dep in tgt.deps:
897 libs/$(CONFIG)/lib${dep}.a\
898% endfor
899
900% endfor
901
Craig Tiller8f126a62015-01-15 08:50:19 -0800902deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800903
nnoble69ac39f2014-12-12 15:43:38 -0800904% if tgt.get('secure', True):
905ifneq ($(NO_SECURE),true)
906% endif
907ifneq ($(NO_DEPS),true)
Craig Tiller8f126a62015-01-15 08:50:19 -0800908-include $(${tgt.name.upper()}_OBJS:.o=.dep)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800909endif
nnoble69ac39f2014-12-12 15:43:38 -0800910% if tgt.get('secure', True):
911endif
912% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800913</%def>
914
nnoble85a49262014-12-08 18:14:03 -0800915.PHONY: all strip tools \
nnoble69ac39f2014-12-12 15:43:38 -0800916dep_error openssl_dep_error openssl_dep_message git_update stop \
nnoble85a49262014-12-08 18:14:03 -0800917buildtests buildtests_c buildtests_cxx \
918test test_c test_cxx \
919install install_c install_cxx \
920install-headers install-headers_c install-headers_cxx \
921install-shared install-shared_c install-shared_cxx \
922install-static install-static_c install-static_cxx \
923strip strip-shared strip-static \
924strip_c strip-shared_c strip-static_c \
925strip_cxx strip-shared_cxx strip-static_cxx \
Craig Tillerf0afe502015-01-15 09:04:49 -0800926dep_c dep_cxx bins_dep_c bins_dep_cxx \
Craig Tiller12c82092015-01-15 08:45:56 -0800927clean
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800928