Makefile.template 57 KB

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