Makefile.template 56 KB

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