blob: 544e9cc3156178ae390c2775f94fc855a0696ed2 [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
nnoble60825402014-12-15 14:43:51 -0800153HAS_SYSTEM_EVENT2 = $(shell $(EVENT2_CHECK_CMD) 2> /dev/null && echo true || echo false)
154HAS_SYSTEM_OPENSSL_ALPN = $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
155HAS_SYSTEM_ZLIB = $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
nnoble69ac39f2014-12-12 15:43:38 -0800156
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
nnoble20e2e3f2014-12-16 15:37:57 -0800194OPENSSL_MERGE_LIBS += third_party/openssl/libssl.a third_party/openssl/libcrypto.a
nnoble69ac39f2014-12-12 15:43:38 -0800195CPPFLAGS += -Ithird_party/openssl/include
196LDFLAGS += -Lthird_party/openssl
197else
198NO_SECURE = true
199endif
200endif
201
202ifneq ($(DEP_MISSING),)
203NO_DEPS = true
204endif
205
206ifneq ($(MAKECMDGOALS),clean)
207NO_DEPS = true
208endif
209
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800210.SECONDARY = %.pb.h %.pb.cc
211
nnoble69ac39f2014-12-12 15:43:38 -0800212ifeq ($(DEP_MISSING),)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800213all: static shared\
214% for tgt in targets:
215% if tgt.build == 'all':
216 bins/${tgt.name}\
217% endif
218% endfor
219
nnoble69ac39f2014-12-12 15:43:38 -0800220dep_error:
221 @echo "You shouldn't see this message - all of your dependencies are correct."
222else
223all: dep_error git_update stop
224
225dep_error:
226 @echo
227 @echo "DEPENDENCY ERROR"
228 @echo
229 @echo "You are missing system dependencies that are essential to build grpc,"
230 @echo "and the third_party directory doesn't have them:"
231 @echo
232 @echo " $(DEP_MISSING)"
233 @echo
234 @echo "Installing the development packages for your system will solve"
235 @echo "this issue. Please consult INSTALL to get more information."
236 @echo
237 @echo "If you need information about why these tests failed, run:"
238 @echo
239 @echo " make run_dep_checks"
240 @echo
241endif
242
243git_update:
244ifeq ($(IS_GIT_FOLDER),true)
245 @echo "Additionally, since you are in a git clone, you can download the"
246 @echo "missing dependencies in third_party by running the following command:"
247 @echo
ctiller64f29102014-12-15 10:40:59 -0800248 @echo " git submodule update --init"
nnoble69ac39f2014-12-12 15:43:38 -0800249 @echo
250endif
251
252openssl_dep_error: openssl_dep_message git_update stop
253
254openssl_dep_message:
255 @echo
256 @echo "DEPENDENCY ERROR"
257 @echo
258 @echo "The target you are trying to run requires OpenSSL with ALPN support."
259 @echo "Your system doesn't have it, and neither does the third_party directory."
260 @echo
261 @echo "Please consult INSTALL to get more information."
262 @echo
263 @echo "If you need information about why these tests failed, run:"
264 @echo
265 @echo " make run_dep_checks"
266 @echo
267
268stop:
269 @false
270
271run_dep_checks:
272 $(EVENT2_CHECK_CMD) || true
273 $(OPENSSL_ALPN_CHECK_CMD) || true
274 $(ZLIB_CHECK_CMD) || true
275
276third_party/zlib/libz.a:
277 (cd third_party/zlib ; CFLAGS="-fPIC -fvisibility=hidden" ./configure --static)
278 $(MAKE) -C third_party/zlib
279
280third_party/openssl/libssl.a:
281 (cd third_party/openssl ; CC="$(CC) -fPIC -fvisibility=hidden" ./config)
282 $(MAKE) -C third_party/openssl build_crypto build_ssl
283
nnoble29e1d292014-12-01 10:27:40 -0800284static: static_c static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800285
nnoble85a49262014-12-08 18:14:03 -0800286static_c: dep_c\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800287% for lib in libs:
nnoble29e1d292014-12-01 10:27:40 -0800288% if lib.build == 'all' and not lib.get('c++', False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800289 libs/lib${lib.name}.a\
290% endif
291% endfor
292
293
nnoble85a49262014-12-08 18:14:03 -0800294static_cxx: dep_cxx\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800295% for lib in libs:
nnoble29e1d292014-12-01 10:27:40 -0800296% if lib.build == 'all' and lib.get('c++', False):
297 libs/lib${lib.name}.a\
298% endif
299% endfor
300
301
302shared: shared_c shared_cxx
303
nnoble85a49262014-12-08 18:14:03 -0800304shared_c: dep_c\
nnoble29e1d292014-12-01 10:27:40 -0800305% for lib in libs:
306% if lib.build == 'all' and not lib.get('c++', False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800307 libs/lib${lib.name}.so.$(VERSION)\
308% endif
309% endfor
310
311
nnoble85a49262014-12-08 18:14:03 -0800312shared_cxx: dep_cxx\
nnoble29e1d292014-12-01 10:27:40 -0800313% for lib in libs:
314% if lib.build == 'all' and lib.get('c++', False):
315 libs/lib${lib.name}.so.$(VERSION)\
316% endif
317% endfor
318
319
320privatelibs: privatelibs_c privatelibs_cxx
321
nnoble85a49262014-12-08 18:14:03 -0800322privatelibs_c: dep_c\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800323% for lib in libs:
324% if lib.build == 'private':
325 libs/lib${lib.name}.a\
326% endif
327% endfor
328
329
nnoble85a49262014-12-08 18:14:03 -0800330privatelibs_cxx: dep_cxx\
nnoble29e1d292014-12-01 10:27:40 -0800331% for lib in libs:
332% if lib.build == 'private':
333 libs/lib${lib.name}.a\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800334% endif
335% endfor
336
337
nnoble29e1d292014-12-01 10:27:40 -0800338buildtests: buildtests_c buildtests_cxx
339
nnoblebba76922014-12-15 13:27:38 -0800340buildtests_c: bins_dep_c privatelibs_c\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800341% for tgt in targets:
342% if tgt.build == 'test' and not tgt.get('c++', False):
343 bins/${tgt.name}\
344% endif
345% endfor
346
347
nnoblebba76922014-12-15 13:27:38 -0800348buildtests_cxx: bins_dep_cxx privatelibs_cxx\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800349% for tgt in targets:
nnoble29e1d292014-12-01 10:27:40 -0800350% if tgt.build == 'test' and tgt.get('c++', False):
351 bins/${tgt.name}\
352% endif
353% endfor
354
355
nnoble85a49262014-12-08 18:14:03 -0800356test: test_c test_cxx
nnoble29e1d292014-12-01 10:27:40 -0800357
nnoble85a49262014-12-08 18:14:03 -0800358test_c: buildtests_c
nnoble29e1d292014-12-01 10:27:40 -0800359% for tgt in targets:
360% if tgt.build == 'test' and tgt.get('run', True) and not tgt.get('c++', False):
361 $(E) "[RUN] Testing ${tgt.name}"
362 $(Q) ./bins/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
363% endif
364% endfor
365
366
nnoble85a49262014-12-08 18:14:03 -0800367test_cxx: buildtests_cxx
nnoble29e1d292014-12-01 10:27:40 -0800368% for tgt in targets:
369% if tgt.build == 'test' and tgt.get('run', True) and tgt.get('c++', False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800370 $(E) "[RUN] Testing ${tgt.name}"
371 $(Q) ./bins/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
372% endif
373% endfor
374
375
376tools: privatelibs\
377% for tgt in targets:
378% if tgt.build == 'tool':
379 bins/${tgt.name}\
380% endif
381% endfor
382
383
nnobleebebb7e2014-12-10 16:31:01 -0800384protoc_plugins:\
385% for tgt in targets:
386% if tgt.build == 'protoc':
387 bins/${tgt.name}\
388% endif
389% endfor
390
391
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800392buildbenchmarks: privatelibs\
393% for tgt in targets:
394% if tgt.build == 'benchmark':
395 bins/${tgt.name}\
396% endif
397% endfor
398
399
400benchmarks: buildbenchmarks
401
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800402strip: strip-static strip-shared
403
nnoble20e2e3f2014-12-16 15:37:57 -0800404strip-static: strip-static_c strip-static_cxx
405
406strip-shared: strip-shared_c strip-shared_cxx
407
nnoble85a49262014-12-08 18:14:03 -0800408strip-static_c: static_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800409% for lib in libs:
nnoble85a49262014-12-08 18:14:03 -0800410% if not lib.get("c++", False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800411% if lib.build == "all":
412 $(E) "[STRIP] Stripping lib${lib.name}.a"
413 $(Q) $(STRIP) libs/lib${lib.name}.a
414% endif
nnoble85a49262014-12-08 18:14:03 -0800415% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800416% endfor
417
nnoble85a49262014-12-08 18:14:03 -0800418strip-static_cxx: static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800419% for lib in libs:
nnoble85a49262014-12-08 18:14:03 -0800420% if lib.get("c++", False):
421% if lib.build == "all":
422 $(E) "[STRIP] Stripping lib${lib.name}.a"
423 $(Q) $(STRIP) libs/lib${lib.name}.a
424% endif
425% endif
426% endfor
427
428strip-shared_c: shared_c
429% for lib in libs:
430% if not lib.get("c++", False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800431% if lib.build == "all":
432 $(E) "[STRIP] Stripping lib${lib.name}.so"
433 $(Q) $(STRIP) libs/lib${lib.name}.so.$(VERSION)
434% endif
nnoble85a49262014-12-08 18:14:03 -0800435% endif
436% endfor
437
438strip-shared_cxx: shared_cxx
439% for lib in libs:
440% if lib.get("c++", False):
441% if lib.build == "all":
442 $(E) "[STRIP] Stripping lib${lib.name}.so"
443 $(Q) $(STRIP) libs/lib${lib.name}.so.$(VERSION)
444% endif
445% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800446% endfor
447
nnoble72309c62014-12-12 11:42:26 -0800448% for p in protos:
449deps/gens/${p}.pb.dep:
450 $(Q) mkdir -p `dirname $@`
451 $(Q) touch $@
452
453gens/${p}.pb.cc: ${p}.proto protoc_plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800454 $(E) "[PROTOC] Generating protobuf CC file from $<"
455 $(Q) mkdir -p `dirname $@`
nnoble72309c62014-12-12 11:42:26 -0800456 $(Q) $(PROTOC) --cpp_out=gens --grpc_out=gens --plugin=protoc-gen-grpc=bins/cpp_plugin $<
457
458% endfor
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800459
460deps/%.dep : %.c
461 $(E) "[DEP] Generating dependencies for $<"
462 $(Q) mkdir -p `dirname $@`
463 $(Q) $(CC) $(CFLAGS) $(CPPFLAGS_NO_ARCH) -MG -M $< > $@
464
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800465deps/%.dep : %.cc
466 $(E) "[DEP] Generating dependencies for $<"
467 $(Q) mkdir -p `dirname $@`
468 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS_NO_ARCH) -MG -M $< > $@
469
470objs/%.o : %.c
471 $(E) "[C] Compiling $<"
472 $(Q) mkdir -p `dirname $@`
473 $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
474
475objs/%.o : gens/%.pb.cc
476 $(E) "[CXX] Compiling $<"
477 $(Q) mkdir -p `dirname $@`
478 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
479
nnoble72309c62014-12-12 11:42:26 -0800480objs/src/compiler/%.o : src/compiler/%.cc
481 $(E) "[HOSTCXX] Compiling $<"
482 $(Q) mkdir -p `dirname $@`
483 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -c -o $@ $<
484
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800485objs/%.o : %.cc
486 $(E) "[CXX] Compiling $<"
487 $(Q) mkdir -p `dirname $@`
488 $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
489
nnoble0c475f02014-12-05 15:37:39 -0800490dep: dep_c dep_cxx
491
492dep_c:\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800493% for lib in libs:
nnoble0c475f02014-12-05 15:37:39 -0800494% if not lib.get('c++', False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800495 deps_lib${lib.name}\
nnoble0c475f02014-12-05 15:37:39 -0800496% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800497% endfor
nnoble69ac39f2014-12-12 15:43:38 -0800498
499
500bins_dep_c:\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800501% for tgt in targets:
nnoble0c475f02014-12-05 15:37:39 -0800502% if not tgt.get('c++', False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800503 deps_${tgt.name}\
nnoble0c475f02014-12-05 15:37:39 -0800504% endif
505% endfor
506
507
508dep_cxx:\
509% for lib in libs:
510% if lib.get('c++', False):
511 deps_lib${lib.name}\
512% endif
513% endfor
nnoble69ac39f2014-12-12 15:43:38 -0800514
515
516bins_dep_cxx:\
nnoble0c475f02014-12-05 15:37:39 -0800517% for tgt in targets:
518% if tgt.get('c++', False):
519 deps_${tgt.name}\
520% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800521% endfor
522
523
nnoble85a49262014-12-08 18:14:03 -0800524install: install_c install_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800525
nnoble85a49262014-12-08 18:14:03 -0800526install_c: install-headers_c install-static_c install-shared_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800527
nnoble85a49262014-12-08 18:14:03 -0800528install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
529
530install-headers: install-headers_c install-headers_cxx
531
532install-headers_c:
533 $(E) "[INSTALL] Installing public C headers"
534 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
535
536install-headers_cxx:
537 $(E) "[INSTALL] Installing public C++ headers"
538 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
539
540install-static: install-static_c install-static_cxx
541
542install-static_c: static_c strip-static_c
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800543% for lib in libs:
nnoble85a49262014-12-08 18:14:03 -0800544% if not lib.get("c++", False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800545% if lib.build == "all":
546 $(E) "[INSTALL] Installing lib${lib.name}.a"
547 $(Q) $(INSTALL) libs/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
548% endif
nnoble85a49262014-12-08 18:14:03 -0800549% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800550% endfor
551
nnoble85a49262014-12-08 18:14:03 -0800552install-static_cxx: static_cxx strip-static_cxx
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800553% for lib in libs:
nnoble85a49262014-12-08 18:14:03 -0800554% if lib.get("c++", False):
555% if lib.build == "all":
556 $(E) "[INSTALL] Installing lib${lib.name}.a"
557 $(Q) $(INSTALL) libs/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
558% endif
559% endif
560% endfor
561
562install-shared_c: shared_c strip-shared_c
563% for lib in libs:
564% if not lib.get("c++", False):
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800565% if lib.build == "all":
566 $(E) "[INSTALL] Installing lib${lib.name}.so"
567 $(Q) $(INSTALL) libs/lib${lib.name}.so.$(VERSION) $(prefix)/lib/lib${lib.name}.so.$(VERSION)
568% endif
nnoble85a49262014-12-08 18:14:03 -0800569% endif
570% endfor
571
572install-shared_cxx: shared_cxx strip-shared_cxx
573% for lib in libs:
574% if lib.get("c++", False):
575% if lib.build == "all":
576 $(E) "[INSTALL] Installing lib${lib.name}.so"
577 $(Q) $(INSTALL) libs/lib${lib.name}.so.$(VERSION) $(prefix)/lib/lib${lib.name}.so.$(VERSION)
578% endif
579% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800580% endfor
581
582clean:\
583% for lib in libs:
584 clean_lib${lib.name}\
585% endfor
586% for tgt in targets:
587 clean_${tgt.name}\
588% endfor
589
590 $(Q) $(RM) -r deps objs libs bins gens
591
592
593# The various libraries
594
595% for lib in libs:
596${makelib(lib)}
597% endfor
598
599
nnoble69ac39f2014-12-12 15:43:38 -0800600# All of the test targets, and protoc plugins
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800601
602% for tgt in targets:
603${maketarget(tgt)}
604% endfor
605
606<%def name="makelib(lib)">
607LIB${lib.name.upper()}_SRC = \\
608
609% for src in lib.src:
nnoble72309c62014-12-12 11:42:26 -0800610 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800611
612% endfor
613
614% if "public_headers" in lib:
nnoble85a49262014-12-08 18:14:03 -0800615% if lib.get("c++", False):
616PUBLIC_HEADERS_CXX += \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800617
nnoble85a49262014-12-08 18:14:03 -0800618% else:
619PUBLIC_HEADERS_C += \\
620
621% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800622% for hdr in lib.public_headers:
623 ${hdr} \\
624
625% endfor
626% endif
627
628LIB${lib.name.upper()}_OBJS = $(addprefix objs/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
629LIB${lib.name.upper()}_DEPS = $(addprefix deps/, $(addsuffix .dep, $(basename $(LIB${lib.name.upper()}_SRC))))
630
nnoble69ac39f2014-12-12 15:43:38 -0800631% if lib.get('secure', True):
nnoble69ac39f2014-12-12 15:43:38 -0800632ifeq ($(NO_SECURE),true)
633
634libs/lib${lib.name}.a: openssl_dep_error
635
636else
637
nnoble20e2e3f2014-12-16 15:37:57 -0800638libs/lib${lib.name}.a: $(LIB${lib.name.upper()}_OBJS) $(OPENSSL_DEP)
639% else:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800640libs/lib${lib.name}.a: $(LIB${lib.name.upper()}_OBJS)
nnoble20e2e3f2014-12-16 15:37:57 -0800641% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800642 $(E) "[AR] Creating $@"
nnoble85a49262014-12-08 18:14:03 -0800643 $(Q) mkdir -p `dirname $@`
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800644 $(Q) $(AR) rcs libs/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
nnoble20e2e3f2014-12-16 15:37:57 -0800645% if lib.get('baselib', False):
646% if lib.get('secure', True):
647 $(Q) mkdir tmp-merge
648 $(Q) ( cd tmp-merge ; $(AR) x ../libs/lib${lib.name}.a )
649 $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge ; <%text>ar x ../$${l}</%text> ) ; done
650 $(Q) rm -f libs/lib${lib.name}.a tmp-merge/__.SYMDEF*
651 $(Q) ar rcs libs/lib${lib.name}.a tmp-merge/*
652 $(Q) rm -rf tmp-merge
653% endif
654% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800655
656% if lib.build == "all":
657libs/lib${lib.name}.so.$(VERSION): $(LIB${lib.name.upper()}_OBJS)
658 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -0800659 $(Q) mkdir -p `dirname $@`
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800660% if lib.get('c++', False):
661 $(Q) $(LDXX) $(LDFLAGS) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} \
662% else:
663 $(Q) $(LD) $(LDFLAGS) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} \
664% endif
665-o libs/lib${lib.name}.so.$(VERSION) $(LIB${lib.name.upper()}_OBJS) $(LDLIBS)\
nnoble69ac39f2014-12-12 15:43:38 -0800666% if lib.get('secure', True):
nnoblec78b3402014-12-11 16:06:57 -0800667 $(LDLIBS_SECURE)\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800668% endif
669% endif
670
nnoble69ac39f2014-12-12 15:43:38 -0800671% if lib.get('secure', True):
672
673endif
674% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800675
676deps_lib${lib.name}: $(LIB${lib.name.upper()}_DEPS)
677
nnoble69ac39f2014-12-12 15:43:38 -0800678% if lib.get('secure', True):
679ifneq ($(NO_SECURE),true)
680% endif
681ifneq ($(NO_DEPS),true)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800682-include $(LIB${lib.name.upper()}_DEPS)
683endif
nnoble69ac39f2014-12-12 15:43:38 -0800684% if lib.get('secure', True):
685endif
686% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800687
688clean_lib${lib.name}:
689 $(E) "[CLEAN] Cleaning lib${lib.name} files"
690 $(Q) $(RM) $(LIB${lib.name.upper()}_OBJS)
691 $(Q) $(RM) $(LIB${lib.name.upper()}_DEPS)
692 $(Q) $(RM) libs/lib${lib.name}.a
693 $(Q) $(RM) libs/lib${lib.name}.so.$(VERSION)
694</%def>
695
696<%def name="maketarget(tgt)">
697${tgt.name.upper()}_SRC = \\
698
699% for src in tgt.src:
nnoble72309c62014-12-12 11:42:26 -0800700 ${proto_to_cc(src)} \\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800701
702% endfor
703
704${tgt.name.upper()}_OBJS = $(addprefix objs/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
705${tgt.name.upper()}_DEPS = $(addprefix deps/, $(addsuffix .dep, $(basename $(${tgt.name.upper()}_SRC))))
706
nnoble69ac39f2014-12-12 15:43:38 -0800707% if tgt.get('secure', True):
708ifeq ($(NO_SECURE),true)
709
710bins/${tgt.name}: openssl_dep_error
711
712else
713
714% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800715bins/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
716% for dep in tgt.deps:
717 libs/lib${dep}.a\
718% endfor
719
nnoble72309c62014-12-12 11:42:26 -0800720% if tgt.get("c++", False):
721% if tgt.build == 'protoc':
722 $(E) "[HOSTLD] Linking $@"
723 $(Q) mkdir -p `dirname $@`
724 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(${tgt.name.upper()}_OBJS)\
725% else:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800726 $(E) "[LD] Linking $@"
nnoble85a49262014-12-08 18:14:03 -0800727 $(Q) mkdir -p `dirname $@`
nnoblec78b3402014-12-11 16:06:57 -0800728 $(Q) $(LDXX) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
nnoble72309c62014-12-12 11:42:26 -0800729% endif
nnoblec78b3402014-12-11 16:06:57 -0800730% if tgt.build == 'test':
731 $(GTEST_LIB)\
732% endif
733 -Llibs\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800734% else:
nnoble72309c62014-12-12 11:42:26 -0800735 $(E) "[LD] Linking $@"
736 $(Q) mkdir -p `dirname $@`
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800737 $(Q) $(LD) $(LDFLAGS) $(${tgt.name.upper()}_OBJS) -Llibs\
738% endif
739% for dep in tgt.deps:
740 -l${dep}\
741% endfor
742% if tgt.get("c++", False):
nnoble72309c62014-12-12 11:42:26 -0800743% if tgt.build == 'protoc':
744 $(HOST_LDLIBSXX)\
745% else:
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800746 $(LDLIBSXX)\
747% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800748% endif
nnoblec78b3402014-12-11 16:06:57 -0800749% if tgt.build == 'protoc':
nnoble72309c62014-12-12 11:42:26 -0800750 $(HOST_LDLIBS)\
751% else:
752 $(LDLIBS)\
753% endif
754% if tgt.build == 'protoc':
755 $(HOST_LDLIBS_PROTOC)\
756% elif tgt.get('secure', True):
757 $(LDLIBS_SECURE)\
nnoblec78b3402014-12-11 16:06:57 -0800758% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800759 -o bins/${tgt.name}
nnoble69ac39f2014-12-12 15:43:38 -0800760% if tgt.get('secure', True):
761
762endif
763% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800764
765deps_${tgt.name}: $(${tgt.name.upper()}_DEPS)
766
nnoble69ac39f2014-12-12 15:43:38 -0800767% if tgt.get('secure', True):
768ifneq ($(NO_SECURE),true)
769% endif
770ifneq ($(NO_DEPS),true)
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800771-include $(${tgt.name.upper()}_DEPS)
772endif
nnoble69ac39f2014-12-12 15:43:38 -0800773% if tgt.get('secure', True):
774endif
775% endif
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800776
777clean_${tgt.name}:
778 $(E) "[CLEAN] Cleaning ${tgt.name} files"
779 $(Q) $(RM) $(${tgt.name.upper()}_OBJS)
780 $(Q) $(RM) $(${tgt.name.upper()}_DEPS)
781 $(Q) $(RM) bins/${tgt.name}
782</%def>
783
nnoble85a49262014-12-08 18:14:03 -0800784.PHONY: all strip tools \
nnoble69ac39f2014-12-12 15:43:38 -0800785dep_error openssl_dep_error openssl_dep_message git_update stop \
nnoble85a49262014-12-08 18:14:03 -0800786buildtests buildtests_c buildtests_cxx \
787test test_c test_cxx \
788install install_c install_cxx \
789install-headers install-headers_c install-headers_cxx \
790install-shared install-shared_c install-shared_cxx \
791install-static install-static_c install-static_cxx \
792strip strip-shared strip-static \
793strip_c strip-shared_c strip-static_c \
794strip_cxx strip-shared_cxx strip-static_cxx \
nnoblebba76922014-12-15 13:27:38 -0800795clean \
796dep_c dep_cxx bins_dep_c bins_dep_cxx\
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800797% for lib in libs:
798 deps_lib${lib.name} clean_lib${lib.name}\
799% endfor
800% for tgt in targets:
801 deps_${tgt.name} clean_${tgt.name}\
802% endfor
803