Makefile.template 30 KB

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