Makefile.template 37 KB

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