Makefile.template 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  1. # GRPC global makefile
  2. # This currently builds C and C++ code.
  3. # Copyright 2015, Google Inc.
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. #
  10. # * Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # * Redistributions in binary form must reproduce the above
  13. # copyright notice, this list of conditions and the following disclaimer
  14. # in the documentation and/or other materials provided with the
  15. # distribution.
  16. # * Neither the name of Google Inc. nor the names of its
  17. # contributors may be used to endorse or promote products derived from
  18. # this software without specific prior written permission.
  19. #
  20. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. <%!
  32. import re
  33. import os
  34. proto_re = re.compile('(.*)\\.proto')
  35. def proto_to_cc(filename):
  36. m = proto_re.match(filename)
  37. if not m:
  38. return filename
  39. return '$(GENDIR)/' + m.group(1) + '.pb.cc $(GENDIR)/' + m.group(1) + '.grpc.pb.cc'
  40. %>
  41. # Basic platform detection
  42. HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
  43. ifeq ($(SYSTEM),)
  44. SYSTEM = $(HOST_SYSTEM)
  45. endif
  46. ifeq ($(SYSTEM),MSYS)
  47. SYSTEM = MINGW32
  48. endif
  49. ifndef BUILDDIR
  50. BUILDDIR = .
  51. endif
  52. HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false)
  53. HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false)
  54. HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false)
  55. ifeq ($(HAS_CC),true)
  56. DEFAULT_CC = cc
  57. DEFAULT_CXX = c++
  58. else
  59. ifeq ($(HAS_GCC),true)
  60. DEFAULT_CC = gcc
  61. DEFAULT_CXX = g++
  62. else
  63. ifeq ($(HAS_CLANG),true)
  64. DEFAULT_CC = clang
  65. DEFAULT_CXX = clang++
  66. else
  67. DEFAULT_CC = no_c_compiler
  68. DEFAULT_CXX = no_c++_compiler
  69. endif
  70. endif
  71. endif
  72. BINDIR = $(BUILDDIR)/bins
  73. OBJDIR = $(BUILDDIR)/objs
  74. LIBDIR = $(BUILDDIR)/libs
  75. GENDIR = $(BUILDDIR)/gens
  76. # Configurations
  77. VALID_CONFIG_opt = 1
  78. CC_opt = $(DEFAULT_CC)
  79. CXX_opt = $(DEFAULT_CXX)
  80. LD_opt = $(DEFAULT_CC)
  81. LDXX_opt = $(DEFAULT_CXX)
  82. CPPFLAGS_opt = -O2
  83. LDFLAGS_opt =
  84. DEFINES_opt = NDEBUG
  85. VALID_CONFIG_dbg = 1
  86. CC_dbg = $(DEFAULT_CC)
  87. CXX_dbg = $(DEFAULT_CXX)
  88. LD_dbg = $(DEFAULT_CC)
  89. LDXX_dbg = $(DEFAULT_CXX)
  90. CPPFLAGS_dbg = -O0
  91. LDFLAGS_dbg =
  92. DEFINES_dbg = _DEBUG DEBUG
  93. VALID_CONFIG_mutrace = 1
  94. CC_mutrace = $(DEFAULT_CC)
  95. CXX_mutrace = $(DEFAULT_CXX)
  96. LD_mutrace = $(DEFAULT_CC)
  97. LDXX_mutrace = $(DEFAULT_CXX)
  98. CPPFLAGS_mutrace = -O0
  99. LDFLAGS_mutrace = -rdynamic
  100. DEFINES_mutrace = _DEBUG DEBUG
  101. VALID_CONFIG_valgrind = 1
  102. REQUIRE_CUSTOM_LIBRARIES_valgrind = 1
  103. CC_valgrind = $(DEFAULT_CC)
  104. CXX_valgrind = $(DEFAULT_CXX)
  105. LD_valgrind = $(DEFAULT_CC)
  106. LDXX_valgrind = $(DEFAULT_CXX)
  107. CPPFLAGS_valgrind = -O0
  108. OPENSSL_CFLAGS_valgrind = -DPURIFY
  109. LDFLAGS_valgrind =
  110. DEFINES_valgrind = _DEBUG DEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20
  111. VALID_CONFIG_tsan = 1
  112. REQUIRE_CUSTOM_LIBRARIES_tsan = 1
  113. CC_tsan = clang
  114. CXX_tsan = clang++
  115. LD_tsan = clang
  116. LDXX_tsan = clang++
  117. CPPFLAGS_tsan = -O1 -fsanitize=thread -fno-omit-frame-pointer
  118. LDFLAGS_tsan = -fsanitize=thread
  119. DEFINES_tsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10
  120. VALID_CONFIG_asan = 1
  121. REQUIRE_CUSTOM_LIBRARIES_asan = 1
  122. CC_asan = clang
  123. CXX_asan = clang++
  124. LD_asan = clang
  125. LDXX_asan = clang++
  126. CPPFLAGS_asan = -O1 -fsanitize=address -fno-omit-frame-pointer
  127. LDFLAGS_asan = -fsanitize=address
  128. DEFINES_asan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5
  129. VALID_CONFIG_msan = 1
  130. REQUIRE_CUSTOM_LIBRARIES_msan = 1
  131. CC_msan = clang
  132. CXX_msan = clang++-libc++
  133. LD_msan = clang
  134. LDXX_msan = clang++-libc++
  135. CPPFLAGS_msan = -O1 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
  136. OPENSSL_CFLAGS_msan = -DPURIFY
  137. LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
  138. DEFINES_msan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20
  139. VALID_CONFIG_ubsan = 1
  140. REQUIRE_CUSTOM_LIBRARIES_ubsan = 1
  141. CC_ubsan = clang
  142. CXX_ubsan = clang++
  143. LD_ubsan = clang
  144. LDXX_ubsan = clang++
  145. CPPFLAGS_ubsan = -O1 -fsanitize=undefined -fno-omit-frame-pointer
  146. OPENSSL_CFLAGS_ubsan = -DPURIFY
  147. LDFLAGS_ubsan = -fsanitize=undefined
  148. DEFINES_ubsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10
  149. VALID_CONFIG_gcov = 1
  150. CC_gcov = gcc
  151. CXX_gcov = g++
  152. LD_gcov = gcc
  153. LDXX_gcov = g++
  154. CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage
  155. LDFLAGS_gcov = -fprofile-arcs -ftest-coverage
  156. DEFINES_gcov = NDEBUG
  157. # General settings.
  158. # You may want to change these depending on your system.
  159. prefix ?= /usr/local
  160. PROTOC = protoc
  161. CONFIG ?= opt
  162. CC = $(CC_$(CONFIG))
  163. CXX = $(CXX_$(CONFIG))
  164. LD = $(LD_$(CONFIG))
  165. LDXX = $(LDXX_$(CONFIG))
  166. AR = ar
  167. ifeq ($(SYSTEM),Linux)
  168. STRIP = strip --strip-unneeded
  169. else
  170. ifeq ($(SYSTEM),Darwin)
  171. STRIP = strip -x
  172. else
  173. STRIP = strip
  174. endif
  175. endif
  176. INSTALL = install
  177. RM = rm -f
  178. ifndef VALID_CONFIG_$(CONFIG)
  179. $(error Invalid CONFIG value '$(CONFIG)')
  180. endif
  181. ifeq ($(SYSTEM),Linux)
  182. TMPOUT = /dev/null
  183. else
  184. TMPOUT = `mktemp /tmp/test-out-XXXXXX`
  185. endif
  186. # Detect if we can use C++11
  187. CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc
  188. HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false)
  189. # The HOST compiler settings are used to compile the protoc plugins.
  190. # In most cases, you won't have to change anything, but if you are
  191. # cross-compiling, you can override these variables from GNU make's
  192. # command line: make CC=cross-gcc HOST_CC=gcc
  193. HOST_CC = $(CC)
  194. HOST_CXX = $(CXX)
  195. HOST_LD = $(LD)
  196. HOST_LDXX = $(LDXX)
  197. CPPFLAGS += $(CPPFLAGS_$(CONFIG))
  198. DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
  199. LDFLAGS += $(LDFLAGS_$(CONFIG))
  200. ifdef EXTRA_DEFINES
  201. DEFINES += $(EXTRA_DEFINES)
  202. endif
  203. CFLAGS += -std=c89 -pedantic
  204. ifeq ($(HAS_CXX11),true)
  205. CXXFLAGS += -std=c++11
  206. else
  207. CXXFLAGS += -std=c++0x
  208. endif
  209. CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
  210. LDFLAGS += -g
  211. ifneq ($(SYSTEM),MINGW32)
  212. PIC_CPPFLAGS = -fPIC
  213. CPPFLAGS += -fPIC
  214. LDFLAGS += -fPIC
  215. endif
  216. INCLUDES = . include $(GENDIR)
  217. ifeq ($(SYSTEM),Darwin)
  218. ifneq ($(wildcard /usr/local/ssl/include),)
  219. INCLUDES += /usr/local/ssl/include
  220. endif
  221. ifneq ($(wildcard /opt/local/include),)
  222. INCLUDES += /opt/local/include
  223. endif
  224. ifneq ($(wildcard /usr/local/include),)
  225. INCLUDES += /usr/local/include
  226. endif
  227. LIBS = m z
  228. ifneq ($(wildcard /usr/local/ssl/lib),)
  229. LDFLAGS += -L/usr/local/ssl/lib
  230. endif
  231. ifneq ($(wildcard /opt/local/lib),)
  232. LDFLAGS += -L/opt/local/lib
  233. endif
  234. ifneq ($(wildcard /usr/local/lib),)
  235. LDFLAGS += -L/usr/local/lib
  236. endif
  237. endif
  238. ifeq ($(SYSTEM),Linux)
  239. LIBS = rt m z pthread
  240. LDFLAGS += -pthread
  241. endif
  242. ifeq ($(SYSTEM),MINGW32)
  243. LIBS = m z pthread
  244. LDFLAGS += -pthread
  245. endif
  246. ifneq ($(wildcard /usr/src/gtest/src/gtest-all.cc),)
  247. GTEST_LIB = /usr/src/gtest/src/gtest-all.cc -I/usr/src/gtest
  248. else
  249. GTEST_LIB = -lgtest
  250. endif
  251. GTEST_LIB += -lgflags
  252. ifeq ($(V),1)
  253. E = @:
  254. Q =
  255. else
  256. E = @echo
  257. Q = @
  258. endif
  259. VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build}
  260. CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
  261. CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
  262. LDFLAGS += $(ARCH_FLAGS)
  263. LDLIBS += $(addprefix -l, $(LIBS))
  264. LDLIBSXX += $(addprefix -l, $(LIBSXX))
  265. HOST_CPPFLAGS = $(CPPFLAGS)
  266. HOST_CFLAGS = $(CFLAGS)
  267. HOST_CXXFLAGS = $(CXXFLAGS)
  268. HOST_LDFLAGS = $(LDFLAGS)
  269. HOST_LDLIBS = $(LDLIBS)
  270. # These are automatically computed variables.
  271. # There shouldn't be any need to change anything from now on.
  272. ifeq ($(SYSTEM),MINGW32)
  273. SHARED_EXT = dll
  274. endif
  275. ifeq ($(SYSTEM),Darwin)
  276. SHARED_EXT = dylib
  277. endif
  278. ifeq ($(SHARED_EXT),)
  279. SHARED_EXT = so.$(VERSION)
  280. endif
  281. ifeq ($(wildcard .git),)
  282. IS_GIT_FOLDER = false
  283. else
  284. IS_GIT_FOLDER = true
  285. endif
  286. ifeq ($(SYSTEM),Linux)
  287. OPENSSL_REQUIRES_DL = true
  288. endif
  289. ifeq ($(SYSTEM),Darwin)
  290. OPENSSL_REQUIRES_DL = true
  291. endif
  292. ifeq ($(SYSTEM),MINGW32)
  293. OPENSSL_LIBS = ssl32 eay32
  294. else
  295. OPENSSL_LIBS = ssl crypto
  296. endif
  297. OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
  298. ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
  299. PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
  300. PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
  301. PROTOC_CMD = which protoc > /dev/null
  302. PROTOC_CHECK_CMD = protoc --version | grep -q libprotoc.3
  303. ifeq ($(OPENSSL_REQUIRES_DL),true)
  304. OPENSSL_ALPN_CHECK_CMD += -ldl
  305. endif
  306. ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
  307. HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
  308. ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
  309. DEFINES += GRPC_HAVE_PERFTOOLS
  310. LIBS += profiler
  311. endif
  312. endif
  313. HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
  314. ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
  315. HAS_SYSTEM_OPENSSL_ALPN = $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
  316. HAS_SYSTEM_ZLIB = $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
  317. HAS_SYSTEM_PROTOBUF = $(HAS_SYSTEM_PROTOBUF_VERIFY)
  318. else
  319. # override system libraries if the config requires a custom compiled library
  320. HAS_SYSTEM_OPENSSL_ALPN = false
  321. HAS_SYSTEM_ZLIB = false
  322. HAS_SYSTEM_PROTOBUF = false
  323. endif
  324. HAS_PROTOC = $(shell $(PROTOC_CMD) 2> /dev/null && echo true || echo false)
  325. ifeq ($(HAS_PROTOC),true)
  326. HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
  327. else
  328. HAS_VALID_PROTOC = false
  329. endif
  330. ifeq ($(wildcard third_party/openssl/ssl/ssl.h),)
  331. HAS_EMBEDDED_OPENSSL_ALPN = false
  332. else
  333. HAS_EMBEDDED_OPENSSL_ALPN = true
  334. endif
  335. ifeq ($(wildcard third_party/zlib/zlib.h),)
  336. HAS_EMBEDDED_ZLIB = false
  337. else
  338. HAS_EMBEDDED_ZLIB = true
  339. endif
  340. ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
  341. HAS_EMBEDDED_PROTOBUF = false
  342. ifneq ($(HAS_VALID_PROTOC),true)
  343. NO_PROTOC = true
  344. endif
  345. else
  346. HAS_EMBEDDED_PROTOBUF = true
  347. endif
  348. ifeq ($(HAS_SYSTEM_ZLIB),false)
  349. ifeq ($(HAS_EMBEDDED_ZLIB),true)
  350. ZLIB_DEP = $(LIBDIR)/$(CONFIG)/zlib/libz.a
  351. CPPFLAGS += -Ithird_party/zlib
  352. LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib
  353. else
  354. DEP_MISSING += zlib
  355. endif
  356. endif
  357. ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false)
  358. ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true)
  359. OPENSSL_DEP = $(LIBDIR)/$(CONFIG)/openssl/libssl.a
  360. OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/openssl/libssl.a $(LIBDIR)/$(CONFIG)/openssl/libcrypto.a
  361. # need to prefix these to ensure overriding system libraries
  362. CPPFLAGS := -Ithird_party/openssl/include $(CPPFLAGS)
  363. LDFLAGS := -L$(LIBDIR)/$(CONFIG)/openssl $(LDFLAGS)
  364. ifeq ($(OPENSSL_REQUIRES_DL),true)
  365. LIBS_SECURE = dl
  366. endif
  367. else
  368. NO_SECURE = true
  369. endif
  370. else
  371. LIBS_SECURE = $(OPENSSL_LIBS)
  372. ifeq ($(OPENSSL_REQUIRES_DL),true)
  373. LIBS_SECURE += dl
  374. endif
  375. endif
  376. LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
  377. ifeq ($(HAS_SYSTEM_PROTOBUF),false)
  378. ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
  379. PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
  380. CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
  381. LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
  382. PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
  383. else
  384. NO_PROTOBUF = true
  385. endif
  386. else
  387. endif
  388. LIBS_PROTOBUF = protobuf
  389. LIBS_PROTOC = protoc protobuf
  390. LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
  391. HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
  392. ifeq ($(MAKECMDGOALS),clean)
  393. NO_DEPS = true
  394. endif
  395. INSTALL_OK = false
  396. ifeq ($(HAS_VALID_PROTOC),true)
  397. ifeq ($(HAS_SYSTEM_PROTOBUF_VERIFY),true)
  398. INSTALL_OK = true
  399. endif
  400. endif
  401. .SECONDARY = %.pb.h %.pb.cc
  402. PROTOC_PLUGINS =\
  403. % for tgt in targets:
  404. % if tgt.build == 'protoc':
  405. $(BINDIR)/$(CONFIG)/${tgt.name}\
  406. % endif
  407. % endfor
  408. ifeq ($(DEP_MISSING),)
  409. all: static shared plugins\
  410. % for tgt in targets:
  411. % if tgt.build == 'all':
  412. $(BINDIR)/$(CONFIG)/${tgt.name}\
  413. % endif
  414. % endfor
  415. dep_error:
  416. @echo "You shouldn't see this message - all of your dependencies are correct."
  417. else
  418. all: dep_error git_update stop
  419. dep_error:
  420. @echo
  421. @echo "DEPENDENCY ERROR"
  422. @echo
  423. @echo "You are missing system dependencies that are essential to build grpc,"
  424. @echo "and the third_party directory doesn't have them:"
  425. @echo
  426. @echo " $(DEP_MISSING)"
  427. @echo
  428. @echo "Installing the development packages for your system will solve"
  429. @echo "this issue. Please consult INSTALL to get more information."
  430. @echo
  431. @echo "If you need information about why these tests failed, run:"
  432. @echo
  433. @echo " make run_dep_checks"
  434. @echo
  435. endif
  436. git_update:
  437. ifeq ($(IS_GIT_FOLDER),true)
  438. @echo "Additionally, since you are in a git clone, you can download the"
  439. @echo "missing dependencies in third_party by running the following command:"
  440. @echo
  441. @echo " git submodule update --init"
  442. @echo
  443. endif
  444. openssl_dep_error: openssl_dep_message git_update stop
  445. protobuf_dep_error: protobuf_dep_message git_update stop
  446. protoc_dep_error: protoc_dep_message git_update stop
  447. openssl_dep_message:
  448. @echo
  449. @echo "DEPENDENCY ERROR"
  450. @echo
  451. @echo "The target you are trying to run requires OpenSSL with ALPN support."
  452. @echo "Your system doesn't have it, and neither does the third_party directory."
  453. @echo
  454. @echo "Please consult INSTALL to get more information."
  455. @echo
  456. @echo "If you need information about why these tests failed, run:"
  457. @echo
  458. @echo " make run_dep_checks"
  459. @echo
  460. protobuf_dep_message:
  461. @echo
  462. @echo "DEPENDENCY ERROR"
  463. @echo
  464. @echo "The target you are trying to run requires protobuf 3.0.0+"
  465. @echo "Your system doesn't have it, and neither does the third_party directory."
  466. @echo
  467. @echo "Please consult INSTALL to get more information."
  468. @echo
  469. @echo "If you need information about why these tests failed, run:"
  470. @echo
  471. @echo " make run_dep_checks"
  472. @echo
  473. protoc_dep_message:
  474. @echo
  475. @echo "DEPENDENCY ERROR"
  476. @echo
  477. @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
  478. @echo "Your system doesn't have it, and neither does the third_party directory."
  479. @echo
  480. @echo "Please consult INSTALL to get more information."
  481. @echo
  482. @echo "If you need information about why these tests failed, run:"
  483. @echo
  484. @echo " make run_dep_checks"
  485. @echo
  486. stop:
  487. @false
  488. % for tgt in targets:
  489. ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
  490. % endfor
  491. run_dep_checks:
  492. $(OPENSSL_ALPN_CHECK_CMD) || true
  493. $(ZLIB_CHECK_CMD) || true
  494. $(PERFTOOLS_CHECK_CMD) || true
  495. $(PROTOBUF_CHECK_CMD) || true
  496. $(PROTOC_CHECK_CMD) || true
  497. $(LIBDIR)/$(CONFIG)/zlib/libz.a:
  498. $(E) "[MAKE] Building zlib"
  499. $(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="$(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG))" ./configure --static)
  500. $(Q)$(MAKE) -C third_party/zlib clean
  501. $(Q)$(MAKE) -C third_party/zlib
  502. $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/zlib
  503. $(Q)cp third_party/zlib/libz.a $(LIBDIR)/$(CONFIG)/zlib
  504. $(LIBDIR)/$(CONFIG)/openssl/libssl.a:
  505. $(E) "[MAKE] Building openssl for $(SYSTEM)"
  506. ifeq ($(SYSTEM),Darwin)
  507. $(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./Configure darwin64-x86_64-cc)
  508. else
  509. ifeq ($(SYSTEM),MINGW32)
  510. @echo "We currently don't have a good way to compile OpenSSL in-place under msys."
  511. @echo "Please provide an ALPN-capable OpenSSL in your mingw32 system."
  512. @echo
  513. @echo "Note that you can find a compatible version of the libraries here:"
  514. @echo
  515. @echo "http://slproweb.com/products/Win32OpenSSL.html"
  516. @echo
  517. @echo "If you decide to install that one, take the full version. The light"
  518. @echo "version only contains compiled DLLs, without the development files."
  519. @echo
  520. @echo "When installing, chose to copy the OpenSSL dlls to the OpenSSL binaries"
  521. @echo "directory. This way we'll link to them directly."
  522. @echo
  523. @echo "You can then re-start the build the following way:"
  524. @echo
  525. @echo " CPPFLAGS=-I/c/OpenSSL-Win64/include LDFLAGS=-L/c/OpenSSL-Win64 make"
  526. @false
  527. else
  528. $(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./config no-asm $(OPENSSL_CONFIG_$(CONFIG)))
  529. endif
  530. endif
  531. $(Q)$(MAKE) -C third_party/openssl clean
  532. $(Q)$(MAKE) -C third_party/openssl build_crypto build_ssl
  533. $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/openssl
  534. $(Q)cp third_party/openssl/libssl.a third_party/openssl/libcrypto.a $(LIBDIR)/$(CONFIG)/openssl
  535. third_party/protobuf/configure:
  536. $(E) "[AUTOGEN] Preparing protobuf"
  537. $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
  538. $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
  539. $(E) "[MAKE] Building protobuf"
  540. ifeq ($(HAVE_CXX11),true)
  541. $(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g" CXXFLAGS="-DLANG_CXX11 -std=c++11" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g" ./configure --disable-shared --enable-static)
  542. else
  543. $(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g" CXXFLAGS="-std=c++0x" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g" ./configure --disable-shared --enable-static)
  544. endif
  545. $(Q)$(MAKE) -C third_party/protobuf clean
  546. $(Q)$(MAKE) -C third_party/protobuf
  547. $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
  548. $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
  549. $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
  550. $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
  551. $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
  552. static: static_c static_cxx
  553. static_c: \
  554. % for lib in libs:
  555. % if lib.build == 'all' and lib.language == 'c':
  556. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  557. % endif
  558. % endfor
  559. static_cxx: \
  560. % for lib in libs:
  561. % if lib.build == 'all' and lib.language == 'c++':
  562. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  563. % endif
  564. % endfor
  565. shared: shared_c shared_cxx
  566. shared_c: \
  567. % for lib in libs:
  568. % if lib.build == 'all' and lib.language == 'c':
  569. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
  570. % endif
  571. % endfor
  572. shared_cxx: \
  573. % for lib in libs:
  574. % if lib.build == 'all' and lib.language == 'c++':
  575. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
  576. % endif
  577. % endfor
  578. shared_csharp: shared_c \
  579. % for lib in libs:
  580. % if lib.build == 'all' and lib.language == 'csharp':
  581. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
  582. % endif
  583. % endfor
  584. grpc_csharp_ext: shared_csharp
  585. plugins: $(PROTOC_PLUGINS)
  586. privatelibs: privatelibs_c privatelibs_cxx
  587. privatelibs_c: \
  588. % for lib in libs:
  589. % if lib.build == 'private' and lib.language == 'c':
  590. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  591. % endif
  592. % endfor
  593. privatelibs_cxx: \
  594. % for lib in libs:
  595. % if lib.build == 'private' and lib.language == 'c++':
  596. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  597. % endif
  598. % endfor
  599. buildtests: buildtests_c buildtests_cxx
  600. buildtests_c: privatelibs_c\
  601. % for tgt in targets:
  602. % if tgt.build == 'test' and not tgt.language == 'c++':
  603. $(BINDIR)/$(CONFIG)/${tgt.name}\
  604. % endif
  605. % endfor
  606. buildtests_cxx: privatelibs_cxx\
  607. % for tgt in targets:
  608. % if tgt.build == 'test' and tgt.language == 'c++':
  609. $(BINDIR)/$(CONFIG)/${tgt.name}\
  610. % endif
  611. % endfor
  612. test: test_c test_cxx
  613. test_c: buildtests_c
  614. % for tgt in targets:
  615. % if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++':
  616. $(E) "[RUN] Testing ${tgt.name}"
  617. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  618. % endif
  619. % endfor
  620. test_cxx: buildtests_cxx
  621. % for tgt in targets:
  622. % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++':
  623. $(E) "[RUN] Testing ${tgt.name}"
  624. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  625. % endif
  626. % endfor
  627. test_python: static_c
  628. $(E) "[RUN] Testing python code"
  629. $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
  630. tools: privatelibs\
  631. % for tgt in targets:
  632. % if tgt.build == 'tool':
  633. $(BINDIR)/$(CONFIG)/${tgt.name}\
  634. % endif
  635. % endfor
  636. buildbenchmarks: privatelibs\
  637. % for tgt in targets:
  638. % if tgt.build == 'benchmark':
  639. $(BINDIR)/$(CONFIG)/${tgt.name}\
  640. % endif
  641. % endfor
  642. benchmarks: buildbenchmarks
  643. strip: strip-static strip-shared
  644. strip-static: strip-static_c strip-static_cxx
  645. strip-shared: strip-shared_c strip-shared_cxx
  646. # TODO(nnoble): the strip target is stripping in-place, instead
  647. # of copying files in a temporary folder.
  648. # This prevents proper debugging after running make install.
  649. strip-static_c: static_c
  650. ifeq ($(CONFIG),opt)
  651. % for lib in libs:
  652. % if lib.language == "c":
  653. % if lib.build == "all":
  654. $(E) "[STRIP] Stripping lib${lib.name}.a"
  655. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  656. % endif
  657. % endif
  658. % endfor
  659. endif
  660. strip-static_cxx: static_cxx
  661. ifeq ($(CONFIG),opt)
  662. % for lib in libs:
  663. % if lib.language == "c++":
  664. % if lib.build == "all":
  665. $(E) "[STRIP] Stripping lib${lib.name}.a"
  666. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  667. % endif
  668. % endif
  669. % endfor
  670. endif
  671. strip-shared_c: shared_c
  672. ifeq ($(CONFIG),opt)
  673. % for lib in libs:
  674. % if lib.language == "c":
  675. % if lib.build == "all":
  676. $(E) "[STRIP] Stripping lib${lib.name}.so"
  677. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
  678. % endif
  679. % endif
  680. % endfor
  681. endif
  682. strip-shared_cxx: shared_cxx
  683. ifeq ($(CONFIG),opt)
  684. % for lib in libs:
  685. % if lib.language == "c++":
  686. % if lib.build == "all":
  687. $(E) "[STRIP] Stripping lib${lib.name}.so"
  688. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
  689. % endif
  690. % endif
  691. % endfor
  692. endif
  693. strip-shared_csharp: shared_csharp
  694. ifeq ($(CONFIG),opt)
  695. % for lib in libs:
  696. % if lib.language == "csharp":
  697. % if lib.build == "all":
  698. $(E) "[STRIP] Stripping lib${lib.name}.so"
  699. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
  700. % endif
  701. % endif
  702. % endfor
  703. endif
  704. % for p in protos:
  705. ifeq ($(NO_PROTOC),true)
  706. $(GENDIR)/${p}.pb.cc: protoc_dep_error
  707. $(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error
  708. else
  709. $(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
  710. $(E) "[PROTOC] Generating protobuf CC file from $<"
  711. $(Q) mkdir -p `dirname $@`
  712. $(Q) $(PROTOC) --cpp_out=$(GENDIR) $<
  713. $(GENDIR)/${p}.grpc.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
  714. $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
  715. $(Q) mkdir -p `dirname $@`
  716. $(Q) $(PROTOC) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $<
  717. endif
  718. % endfor
  719. $(OBJDIR)/$(CONFIG)/%.o : %.c
  720. $(E) "[C] Compiling $<"
  721. $(Q) mkdir -p `dirname $@`
  722. $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  723. $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
  724. $(E) "[CXX] Compiling $<"
  725. $(Q) mkdir -p `dirname $@`
  726. $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  727. $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
  728. $(E) "[HOSTCXX] Compiling $<"
  729. $(Q) mkdir -p `dirname $@`
  730. $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  731. $(OBJDIR)/$(CONFIG)/%.o : %.cc
  732. $(E) "[CXX] Compiling $<"
  733. $(Q) mkdir -p `dirname $@`
  734. $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  735. install: install_c install_cxx install-plugins install-certs verify-install
  736. install_c: install-headers_c install-static_c install-shared_c
  737. install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
  738. install_csharp: install-shared_csharp install_c
  739. install_grpc_csharp_ext: install_csharp
  740. install-headers: install-headers_c install-headers_cxx
  741. install-headers_c:
  742. $(E) "[INSTALL] Installing public C headers"
  743. $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
  744. $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
  745. install-headers_cxx:
  746. $(E) "[INSTALL] Installing public C++ headers"
  747. $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
  748. $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
  749. install-static: install-static_c install-static_cxx
  750. install-static_c: static_c strip-static_c
  751. % for lib in libs:
  752. % if lib.language == "c":
  753. % if lib.build == "all":
  754. $(E) "[INSTALL] Installing lib${lib.name}.a"
  755. $(Q) $(INSTALL) -d $(prefix)/lib
  756. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
  757. % endif
  758. % endif
  759. % endfor
  760. install-static_cxx: static_cxx strip-static_cxx
  761. % for lib in libs:
  762. % if lib.language == "c++":
  763. % if lib.build == "all":
  764. $(E) "[INSTALL] Installing lib${lib.name}.a"
  765. $(Q) $(INSTALL) -d $(prefix)/lib
  766. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
  767. % endif
  768. % endif
  769. % endfor
  770. <%def name="install_shared(lang_filter)">\
  771. % for lib in libs:
  772. % if lib.language == lang_filter:
  773. % if lib.build == "all":
  774. ifeq ($(SYSTEM),MINGW32)
  775. $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)"
  776. $(Q) $(INSTALL) -d $(prefix)/lib
  777. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT)
  778. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
  779. else
  780. $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)"
  781. $(Q) $(INSTALL) -d $(prefix)/lib
  782. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT)
  783. ifneq ($(SYSTEM),Darwin)
  784. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so.${settings.version.major}
  785. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
  786. endif
  787. endif
  788. % endif
  789. % endif
  790. % endfor
  791. ifneq ($(SYSTEM),MINGW32)
  792. ifneq ($(SYSTEM),Darwin)
  793. $(Q) ldconfig || true
  794. endif
  795. endif
  796. </%def>
  797. install-shared_c: shared_c strip-shared_c
  798. ${install_shared("c")}
  799. install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c
  800. ${install_shared("c++")}
  801. install-shared_csharp: shared_csharp strip-shared_csharp
  802. ${install_shared("csharp")}
  803. install-plugins: $(PROTOC_PLUGINS)
  804. ifeq ($(SYSTEM),MINGW32)
  805. $(Q) false
  806. else
  807. $(E) "[INSTALL] Installing grpc protoc plugins"
  808. % for tgt in targets:
  809. % if tgt.build == 'protoc':
  810. $(Q) $(INSTALL) -d $(prefix)/bin
  811. $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
  812. % endif
  813. % endfor
  814. endif
  815. install-certs: etc/roots.pem
  816. $(E) "[INSTALL] Installing root certificates"
  817. $(Q) $(INSTALL) -d $(prefix)/share/grpc
  818. $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
  819. verify-install:
  820. ifeq ($(INSTALL_OK),true)
  821. @echo "Your system looks ready to go."
  822. @echo
  823. else
  824. @echo "We couldn't find protoc 3.0.0+ installed on your system. While this"
  825. @echo "won't prevent grpc from working, you won't be able to compile"
  826. @echo "and run any meaningful code with it."
  827. @echo
  828. @echo
  829. @echo "Please download and install protobuf 3.0.0+ from:"
  830. @echo
  831. @echo " https://github.com/google/protobuf/releases"
  832. @echo
  833. @echo "Once you've done so, or if you think this message is in error,"
  834. @echo "you can re-run this check by doing:"
  835. @echo
  836. @echo " make verify-install"
  837. endif
  838. clean:
  839. $(E) "[CLEAN] Cleaning build directories."
  840. $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR)
  841. # The various libraries
  842. % for lib in libs:
  843. ${makelib(lib)}
  844. % endfor
  845. # All of the test targets, and protoc plugins
  846. % for tgt in targets:
  847. ${maketarget(tgt)}
  848. % endfor
  849. <%def name="makelib(lib)">
  850. LIB${lib.name.upper()}_SRC = \\
  851. % for src in lib.src:
  852. ${proto_to_cc(src)} \\
  853. % endfor
  854. % if "public_headers" in lib:
  855. % if lib.language == "c++":
  856. PUBLIC_HEADERS_CXX += \\
  857. % else:
  858. PUBLIC_HEADERS_C += \\
  859. % endif
  860. % for hdr in lib.public_headers:
  861. ${hdr} \\
  862. % endfor
  863. % endif
  864. LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
  865. ## If the library requires OpenSSL with ALPN, let's add some restrictions.
  866. % if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
  867. ifeq ($(NO_SECURE),true)
  868. # You can't build secure libraries if you don't have OpenSSL with ALPN.
  869. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
  870. % if lib.build == "all":
  871. ifeq ($(SYSTEM),MINGW32)
  872. $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error
  873. else
  874. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error
  875. endif
  876. % endif
  877. else
  878. % if lib.language == 'c++':
  879. ifeq ($(NO_PROTOBUF),true)
  880. # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
  881. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
  882. % if lib.build == "all":
  883. ifeq ($(SYSTEM),MINGW32)
  884. $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
  885. else
  886. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
  887. endif
  888. % endif
  889. else
  890. % endif
  891. ifneq ($(OPENSSL_DEP),)
  892. # This is to ensure the embedded OpenSSL is built beforehand, properly
  893. # installing headers to their final destination on the drive. We need this
  894. # otherwise parallel compilation will fail if a source is compiled first.
  895. % for src in lib.src:
  896. ${src}: $(OPENSSL_DEP)
  897. % endfor
  898. endif
  899. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
  900. ## The else here corresponds to the if secure earlier.
  901. % else:
  902. % if lib.language == 'c++':
  903. ifeq ($(NO_PROTOBUF),true)
  904. # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
  905. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
  906. % if lib.build == "all":
  907. ifeq ($(SYSTEM),MINGW32)
  908. $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
  909. else
  910. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
  911. endif
  912. % endif
  913. else
  914. % endif
  915. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP)\
  916. % endif
  917. % if lib.language == 'c++':
  918. $(PROTOBUF_DEP)\
  919. % endif
  920. $(LIB${lib.name.upper()}_OBJS)
  921. $(E) "[AR] Creating $@"
  922. $(Q) mkdir -p `dirname $@`
  923. $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  924. $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
  925. % if lib.get('baselib', False):
  926. % if lib.get('secure', 'check') == 'yes':
  927. $(Q) rm -rf tmp-merge-${lib.name}
  928. $(Q) mkdir tmp-merge-${lib.name}
  929. $(Q) ( cd tmp-merge-${lib.name} ; $(AR) x ../$(LIBDIR)/$(CONFIG)/lib${lib.name}.a )
  930. $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge-${lib.name} ; <%text>ar x ../$${l}</%text> ) ; done
  931. $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/__.SYMDEF*
  932. $(Q) ar rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/*
  933. $(Q) rm -rf tmp-merge-${lib.name}
  934. % endif
  935. % endif
  936. ifeq ($(SYSTEM),Darwin)
  937. $(Q) ranlib $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  938. endif
  939. <%
  940. if lib.language == 'c++':
  941. ld = '$(LDXX)'
  942. else:
  943. ld = '$(LD)'
  944. out_base = '$(LIBDIR)/$(CONFIG)/' + lib.name
  945. out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name
  946. common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
  947. libs = ''
  948. lib_deps = ' $(ZLIB_DEP)'
  949. mingw_libs = ''
  950. mingw_lib_deps = ' $(ZLIB_DEP)'
  951. for dep in lib.get('deps', []):
  952. libs = libs + ' -l' + dep
  953. lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
  954. mingw_libs = mingw_libs + ' -l' + dep + '-imp'
  955. mingw_lib_deps = mingw_lib_deps + '$(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
  956. if lib.get('secure', 'check') == 'yes':
  957. common = common + ' $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS)'
  958. if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
  959. lib_deps = lib_deps + ' $(OPENSSL_DEP)'
  960. mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
  961. if lib.language == 'c++':
  962. common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
  963. %>
  964. % if lib.build == "all":
  965. ifeq ($(SYSTEM),MINGW32)
  966. ${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
  967. $(E) "[LD] Linking $@"
  968. $(Q) mkdir -p `dirname $@`
  969. $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=${out_base}.def -Wl,--out-implib=${out_libbase}-imp.a -o ${out_base}.$(SHARED_EXT) ${common}${mingw_libs}
  970. else
  971. ${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
  972. $(E) "[LD] Linking $@"
  973. $(Q) mkdir -p `dirname $@`
  974. ifeq ($(SYSTEM),Darwin)
  975. $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name lib${lib.name}.$(SHARED_EXT) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
  976. else
  977. $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
  978. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major}
  979. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so
  980. endif
  981. endif
  982. % endif
  983. % if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
  984. ## If the lib was secure, we have to close the Makefile's if that tested
  985. ## the presence of an ALPN-capable OpenSSL.
  986. endif
  987. % endif
  988. % if lib.language == 'c++':
  989. ## If the lib was C++, we have to close the Makefile's if that tested
  990. ## the presence of protobuf 3.0.0+
  991. endif
  992. % endif
  993. % if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
  994. ifneq ($(NO_SECURE),true)
  995. % endif
  996. ifneq ($(NO_DEPS),true)
  997. -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
  998. endif
  999. % if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
  1000. endif
  1001. % endif
  1002. % for src in lib.src:
  1003. % if not proto_re.match(src):
  1004. $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
  1005. % for src2 in lib.src:
  1006. % if proto_re.match(src2):
  1007. ${proto_to_cc(src2)}\
  1008. % endif
  1009. % endfor
  1010. % endif
  1011. % endfor
  1012. </%def>
  1013. <%def name="maketarget(tgt)">
  1014. ${tgt.name.upper()}_SRC = \\
  1015. % for src in tgt.src:
  1016. ${proto_to_cc(src)} \\
  1017. % endfor
  1018. ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
  1019. % if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
  1020. ifeq ($(NO_SECURE),true)
  1021. # You can't build secure targets if you don't have OpenSSL with ALPN.
  1022. $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
  1023. else
  1024. % endif
  1025. ##
  1026. ## We're not trying to add a dependency on building zlib and openssl here,
  1027. ## as it's already done in the libraries. We're assuming that the build
  1028. ## trickles down, and that a secure target requires a secure version of
  1029. ## a library.
  1030. ##
  1031. ## That simplifies the codegen a bit, but prevents a fully defined Makefile.
  1032. ## I can live with that.
  1033. ##
  1034. % if tgt.build == 'protoc' or tgt.language == 'c++':
  1035. ifeq ($(NO_PROTOBUF),true)
  1036. # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+.
  1037. $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
  1038. else
  1039. $(BINDIR)/$(CONFIG)/${tgt.name}: $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
  1040. % else:
  1041. $(BINDIR)/$(CONFIG)/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
  1042. % endif
  1043. % for dep in tgt.deps:
  1044. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  1045. % endfor
  1046. % if tgt.language == "c++":
  1047. ## C++ targets specificies.
  1048. % if tgt.build == 'protoc':
  1049. $(E) "[HOSTLD] Linking $@"
  1050. $(Q) mkdir -p `dirname $@`
  1051. $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(${tgt.name.upper()}_OBJS)\
  1052. % else:
  1053. $(E) "[LD] Linking $@"
  1054. $(Q) mkdir -p `dirname $@`
  1055. $(Q) $(LDXX) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
  1056. % endif
  1057. % if tgt.build == 'test':
  1058. $(GTEST_LIB)\
  1059. % endif
  1060. % else:
  1061. ## C-only targets specificities.
  1062. $(E) "[LD] Linking $@"
  1063. $(Q) mkdir -p `dirname $@`
  1064. $(Q) $(LD) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
  1065. % endif
  1066. % for dep in tgt.deps:
  1067. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  1068. % endfor
  1069. % if tgt.language == "c++":
  1070. % if tgt.build == 'protoc':
  1071. $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
  1072. % else:
  1073. $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
  1074. % endif
  1075. % endif
  1076. % if tgt.build == 'protoc':
  1077. $(HOST_LDLIBS)\
  1078. % else:
  1079. $(LDLIBS)\
  1080. % endif
  1081. % if tgt.build == 'protoc':
  1082. $(HOST_LDLIBS_PROTOC)\
  1083. % elif tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
  1084. $(LDLIBS_SECURE)\
  1085. % endif
  1086. -o $(BINDIR)/$(CONFIG)/${tgt.name}
  1087. % if tgt.build == 'protoc' or tgt.language == 'c++':
  1088. endif
  1089. % endif
  1090. % if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
  1091. endif
  1092. % endif
  1093. % for src in tgt.src:
  1094. $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
  1095. % for dep in tgt.deps:
  1096. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  1097. % endfor
  1098. % endfor
  1099. deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
  1100. % if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
  1101. ifneq ($(NO_SECURE),true)
  1102. % endif
  1103. ifneq ($(NO_DEPS),true)
  1104. -include $(${tgt.name.upper()}_OBJS:.o=.dep)
  1105. endif
  1106. % if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
  1107. endif
  1108. % endif
  1109. </%def>
  1110. .PHONY: all strip tools \
  1111. dep_error openssl_dep_error openssl_dep_message git_update stop \
  1112. buildtests buildtests_c buildtests_cxx \
  1113. test test_c test_cxx \
  1114. install install_c install_cxx \
  1115. install-headers install-headers_c install-headers_cxx \
  1116. install-shared install-shared_c install-shared_cxx \
  1117. install-static install-static_c install-static_cxx \
  1118. strip strip-shared strip-static \
  1119. strip_c strip-shared_c strip-static_c \
  1120. strip_cxx strip-shared_cxx strip-static_cxx \
  1121. dep_c dep_cxx bins_dep_c bins_dep_cxx \
  1122. clean