Makefile.template 62 KB

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