Makefile.template 56 KB

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