Debian Codegraph @

templates/Makefile.template

raw
1 %YAML 1.2
2 --- |
3 # GRPC global makefile
4 # This currently builds C and C++ code.
5 # This file has been automatically generated from a template file.
6 # Please look at the templates directory instead.
7 # This file can be regenerated from the template by running
8 # tools/buildgen/generate_projects.sh
9
10 # Copyright 2015 gRPC authors.
11 #
12 # Licensed under the Apache License, Version 2.0 (the "License");
13 # you may not use this file except in compliance with the License.
14 # You may obtain a copy of the License at
15 #
16 # http://www.apache.org/licenses/LICENSE-2.0
17 #
18 # Unless required by applicable law or agreed to in writing, software
19 # distributed under the License is distributed on an "AS IS" BASIS,
20 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 # See the License for the specific language governing permissions and
22 # limitations under the License.
23 <%!
24 import re
25 import os
26
27 def is_absl_lib(target_name):
28 return target_name.startswith("absl/");
29
30 sources_that_need_openssl = set()
31 sources_that_don_t_need_openssl = set()
32
33 # warnings we'd like, but that don't exist in all compilers
34 PREFERRED_WARNINGS=['extra-semi']
35 CHECK_WARNINGS=PREFERRED_WARNINGS + ['no-shift-negative-value', 'no-unused-but-set-variable', 'no-maybe-uninitialized', 'no-unknown-warning-option']
36
37 def warning_var(fmt, warning):
38 return fmt % warning.replace('-', '_').replace('+', 'X').upper()
39
40 def neg_warning(warning):
41 if warning[0:3] == 'no-':
42 return warning[3:]
43 else:
44 return 'no-' + warning
45
46 lang_to_var = {
47 'c': 'CORE',
48 'c++': 'CPP',
49 'csharp': 'CSHARP'
50 }
51 %>
52 <%
53 # Makefile is only intended for internal needs (building distribution artifacts etc.)
54 # so we can restrict the number of libraries/targets that are buildable using the Makefile.
55 # Other targets can be built with cmake or bazel.
56 # TODO(jtattermusch): Figure out how to avoid the need to list the dependencies explicitly.
57 # Currently it is necessary because some dependencies are marked as "build: private" in build.yaml
58 # (which itself is correct, as they are not "public" libraries from our perspective and cmake
59 # needs to have them marked as such)
60 filtered_libs = [lib for lib in libs if (lib.build in ['all'] and lib.language != 'c++') or lib.name in ['ares', 'boringssl', 're2', 'upb', 'z']]
61 filtered_targets = [tgt for tgt in targets if tgt.build in ['all'] and lib.language != 'c++']
62 %>
63
64 comma := ,
65
66
67 # Basic platform detection
68 HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
69 SYSTEM ?= $(HOST_SYSTEM)
70 ifeq ($(SYSTEM),MSYS)
71 SYSTEM = MINGW32
72 endif
73 ifeq ($(SYSTEM),MINGW64)
74 SYSTEM = MINGW32
75 endif
76
77 MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
78 ifndef BUILDDIR
79 BUILDDIR_ABSOLUTE = $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))
80 else
81 BUILDDIR_ABSOLUTE = $(abspath $(BUILDDIR))
82 endif
83
84 HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false)
85 HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false)
86 HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false)
87
88 ifeq ($(HAS_CC),true)
89 DEFAULT_CC = cc
90 DEFAULT_CXX = c++
91 else
92 ifeq ($(HAS_GCC),true)
93 DEFAULT_CC = gcc
94 DEFAULT_CXX = g++
95 else
96 ifeq ($(HAS_CLANG),true)
97 DEFAULT_CC = clang
98 DEFAULT_CXX = clang++
99 else
100 DEFAULT_CC = no_c_compiler
101 DEFAULT_CXX = no_c++_compiler
102 endif
103 endif
104 endif
105
106
107 BINDIR = $(BUILDDIR_ABSOLUTE)/bins
108 OBJDIR = $(BUILDDIR_ABSOLUTE)/objs
109 LIBDIR = $(BUILDDIR_ABSOLUTE)/libs
110 GENDIR = $(BUILDDIR_ABSOLUTE)/gens
111
112 # Configurations (as defined under "configs" section in build_handwritten.yaml)
113
114 % for name, args in configs.items():
115 VALID_CONFIG_${name} = 1
116 % if args.get('compile_the_world', False):
117 REQUIRE_CUSTOM_LIBRARIES_${name} = 1
118 % endif
119 % for tool, default in [('CC', 'CC'), ('CXX', 'CXX'), ('LD', 'CC'), ('LDXX', 'CXX')]:
120 ${tool}_${name} = ${args.get(tool, '$(DEFAULT_%s)' % default)}
121 % endfor
122 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES']:
123 % if args.get(arg, None) is not None:
124 ${arg}_${name} = ${args.get(arg)}
125 % endif
126 % endfor
127
128 % endfor
129
130
131 # General settings.
132 # You may want to change these depending on your system.
133
134 prefix ?= /usr/local
135
136 DTRACE ?= dtrace
137 CONFIG ?= opt
138 # Doing X ?= Y is the same as:
139 # ifeq ($(origin X), undefined)
140 # X = Y
141 # endif
142 # but some variables, such as CC, CXX, LD or AR, have defaults.
143 # So instead of using ?= on them, we need to check their origin.
144 # See:
145 # https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
146 # https://www.gnu.org/software/make/manual/html_node/Flavors.html#index-_003f_003d
147 # https://www.gnu.org/software/make/manual/html_node/Origin-Function.html
148 ifeq ($(origin CC), default)
149 CC = $(CC_$(CONFIG))
150 endif
151 ifeq ($(origin CXX), default)
152 CXX = $(CXX_$(CONFIG))
153 endif
154 ifeq ($(origin LD), default)
155 LD = $(LD_$(CONFIG))
156 endif
157 LDXX ?= $(LDXX_$(CONFIG))
158 ARFLAGS ?= rcs
159 ifeq ($(SYSTEM),Linux)
160 ifeq ($(origin AR), default)
161 AR = ar
162 endif
163 STRIP ?= strip --strip-unneeded
164 else
165 ifeq ($(SYSTEM),Darwin)
166 ifeq ($(origin AR), default)
167 AR = libtool
168 ARFLAGS = -no_warning_for_no_symbols -o
169 endif
170 STRIP ?= strip -x
171 else
172 ifeq ($(SYSTEM),MINGW32)
173 ifeq ($(origin AR), default)
174 AR = ar
175 endif
176 STRIP ?= strip --strip-unneeded
177 else
178 ifeq ($(origin AR), default)
179 AR = ar
180 endif
181 STRIP ?= strip
182 endif
183 endif
184 endif
185 INSTALL ?= install
186 RM ?= rm -f
187 PKG_CONFIG ?= pkg-config
188 RANLIB ?= ranlib
189 ifeq ($(SYSTEM),Darwin)
190 APPLE_RANLIB = $(shell [[ "`$(RANLIB) -V 2>/dev/null`" == "Apple Inc."* ]]; echo $$?)
191 ifeq ($(APPLE_RANLIB),0)
192 RANLIBFLAGS = -no_warning_for_no_symbols
193 endif
194 endif
195
196 ifndef VALID_CONFIG_$(CONFIG)
197 $(error Invalid CONFIG value '$(CONFIG)')
198 endif
199
200 ifeq ($(SYSTEM),Linux)
201 TMPOUT = /dev/null
202 else
203 TMPOUT = `mktemp /tmp/test-out-XXXXXX`
204 endif
205
206 CHECK_NO_CXX14_COMPAT_WORKS_CMD = $(CC) -std=c++14 -Werror -Wno-c++14-compat -o $(TMPOUT) -c test/build/no-c++14-compat.cc
207 HAS_WORKING_NO_CXX14_COMPAT = $(shell $(CHECK_NO_CXX14_COMPAT_WORKS_CMD) 2> /dev/null && echo true || echo false)
208 ifeq ($(HAS_WORKING_NO_CXX14_COMPAT),true)
209 W_NO_CXX14_COMPAT=-Wno-c++14-compat
210 endif
211
212 %for warning in CHECK_WARNINGS:
213 ${warning_var('CHECK_%s_WORKS_CMD', warning)} = $(CC) -std=c99 -Werror -W${warning} -o $(TMPOUT) -c test/build/${warning}.c
214 ${warning_var('HAS_WORKING_%s', warning)} = $(shell $(${warning_var('CHECK_%s_WORKS_CMD', warning)}) 2> /dev/null && echo true || echo false)
215 ifeq ($(${warning_var('HAS_WORKING_%s', warning)}),true)
216 ${warning_var('W_%s', warning)}=-W${warning}
217 ${warning_var('NO_W_%s', warning)}=-W${neg_warning(warning)}
218 endif
219 %endfor
220
221 # The HOST compiler settings are used to compile the protoc plugins.
222 # In most cases, you won't have to change anything, but if you are
223 # cross-compiling, you can override these variables from GNU make's
224 # command line: make CC=cross-gcc HOST_CC=gcc
225
226 HOST_CC ?= $(CC)
227 HOST_CXX ?= $(CXX)
228 HOST_LD ?= $(LD)
229 HOST_LDXX ?= $(LDXX)
230
231 CFLAGS += -std=c11 ${' '.join(warning_var('$(W_%s)', warning) for warning in PREFERRED_WARNINGS)}
232 CXXFLAGS += -std=c++14
233 ifeq ($(SYSTEM),Darwin)
234 CXXFLAGS += -stdlib=libc++
235 LDFLAGS += -framework CoreFoundation
236 endif
237 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'COREFLAGS', 'LDFLAGS', 'DEFINES']:
238 % if defaults.get('global', []).get(arg, None) is not None:
239 ${arg} += ${defaults.get('global').get(arg)}
240 % endif
241 % endfor
242
243 CPPFLAGS += $(CPPFLAGS_$(CONFIG))
244 CFLAGS += $(CFLAGS_$(CONFIG))
245 CXXFLAGS += $(CXXFLAGS_$(CONFIG))
246 DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
247 LDFLAGS += $(LDFLAGS_$(CONFIG))
248
249 ifneq ($(SYSTEM),MINGW32)
250 PIC_CPPFLAGS = -fPIC
251 CPPFLAGS += -fPIC
252 LDFLAGS += -fPIC
253 endif
254
255 INCLUDES = . include $(GENDIR)
256 LDFLAGS += -Llibs/$(CONFIG)
257
258 ifeq ($(SYSTEM),Darwin)
259 ifneq ($(wildcard /usr/local/ssl/include),)
260 INCLUDES += /usr/local/ssl/include
261 endif
262 ifneq ($(wildcard /opt/local/include),)
263 INCLUDES += /opt/local/include
264 endif
265 ifneq ($(wildcard /usr/local/include),)
266 INCLUDES += /usr/local/include
267 endif
268 LIBS = m z
269 ifneq ($(wildcard /usr/local/ssl/lib),)
270 LDFLAGS += -L/usr/local/ssl/lib
271 endif
272 ifneq ($(wildcard /opt/local/lib),)
273 LDFLAGS += -L/opt/local/lib
274 endif
275 ifneq ($(wildcard /usr/local/lib),)
276 LDFLAGS += -L/usr/local/lib
277 endif
278 endif
279
280 ifeq ($(SYSTEM),Linux)
281 LIBS = dl rt m pthread
282 LDFLAGS += -pthread
283 endif
284
285 ifeq ($(SYSTEM),MINGW32)
286 LIBS = m pthread ws2_32 dbghelp bcrypt
287 LDFLAGS += -pthread
288 endif
289
290 #
291 # The steps for cross-compiling are as follows:
292 # First, clone and make install of grpc using the native compilers for the host.
293 # Also, install protoc (e.g., from a package like apt-get)
294 # Then clone a fresh grpc for the actual cross-compiled build
295 # Set the environment variable GRPC_CROSS_COMPILE to true
296 # Set CC, CXX, LD, LDXX, AR, and STRIP to the cross-compiling binaries
297 # Also set PROTOBUF_CONFIG_OPTS to indicate cross-compilation to protobuf (e.g.,
298 # PROTOBUF_CONFIG_OPTS="--host=arm-linux --with-protoc=/usr/local/bin/protoc" )
299 # Set HAS_PKG_CONFIG=false
300 # Make sure that you enable building shared libraries and set your prefix to
301 # something useful like /usr/local/cross
302 # You will also need to set GRPC_CROSS_LDOPTS and GRPC_CROSS_AROPTS to hold
303 # additional required arguments for LD and AR (examples below)
304 # Then you can do a make from the cross-compiling fresh clone!
305 #
306 ifeq ($(GRPC_CROSS_COMPILE),true)
307 LDFLAGS += $(GRPC_CROSS_LDOPTS) # e.g. -L/usr/local/lib -L/usr/local/cross/lib
308 ARFLAGS += $(GRPC_CROSS_AROPTS) # e.g., rc --target=elf32-little
309 USE_BUILT_PROTOC = false
310 endif
311
312 # V=1 can be used to print commands run by make
313 ifeq ($(V),1)
314 E = @:
315 Q =
316 else
317 E = @echo
318 Q = @
319 endif
320
321 CORE_VERSION = ${settings.core_version}
322 CPP_VERSION = ${settings.cpp_version}
323 CSHARP_VERSION = ${settings.csharp_version}
324
325 CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
326 CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
327
328 LDFLAGS += $(ARCH_FLAGS)
329 LDLIBS += $(addprefix -l, $(LIBS))
330 LDLIBSXX += $(addprefix -l, $(LIBSXX))
331
332
333 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES', 'LDLIBS']:
334 ${arg} += $(EXTRA_${arg})
335 % endfor
336
337 HOST_CPPFLAGS += $(CPPFLAGS)
338 HOST_CFLAGS += $(CFLAGS)
339 HOST_CXXFLAGS += $(CXXFLAGS)
340 HOST_LDFLAGS += $(LDFLAGS)
341 HOST_LDLIBS += $(LDLIBS)
342
343 # These are automatically computed variables.
344 # There shouldn't be any need to change anything from now on.
345
346 -include cache.mk
347
348 CACHE_MK =
349
350 ifeq ($(SYSTEM),MINGW32)
351 EXECUTABLE_SUFFIX = .exe
352 SHARED_EXT_CORE = dll
353 SHARED_EXT_CPP = dll
354 SHARED_EXT_CSHARP = dll
355 SHARED_PREFIX =
356 SHARED_VERSION_CORE = -${settings.core_version.major}
357 SHARED_VERSION_CPP = -${settings.cpp_version.major}
358 SHARED_VERSION_CSHARP = -${settings.csharp_version.major}
359 else ifeq ($(SYSTEM),Darwin)
360 EXECUTABLE_SUFFIX =
361 SHARED_EXT_CORE = dylib
362 SHARED_EXT_CPP = dylib
363 SHARED_EXT_CSHARP = dylib
364 SHARED_PREFIX = lib
365 SHARED_VERSION_CORE =
366 SHARED_VERSION_CPP =
367 SHARED_VERSION_CSHARP =
368 else
369 EXECUTABLE_SUFFIX =
370 SHARED_EXT_CORE = so.$(CORE_VERSION)
371 SHARED_EXT_CPP = so.$(CPP_VERSION)
372 SHARED_EXT_CSHARP = so.$(CSHARP_VERSION)
373 SHARED_PREFIX = lib
374 SHARED_VERSION_CORE =
375 SHARED_VERSION_CPP =
376 SHARED_VERSION_CSHARP =
377 endif
378
379 ifeq ($(wildcard .git),)
380 IS_GIT_FOLDER = false
381 else
382 IS_GIT_FOLDER = true
383 endif
384
385 # Setup zlib dependency
386
387 ifeq ($(wildcard third_party/zlib/zlib.h),)
388 HAS_EMBEDDED_ZLIB = false
389 else
390 HAS_EMBEDDED_ZLIB = true
391 endif
392
393 # for zlib, we support building both from submodule
394 # and from system-installed zlib. In some builds,
395 # embedding zlib is not desirable.
396 # By default we use the system zlib (to match legacy behavior)
397 EMBED_ZLIB ?= false
398
399 ifeq ($(EMBED_ZLIB),true)
400 ZLIB_DEP = $(LIBDIR)/$(CONFIG)/libz.a
401 ZLIB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libz.a
402 ZLIB_MERGE_OBJS = $(LIBZ_OBJS)
403 CPPFLAGS += -Ithird_party/zlib
404 else
405 LIBS += z
406 endif
407
408 # Setup c-ares dependency
409
410 ifeq ($(wildcard third_party/cares/cares/include/ares.h),)
411 HAS_EMBEDDED_CARES = false
412 else
413 HAS_EMBEDDED_CARES = true
414 endif
415
416 ifeq ($(HAS_EMBEDDED_CARES),true)
417 EMBED_CARES ?= true
418 else
419 # only building with c-ares from submodule is supported
420 DEP_MISSING += cares
421 EMBED_CARES ?= broken
422 endif
423
424 ifeq ($(EMBED_CARES),true)
425 CARES_DEP = $(LIBDIR)/$(CONFIG)/libares.a
426 CARES_MERGE_OBJS = $(LIBARES_OBJS)
427 CARES_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libares.a
428 CPPFLAGS := -Ithird_party/cares/cares/include -Ithird_party/cares -Ithird_party/cares/cares $(CPPFLAGS)
429 endif
430
431 # Setup address_sorting dependency
432
433 ADDRESS_SORTING_DEP = $(LIBDIR)/$(CONFIG)/libaddress_sorting.a
434 ADDRESS_SORTING_MERGE_OBJS = $(LIBADDRESS_SORTING_OBJS)
435 ADDRESS_SORTING_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libaddress_sorting.a
436 CPPFLAGS := -Ithird_party/address_sorting/include $(CPPFLAGS)
437
438 # Setup abseil dependency
439
440 GRPC_ABSEIL_DEP = $(LIBDIR)/$(CONFIG)/libgrpc_abseil.a
441 GRPC_ABSEIL_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libgrpc_abseil.a
442
443 # Setup re2 dependency
444
445 RE2_DEP = $(LIBDIR)/$(CONFIG)/libre2.a
446 RE2_MERGE_OBJS = $(LIBRE2_OBJS)
447 RE2_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libre2.a
448
449 # Setup upb dependency
450
451 UPB_DEP = $(LIBDIR)/$(CONFIG)/libupb.a
452 UPB_MERGE_OBJS = $(LIBUPB_OBJS)
453 UPB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libupb.a
454
455 # Setup boringssl dependency
456
457 ifeq ($(wildcard third_party/boringssl-with-bazel/src/include/openssl/ssl.h),)
458 HAS_EMBEDDED_OPENSSL = false
459 else
460 HAS_EMBEDDED_OPENSSL = true
461 endif
462
463 ifeq ($(HAS_EMBEDDED_OPENSSL),true)
464 EMBED_OPENSSL ?= true
465 else
466 # only support building boringssl from submodule
467 DEP_MISSING += openssl
468 EMBED_OPENSSL ?= broken
469 endif
470
471 ifeq ($(EMBED_OPENSSL),true)
472 OPENSSL_DEP += $(LIBDIR)/$(CONFIG)/libboringssl.a
473 OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/libboringssl.a
474 OPENSSL_MERGE_OBJS += $(LIBBORINGSSL_OBJS)
475 # need to prefix these to ensure overriding system libraries
476 CPPFLAGS := -Ithird_party/boringssl-with-bazel/src/include $(CPPFLAGS)
477 ifeq ($(DISABLE_ALPN),true)
478 CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0
479 LIBS_SECURE = $(OPENSSL_LIBS)
480 endif # DISABLE_ALPN
481 endif # EMBED_OPENSSL
482
483 LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
484
485 ifeq ($(MAKECMDGOALS),clean)
486 NO_DEPS = true
487 endif
488
489 .SECONDARY = %.pb.h %.pb.cc
490
491 ifeq ($(DEP_MISSING),)
492 all: static shared\
493 % for tgt in filtered_targets:
494 % if tgt.build == 'all':
495 $(BINDIR)/$(CONFIG)/${tgt.name}\
496 % endif
497 % endfor
498
499 dep_error:
500 @echo "You shouldn't see this message - all of your dependencies are correct."
501 else
502 all: dep_error git_update stop
503
504 dep_error:
505 @echo
506 @echo "DEPENDENCY ERROR"
507 @echo
508 @echo "You are missing system dependencies that are essential to build grpc,"
509 @echo "and the third_party directory doesn't have them:"
510 @echo
511 @echo " $(DEP_MISSING)"
512 @echo
513 @echo "Installing the development packages for your system will solve"
514 @echo "this issue. Please consult INSTALL to get more information."
515 @echo
516 @echo "If you need information about why these tests failed, run:"
517 @echo
518 @echo " make run_dep_checks"
519 @echo
520 endif
521
522 git_update:
523 ifeq ($(IS_GIT_FOLDER),true)
524 @echo "Additionally, since you are in a git clone, you can download the"
525 @echo "missing dependencies in third_party by running the following command:"
526 @echo
527 @echo " git submodule update --init"
528 @echo
529 endif
530
531 openssl_dep_error: openssl_dep_message git_update stop
532
533 openssl_dep_message:
534 @echo
535 @echo "DEPENDENCY ERROR"
536 @echo
537 @echo "The target you are trying to run requires an OpenSSL implementation."
538 @echo "Your system doesn't have one, and either the third_party directory"
539 @echo "doesn't have it, or your compiler can't build BoringSSL."
540 @echo
541 @echo "Please consult BUILDING.md to get more information."
542 @echo
543 @echo "If you need information about why these tests failed, run:"
544 @echo
545 @echo " make run_dep_checks"
546 @echo
547
548 systemtap_dep_error:
549 @echo
550 @echo "DEPENDENCY ERROR"
551 @echo
552 @echo "Under the '$(CONFIG)' configutation, the target you are trying "
553 @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other "
554 @echo "platforms such as Solaris and *BSD). "
555 @echo
556 @echo "Please consult BUILDING.md to get more information."
557 @echo
558
559 install_not_supported_message:
560 @echo
561 @echo "Installing via 'make' is no longer supported. Use cmake or bazel instead."
562 @echo
563 @echo "Please consult BUILDING.md to get more information."
564 @echo
565
566 install_not_supported_error: install_not_supported_message stop
567
568 stop:
569 @false
570
571 % for tgt in filtered_targets:
572 ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
573 % endfor
574
575 run_dep_checks:
576 @echo "run_dep_checks target has been deprecated."
577
578 static: static_c static_cxx
579
580 static_c: cache.mk \
581 % for lib in filtered_libs:
582 % if 'Makefile' in lib.get('build_system', ['Makefile']):
583 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
584 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
585 % endif
586 % endif
587 % endfor
588
589
590 static_cxx: cache.mk \
591 % for lib in filtered_libs:
592 % if 'Makefile' in lib.get('build_system', ['Makefile']):
593 % if lib.build == 'all' and lib.language == 'c++':
594 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
595 % endif
596 % endif
597 % endfor
598
599
600 static_csharp: static_c \
601 % for lib in filtered_libs:
602 % if 'Makefile' in lib.get('build_system', ['Makefile']):
603 % if lib.build == 'all' and lib.language == 'csharp':
604 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
605 % endif
606 % endif
607 % endfor
608
609
610 shared: shared_c shared_cxx
611
612 shared_c: cache.mk\
613 % for lib in filtered_libs:
614 % if 'Makefile' in lib.get('build_system', ['Makefile']):
615 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
616 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)\
617 % endif
618 % endif
619 % endfor
620
621 shared_cxx: cache.mk\
622 % for lib in filtered_libs:
623 % if 'Makefile' in lib.get('build_system', ['Makefile']):
624 % if lib.build == 'all' and lib.language == 'c++':
625 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)\
626 % endif
627 % endif
628 % endfor
629
630
631 shared_csharp: shared_c \
632 % for lib in filtered_libs:
633 % if 'Makefile' in lib.get('build_system', ['Makefile']):
634 % if lib.build == 'all' and lib.language == 'csharp':
635 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)\
636 % endif
637 % endif
638 % endfor
639
640 grpc_csharp_ext: shared_csharp
641
642 privatelibs: privatelibs_c privatelibs_cxx
643
644 privatelibs_c: \
645 % for lib in filtered_libs:
646 % if 'Makefile' in lib.get('build_system', ['Makefile']):
647 % if lib.build == 'private' and lib.language == 'c' and not lib.get('external_deps', None) and not lib.boringssl:
648 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
649 % endif
650 % endif
651 % endfor
652
653 ifeq ($(EMBED_OPENSSL),true)
654 privatelibs_cxx: \
655 % for lib in filtered_libs:
656 % if 'Makefile' in lib.get('build_system', ['Makefile']):
657 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None):
658 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
659 % endif
660 % endif
661 % endfor
662
663 else
664 privatelibs_cxx: \
665 % for lib in filtered_libs:
666 % if 'Makefile' in lib.get('build_system', ['Makefile']):
667 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None) and not lib.boringssl:
668 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
669 % endif
670 % endif
671 % endfor
672
673 endif
674
675
676 strip: strip-static strip-shared
677
678 strip-static: strip-static_c strip-static_cxx
679
680 strip-shared: strip-shared_c strip-shared_cxx
681
682 strip-static_c: static_c
683 ifeq ($(CONFIG),opt)
684 % for lib in filtered_libs:
685 % if 'Makefile' in lib.get('build_system', ['Makefile']):
686 % if lib.language == "c":
687 % if lib.build == "all":
688 % if not lib.get('external_deps', None):
689 $(E) "[STRIP] Stripping lib${lib.name}.a"
690 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
691 % endif
692 % endif
693 % endif
694 % endif
695 % endfor
696 endif
697
698 strip-static_cxx: static_cxx
699 ifeq ($(CONFIG),opt)
700 % for lib in filtered_libs:
701 % if 'Makefile' in lib.get('build_system', ['Makefile']):
702 % if lib.language == "c++":
703 % if lib.build == "all":
704 $(E) "[STRIP] Stripping lib${lib.name}.a"
705 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
706 % endif
707 % endif
708 % endif
709 % endfor
710 endif
711
712 strip-shared_c: shared_c
713 ifeq ($(CONFIG),opt)
714 % for lib in filtered_libs:
715 % if 'Makefile' in lib.get('build_system', ['Makefile']):
716 % if lib.language == "c":
717 % if lib.build == "all":
718 % if not lib.get('external_deps', None):
719 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)"
720 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)
721 % endif
722 % endif
723 % endif
724 % endif
725 % endfor
726 endif
727
728 strip-shared_cxx: shared_cxx
729 ifeq ($(CONFIG),opt)
730 % for lib in filtered_libs:
731 % if 'Makefile' in lib.get('build_system', ['Makefile']):
732 % if lib.language == "c++":
733 % if lib.build == "all":
734 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)"
735 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)
736 % endif
737 % endif
738 % endif
739 % endfor
740 endif
741
742 strip-shared_csharp: shared_csharp
743 ifeq ($(CONFIG),opt)
744 % for lib in filtered_libs:
745 % if 'Makefile' in lib.get('build_system', ['Makefile']):
746 % if lib.language == "csharp":
747 % if lib.build == "all":
748 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)"
749 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)
750 % endif
751 % endif
752 % endif
753 % endfor
754 endif
755
756 cache.mk::
757 $(E) "[MAKE] Generating $@"
758 $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@
759
760 $(OBJDIR)/$(CONFIG)/%.o : %.c
761 $(E) "[C] Compiling $<"
762 $(Q) mkdir -p `dirname $@`
763 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
764
765 $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
766 $(E) "[CXX] Compiling $<"
767 $(Q) mkdir -p `dirname $@`
768 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
769
770 $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
771 $(E) "[HOSTCXX] Compiling $<"
772 $(Q) mkdir -p `dirname $@`
773 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
774
775 $(OBJDIR)/$(CONFIG)/src/core/%.o : src/core/%.cc
776 $(E) "[CXX] Compiling $<"
777 $(Q) mkdir -p `dirname $@`
778 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
779
780 $(OBJDIR)/$(CONFIG)/test/core/%.o : test/core/%.cc
781 $(E) "[CXX] Compiling $<"
782 $(Q) mkdir -p `dirname $@`
783 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
784
785 $(OBJDIR)/$(CONFIG)/%.o : %.cc
786 $(E) "[CXX] Compiling $<"
787 $(Q) mkdir -p `dirname $@`
788 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
789
790 $(OBJDIR)/$(CONFIG)/%.o : %.cpp
791 $(E) "[CXX] Compiling $<"
792 $(Q) mkdir -p `dirname $@`
793 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
794
795 install: install_not_supported_error
796
797 install_c: install_not_supported_error
798
799 install_cxx: install_not_supported_error
800
801 install_csharp: install_not_supported_error
802
803 install-static: install_not_supported_error
804
805 install-certs: install_not_supported_error
806
807 clean:
808 $(E) "[CLEAN] Cleaning build directories."
809 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk
810
811
812 # The various libraries
813
814 % for lib in filtered_libs:
815 % if 'Makefile' in lib.get('build_system', ['Makefile']):
816 ${makelib(lib)}
817 % endif
818 % endfor
819
820 # Add private ABSEIL target which contains all sources used by all baselib libraries.
821 <%
822 # Collect all abseil source and header files used by gpr, grpc, so on.
823 used_abseil_rules = set()
824 for lib in libs:
825 if lib.get("baselib"):
826 for dep in lib.transitive_deps:
827 if is_absl_lib(dep):
828 used_abseil_rules.add(dep)
829 used_abseil_srcs = []
830 used_abseil_hdrs = []
831 for lib in libs:
832 if lib.name in used_abseil_rules:
833 used_abseil_srcs.extend(lib.get("src", []))
834 used_abseil_hdrs.extend(lib.get("hdr", []))
835 # Create `grpc_abseil` rule with collected files.
836 lib_type = type(libs[0])
837 grpc_abseil_lib = lib_type({
838 "name": "grpc_abseil",
839 "build": "private",
840 "language": "c",
841 "defaults": "abseil",
842 "src": sorted(used_abseil_srcs),
843 "hdr": sorted(used_abseil_hdrs),
844 })
845 %>
846 ${makelib(grpc_abseil_lib)}
847
848 <%def name="makelib(lib)">
849 # start of build recipe for library "${lib.name}" (generated by makelib(lib) template function)
850 LIB${lib.name.upper()}_SRC = \\
851
852 % for src in lib.src:
853 ${src} \\
854
855 % endfor
856
857 % if "public_headers" in lib:
858 % if lib.language == "c++":
859 PUBLIC_HEADERS_CXX += \\
860
861 % else:
862 PUBLIC_HEADERS_C += \\
863
864 % endif
865 % for hdr in lib.public_headers:
866 ${hdr} \\
867
868 % endfor
869 % endif
870
871 LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
872
873 % if lib.get('defaults', None):
874 % for name, value in defaults.get(lib.defaults).items():
875 $(LIB${lib.name.upper()}_OBJS): ${name} += ${value}
876 % endfor
877 % endif
878
879 ## If the library requires OpenSSL, let's add some restrictions.
880 % if 'libssl' in lib.get('deps', []):
881 ifeq ($(NO_SECURE),true)
882
883 # You can't build secure libraries if you don't have OpenSSL.
884
885 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
886
887 % if lib.build == "all":
888 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}): openssl_dep_error
889 % endif
890
891 else
892
893 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(RE2_DEP) $(UPB_DEP) $(GRPC_ABSEIL_DEP) \
894 ## The else here corresponds to the if secure earlier.
895 % else:
896 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: \
897 % if lib.name not in ['z', 'ares', 'address_sorting', 're2', 'upb', 'grpc_abseil']:
898 $(ZLIB_DEP) \
899 $(CARES_DEP) \
900 $(ADDRESS_SORTING_DEP) \
901 $(RE2_DEP) \
902 $(UPB_DEP) \
903 $(GRPC_ABSEIL_DEP) \
904 % endif
905 % endif
906 $(LIB${lib.name.upper()}_OBJS) \
907 % if lib.get('baselib', False):
908 $(LIBGPR_OBJS) \
909 $(LIBGRPC_ABSEIL_OBJS) \
910 $(ZLIB_MERGE_OBJS) \
911 $(CARES_MERGE_OBJS) \
912 $(ADDRESS_SORTING_MERGE_OBJS) \
913 $(RE2_MERGE_OBJS) \
914 $(UPB_MERGE_OBJS) \
915 % if 'libssl' in lib.get('deps', []):
916 $(OPENSSL_MERGE_OBJS) \
917 % endif
918 % endif
919
920 $(E) "[AR] Creating $@"
921 $(Q) mkdir -p `dirname $@`
922 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
923 $(Q) $(AR) $(ARFLAGS) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) \
924 % if lib.get('baselib', False):
925 $(LIBGPR_OBJS) \
926 $(LIBGRPC_ABSEIL_OBJS) \
927 $(ZLIB_MERGE_OBJS) \
928 $(CARES_MERGE_OBJS) \
929 $(ADDRESS_SORTING_MERGE_OBJS) \
930 $(RE2_MERGE_OBJS) \
931 $(UPB_MERGE_OBJS) \
932 % if 'libssl' in lib.get('deps', []):
933 $(OPENSSL_MERGE_OBJS) \
934 % endif
935 % endif
936
937 ifeq ($(SYSTEM),Darwin)
938 $(Q) $(RANLIB) $(RANLIBFLAGS) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
939 endif
940
941 <%
942 ld = '$(LDXX)'
943
944 out_mingbase = '$(LIBDIR)/$(CONFIG)/' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
945 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
946
947 common = '$(LIB' + lib.name.upper() + '_OBJS)'
948
949 link_libs = ''
950 lib_deps = ' $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(RE2_DEP) $(UPB_DEP) $(GRPC_ABSEIL_DEP)'
951 mingw_libs = ''
952 mingw_lib_deps = ' $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(RE2_DEP) $(UPB_DEP) $(GRPC_ABSEIL_DEP)'
953 for dep in lib.get('deps', []):
954 if is_absl_lib(dep): continue
955 if 'libssl' == dep: continue
956 lib_archive = '$(LIBDIR)/$(CONFIG)/lib' + dep + '.a'
957 common = common + ' ' + lib_archive
958 lib_deps = lib_deps + ' ' + lib_archive
959 mingw_lib_deps = mingw_lib_deps + ' ' + lib_archive
960
961 security = 'libssl' in lib.get('deps', [])
962 if security == True:
963 common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)'
964 common = common + ' $(ZLIB_MERGE_LIBS) $(CARES_MERGE_LIBS) $(ADDRESS_SORTING_MERGE_LIBS) $(RE2_MERGE_LIBS) $(UPB_MERGE_LIBS) $(GRPC_ABSEIL_MERGE_LIBS)'
965
966 if security in [True, 'check']:
967 for src in lib.src:
968 sources_that_need_openssl.add(src)
969 else:
970 for src in lib.src:
971 sources_that_don_t_need_openssl.add(src)
972
973 if 'libssl' in lib.get('deps', []):
974 lib_deps = lib_deps + ' $(OPENSSL_DEP)'
975 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)'
976
977 ldflags = '$(LDFLAGS)'
978 if lib.get('LDFLAGS', None):
979 ldflags += ' ' + lib['LDFLAGS']
980
981 common = common + ' $(LDLIBS)'
982 %>
983
984 % if lib.build == "all":
985 ifeq ($(SYSTEM),MINGW32)
986 ${out_mingbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps}
987 $(E) "[LD] Linking $@"
988 $(Q) mkdir -p `dirname $@`
989 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=${out_mingbase}.def -Wl,--out-implib=${out_libbase}-dll.a -o ${out_mingbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${mingw_libs}
990 else
991 ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${lib_deps}
992 $(E) "[LD] Linking $@"
993 $(Q) mkdir -p `dirname $@`
994 ifeq ($(SYSTEM),Darwin)
995 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) -dynamiclib -o ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${link_libs}
996 else
997 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.get(lang_to_var[lib.language].lower() + '_version').major} -o ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${link_libs}
998 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) ${out_libbase}.so.${settings.get(lang_to_var[lib.language].lower() + '_version').major}
999 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) ${out_libbase}.so
1000 endif
1001 endif
1002 % endif
1003 % if 'libssl' in lib.get('deps', []):
1004 ## If the lib was secure, we have to close the Makefile's if that tested
1005 ## the presence of OpenSSL.
1006
1007 endif
1008 % endif
1009
1010 % if 'libssl' in lib.get('deps', []):
1011 ifneq ($(NO_SECURE),true)
1012 % endif
1013 ifneq ($(NO_DEPS),true)
1014 -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
1015 endif
1016 % if 'libssl' in lib.get('deps', []):
1017 endif
1018 % endif
1019 # end of build recipe for library "${lib.name}"
1020 </%def>
1021
1022 # TODO(jtattermusch): is there a way to get around this hack?
1023 ifneq ($(OPENSSL_DEP),)
1024 # This is to ensure the embedded OpenSSL is built beforehand, properly
1025 # installing headers to their final destination on the drive. We need this
1026 # otherwise parallel compilation will fail if a source is compiled first.
1027 % for src in sorted(sources_that_need_openssl):
1028 % if src not in sources_that_don_t_need_openssl:
1029 ${src}: $(OPENSSL_DEP)
1030 % endif
1031 % endfor
1032 endif
1033
1034 .PHONY: all strip tools \
1035 dep_error openssl_dep_error openssl_dep_message git_update stop \
1036 buildtests buildtests_c buildtests_cxx \
1037 test test_c test_cxx \
1038 install install_c install_cxx install_csharp install-static install-certs \
1039 strip strip-shared strip-static \
1040 strip_c strip-shared_c strip-static_c \
1041 strip_cxx strip-shared_cxx strip-static_cxx \
1042 dep_c dep_cxx bins_dep_c bins_dep_cxx \
1043 clean
1044
1045 .PHONY: printvars
1046 printvars:
1047 @$(foreach V,$(sort $(.VARIABLES)), \
1048 $(if $(filter-out environment% default automatic, \
1049 $(origin $V)),$(warning $V=$($V) ($(value $V)))))