Makefile.template 37 KB

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