Makefile.template 20 KB

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