Makefile.template 56 KB

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