Makefile.template 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. # GRPC global makefile
  2. # This currently builds C and C++ code.
  3. <%!
  4. import re
  5. import os
  6. proto_re = re.compile('(.*)\\.proto')
  7. def excluded(filename, exclude_res):
  8. for r in exclude_res:
  9. if r.match(filename):
  10. return True
  11. return False
  12. def proto_to_cc(filename):
  13. m = proto_re.match(filename)
  14. if not m:
  15. return filename
  16. return 'gens/' + m.group(1) + '.pb.cc'
  17. %>
  18. # Configurations
  19. VALID_CONFIG_opt = 1
  20. CC_opt = gcc
  21. CXX_opt = g++
  22. LD_opt = gcc
  23. LDXX_opt = g++
  24. CPPFLAGS_opt = -O2
  25. LDFLAGS_opt =
  26. DEFINES_opt = NDEBUG
  27. VALID_CONFIG_dbg = 1
  28. CC_dbg = gcc
  29. CXX_dbg = g++
  30. LD_dbg = gcc
  31. LDXX_dbg = g++
  32. CPPFLAGS_dbg = -O0
  33. LDFLAGS_dbg =
  34. DEFINES_dbg = _DEBUG DEBUG
  35. VALID_CONFIG_tsan = 1
  36. CC_tsan = clang
  37. CXX_tsan = clang++
  38. LD_tsan = clang
  39. LDXX_tsan = clang++
  40. CPPFLAGS_tsan = -O1 -fsanitize=thread -fno-omit-frame-pointer
  41. LDFLAGS_tsan = -fsanitize=thread
  42. DEFINES_tsan = NDEBUG
  43. VALID_CONFIG_asan = 1
  44. CC_asan = clang
  45. CXX_asan = clang++
  46. LD_asan = clang
  47. LDXX_asan = clang++
  48. CPPFLAGS_asan = -O1 -fsanitize=address -fno-omit-frame-pointer
  49. LDFLAGS_asan = -fsanitize=address
  50. DEFINES_asan = NDEBUG
  51. VALID_CONFIG_msan = 1
  52. CC_msan = clang
  53. CXX_msan = clang++
  54. LD_msan = clang
  55. LDXX_msan = clang++
  56. CPPFLAGS_msan = -O1 -fsanitize=memory -fno-omit-frame-pointer
  57. LDFLAGS_msan = -fsanitize=memory
  58. DEFINES_msan = NDEBUG
  59. VALID_CONFIG_gcov = 1
  60. CC_gcov = gcc
  61. CXX_gcov = g++
  62. LD_gcov = gcc
  63. LDXX_gcov = g++
  64. CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage
  65. LDFLAGS_gcov = -fprofile-arcs -ftest-coverage
  66. DEFINES_gcov = NDEBUG
  67. # General settings.
  68. # You may want to change these depending on your system.
  69. prefix ?= /usr/local
  70. PROTOC = protoc
  71. CONFIG ?= opt
  72. CC = $(CC_$(CONFIG))
  73. CXX = $(CXX_$(CONFIG))
  74. LD = $(LD_$(CONFIG))
  75. LDXX = $(LDXX_$(CONFIG))
  76. AR = ar
  77. STRIP = strip --strip-unneeded
  78. INSTALL = install -D
  79. RM = rm -f
  80. ifndef VALID_CONFIG_$(CONFIG)
  81. $(error Invalid CONFIG value '$(CONFIG)')
  82. endif
  83. HOST_CC = $(CC)
  84. HOST_CXX = $(CXX)
  85. HOST_LD = $(LD)
  86. HOST_LDXX = $(LDXX)
  87. CPPFLAGS += $(CPPFLAGS_$(CONFIG))
  88. DEFINES += $(DEFINES_$(CONFIG))
  89. LDFLAGS += $(LDFLAGS_$(CONFIG))
  90. CFLAGS += -std=c89 -pedantic
  91. CXXFLAGS += -std=c++11
  92. CPPFLAGS += -g -fPIC -Wall -Werror -Wno-long-long
  93. LDFLAGS += -g -pthread -fPIC
  94. INCLUDES = . include gens
  95. LIBS = rt m z pthread
  96. LIBSXX = protobuf
  97. LIBS_PROTOC = protoc protobuf
  98. ifneq ($(wildcard /usr/src/gtest/src/gtest-all.cc),)
  99. GTEST_LIB = /usr/src/gtest/src/gtest-all.cc -I/usr/src/gtest
  100. else
  101. GTEST_LIB = -lgtest
  102. endif
  103. GTEST_LIB += -lgflags
  104. ifeq ($(V),1)
  105. E = @:
  106. Q =
  107. else
  108. E = @echo
  109. Q = @
  110. endif
  111. VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build}
  112. CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
  113. CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
  114. LDFLAGS += $(ARCH_FLAGS)
  115. LDLIBS += $(addprefix -l, $(LIBS))
  116. LDLIBSXX += $(addprefix -l, $(LIBSXX))
  117. HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
  118. HOST_CPPFLAGS = $(CPPFLAGS)
  119. HOST_CFLAGS = $(CFLAGS)
  120. HOST_CXXFLAGS = $(CXXFLAGS)
  121. HOST_LDFLAGS = $(LDFLAGS)
  122. HOST_LDLIBS = $(LDLIBS)
  123. # These are automatically computed variables.
  124. # There shouldn't be any need to change anything from now on.
  125. HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
  126. ifeq ($(SYSTEM),)
  127. SYSTEM = $(HOST_SYSTEM)
  128. endif
  129. ifeq ($(SYSTEM),MINGW32)
  130. SHARED_EXT = dll
  131. endif
  132. ifeq ($(SYSTEM),Darwin)
  133. SHARED_EXT = dylib
  134. endif
  135. ifeq ($(SHARED_EXT),)
  136. SHARED_EXT = so.$(VERSION)
  137. endif
  138. ifeq ($(wildcard .git),)
  139. IS_GIT_FOLDER = false
  140. else
  141. IS_GIT_FOLDER = true
  142. endif
  143. OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/openssl-alpn.c -lssl -lcrypto -ldl $(LDFLAGS)
  144. ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/zlib.c -lz $(LDFLAGS)
  145. HAS_SYSTEM_OPENSSL_ALPN = $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
  146. HAS_SYSTEM_ZLIB = $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
  147. ifeq ($(wildcard third_party/openssl/ssl/ssl.h),)
  148. HAS_EMBEDDED_OPENSSL_ALPN = false
  149. else
  150. HAS_EMBEDDED_OPENSSL_ALPN = true
  151. endif
  152. ifeq ($(wildcard third_party/zlib/zlib.h),)
  153. HAS_EMBEDDED_ZLIB = false
  154. else
  155. HAS_EMBEDDED_ZLIB = true
  156. endif
  157. ifeq ($(HAS_SYSTEM_ZLIB),false)
  158. ifeq ($(HAS_EMBEDDED_ZLIB),true)
  159. ZLIB_DEP = third_party/zlib/libz.a
  160. CPPFLAGS += -Ithird_party/zlib
  161. LDFLAGS += -Lthird_party/zlib
  162. else
  163. DEP_MISSING += zlib
  164. endif
  165. endif
  166. ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false)
  167. ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true)
  168. OPENSSL_DEP = third_party/openssl/libssl.a
  169. OPENSSL_MERGE_LIBS += third_party/openssl/libssl.a third_party/openssl/libcrypto.a
  170. CPPFLAGS += -Ithird_party/openssl/include
  171. LDFLAGS += -Lthird_party/openssl
  172. LIBS_SECURE = dl
  173. else
  174. NO_SECURE = true
  175. endif
  176. else
  177. LIBS_SECURE = ssl crypto dl
  178. endif
  179. LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
  180. ifneq ($(DEP_MISSING),)
  181. NO_DEPS = true
  182. endif
  183. ifneq ($(MAKECMDGOALS),clean)
  184. NO_DEPS = true
  185. endif
  186. .SECONDARY = %.pb.h %.pb.cc
  187. ifeq ($(DEP_MISSING),)
  188. all: static shared\
  189. % for tgt in targets:
  190. % if tgt.build == 'all':
  191. bins/$(CONFIG)/${tgt.name}\
  192. % endif
  193. % endfor
  194. dep_error:
  195. @echo "You shouldn't see this message - all of your dependencies are correct."
  196. else
  197. all: dep_error git_update stop
  198. dep_error:
  199. @echo
  200. @echo "DEPENDENCY ERROR"
  201. @echo
  202. @echo "You are missing system dependencies that are essential to build grpc,"
  203. @echo "and the third_party directory doesn't have them:"
  204. @echo
  205. @echo " $(DEP_MISSING)"
  206. @echo
  207. @echo "Installing the development packages for your system will solve"
  208. @echo "this issue. Please consult INSTALL to get more information."
  209. @echo
  210. @echo "If you need information about why these tests failed, run:"
  211. @echo
  212. @echo " make run_dep_checks"
  213. @echo
  214. endif
  215. git_update:
  216. ifeq ($(IS_GIT_FOLDER),true)
  217. @echo "Additionally, since you are in a git clone, you can download the"
  218. @echo "missing dependencies in third_party by running the following command:"
  219. @echo
  220. @echo " git submodule update --init"
  221. @echo
  222. endif
  223. openssl_dep_error: openssl_dep_message git_update stop
  224. openssl_dep_message:
  225. @echo
  226. @echo "DEPENDENCY ERROR"
  227. @echo
  228. @echo "The target you are trying to run requires OpenSSL with ALPN support."
  229. @echo "Your system doesn't have it, and neither does the third_party directory."
  230. @echo
  231. @echo "Please consult INSTALL to get more information."
  232. @echo
  233. @echo "If you need information about why these tests failed, run:"
  234. @echo
  235. @echo " make run_dep_checks"
  236. @echo
  237. stop:
  238. @false
  239. % for tgt in targets:
  240. ${tgt.name}: bins/$(CONFIG)/${tgt.name}
  241. % endfor
  242. run_dep_checks:
  243. $(OPENSSL_ALPN_CHECK_CMD) || true
  244. $(ZLIB_CHECK_CMD) || true
  245. third_party/zlib/libz.a:
  246. (cd third_party/zlib ; CFLAGS="-fPIC -fvisibility=hidden" ./configure --static)
  247. $(MAKE) -C third_party/zlib
  248. third_party/openssl/libssl.a:
  249. (cd third_party/openssl ; CC="$(CC) -fPIC -fvisibility=hidden" ./config)
  250. $(MAKE) -C third_party/openssl build_crypto build_ssl
  251. static: static_c static_cxx
  252. static_c: dep_c\
  253. % for lib in libs:
  254. % if lib.build == 'all' and not lib.get('c++', False):
  255. libs/$(CONFIG)/lib${lib.name}.a\
  256. % endif
  257. % endfor
  258. static_cxx: dep_cxx\
  259. % for lib in libs:
  260. % if lib.build == 'all' and lib.get('c++', False):
  261. libs/$(CONFIG)/lib${lib.name}.a\
  262. % endif
  263. % endfor
  264. shared: shared_c shared_cxx
  265. shared_c: dep_c\
  266. % for lib in libs:
  267. % if lib.build == 'all' and not lib.get('c++', False):
  268. libs/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
  269. % endif
  270. % endfor
  271. shared_cxx: dep_cxx\
  272. % for lib in libs:
  273. % if lib.build == 'all' and lib.get('c++', False):
  274. libs/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
  275. % endif
  276. % endfor
  277. privatelibs: privatelibs_c privatelibs_cxx
  278. privatelibs_c: dep_c\
  279. % for lib in libs:
  280. % if lib.build == 'private' and not lib.get('c++', False):
  281. libs/$(CONFIG)/lib${lib.name}.a\
  282. % endif
  283. % endfor
  284. privatelibs_cxx: dep_cxx\
  285. % for lib in libs:
  286. % if lib.build == 'private' and lib.get('c++', False):
  287. libs/$(CONFIG)/lib${lib.name}.a\
  288. % endif
  289. % endfor
  290. buildtests: buildtests_c buildtests_cxx
  291. buildtests_c: bins_dep_c privatelibs_c\
  292. % for tgt in targets:
  293. % if tgt.build == 'test' and not tgt.get('c++', False):
  294. bins/$(CONFIG)/${tgt.name}\
  295. % endif
  296. % endfor
  297. buildtests_cxx: bins_dep_cxx privatelibs_cxx\
  298. % for tgt in targets:
  299. % if tgt.build == 'test' and tgt.get('c++', False):
  300. bins/$(CONFIG)/${tgt.name}\
  301. % endif
  302. % endfor
  303. test: test_c test_cxx
  304. test_c: buildtests_c
  305. % for tgt in targets:
  306. % if tgt.build == 'test' and tgt.get('run', True) and not tgt.get('c++', False):
  307. $(E) "[RUN] Testing ${tgt.name}"
  308. $(Q) ./bins/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  309. % endif
  310. % endfor
  311. test_cxx: buildtests_cxx
  312. % for tgt in targets:
  313. % if tgt.build == 'test' and tgt.get('run', True) and tgt.get('c++', False):
  314. $(E) "[RUN] Testing ${tgt.name}"
  315. $(Q) ./bins/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  316. % endif
  317. % endfor
  318. tools: privatelibs\
  319. % for tgt in targets:
  320. % if tgt.build == 'tool':
  321. bins/$(CONFIG)/${tgt.name}\
  322. % endif
  323. % endfor
  324. protoc_plugins:\
  325. % for tgt in targets:
  326. % if tgt.build == 'protoc':
  327. bins/$(CONFIG)/${tgt.name}\
  328. % endif
  329. % endfor
  330. buildbenchmarks: privatelibs\
  331. % for tgt in targets:
  332. % if tgt.build == 'benchmark':
  333. bins/$(CONFIG)/${tgt.name}\
  334. % endif
  335. % endfor
  336. benchmarks: buildbenchmarks
  337. strip: strip-static strip-shared
  338. strip-static: strip-static_c strip-static_cxx
  339. strip-shared: strip-shared_c strip-shared_cxx
  340. strip-static_c: static_c
  341. % for lib in libs:
  342. % if not lib.get("c++", False):
  343. % if lib.build == "all":
  344. $(E) "[STRIP] Stripping lib${lib.name}.a"
  345. $(Q) $(STRIP) libs/$(CONFIG)/lib${lib.name}.a
  346. % endif
  347. % endif
  348. % endfor
  349. strip-static_cxx: static_cxx
  350. % for lib in libs:
  351. % if lib.get("c++", False):
  352. % if lib.build == "all":
  353. $(E) "[STRIP] Stripping lib${lib.name}.a"
  354. $(Q) $(STRIP) libs/$(CONFIG)/lib${lib.name}.a
  355. % endif
  356. % endif
  357. % endfor
  358. strip-shared_c: shared_c
  359. % for lib in libs:
  360. % if not lib.get("c++", False):
  361. % if lib.build == "all":
  362. $(E) "[STRIP] Stripping lib${lib.name}.so"
  363. $(Q) $(STRIP) libs/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
  364. % endif
  365. % endif
  366. % endfor
  367. strip-shared_cxx: shared_cxx
  368. % for lib in libs:
  369. % if lib.get("c++", False):
  370. % if lib.build == "all":
  371. $(E) "[STRIP] Stripping lib${lib.name}.so"
  372. $(Q) $(STRIP) libs/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
  373. % endif
  374. % endif
  375. % endfor
  376. % for p in protos:
  377. deps/$(CONFIG)/gens/${p}.pb.dep:
  378. $(Q) mkdir -p `dirname $@`
  379. $(Q) touch $@
  380. gens/${p}.pb.cc: ${p}.proto protoc_plugins
  381. $(E) "[PROTOC] Generating protobuf CC file from $<"
  382. $(Q) mkdir -p `dirname $@`
  383. $(Q) $(PROTOC) --cpp_out=gens --grpc_out=gens --plugin=protoc-gen-grpc=bins/$(CONFIG)/cpp_plugin $<
  384. % endfor
  385. deps/$(CONFIG)/%.dep : %.c
  386. $(E) "[DEP] Generating dependencies for $<"
  387. $(Q) mkdir -p `dirname $@`
  388. $(Q) $(CC) $(CFLAGS) $(CPPFLAGS_NO_ARCH) -MG -M $< > $@
  389. deps/$(CONFIG)/%.dep : %.cc
  390. $(E) "[DEP] Generating dependencies for $<"
  391. $(Q) mkdir -p `dirname $@`
  392. $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS_NO_ARCH) -MG -M $< > $@
  393. objs/$(CONFIG)/%.o : %.c
  394. $(E) "[C] Compiling $<"
  395. $(Q) mkdir -p `dirname $@`
  396. $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
  397. objs/$(CONFIG)/%.o : gens/%.pb.cc
  398. $(E) "[CXX] Compiling $<"
  399. $(Q) mkdir -p `dirname $@`
  400. $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
  401. objs/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
  402. $(E) "[HOSTCXX] Compiling $<"
  403. $(Q) mkdir -p `dirname $@`
  404. $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -c -o $@ $<
  405. objs/$(CONFIG)/%.o : %.cc
  406. $(E) "[CXX] Compiling $<"
  407. $(Q) mkdir -p `dirname $@`
  408. $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
  409. dep: dep_c dep_cxx
  410. dep_c:\
  411. % for lib in libs:
  412. % if not lib.get('c++', False):
  413. deps_lib${lib.name}\
  414. % endif
  415. % endfor
  416. bins_dep_c:\
  417. % for tgt in targets:
  418. % if not tgt.get('c++', False):
  419. deps_${tgt.name}\
  420. % endif
  421. % endfor
  422. dep_cxx:\
  423. % for lib in libs:
  424. % if lib.get('c++', False):
  425. deps_lib${lib.name}\
  426. % endif
  427. % endfor
  428. bins_dep_cxx:\
  429. % for tgt in targets:
  430. % if tgt.get('c++', False):
  431. deps_${tgt.name}\
  432. % endif
  433. % endfor
  434. install: install_c install_cxx
  435. install_c: install-headers_c install-static_c install-shared_c
  436. install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
  437. install-headers: install-headers_c install-headers_cxx
  438. install-headers_c:
  439. $(E) "[INSTALL] Installing public C headers"
  440. $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
  441. install-headers_cxx:
  442. $(E) "[INSTALL] Installing public C++ headers"
  443. $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
  444. install-static: install-static_c install-static_cxx
  445. install-static_c: static_c strip-static_c
  446. % for lib in libs:
  447. % if not lib.get("c++", False):
  448. % if lib.build == "all":
  449. $(E) "[INSTALL] Installing lib${lib.name}.a"
  450. $(Q) $(INSTALL) libs/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
  451. % endif
  452. % endif
  453. % endfor
  454. install-static_cxx: static_cxx strip-static_cxx
  455. % for lib in libs:
  456. % if lib.get("c++", False):
  457. % if lib.build == "all":
  458. $(E) "[INSTALL] Installing lib${lib.name}.a"
  459. $(Q) $(INSTALL) libs/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
  460. % endif
  461. % endif
  462. % endfor
  463. install-shared_c: shared_c strip-shared_c
  464. % for lib in libs:
  465. % if not lib.get("c++", False):
  466. % if lib.build == "all":
  467. ifeq ($(SYSTEM),MINGW32)
  468. $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)"
  469. $(Q) $(INSTALL) libs/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT)
  470. $(Q) $(INSTALL) libs/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
  471. else
  472. $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)"
  473. $(Q) $(INSTALL) libs/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT)
  474. ifneq ($(SYSTEM),Darwin)
  475. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
  476. endif
  477. endif
  478. % endif
  479. % endif
  480. % endfor
  481. ifneq ($(SYSTEM),MINGW32)
  482. ifneq ($(SYSTEM),Darwin)
  483. $(Q) ldconfig
  484. endif
  485. endif
  486. install-shared_cxx: shared_cxx strip-shared_cxx
  487. % for lib in libs:
  488. % if lib.get("c++", False):
  489. % if lib.build == "all":
  490. ifeq ($(SYSTEM),MINGW32)
  491. $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)"
  492. $(Q) $(INSTALL) libs/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT)
  493. $(Q) $(INSTALL) libs/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
  494. else
  495. $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)"
  496. $(Q) $(INSTALL) libs/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT)
  497. ifneq ($(SYSTEM),Darwin)
  498. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
  499. endif
  500. endif
  501. % endif
  502. % endif
  503. % endfor
  504. ifneq ($(SYSTEM),MINGW32)
  505. ifneq ($(SYSTEM),Darwin)
  506. $(Q) ldconfig
  507. endif
  508. endif
  509. clean:\
  510. % for lib in libs:
  511. clean_lib${lib.name}\
  512. % endfor
  513. % for tgt in targets:
  514. clean_${tgt.name}\
  515. % endfor
  516. $(Q) $(RM) -r deps objs libs bins gens
  517. # The various libraries
  518. % for lib in libs:
  519. ${makelib(lib)}
  520. % endfor
  521. # All of the test targets, and protoc plugins
  522. % for tgt in targets:
  523. ${maketarget(tgt)}
  524. % endfor
  525. <%def name="makelib(lib)">
  526. LIB${lib.name.upper()}_SRC = \\
  527. % for src in lib.src:
  528. ${proto_to_cc(src)} \\
  529. % endfor
  530. % if "public_headers" in lib:
  531. % if lib.get("c++", False):
  532. PUBLIC_HEADERS_CXX += \\
  533. % else:
  534. PUBLIC_HEADERS_C += \\
  535. % endif
  536. % for hdr in lib.public_headers:
  537. ${hdr} \\
  538. % endfor
  539. % endif
  540. LIB${lib.name.upper()}_OBJS = $(addprefix objs/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
  541. LIB${lib.name.upper()}_DEPS = $(addprefix deps/$(CONFIG)/, $(addsuffix .dep, $(basename $(LIB${lib.name.upper()}_SRC))))
  542. % if lib.get('secure', True):
  543. ifeq ($(NO_SECURE),true)
  544. libs/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
  545. % if lib.build == "all":
  546. ifeq ($(SYSTEM),MINGW32)
  547. libs/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error
  548. else
  549. libs/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error
  550. endif
  551. % endif
  552. else
  553. libs/$(CONFIG)/lib${lib.name}.a: $(OPENSSL_DEP) $(LIB${lib.name.upper()}_OBJS)
  554. % else:
  555. libs/$(CONFIG)/lib${lib.name}.a: $(LIB${lib.name.upper()}_OBJS)
  556. % endif
  557. $(E) "[AR] Creating $@"
  558. $(Q) mkdir -p `dirname $@`
  559. $(Q) $(AR) rcs libs/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
  560. % if lib.get('baselib', False):
  561. % if lib.get('secure', True):
  562. $(Q) rm -rf tmp-merge
  563. $(Q) mkdir tmp-merge
  564. $(Q) ( cd tmp-merge ; $(AR) x ../libs/$(CONFIG)/lib${lib.name}.a )
  565. $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge ; <%text>ar x ../$${l}</%text> ) ; done
  566. $(Q) rm -f libs/$(CONFIG)/lib${lib.name}.a tmp-merge/__.SYMDEF*
  567. $(Q) ar rcs libs/$(CONFIG)/lib${lib.name}.a tmp-merge/*
  568. $(Q) rm -rf tmp-merge
  569. % endif
  570. % endif
  571. <%
  572. if lib.get('c++', False):
  573. ld = '$(LDXX)'
  574. else:
  575. ld = '$(LD)'
  576. out_base = 'libs/$(CONFIG)/' + lib.name
  577. out_libbase = 'libs/$(CONFIG)/lib' + lib.name
  578. common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
  579. libs = ''
  580. lib_deps = ''
  581. mingw_libs = ''
  582. mingw_lib_deps = ''
  583. for dep in lib.get('deps', []):
  584. libs = libs + ' -l' + dep
  585. lib_deps = lib_deps + 'libs/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
  586. mingw_libs = mingw_libs + ' -l' + dep + '-imp'
  587. mingw_lib_deps = mingw_lib_deps + 'libs/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
  588. if lib.get('secure', True):
  589. common = common + ' $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS)'
  590. lib_deps = lib_deps + ' $(OPENSSL_DEP)'
  591. mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
  592. %>
  593. % if lib.build == "all":
  594. ifeq ($(SYSTEM),MINGW32)
  595. ${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
  596. $(E) "[LD] Linking $@"
  597. $(Q) mkdir -p `dirname $@`
  598. $(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}
  599. else
  600. ${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
  601. $(E) "[LD] Linking $@"
  602. $(Q) mkdir -p `dirname $@`
  603. ifeq ($(SYSTEM),Darwin)
  604. $(Q) ${ld} $(LDFLAGS) -Llibs/$(CONFIG) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
  605. else
  606. $(Q) ${ld} $(LDFLAGS) -Llibs/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
  607. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so
  608. endif
  609. endif
  610. % endif
  611. % if lib.get('secure', True):
  612. endif
  613. % endif
  614. deps_lib${lib.name}: $(LIB${lib.name.upper()}_DEPS)
  615. % if lib.get('secure', True):
  616. ifneq ($(NO_SECURE),true)
  617. % endif
  618. ifneq ($(NO_DEPS),true)
  619. -include $(LIB${lib.name.upper()}_DEPS)
  620. endif
  621. % if lib.get('secure', True):
  622. endif
  623. % endif
  624. % for src in lib.src:
  625. % if not proto_re.match(src):
  626. objs/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
  627. % for src2 in lib.src:
  628. % if proto_re.match(src2):
  629. ${proto_to_cc(src2)}\
  630. % endif
  631. % endfor
  632. % endif
  633. % endfor
  634. clean_lib${lib.name}:
  635. $(E) "[CLEAN] Cleaning lib${lib.name} files"
  636. $(Q) $(RM) $(LIB${lib.name.upper()}_OBJS)
  637. $(Q) $(RM) $(LIB${lib.name.upper()}_DEPS)
  638. $(Q) $(RM) libs/$(CONFIG)/lib${lib.name}.a
  639. $(Q) $(RM) libs/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
  640. </%def>
  641. <%def name="maketarget(tgt)">
  642. ${tgt.name.upper()}_SRC = \\
  643. % for src in tgt.src:
  644. ${proto_to_cc(src)} \\
  645. % endfor
  646. ${tgt.name.upper()}_OBJS = $(addprefix objs/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
  647. ${tgt.name.upper()}_DEPS = $(addprefix deps/$(CONFIG)/, $(addsuffix .dep, $(basename $(${tgt.name.upper()}_SRC))))
  648. % if tgt.get('secure', True):
  649. ifeq ($(NO_SECURE),true)
  650. bins/$(CONFIG)/${tgt.name}: openssl_dep_error
  651. else
  652. % endif
  653. bins/$(CONFIG)/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
  654. % for dep in tgt.deps:
  655. libs/$(CONFIG)/lib${dep}.a\
  656. % endfor
  657. % if tgt.get("c++", False):
  658. % if tgt.build == 'protoc':
  659. $(E) "[HOSTLD] Linking $@"
  660. $(Q) mkdir -p `dirname $@`
  661. $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(${tgt.name.upper()}_OBJS)\
  662. % else:
  663. $(E) "[LD] Linking $@"
  664. $(Q) mkdir -p `dirname $@`
  665. $(Q) $(LDXX) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
  666. % endif
  667. % if tgt.build == 'test':
  668. $(GTEST_LIB)\
  669. % endif
  670. % else:
  671. $(E) "[LD] Linking $@"
  672. $(Q) mkdir -p `dirname $@`
  673. $(Q) $(LD) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
  674. % endif
  675. % for dep in tgt.deps:
  676. libs/$(CONFIG)/lib${dep}.a\
  677. % endfor
  678. % if tgt.get("c++", False):
  679. % if tgt.build == 'protoc':
  680. $(HOST_LDLIBSXX)\
  681. % else:
  682. $(LDLIBSXX)\
  683. % endif
  684. % endif
  685. % if tgt.build == 'protoc':
  686. $(HOST_LDLIBS)\
  687. % else:
  688. $(LDLIBS)\
  689. % endif
  690. % if tgt.build == 'protoc':
  691. $(HOST_LDLIBS_PROTOC)\
  692. % elif tgt.get('secure', True):
  693. $(LDLIBS_SECURE)\
  694. % endif
  695. -o bins/$(CONFIG)/${tgt.name}
  696. % if tgt.get('secure', True):
  697. endif
  698. % endif
  699. % for src in tgt.src:
  700. objs/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
  701. % for dep in tgt.deps:
  702. libs/$(CONFIG)/lib${dep}.a\
  703. % endfor
  704. % endfor
  705. deps_${tgt.name}: $(${tgt.name.upper()}_DEPS)
  706. % if tgt.get('secure', True):
  707. ifneq ($(NO_SECURE),true)
  708. % endif
  709. ifneq ($(NO_DEPS),true)
  710. -include $(${tgt.name.upper()}_DEPS)
  711. endif
  712. % if tgt.get('secure', True):
  713. endif
  714. % endif
  715. clean_${tgt.name}:
  716. $(E) "[CLEAN] Cleaning ${tgt.name} files"
  717. $(Q) $(RM) $(${tgt.name.upper()}_OBJS)
  718. $(Q) $(RM) $(${tgt.name.upper()}_DEPS)
  719. $(Q) $(RM) bins/$(CONFIG)/${tgt.name}
  720. </%def>
  721. .PHONY: all strip tools \
  722. dep_error openssl_dep_error openssl_dep_message git_update stop \
  723. buildtests buildtests_c buildtests_cxx \
  724. test test_c test_cxx \
  725. install install_c install_cxx \
  726. install-headers install-headers_c install-headers_cxx \
  727. install-shared install-shared_c install-shared_cxx \
  728. install-static install-static_c install-static_cxx \
  729. strip strip-shared strip-static \
  730. strip_c strip-shared_c strip-static_c \
  731. strip_cxx strip-shared_cxx strip-static_cxx \
  732. clean \
  733. dep_c dep_cxx bins_dep_c bins_dep_cxx\
  734. % for lib in libs:
  735. deps_lib${lib.name} clean_lib${lib.name}\
  736. % endfor
  737. % for tgt in targets:
  738. deps_${tgt.name} clean_${tgt.name}\
  739. % endfor