Makefile.template 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463
  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
  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
  152. LDFLAGS_asan = -fsanitize=address
  153. DEFINES_asan = GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5
  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
  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=20
  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
  171. OPENSSL_CFLAGS_ubsan = -DPURIFY
  172. LDFLAGS_ubsan = -fsanitize=undefined
  173. DEFINES_ubsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10
  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. ifndef VALID_CONFIG_$(CONFIG)
  205. $(error Invalid CONFIG value '$(CONFIG)')
  206. endif
  207. ifeq ($(SYSTEM),Linux)
  208. TMPOUT = /dev/null
  209. else
  210. TMPOUT = `mktemp /tmp/test-out-XXXXXX`
  211. endif
  212. # Detect if we can use C++11
  213. CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc
  214. HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false)
  215. # The HOST compiler settings are used to compile the protoc plugins.
  216. # In most cases, you won't have to change anything, but if you are
  217. # cross-compiling, you can override these variables from GNU make's
  218. # command line: make CC=cross-gcc HOST_CC=gcc
  219. HOST_CC = $(CC)
  220. HOST_CXX = $(CXX)
  221. HOST_LD = $(LD)
  222. HOST_LDXX = $(LDXX)
  223. CPPFLAGS += $(CPPFLAGS_$(CONFIG))
  224. DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
  225. LDFLAGS += $(LDFLAGS_$(CONFIG))
  226. ifdef EXTRA_DEFINES
  227. DEFINES += $(EXTRA_DEFINES)
  228. endif
  229. CFLAGS += -std=c89 -pedantic
  230. ifeq ($(HAS_CXX11),true)
  231. CXXFLAGS += -std=c++11
  232. else
  233. CXXFLAGS += -std=c++0x
  234. endif
  235. CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
  236. LDFLAGS += -g
  237. ifneq ($(SYSTEM),MINGW32)
  238. PIC_CPPFLAGS = -fPIC
  239. CPPFLAGS += -fPIC
  240. LDFLAGS += -fPIC
  241. endif
  242. INCLUDES = . include $(GENDIR)
  243. LDFLAGS += -Llibs/$(CONFIG)
  244. ifeq ($(SYSTEM),Darwin)
  245. ifneq ($(wildcard /usr/local/ssl/include),)
  246. INCLUDES += /usr/local/ssl/include
  247. endif
  248. ifneq ($(wildcard /opt/local/include),)
  249. INCLUDES += /opt/local/include
  250. endif
  251. ifneq ($(wildcard /usr/local/include),)
  252. INCLUDES += /usr/local/include
  253. endif
  254. LIBS = m z
  255. ifneq ($(wildcard /usr/local/ssl/lib),)
  256. LDFLAGS += -L/usr/local/ssl/lib
  257. endif
  258. ifneq ($(wildcard /opt/local/lib),)
  259. LDFLAGS += -L/opt/local/lib
  260. endif
  261. ifneq ($(wildcard /usr/local/lib),)
  262. LDFLAGS += -L/usr/local/lib
  263. endif
  264. endif
  265. ifeq ($(SYSTEM),Linux)
  266. LIBS = rt m z pthread
  267. LDFLAGS += -pthread
  268. endif
  269. ifeq ($(SYSTEM),MINGW32)
  270. LIBS = m z pthread
  271. LDFLAGS += -pthread
  272. endif
  273. ifneq ($(wildcard /usr/src/gtest/src/gtest-all.cc),)
  274. GTEST_LIB = /usr/src/gtest/src/gtest-all.cc -I/usr/src/gtest
  275. else
  276. GTEST_LIB = -lgtest
  277. endif
  278. GTEST_LIB += -lgflags
  279. ifeq ($(V),1)
  280. E = @:
  281. Q =
  282. else
  283. E = @echo
  284. Q = @
  285. endif
  286. VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build}
  287. CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
  288. CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
  289. LDFLAGS += $(ARCH_FLAGS)
  290. LDLIBS += $(addprefix -l, $(LIBS))
  291. LDLIBSXX += $(addprefix -l, $(LIBSXX))
  292. HOST_CPPFLAGS = $(CPPFLAGS)
  293. HOST_CFLAGS = $(CFLAGS)
  294. HOST_CXXFLAGS = $(CXXFLAGS)
  295. HOST_LDFLAGS = $(LDFLAGS)
  296. HOST_LDLIBS = $(LDLIBS)
  297. # These are automatically computed variables.
  298. # There shouldn't be any need to change anything from now on.
  299. ifeq ($(SYSTEM),MINGW32)
  300. SHARED_EXT = dll
  301. endif
  302. ifeq ($(SYSTEM),Darwin)
  303. SHARED_EXT = dylib
  304. endif
  305. ifeq ($(SHARED_EXT),)
  306. SHARED_EXT = so.$(VERSION)
  307. endif
  308. ifeq ($(wildcard .git),)
  309. IS_GIT_FOLDER = false
  310. else
  311. IS_GIT_FOLDER = true
  312. endif
  313. ifeq ($(SYSTEM),Linux)
  314. OPENSSL_REQUIRES_DL = true
  315. endif
  316. ifeq ($(SYSTEM),Darwin)
  317. OPENSSL_REQUIRES_DL = true
  318. endif
  319. ifeq ($(SYSTEM),MINGW32)
  320. OPENSSL_LIBS = ssl32 eay32
  321. else
  322. OPENSSL_LIBS = ssl crypto
  323. endif
  324. OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS)
  325. ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS)
  326. PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS)
  327. PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS)
  328. PROTOC_CHECK_CMD = which protoc > /dev/null
  329. PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3
  330. DTRACE_CHECK_CMD = which dtrace > /dev/null
  331. SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS)
  332. ifeq ($(OPENSSL_REQUIRES_DL),true)
  333. OPENSSL_ALPN_CHECK_CMD += -ldl
  334. endif
  335. ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
  336. HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
  337. ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
  338. DEFINES += GRPC_HAVE_PERFTOOLS
  339. LIBS += profiler
  340. endif
  341. endif
  342. HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
  343. ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
  344. HAS_SYSTEM_OPENSSL_ALPN = $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
  345. HAS_SYSTEM_ZLIB = $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
  346. HAS_SYSTEM_PROTOBUF = $(HAS_SYSTEM_PROTOBUF_VERIFY)
  347. else
  348. # override system libraries if the config requires a custom compiled library
  349. HAS_SYSTEM_OPENSSL_ALPN = false
  350. HAS_SYSTEM_ZLIB = false
  351. HAS_SYSTEM_PROTOBUF = false
  352. endif
  353. HAS_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
  354. ifeq ($(HAS_PROTOC),true)
  355. HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false)
  356. else
  357. HAS_VALID_PROTOC = false
  358. endif
  359. # Check for Systemtap (https://sourceware.org/systemtap/), first by making sure <sys/sdt.h> is present
  360. # in the system and secondly by checking for the "dtrace" binary (on Linux, this is part of the Systemtap
  361. # distribution. It's part of the base system on BSD/Solaris machines).
  362. HAS_SYSTEMTAP_HEADERS = $(shell $(SYSTEMTAP_HEADERS_CHECK_CMD) 2> /dev/null && echo true || echo false)
  363. HAS_DTRACE = $(shell $(DTRACE_CHECK_CMD) 2> /dev/null && echo true || echo false)
  364. HAS_SYSTEMTAP = false
  365. ifeq ($(HAS_SYSTEMTAP_HEADERS),true)
  366. ifeq ($(HAS_DTRACE),true)
  367. HAS_SYSTEMTAP = true
  368. endif
  369. endif
  370. ifeq ($(wildcard third_party/openssl/ssl/ssl.h),)
  371. HAS_EMBEDDED_OPENSSL_ALPN = false
  372. else
  373. HAS_EMBEDDED_OPENSSL_ALPN = true
  374. endif
  375. ifeq ($(wildcard third_party/zlib/zlib.h),)
  376. HAS_EMBEDDED_ZLIB = false
  377. else
  378. HAS_EMBEDDED_ZLIB = true
  379. endif
  380. ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
  381. HAS_EMBEDDED_PROTOBUF = false
  382. ifneq ($(HAS_VALID_PROTOC),true)
  383. NO_PROTOC = true
  384. endif
  385. else
  386. HAS_EMBEDDED_PROTOBUF = true
  387. endif
  388. ifeq ($(HAS_SYSTEM_ZLIB),false)
  389. ifeq ($(HAS_EMBEDDED_ZLIB),true)
  390. ZLIB_DEP = $(LIBDIR)/$(CONFIG)/zlib/libz.a
  391. CPPFLAGS += -Ithird_party/zlib
  392. LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib
  393. else
  394. DEP_MISSING += zlib
  395. endif
  396. endif
  397. ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false)
  398. ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true)
  399. OPENSSL_DEP = $(LIBDIR)/$(CONFIG)/openssl/libssl.a
  400. OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/openssl/libssl.a $(LIBDIR)/$(CONFIG)/openssl/libcrypto.a
  401. # need to prefix these to ensure overriding system libraries
  402. CPPFLAGS := -Ithird_party/openssl/include $(CPPFLAGS)
  403. LDFLAGS := -L$(LIBDIR)/$(CONFIG)/openssl $(LDFLAGS)
  404. ifeq ($(OPENSSL_REQUIRES_DL),true)
  405. LIBS_SECURE = dl
  406. endif
  407. else
  408. NO_SECURE = true
  409. endif
  410. else
  411. LIBS_SECURE = $(OPENSSL_LIBS)
  412. ifeq ($(OPENSSL_REQUIRES_DL),true)
  413. LIBS_SECURE += dl
  414. endif
  415. endif
  416. LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
  417. ifeq ($(HAS_SYSTEM_PROTOBUF),false)
  418. ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
  419. PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
  420. CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
  421. LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
  422. PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
  423. else
  424. NO_PROTOBUF = true
  425. endif
  426. else
  427. endif
  428. LIBS_PROTOBUF = protobuf
  429. LIBS_PROTOC = protoc protobuf
  430. LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
  431. HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
  432. ifeq ($(MAKECMDGOALS),clean)
  433. NO_DEPS = true
  434. endif
  435. INSTALL_OK = false
  436. ifeq ($(HAS_VALID_PROTOC),true)
  437. ifeq ($(HAS_SYSTEM_PROTOBUF_VERIFY),true)
  438. INSTALL_OK = true
  439. endif
  440. endif
  441. .SECONDARY = %.pb.h %.pb.cc
  442. PROTOC_PLUGINS =\
  443. % for tgt in targets:
  444. % if tgt.build == 'protoc':
  445. $(BINDIR)/$(CONFIG)/${tgt.name}\
  446. % endif
  447. % endfor
  448. ifeq ($(DEP_MISSING),)
  449. all: static shared plugins\
  450. % for tgt in targets:
  451. % if tgt.build == 'all':
  452. $(BINDIR)/$(CONFIG)/${tgt.name}\
  453. % endif
  454. % endfor
  455. dep_error:
  456. @echo "You shouldn't see this message - all of your dependencies are correct."
  457. else
  458. all: dep_error git_update stop
  459. dep_error:
  460. @echo
  461. @echo "DEPENDENCY ERROR"
  462. @echo
  463. @echo "You are missing system dependencies that are essential to build grpc,"
  464. @echo "and the third_party directory doesn't have them:"
  465. @echo
  466. @echo " $(DEP_MISSING)"
  467. @echo
  468. @echo "Installing the development packages for your system will solve"
  469. @echo "this issue. Please consult INSTALL to get more information."
  470. @echo
  471. @echo "If you need information about why these tests failed, run:"
  472. @echo
  473. @echo " make run_dep_checks"
  474. @echo
  475. endif
  476. git_update:
  477. ifeq ($(IS_GIT_FOLDER),true)
  478. @echo "Additionally, since you are in a git clone, you can download the"
  479. @echo "missing dependencies in third_party by running the following command:"
  480. @echo
  481. @echo " git submodule update --init"
  482. @echo
  483. endif
  484. openssl_dep_error: openssl_dep_message git_update stop
  485. protobuf_dep_error: protobuf_dep_message git_update stop
  486. protoc_dep_error: protoc_dep_message git_update stop
  487. openssl_dep_message:
  488. @echo
  489. @echo "DEPENDENCY ERROR"
  490. @echo
  491. @echo "The target you are trying to run requires OpenSSL with ALPN support."
  492. @echo "Your system doesn't have it, and neither does the third_party directory."
  493. @echo
  494. @echo "Please consult INSTALL to get more information."
  495. @echo
  496. @echo "If you need information about why these tests failed, run:"
  497. @echo
  498. @echo " make run_dep_checks"
  499. @echo
  500. protobuf_dep_message:
  501. @echo
  502. @echo "DEPENDENCY ERROR"
  503. @echo
  504. @echo "The target you are trying to run requires protobuf 3.0.0+"
  505. @echo "Your system doesn't have it, and neither does the third_party directory."
  506. @echo
  507. @echo "Please consult INSTALL to get more information."
  508. @echo
  509. @echo "If you need information about why these tests failed, run:"
  510. @echo
  511. @echo " make run_dep_checks"
  512. @echo
  513. protoc_dep_message:
  514. @echo
  515. @echo "DEPENDENCY ERROR"
  516. @echo
  517. @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
  518. @echo "Your system doesn't have it, and neither does the third_party directory."
  519. @echo
  520. @echo "Please consult INSTALL to get more information."
  521. @echo
  522. @echo "If you need information about why these tests failed, run:"
  523. @echo
  524. @echo " make run_dep_checks"
  525. @echo
  526. systemtap_dep_error:
  527. @echo
  528. @echo "DEPENDENCY ERROR"
  529. @echo
  530. @echo "Under the '$(CONFIG)' configutation, the target you are trying "
  531. @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other "
  532. @echo "platforms such as Solaris and *BSD). "
  533. @echo
  534. @echo "Please consult INSTALL to get more information."
  535. @echo
  536. stop:
  537. @false
  538. % for tgt in targets:
  539. ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
  540. % endfor
  541. run_dep_checks:
  542. $(OPENSSL_ALPN_CHECK_CMD) || true
  543. $(ZLIB_CHECK_CMD) || true
  544. $(PERFTOOLS_CHECK_CMD) || true
  545. $(PROTOBUF_CHECK_CMD) || true
  546. $(PROTOC_CHECK_VERSION_CMD) || true
  547. $(LIBDIR)/$(CONFIG)/zlib/libz.a:
  548. $(E) "[MAKE] Building zlib"
  549. $(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="$(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG))" ./configure --static)
  550. $(Q)$(MAKE) -C third_party/zlib clean
  551. $(Q)$(MAKE) -C third_party/zlib
  552. $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/zlib
  553. $(Q)cp third_party/zlib/libz.a $(LIBDIR)/$(CONFIG)/zlib
  554. $(LIBDIR)/$(CONFIG)/openssl/libssl.a:
  555. $(E) "[MAKE] Building openssl for $(SYSTEM)"
  556. ifeq ($(SYSTEM),Darwin)
  557. $(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./Configure darwin64-x86_64-cc)
  558. else
  559. ifeq ($(SYSTEM),MINGW32)
  560. @echo "We currently don't have a good way to compile OpenSSL in-place under msys."
  561. @echo "Please provide an ALPN-capable OpenSSL in your mingw32 system."
  562. @echo
  563. @echo "Note that you can find a compatible version of the libraries here:"
  564. @echo
  565. @echo "http://slproweb.com/products/Win32OpenSSL.html"
  566. @echo
  567. @echo "If you decide to install that one, take the full version. The light"
  568. @echo "version only contains compiled DLLs, without the development files."
  569. @echo
  570. @echo "When installing, chose to copy the OpenSSL dlls to the OpenSSL binaries"
  571. @echo "directory. This way we'll link to them directly."
  572. @echo
  573. @echo "You can then re-start the build the following way:"
  574. @echo
  575. @echo " CPPFLAGS=-I/c/OpenSSL-Win64/include LDFLAGS=-L/c/OpenSSL-Win64 make"
  576. @false
  577. else
  578. $(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./config no-asm $(OPENSSL_CONFIG_$(CONFIG)))
  579. endif
  580. endif
  581. $(Q)$(MAKE) -C third_party/openssl clean
  582. $(Q)(unset CPPFLAGS; $(MAKE) -C third_party/openssl build_crypto build_ssl)
  583. $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/openssl
  584. $(Q)cp third_party/openssl/libssl.a third_party/openssl/libcrypto.a $(LIBDIR)/$(CONFIG)/openssl
  585. third_party/protobuf/configure:
  586. $(E) "[AUTOGEN] Preparing protobuf"
  587. $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
  588. $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
  589. $(E) "[MAKE] Building protobuf"
  590. $(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g" ./configure --disable-shared --enable-static)
  591. $(Q)$(MAKE) -C third_party/protobuf clean
  592. $(Q)$(MAKE) -C third_party/protobuf
  593. $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
  594. $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
  595. $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
  596. $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
  597. $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
  598. static: static_c static_cxx
  599. static_c: \
  600. % for lib in libs:
  601. % if lib.build == 'all' and lib.language == 'c':
  602. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  603. % endif
  604. % endfor
  605. static_cxx: \
  606. % for lib in libs:
  607. % if lib.build == 'all' and lib.language == 'c++':
  608. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  609. % endif
  610. % endfor
  611. shared: shared_c shared_cxx
  612. shared_c: \
  613. % for lib in libs:
  614. % if lib.build == 'all' and lib.language == 'c':
  615. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
  616. % endif
  617. % endfor
  618. shared_cxx: \
  619. % for lib in libs:
  620. % if lib.build == 'all' and lib.language == 'c++':
  621. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
  622. % endif
  623. % endfor
  624. shared_csharp: shared_c \
  625. % for lib in libs:
  626. % if lib.build == 'all' and lib.language == 'csharp':
  627. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
  628. % endif
  629. % endfor
  630. grpc_csharp_ext: shared_csharp
  631. plugins: $(PROTOC_PLUGINS)
  632. privatelibs: privatelibs_c privatelibs_cxx
  633. privatelibs_c: \
  634. % for lib in libs:
  635. % if lib.build == 'private' and lib.language == 'c':
  636. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  637. % endif
  638. % endfor
  639. privatelibs_cxx: \
  640. % for lib in libs:
  641. % if lib.build == 'private' and lib.language == 'c++':
  642. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  643. % endif
  644. % endfor
  645. buildtests: buildtests_c buildtests_cxx
  646. buildtests_c: privatelibs_c\
  647. % for tgt in targets:
  648. % if tgt.build == 'test' and not tgt.language == 'c++':
  649. $(BINDIR)/$(CONFIG)/${tgt.name}\
  650. % endif
  651. % endfor
  652. buildtests_cxx: privatelibs_cxx\
  653. % for tgt in targets:
  654. % if tgt.build == 'test' and tgt.language == 'c++':
  655. $(BINDIR)/$(CONFIG)/${tgt.name}\
  656. % endif
  657. % endfor
  658. test: test_c test_cxx
  659. flaky_test: flaky_test_c flaky_test_cxx
  660. test_c: buildtests_c
  661. % for tgt in targets:
  662. % if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++' and not tgt.get('flaky', False):
  663. $(E) "[RUN] Testing ${tgt.name}"
  664. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  665. % endif
  666. % endfor
  667. flaky_test_c: buildtests_c
  668. % for tgt in targets:
  669. % if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++' and tgt.get('flaky', False):
  670. $(E) "[RUN] Testing ${tgt.name}"
  671. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  672. % endif
  673. % endfor
  674. test_cxx: buildtests_cxx
  675. % for tgt in targets:
  676. % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and not tgt.get('flaky', False):
  677. $(E) "[RUN] Testing ${tgt.name}"
  678. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  679. % endif
  680. % endfor
  681. flaky_test_cxx: buildtests_cxx
  682. % for tgt in targets:
  683. % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and tgt.get('flaky', False):
  684. $(E) "[RUN] Testing ${tgt.name}"
  685. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  686. % endif
  687. % endfor
  688. test_python: static_c
  689. $(E) "[RUN] Testing python code"
  690. $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
  691. tools: tools_c tools_cxx
  692. tools_c: privatelibs_c\
  693. % for tgt in targets:
  694. % if tgt.build == 'tool' and not tgt.language=='c++':
  695. $(BINDIR)/$(CONFIG)/${tgt.name}\
  696. % endif
  697. % endfor
  698. tools_cxx: privatelibs_cxx\
  699. % for tgt in targets:
  700. % if tgt.build == 'tool' and tgt.language=='c++':
  701. $(BINDIR)/$(CONFIG)/${tgt.name}\
  702. % endif
  703. % endfor
  704. buildbenchmarks: privatelibs\
  705. % for tgt in targets:
  706. % if tgt.build == 'benchmark':
  707. $(BINDIR)/$(CONFIG)/${tgt.name}\
  708. % endif
  709. % endfor
  710. benchmarks: buildbenchmarks
  711. strip: strip-static strip-shared
  712. strip-static: strip-static_c strip-static_cxx
  713. strip-shared: strip-shared_c strip-shared_cxx
  714. # TODO(nnoble): the strip target is stripping in-place, instead
  715. # of copying files in a temporary folder.
  716. # This prevents proper debugging after running make install.
  717. strip-static_c: static_c
  718. ifeq ($(CONFIG),opt)
  719. % for lib in libs:
  720. % if lib.language == "c":
  721. % if lib.build == "all":
  722. $(E) "[STRIP] Stripping lib${lib.name}.a"
  723. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  724. % endif
  725. % endif
  726. % endfor
  727. endif
  728. strip-static_cxx: static_cxx
  729. ifeq ($(CONFIG),opt)
  730. % for lib in libs:
  731. % if lib.language == "c++":
  732. % if lib.build == "all":
  733. $(E) "[STRIP] Stripping lib${lib.name}.a"
  734. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  735. % endif
  736. % endif
  737. % endfor
  738. endif
  739. strip-shared_c: shared_c
  740. ifeq ($(CONFIG),opt)
  741. % for lib in libs:
  742. % if lib.language == "c":
  743. % if lib.build == "all":
  744. $(E) "[STRIP] Stripping lib${lib.name}.so"
  745. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
  746. % endif
  747. % endif
  748. % endfor
  749. endif
  750. strip-shared_cxx: shared_cxx
  751. ifeq ($(CONFIG),opt)
  752. % for lib in libs:
  753. % if lib.language == "c++":
  754. % if lib.build == "all":
  755. $(E) "[STRIP] Stripping lib${lib.name}.so"
  756. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
  757. % endif
  758. % endif
  759. % endfor
  760. endif
  761. strip-shared_csharp: shared_csharp
  762. ifeq ($(CONFIG),opt)
  763. % for lib in libs:
  764. % if lib.language == "csharp":
  765. % if lib.build == "all":
  766. $(E) "[STRIP] Stripping lib${lib.name}.so"
  767. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
  768. % endif
  769. % endif
  770. % endfor
  771. endif
  772. % for p in protos:
  773. ifeq ($(NO_PROTOC),true)
  774. $(GENDIR)/${p}.pb.cc: protoc_dep_error
  775. $(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error
  776. else
  777. $(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
  778. $(E) "[PROTOC] Generating protobuf CC file from $<"
  779. $(Q) mkdir -p `dirname $@`
  780. $(Q) $(PROTOC) --cpp_out=$(GENDIR) $<
  781. $(GENDIR)/${p}.grpc.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
  782. $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
  783. $(Q) mkdir -p `dirname $@`
  784. $(Q) $(PROTOC) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $<
  785. endif
  786. % endfor
  787. ifeq ($(CONFIG),stapprof)
  788. src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h
  789. ifeq ($(HAS_SYSTEMTAP),true)
  790. $(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d
  791. $(E) "[DTRACE] Compiling $<"
  792. $(Q) mkdir -p `dirname $@`
  793. $(Q) $(DTRACE) -C -h -s $< -o $@
  794. else
  795. $(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop
  796. endif
  797. endif
  798. $(OBJDIR)/$(CONFIG)/%.o : %.c
  799. $(E) "[C] Compiling $<"
  800. $(Q) mkdir -p `dirname $@`
  801. $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  802. $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
  803. $(E) "[CXX] Compiling $<"
  804. $(Q) mkdir -p `dirname $@`
  805. $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  806. $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
  807. $(E) "[HOSTCXX] Compiling $<"
  808. $(Q) mkdir -p `dirname $@`
  809. $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  810. $(OBJDIR)/$(CONFIG)/%.o : %.cc
  811. $(E) "[CXX] Compiling $<"
  812. $(Q) mkdir -p `dirname $@`
  813. $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  814. install: install_c install_cxx install-plugins install-certs verify-install
  815. install_c: install-headers_c install-static_c install-shared_c
  816. install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
  817. install_csharp: install-shared_csharp install_c
  818. install_grpc_csharp_ext: install_csharp
  819. install-headers: install-headers_c install-headers_cxx
  820. install-headers_c:
  821. $(E) "[INSTALL] Installing public C headers"
  822. $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
  823. $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
  824. install-headers_cxx:
  825. $(E) "[INSTALL] Installing public C++ headers"
  826. $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
  827. $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
  828. install-static: install-static_c install-static_cxx
  829. install-static_c: static_c strip-static_c
  830. % for lib in libs:
  831. % if lib.language == "c":
  832. % if lib.build == "all":
  833. $(E) "[INSTALL] Installing lib${lib.name}.a"
  834. $(Q) $(INSTALL) -d $(prefix)/lib
  835. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
  836. % endif
  837. % endif
  838. % endfor
  839. install-static_cxx: static_cxx strip-static_cxx
  840. % for lib in libs:
  841. % if lib.language == "c++":
  842. % if lib.build == "all":
  843. $(E) "[INSTALL] Installing lib${lib.name}.a"
  844. $(Q) $(INSTALL) -d $(prefix)/lib
  845. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
  846. % endif
  847. % endif
  848. % endfor
  849. <%def name="install_shared(lang_filter)">\
  850. % for lib in libs:
  851. % if lib.language == lang_filter:
  852. % if lib.build == "all":
  853. ifeq ($(SYSTEM),MINGW32)
  854. $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)"
  855. $(Q) $(INSTALL) -d $(prefix)/lib
  856. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT)
  857. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
  858. else
  859. $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)"
  860. $(Q) $(INSTALL) -d $(prefix)/lib
  861. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT)
  862. ifneq ($(SYSTEM),Darwin)
  863. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so.${settings.version.major}
  864. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
  865. endif
  866. endif
  867. % endif
  868. % endif
  869. % endfor
  870. ifneq ($(SYSTEM),MINGW32)
  871. ifneq ($(SYSTEM),Darwin)
  872. $(Q) ldconfig || true
  873. endif
  874. endif
  875. </%def>
  876. install-shared_c: shared_c strip-shared_c
  877. ${install_shared("c")}
  878. install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c
  879. ${install_shared("c++")}
  880. install-shared_csharp: shared_csharp strip-shared_csharp
  881. ${install_shared("csharp")}
  882. install-plugins: $(PROTOC_PLUGINS)
  883. ifeq ($(SYSTEM),MINGW32)
  884. $(Q) false
  885. else
  886. $(E) "[INSTALL] Installing grpc protoc plugins"
  887. % for tgt in targets:
  888. % if tgt.build == 'protoc':
  889. $(Q) $(INSTALL) -d $(prefix)/bin
  890. $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
  891. % endif
  892. % endfor
  893. endif
  894. install-certs: etc/roots.pem
  895. $(E) "[INSTALL] Installing root certificates"
  896. $(Q) $(INSTALL) -d $(prefix)/share/grpc
  897. $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
  898. verify-install:
  899. ifeq ($(INSTALL_OK),true)
  900. @echo "Your system looks ready to go."
  901. @echo
  902. else
  903. @echo "We couldn't find protoc 3.0.0+ installed on your system. While this"
  904. @echo "won't prevent grpc from working, you won't be able to compile"
  905. @echo "and run any meaningful code with it."
  906. @echo
  907. @echo
  908. @echo "Please download and install protobuf 3.0.0+ from:"
  909. @echo
  910. @echo " https://github.com/google/protobuf/releases"
  911. @echo
  912. @echo "Once you've done so, or if you think this message is in error,"
  913. @echo "you can re-run this check by doing:"
  914. @echo
  915. @echo " make verify-install"
  916. endif
  917. clean:
  918. $(E) "[CLEAN] Cleaning build directories."
  919. $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR)
  920. # The various libraries
  921. % for lib in libs:
  922. ${makelib(lib)}
  923. % endfor
  924. # All of the test targets, and protoc plugins
  925. % for tgt in targets:
  926. ${maketarget(tgt)}
  927. % endfor
  928. <%def name="makelib(lib)">
  929. LIB${lib.name.upper()}_SRC = \\
  930. % for src in lib.src:
  931. ${proto_to_cc(src)} \\
  932. % endfor
  933. % if "public_headers" in lib:
  934. % if lib.language == "c++":
  935. PUBLIC_HEADERS_CXX += \\
  936. % else:
  937. PUBLIC_HEADERS_C += \\
  938. % endif
  939. % for hdr in lib.public_headers:
  940. ${hdr} \\
  941. % endfor
  942. % endif
  943. LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
  944. ## If the library requires OpenSSL with ALPN, let's add some restrictions.
  945. % if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
  946. ifeq ($(NO_SECURE),true)
  947. # You can't build secure libraries if you don't have OpenSSL with ALPN.
  948. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
  949. % if lib.build == "all":
  950. ifeq ($(SYSTEM),MINGW32)
  951. $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error
  952. else
  953. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error
  954. endif
  955. % endif
  956. else
  957. % if lib.language == 'c++':
  958. ifeq ($(NO_PROTOBUF),true)
  959. # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
  960. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
  961. % if lib.build == "all":
  962. ifeq ($(SYSTEM),MINGW32)
  963. $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
  964. else
  965. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
  966. endif
  967. % endif
  968. else
  969. % endif
  970. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
  971. ## The else here corresponds to the if secure earlier.
  972. % else:
  973. % if lib.language == 'c++':
  974. ifeq ($(NO_PROTOBUF),true)
  975. # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
  976. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
  977. % if lib.build == "all":
  978. ifeq ($(SYSTEM),MINGW32)
  979. $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
  980. else
  981. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
  982. endif
  983. % endif
  984. else
  985. % endif
  986. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP)\
  987. % endif
  988. % if lib.language == 'c++':
  989. $(PROTOBUF_DEP)\
  990. % endif
  991. $(LIB${lib.name.upper()}_OBJS)
  992. $(E) "[AR] Creating $@"
  993. $(Q) mkdir -p `dirname $@`
  994. $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  995. $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
  996. % if lib.get('baselib', False):
  997. % if lib.get('secure', 'check') == 'yes':
  998. $(Q) rm -rf tmp-merge-${lib.name}
  999. $(Q) mkdir tmp-merge-${lib.name}
  1000. $(Q) ( cd tmp-merge-${lib.name} ; $(AR) x ../$(LIBDIR)/$(CONFIG)/lib${lib.name}.a )
  1001. $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge-${lib.name} ; <%text>ar x ../$${l}</%text> ) ; done
  1002. $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/__.SYMDEF*
  1003. $(Q) ar rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/*
  1004. $(Q) rm -rf tmp-merge-${lib.name}
  1005. % endif
  1006. % endif
  1007. ifeq ($(SYSTEM),Darwin)
  1008. $(Q) ranlib $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  1009. endif
  1010. <%
  1011. if lib.language == 'c++':
  1012. ld = '$(LDXX)'
  1013. else:
  1014. ld = '$(LD)'
  1015. out_base = '$(LIBDIR)/$(CONFIG)/' + lib.name
  1016. out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name
  1017. common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
  1018. libs = ''
  1019. lib_deps = ' $(ZLIB_DEP)'
  1020. mingw_libs = ''
  1021. mingw_lib_deps = ' $(ZLIB_DEP)'
  1022. if lib.language == 'c++':
  1023. lib_deps += ' $(PROTOBUF_DEP)'
  1024. mingw_lib_deps += ' $(PROTOBUF_DEP)'
  1025. for dep in lib.get('deps', []):
  1026. libs = libs + ' -l' + dep
  1027. lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
  1028. mingw_libs = mingw_libs + ' -l' + dep + '-imp'
  1029. mingw_lib_deps = mingw_lib_deps + ' $(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
  1030. if lib.get('secure', 'check') == 'yes':
  1031. common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)'
  1032. for src in lib.src:
  1033. sources_that_need_openssl.add(src)
  1034. else:
  1035. for src in lib.src:
  1036. sources_that_don_t_need_openssl.add(src)
  1037. if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
  1038. lib_deps = lib_deps + ' $(OPENSSL_DEP)'
  1039. mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
  1040. if lib.language == 'c++':
  1041. common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
  1042. %>
  1043. % if lib.build == "all":
  1044. ifeq ($(SYSTEM),MINGW32)
  1045. ${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
  1046. $(E) "[LD] Linking $@"
  1047. $(Q) mkdir -p `dirname $@`
  1048. $(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}
  1049. else
  1050. ${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
  1051. $(E) "[LD] Linking $@"
  1052. $(Q) mkdir -p `dirname $@`
  1053. ifeq ($(SYSTEM),Darwin)
  1054. $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name lib${lib.name}.$(SHARED_EXT) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
  1055. else
  1056. $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
  1057. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major}
  1058. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so
  1059. endif
  1060. endif
  1061. % endif
  1062. % if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
  1063. ## If the lib was secure, we have to close the Makefile's if that tested
  1064. ## the presence of an ALPN-capable OpenSSL.
  1065. endif
  1066. % endif
  1067. % if lib.language == 'c++':
  1068. ## If the lib was C++, we have to close the Makefile's if that tested
  1069. ## the presence of protobuf 3.0.0+
  1070. endif
  1071. % endif
  1072. % if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
  1073. ifneq ($(NO_SECURE),true)
  1074. % endif
  1075. ifneq ($(NO_DEPS),true)
  1076. -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
  1077. endif
  1078. % if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check':
  1079. endif
  1080. % endif
  1081. % for src in lib.src:
  1082. % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src):
  1083. $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))}
  1084. % endif
  1085. % endfor
  1086. </%def>
  1087. <%def name="maketarget(tgt)"><% has_no_sources = not tgt.src %>
  1088. % if not has_no_sources:
  1089. ${tgt.name.upper()}_SRC = \\
  1090. % for src in tgt.src:
  1091. ${proto_to_cc(src)} \\
  1092. % endfor
  1093. ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
  1094. % endif
  1095. % if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
  1096. ifeq ($(NO_SECURE),true)
  1097. # You can't build secure targets if you don't have OpenSSL with ALPN.
  1098. $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
  1099. else
  1100. % endif
  1101. ##
  1102. ## We're not trying to add a dependency on building zlib and openssl here,
  1103. ## as it's already done in the libraries. We're assuming that the build
  1104. ## trickles down, and that a secure target requires a secure version of
  1105. ## a library.
  1106. ##
  1107. ## That simplifies the codegen a bit, but prevents a fully defined Makefile.
  1108. ## I can live with that.
  1109. ##
  1110. % if tgt.build == 'protoc' or tgt.language == 'c++':
  1111. ifeq ($(NO_PROTOBUF),true)
  1112. # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+.
  1113. $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
  1114. else
  1115. $(BINDIR)/$(CONFIG)/${tgt.name}: \
  1116. % if not has_no_sources:
  1117. $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
  1118. % endif
  1119. % else:
  1120. $(BINDIR)/$(CONFIG)/${tgt.name}: \
  1121. % if not has_no_sources:
  1122. $(${tgt.name.upper()}_OBJS)\
  1123. % endif
  1124. % endif
  1125. % for dep in tgt.deps:
  1126. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  1127. % endfor
  1128. % if tgt.language == "c++":
  1129. ## C++ targets specificies.
  1130. % if tgt.build == 'protoc':
  1131. $(E) "[HOSTLD] Linking $@"
  1132. $(Q) mkdir -p `dirname $@`
  1133. $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) \
  1134. % if not has_no_sources:
  1135. $(${tgt.name.upper()}_OBJS)\
  1136. % endif
  1137. % else:
  1138. $(E) "[LD] Linking $@"
  1139. $(Q) mkdir -p `dirname $@`
  1140. $(Q) $(LDXX) $(LDFLAGS) \
  1141. % if not has_no_sources:
  1142. $(${tgt.name.upper()}_OBJS)\
  1143. % endif
  1144. % endif
  1145. % else:
  1146. ## C-only targets specificities.
  1147. $(E) "[LD] Linking $@"
  1148. $(Q) mkdir -p `dirname $@`
  1149. $(Q) $(LD) $(LDFLAGS) \
  1150. % if not has_no_sources:
  1151. $(${tgt.name.upper()}_OBJS)\
  1152. % endif
  1153. % endif
  1154. % for dep in tgt.deps:
  1155. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  1156. % endfor
  1157. % if tgt.language == "c++":
  1158. % if tgt.build == 'protoc':
  1159. $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
  1160. % else:
  1161. $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
  1162. % endif
  1163. % endif
  1164. % if tgt.build == 'protoc':
  1165. $(HOST_LDLIBS)\
  1166. % else:
  1167. $(LDLIBS)\
  1168. % endif
  1169. % if tgt.build == 'protoc':
  1170. $(HOST_LDLIBS_PROTOC)\
  1171. % elif tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
  1172. $(LDLIBS_SECURE)\
  1173. % endif
  1174. % if tgt.language == 'c++' and tgt.build == 'test':
  1175. $(GTEST_LIB)\
  1176. % elif tgt.language == 'c++' and tgt.build == 'benchmark':
  1177. $(GTEST_LIB)\
  1178. % endif
  1179. -o $(BINDIR)/$(CONFIG)/${tgt.name}
  1180. % if tgt.build == 'protoc' or tgt.language == 'c++':
  1181. endif
  1182. % endif
  1183. % if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
  1184. endif
  1185. % endif
  1186. % for src in tgt.src:
  1187. $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
  1188. % for dep in tgt.deps:
  1189. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  1190. % endfor
  1191. % endfor
  1192. % if not has_no_sources:
  1193. deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
  1194. % endif
  1195. % if not has_no_sources:
  1196. % if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
  1197. ifneq ($(NO_SECURE),true)
  1198. % endif
  1199. ifneq ($(NO_DEPS),true)
  1200. -include $(${tgt.name.upper()}_OBJS:.o=.dep)
  1201. endif
  1202. % if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check':
  1203. endif
  1204. % endif
  1205. % endif
  1206. </%def>
  1207. ifneq ($(OPENSSL_DEP),)
  1208. # This is to ensure the embedded OpenSSL is built beforehand, properly
  1209. # installing headers to their final destination on the drive. We need this
  1210. # otherwise parallel compilation will fail if a source is compiled first.
  1211. % for src in sorted(sources_that_need_openssl):
  1212. % if src not in sources_that_don_t_need_openssl:
  1213. ${src}: $(OPENSSL_DEP)
  1214. % endif
  1215. % endfor
  1216. endif
  1217. .PHONY: all strip tools \
  1218. dep_error openssl_dep_error openssl_dep_message git_update stop \
  1219. buildtests buildtests_c buildtests_cxx \
  1220. test test_c test_cxx \
  1221. install install_c install_cxx \
  1222. install-headers install-headers_c install-headers_cxx \
  1223. install-shared install-shared_c install-shared_cxx \
  1224. install-static install-static_c install-static_cxx \
  1225. strip strip-shared strip-static \
  1226. strip_c strip-shared_c strip-static_c \
  1227. strip_cxx strip-shared_cxx strip-static_cxx \
  1228. dep_c dep_cxx bins_dep_c bins_dep_cxx \
  1229. clean