Makefile.template 33 KB

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