blob: 5189000a4c05f744b5cf2a66251f42c350df107f [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001# GRPC global makefile
2# This currently builds C and C++ code.
3<%!
4 from copy import deepcopy
5 import re
6
nnoble72309c62014-12-12 11:42:26 -08007 proto_re = re.compile('(.*)\.proto')
8
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
22<%
23 altlibs = []
24 for lib in libs:
25 for alt in lib.get('alternates', []):
26 new = deepcopy(lib)
27 new.name = alt.name
28 new.alternates = []
29 exclude_res = [re.compile(str) for str in alt.get('exclude_res', [])]
30
31 src = [file for file in new.get('src', []) if not excluded(file, exclude_res)]
32 src.extend(alt.get('include_src', []))
33 new.src = src
34
35 headers = [file for file in new.get('headers', []) if not excluded(file, exclude_res)]
36 headers.extend(alt.get('include_headers', []))
37 new.headers = headers
38
39 public_headers = [file for file in new.get('public_headers', []) if not excluded(file, exclude_res)]
40 public_headers.extend(alt.get('include_public_headers', []))
41 new.public_headers = public_headers
42
43 for prop in alt.properties:
44 new[prop.name] = prop.value
45
46 altlibs.append(new)
47 libs.extend(altlibs)
48
nnoble72309c62014-12-12 11:42:26 -080049 protos = set()
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080050 for lib in libs:
51 for src in lib.src:
nnoble72309c62014-12-12 11:42:26 -080052 m = proto_re.match(src)
53 if m:
54 protos.add(m.group(1))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080055 for tgt in targets:
56 for src in tgt.src:
nnoble72309c62014-12-12 11:42:26 -080057 m = proto_re.match(src)
58 if m:
59 protos.add(m.group(1))
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080060
nnoble72309c62014-12-12 11:42:26 -080061 protos = sorted(protos)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080062%>
63
64# General settings.
65# You may want to change these depending on your system.
66
67prefix ?= /usr/local
68
69PROTOC = protoc
70CC = gcc
71CXX = g++
72LD = gcc
73LDXX = g++
74AR = ar
75STRIP = strip --strip-unneeded
76INSTALL = install -D
77RM = rm -f
78
nnoble72309c62014-12-12 11:42:26 -080079HOST_CC = $(CC)
80HOST_CXX = $(CXX)
81HOST_LD = $(LD)
82HOST_LDXX = $(LDXX)
83
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080084ifeq ($(DEBUG),)
85CPPFLAGS += -O2
86DEFINES += NDEBUG
87else
88CPPFLAGS += -O0
89DEFINES += _DEBUG DEBUG
90endif
91
92CFLAGS += -std=c89 -pedantic
93CXXFLAGS += -std=c++11
94CPPFLAGS += -g -fPIC -Wall -Werror -Wno-long-long
95LDFLAGS += -g -pthread -fPIC
96
97INCLUDES = . include gens
98LIBS = rt m z event event_pthreads pthread
99LIBSXX = protobuf
100LIBS_SECURE = ssl crypto dl
nnoblec78b3402014-12-11 16:06:57 -0800101LIBS_PROTOC = protoc protobuf
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800102
103ifneq ($(wildcard /usr/src/gtest/src/gtest-all.cc),)
104GTEST_LIB = /usr/src/gtest/src/gtest-all.cc -I/usr/src/gtest
105else
106GTEST_LIB = -lgtest
107endif
chenwa8fd44a2014-12-10 15:13:55 -0800108GTEST_LIB += -lgflags
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800109ifeq ($(V),1)
110E = @:
111Q =
112else
113E = @echo
114Q = @
115endif
116
117VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build}
118
119CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
120CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
121
122LDFLAGS += $(ARCH_FLAGS)
123LDLIBS += $(addprefix -l, $(LIBS))
124LDLIBSXX += $(addprefix -l, $(LIBSXX))
125LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
nnoble72309c62014-12-12 11:42:26 -0800126HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
127
128HOST_CPPFLAGS = $(CPPFLAGS)
129HOST_CFLAGS = $(CFLAGS)
130HOST_CXXFLAGS = $(CXXFLAGS)
131HOST_LDFLAGS = $(LDFLAGS)
132HOST_LDLIBS = $(LDLIBS)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800133
nnoble69ac39f2014-12-12 15:43:38 -0800134
135# These are automatically computed variables.
136# There shouldn't be any need to change anything from now on.
137
138HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
139ifeq ($(SYSTEM),)
140SYSTEM = $(HOST_SYSTEM)
141endif
142
143ifeq ($(wildcard .git),)
144IS_GIT_FOLDER = false
145else
146IS_GIT_FOLDER = true
147endif
148
149EVENT2_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/event2.c -levent $(LDFLAGS)
150OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/openssl-alpn.c -levent $(LDFLAGS) $(LDLIBS_SECURE)
151ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/event2.c -levent $(LDFLAGS)
152
153HAS_SYSTEM_EVENT2 = $(shell $(EVENT2_CHECK_CMD) >& /dev/null && echo true || echo false)
154HAS_SYSTEM_OPENSSL_ALPN = $(shell $(OPENSSL_ALPN_CHECK_CMD) >& /dev/null && echo true || echo false)
155HAS_SYSTEM_ZLIB = $(shell $(ZLIB_CHECK_CMD) >& /dev/null && echo true || echo false)
156
157ifeq ($(wildcard third_party/libevent/include/event2/event.h),)
158HAS_EMBEDDED_EVENT2 = false
159else
160HAS_EMBEDDED_EVENT2 = true
161endif
162
163ifeq ($(wildcard third_party/openssl/ssl/ssl.h),)
164HAS_EMBEDDED_OPENSSL_ALPN = false
165else
166HAS_EMBEDDED_OPENSSL_ALPN = true
167endif
168
169ifeq ($(wildcard third_party/zlib/zlib.h),)
170HAS_EMBEDDED_ZLIB = false
171else
172HAS_EMBEDDED_ZLIB = true
173endif
174
175ifneq ($(SYSTEM),MINGW32)
176ifeq ($(HAS_SYSTEM_EVENT2),false)
177DEP_MISSING += libevent
178endif
179endif
180
181ifeq ($(HAS_SYSTEM_ZLIB),false)
182ifeq ($(HAS_EMBEDDED_ZLIB),true)
183ZLIB_DEP = third_party/zlib/libz.a
184CPPFLAGS += -Ithird_party/zlib
185LDFLAGS += -Lthird_party/zlib
186else
187DEP_MISSING += zlib
188endif
189endif
190
191ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false)
192ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true)
193OPENSSL_DEP = third_party/openssl/libssl.a
194CPPFLAGS += -Ithird_party/openssl/include
195LDFLAGS += -Lthird_party/openssl
196else
197NO_SECURE = true
198endif
199endif
200
201ifneq ($(DEP_MISSING),)
202NO_DEPS = true
203endif
204
205ifneq ($(MAKECMDGOALS),clean)
206NO_DEPS = true
207endif
208
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800209.SECONDARY = %.pb.h %.pb.cc
210
nnoble69ac39f2014-12-12 15:43:38 -0800211ifeq ($(DEP_MISSING),)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800212all: static shared\
213% for tgt in targets:
214% if tgt.build == 'all':
215 bins/${tgt.name}\
216% endif
217% endfor
218
nnoble69ac39f2014-12-12 15:43:38 -0800219dep_error:
220 @echo "You shouldn't see this message - all of your dependencies are correct."
221else
222all: dep_error git_update stop
223
224dep_error:
225 @echo
226 @echo "DEPENDENCY ERROR"
227 @echo
228 @echo "You are missing system dependencies that are essential to build grpc,"
229 @echo "and the third_party directory doesn't have them:"
230 @echo
231 @echo " $(DEP_MISSING)"
232 @echo
233 @echo "Installing the development packages for your system will solve"
234 @echo "this issue. Please consult INSTALL to get more information."
235 @echo
236 @echo "If you need information about why these tests failed, run:"
237 @echo
238 @echo " make run_dep_checks"
239 @echo
240endif
241
242git_update:
243ifeq ($(IS_GIT_FOLDER),true)
244 @echo "Additionally, since you are in a git clone, you can download the"
245 @echo "missing dependencies in third_party by running the following command:"
246 @echo
ctiller64f29102014-12-15 10:40:59 -0800247 @echo " git submodule update --init"
nnoble69ac39f2014-12-12 15:43:38 -0800248 @echo
249endif
250
251openssl_dep_error: openssl_dep_message git_update stop
252
253openssl_dep_message:
254 @echo
255 @echo "DEPENDENCY ERROR"
256 @echo
257 @echo "The target you are trying to run requires OpenSSL with ALPN support."
258 @echo "Your system doesn't have it, and neither does the third_party directory."
259 @echo
260 @echo "Please consult INSTALL to get more information."
261 @echo
262 @echo "If you need information about why these tests failed, run:"
263 @echo
264 @echo " make run_dep_checks"
265 @echo
266
267stop:
268 @false
269
270run_dep_checks:
271 $(EVENT2_CHECK_CMD) || true
272 $(OPENSSL_ALPN_CHECK_CMD) || true
273 $(ZLIB_CHECK_CMD) || true
274
275third_party/zlib/libz.a:
276 (cd third_party/zlib ; CFLAGS="-fPIC -fvisibility=hidden" ./configure --static)
277 $(MAKE) -C third_party/zlib
278
279third_party/openssl/libssl.a:
280 (cd third_party/openssl ; CC="$(CC) -fPIC -fvisibility=hidden" ./config)
281 $(MAKE) -C third_party/openssl build_crypto build_ssl
282
nnoble29e1d292014-12-01 10:27:40 -0800283static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800284
nnoble85a49262014-12-08 18:14:03 -0800285static_c: dep_c\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800286% for lib in libs:
nnoble29e1d292014-12-01 10:27:40 -0800287% if lib.build == 'all' and not lib.get('c++', False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800288 libs/lib${lib.name}.a\
289% endif
290% endfor
291
292
nnoble85a49262014-12-08 18:14:03 -0800293static_cxx: dep_cxx\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800294% for lib in libs:
nnoble29e1d292014-12-01 10:27:40 -0800295% if lib.build == 'all' and lib.get('c++', False):
296 libs/lib${lib.name}.a\
297% endif
298% endfor
299
300
301shared: shared_c shared_cxx
302
nnoble85a49262014-12-08 18:14:03 -0800303shared_c: dep_c\
nnoble29e1d292014-12-01 10:27:40 -0800304% for lib in libs:
305% if lib.build == 'all' and not lib.get('c++', False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800306 libs/lib${lib.name}.so.$(VERSION)\
307% endif
308% endfor
309
310
nnoble85a49262014-12-08 18:14:03 -0800311shared_cxx: dep_cxx\
nnoble29e1d292014-12-01 10:27:40 -0800312% for lib in libs:
313% if lib.build == 'all' and lib.get('c++', False):
314 libs/lib${lib.name}.so.$(VERSION)\
315% endif
316% endfor
317
318
319privatelibs: privatelibs_c privatelibs_cxx
320
nnoble85a49262014-12-08 18:14:03 -0800321privatelibs_c: dep_c\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800322% for lib in libs:
323% if lib.build == 'private':
324 libs/lib${lib.name}.a\
325% endif
326% endfor
327
328
nnoble85a49262014-12-08 18:14:03 -0800329privatelibs_cxx: dep_cxx\
nnoble29e1d292014-12-01 10:27:40 -0800330% for lib in libs:
331% if lib.build == 'private':
332 libs/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800333% endif
334% endfor
335
336
nnoble29e1d292014-12-01 10:27:40 -0800337buildtests: buildtests_c buildtests_cxx
338
nnoble69ac39f2014-12-12 15:43:38 -0800339buildtests_c: bin_dep_c privatelibs_c\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800340% for tgt in targets:
341% if tgt.build == 'test' and not tgt.get('c++', False):
342 bins/${tgt.name}\
343% endif
344% endfor
345
346
nnoble69ac39f2014-12-12 15:43:38 -0800347buildtests_cxx: bin_dep_cxx privatelibs_cxx\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800348% for tgt in targets:
nnoble29e1d292014-12-01 10:27:40 -0800349% if tgt.build == 'test' and tgt.get('c++', False):
350 bins/${tgt.name}\
351% endif
352% endfor
353
354
nnoble85a49262014-12-08 18:14:03 -0800355test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -0800356
nnoble85a49262014-12-08 18:14:03 -0800357test_c: buildtests_c
nnoble29e1d292014-12-01 10:27:40 -0800358% for tgt in targets:
359% if tgt.build == 'test' and tgt.get('run', True) and not tgt.get('c++', False):
360 $(E) "[RUN] Testing ${tgt.name}"
361 $(Q) ./bins/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
362% endif
363% endfor
364
365
nnoble85a49262014-12-08 18:14:03 -0800366test_cxx: buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -0800367% for tgt in targets:
368% if tgt.build == 'test' and tgt.get('run', True) and tgt.get('c++', False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800369 $(E) "[RUN] Testing ${tgt.name}"
370 $(Q) ./bins/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
371% endif
372% endfor
373
374
375tools: privatelibs\
376% for tgt in targets:
377% if tgt.build == 'tool':
378 bins/${tgt.name}\
379% endif
380% endfor
381
382
nnobleebebb7e2014-12-10 16:31:01 -0800383protoc_plugins:\
384% for tgt in targets:
385% if tgt.build == 'protoc':
386 bins/${tgt.name}\
387% endif
388% endfor
389
390
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800391buildbenchmarks: privatelibs\
392% for tgt in targets:
393% if tgt.build == 'benchmark':
394 bins/${tgt.name}\
395% endif
396% endfor
397
398
399benchmarks: buildbenchmarks
400
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800401strip: strip-static strip-shared
402
nnoble85a49262014-12-08 18:14:03 -0800403strip-static_c: static_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800404% for lib in libs:
nnoble85a49262014-12-08 18:14:03 -0800405% if not lib.get("c++", False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800406% if lib.build == "all":
407 $(E) "[STRIP] Stripping lib${lib.name}.a"
408 $(Q) $(STRIP) libs/lib${lib.name}.a
409% endif
nnoble85a49262014-12-08 18:14:03 -0800410% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800411% endfor
412
nnoble85a49262014-12-08 18:14:03 -0800413strip-static_cxx: static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800414% for lib in libs:
nnoble85a49262014-12-08 18:14:03 -0800415% if lib.get("c++", False):
416% if lib.build == "all":
417 $(E) "[STRIP] Stripping lib${lib.name}.a"
418 $(Q) $(STRIP) libs/lib${lib.name}.a
419% endif
420% endif
421% endfor
422
423strip-shared_c: shared_c
424% for lib in libs:
425% if not lib.get("c++", False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800426% if lib.build == "all":
427 $(E) "[STRIP] Stripping lib${lib.name}.so"
428 $(Q) $(STRIP) libs/lib${lib.name}.so.$(VERSION)
429% endif
nnoble85a49262014-12-08 18:14:03 -0800430% endif
431% endfor
432
433strip-shared_cxx: shared_cxx
434% for lib in libs:
435% if lib.get("c++", False):
436% if lib.build == "all":
437 $(E) "[STRIP] Stripping lib${lib.name}.so"
438 $(Q) $(STRIP) libs/lib${lib.name}.so.$(VERSION)
439% endif
440% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800441% endfor
442
nnoble72309c62014-12-12 11:42:26 -0800443% for p in protos:
444deps/gens/${p}.pb.dep:
445 $(Q) mkdir -p `dirname $@`
446 $(Q) touch $@
447
448gens/${p}.pb.cc: ${p}.proto protoc_plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800449 $(E) "[PROTOC] Generating protobuf CC file from $<"
450 $(Q) mkdir -p `dirname $@`
nnoble72309c62014-12-12 11:42:26 -0800451 $(Q) $(PROTOC) --cpp_out=gens --grpc_out=gens --plugin=protoc-gen-grpc=bins/cpp_plugin $<
452
453% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800454
455deps/%.dep : %.c
456 $(E) "[DEP] Generating dependencies for $<"
457 $(Q) mkdir -p `dirname $@`
458 $(Q) $(CC) $(CFLAGS) $(CPPFLAGS_NO_ARCH) -MG -M $< > $@
459
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800460deps/%.dep : %.cc
461 $(E) "[DEP] Generating dependencies for $<"
462 $(Q) mkdir -p `dirname $@`
463 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS_NO_ARCH) -MG -M $< > $@
464
465objs/%.o : %.c
466 $(E) "[C] Compiling $<"
467 $(Q) mkdir -p `dirname $@`
468 $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
469
470objs/%.o : gens/%.pb.cc
471 $(E) "[CXX] Compiling $<"
472 $(Q) mkdir -p `dirname $@`
473 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
474
nnoble72309c62014-12-12 11:42:26 -0800475objs/src/compiler/%.o : src/compiler/%.cc
476 $(E) "[HOSTCXX] Compiling $<"
477 $(Q) mkdir -p `dirname $@`
478 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -c -o $@ $<
479
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800480objs/%.o : %.cc
481 $(E) "[CXX] Compiling $<"
482 $(Q) mkdir -p `dirname $@`
483 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
484
nnoble0c475f02014-12-05 15:37:39 -0800485dep: dep_c dep_cxx
486
487dep_c:\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800488% for lib in libs:
nnoble0c475f02014-12-05 15:37:39 -0800489% if not lib.get('c++', False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800490 deps_lib${lib.name}\
nnoble0c475f02014-12-05 15:37:39 -0800491% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800492% endfor
nnoble69ac39f2014-12-12 15:43:38 -0800493
494
495bins_dep_c:\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800496% for tgt in targets:
nnoble0c475f02014-12-05 15:37:39 -0800497% if not tgt.get('c++', False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800498 deps_${tgt.name}\
nnoble0c475f02014-12-05 15:37:39 -0800499% endif
500% endfor
501
502
503dep_cxx:\
504% for lib in libs:
505% if lib.get('c++', False):
506 deps_lib${lib.name}\
507% endif
508% endfor
nnoble69ac39f2014-12-12 15:43:38 -0800509
510
511bins_dep_cxx:\
nnoble0c475f02014-12-05 15:37:39 -0800512% for tgt in targets:
513% if tgt.get('c++', False):
514 deps_${tgt.name}\
515% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800516% endfor
517
518
nnoble85a49262014-12-08 18:14:03 -0800519install: install_c install_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800520
nnoble85a49262014-12-08 18:14:03 -0800521install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800522
nnoble85a49262014-12-08 18:14:03 -0800523install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
524
525install-headers: install-headers_c install-headers_cxx
526
527install-headers_c:
528 $(E) "[INSTALL] Installing public C headers"
529 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
530
531install-headers_cxx:
532 $(E) "[INSTALL] Installing public C++ headers"
533 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
534
535install-static: install-static_c install-static_cxx
536
537install-static_c: static_c strip-static_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800538% for lib in libs:
nnoble85a49262014-12-08 18:14:03 -0800539% if not lib.get("c++", False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800540% if lib.build == "all":
541 $(E) "[INSTALL] Installing lib${lib.name}.a"
542 $(Q) $(INSTALL) libs/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
543% endif
nnoble85a49262014-12-08 18:14:03 -0800544% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800545% endfor
546
nnoble85a49262014-12-08 18:14:03 -0800547install-static_cxx: static_cxx strip-static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800548% for lib in libs:
nnoble85a49262014-12-08 18:14:03 -0800549% if lib.get("c++", False):
550% if lib.build == "all":
551 $(E) "[INSTALL] Installing lib${lib.name}.a"
552 $(Q) $(INSTALL) libs/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
553% endif
554% endif
555% endfor
556
557install-shared_c: shared_c strip-shared_c
558% for lib in libs:
559% if not lib.get("c++", False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800560% if lib.build == "all":
561 $(E) "[INSTALL] Installing lib${lib.name}.so"
562 $(Q) $(INSTALL) libs/lib${lib.name}.so.$(VERSION) $(prefix)/lib/lib${lib.name}.so.$(VERSION)
563% endif
nnoble85a49262014-12-08 18:14:03 -0800564% endif
565% endfor
566
567install-shared_cxx: shared_cxx strip-shared_cxx
568% for lib in libs:
569% if lib.get("c++", False):
570% if lib.build == "all":
571 $(E) "[INSTALL] Installing lib${lib.name}.so"
572 $(Q) $(INSTALL) libs/lib${lib.name}.so.$(VERSION) $(prefix)/lib/lib${lib.name}.so.$(VERSION)
573% endif
574% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800575% endfor
576
577clean:\
578% for lib in libs:
579 clean_lib${lib.name}\
580% endfor
581% for tgt in targets:
582 clean_${tgt.name}\
583% endfor
584
585 $(Q) $(RM) -r deps objs libs bins gens
586
587
588# The various libraries
589
590% for lib in libs:
591${makelib(lib)}
592% endfor
593
594
nnoble69ac39f2014-12-12 15:43:38 -0800595# All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800596
597% for tgt in targets:
598${maketarget(tgt)}
599% endfor
600
601<%def name="makelib(lib)">
602LIB${lib.name.upper()}_SRC = \\
603
604% for src in lib.src:
nnoble72309c62014-12-12 11:42:26 -0800605 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800606
607% endfor
608
609% if "public_headers" in lib:
nnoble85a49262014-12-08 18:14:03 -0800610% if lib.get("c++", False):
611PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800612
nnoble85a49262014-12-08 18:14:03 -0800613% else:
614PUBLIC_HEADERS_C += \\
615
616% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800617% for hdr in lib.public_headers:
618 ${hdr} \\
619
620% endfor
621% endif
622
623LIB${lib.name.upper()}_OBJS = $(addprefix objs/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
624LIB${lib.name.upper()}_DEPS = $(addprefix deps/, $(addsuffix .dep, $(basename $(LIB${lib.name.upper()}_SRC))))
625
nnoble69ac39f2014-12-12 15:43:38 -0800626% if lib.get('secure', True):
627LIB${lib.name.upper()}_OBJS += $(OPENSSL_DEP)
628
629ifeq ($(NO_SECURE),true)
630
631libs/lib${lib.name}.a: openssl_dep_error
632
633else
634
635% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800636libs/lib${lib.name}.a: $(LIB${lib.name.upper()}_OBJS)
637 $(E) "[AR] Creating $@"
nnoble85a49262014-12-08 18:14:03 -0800638 $(Q) mkdir -p `dirname $@`
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800639 $(Q) $(AR) rcs libs/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
640
641% if lib.build == "all":
642libs/lib${lib.name}.so.$(VERSION): $(LIB${lib.name.upper()}_OBJS)
643 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -0800644 $(Q) mkdir -p `dirname $@`
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800645% if lib.get('c++', False):
646 $(Q) $(LDXX) $(LDFLAGS) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} \
647% else:
648 $(Q) $(LD) $(LDFLAGS) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} \
649% endif
650-o libs/lib${lib.name}.so.$(VERSION) $(LIB${lib.name.upper()}_OBJS) $(LDLIBS)\
nnoble69ac39f2014-12-12 15:43:38 -0800651% if lib.get('secure', True):
nnoblec78b3402014-12-11 16:06:57 -0800652 $(LDLIBS_SECURE)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800653% endif
654% endif
655
nnoble69ac39f2014-12-12 15:43:38 -0800656% if lib.get('secure', True):
657
658endif
659% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800660
661deps_lib${lib.name}: $(LIB${lib.name.upper()}_DEPS)
662
nnoble69ac39f2014-12-12 15:43:38 -0800663% if lib.get('secure', True):
664ifneq ($(NO_SECURE),true)
665% endif
666ifneq ($(NO_DEPS),true)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800667-include $(LIB${lib.name.upper()}_DEPS)
668endif
nnoble69ac39f2014-12-12 15:43:38 -0800669% if lib.get('secure', True):
670endif
671% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800672
673clean_lib${lib.name}:
674 $(E) "[CLEAN] Cleaning lib${lib.name} files"
675 $(Q) $(RM) $(LIB${lib.name.upper()}_OBJS)
676 $(Q) $(RM) $(LIB${lib.name.upper()}_DEPS)
677 $(Q) $(RM) libs/lib${lib.name}.a
678 $(Q) $(RM) libs/lib${lib.name}.so.$(VERSION)
679</%def>
680
681<%def name="maketarget(tgt)">
682${tgt.name.upper()}_SRC = \\
683
684% for src in tgt.src:
nnoble72309c62014-12-12 11:42:26 -0800685 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800686
687% endfor
688
689${tgt.name.upper()}_OBJS = $(addprefix objs/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
690${tgt.name.upper()}_DEPS = $(addprefix deps/, $(addsuffix .dep, $(basename $(${tgt.name.upper()}_SRC))))
691
nnoble69ac39f2014-12-12 15:43:38 -0800692% if tgt.get('secure', True):
693ifeq ($(NO_SECURE),true)
694
695bins/${tgt.name}: openssl_dep_error
696
697else
698
699% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800700bins/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
701% for dep in tgt.deps:
702 libs/lib${dep}.a\
703% endfor
704
nnoble72309c62014-12-12 11:42:26 -0800705% if tgt.get("c++", False):
706% if tgt.build == 'protoc':
707 $(E) "[HOSTLD] Linking $@"
708 $(Q) mkdir -p `dirname $@`
709 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(${tgt.name.upper()}_OBJS)\
710% else:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800711 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -0800712 $(Q) mkdir -p `dirname $@`
nnoblec78b3402014-12-11 16:06:57 -0800713 $(Q) $(LDXX) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
nnoble72309c62014-12-12 11:42:26 -0800714% endif
nnoblec78b3402014-12-11 16:06:57 -0800715% if tgt.build == 'test':
716 $(GTEST_LIB)\
717% endif
718 -Llibs\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800719% else:
nnoble72309c62014-12-12 11:42:26 -0800720 $(E) "[LD] Linking $@"
721 $(Q) mkdir -p `dirname $@`
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800722 $(Q) $(LD) $(LDFLAGS) $(${tgt.name.upper()}_OBJS) -Llibs\
723% endif
724% for dep in tgt.deps:
725 -l${dep}\
726% endfor
727% if tgt.get("c++", False):
nnoble72309c62014-12-12 11:42:26 -0800728% if tgt.build == 'protoc':
729 $(HOST_LDLIBSXX)\
730% else:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800731 $(LDLIBSXX)\
732% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800733% endif
nnoblec78b3402014-12-11 16:06:57 -0800734% if tgt.build == 'protoc':
nnoble72309c62014-12-12 11:42:26 -0800735 $(HOST_LDLIBS)\
736% else:
737 $(LDLIBS)\
738% endif
739% if tgt.build == 'protoc':
740 $(HOST_LDLIBS_PROTOC)\
741% elif tgt.get('secure', True):
742 $(LDLIBS_SECURE)\
nnoblec78b3402014-12-11 16:06:57 -0800743% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800744 -o bins/${tgt.name}
nnoble69ac39f2014-12-12 15:43:38 -0800745% if tgt.get('secure', True):
746
747endif
748% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800749
750deps_${tgt.name}: $(${tgt.name.upper()}_DEPS)
751
nnoble69ac39f2014-12-12 15:43:38 -0800752% if tgt.get('secure', True):
753ifneq ($(NO_SECURE),true)
754% endif
755ifneq ($(NO_DEPS),true)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800756-include $(${tgt.name.upper()}_DEPS)
757endif
nnoble69ac39f2014-12-12 15:43:38 -0800758% if tgt.get('secure', True):
759endif
760% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800761
762clean_${tgt.name}:
763 $(E) "[CLEAN] Cleaning ${tgt.name} files"
764 $(Q) $(RM) $(${tgt.name.upper()}_OBJS)
765 $(Q) $(RM) $(${tgt.name.upper()}_DEPS)
766 $(Q) $(RM) bins/${tgt.name}
767</%def>
768
nnoble85a49262014-12-08 18:14:03 -0800769.PHONY: all strip tools \
nnoble69ac39f2014-12-12 15:43:38 -0800770dep_error openssl_dep_error openssl_dep_message git_update stop \
nnoble85a49262014-12-08 18:14:03 -0800771buildtests buildtests_c buildtests_cxx \
772test test_c test_cxx \
773install install_c install_cxx \
774install-headers install-headers_c install-headers_cxx \
775install-shared install-shared_c install-shared_cxx \
776install-static install-static_c install-static_cxx \
777strip strip-shared strip-static \
778strip_c strip-shared_c strip-static_c \
779strip_cxx strip-shared_cxx strip-static_cxx \
780clean\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800781% for lib in libs:
782 deps_lib${lib.name} clean_lib${lib.name}\
783% endfor
784% for tgt in targets:
785 deps_${tgt.name} clean_${tgt.name}\
786% endfor
787