Makefile.template 55 KB

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