Makefile.template 53 KB

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