Makefile.template 37 KB

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