Makefile.template 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954
  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. RE2_DEP = $(LIBDIR)/$(CONFIG)/libre2.a
  542. RE2_MERGE_OBJS = $(LIBRE2_OBJS)
  543. RE2_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libre2.a
  544. UPB_DEP = $(LIBDIR)/$(CONFIG)/libupb.a
  545. UPB_MERGE_OBJS = $(LIBUPB_OBJS)
  546. UPB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libupb.a
  547. ifeq ($(EMBED_CARES),true)
  548. CARES_DEP = $(LIBDIR)/$(CONFIG)/libares.a
  549. CARES_MERGE_OBJS = $(LIBARES_OBJS)
  550. CARES_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libares.a
  551. CPPFLAGS := -Ithird_party/cares -Ithird_party/cares/cares $(CPPFLAGS)
  552. else
  553. ifeq ($(HAS_PKG_CONFIG),true)
  554. PC_REQUIRES_GRPC += libcares
  555. CPPFLAGS += $(shell $(PKG_CONFIG) --cflags libcares)
  556. LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libcares)
  557. LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l libcares))
  558. else
  559. PC_LIBS_GRPC += -lcares
  560. LIBS += cares
  561. endif
  562. endif
  563. OPENSSL_PKG_CONFIG = false
  564. PC_REQUIRES_SECURE =
  565. PC_LIBS_SECURE =
  566. ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true)
  567. EMBED_OPENSSL ?= false
  568. NO_SECURE ?= false
  569. else # HAS_SYSTEM_OPENSSL_ALPN=false
  570. ifneq ($(HAS_EMBEDDED_OPENSSL_ALPN),false)
  571. EMBED_OPENSSL ?= $(HAS_EMBEDDED_OPENSSL_ALPN)
  572. NO_SECURE ?= false
  573. else # HAS_EMBEDDED_OPENSSL_ALPN=false
  574. NO_SECURE ?= true
  575. endif # HAS_EMBEDDED_OPENSSL_ALPN
  576. endif # HAS_SYSTEM_OPENSSL_ALPN
  577. OPENSSL_DEP :=
  578. OPENSSL_MERGE_LIBS :=
  579. ifeq ($(NO_SECURE),false)
  580. ifeq ($(EMBED_OPENSSL),true)
  581. OPENSSL_DEP += $(LIBDIR)/$(CONFIG)/libboringssl.a
  582. OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/libboringssl.a
  583. OPENSSL_MERGE_OBJS += $(LIBBORINGSSL_OBJS)
  584. # need to prefix these to ensure overriding system libraries
  585. CPPFLAGS := -Ithird_party/boringssl-with-bazel/src/include $(CPPFLAGS)
  586. else ifneq ($(EMBED_OPENSSL),false)
  587. OPENSSL_DEP += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
  588. OPENSSL_MERGE_LIBS += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a
  589. OPENSSL_MERGE_OBJS += $(wildcard $(EMBED_OPENSSL)/grpc_obj/*.o)
  590. # need to prefix these to ensure overriding system libraries
  591. CPPFLAGS := -I$(EMBED_OPENSSL)/include $(CPPFLAGS)
  592. else # EMBED_OPENSSL=false
  593. ifeq ($(HAS_PKG_CONFIG),true)
  594. OPENSSL_PKG_CONFIG = true
  595. PC_REQUIRES_SECURE = openssl
  596. CPPFLAGS := $(shell $(PKG_CONFIG) --cflags openssl) $(CPPFLAGS)
  597. LDFLAGS_OPENSSL_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L openssl)
  598. ifeq ($(SYSTEM),Linux)
  599. ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),)
  600. LDFLAGS_OPENSSL_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L openssl | sed s/L/Wl,-rpath,/)
  601. endif # LDFLAGS_OPENSSL_PKG_CONFIG=''
  602. endif # System=Linux
  603. LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS)
  604. else # HAS_PKG_CONFIG=false
  605. LIBS_SECURE = $(OPENSSL_LIBS)
  606. endif # HAS_PKG_CONFIG
  607. ifeq ($(DISABLE_ALPN),true)
  608. CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0
  609. LIBS_SECURE = $(OPENSSL_LIBS)
  610. endif # DISABLE_ALPN
  611. PC_LIBS_SECURE = $(addprefix -l, $(LIBS_SECURE))
  612. endif # EMBED_OPENSSL
  613. endif # NO_SECURE
  614. ifeq ($(OPENSSL_PKG_CONFIG),true)
  615. LDLIBS_SECURE += $(shell $(PKG_CONFIG) --libs-only-l openssl)
  616. else
  617. LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
  618. endif
  619. # gpr .pc file
  620. PC_NAME = gpr
  621. PC_DESCRIPTION = gRPC platform support library
  622. PC_CFLAGS =
  623. PC_REQUIRES = $(PC_REQUIRES_GPR)
  624. PC_LIBS_PRIVATE = $(PC_LIBS_GPR)
  625. PC_LIB = -lgpr
  626. GPR_PC_FILE := $(CORE_PC_TEMPLATE)
  627. # grpc .pc file
  628. PC_NAME = gRPC
  629. PC_DESCRIPTION = high performance general RPC framework
  630. PC_CFLAGS =
  631. PC_REQUIRES = gpr $(PC_REQUIRES_GRPC) $(PC_REQUIRES_SECURE)
  632. PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) $(PC_LIBS_SECURE)
  633. PC_LIB = -lgrpc
  634. GRPC_PC_FILE := $(CORE_PC_TEMPLATE)
  635. # grpc_unsecure .pc file
  636. PC_NAME = gRPC unsecure
  637. PC_DESCRIPTION = high performance general RPC framework without SSL
  638. PC_CFLAGS =
  639. PC_REQUIRES = gpr $(PC_REQUIRES_GRPC)
  640. PC_LIBS_PRIVATE = $(PC_LIBS_GRPC)
  641. PC_LIB = -lgrpc_unsecure
  642. GRPC_UNSECURE_PC_FILE := $(CORE_PC_TEMPLATE)
  643. PROTOBUF_PKG_CONFIG = false
  644. PC_REQUIRES_GRPCXX =
  645. PC_LIBS_GRPCXX =
  646. CPPFLAGS := -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googlemock/include $(CPPFLAGS)
  647. PROTOC_PLUGINS_ALL =\
  648. % for tgt in targets:
  649. % if tgt.build == 'protoc':
  650. $(BINDIR)/$(CONFIG)/${tgt.name}\
  651. % endif
  652. % endfor
  653. PROTOC_PLUGINS_DIR = $(BINDIR)/$(CONFIG)
  654. ifeq ($(HAS_SYSTEM_PROTOBUF),true)
  655. ifeq ($(HAS_PKG_CONFIG),true)
  656. PROTOBUF_PKG_CONFIG = true
  657. PC_REQUIRES_GRPCXX = protobuf
  658. CPPFLAGS := $(CPPFLAGS) $(shell $(PKG_CONFIG) --cflags protobuf)
  659. LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L protobuf)
  660. ifeq ($(SYSTEM),Linux)
  661. ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),)
  662. LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L protobuf | sed s/L/Wl,-rpath,/)
  663. endif
  664. endif
  665. else
  666. PC_LIBS_GRPCXX = -lprotobuf
  667. endif
  668. PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
  669. else
  670. ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
  671. PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
  672. CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
  673. LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
  674. ifneq ($(USE_BUILT_PROTOC),false)
  675. PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
  676. PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL)
  677. else
  678. PROTOC_PLUGINS =
  679. PROTOC_PLUGINS_DIR = $(prefix)/bin
  680. endif
  681. else
  682. NO_PROTOBUF = true
  683. endif
  684. endif
  685. LIBS_PROTOBUF = protobuf
  686. LIBS_PROTOC = protoc protobuf
  687. HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
  688. ifeq ($(PROTOBUF_PKG_CONFIG),true)
  689. LDLIBS_PROTOBUF += $(shell $(PKG_CONFIG) --libs-only-l protobuf)
  690. else
  691. LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
  692. endif
  693. # grpc++ .pc file
  694. PC_NAME = gRPC++
  695. PC_DESCRIPTION = C++ wrapper for gRPC
  696. PC_CFLAGS =
  697. PC_REQUIRES = grpc $(PC_REQUIRES_GRPCXX)
  698. PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
  699. PC_LIB = -lgrpc++
  700. GRPCXX_PC_FILE := $(CPP_PC_TEMPLATE)
  701. # grpc++_unsecure .pc file
  702. PC_NAME = gRPC++ unsecure
  703. PC_DESCRIPTION = C++ wrapper for gRPC without SSL
  704. PC_CFLAGS =
  705. PC_REQUIRES = grpc_unsecure $(PC_REQUIRES_GRPCXX)
  706. PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX)
  707. PC_LIB = -lgrpc++_unsecure
  708. GRPCXX_UNSECURE_PC_FILE := $(CPP_PC_TEMPLATE)
  709. ifeq ($(MAKECMDGOALS),clean)
  710. NO_DEPS = true
  711. endif
  712. .SECONDARY = %.pb.h %.pb.cc
  713. ifeq ($(DEP_MISSING),)
  714. all: static shared plugins\
  715. % for tgt in targets:
  716. % if tgt.build == 'all':
  717. $(BINDIR)/$(CONFIG)/${tgt.name}\
  718. % endif
  719. % endfor
  720. dep_error:
  721. @echo "You shouldn't see this message - all of your dependencies are correct."
  722. else
  723. all: dep_error git_update stop
  724. dep_error:
  725. @echo
  726. @echo "DEPENDENCY ERROR"
  727. @echo
  728. @echo "You are missing system dependencies that are essential to build grpc,"
  729. @echo "and the third_party directory doesn't have them:"
  730. @echo
  731. @echo " $(DEP_MISSING)"
  732. @echo
  733. @echo "Installing the development packages for your system will solve"
  734. @echo "this issue. Please consult INSTALL to get more information."
  735. @echo
  736. @echo "If you need information about why these tests failed, run:"
  737. @echo
  738. @echo " make run_dep_checks"
  739. @echo
  740. endif
  741. git_update:
  742. ifeq ($(IS_GIT_FOLDER),true)
  743. @echo "Additionally, since you are in a git clone, you can download the"
  744. @echo "missing dependencies in third_party by running the following command:"
  745. @echo
  746. @echo " git submodule update --init"
  747. @echo
  748. endif
  749. openssl_dep_error: openssl_dep_message git_update stop
  750. protobuf_dep_error: protobuf_dep_message git_update stop
  751. protoc_dep_error: protoc_dep_message git_update stop
  752. openssl_dep_message:
  753. @echo
  754. @echo "DEPENDENCY ERROR"
  755. @echo
  756. @echo "The target you are trying to run requires an OpenSSL implementation."
  757. @echo "Your system doesn't have one, and either the third_party directory"
  758. @echo "doesn't have it, or your compiler can't build BoringSSL."
  759. @echo
  760. @echo "Please consult INSTALL to get more information."
  761. @echo
  762. @echo "If you need information about why these tests failed, run:"
  763. @echo
  764. @echo " make run_dep_checks"
  765. @echo
  766. protobuf_dep_message:
  767. @echo
  768. @echo "DEPENDENCY ERROR"
  769. @echo
  770. @echo "The target you are trying to run requires protobuf 3.12.0+"
  771. @echo "Your system doesn't have it, and neither does the third_party directory."
  772. @echo
  773. @echo "Please consult INSTALL to get more information."
  774. @echo
  775. @echo "If you need information about why these tests failed, run:"
  776. @echo
  777. @echo " make run_dep_checks"
  778. @echo
  779. protoc_dep_message:
  780. @echo
  781. @echo "DEPENDENCY ERROR"
  782. @echo
  783. @echo "The target you are trying to run requires protobuf-compiler 3.12.0+"
  784. @echo "Your system doesn't have it, and neither does the third_party directory."
  785. @echo
  786. @echo "Please consult INSTALL to get more information."
  787. @echo
  788. @echo "If you need information about why these tests failed, run:"
  789. @echo
  790. @echo " make run_dep_checks"
  791. @echo
  792. systemtap_dep_error:
  793. @echo
  794. @echo "DEPENDENCY ERROR"
  795. @echo
  796. @echo "Under the '$(CONFIG)' configutation, the target you are trying "
  797. @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other "
  798. @echo "platforms such as Solaris and *BSD). "
  799. @echo
  800. @echo "Please consult INSTALL to get more information."
  801. @echo
  802. stop:
  803. @false
  804. % for tgt in targets:
  805. ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
  806. % endfor
  807. run_dep_checks:
  808. $(OPENSSL_ALPN_CHECK_CMD) || true
  809. $(ZLIB_CHECK_CMD) || true
  810. $(PERFTOOLS_CHECK_CMD) || true
  811. $(PROTOBUF_CHECK_CMD) || true
  812. $(PROTOC_CHECK_VERSION_CMD) || true
  813. $(CARES_CHECK_CMD) || true
  814. third_party/protobuf/configure:
  815. $(E) "[AUTOGEN] Preparing protobuf"
  816. $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
  817. $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
  818. $(E) "[MAKE] Building protobuf"
  819. $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
  820. $(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))
  821. $(Q)$(MAKE) -C third_party/protobuf clean
  822. $(Q)$(MAKE) -C third_party/protobuf
  823. $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
  824. $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
  825. $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
  826. $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
  827. static: static_c static_cxx
  828. static_c: pc_c pc_c_unsecure cache.mk \
  829. % for lib in libs:
  830. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  831. % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
  832. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  833. % endif
  834. % endif
  835. % endfor
  836. static_cxx: pc_cxx pc_cxx_unsecure cache.mk \
  837. % for lib in libs:
  838. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  839. % if lib.build == 'all' and lib.language == 'c++':
  840. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  841. % endif
  842. % endif
  843. % endfor
  844. static_csharp: static_c \
  845. % for lib in libs:
  846. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  847. % if lib.build == 'all' and lib.language == 'csharp':
  848. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  849. % endif
  850. % endif
  851. % endfor
  852. shared: shared_c shared_cxx
  853. shared_c: pc_c pc_c_unsecure cache.mk\
  854. % for lib in libs:
  855. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  856. % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
  857. $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)\
  858. % endif
  859. % endif
  860. % endfor
  861. shared_cxx: pc_cxx pc_cxx_unsecure cache.mk\
  862. % for lib in libs:
  863. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  864. % if lib.build == 'all' and lib.language == 'c++':
  865. $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)\
  866. % endif
  867. % endif
  868. % endfor
  869. shared_csharp: shared_c \
  870. % for lib in libs:
  871. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  872. % if lib.build == 'all' and lib.language == 'csharp':
  873. $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)\
  874. % endif
  875. % endif
  876. % endfor
  877. grpc_csharp_ext: shared_csharp
  878. plugins: $(PROTOC_PLUGINS)
  879. privatelibs: privatelibs_c privatelibs_cxx
  880. privatelibs_c: \
  881. % for lib in libs:
  882. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  883. % if lib.build == 'private' and lib.language == 'c' and not lib.get('external_deps', None) and not lib.boringssl:
  884. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  885. % endif
  886. % endif
  887. % endfor
  888. pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc
  889. pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc
  890. pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc
  891. pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc
  892. ifeq ($(EMBED_OPENSSL),true)
  893. privatelibs_cxx: \
  894. % for lib in libs:
  895. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  896. % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None):
  897. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  898. % endif
  899. % endif
  900. % endfor
  901. else
  902. privatelibs_cxx: \
  903. % for lib in libs:
  904. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  905. % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None) and not lib.boringssl:
  906. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  907. % endif
  908. % endif
  909. % endfor
  910. endif
  911. buildtests: buildtests_c buildtests_cxx
  912. buildtests_c: privatelibs_c <%text>\</%text>
  913. % for tgt in targets:
  914. % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None):
  915. $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
  916. % endif
  917. % endfor
  918. ifeq ($(EMBED_OPENSSL),true)
  919. buildtests_cxx: privatelibs_cxx <%text>\</%text>
  920. % for tgt in targets:
  921. % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None):
  922. $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
  923. % endif
  924. % endfor
  925. else
  926. buildtests_cxx: privatelibs_cxx <%text>\</%text>
  927. % for tgt in targets:
  928. % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl:
  929. $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text>
  930. % endif
  931. % endfor
  932. endif
  933. test: test_c test_cxx
  934. flaky_test: flaky_test_c flaky_test_cxx
  935. test_c: buildtests_c
  936. % for tgt in targets:
  937. % 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):
  938. $(E) "[RUN] Testing ${tgt.name}"
  939. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  940. % endif
  941. % endfor
  942. flaky_test_c: buildtests_c
  943. % for tgt in targets:
  944. % 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):
  945. $(E) "[RUN] Testing ${tgt.name}"
  946. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  947. % endif
  948. % endfor
  949. test_cxx: buildtests_cxx
  950. % for tgt in targets:
  951. % 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):
  952. $(E) "[RUN] Testing ${tgt.name}"
  953. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  954. % endif
  955. % endfor
  956. flaky_test_cxx: buildtests_cxx
  957. % for tgt in targets:
  958. % 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):
  959. $(E) "[RUN] Testing ${tgt.name}"
  960. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  961. % endif
  962. % endfor
  963. test_python: static_c
  964. $(E) "[RUN] Testing python code"
  965. $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)
  966. tools: tools_c tools_cxx
  967. tools_c: privatelibs_c\
  968. % for tgt in targets:
  969. % if tgt.build == 'tool' and not tgt.language=='c++':
  970. $(BINDIR)/$(CONFIG)/${tgt.name}\
  971. % endif
  972. % endfor
  973. tools_cxx: privatelibs_cxx\
  974. % for tgt in targets:
  975. % if tgt.build == 'tool' and tgt.language=='c++':
  976. $(BINDIR)/$(CONFIG)/${tgt.name}\
  977. % endif
  978. % endfor
  979. buildbenchmarks: privatelibs\
  980. % for tgt in targets:
  981. % if tgt.build == 'benchmark':
  982. $(BINDIR)/$(CONFIG)/${tgt.name}\
  983. % endif
  984. % endfor
  985. benchmarks: buildbenchmarks
  986. strip: strip-static strip-shared
  987. strip-static: strip-static_c strip-static_cxx
  988. strip-shared: strip-shared_c strip-shared_cxx
  989. # TODO(nnoble): the strip target is stripping in-place, instead
  990. # of copying files in a temporary folder.
  991. # This prevents proper debugging after running make install.
  992. strip-static_c: static_c
  993. ifeq ($(CONFIG),opt)
  994. % for lib in libs:
  995. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  996. % if lib.language == "c":
  997. % if lib.build == "all":
  998. % if not lib.get('external_deps', None):
  999. $(E) "[STRIP] Stripping lib${lib.name}.a"
  1000. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  1001. % endif
  1002. % endif
  1003. % endif
  1004. % endif
  1005. % endfor
  1006. endif
  1007. strip-static_cxx: static_cxx
  1008. ifeq ($(CONFIG),opt)
  1009. % for lib in libs:
  1010. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  1011. % if lib.language == "c++":
  1012. % if lib.build == "all":
  1013. $(E) "[STRIP] Stripping lib${lib.name}.a"
  1014. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  1015. % endif
  1016. % endif
  1017. % endif
  1018. % endfor
  1019. endif
  1020. strip-shared_c: shared_c
  1021. ifeq ($(CONFIG),opt)
  1022. % for lib in libs:
  1023. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  1024. % if lib.language == "c":
  1025. % if lib.build == "all":
  1026. % if not lib.get('external_deps', None):
  1027. $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)"
  1028. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)
  1029. % endif
  1030. % endif
  1031. % endif
  1032. % endif
  1033. % endfor
  1034. endif
  1035. strip-shared_cxx: shared_cxx
  1036. ifeq ($(CONFIG),opt)
  1037. % for lib in libs:
  1038. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  1039. % if lib.language == "c++":
  1040. % if lib.build == "all":
  1041. $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)"
  1042. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)
  1043. % endif
  1044. % endif
  1045. % endif
  1046. % endfor
  1047. endif
  1048. strip-shared_csharp: shared_csharp
  1049. ifeq ($(CONFIG),opt)
  1050. % for lib in libs:
  1051. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  1052. % if lib.language == "csharp":
  1053. % if lib.build == "all":
  1054. $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)"
  1055. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)
  1056. % endif
  1057. % endif
  1058. % endif
  1059. % endfor
  1060. endif
  1061. cache.mk::
  1062. $(E) "[MAKE] Generating $@"
  1063. $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@
  1064. $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc:
  1065. $(E) "[MAKE] Generating $@"
  1066. $(Q) mkdir -p $(@D)
  1067. $(Q) echo "$(GPR_PC_FILE)" | tr , '\n' >$@
  1068. $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc:
  1069. $(E) "[MAKE] Generating $@"
  1070. $(Q) mkdir -p $(@D)
  1071. $(Q) echo "$(GRPC_PC_FILE)" | tr , '\n' >$@
  1072. $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc:
  1073. $(E) "[MAKE] Generating $@"
  1074. $(Q) mkdir -p $(@D)
  1075. $(Q) echo "$(GRPC_UNSECURE_PC_FILE)" | tr , '\n' >$@
  1076. $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc:
  1077. $(E) "[MAKE] Generating $@"
  1078. $(Q) mkdir -p $(@D)
  1079. $(Q) echo "$(GRPCXX_PC_FILE)" | tr , '\n' >$@
  1080. $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc:
  1081. $(E) "[MAKE] Generating $@"
  1082. $(Q) mkdir -p $(@D)
  1083. $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@
  1084. % for p in protos:
  1085. ifeq ($(NO_PROTOC),true)
  1086. $(GENDIR)/${p}.pb.cc: protoc_dep_error
  1087. $(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error
  1088. else
  1089. <%
  1090. pluginflags=""
  1091. %>
  1092. % if p in ["src/proto/grpc/testing/compiler_test", "src/proto/grpc/testing/echo"]:
  1093. <%
  1094. pluginflags="generate_mock_code=true:"
  1095. %>
  1096. % endif
  1097. $(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) ${' '.join('$(GENDIR)/%s.pb.cc' % q for q in proto_deps.get(p, []))}
  1098. $(E) "[PROTOC] Generating protobuf CC file from $<"
  1099. $(Q) mkdir -p `dirname $@`
  1100. $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --cpp_out=$(GENDIR) $<
  1101. $(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, []))}
  1102. $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<"
  1103. $(Q) mkdir -p `dirname $@`
  1104. $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=${pluginflags}$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $<
  1105. endif
  1106. % endfor
  1107. ifeq ($(CONFIG),stapprof)
  1108. src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h
  1109. ifeq ($(HAS_SYSTEMTAP),true)
  1110. $(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d
  1111. $(E) "[DTRACE] Compiling $<"
  1112. $(Q) mkdir -p `dirname $@`
  1113. $(Q) $(DTRACE) -C -h -s $< -o $@
  1114. else
  1115. $(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop
  1116. endif
  1117. endif
  1118. $(OBJDIR)/$(CONFIG)/%.o : %.c
  1119. $(E) "[C] Compiling $<"
  1120. $(Q) mkdir -p `dirname $@`
  1121. $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  1122. $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
  1123. $(E) "[CXX] Compiling $<"
  1124. $(Q) mkdir -p `dirname $@`
  1125. $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  1126. $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
  1127. $(E) "[HOSTCXX] Compiling $<"
  1128. $(Q) mkdir -p `dirname $@`
  1129. $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  1130. $(OBJDIR)/$(CONFIG)/src/core/%.o : src/core/%.cc
  1131. $(E) "[CXX] Compiling $<"
  1132. $(Q) mkdir -p `dirname $@`
  1133. $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  1134. $(OBJDIR)/$(CONFIG)/test/core/%.o : test/core/%.cc
  1135. $(E) "[CXX] Compiling $<"
  1136. $(Q) mkdir -p `dirname $@`
  1137. $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  1138. $(OBJDIR)/$(CONFIG)/%.o : %.cc
  1139. $(E) "[CXX] Compiling $<"
  1140. $(Q) mkdir -p `dirname $@`
  1141. $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  1142. $(OBJDIR)/$(CONFIG)/%.o : %.cpp
  1143. $(E) "[CXX] Compiling $<"
  1144. $(Q) mkdir -p `dirname $@`
  1145. $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  1146. install: install_c install_cxx install-plugins install-certs
  1147. install_c: install-headers_c install-static_c install-shared_c
  1148. install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
  1149. install_csharp: install-shared_csharp install_c
  1150. install_grpc_csharp_ext: install_csharp
  1151. install-headers: install-headers_c install-headers_cxx
  1152. install-headers_c:
  1153. $(E) "[INSTALL] Installing public C headers"
  1154. $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
  1155. $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
  1156. install-headers_cxx:
  1157. $(E) "[INSTALL] Installing public C++ headers"
  1158. $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
  1159. $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
  1160. install-static: install-static_c install-static_cxx
  1161. install-static_c: static_c strip-static_c install-pkg-config_c
  1162. % for lib in libs:
  1163. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  1164. % if lib.language == "c":
  1165. % if lib.build == "all":
  1166. % if not lib.get('external_deps', None):
  1167. $(E) "[INSTALL] Installing lib${lib.name}.a"
  1168. $(Q) $(INSTALL) -d $(prefix)/lib
  1169. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
  1170. % endif
  1171. % endif
  1172. % endif
  1173. % endif
  1174. % endfor
  1175. install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx
  1176. % for lib in libs:
  1177. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  1178. % if lib.language == "c++":
  1179. % if lib.build == "all":
  1180. $(E) "[INSTALL] Installing lib${lib.name}.a"
  1181. $(Q) $(INSTALL) -d $(prefix)/lib
  1182. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
  1183. % endif
  1184. % endif
  1185. % endif
  1186. % endfor
  1187. <%def name="install_shared(lang_filter)">\
  1188. % for lib in libs:
  1189. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  1190. % if lib.language == lang_filter:
  1191. % if lib.build == "all":
  1192. % if not lib.get('external_deps', None):
  1193. $(E) "[INSTALL] Installing $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]})"
  1194. $(Q) $(INSTALL) -d $(prefix)/lib
  1195. $(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]})
  1196. ifeq ($(SYSTEM),MINGW32)
  1197. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]})-dll.a $(prefix)/lib/lib${lib.name}.a
  1198. else ifneq ($(SYSTEM),Darwin)
  1199. $(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}
  1200. $(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
  1201. endif
  1202. % endif
  1203. % endif
  1204. % endif
  1205. % endif
  1206. % endfor
  1207. ifneq ($(SYSTEM),MINGW32)
  1208. ifneq ($(SYSTEM),Darwin)
  1209. $(Q) ldconfig || true
  1210. endif
  1211. endif
  1212. </%def>
  1213. install-shared_c: shared_c strip-shared_c install-pkg-config_c
  1214. ${install_shared("c")}
  1215. install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c install-pkg-config_cxx
  1216. ${install_shared("c++")}
  1217. install-shared_csharp: shared_csharp strip-shared_csharp
  1218. ${install_shared("csharp")}
  1219. install-plugins: $(PROTOC_PLUGINS)
  1220. $(E) "[INSTALL] Installing grpc protoc plugins"
  1221. % for tgt in targets:
  1222. % if tgt.build == 'protoc':
  1223. $(Q) $(INSTALL) -d $(prefix)/bin
  1224. $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
  1225. % endif
  1226. % endfor
  1227. install-grpc-cli: grpc_cli
  1228. $(E) "[INSTALL] Installing grpc cli"
  1229. $(Q) $(INSTALL) -d $(prefix)/bin
  1230. $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/grpc_cli $(prefix)/bin/grpc_cli
  1231. install-pkg-config_c: pc_c pc_c_unsecure
  1232. $(E) "[INSTALL] Installing C pkg-config files"
  1233. $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
  1234. $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc $(prefix)/lib/pkgconfig/gpr.pc
  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-pkg-config_cxx: pc_cxx pc_cxx_unsecure
  1238. $(E) "[INSTALL] Installing C++ pkg-config files"
  1239. $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig
  1240. $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc $(prefix)/lib/pkgconfig/grpc++.pc
  1241. $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc $(prefix)/lib/pkgconfig/grpc++_unsecure.pc
  1242. install-certs: etc/roots.pem
  1243. $(E) "[INSTALL] Installing root certificates"
  1244. $(Q) $(INSTALL) -d $(prefix)/share/grpc
  1245. $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
  1246. clean:
  1247. $(E) "[CLEAN] Cleaning build directories."
  1248. $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk
  1249. # The various libraries
  1250. % for lib in libs:
  1251. % if 'Makefile' in lib.get('build_system', ['Makefile']):
  1252. ${makelib(lib)}
  1253. % endif
  1254. % endfor
  1255. # Add private ABSEIL target which contains all sources used by all baselib libraries.
  1256. <%
  1257. # Collect all abseil source and header files used by gpr, grpc, so on.
  1258. used_abseil_rules = set()
  1259. for lib in libs:
  1260. if lib.get("baselib"):
  1261. for dep in lib.transitive_deps:
  1262. if is_absl_lib(dep):
  1263. used_abseil_rules.add(dep)
  1264. used_abseil_srcs = []
  1265. used_abseil_hdrs = []
  1266. for lib in libs:
  1267. if lib.name in used_abseil_rules:
  1268. used_abseil_srcs.extend(lib.get("src", []))
  1269. used_abseil_hdrs.extend(lib.get("hdr", []))
  1270. # Create `grpc_abseil` rule with collected files.
  1271. lib_type = type(libs[0])
  1272. grpc_abseil_lib = lib_type({
  1273. "name": "grpc_abseil",
  1274. "build": "private",
  1275. "language": "c",
  1276. "defaults": "abseil",
  1277. "src": sorted(used_abseil_srcs),
  1278. "hdr": sorted(used_abseil_hdrs),
  1279. "secure": False,
  1280. })
  1281. %>
  1282. ${makelib(grpc_abseil_lib)}
  1283. # All of the test targets, and protoc plugins
  1284. % for tgt in targets:
  1285. ${maketarget(tgt)}
  1286. % endfor
  1287. <%def name="makelib(lib)">
  1288. LIB${lib.name.upper()}_SRC = \\
  1289. % for src in lib.src:
  1290. ${proto_to_cc(src)} \\
  1291. % endfor
  1292. % if "public_headers" in lib:
  1293. % if lib.language == "c++":
  1294. PUBLIC_HEADERS_CXX += \\
  1295. % else:
  1296. PUBLIC_HEADERS_C += \\
  1297. % endif
  1298. % for hdr in lib.public_headers:
  1299. ${hdr} \\
  1300. % endfor
  1301. % endif
  1302. LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
  1303. % if lib.get('defaults', None):
  1304. % for name, value in defaults.get(lib.defaults).iteritems():
  1305. $(LIB${lib.name.upper()}_OBJS): ${name} += ${value}
  1306. % endfor
  1307. % endif
  1308. ## If the library requires OpenSSL, let's add some restrictions.
  1309. % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
  1310. ifeq ($(NO_SECURE),true)
  1311. # You can't build secure libraries if you don't have OpenSSL.
  1312. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
  1313. % if lib.build == "all":
  1314. $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}): openssl_dep_error
  1315. % endif
  1316. else
  1317. % if lib.language == 'c++':
  1318. ifeq ($(NO_PROTOBUF),true)
  1319. # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
  1320. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
  1321. % if lib.build == "all":
  1322. $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}): protobuf_dep_error
  1323. % endif
  1324. else
  1325. % endif
  1326. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(RE2_DEP) $(UPB_DEP) $(GRPC_ABSEIL_DEP) \
  1327. ## The else here corresponds to the if secure earlier.
  1328. % else:
  1329. % if lib.language == 'c++':
  1330. ifeq ($(NO_PROTOBUF),true)
  1331. # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
  1332. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
  1333. % if lib.build == "all":
  1334. $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}): protobuf_dep_error
  1335. % endif
  1336. else
  1337. % endif
  1338. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: \
  1339. % if lib.name not in ['z', 'ares', 'address_sorting', 're2', 'upb', 'grpc_abseil']:
  1340. $(ZLIB_DEP) \
  1341. $(CARES_DEP) \
  1342. $(ADDRESS_SORTING_DEP) \
  1343. $(RE2_DEP) \
  1344. $(UPB_DEP) \
  1345. $(GRPC_ABSEIL_DEP) \
  1346. % endif
  1347. % endif
  1348. % if lib.language == 'c++':
  1349. $(PROTOBUF_DEP)\
  1350. % endif
  1351. $(LIB${lib.name.upper()}_OBJS) \
  1352. % if lib.get('baselib', False):
  1353. $(LIBGPR_OBJS) \
  1354. $(LIBGRPC_ABSEIL_OBJS) \
  1355. $(ZLIB_MERGE_OBJS) \
  1356. $(CARES_MERGE_OBJS) \
  1357. $(ADDRESS_SORTING_MERGE_OBJS) \
  1358. $(RE2_MERGE_OBJS) \
  1359. $(UPB_MERGE_OBJS) \
  1360. % if lib.get('secure', 'check') == True:
  1361. $(OPENSSL_MERGE_OBJS) \
  1362. % endif
  1363. % endif
  1364. $(E) "[AR] Creating $@"
  1365. $(Q) mkdir -p `dirname $@`
  1366. $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  1367. $(Q) $(AR) $(ARFLAGS) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) \
  1368. % if lib.get('baselib', False):
  1369. $(LIBGPR_OBJS) \
  1370. $(LIBGRPC_ABSEIL_OBJS) \
  1371. $(ZLIB_MERGE_OBJS) \
  1372. $(CARES_MERGE_OBJS) \
  1373. $(ADDRESS_SORTING_MERGE_OBJS) \
  1374. $(RE2_MERGE_OBJS) \
  1375. $(UPB_MERGE_OBJS) \
  1376. % if lib.get('secure', 'check') == True:
  1377. $(OPENSSL_MERGE_OBJS) \
  1378. % endif
  1379. % endif
  1380. ifeq ($(SYSTEM),Darwin)
  1381. $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  1382. endif
  1383. <%
  1384. if lib.language == 'c++':
  1385. ld = '$(LDXX)'
  1386. else:
  1387. ld = '$(LDXX)'
  1388. out_mingbase = '$(LIBDIR)/$(CONFIG)/' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
  1389. out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
  1390. common = '$(LIB' + lib.name.upper() + '_OBJS)'
  1391. link_libs = ''
  1392. lib_deps = ' $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(RE2_DEP) $(UPB_DEP) $(GRPC_ABSEIL_DEP)'
  1393. mingw_libs = ''
  1394. mingw_lib_deps = ' $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(RE2_DEP) $(UPB_DEP) $(GRPC_ABSEIL_DEP)'
  1395. if lib.language == 'c++':
  1396. lib_deps += ' $(PROTOBUF_DEP)'
  1397. mingw_lib_deps += ' $(PROTOBUF_DEP)'
  1398. if lib.get('deps_linkage', None) == 'static':
  1399. for dep in lib.get('deps', []):
  1400. if is_absl_lib(dep): continue
  1401. lib_archive = '$(LIBDIR)/$(CONFIG)/lib' + dep + '.a'
  1402. common = common + ' ' + lib_archive
  1403. lib_deps = lib_deps + ' ' + lib_archive
  1404. mingw_lib_deps = mingw_lib_deps + ' ' + lib_archive
  1405. else:
  1406. for dep in lib.get('deps', []):
  1407. if is_absl_lib(dep): continue
  1408. dep_lib = None
  1409. for dl in libs:
  1410. if dl.name == dep:
  1411. dep_lib = dl
  1412. assert dep_lib, 'lib %s not found (in %s)' % (dep, lib.name)
  1413. link_libs = link_libs + ' -l' + dep
  1414. lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT_' + lang_to_var[dep_lib.language] + ')'
  1415. mingw_libs = mingw_libs + ' -l' + dep + '$(SHARED_VERSION_' + lang_to_var[dep_lib.language] + ')-dll'
  1416. 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] + ')'
  1417. security = lib.get('secure', 'check')
  1418. if security == True:
  1419. common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)'
  1420. common = common + ' $(ZLIB_MERGE_LIBS) $(CARES_MERGE_LIBS) $(ADDRESS_SORTING_MERGE_LIBS) $(RE2_MERGE_LIBS) $(UPB_MERGE_LIBS) $(GRPC_ABSEIL_MERGE_LIBS)'
  1421. if security in [True, 'check']:
  1422. for src in lib.src:
  1423. if not proto_re.match(src):
  1424. sources_that_need_openssl.add(src)
  1425. else:
  1426. for src in lib.src:
  1427. sources_that_don_t_need_openssl.add(src)
  1428. if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
  1429. lib_deps = lib_deps + ' $(OPENSSL_DEP)'
  1430. mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
  1431. if lib.language == 'c++':
  1432. common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
  1433. ldflags = '$(LDFLAGS)'
  1434. if lib.get('LDFLAGS', None):
  1435. ldflags += ' ' + lib['LDFLAGS']
  1436. common = common + ' $(LDLIBS)'
  1437. %>
  1438. % if lib.build == "all":
  1439. ifeq ($(SYSTEM),MINGW32)
  1440. ${out_mingbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
  1441. $(E) "[LD] Linking $@"
  1442. $(Q) mkdir -p `dirname $@`
  1443. $(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}
  1444. else
  1445. ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
  1446. $(E) "[LD] Linking $@"
  1447. $(Q) mkdir -p `dirname $@`
  1448. ifeq ($(SYSTEM),Darwin)
  1449. $(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}
  1450. else
  1451. $(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}
  1452. $(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}
  1453. $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) ${out_libbase}.so
  1454. endif
  1455. endif
  1456. % endif
  1457. % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
  1458. ## If the lib was secure, we have to close the Makefile's if that tested
  1459. ## the presence of OpenSSL.
  1460. endif
  1461. % endif
  1462. % if lib.language == 'c++':
  1463. ## If the lib was C++, we have to close the Makefile's if that tested
  1464. ## the presence of protobuf 3.12.0+
  1465. endif
  1466. % endif
  1467. % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
  1468. ifneq ($(NO_SECURE),true)
  1469. % endif
  1470. ifneq ($(NO_DEPS),true)
  1471. -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
  1472. endif
  1473. % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check':
  1474. endif
  1475. % endif
  1476. % for src in lib.src:
  1477. % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src):
  1478. $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))}
  1479. % endif
  1480. % endfor
  1481. </%def>
  1482. <%def name="maketarget(tgt)"><% has_no_sources = not tgt.src %>
  1483. % if not has_no_sources:
  1484. ${tgt.name.upper()}_SRC = \\
  1485. % for src in tgt.src:
  1486. ${proto_to_cc(src)} \\
  1487. % endfor
  1488. ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
  1489. % endif
  1490. % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
  1491. ifeq ($(NO_SECURE),true)
  1492. # You can't build secure targets if you don't have OpenSSL.
  1493. $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
  1494. else
  1495. % endif
  1496. % if tgt.boringssl:
  1497. # boringssl needs an override to ensure that it does not include
  1498. # system openssl headers regardless of other configuration
  1499. # we do so here with a target specific variable assignment
  1500. $(${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)
  1501. $(${tgt.name.upper()}_OBJS): CXXFLAGS := -Ithird_party/boringssl-with-bazel/src/include $(CXXFLAGS)
  1502. $(${tgt.name.upper()}_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE
  1503. % else:
  1504. % endif
  1505. ##
  1506. ## We're not trying to add a dependency on building zlib and openssl here,
  1507. ## as it's already done in the libraries. We're assuming that the build
  1508. ## trickles down, and that a secure target requires a secure version of
  1509. ## a library.
  1510. ##
  1511. ## That simplifies the codegen a bit, but prevents a fully defined Makefile.
  1512. ## I can live with that.
  1513. ##
  1514. % if tgt.build == 'protoc' or tgt.language == 'c++':
  1515. ifeq ($(NO_PROTOBUF),true)
  1516. # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.12.0+.
  1517. $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
  1518. else
  1519. $(BINDIR)/$(CONFIG)/${tgt.name}: \
  1520. % if not has_no_sources:
  1521. $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
  1522. % endif
  1523. % else:
  1524. $(BINDIR)/$(CONFIG)/${tgt.name}: \
  1525. % if not has_no_sources:
  1526. $(${tgt.name.upper()}_OBJS)\
  1527. % endif
  1528. % endif
  1529. % for dep in tgt.deps:
  1530. % if not is_absl_lib(dep):
  1531. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  1532. % endif
  1533. % endfor
  1534. % if tgt.language == "c++" or tgt.boringssl or tgt.build == 'fuzzer':
  1535. ## C++ targets specificies.
  1536. % if tgt.build == 'protoc':
  1537. $(E) "[HOSTLD] Linking $@"
  1538. $(Q) mkdir -p `dirname $@`
  1539. $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) \
  1540. % if not has_no_sources:
  1541. $(${tgt.name.upper()}_OBJS)\
  1542. % endif
  1543. % else:
  1544. $(E) "[LD] Linking $@"
  1545. $(Q) mkdir -p `dirname $@`
  1546. $(Q) $(LDXX) $(LDFLAGS) \
  1547. % if not has_no_sources:
  1548. $(${tgt.name.upper()}_OBJS)\
  1549. % endif
  1550. % endif
  1551. % else:
  1552. ## C-only targets specificities.
  1553. $(E) "[LD] Linking $@"
  1554. $(Q) mkdir -p `dirname $@`
  1555. $(Q) $(LDXX) $(LDFLAGS) \
  1556. % if not has_no_sources:
  1557. $(${tgt.name.upper()}_OBJS)\
  1558. % endif
  1559. % endif
  1560. % for dep in tgt.deps:
  1561. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  1562. % endfor
  1563. % if tgt.language == "c++":
  1564. % if tgt.build == 'protoc':
  1565. $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
  1566. % else:
  1567. $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
  1568. % endif
  1569. % endif
  1570. % if tgt.build == 'protoc':
  1571. $(HOST_LDLIBS)\
  1572. % else:
  1573. $(LDLIBS)\
  1574. % endif
  1575. % if tgt.build == 'protoc':
  1576. $(HOST_LDLIBS_PROTOC)\
  1577. % elif tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
  1578. $(LDLIBS_SECURE)\
  1579. % endif
  1580. % if tgt.language == 'c++' and tgt.build == 'test':
  1581. $(GTEST_LIB)\
  1582. % elif tgt.language == 'c++' and tgt.build == 'benchmark':
  1583. $(GTEST_LIB)\
  1584. % endif
  1585. % if tgt.build == 'fuzzer':
  1586. -lFuzzer\
  1587. % endif
  1588. -o $(BINDIR)/$(CONFIG)/${tgt.name}
  1589. % if tgt.build == 'protoc' or tgt.language == 'c++':
  1590. endif
  1591. % endif
  1592. % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
  1593. endif
  1594. % endif
  1595. % if tgt.get('defaults', None):
  1596. % for name, value in defaults.get(tgt.defaults).iteritems():
  1597. $(${tgt.name.upper()}_OBJS): ${name} += ${value}
  1598. % endfor
  1599. % endif
  1600. % for src in tgt.src:
  1601. $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
  1602. % for dep in tgt.deps:
  1603. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  1604. % endfor
  1605. % if tgt.language == 'c89':
  1606. % for src in tgt.src:
  1607. $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o : ${src}
  1608. $(E) "[C] Compiling $<"
  1609. $(Q) mkdir -p `dirname $@`
  1610. $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -std=c89 -pedantic -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  1611. % endfor
  1612. % endif
  1613. % endfor
  1614. % if not has_no_sources:
  1615. deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
  1616. % endif
  1617. % if not has_no_sources:
  1618. % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
  1619. ifneq ($(NO_SECURE),true)
  1620. % endif
  1621. ifneq ($(NO_DEPS),true)
  1622. -include $(${tgt.name.upper()}_OBJS:.o=.dep)
  1623. endif
  1624. % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check':
  1625. endif
  1626. % endif
  1627. % endif
  1628. % for src in tgt.src:
  1629. % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in tgt.src):
  1630. $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in tgt.src if proto_re.match(src2))}
  1631. % endif
  1632. % endfor
  1633. </%def>
  1634. ifneq ($(OPENSSL_DEP),)
  1635. # This is to ensure the embedded OpenSSL is built beforehand, properly
  1636. # installing headers to their final destination on the drive. We need this
  1637. # otherwise parallel compilation will fail if a source is compiled first.
  1638. % for src in sorted(sources_that_need_openssl):
  1639. % if src not in sources_that_don_t_need_openssl:
  1640. ${src}: $(OPENSSL_DEP)
  1641. % endif
  1642. % endfor
  1643. endif
  1644. .PHONY: all strip tools \
  1645. dep_error openssl_dep_error openssl_dep_message git_update stop \
  1646. buildtests buildtests_c buildtests_cxx \
  1647. test test_c test_cxx \
  1648. install install_c install_cxx \
  1649. install-headers install-headers_c install-headers_cxx \
  1650. install-shared install-shared_c install-shared_cxx \
  1651. install-static install-static_c install-static_cxx \
  1652. strip strip-shared strip-static \
  1653. strip_c strip-shared_c strip-static_c \
  1654. strip_cxx strip-shared_cxx strip-static_cxx \
  1655. dep_c dep_cxx bins_dep_c bins_dep_cxx \
  1656. clean
  1657. .PHONY: printvars
  1658. printvars:
  1659. @$(foreach V,$(sort $(.VARIABLES)), \
  1660. $(if $(filter-out environment% default automatic, \
  1661. $(origin $V)),$(warning $V=$($V) ($(value $V)))))