Makefile.template 45 KB

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