Makefile.template 57 KB

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