Makefile.template 62 KB

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