Makefile.template 31 KB

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