Makefile.template 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842
  1. %YAML 1.2
  2. --- |
  3. # GRPC global makefile
  4. # This currently builds C and C++ code.
  5. # This file has been automatically generated from a template file.
  6. # Please look at the templates directory instead.
  7. # This file can be regenerated from the template by running
  8. # tools/buildgen/generate_projects.sh
  9. # Copyright 2015-2016, Google Inc.
  10. # All rights reserved.
  11. #
  12. # Redistribution and use in source and binary forms, with or without
  13. # modification, are permitted provided that the following conditions are
  14. # met:
  15. #
  16. # * Redistributions of source code must retain the above copyright
  17. # notice, this list of conditions and the following disclaimer.
  18. # * Redistributions in binary form must reproduce the above
  19. # copyright notice, this list of conditions and the following disclaimer
  20. # in the documentation and/or other materials provided with the
  21. # distribution.
  22. # * Neither the name of Google Inc. nor the names of its
  23. # contributors may be used to endorse or promote products derived from
  24. # this software without specific prior written permission.
  25. #
  26. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  29. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  30. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  31. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  32. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  33. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  34. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  35. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  36. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. <%!
  38. import re
  39. import os
  40. proto_re = re.compile('(.*)\\.proto')
  41. def proto_to_cc(filename):
  42. m = proto_re.match(filename)
  43. if not m:
  44. return filename
  45. return '$(GENDIR)/' + m.group(1) + '.pb.cc $(GENDIR)/' + m.group(1) + '.grpc.pb.cc'
  46. sources_that_need_openssl = set()
  47. sources_that_don_t_need_openssl = set()
  48. %>
  49. comma := ,
  50. # Basic platform detection
  51. HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
  52. ifeq ($(SYSTEM),)
  53. SYSTEM = $(HOST_SYSTEM)
  54. endif
  55. ifeq ($(SYSTEM),MSYS)
  56. SYSTEM = MINGW32
  57. endif
  58. ifeq ($(SYSTEM),MINGW64)
  59. SYSTEM = MINGW32
  60. endif
  61. MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
  62. ifndef BUILDDIR
  63. BUILDDIR_ABSOLUTE = $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))
  64. else
  65. BUILDDIR_ABSOLUTE = $(abspath $(BUILDDIR))
  66. endif
  67. HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false)
  68. HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false)
  69. HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false)
  70. ifeq ($(HAS_CC),true)
  71. DEFAULT_CC = cc
  72. DEFAULT_CXX = c++
  73. else
  74. ifeq ($(HAS_GCC),true)
  75. DEFAULT_CC = gcc
  76. DEFAULT_CXX = g++
  77. else
  78. ifeq ($(HAS_CLANG),true)
  79. DEFAULT_CC = clang
  80. DEFAULT_CXX = clang++
  81. else
  82. DEFAULT_CC = no_c_compiler
  83. DEFAULT_CXX = no_c++_compiler
  84. endif
  85. endif
  86. endif
  87. BINDIR = $(BUILDDIR_ABSOLUTE)/bins
  88. OBJDIR = $(BUILDDIR_ABSOLUTE)/objs
  89. LIBDIR = $(BUILDDIR_ABSOLUTE)/libs
  90. GENDIR = $(BUILDDIR_ABSOLUTE)/gens
  91. # Configurations
  92. % for name, args in configs.iteritems():
  93. VALID_CONFIG_${name} = 1
  94. % if args.get('compile_the_world', False):
  95. REQUIRE_CUSTOM_LIBRARIES_${name} = 1
  96. % endif
  97. % for tool, default in [('CC', 'CC'), ('CXX', 'CXX'), ('LD', 'CC'), ('LDXX', 'CXX')]:
  98. ${tool}_${name} = ${args.get(tool, '$(DEFAULT_%s)' % default)}
  99. % endfor
  100. % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES']:
  101. % if args.get(arg, None) is not None:
  102. ${arg}_${name} = ${args.get(arg)}
  103. % endif
  104. % endfor
  105. % if args.get('timeout_multiplier', 1) != 1:
  106. DEFINES_${name} += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=${args.timeout_multiplier}
  107. % endif
  108. % endfor
  109. # General settings.
  110. # You may want to change these depending on your system.
  111. prefix ?= /usr/local
  112. PROTOC ?= protoc
  113. DTRACE ?= dtrace
  114. CONFIG ?= opt
  115. # Doing X ?= Y is the same as:
  116. # ifeq ($(origin X), undefined)
  117. # X = Y
  118. # endif
  119. # but some variables, such as CC, CXX, LD or AR, have defaults.
  120. # So instead of using ?= on them, we need to check their origin.
  121. # See:
  122. # https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
  123. # https://www.gnu.org/software/make/manual/html_node/Flavors.html#index-_003f_003d
  124. # https://www.gnu.org/software/make/manual/html_node/Origin-Function.html
  125. ifeq ($(origin CC), default)
  126. CC = $(CC_$(CONFIG))
  127. endif
  128. ifeq ($(origin CXX), default)
  129. CXX = $(CXX_$(CONFIG))
  130. endif
  131. ifeq ($(origin LD), default)
  132. LD = $(LD_$(CONFIG))
  133. endif
  134. LDXX ?= $(LDXX_$(CONFIG))
  135. ifeq ($(origin AR), default)
  136. AR = ar
  137. endif
  138. ifeq ($(SYSTEM),Linux)
  139. STRIP ?= strip --strip-unneeded
  140. else
  141. ifeq ($(SYSTEM),Darwin)
  142. STRIP ?= strip -x
  143. else
  144. STRIP ?= strip
  145. endif
  146. endif
  147. INSTALL ?= install
  148. RM ?= rm -f
  149. PKG_CONFIG ?= pkg-config
  150. ifndef VALID_CONFIG_$(CONFIG)
  151. $(error Invalid CONFIG value '$(CONFIG)')
  152. endif
  153. ifeq ($(SYSTEM),Linux)
  154. TMPOUT = /dev/null
  155. else
  156. TMPOUT = `mktemp /tmp/test-out-XXXXXX`
  157. endif
  158. # Detect if we can use C++11
  159. CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc
  160. HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false)
  161. CHECK_NO_SHIFT_NEGATIVE_VALUE_CMD = $(CC) -std=c99 -Werror -Wno-shift-negative-value -o $(TMPOUT) -c test/build/empty.c
  162. HAS_NO_SHIFT_NEGATIVE_VALUE = $(shell $(CHECK_NO_SHIFT_NEGATIVE_VALUE_CMD) 2> /dev/null && echo true || echo false)
  163. ifeq ($(HAS_NO_SHIFT_NEGATIVE_VALUE),true)
  164. W_NO_SHIFT_NEGATIVE_VALUE=-Wno-shift-negative-value
  165. endif
  166. # The HOST compiler settings are used to compile the protoc plugins.
  167. # In most cases, you won't have to change anything, but if you are
  168. # cross-compiling, you can override these variables from GNU make's
  169. # command line: make CC=cross-gcc HOST_CC=gcc
  170. HOST_CC ?= $(CC)
  171. HOST_CXX ?= $(CXX)
  172. HOST_LD ?= $(LD)
  173. HOST_LDXX ?= $(LDXX)
  174. ifdef EXTRA_DEFINES
  175. DEFINES += $(EXTRA_DEFINES)
  176. endif
  177. CFLAGS += -std=c99 -Wsign-conversion -Wconversion -Wshadow
  178. ifeq ($(HAS_CXX11),true)
  179. CXXFLAGS += -std=c++11
  180. else
  181. CXXFLAGS += -std=c++0x
  182. endif
  183. CFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
  184. CXXFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
  185. LDFLAGS += -g
  186. CPPFLAGS += $(CPPFLAGS_$(CONFIG))
  187. CFLAGS += $(CFLAGS_$(CONFIG))
  188. CXXFLAGS += $(CXXFLAGS_$(CONFIG))
  189. DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
  190. LDFLAGS += $(LDFLAGS_$(CONFIG))
  191. ifneq ($(SYSTEM),MINGW32)
  192. PIC_CPPFLAGS = -fPIC
  193. CPPFLAGS += -fPIC
  194. LDFLAGS += -fPIC
  195. endif
  196. INCLUDES = . include $(GENDIR)
  197. LDFLAGS += -Llibs/$(CONFIG)
  198. ifeq ($(SYSTEM),Darwin)
  199. ifneq ($(wildcard /usr/local/ssl/include),)
  200. INCLUDES += /usr/local/ssl/include
  201. endif
  202. ifneq ($(wildcard /opt/local/include),)
  203. INCLUDES += /opt/local/include
  204. endif
  205. ifneq ($(wildcard /usr/local/include),)
  206. INCLUDES += /usr/local/include
  207. endif
  208. LIBS = m z
  209. ifneq ($(wildcard /usr/local/ssl/lib),)
  210. LDFLAGS += -L/usr/local/ssl/lib
  211. endif
  212. ifneq ($(wildcard /opt/local/lib),)
  213. LDFLAGS += -L/opt/local/lib
  214. endif
  215. ifneq ($(wildcard /usr/local/lib),)
  216. LDFLAGS += -L/usr/local/lib
  217. endif
  218. endif
  219. ifeq ($(SYSTEM),Linux)
  220. LIBS = rt m pthread
  221. LDFLAGS += -pthread
  222. endif
  223. ifeq ($(SYSTEM),MINGW32)
  224. LIBS = m pthread
  225. LDFLAGS += -pthread
  226. endif
  227. GTEST_LIB = -Ithird_party/googletest/include -Ithird_party/googletest third_party/googletest/src/gtest-all.cc
  228. GTEST_LIB += -lgflags
  229. ifeq ($(V),1)
  230. E = @:
  231. Q =
  232. else
  233. E = @echo
  234. Q = @
  235. endif
  236. VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build}
  237. CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
  238. CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
  239. LDFLAGS += $(ARCH_FLAGS)
  240. LDLIBS += $(addprefix -l, $(LIBS))
  241. LDLIBSXX += $(addprefix -l, $(LIBSXX))
  242. HOST_CPPFLAGS = $(CPPFLAGS)
  243. HOST_CFLAGS = $(CFLAGS)
  244. HOST_CXXFLAGS = $(CXXFLAGS)
  245. HOST_LDFLAGS = $(LDFLAGS)
  246. HOST_LDLIBS = $(LDLIBS)
  247. # These are automatically computed variables.
  248. # There shouldn't be any need to change anything from now on.
  249. -include cache.mk
  250. CACHE_MK =
  251. HAS_PKG_CONFIG ?= $(shell command -v $(PKG_CONFIG) >/dev/null 2>&1 && echo true || echo false)
  252. ifeq ($(HAS_PKG_CONFIG), true)
  253. CACHE_MK += HAS_PKG_CONFIG = true,
  254. endif
  255. PC_TEMPLATE = prefix=$(prefix),\
  256. exec_prefix=${'\$${prefix}'},\
  257. includedir=${'\$${prefix}'}/include,\
  258. libdir=${'\$${exec_prefix}'}/lib,\
  259. ,\
  260. Name: $(PC_NAME),\
  261. Description: $(PC_DESCRIPTION),\
  262. Version: $(VERSION),\
  263. Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\
  264. Requires.private: $(PC_REQUIRES_PRIVATE),\
  265. Libs: -L${'\$${libdir}'} $(PC_LIB),\
  266. Libs.private: $(PC_LIBS_PRIVATE)
  267. # gpr .pc file
  268. PC_NAME = gRPC Portable Runtime
  269. PC_DESCRIPTION = gRPC Portable Runtime
  270. PC_CFLAGS = -pthread
  271. PC_REQUIRES_PRIVATE =
  272. PC_LIBS_PRIVATE = -lpthread
  273. PC_LIB = -lgpr
  274. ifneq ($(SYSTEM),Darwin)
  275. PC_LIBS_PRIVATE += -lrt
  276. endif
  277. GPR_PC_FILE := $(PC_TEMPLATE)
  278. ifeq ($(SYSTEM),MINGW32)
  279. SHARED_EXT = dll
  280. endif
  281. ifeq ($(SYSTEM),Darwin)
  282. SHARED_EXT = dylib
  283. endif
  284. ifeq ($(SHARED_EXT),)
  285. SHARED_EXT = so.$(VERSION)
  286. endif
  287. ifeq ($(wildcard .git),)
  288. IS_GIT_FOLDER = false
  289. else
  290. IS_GIT_FOLDER = true
  291. endif
  292. ifeq ($(HAS_PKG_CONFIG),true)
  293. OPENSSL_ALPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.2 openssl
  294. OPENSSL_NPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.1 openssl
  295. ZLIB_CHECK_CMD = $(PKG_CONFIG) --exists zlib
  296. PROTOBUF_CHECK_CMD = $(PKG_CONFIG) --atleast-version=3.0.0-alpha-3 protobuf
  297. else # HAS_PKG_CONFIG
  298. ifeq ($(SYSTEM),MINGW32)
  299. OPENSSL_LIBS = ssl32 eay32
  300. else
  301. OPENSSL_LIBS = ssl crypto
  302. endif
  303. OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
  304. OPENSSL_NPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/openssl-npn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
  305. ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
  306. PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
  307. endif # HAS_PKG_CONFIG
  308. PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
  309. PROTOC_CHECK_CMD = which protoc > /dev/null
  310. PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3
  311. DTRACE_CHECK_CMD = which dtrace > /dev/null
  312. SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS)
  313. ZOOKEEPER_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zookeeper.c $(LDFLAGS) -lzookeeper_mt
  314. ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
  315. HAS_SYSTEM_PERFTOOLS ?= $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
  316. ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
  317. DEFINES += GRPC_HAVE_PERFTOOLS
  318. LIBS += profiler
  319. CACHE_MK += HAS_SYSTEM_PERFTOOLS = true,
  320. endif
  321. endif
  322. HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
  323. ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
  324. HAS_SYSTEM_OPENSSL_ALPN ?= $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
  325. ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
  326. HAS_SYSTEM_OPENSSL_NPN = true
  327. CACHE_MK += HAS_SYSTEM_OPENSSL_ALPN = true,
  328. else
  329. HAS_SYSTEM_OPENSSL_NPN ?= $(shell $(OPENSSL_NPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
  330. endif
  331. ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
  332. CACHE_MK += HAS_SYSTEM_OPENSSL_NPN = true,
  333. endif
  334. HAS_SYSTEM_ZLIB ?= $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
  335. ifeq ($(HAS_SYSTEM_ZLIB),true)
  336. CACHE_MK += HAS_SYSTEM_ZLIB = true,
  337. endif
  338. HAS_SYSTEM_PROTOBUF ?= $(HAS_SYSTEM_PROTOBUF_VERIFY)
  339. ifeq ($(HAS_SYSTEM_PROTOBUF),true)
  340. CACHE_MK += HAS_SYSTEM_PROTOBUF = true,
  341. endif
  342. else
  343. # override system libraries if the config requires a custom compiled library
  344. HAS_SYSTEM_OPENSSL_ALPN = false
  345. HAS_SYSTEM_OPENSSL_NPN = false
  346. HAS_SYSTEM_ZLIB = false
  347. HAS_SYSTEM_PROTOBUF = false
  348. endif
  349. HAS_PROTOC ?= $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
  350. ifeq ($(HAS_PROTOC),true)
  351. CACHE_MK += HAS_PROTOC = true,
  352. HAS_VALID_PROTOC ?= $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false)
  353. ifeq ($(HAS_VALID_PROTOC),true)
  354. CACHE_MK += HAS_VALID_PROTOC = true,
  355. endif
  356. else
  357. HAS_VALID_PROTOC = false
  358. endif
  359. # Check for Systemtap (https://sourceware.org/systemtap/), first by making sure <sys/sdt.h> is present
  360. # in the system and secondly by checking for the "dtrace" binary (on Linux, this is part of the Systemtap
  361. # distribution. It's part of the base system on BSD/Solaris machines).
  362. ifndef HAS_SYSTEMTAP
  363. HAS_SYSTEMTAP_HEADERS = $(shell $(SYSTEMTAP_HEADERS_CHECK_CMD) 2> /dev/null && echo true || echo false)
  364. HAS_DTRACE = $(shell $(DTRACE_CHECK_CMD) 2> /dev/null && echo true || echo false)
  365. HAS_SYSTEMTAP = false
  366. ifeq ($(HAS_SYSTEMTAP_HEADERS),true)
  367. ifeq ($(HAS_DTRACE),true)
  368. HAS_SYSTEMTAP = true
  369. endif
  370. endif
  371. endif
  372. ifeq ($(HAS_SYSTEMTAP),true)
  373. CACHE_MK += HAS_SYSTEMTAP = true,
  374. endif
  375. HAS_ZOOKEEPER = $(shell $(ZOOKEEPER_CHECK_CMD) 2> /dev/null && echo true || echo false)
  376. # Note that for testing purposes, one can do:
  377. # make HAS_EMBEDDED_OPENSSL_ALPN=false
  378. # to emulate the fact we do not have OpenSSL in the third_party folder.
  379. ifeq ($(wildcard third_party/boringssl/include/openssl/ssl.h),)
  380. HAS_EMBEDDED_OPENSSL_ALPN = false
  381. else
  382. HAS_EMBEDDED_OPENSSL_ALPN = true
  383. endif
  384. ifeq ($(wildcard third_party/zlib/zlib.h),)
  385. HAS_EMBEDDED_ZLIB = false
  386. else
  387. HAS_EMBEDDED_ZLIB = true
  388. endif
  389. ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
  390. HAS_EMBEDDED_PROTOBUF = false
  391. ifneq ($(HAS_VALID_PROTOC),true)
  392. NO_PROTOC = true
  393. endif
  394. else
  395. HAS_EMBEDDED_PROTOBUF = true
  396. endif
  397. PC_REQUIRES_GRPC = gpr
  398. PC_LIBS_GRPC =
  399. ifeq ($(HAS_SYSTEM_ZLIB),false)
  400. ifeq ($(HAS_EMBEDDED_ZLIB), true)
  401. EMBED_ZLIB ?= true
  402. else
  403. DEP_MISSING += zlib
  404. EMBED_ZLIB ?= broken
  405. endif
  406. else
  407. EMBED_ZLIB ?= false
  408. endif
  409. ifeq ($(EMBED_ZLIB),true)
  410. ZLIB_DEP = $(LIBDIR)/$(CONFIG)/libz.a
  411. ZLIB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libz.a
  412. CPPFLAGS += -Ithird_party/zlib
  413. LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib
  414. else
  415. ifeq ($(HAS_PKG_CONFIG),true)
  416. CPPFLAGS += $(shell $(PKG_CONFIG) --cflags zlib)
  417. LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L zlib)
  418. LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l zlib))
  419. PC_REQUIRES_GRPC += zlib
  420. else
  421. PC_LIBS_GRPC += -lz
  422. LIBS += z
  423. endif
  424. endif
  425. OPENSSL_PKG_CONFIG = false
  426. PC_REQUIRES_SECURE =
  427. PC_LIBS_SECURE =
  428. ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
  429. EMBED_OPENSSL ?= false
  430. NO_SECURE ?= false
  431. else # HAS_SYSTEM_OPENSSL_ALPN=false
  432. ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true)
  433. EMBED_OPENSSL ?= true
  434. NO_SECURE ?= false
  435. else # HAS_EMBEDDED_OPENSSL_ALPN=false
  436. ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
  437. EMBED_OPENSSL ?= false
  438. NO_SECURE ?= false
  439. else
  440. NO_SECURE ?= true
  441. endif # HAS_SYSTEM_OPENSSL_NPN=true
  442. endif # HAS_EMBEDDED_OPENSSL_ALPN
  443. endif # HAS_SYSTEM_OPENSSL_ALPN
  444. OPENSSL_DEP :=
  445. OPENSSL_MERGE_LIBS :=
  446. ifeq ($(NO_SECURE),false)
  447. ifeq ($(EMBED_OPENSSL),true)
  448. OPENSSL_DEP += $(LIBDIR)/$(CONFIG)/libboringssl.a
  449. OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/libboringssl.a
  450. # need to prefix these to ensure overriding system libraries
  451. CPPFLAGS := -Ithird_party/boringssl/include $(CPPFLAGS)
  452. else # EMBED_OPENSSL=false
  453. ifeq ($(HAS_PKG_CONFIG),true)
  454. OPENSSL_PKG_CONFIG = true
  455. PC_REQUIRES_SECURE = openssl
  456. CPPFLAGS := $(shell $(PKG_CONFIG) --cflags openssl) $(CPPFLAGS)
  457. LDFLAGS_OPENSSL_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L openssl)
  458. ifeq ($(SYSTEM),Linux)
  459. ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),)
  460. LDFLAGS_OPENSSL_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L openssl | sed s/L/Wl,-rpath,/)
  461. endif # LDFLAGS_OPENSSL_PKG_CONFIG=''
  462. endif # System=Linux
  463. LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS)
  464. else # HAS_PKG_CONFIG=false
  465. LIBS_SECURE = $(OPENSSL_LIBS)
  466. endif # HAS_PKG_CONFIG
  467. ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true)
  468. CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0
  469. LIBS_SECURE = $(OPENSSL_LIBS)
  470. endif # HAS_SYSTEM_OPENSSL_NPN
  471. PC_LIBS_SECURE = $(addprefix -l, $(LIBS_SECURE))
  472. endif # EMBED_OPENSSL
  473. endif # NO_SECURE
  474. ifeq ($(OPENSSL_PKG_CONFIG),true)
  475. LDLIBS_SECURE += $(shell $(PKG_CONFIG) --libs-only-l openssl)
  476. else
  477. LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
  478. endif
  479. # grpc .pc file
  480. PC_NAME = gRPC
  481. PC_DESCRIPTION = high performance general RPC framework
  482. PC_CFLAGS =
  483. PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC) $(PC_REQUIRES_SECURE)
  484. PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) $(PC_LIBS_SECURE)
  485. PC_LIB = -lgrpc
  486. GRPC_PC_FILE := $(PC_TEMPLATE)
  487. # gprc_unsecure .pc file
  488. PC_NAME = gRPC unsecure
  489. PC_DESCRIPTION = high performance general RPC framework without SSL
  490. PC_CFLAGS =
  491. PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC)
  492. PC_LIBS_PRIVATE = $(PC_LIBS_GRPC)
  493. PC_LIB = -lgrpc
  494. GRPC_UNSECURE_PC_FILE := $(PC_TEMPLATE)
  495. # gprc_zookeeper .pc file
  496. PC_NAME = gRPC zookeeper
  497. PC_DESCRIPTION = gRPC's zookeeper plugin
  498. PC_CFLAGS =
  499. PC_REQUIRES_PRIVATE =
  500. PC_LIBS_PRIVATE = -lzookeeper_mt
  501. GRPC_ZOOKEEPER_PC_FILE := $(PC_TEMPLATE)
  502. PROTOBUF_PKG_CONFIG = false
  503. PC_REQUIRES_GRPCXX =
  504. PC_LIBS_GRPCXX =
  505. CPPFLAGS := -Ithird_party/googletest/include $(CPPFLAGS)
  506. ifeq ($(HAS_SYSTEM_PROTOBUF),true)
  507. ifeq ($(HAS_PKG_CONFIG),true)
  508. PROTOBUF_PKG_CONFIG = true
  509. PC_REQUIRES_GRPCXX = protobuf
  510. CPPFLAGS := $(shell $(PKG_CONFIG) --cflags protobuf) $(CPPFLAGS)
  511. LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L protobuf)
  512. ifeq ($(SYSTEM),Linux)
  513. ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),)
  514. LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L protobuf | sed s/L/Wl,-rpath,/)
  515. endif
  516. endif
  517. else
  518. PC_LIBS_GRPCXX = -lprotobuf
  519. endif
  520. else
  521. ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
  522. PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
  523. CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
  524. LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
  525. PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
  526. else
  527. NO_PROTOBUF = true
  528. endif
  529. endif
  530. LIBS_PROTOBUF = protobuf
  531. LIBS_PROTOC = protoc protobuf
  532. HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
  533. ifeq ($(PROTOBUF_PKG_CONFIG),true)
  534. LDLIBS_PROTOBUF += $(shell $(PKG_CONFIG) --libs-only-l protobuf)
  535. else
  536. LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
  537. endif
  538. # grpc++ .pc file
  539. PC_NAME = gRPC++
  540. PC_DESCRIPTION = C++ wrapper for gRPC
  541. PC_CFLAGS =
  542. PC_REQUIRES_PRIVATE = grpc $(PC_REQUIRES_GRPCXX)
  543. PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
  544. PC_LIB = -lgrpc++
  545. GRPCXX_PC_FILE := $(PC_TEMPLATE)
  546. # grpc++_unsecure .pc file
  547. PC_NAME = gRPC++ unsecure
  548. PC_DESCRIPTION = C++ wrapper for gRPC without SSL
  549. PC_CFLAGS =
  550. PC_REQUIRES_PRIVATE = grpc_unsecure $(PC_REQUIRES_GRPCXX)
  551. PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
  552. PC_LIB = -lgrpc++
  553. GRPCXX_UNSECURE_PC_FILE := $(PC_TEMPLATE)
  554. ifeq ($(MAKECMDGOALS),clean)
  555. NO_DEPS = true
  556. endif
  557. INSTALL_OK = false
  558. ifeq ($(HAS_VALID_PROTOC),true)
  559. ifeq ($(HAS_SYSTEM_PROTOBUF_VERIFY),true)
  560. INSTALL_OK = true
  561. endif
  562. endif
  563. .SECONDARY = %.pb.h %.pb.cc
  564. PROTOC_PLUGINS =\
  565. % for tgt in targets:
  566. % if tgt.build == 'protoc':
  567. $(BINDIR)/$(CONFIG)/${tgt.name}\
  568. % endif
  569. % endfor
  570. ifeq ($(DEP_MISSING),)
  571. all: static shared plugins\
  572. % for tgt in targets:
  573. % if tgt.build == 'all':
  574. $(BINDIR)/$(CONFIG)/${tgt.name}\
  575. % endif
  576. % endfor
  577. dep_error:
  578. @echo "You shouldn't see this message - all of your dependencies are correct."
  579. else
  580. all: dep_error git_update stop
  581. dep_error:
  582. @echo
  583. @echo "DEPENDENCY ERROR"
  584. @echo
  585. @echo "You are missing system dependencies that are essential to build grpc,"
  586. @echo "and the third_party directory doesn't have them:"
  587. @echo
  588. @echo " $(DEP_MISSING)"
  589. @echo
  590. @echo "Installing the development packages for your system will solve"
  591. @echo "this issue. Please consult INSTALL to get more information."
  592. @echo
  593. @echo "If you need information about why these tests failed, run:"
  594. @echo
  595. @echo " make run_dep_checks"
  596. @echo
  597. endif
  598. git_update:
  599. ifeq ($(IS_GIT_FOLDER),true)
  600. @echo "Additionally, since you are in a git clone, you can download the"
  601. @echo "missing dependencies in third_party by running the following command:"
  602. @echo
  603. @echo " git submodule update --init"
  604. @echo
  605. endif
  606. openssl_dep_error: openssl_dep_message git_update stop
  607. protobuf_dep_error: protobuf_dep_message git_update stop
  608. protoc_dep_error: protoc_dep_message git_update stop
  609. openssl_dep_message:
  610. @echo
  611. @echo "DEPENDENCY ERROR"
  612. @echo
  613. @echo "The target you are trying to run requires OpenSSL."
  614. @echo "Your system doesn't have it, and neither does the third_party directory."
  615. @echo
  616. @echo "Please consult INSTALL to get more information."
  617. @echo
  618. @echo "If you need information about why these tests failed, run:"
  619. @echo
  620. @echo " make run_dep_checks"
  621. @echo
  622. protobuf_dep_message:
  623. @echo
  624. @echo "DEPENDENCY ERROR"
  625. @echo
  626. @echo "The target you are trying to run requires protobuf 3.0.0+"
  627. @echo "Your system doesn't have it, and neither does the third_party directory."
  628. @echo
  629. @echo "Please consult INSTALL to get more information."
  630. @echo
  631. @echo "If you need information about why these tests failed, run:"
  632. @echo
  633. @echo " make run_dep_checks"
  634. @echo
  635. protoc_dep_message:
  636. @echo
  637. @echo "DEPENDENCY ERROR"
  638. @echo
  639. @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
  640. @echo "Your system doesn't have it, and neither does the third_party directory."
  641. @echo
  642. @echo "Please consult INSTALL to get more information."
  643. @echo
  644. @echo "If you need information about why these tests failed, run:"
  645. @echo
  646. @echo " make run_dep_checks"
  647. @echo
  648. systemtap_dep_error:
  649. @echo
  650. @echo "DEPENDENCY ERROR"
  651. @echo
  652. @echo "Under the '$(CONFIG)' configutation, the target you are trying "
  653. @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other "
  654. @echo "platforms such as Solaris and *BSD). "
  655. @echo
  656. @echo "Please consult INSTALL to get more information."
  657. @echo
  658. stop:
  659. @false
  660. % for tgt in targets:
  661. ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
  662. % endfor
  663. run_dep_checks:
  664. $(OPENSSL_ALPN_CHECK_CMD) || true
  665. $(OPENSSL_NPN_CHECK_CMD) || true
  666. $(ZLIB_CHECK_CMD) || true
  667. $(PERFTOOLS_CHECK_CMD) || true
  668. $(PROTOBUF_CHECK_CMD) || true
  669. $(PROTOC_CHECK_VERSION_CMD) || true
  670. $(ZOOKEEPER_CHECK_CMD) || true
  671. third_party/protobuf/configure:
  672. $(E) "[AUTOGEN] Preparing protobuf"
  673. $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
  674. $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
  675. $(E) "[MAKE] Building protobuf"
  676. $(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g $(PROTOBUF_LDFLAGS_EXTRA)" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g $(PROTOBUF_CPPFLAGS_EXTRA)" ./configure --disable-shared --enable-static)
  677. $(Q)$(MAKE) -C third_party/protobuf clean
  678. $(Q)$(MAKE) -C third_party/protobuf
  679. $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
  680. $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
  681. $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
  682. $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
  683. $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
  684. static: static_c static_cxx
  685. static_c: pc_c pc_c_unsecure cache.mk pc_gpr pc_c_zookeeper\
  686. % for lib in libs:
  687. % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
  688. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  689. % endif
  690. % endfor
  691. static_zookeeper_libs
  692. static_cxx: pc_cxx pc_cxx_unsecure pc_gpr cache.mk \
  693. % for lib in libs:
  694. % if lib.build == 'all' and lib.language == 'c++':
  695. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  696. % endif
  697. % endfor
  698. shared: shared_c shared_cxx
  699. shared_c: pc_c pc_c_unsecure pc_gpr cache.mk pc_c_zookeeper\
  700. % for lib in libs:
  701. % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
  702. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
  703. % endif
  704. % endfor
  705. shared_zookeeper_libs
  706. shared_cxx: pc_cxx pc_cxx_unsecure cache.mk\
  707. % for lib in libs:
  708. % if lib.build == 'all' and lib.language == 'c++':
  709. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
  710. % endif
  711. % endfor
  712. shared_csharp: shared_c \
  713. % for lib in libs:
  714. % if lib.build == 'all' and lib.language == 'csharp':
  715. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
  716. % endif
  717. % endfor
  718. ifeq ($(HAS_ZOOKEEPER),true)
  719. static_zookeeper_libs:\
  720. % for lib in libs:
  721. % if lib.build == 'all' and lib.language == 'c' and 'zookeeper' in lib.get('external_deps', []):
  722. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  723. % endif
  724. % endfor
  725. shared_zookeeper_libs:\
  726. % for lib in libs:
  727. % if lib.build == 'all' and lib.language == 'c' and 'zookeeper' in lib.get('external_deps', []):
  728. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
  729. % endif
  730. % endfor
  731. else
  732. static_zookeeper_libs:
  733. shared_zookeeper_libs:
  734. endif
  735. grpc_csharp_ext: shared_csharp
  736. plugins: $(PROTOC_PLUGINS)
  737. privatelibs: privatelibs_c privatelibs_cxx
  738. privatelibs_c: \
  739. % for lib in libs:
  740. % if lib.build == 'private' and lib.language == 'c' and not lib.get('external_deps', None) and not lib.boringssl:
  741. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  742. % endif
  743. % endfor
  744. pc_gpr: $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc
  745. pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc
  746. pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc
  747. ifeq ($(HAS_ZOOKEEPER),true)
  748. pc_c_zookeeper: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_zookeeper.pc
  749. else
  750. pc_c_zookeeper:
  751. endif
  752. pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc
  753. pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc
  754. privatelibs_cxx: \
  755. % for lib in libs:
  756. % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None):
  757. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  758. % endif
  759. % endfor
  760. ifeq ($(HAS_ZOOKEEPER),true)
  761. privatelibs_zookeeper: \
  762. % for lib in libs:
  763. % if lib.build == 'private' and lib.language == 'c++' and zookeeper in lib.get('external_deps', []):
  764. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  765. % endif
  766. % endfor
  767. else
  768. privatelibs_zookeeper:
  769. endif
  770. buildtests: buildtests_c buildtests_cxx buildtests_zookeeper
  771. buildtests_c: privatelibs_c <%text>\</%text>
  772. % for tgt in targets:
  773. % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None):
  774. $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
  775. % endif
  776. % endfor
  777. buildtests_cxx: buildtests_zookeeper privatelibs_cxx <%text>\</%text>
  778. % for tgt in targets:
  779. % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None):
  780. $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
  781. % endif
  782. % endfor
  783. ifeq ($(HAS_ZOOKEEPER),true)
  784. buildtests_zookeeper: privatelibs_zookeeper <%text>\</%text>
  785. % for tgt in targets:
  786. % if tgt.build == 'test' and tgt.language == 'c++' and 'zookeeper' in tgt.get('external_deps', []):
  787. $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
  788. % endif
  789. % endfor
  790. else
  791. buildtests_zookeeper:
  792. endif
  793. test: test_c test_cxx test_zookeeper
  794. flaky_test: flaky_test_c flaky_test_cxx flaky_test_zookeeper
  795. test_c: buildtests_c
  796. % for tgt in targets:
  797. % if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++' and not tgt.get('flaky', False) and not tgt.get('external_deps', None):
  798. $(E) "[RUN] Testing ${tgt.name}"
  799. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  800. % endif
  801. % endfor
  802. flaky_test_c: buildtests_c
  803. % for tgt in targets:
  804. % if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++' and tgt.get('flaky', False) and not tgt.get('external_deps', None):
  805. $(E) "[RUN] Testing ${tgt.name}"
  806. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  807. % endif
  808. % endfor
  809. test_cxx: test_zookeeper buildtests_cxx
  810. % for tgt in targets:
  811. % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and not tgt.get('flaky', False) and not tgt.get('external_deps', None):
  812. $(E) "[RUN] Testing ${tgt.name}"
  813. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  814. % endif
  815. % endfor
  816. flaky_test_cxx: buildtests_cxx
  817. % for tgt in targets:
  818. % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and tgt.get('flaky', False) and not tgt.get('external_deps', None):
  819. $(E) "[RUN] Testing ${tgt.name}"
  820. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  821. % endif
  822. % endfor
  823. ifeq ($(HAS_ZOOKEEPER),true)
  824. test_zookeeper: buildtests_zookeeper
  825. % for tgt in targets:
  826. % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and not tgt.get('flaky', False) and 'zookeeper' in tgt.get('external_deps', []):
  827. $(E) "[RUN] Testing ${tgt.name}"
  828. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  829. % endif
  830. % endfor
  831. flaky_test_zookeeper: buildtests_zookeeper
  832. % for tgt in targets:
  833. % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and tgt.get('flaky', False) and 'zookeeper' in tgt.get('external_deps', []):
  834. $(E) "[RUN] Testing ${tgt.name}"
  835. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  836. % endif
  837. % endfor
  838. else
  839. test_zookeeper:
  840. flaky_test_zookeeper:
  841. endif
  842. test_python: static_c
  843. $(E) "[RUN] Testing python code"
  844. $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
  845. tools: tools_c tools_cxx
  846. tools_c: privatelibs_c\
  847. % for tgt in targets:
  848. % if tgt.build == 'tool' and not tgt.language=='c++':
  849. $(BINDIR)/$(CONFIG)/${tgt.name}\
  850. % endif
  851. % endfor
  852. tools_cxx: privatelibs_cxx\
  853. % for tgt in targets:
  854. % if tgt.build == 'tool' and tgt.language=='c++':
  855. $(BINDIR)/$(CONFIG)/${tgt.name}\
  856. % endif
  857. % endfor
  858. buildbenchmarks: privatelibs\
  859. % for tgt in targets:
  860. % if tgt.build == 'benchmark':
  861. $(BINDIR)/$(CONFIG)/${tgt.name}\
  862. % endif
  863. % endfor
  864. benchmarks: buildbenchmarks
  865. strip: strip-static strip-shared
  866. strip-static: strip-static_c strip-static_cxx
  867. strip-shared: strip-shared_c strip-shared_cxx
  868. # TODO(nnoble): the strip target is stripping in-place, instead
  869. # of copying files in a temporary folder.
  870. # This prevents proper debugging after running make install.
  871. strip-static_c: static_c
  872. ifeq ($(CONFIG),opt)
  873. % for lib in libs:
  874. % if lib.language == "c":
  875. % if lib.build == "all":
  876. % if not lib.get('external_deps', None):
  877. $(E) "[STRIP] Stripping lib${lib.name}.a"
  878. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  879. % endif
  880. % endif
  881. % endif
  882. % endfor
  883. ifeq ($(HAS_ZOOKEEPER),true)
  884. % for lib in libs:
  885. % if lib.language == "c":
  886. % if lib.build == "all":
  887. % if 'zookeeper' in lib.get('external_deps', []):
  888. $(E) "[STRIP] Stripping lib${lib.name}.a"
  889. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  890. % endif
  891. % endif
  892. % endif
  893. % endfor
  894. endif
  895. endif
  896. strip-static_cxx: static_cxx
  897. ifeq ($(CONFIG),opt)
  898. % for lib in libs:
  899. % if lib.language == "c++":
  900. % if lib.build == "all":
  901. $(E) "[STRIP] Stripping lib${lib.name}.a"
  902. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  903. % endif
  904. % endif
  905. % endfor
  906. endif
  907. strip-shared_c: shared_c
  908. ifeq ($(CONFIG),opt)
  909. % for lib in libs:
  910. % if lib.language == "c":
  911. % if lib.build == "all":
  912. % if not lib.get('external_deps', None):
  913. $(E) "[STRIP] Stripping lib${lib.name}.so"
  914. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
  915. % endif
  916. % endif
  917. % endif
  918. % endfor
  919. ifeq ($(HAS_ZOOKEEPER),true)
  920. % for lib in libs:
  921. % if lib.language == "c":
  922. % if lib.build == "all":
  923. % if 'zookeeper' in lib.get('external_deps', []):
  924. $(E) "[STRIP] Stripping lib${lib.name}.so"
  925. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
  926. % endif
  927. % endif
  928. % endif
  929. % endfor
  930. endif
  931. endif
  932. strip-shared_cxx: shared_cxx
  933. ifeq ($(CONFIG),opt)
  934. % for lib in libs:
  935. % if lib.language == "c++":
  936. % if lib.build == "all":
  937. $(E) "[STRIP] Stripping lib${lib.name}.so"
  938. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
  939. % endif
  940. % endif
  941. % endfor
  942. endif
  943. strip-shared_csharp: shared_csharp
  944. ifeq ($(CONFIG),opt)
  945. % for lib in libs:
  946. % if lib.language == "csharp":
  947. % if lib.build == "all":
  948. $(E) "[STRIP] Stripping lib${lib.name}.so"
  949. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
  950. % endif
  951. % endif
  952. % endfor
  953. endif
  954. cache.mk::
  955. $(E) "[MAKE] Generating $@"
  956. $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@
  957. $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc:
  958. $(E) "[MAKE] Generating $@"
  959. $(Q) mkdir -p $(@D)
  960. $(Q) echo "$(GPR_PC_FILE)" | tr , '\n' >$@
  961. $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc:
  962. $(E) "[MAKE] Generating $@"
  963. $(Q) mkdir -p $(@D)
  964. $(Q) echo "$(GRPC_PC_FILE)" | tr , '\n' >$@
  965. $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc:
  966. $(E) "[MAKE] Generating $@"
  967. $(Q) mkdir -p $(@D)
  968. $(Q) echo "$(GRPC_UNSECURE_PC_FILE)" | tr , '\n' >$@
  969. $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_zookeeper.pc:
  970. $(E) "[MAKE] Generating $@"
  971. $(Q) mkdir -p $(@D)
  972. $(Q) echo -e "$(GRPC_ZOOKEEPER_PC_FILE)" >$@
  973. $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc:
  974. $(E) "[MAKE] Generating $@"
  975. $(Q) mkdir -p $(@D)
  976. $(Q) echo "$(GRPCXX_PC_FILE)" | tr , '\n' >$@
  977. $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc:
  978. $(E) "[MAKE] Generating $@"
  979. $(Q) mkdir -p $(@D)
  980. $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@
  981. % for p in protos:
  982. ifeq ($(NO_PROTOC),true)
  983. $(GENDIR)/${p}.pb.cc: protoc_dep_error
  984. $(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error
  985. else
  986. $(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) ${' '.join('$(GENDIR)/%s.pb.cc' % q for q in proto_deps.get(p, []))}
  987. $(E) "[PROTOC] Generating protobuf CC file from $<"
  988. $(Q) mkdir -p `dirname $@`
  989. $(Q) $(PROTOC) --cpp_out=$(GENDIR) $<
  990. $(GENDIR)/${p}.grpc.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) ${' '.join('$(GENDIR)/%s.pb.cc $(GENDIR)/%s.grpc.pb.cc' % (q,q) for q in proto_deps.get(p, []))}
  991. $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
  992. $(Q) mkdir -p `dirname $@`
  993. $(Q) $(PROTOC) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $<
  994. endif
  995. % endfor
  996. ifeq ($(CONFIG),stapprof)
  997. src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h
  998. ifeq ($(HAS_SYSTEMTAP),true)
  999. $(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d
  1000. $(E) "[DTRACE] Compiling $<"
  1001. $(Q) mkdir -p `dirname $@`
  1002. $(Q) $(DTRACE) -C -h -s $< -o $@
  1003. else
  1004. $(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop
  1005. endif
  1006. endif
  1007. $(OBJDIR)/$(CONFIG)/%.o : %.c
  1008. $(E) "[C] Compiling $<"
  1009. $(Q) mkdir -p `dirname $@`
  1010. $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  1011. $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
  1012. $(E) "[CXX] Compiling $<"
  1013. $(Q) mkdir -p `dirname $@`
  1014. $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  1015. $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
  1016. $(E) "[HOSTCXX] Compiling $<"
  1017. $(Q) mkdir -p `dirname $@`
  1018. $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  1019. $(OBJDIR)/$(CONFIG)/%.o : %.cc
  1020. $(E) "[CXX] Compiling $<"
  1021. $(Q) mkdir -p `dirname $@`
  1022. $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  1023. install: install_c install_cxx install-plugins install-certs verify-install
  1024. install_c: install-headers_c install-static_c install-shared_c
  1025. install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
  1026. install_csharp: install-shared_csharp install_c
  1027. install_grpc_csharp_ext: install_csharp
  1028. install-headers: install-headers_c install-headers_cxx
  1029. install-headers_c:
  1030. $(E) "[INSTALL] Installing public C headers"
  1031. $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
  1032. $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
  1033. install-headers_cxx:
  1034. $(E) "[INSTALL] Installing public C++ headers"
  1035. $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
  1036. $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
  1037. install-static: install-static_c install-static_cxx
  1038. install-static_c: static_c strip-static_c install-pkg-config_c
  1039. % for lib in libs:
  1040. % if lib.language == "c":
  1041. % if lib.build == "all":
  1042. % if not lib.get('external_deps', None):
  1043. $(E) "[INSTALL] Installing lib${lib.name}.a"
  1044. $(Q) $(INSTALL) -d $(prefix)/lib
  1045. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
  1046. % endif
  1047. % endif
  1048. % endif
  1049. % endfor
  1050. ifeq ($(HAS_ZOOKEEPER),true)
  1051. % for lib in libs:
  1052. % if lib.language == "c":
  1053. % if lib.build == "all":
  1054. % if 'zookeeper' in lib.get('external_deps', []):
  1055. $(E) "[INSTALL] Installing lib${lib.name}.a"
  1056. $(Q) $(INSTALL) -d $(prefix)/lib
  1057. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
  1058. % endif
  1059. % endif
  1060. % endif
  1061. % endfor
  1062. endif
  1063. install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx
  1064. % for lib in libs:
  1065. % if lib.language == "c++":
  1066. % if lib.build == "all":
  1067. $(E) "[INSTALL] Installing lib${lib.name}.a"
  1068. $(Q) $(INSTALL) -d $(prefix)/lib
  1069. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
  1070. % endif
  1071. % endif
  1072. % endfor
  1073. <%def name="install_shared(lang_filter)">\
  1074. % for lib in libs:
  1075. % if lib.language == lang_filter:
  1076. % if lib.build == "all":
  1077. % if not lib.get('external_deps', None):
  1078. ifeq ($(SYSTEM),MINGW32)
  1079. $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)"
  1080. $(Q) $(INSTALL) -d $(prefix)/lib
  1081. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT)
  1082. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
  1083. else
  1084. $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)"
  1085. $(Q) $(INSTALL) -d $(prefix)/lib
  1086. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT)
  1087. ifneq ($(SYSTEM),Darwin)
  1088. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so.${settings.version.major}
  1089. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
  1090. endif
  1091. endif
  1092. % endif
  1093. % endif
  1094. % endif
  1095. % endfor
  1096. ifeq ($(HAS_ZOOKEEPER),true)
  1097. % for lib in libs:
  1098. % if lib.language == lang_filter:
  1099. % if lib.build == "all":
  1100. % if 'zookeeper' in lib.get('external_deps', []):
  1101. ifeq ($(SYSTEM),MINGW32)
  1102. $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)"
  1103. $(Q) $(INSTALL) -d $(prefix)/lib
  1104. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT)
  1105. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
  1106. else
  1107. $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)"
  1108. $(Q) $(INSTALL) -d $(prefix)/lib
  1109. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT)
  1110. ifneq ($(SYSTEM),Darwin)
  1111. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so.${settings.version.major}
  1112. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
  1113. endif
  1114. endif
  1115. % endif
  1116. % endif
  1117. % endif
  1118. % endfor
  1119. endif
  1120. ifneq ($(SYSTEM),MINGW32)
  1121. ifneq ($(SYSTEM),Darwin)
  1122. $(Q) ldconfig || true
  1123. endif
  1124. endif
  1125. </%def>
  1126. install-shared_c: shared_c strip-shared_c install-pkg-config_c
  1127. ${install_shared("c")}
  1128. install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c install-pkg-config_cxx
  1129. ${install_shared("c++")}
  1130. install-shared_csharp: shared_csharp strip-shared_csharp
  1131. ${install_shared("csharp")}
  1132. install-plugins: $(PROTOC_PLUGINS)
  1133. ifeq ($(SYSTEM),MINGW32)
  1134. $(Q) false
  1135. else
  1136. $(E) "[INSTALL] Installing grpc protoc plugins"
  1137. % for tgt in targets:
  1138. % if tgt.build == 'protoc':
  1139. $(Q) $(INSTALL) -d $(prefix)/bin
  1140. $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
  1141. % endif
  1142. % endfor
  1143. endif
  1144. install-pkg-config_c: pc_gpr pc_c pc_c_unsecure pc_c_zookeeper
  1145. $(E) "[INSTALL] Installing C pkg-config files"
  1146. $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
  1147. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc $(prefix)/lib/pkgconfig/gpr.pc
  1148. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(prefix)/lib/pkgconfig/grpc.pc
  1149. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(prefix)/lib/pkgconfig/grpc_unsecure.pc
  1150. ifeq ($(HAS_ZOOKEEPER),true)
  1151. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_zookeeper.pc $(prefix)/lib/pkgconfig/grpc_zookeeper.pc
  1152. endif
  1153. install-pkg-config_cxx: pc_cxx pc_cxx_unsecure
  1154. $(E) "[INSTALL] Installing C++ pkg-config files"
  1155. $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
  1156. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc $(prefix)/lib/pkgconfig/grpc++.pc
  1157. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc $(prefix)/lib/pkgconfig/grpc++_unsecure.pc
  1158. install-certs: etc/roots.pem
  1159. $(E) "[INSTALL] Installing root certificates"
  1160. $(Q) $(INSTALL) -d $(prefix)/share/grpc
  1161. $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
  1162. verify-install:
  1163. ifeq ($(INSTALL_OK),true)
  1164. @echo "Your system looks ready to go."
  1165. @echo
  1166. else
  1167. @echo "We couldn't find protoc 3.0.0+ installed on your system. While this"
  1168. @echo "won't prevent grpc from working, you won't be able to compile"
  1169. @echo "and run any meaningful code with it."
  1170. @echo
  1171. @echo
  1172. @echo "Please download and install protobuf 3.0.0+ from:"
  1173. @echo
  1174. @echo " https://github.com/google/protobuf/releases"
  1175. @echo
  1176. @echo "Once you've done so, or if you think this message is in error,"
  1177. @echo "you can re-run this check by doing:"
  1178. @echo
  1179. @echo " make verify-install"
  1180. endif
  1181. clean:
  1182. $(E) "[CLEAN] Cleaning build directories."
  1183. $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk
  1184. # The various libraries
  1185. % for lib in libs:
  1186. ${makelib(lib)}
  1187. % endfor
  1188. # All of the test targets, and protoc plugins
  1189. % for tgt in targets:
  1190. ${maketarget(tgt)}
  1191. % endfor
  1192. <%def name="makelib(lib)">
  1193. LIB${lib.name.upper()}_SRC = \\
  1194. % for src in lib.src:
  1195. ${proto_to_cc(src)} \\
  1196. % endfor
  1197. % if "public_headers" in lib:
  1198. % if lib.language == "c++":
  1199. PUBLIC_HEADERS_CXX += \\
  1200. % else:
  1201. PUBLIC_HEADERS_C += \\
  1202. % endif
  1203. % for hdr in lib.public_headers:
  1204. ${hdr} \\
  1205. % endfor
  1206. % endif
  1207. LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
  1208. % if lib.boringssl:
  1209. # boringssl needs an override to ensure that it does not include
  1210. # system openssl headers regardless of other configuration
  1211. # we do so here with a target specific variable assignment
  1212. $(LIB${lib.name.upper()}_OBJS): CFLAGS := -Ithird_party/boringssl/include $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value -fvisibility=hidden
  1213. $(LIB${lib.name.upper()}_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS) -fvisibility=hidden
  1214. $(LIB${lib.name.upper()}_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE
  1215. % elif lib.zlib:
  1216. $(LIB${lib.name.upper()}_OBJS): CFLAGS := $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value -Wno-implicit-function-declaration $(W_NO_SHIFT_NEGATIVE_VALUE) -fvisibility=hidden
  1217. % else:
  1218. % endif
  1219. ## If the library requires OpenSSL, let's add some restrictions.
  1220. % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
  1221. ifeq ($(NO_SECURE),true)
  1222. # You can't build secure libraries if you don't have OpenSSL.
  1223. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
  1224. % if lib.build == "all":
  1225. ifeq ($(SYSTEM),MINGW32)
  1226. $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error
  1227. else
  1228. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error
  1229. endif
  1230. % endif
  1231. else
  1232. % if lib.language == 'c++':
  1233. ifeq ($(NO_PROTOBUF),true)
  1234. # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
  1235. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
  1236. % if lib.build == "all":
  1237. ifeq ($(SYSTEM),MINGW32)
  1238. $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
  1239. else
  1240. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
  1241. endif
  1242. % endif
  1243. else
  1244. % endif
  1245. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
  1246. ## The else here corresponds to the if secure earlier.
  1247. % else:
  1248. % if lib.language == 'c++':
  1249. ifeq ($(NO_PROTOBUF),true)
  1250. # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
  1251. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
  1252. % if lib.build == "all":
  1253. ifeq ($(SYSTEM),MINGW32)
  1254. $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
  1255. else
  1256. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
  1257. endif
  1258. % endif
  1259. else
  1260. % endif
  1261. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP) \
  1262. % endif
  1263. % if lib.language == 'c++':
  1264. $(PROTOBUF_DEP)\
  1265. % endif
  1266. $(LIB${lib.name.upper()}_OBJS)
  1267. $(E) "[AR] Creating $@"
  1268. $(Q) mkdir -p `dirname $@`
  1269. $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  1270. $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
  1271. % if lib.get('baselib', False):
  1272. $(Q) rm -rf $(BUILDDIR_ABSOLUTE)/tmp-merge-${lib.name}
  1273. $(Q) ( mkdir -p $(BUILDDIR_ABSOLUTE)/tmp-merge-${lib.name}/grpc ; <%text>\</%text>
  1274. cd $(BUILDDIR_ABSOLUTE)/tmp-merge-${lib.name}/grpc ; <%text>\</%text>
  1275. $(AR) x $(LIBDIR)/$(CONFIG)/lib${lib.name}.a )
  1276. $(Q) for l in $(ZLIB_MERGE_LIBS) ; do ( <%text>\</%text>
  1277. mkdir -p $(BUILDDIR_ABSOLUTE)/tmp-merge-${lib.name}/zlib ; <%text>\</%text>
  1278. cd $(BUILDDIR_ABSOLUTE)/tmp-merge-${lib.name}/zlib ; <%text>\</%text>
  1279. <%text>$(AR) x $${l}</%text> ) ; done
  1280. $(Q) for l in $(ZLIB_MERGE_LIBS) ; do ( <%text>\</%text>
  1281. mkdir -p $(BUILDDIR_ABSOLUTE)/tmp-merge-${lib.name}/zlib ; <%text>\</%text>
  1282. cd $(BUILDDIR_ABSOLUTE)/tmp-merge-${lib.name}/zlib ; <%text>\</%text>
  1283. <%text>$(AR) x $${l}</%text> ) ; done
  1284. % if lib.get('secure', 'check') == True:
  1285. $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( <%text>\</%text>
  1286. mkdir -p $(BUILDDIR_ABSOLUTE)/tmp-merge-${lib.name}/ssl ; <%text>\</%text>
  1287. cd $(BUILDDIR_ABSOLUTE)/tmp-merge-${lib.name}/ssl ; <%text>\</%text>
  1288. <%text>$(AR) x $${l}</%text> ) ; done
  1289. $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( <%text>\</%text>
  1290. mkdir -p $(BUILDDIR_ABSOLUTE)/tmp-merge-${lib.name}/ssl ; <%text>\</%text>
  1291. cd $(BUILDDIR_ABSOLUTE)/tmp-merge-${lib.name}/ssl ; <%text>\</%text>
  1292. <%text>$(AR) x $${l}</%text> ) ; done
  1293. % endif
  1294. $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(BUILDDIR_ABSOLUTE)/tmp-merge-${lib.name}/*/__.SYMDEF*
  1295. $(Q) ar rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(BUILDDIR_ABSOLUTE)/tmp-merge-${lib.name}/*/*
  1296. $(Q) rm -rf $(BUILDDIR_ABSOLUTE)/tmp-merge-${lib.name}
  1297. % endif
  1298. ifeq ($(SYSTEM),Darwin)
  1299. $(Q) ranlib $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  1300. endif
  1301. <%
  1302. if lib.language == 'c++':
  1303. ld = '$(LDXX)'
  1304. else:
  1305. ld = '$(LD)'
  1306. out_base = '$(LIBDIR)/$(CONFIG)/' + lib.name
  1307. out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name
  1308. common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
  1309. libs = ''
  1310. lib_deps = ' $(ZLIB_DEP)'
  1311. mingw_libs = ''
  1312. mingw_lib_deps = ' $(ZLIB_DEP)'
  1313. if lib.language == 'c++':
  1314. lib_deps += ' $(PROTOBUF_DEP)'
  1315. mingw_lib_deps += ' $(PROTOBUF_DEP)'
  1316. if lib.get('deps_linkage', None) == 'static':
  1317. for dep in lib.get('deps', []):
  1318. lib_archive = '$(LIBDIR)/$(CONFIG)/lib' + dep + '.a'
  1319. common = common + ' ' + lib_archive
  1320. lib_deps = lib_deps + ' ' + lib_archive
  1321. mingw_lib_deps = mingw_lib_deps + ' ' + lib_archive
  1322. else:
  1323. for dep in lib.get('deps', []):
  1324. libs = libs + ' -l' + dep
  1325. lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
  1326. mingw_libs = mingw_libs + ' -l' + dep + '-imp'
  1327. mingw_lib_deps = mingw_lib_deps + ' $(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
  1328. security = lib.get('secure', 'check')
  1329. if security == True:
  1330. common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)'
  1331. common = common + ' $(ZLIB_MERGE_LIBS)'
  1332. if security in [True, 'check']:
  1333. for src in lib.src:
  1334. if not proto_re.match(src):
  1335. sources_that_need_openssl.add(src)
  1336. else:
  1337. for src in lib.src:
  1338. sources_that_don_t_need_openssl.add(src)
  1339. if 'zookeeper' in lib.get('external_deps', []):
  1340. libs = libs + ' -lzookeeper_mt'
  1341. if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
  1342. lib_deps = lib_deps + ' $(OPENSSL_DEP)'
  1343. mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
  1344. if lib.language == 'c++':
  1345. common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
  1346. %>
  1347. % if lib.build == "all":
  1348. ifeq ($(SYSTEM),MINGW32)
  1349. ${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
  1350. $(E) "[LD] Linking $@"
  1351. $(Q) mkdir -p `dirname $@`
  1352. $(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}
  1353. else
  1354. ${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
  1355. $(E) "[LD] Linking $@"
  1356. $(Q) mkdir -p `dirname $@`
  1357. ifeq ($(SYSTEM),Darwin)
  1358. $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name lib${lib.name}.$(SHARED_EXT) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
  1359. else
  1360. $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
  1361. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major}
  1362. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so
  1363. endif
  1364. endif
  1365. % endif
  1366. % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
  1367. ## If the lib was secure, we have to close the Makefile's if that tested
  1368. ## the presence of OpenSSL.
  1369. endif
  1370. % endif
  1371. % if lib.language == 'c++':
  1372. ## If the lib was C++, we have to close the Makefile's if that tested
  1373. ## the presence of protobuf 3.0.0+
  1374. endif
  1375. % endif
  1376. % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
  1377. ifneq ($(NO_SECURE),true)
  1378. % endif
  1379. ifneq ($(NO_DEPS),true)
  1380. -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
  1381. endif
  1382. % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
  1383. endif
  1384. % endif
  1385. % for src in lib.src:
  1386. % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src):
  1387. $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))}
  1388. % endif
  1389. % endfor
  1390. </%def>
  1391. <%def name="maketarget(tgt)"><% has_no_sources = not tgt.src %>
  1392. % if not has_no_sources:
  1393. ${tgt.name.upper()}_SRC = \\
  1394. % for src in tgt.src:
  1395. ${proto_to_cc(src)} \\
  1396. % endfor
  1397. ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
  1398. % endif
  1399. % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
  1400. ifeq ($(NO_SECURE),true)
  1401. # You can't build secure targets if you don't have OpenSSL.
  1402. $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
  1403. else
  1404. % endif
  1405. % if tgt.boringssl:
  1406. # boringssl needs an override to ensure that it does not include
  1407. # system openssl headers regardless of other configuration
  1408. # we do so here with a target specific variable assignment
  1409. $(${tgt.name.upper()}_OBJS): CFLAGS := -Ithird_party/boringssl/include $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value
  1410. $(${tgt.name.upper()}_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS)
  1411. $(${tgt.name.upper()}_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE
  1412. % else:
  1413. % endif
  1414. ##
  1415. ## We're not trying to add a dependency on building zlib and openssl here,
  1416. ## as it's already done in the libraries. We're assuming that the build
  1417. ## trickles down, and that a secure target requires a secure version of
  1418. ## a library.
  1419. ##
  1420. ## That simplifies the codegen a bit, but prevents a fully defined Makefile.
  1421. ## I can live with that.
  1422. ##
  1423. % if tgt.build == 'protoc' or tgt.language == 'c++':
  1424. ifeq ($(NO_PROTOBUF),true)
  1425. # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+.
  1426. $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
  1427. else
  1428. $(BINDIR)/$(CONFIG)/${tgt.name}: \
  1429. % if not has_no_sources:
  1430. $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
  1431. % endif
  1432. % else:
  1433. $(BINDIR)/$(CONFIG)/${tgt.name}: \
  1434. % if not has_no_sources:
  1435. $(${tgt.name.upper()}_OBJS)\
  1436. % endif
  1437. % endif
  1438. % for dep in tgt.deps:
  1439. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  1440. % endfor
  1441. % if tgt.language == "c++" or tgt.boringssl:
  1442. ## C++ targets specificies.
  1443. % if tgt.build == 'protoc':
  1444. $(E) "[HOSTLD] Linking $@"
  1445. $(Q) mkdir -p `dirname $@`
  1446. $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) \
  1447. % if not has_no_sources:
  1448. $(${tgt.name.upper()}_OBJS)\
  1449. % endif
  1450. % else:
  1451. $(E) "[LD] Linking $@"
  1452. $(Q) mkdir -p `dirname $@`
  1453. $(Q) $(LDXX) $(LDFLAGS) \
  1454. % if not has_no_sources:
  1455. $(${tgt.name.upper()}_OBJS)\
  1456. % endif
  1457. % endif
  1458. % else:
  1459. ## C-only targets specificities.
  1460. $(E) "[LD] Linking $@"
  1461. $(Q) mkdir -p `dirname $@`
  1462. $(Q) $(LD) $(LDFLAGS) \
  1463. % if not has_no_sources:
  1464. $(${tgt.name.upper()}_OBJS)\
  1465. % endif
  1466. % endif
  1467. % for dep in tgt.deps:
  1468. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  1469. % endfor
  1470. % if 'zookeeper' in tgt.get('external_deps', []):
  1471. -lzookeeper_mt\
  1472. % endif
  1473. % if tgt.language == "c++":
  1474. % if tgt.build == 'protoc':
  1475. $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
  1476. % else:
  1477. $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
  1478. % endif
  1479. % endif
  1480. % if tgt.build == 'protoc':
  1481. $(HOST_LDLIBS)\
  1482. % else:
  1483. $(LDLIBS)\
  1484. % endif
  1485. % if tgt.build == 'protoc':
  1486. $(HOST_LDLIBS_PROTOC)\
  1487. % elif tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
  1488. $(LDLIBS_SECURE)\
  1489. % endif
  1490. % if tgt.language == 'c++' and tgt.build == 'test':
  1491. $(GTEST_LIB)\
  1492. % elif tgt.language == 'c++' and tgt.build == 'benchmark':
  1493. $(GTEST_LIB)\
  1494. % endif
  1495. -o $(BINDIR)/$(CONFIG)/${tgt.name}
  1496. % if tgt.build == 'protoc' or tgt.language == 'c++':
  1497. endif
  1498. % endif
  1499. % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
  1500. endif
  1501. % endif
  1502. % for src in tgt.src:
  1503. $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
  1504. % for dep in tgt.deps:
  1505. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  1506. % endfor
  1507. % if tgt.language == 'c89':
  1508. % for src in tgt.src:
  1509. $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o : ${src}
  1510. $(E) "[C] Compiling $<"
  1511. $(Q) mkdir -p `dirname $@`
  1512. $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -std=c89 -pedantic -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  1513. % endfor
  1514. % endif
  1515. % endfor
  1516. % if not has_no_sources:
  1517. deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
  1518. % endif
  1519. % if not has_no_sources:
  1520. % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
  1521. ifneq ($(NO_SECURE),true)
  1522. % endif
  1523. ifneq ($(NO_DEPS),true)
  1524. -include $(${tgt.name.upper()}_OBJS:.o=.dep)
  1525. endif
  1526. % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
  1527. endif
  1528. % endif
  1529. % endif
  1530. % for src in tgt.src:
  1531. % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in tgt.src):
  1532. $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in tgt.src if proto_re.match(src2))}
  1533. % endif
  1534. % endfor
  1535. </%def>
  1536. ifneq ($(OPENSSL_DEP),)
  1537. # This is to ensure the embedded OpenSSL is built beforehand, properly
  1538. # installing headers to their final destination on the drive. We need this
  1539. # otherwise parallel compilation will fail if a source is compiled first.
  1540. % for src in sorted(sources_that_need_openssl):
  1541. % if src not in sources_that_don_t_need_openssl:
  1542. ${src}: $(OPENSSL_DEP)
  1543. % endif
  1544. % endfor
  1545. endif
  1546. .PHONY: all strip tools \
  1547. dep_error openssl_dep_error openssl_dep_message git_update stop \
  1548. buildtests buildtests_c buildtests_cxx \
  1549. test test_c test_cxx \
  1550. install install_c install_cxx \
  1551. install-headers install-headers_c install-headers_cxx \
  1552. install-shared install-shared_c install-shared_cxx \
  1553. install-static install-static_c install-static_cxx \
  1554. strip strip-shared strip-static \
  1555. strip_c strip-shared_c strip-static_c \
  1556. strip_cxx strip-shared_cxx strip-static_cxx \
  1557. dep_c dep_cxx bins_dep_c bins_dep_cxx \
  1558. clean