Makefile.template 58 KB

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