Makefile.template 56 KB

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