Makefile.template 53 KB

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