Makefile.template 58 KB

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