Makefile.template 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  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_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_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_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_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_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. STRIP = strip --strip-unneeded
  142. INSTALL = install
  143. RM = rm -f
  144. ifndef VALID_CONFIG_$(CONFIG)
  145. $(error Invalid CONFIG value '$(CONFIG)')
  146. endif
  147. # Detect if we can use C++11
  148. CXX11_CHECK_CMD = $(CXX) -std=c++11 -o /dev/null -c test/build/c++11.cc
  149. HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false)
  150. # The HOST compiler settings are used to compile the protoc plugins.
  151. # In most cases, you won't have to change anything, but if you are
  152. # cross-compiling, you can override these variables from GNU make's
  153. # command line: make CC=cross-gcc HOST_CC=gcc
  154. HOST_CC = $(CC)
  155. HOST_CXX = $(CXX)
  156. HOST_LD = $(LD)
  157. HOST_LDXX = $(LDXX)
  158. CPPFLAGS += $(CPPFLAGS_$(CONFIG))
  159. DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
  160. LDFLAGS += $(LDFLAGS_$(CONFIG))
  161. CFLAGS += -std=c89 -pedantic
  162. ifeq ($(HAS_CXX11),true)
  163. CXXFLAGS += -std=c++11
  164. else
  165. CXXFLAGS += -std=c++0x
  166. DEFINES += GRPC_OLD_CXX
  167. endif
  168. CPPFLAGS += -g -fPIC -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter
  169. LDFLAGS += -g -fPIC
  170. INCLUDES = . include $(GENDIR)
  171. ifeq ($(SYSTEM),Darwin)
  172. INCLUDES += /usr/local/ssl/include /opt/local/include
  173. LIBS = m z
  174. LDFLAGS += -L/usr/local/ssl/lib -L/opt/local/lib
  175. else
  176. LIBS = rt m z pthread
  177. LDFLAGS += -pthread
  178. endif
  179. ifneq ($(wildcard /usr/src/gtest/src/gtest-all.cc),)
  180. GTEST_LIB = /usr/src/gtest/src/gtest-all.cc -I/usr/src/gtest
  181. else
  182. GTEST_LIB = -lgtest
  183. endif
  184. GTEST_LIB += -lgflags
  185. ifeq ($(V),1)
  186. E = @:
  187. Q =
  188. else
  189. E = @echo
  190. Q = @
  191. endif
  192. VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build}
  193. CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
  194. CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
  195. LDFLAGS += $(ARCH_FLAGS)
  196. LDLIBS += $(addprefix -l, $(LIBS))
  197. LDLIBSXX += $(addprefix -l, $(LIBSXX))
  198. HOST_CPPFLAGS = $(CPPFLAGS)
  199. HOST_CFLAGS = $(CFLAGS)
  200. HOST_CXXFLAGS = $(CXXFLAGS)
  201. HOST_LDFLAGS = $(LDFLAGS)
  202. HOST_LDLIBS = $(LDLIBS)
  203. # These are automatically computed variables.
  204. # There shouldn't be any need to change anything from now on.
  205. ifeq ($(SYSTEM),MINGW32)
  206. SHARED_EXT = dll
  207. endif
  208. ifeq ($(SYSTEM),Darwin)
  209. SHARED_EXT = dylib
  210. endif
  211. ifeq ($(SHARED_EXT),)
  212. SHARED_EXT = so.$(VERSION)
  213. endif
  214. ifeq ($(wildcard .git),)
  215. IS_GIT_FOLDER = false
  216. else
  217. IS_GIT_FOLDER = true
  218. endif
  219. OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/openssl-alpn.c -lssl -lcrypto -ldl $(LDFLAGS)
  220. ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/zlib.c -lz $(LDFLAGS)
  221. PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/perftools.c -lprofiler $(LDFLAGS)
  222. PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o /dev/null test/build/protobuf.cc -lprotobuf $(LDFLAGS)
  223. PROTOC_CMD = which protoc
  224. PROTOC_CHECK_CMD = protoc --version | grep -q libprotoc.3
  225. ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
  226. HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false)
  227. ifeq ($(HAS_SYSTEM_PERFTOOLS),true)
  228. DEFINES += GRPC_HAVE_PERFTOOLS
  229. LIBS += profiler
  230. endif
  231. endif
  232. HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false)
  233. ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG)
  234. HAS_SYSTEM_OPENSSL_ALPN = $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false)
  235. HAS_SYSTEM_ZLIB = $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false)
  236. HAS_SYSTEM_PROTOBUF = $(HAS_SYSTEM_PROTOBUF_VERIFY)
  237. else
  238. # override system libraries if the config requires a custom compiled library
  239. HAS_SYSTEM_OPENSSL_ALPN = false
  240. HAS_SYSTEM_ZLIB = false
  241. HAS_SYSTEM_PROTOBUF = false
  242. endif
  243. HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false)
  244. ifeq ($(HAS_PROTOC),true)
  245. HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
  246. else
  247. HAS_VALID_PROTOC = false
  248. endif
  249. ifeq ($(wildcard third_party/openssl/ssl/ssl.h),)
  250. HAS_EMBEDDED_OPENSSL_ALPN = false
  251. else
  252. HAS_EMBEDDED_OPENSSL_ALPN = true
  253. endif
  254. ifeq ($(wildcard third_party/zlib/zlib.h),)
  255. HAS_EMBEDDED_ZLIB = false
  256. else
  257. HAS_EMBEDDED_ZLIB = true
  258. endif
  259. ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),)
  260. HAS_EMBEDDED_PROTOBUF = false
  261. ifneq ($(HAS_VALID_PROTOC),true)
  262. NO_PROTOC = true
  263. endif
  264. else
  265. HAS_EMBEDDED_PROTOBUF = true
  266. endif
  267. ifeq ($(HAS_SYSTEM_ZLIB),false)
  268. ifeq ($(HAS_EMBEDDED_ZLIB),true)
  269. ZLIB_DEP = $(LIBDIR)/$(CONFIG)/zlib/libz.a
  270. CPPFLAGS += -Ithird_party/zlib
  271. LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib
  272. else
  273. DEP_MISSING += zlib
  274. endif
  275. endif
  276. ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false)
  277. ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true)
  278. OPENSSL_DEP = $(LIBDIR)/$(CONFIG)/openssl/libssl.a
  279. OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/openssl/libssl.a $(LIBDIR)/$(CONFIG)/openssl/libcrypto.a
  280. # need to prefix these to ensure overriding system libraries
  281. CPPFLAGS := -Ithird_party/openssl/include $(CPPFLAGS)
  282. LDFLAGS := -L$(LIBDIR)/$(CONFIG)/openssl $(LDFLAGS)
  283. LIBS_SECURE = dl
  284. else
  285. NO_SECURE = true
  286. endif
  287. else
  288. LIBS_SECURE = ssl crypto dl
  289. endif
  290. LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
  291. ifeq ($(HAS_SYSTEM_PROTOBUF),false)
  292. ifeq ($(HAS_EMBEDDED_PROTOBUF),true)
  293. PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a
  294. CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS)
  295. LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
  296. PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc
  297. else
  298. NO_PROTOBUF = true
  299. endif
  300. else
  301. endif
  302. LIBS_PROTOBUF = protobuf
  303. LIBS_PROTOC = protoc protobuf
  304. LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF))
  305. HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC))
  306. ifeq ($(MAKECMDGOALS),clean)
  307. NO_DEPS = true
  308. endif
  309. INSTALL_OK = false
  310. ifeq ($(HAS_VALID_PROTOC),true)
  311. ifeq ($(HAS_SYSTEM_PROTOBUF_VERIFY),true)
  312. INSTALL_OK = true
  313. endif
  314. endif
  315. .SECONDARY = %.pb.h %.pb.cc
  316. PROTOC_PLUGINS =\
  317. % for tgt in targets:
  318. % if tgt.build == 'protoc':
  319. $(BINDIR)/$(CONFIG)/${tgt.name}\
  320. % endif
  321. % endfor
  322. ifeq ($(DEP_MISSING),)
  323. all: static shared plugins\
  324. % for tgt in targets:
  325. % if tgt.build == 'all':
  326. $(BINDIR)/$(CONFIG)/${tgt.name}\
  327. % endif
  328. % endfor
  329. dep_error:
  330. @echo "You shouldn't see this message - all of your dependencies are correct."
  331. else
  332. all: dep_error git_update stop
  333. dep_error:
  334. @echo
  335. @echo "DEPENDENCY ERROR"
  336. @echo
  337. @echo "You are missing system dependencies that are essential to build grpc,"
  338. @echo "and the third_party directory doesn't have them:"
  339. @echo
  340. @echo " $(DEP_MISSING)"
  341. @echo
  342. @echo "Installing the development packages for your system will solve"
  343. @echo "this issue. Please consult INSTALL to get more information."
  344. @echo
  345. @echo "If you need information about why these tests failed, run:"
  346. @echo
  347. @echo " make run_dep_checks"
  348. @echo
  349. endif
  350. git_update:
  351. ifeq ($(IS_GIT_FOLDER),true)
  352. @echo "Additionally, since you are in a git clone, you can download the"
  353. @echo "missing dependencies in third_party by running the following command:"
  354. @echo
  355. @echo " git submodule update --init"
  356. @echo
  357. endif
  358. openssl_dep_error: openssl_dep_message git_update stop
  359. protobuf_dep_error: protobuf_dep_message git_update stop
  360. protoc_dep_error: protoc_dep_message git_update stop
  361. openssl_dep_message:
  362. @echo
  363. @echo "DEPENDENCY ERROR"
  364. @echo
  365. @echo "The target you are trying to run requires OpenSSL with ALPN support."
  366. @echo "Your system doesn't have it, and neither does the third_party directory."
  367. @echo
  368. @echo "Please consult INSTALL to get more information."
  369. @echo
  370. @echo "If you need information about why these tests failed, run:"
  371. @echo
  372. @echo " make run_dep_checks"
  373. @echo
  374. protobuf_dep_message:
  375. @echo
  376. @echo "DEPENDENCY ERROR"
  377. @echo
  378. @echo "The target you are trying to run requires protobuf 3.0.0+"
  379. @echo "Your system doesn't have it, and neither does the third_party directory."
  380. @echo
  381. @echo "Please consult INSTALL to get more information."
  382. @echo
  383. @echo "If you need information about why these tests failed, run:"
  384. @echo
  385. @echo " make run_dep_checks"
  386. @echo
  387. protoc_dep_message:
  388. @echo
  389. @echo "DEPENDENCY ERROR"
  390. @echo
  391. @echo "The target you are trying to run requires protobuf-compiler 3.0.0+"
  392. @echo "Your system doesn't have it, and neither does the third_party directory."
  393. @echo
  394. @echo "Please consult INSTALL to get more information."
  395. @echo
  396. @echo "If you need information about why these tests failed, run:"
  397. @echo
  398. @echo " make run_dep_checks"
  399. @echo
  400. stop:
  401. @false
  402. % for tgt in targets:
  403. ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
  404. % endfor
  405. run_dep_checks:
  406. $(OPENSSL_ALPN_CHECK_CMD) || true
  407. $(ZLIB_CHECK_CMD) || true
  408. $(PERFTOOLS_CHECK_CMD) || true
  409. $(PROTOBUF_CHECK_CMD) || true
  410. $(PROTOC_CHECK_CMD) || true
  411. $(LIBDIR)/$(CONFIG)/zlib/libz.a:
  412. $(E) "[MAKE] Building zlib"
  413. $(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="-fPIC -fvisibility=hidden $(CPPFLAGS_$(CONFIG))" ./configure --static)
  414. $(Q)$(MAKE) -C third_party/zlib clean
  415. $(Q)$(MAKE) -C third_party/zlib
  416. $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/zlib
  417. $(Q)cp third_party/zlib/libz.a $(LIBDIR)/$(CONFIG)/zlib
  418. $(LIBDIR)/$(CONFIG)/openssl/libssl.a:
  419. $(E) "[MAKE] Building openssl for $(SYSTEM)"
  420. ifeq ($(SYSTEM),Darwin)
  421. $(Q)(cd third_party/openssl ; CC="$(CC) -fPIC -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./Configure darwin64-x86_64-cc)
  422. else
  423. $(Q)(cd third_party/openssl ; CC="$(CC) -fPIC -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG))" ./config no-asm $(OPENSSL_CONFIG_$(CONFIG)))
  424. endif
  425. $(Q)$(MAKE) -C third_party/openssl clean
  426. $(Q)$(MAKE) -C third_party/openssl build_crypto build_ssl
  427. $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/openssl
  428. $(Q)cp third_party/openssl/libssl.a third_party/openssl/libcrypto.a $(LIBDIR)/$(CONFIG)/openssl
  429. third_party/protobuf/configure:
  430. $(E) "[AUTOGEN] Preparing protobuf"
  431. $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete)
  432. $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure
  433. $(E) "[MAKE] Building protobuf"
  434. ifeq ($(HAVE_CXX11),true)
  435. $(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)
  436. else
  437. $(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)
  438. endif
  439. $(Q)$(MAKE) -C third_party/protobuf clean
  440. $(Q)$(MAKE) -C third_party/protobuf
  441. $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf
  442. $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf
  443. $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf
  444. $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf
  445. $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf
  446. static: static_c static_cxx
  447. static_c: \
  448. % for lib in libs:
  449. % if lib.build == 'all' and lib.language == 'c':
  450. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  451. % endif
  452. % endfor
  453. static_cxx: \
  454. % for lib in libs:
  455. % if lib.build == 'all' and lib.language == 'c++':
  456. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  457. % endif
  458. % endfor
  459. shared: shared_c shared_cxx
  460. shared_c: \
  461. % for lib in libs:
  462. % if lib.build == 'all' and lib.language == 'c':
  463. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
  464. % endif
  465. % endfor
  466. shared_cxx: \
  467. % for lib in libs:
  468. % if lib.build == 'all' and lib.language == 'c++':
  469. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
  470. % endif
  471. % endfor
  472. shared_csharp: shared_c \
  473. % for lib in libs:
  474. % if lib.build == 'all' and lib.language == 'csharp':
  475. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\
  476. % endif
  477. % endfor
  478. grpc_csharp_ext: shared_csharp
  479. plugins: $(PROTOC_PLUGINS)
  480. privatelibs: privatelibs_c privatelibs_cxx
  481. privatelibs_c: \
  482. % for lib in libs:
  483. % if lib.build == 'private' and lib.language == 'c':
  484. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  485. % endif
  486. % endfor
  487. privatelibs_cxx: \
  488. % for lib in libs:
  489. % if lib.build == 'private' and lib.language == 'c++':
  490. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
  491. % endif
  492. % endfor
  493. buildtests: buildtests_c buildtests_cxx
  494. buildtests_c: privatelibs_c\
  495. % for tgt in targets:
  496. % if tgt.build == 'test' and not tgt.language == 'c++':
  497. $(BINDIR)/$(CONFIG)/${tgt.name}\
  498. % endif
  499. % endfor
  500. buildtests_cxx: privatelibs_cxx\
  501. % for tgt in targets:
  502. % if tgt.build == 'test' and tgt.language == 'c++':
  503. $(BINDIR)/$(CONFIG)/${tgt.name}\
  504. % endif
  505. % endfor
  506. test: test_c test_cxx
  507. test_c: buildtests_c
  508. % for tgt in targets:
  509. % if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++':
  510. $(E) "[RUN] Testing ${tgt.name}"
  511. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  512. % endif
  513. % endfor
  514. test_cxx: buildtests_cxx
  515. % for tgt in targets:
  516. % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++':
  517. $(E) "[RUN] Testing ${tgt.name}"
  518. $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 )
  519. % endif
  520. % endfor
  521. tools: privatelibs\
  522. % for tgt in targets:
  523. % if tgt.build == 'tool':
  524. $(BINDIR)/$(CONFIG)/${tgt.name}\
  525. % endif
  526. % endfor
  527. buildbenchmarks: privatelibs\
  528. % for tgt in targets:
  529. % if tgt.build == 'benchmark':
  530. $(BINDIR)/$(CONFIG)/${tgt.name}\
  531. % endif
  532. % endfor
  533. benchmarks: buildbenchmarks
  534. strip: strip-static strip-shared
  535. strip-static: strip-static_c strip-static_cxx
  536. strip-shared: strip-shared_c strip-shared_cxx
  537. # TODO(nnoble): the strip target is stripping in-place, instead
  538. # of copying files in a temporary folder.
  539. # This prevents proper debugging after running make install.
  540. strip-static_c: static_c
  541. ifeq ($(CONFIG),opt)
  542. % for lib in libs:
  543. % if lib.language == "c":
  544. % if lib.build == "all":
  545. $(E) "[STRIP] Stripping lib${lib.name}.a"
  546. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  547. % endif
  548. % endif
  549. % endfor
  550. endif
  551. strip-static_cxx: static_cxx
  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-shared_c: shared_c
  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}.so"
  568. $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)
  569. % endif
  570. % endif
  571. % endfor
  572. endif
  573. strip-shared_cxx: shared_cxx
  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_csharp: shared_csharp
  585. ifeq ($(CONFIG),opt)
  586. % for lib in libs:
  587. % if lib.language == "csharp":
  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. % for p in protos:
  596. ifeq ($(NO_PROTOC),true)
  597. $(GENDIR)/${p}.pb.cc: protoc_dep_error
  598. else
  599. $(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS)
  600. $(E) "[PROTOC] Generating protobuf CC file from $<"
  601. $(Q) mkdir -p `dirname $@`
  602. $(Q) $(PROTOC) --cpp_out=$(GENDIR) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $<
  603. endif
  604. % endfor
  605. $(OBJDIR)/$(CONFIG)/%.o : %.c
  606. $(E) "[C] Compiling $<"
  607. $(Q) mkdir -p `dirname $@`
  608. $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  609. $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
  610. $(E) "[CXX] Compiling $<"
  611. $(Q) mkdir -p `dirname $@`
  612. $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  613. $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
  614. $(E) "[HOSTCXX] Compiling $<"
  615. $(Q) mkdir -p `dirname $@`
  616. $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  617. $(OBJDIR)/$(CONFIG)/%.o : %.cc
  618. $(E) "[CXX] Compiling $<"
  619. $(Q) mkdir -p `dirname $@`
  620. $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
  621. install: install_c install_cxx install-plugins install-certs verify-install
  622. install_c: install-headers_c install-static_c install-shared_c
  623. install_cxx: install-headers_cxx install-static_cxx install-shared_cxx
  624. install_csharp: install-shared_csharp install_c
  625. install_grpc_csharp_ext: install_csharp
  626. install-headers: install-headers_c install-headers_cxx
  627. install-headers_c:
  628. $(E) "[INSTALL] Installing public C headers"
  629. $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
  630. $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
  631. install-headers_cxx:
  632. $(E) "[INSTALL] Installing public C++ headers"
  633. $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1
  634. $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1
  635. install-static: install-static_c install-static_cxx
  636. install-static_c: static_c strip-static_c
  637. % for lib in libs:
  638. % if lib.language == "c":
  639. % if lib.build == "all":
  640. $(E) "[INSTALL] Installing lib${lib.name}.a"
  641. $(Q) $(INSTALL) -d $(prefix)/lib
  642. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
  643. % endif
  644. % endif
  645. % endfor
  646. install-static_cxx: static_cxx strip-static_cxx
  647. % for lib in libs:
  648. % if lib.language == "c++":
  649. % if lib.build == "all":
  650. $(E) "[INSTALL] Installing lib${lib.name}.a"
  651. $(Q) $(INSTALL) -d $(prefix)/lib
  652. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a
  653. % endif
  654. % endif
  655. % endfor
  656. <%def name="install_shared(lang_filter)">\
  657. % for lib in libs:
  658. % if lib.language == lang_filter:
  659. % if lib.build == "all":
  660. ifeq ($(SYSTEM),MINGW32)
  661. $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)"
  662. $(Q) $(INSTALL) -d $(prefix)/lib
  663. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT)
  664. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a
  665. else
  666. $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)"
  667. $(Q) $(INSTALL) -d $(prefix)/lib
  668. $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT)
  669. ifneq ($(SYSTEM),Darwin)
  670. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so
  671. endif
  672. endif
  673. % endif
  674. % endif
  675. % endfor
  676. ifneq ($(SYSTEM),MINGW32)
  677. ifneq ($(SYSTEM),Darwin)
  678. $(Q) ldconfig || true
  679. endif
  680. endif
  681. </%def>
  682. install-shared_c: shared_c strip-shared_c
  683. ${install_shared("c")}
  684. install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c
  685. ${install_shared("c++")}
  686. install-shared_csharp: shared_csharp strip-shared_csharp
  687. ${install_shared("csharp")}
  688. install-plugins: $(PROTOC_PLUGINS)
  689. ifeq ($(SYSTEM),MINGW32)
  690. $(Q) false
  691. else
  692. $(E) "[INSTALL] Installing grpc protoc plugins"
  693. % for tgt in targets:
  694. % if tgt.build == 'protoc':
  695. $(Q) $(INSTALL) -d $(prefix)/bin
  696. $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name}
  697. % endif
  698. % endfor
  699. endif
  700. install-certs: etc/roots.pem
  701. $(E) "[INSTALL] Installing root certificates"
  702. $(Q) $(INSTALL) -d $(prefix)/share/grpc
  703. $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
  704. verify-install:
  705. ifeq ($(INSTALL_OK),true)
  706. @echo "Your system looks ready to go."
  707. @echo
  708. else
  709. @echo "Your system doesn't have protoc 3.0.0+ installed. While this"
  710. @echo "won't prevent grpc from working, you won't be able to compile"
  711. @echo "and run any meaningful code with it."
  712. @echo
  713. @echo
  714. @echo "Please download and install protobuf 3.0.0+ from:"
  715. @echo
  716. @echo " https://github.com/google/protobuf/releases"
  717. @echo
  718. @echo "Once you've done so, you can re-run this check by doing:"
  719. @echo
  720. @echo " make verify-install"
  721. endif
  722. clean:
  723. $(E) "[CLEAN] Cleaning build directories."
  724. $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR)
  725. # The various libraries
  726. % for lib in libs:
  727. ${makelib(lib)}
  728. % endfor
  729. # All of the test targets, and protoc plugins
  730. % for tgt in targets:
  731. ${maketarget(tgt)}
  732. % endfor
  733. <%def name="makelib(lib)">
  734. LIB${lib.name.upper()}_SRC = \\
  735. % for src in lib.src:
  736. ${proto_to_cc(src)} \\
  737. % endfor
  738. % if "public_headers" in lib:
  739. % if lib.language == "c++":
  740. PUBLIC_HEADERS_CXX += \\
  741. % else:
  742. PUBLIC_HEADERS_C += \\
  743. % endif
  744. % for hdr in lib.public_headers:
  745. ${hdr} \\
  746. % endfor
  747. % endif
  748. LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
  749. ## If the library requires OpenSSL with ALPN, let's add some restrictions.
  750. % if lib.get('secure', True):
  751. ifeq ($(NO_SECURE),true)
  752. # You can't build secure libraries if you don't have OpenSSL with ALPN.
  753. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
  754. % if lib.build == "all":
  755. ifeq ($(SYSTEM),MINGW32)
  756. $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error
  757. else
  758. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error
  759. endif
  760. % endif
  761. else
  762. % if lib.language == 'c++':
  763. ifeq ($(NO_PROTOBUF),true)
  764. # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
  765. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
  766. % if lib.build == "all":
  767. ifeq ($(SYSTEM),MINGW32)
  768. $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
  769. else
  770. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
  771. endif
  772. % endif
  773. else
  774. % endif
  775. ifneq ($(OPENSSL_DEP),)
  776. # This is to ensure the embedded OpenSSL is built beforehand, properly
  777. # installing headers to their final destination on the drive. We need this
  778. # otherwise parallel compilation will fail if a source is compiled first.
  779. % for src in lib.src:
  780. ${src}: $(OPENSSL_DEP)
  781. % endfor
  782. endif
  783. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
  784. ## The else here corresponds to the if secure earlier.
  785. % else:
  786. % if lib.language == 'c++':
  787. ifeq ($(NO_PROTOBUF),true)
  788. # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
  789. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
  790. % if lib.build == "all":
  791. ifeq ($(SYSTEM),MINGW32)
  792. $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
  793. else
  794. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
  795. endif
  796. % endif
  797. else
  798. % endif
  799. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP)\
  800. % endif
  801. % if lib.language == 'c++':
  802. $(PROTOBUF_DEP)\
  803. % endif
  804. $(LIB${lib.name.upper()}_OBJS)
  805. $(E) "[AR] Creating $@"
  806. $(Q) mkdir -p `dirname $@`
  807. $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  808. $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
  809. % if lib.get('baselib', False):
  810. % if lib.get('secure', True):
  811. $(Q) rm -rf tmp-merge
  812. $(Q) mkdir tmp-merge
  813. $(Q) ( cd tmp-merge ; $(AR) x ../$(LIBDIR)/$(CONFIG)/lib${lib.name}.a )
  814. $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge ; <%text>ar x ../$${l}</%text> ) ; done
  815. $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge/__.SYMDEF*
  816. $(Q) ar rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge/*
  817. $(Q) rm -rf tmp-merge
  818. % endif
  819. % endif
  820. ifeq ($(SYSTEM),Darwin)
  821. $(Q) ranlib $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  822. endif
  823. <%
  824. if lib.language == 'c++':
  825. ld = '$(LDXX)'
  826. else:
  827. ld = '$(LD)'
  828. out_base = '$(LIBDIR)/$(CONFIG)/' + lib.name
  829. out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name
  830. common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
  831. libs = ''
  832. lib_deps = ' $(ZLIB_DEP)'
  833. mingw_libs = ''
  834. mingw_lib_deps = ' $(ZLIB_DEP)'
  835. for dep in lib.get('deps', []):
  836. libs = libs + ' -l' + dep
  837. lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
  838. mingw_libs = mingw_libs + ' -l' + dep + '-imp'
  839. mingw_lib_deps = mingw_lib_deps + '$(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
  840. if lib.get('secure', True):
  841. common = common + ' $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS)'
  842. lib_deps = lib_deps + ' $(OPENSSL_DEP)'
  843. mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
  844. if lib.language == 'c++':
  845. common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
  846. %>
  847. % if lib.build == "all":
  848. ifeq ($(SYSTEM),MINGW32)
  849. ${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
  850. $(E) "[LD] Linking $@"
  851. $(Q) mkdir -p `dirname $@`
  852. $(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}
  853. else
  854. ${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
  855. $(E) "[LD] Linking $@"
  856. $(Q) mkdir -p `dirname $@`
  857. ifeq ($(SYSTEM),Darwin)
  858. $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
  859. else
  860. $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
  861. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major}
  862. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so
  863. endif
  864. endif
  865. % endif
  866. % if lib.get('secure', True):
  867. ## If the lib was secure, we have to close the Makefile's if that tested
  868. ## the presence of an ALPN-capable OpenSSL.
  869. endif
  870. % endif
  871. % if lib.language == 'c++':
  872. ## If the lib was C++, we have to close the Makefile's if that tested
  873. ## the presence of protobuf 3.0.0+
  874. endif
  875. % endif
  876. % if lib.get('secure', True):
  877. ifneq ($(NO_SECURE),true)
  878. % endif
  879. ifneq ($(NO_DEPS),true)
  880. -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
  881. endif
  882. % if lib.get('secure', True):
  883. endif
  884. % endif
  885. % for src in lib.src:
  886. % if not proto_re.match(src):
  887. $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
  888. % for src2 in lib.src:
  889. % if proto_re.match(src2):
  890. ${proto_to_cc(src2)}\
  891. % endif
  892. % endfor
  893. % endif
  894. % endfor
  895. </%def>
  896. <%def name="maketarget(tgt)">
  897. ${tgt.name.upper()}_SRC = \\
  898. % for src in tgt.src:
  899. ${proto_to_cc(src)} \\
  900. % endfor
  901. ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
  902. % if tgt.get('secure', True):
  903. ifeq ($(NO_SECURE),true)
  904. # You can't build secure targets if you don't have OpenSSL with ALPN.
  905. $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
  906. else
  907. % endif
  908. ##
  909. ## We're not trying to add a dependency on building zlib and openssl here,
  910. ## as it's already done in the libraries. We're assuming that the build
  911. ## trickles down, and that a secure target requires a secure version of
  912. ## a library.
  913. ##
  914. ## That simplifies the codegen a bit, but prevents a fully defined Makefile.
  915. ## I can live with that.
  916. ##
  917. % if tgt.build == 'protoc' or tgt.language == 'c++':
  918. ifeq ($(NO_PROTOBUF),true)
  919. # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+.
  920. $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
  921. else
  922. $(BINDIR)/$(CONFIG)/${tgt.name}: $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
  923. % else:
  924. $(BINDIR)/$(CONFIG)/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
  925. % endif
  926. % for dep in tgt.deps:
  927. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  928. % endfor
  929. % if tgt.language == "c++":
  930. ## C++ targets specificies.
  931. % if tgt.build == 'protoc':
  932. $(E) "[HOSTLD] Linking $@"
  933. $(Q) mkdir -p `dirname $@`
  934. $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(${tgt.name.upper()}_OBJS)\
  935. % else:
  936. $(E) "[LD] Linking $@"
  937. $(Q) mkdir -p `dirname $@`
  938. $(Q) $(LDXX) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
  939. % endif
  940. % if tgt.build == 'test':
  941. $(GTEST_LIB)\
  942. % endif
  943. % else:
  944. ## C-only targets specificities.
  945. $(E) "[LD] Linking $@"
  946. $(Q) mkdir -p `dirname $@`
  947. $(Q) $(LD) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
  948. % endif
  949. % for dep in tgt.deps:
  950. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  951. % endfor
  952. % if tgt.language == "c++":
  953. % if tgt.build == 'protoc':
  954. $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
  955. % else:
  956. $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
  957. % endif
  958. % endif
  959. % if tgt.build == 'protoc':
  960. $(HOST_LDLIBS)\
  961. % else:
  962. $(LDLIBS)\
  963. % endif
  964. % if tgt.build == 'protoc':
  965. $(HOST_LDLIBS_PROTOC)\
  966. % elif tgt.get('secure', True):
  967. $(LDLIBS_SECURE)\
  968. % endif
  969. -o $(BINDIR)/$(CONFIG)/${tgt.name}
  970. % if tgt.build == 'protoc' or tgt.language == 'c++':
  971. endif
  972. % endif
  973. % if tgt.get('secure', True):
  974. endif
  975. % endif
  976. % for src in tgt.src:
  977. $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
  978. % for dep in tgt.deps:
  979. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  980. % endfor
  981. % endfor
  982. deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
  983. % if tgt.get('secure', True):
  984. ifneq ($(NO_SECURE),true)
  985. % endif
  986. ifneq ($(NO_DEPS),true)
  987. -include $(${tgt.name.upper()}_OBJS:.o=.dep)
  988. endif
  989. % if tgt.get('secure', True):
  990. endif
  991. % endif
  992. </%def>
  993. .PHONY: all strip tools \
  994. dep_error openssl_dep_error openssl_dep_message git_update stop \
  995. buildtests buildtests_c buildtests_cxx \
  996. test test_c test_cxx \
  997. install install_c install_cxx \
  998. install-headers install-headers_c install-headers_cxx \
  999. install-shared install-shared_c install-shared_cxx \
  1000. install-static install-static_c install-static_cxx \
  1001. strip strip-shared strip-static \
  1002. strip_c strip-shared_c strip-static_c \
  1003. strip_cxx strip-shared_cxx strip-static_cxx \
  1004. dep_c dep_cxx bins_dep_c bins_dep_cxx \
  1005. clean