Makefile.template 36 KB

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