Makefile.template 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  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
  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) > /dev/null && 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 $(CPPFLAGS)
  287. LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS)
  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 install-certs 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. install-certs: etc/roots.pem
  689. $(E) "[INSTALL] Installing root certificates"
  690. $(Q) $(INSTALL) -d $(prefix)/share/grpc
  691. $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem
  692. verify-install:
  693. ifeq ($(INSTALL_OK),true)
  694. @echo "Your system looks ready to go."
  695. @echo
  696. else
  697. @echo "Your system doesn't have protoc 3.0.0+ installed. While this"
  698. @echo "won't prevent grpc from working, you won't be able to compile"
  699. @echo "and run any meaningful code with it."
  700. @echo
  701. @echo
  702. @echo "Please download and install protobuf 3.0.0+ from:"
  703. @echo
  704. @echo " https://github.com/google/protobuf/releases"
  705. @echo
  706. @echo "Once you've done so, you can re-run this check by doing:"
  707. @echo
  708. @echo " make verify-install"
  709. endif
  710. clean:
  711. $(E) "[CLEAN] Cleaning build directories."
  712. $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR)
  713. # The various libraries
  714. % for lib in libs:
  715. ${makelib(lib)}
  716. % endfor
  717. # All of the test targets, and protoc plugins
  718. % for tgt in targets:
  719. ${maketarget(tgt)}
  720. % endfor
  721. <%def name="makelib(lib)">
  722. LIB${lib.name.upper()}_SRC = \\
  723. % for src in lib.src:
  724. ${proto_to_cc(src)} \\
  725. % endfor
  726. % if "public_headers" in lib:
  727. % if lib.language == "c++":
  728. PUBLIC_HEADERS_CXX += \\
  729. % else:
  730. PUBLIC_HEADERS_C += \\
  731. % endif
  732. % for hdr in lib.public_headers:
  733. ${hdr} \\
  734. % endfor
  735. % endif
  736. LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
  737. ## If the library requires OpenSSL with ALPN, let's add some restrictions.
  738. % if lib.get('secure', True):
  739. ifeq ($(NO_SECURE),true)
  740. # You can't build secure libraries if you don't have OpenSSL with ALPN.
  741. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
  742. % if lib.build == "all":
  743. ifeq ($(SYSTEM),MINGW32)
  744. $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error
  745. else
  746. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error
  747. endif
  748. % endif
  749. else
  750. % if lib.language == 'c++':
  751. ifeq ($(NO_PROTOBUF),true)
  752. # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
  753. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
  754. % if lib.build == "all":
  755. ifeq ($(SYSTEM),MINGW32)
  756. $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
  757. else
  758. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
  759. endif
  760. % endif
  761. else
  762. % endif
  763. ifneq ($(OPENSSL_DEP),)
  764. # This is to ensure the embedded OpenSSL is built beforehand, properly
  765. # installing headers to their final destination on the drive. We need this
  766. # otherwise parallel compilation will fail if a source is compiled first.
  767. % for src in lib.src:
  768. ${src}: $(OPENSSL_DEP)
  769. % endfor
  770. endif
  771. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\
  772. ## The else here corresponds to the if secure earlier.
  773. % else:
  774. % if lib.language == 'c++':
  775. ifeq ($(NO_PROTOBUF),true)
  776. # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
  777. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error
  778. % if lib.build == "all":
  779. ifeq ($(SYSTEM),MINGW32)
  780. $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error
  781. else
  782. $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error
  783. endif
  784. % endif
  785. else
  786. % endif
  787. $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP)\
  788. % endif
  789. % if lib.language == 'c++':
  790. $(PROTOBUF_DEP)\
  791. % endif
  792. $(LIB${lib.name.upper()}_OBJS)
  793. $(E) "[AR] Creating $@"
  794. $(Q) mkdir -p `dirname $@`
  795. $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  796. $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
  797. % if lib.get('baselib', False):
  798. % if lib.get('secure', True):
  799. $(Q) rm -rf tmp-merge
  800. $(Q) mkdir tmp-merge
  801. $(Q) ( cd tmp-merge ; $(AR) x ../$(LIBDIR)/$(CONFIG)/lib${lib.name}.a )
  802. $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge ; <%text>ar x ../$${l}</%text> ) ; done
  803. $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge/__.SYMDEF*
  804. $(Q) ar rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge/*
  805. $(Q) rm -rf tmp-merge
  806. % endif
  807. % endif
  808. ifeq ($(SYSTEM),Darwin)
  809. $(Q) ranlib $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
  810. endif
  811. <%
  812. if lib.language == 'c++':
  813. ld = '$(LDXX)'
  814. else:
  815. ld = '$(LD)'
  816. out_base = '$(LIBDIR)/$(CONFIG)/' + lib.name
  817. out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name
  818. common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)'
  819. libs = ''
  820. lib_deps = ' $(ZLIB_DEP)'
  821. mingw_libs = ''
  822. mingw_lib_deps = ' $(ZLIB_DEP)'
  823. for dep in lib.get('deps', []):
  824. libs = libs + ' -l' + dep
  825. lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)'
  826. mingw_libs = mingw_libs + ' -l' + dep + '-imp'
  827. mingw_lib_deps = mingw_lib_deps + '$(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)'
  828. if lib.get('secure', True):
  829. common = common + ' $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS)'
  830. lib_deps = lib_deps + ' $(OPENSSL_DEP)'
  831. mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
  832. if lib.language == 'c++':
  833. common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)'
  834. %>
  835. % if lib.build == "all":
  836. ifeq ($(SYSTEM),MINGW32)
  837. ${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
  838. $(E) "[LD] Linking $@"
  839. $(Q) mkdir -p `dirname $@`
  840. $(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}
  841. else
  842. ${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
  843. $(E) "[LD] Linking $@"
  844. $(Q) mkdir -p `dirname $@`
  845. ifeq ($(SYSTEM),Darwin)
  846. $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
  847. else
  848. $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} -o ${out_libbase}.$(SHARED_EXT) ${common}${libs}
  849. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major}
  850. $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so
  851. endif
  852. endif
  853. % endif
  854. % if lib.get('secure', True):
  855. ## If the lib was secure, we have to close the Makefile's if that tested
  856. ## the presence of an ALPN-capable OpenSSL.
  857. endif
  858. % endif
  859. % if lib.language == 'c++':
  860. ## If the lib was C++, we have to close the Makefile's if that tested
  861. ## the presence of protobuf 3.0.0+
  862. endif
  863. % endif
  864. % if lib.get('secure', True):
  865. ifneq ($(NO_SECURE),true)
  866. % endif
  867. ifneq ($(NO_DEPS),true)
  868. -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
  869. endif
  870. % if lib.get('secure', True):
  871. endif
  872. % endif
  873. % for src in lib.src:
  874. % if not proto_re.match(src):
  875. $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
  876. % for src2 in lib.src:
  877. % if proto_re.match(src2):
  878. ${proto_to_cc(src2)}\
  879. % endif
  880. % endfor
  881. % endif
  882. % endfor
  883. </%def>
  884. <%def name="maketarget(tgt)">
  885. ${tgt.name.upper()}_SRC = \\
  886. % for src in tgt.src:
  887. ${proto_to_cc(src)} \\
  888. % endfor
  889. ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC))))
  890. % if tgt.get('secure', True):
  891. ifeq ($(NO_SECURE),true)
  892. # You can't build secure targets if you don't have OpenSSL with ALPN.
  893. $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error
  894. else
  895. % endif
  896. ##
  897. ## We're not trying to add a dependency on building zlib and openssl here,
  898. ## as it's already done in the libraries. We're assuming that the build
  899. ## trickles down, and that a secure target requires a secure version of
  900. ## a library.
  901. ##
  902. ## That simplifies the codegen a bit, but prevents a fully defined Makefile.
  903. ## I can live with that.
  904. ##
  905. % if tgt.build == 'protoc':
  906. ifeq ($(NO_PROTOBUF),true)
  907. # You can't build the protoc plugins if you don't have protobuf 3.0.0+.
  908. $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error
  909. else
  910. $(BINDIR)/$(CONFIG)/${tgt.name}: $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\
  911. % else:
  912. $(BINDIR)/$(CONFIG)/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
  913. % endif
  914. % for dep in tgt.deps:
  915. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  916. % endfor
  917. % if tgt.language == "c++":
  918. ## C++ targets specificies.
  919. % if tgt.build == 'protoc':
  920. $(E) "[HOSTLD] Linking $@"
  921. $(Q) mkdir -p `dirname $@`
  922. $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) $(${tgt.name.upper()}_OBJS)\
  923. % else:
  924. $(E) "[LD] Linking $@"
  925. $(Q) mkdir -p `dirname $@`
  926. $(Q) $(LDXX) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
  927. % endif
  928. % if tgt.build == 'test':
  929. $(GTEST_LIB)\
  930. % endif
  931. % else:
  932. ## C-only targets specificities.
  933. $(E) "[LD] Linking $@"
  934. $(Q) mkdir -p `dirname $@`
  935. $(Q) $(LD) $(LDFLAGS) $(${tgt.name.upper()}_OBJS)\
  936. % endif
  937. % for dep in tgt.deps:
  938. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  939. % endfor
  940. % if tgt.language == "c++":
  941. % if tgt.build == 'protoc':
  942. $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\
  943. % else:
  944. $(LDLIBSXX) $(LDLIBS_PROTOBUF)\
  945. % endif
  946. % endif
  947. % if tgt.build == 'protoc':
  948. $(HOST_LDLIBS)\
  949. % else:
  950. $(LDLIBS)\
  951. % endif
  952. % if tgt.build == 'protoc':
  953. $(HOST_LDLIBS_PROTOC)\
  954. % elif tgt.get('secure', True):
  955. $(LDLIBS_SECURE)\
  956. % endif
  957. -o $(BINDIR)/$(CONFIG)/${tgt.name}
  958. % if tgt.build == 'protoc':
  959. endif
  960. % endif
  961. % if tgt.get('secure', True):
  962. endif
  963. % endif
  964. % for src in tgt.src:
  965. $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
  966. % for dep in tgt.deps:
  967. $(LIBDIR)/$(CONFIG)/lib${dep}.a\
  968. % endfor
  969. % endfor
  970. deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep)
  971. % if tgt.get('secure', True):
  972. ifneq ($(NO_SECURE),true)
  973. % endif
  974. ifneq ($(NO_DEPS),true)
  975. -include $(${tgt.name.upper()}_OBJS:.o=.dep)
  976. endif
  977. % if tgt.get('secure', True):
  978. endif
  979. % endif
  980. </%def>
  981. .PHONY: all strip tools \
  982. dep_error openssl_dep_error openssl_dep_message git_update stop \
  983. buildtests buildtests_c buildtests_cxx \
  984. test test_c test_cxx \
  985. install install_c install_cxx \
  986. install-headers install-headers_c install-headers_cxx \
  987. install-shared install-shared_c install-shared_cxx \
  988. install-static install-static_c install-static_cxx \
  989. strip strip-shared strip-static \
  990. strip_c strip-shared_c strip-static_c \
  991. strip_cxx strip-shared_cxx strip-static_cxx \
  992. dep_c dep_cxx bins_dep_c bins_dep_cxx \
  993. clean