xref: /aosp_15_r20/external/grpc-grpc/templates/Makefile.template (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
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
28    def get_dep_expression(dep):
29      """For given dependency, return the expression to be used in Makefile rule dependencies."""
30      if dep == 'z':
31          return "$(ZLIB_DEP)"
32      elif dep == 'libssl':
33          return "$(OPENSSL_DEP)"
34      else:
35          return "$(LIBDIR)/$(CONFIG)/lib%s.a" % dep
36
37
38    def get_merge_libs_expression(dep):
39      """For given dependency, return the lib archive expression to be used when linking."""
40      if dep == 'z':
41          return "$(ZLIB_MERGE_LIBS)"
42      elif dep == 'libssl':
43          return "$(OPENSSL_MERGE_LIBS)"
44      else:
45          return "$(LIBDIR)/$(CONFIG)/lib%s.a" % dep
46
47
48    def get_objs_expression(dep):
49      """For given dependency, return the expression with variable that has list of all object files."""
50      if dep == 'z':
51          return "$(ZLIB_MERGE_OBJS)"
52      elif dep == 'libssl':
53          return "$(OPENSSL_MERGE_OBJS)"
54      else:
55          return "$(LIB%s_OBJS)" % dep.upper()
56
57
58    def get_make_rule_static_lib_deps(lib):
59      """Generate make rule dependency list for given library, when building as static."""
60
61      make_rule_deps = []
62      collapsed_deps = lib.get('transitive_deps', [])
63
64      # depend on static libraries
65      for dep in collapsed_deps:
66          make_rule_deps.append(get_dep_expression(dep))
67
68      # depend of obj files of this library itself
69      make_rule_deps.append(get_objs_expression(lib.name))
70
71      # depend on obj files of dependencies
72      for dep in collapsed_deps:
73          make_rule_deps.append(get_objs_expression(dep))
74
75      return " ".join(make_rule_deps)
76
77
78    def get_merge_objs_for_deps(lib):
79      """Get list of merge objs for all deps of a given library."""
80      result = []
81      collapsed_deps = lib.get('transitive_deps', [])
82
83      for dep in collapsed_deps:
84          result.append(get_objs_expression(dep))
85
86      return " ".join(result)
87
88
89    def get_make_rule_shared_lib_deps(lib):
90      """Generate make rule dependency list given library, when built as shared."""
91      make_rule_deps = []
92
93      collapsed_deps = lib.get('transitive_deps', [])
94
95      # depend of obj files of this library itself
96      make_rule_deps.append(get_objs_expression(lib.name))
97
98      # depend on static libraries
99      for dep in collapsed_deps:
100          make_rule_deps.append(get_dep_expression(dep))
101
102      return " ".join(make_rule_deps)
103
104
105    def get_shared_lib_linklibs(lib):
106      """Generate list of libraries to link given library, when built as shared."""
107      result = []
108
109      collapsed_deps = lib.get('transitive_deps', [])
110
111      # depend of obj files of this library itself
112      result.append(get_objs_expression(lib.name))
113
114      # depend on static libraries
115      for dep in collapsed_deps:
116          result.append(get_merge_libs_expression(dep))
117
118      if 'libssl' in collapsed_deps:
119          result.append("$(LDLIBS_SECURE)")
120
121      result.append("$(LDLIBS)")
122
123      return " ".join(result)
124
125
126    lang_to_var = {
127      'c': 'CORE',
128      'c++': 'CPP',
129    }
130  %>
131  <%
132    lib_maps = {lib.name: lib for lib in libs}
133    sys_libs = ['boringssl', 'cares', 'libssl', 'z']
134
135    # Build a new gRPC target which embeds sources of all dependencies except system libraries such as libz
136    grpc_lib = lib_maps.get('grpc', None)
137    for dep in set(grpc_lib.transitive_deps) - set(sys_libs):
138      dep_lib = lib_maps.get(dep, None)
139      if dep_lib:
140         grpc_lib.src += dep_lib.src
141         grpc_lib.headers += dep_lib.headers
142    grpc_lib.src = list(sorted(set(grpc_lib.src)))
143    grpc_lib.headers = list(sorted(set(grpc_lib.headers)))
144    grpc_lib.deps = list(sorted(list(set(grpc_lib.deps) & set(sys_libs))))
145    grpc_lib.transitive_deps = list(sorted(list(set(grpc_lib.transitive_deps) & set(sys_libs))))
146
147    # Makefile is only intended for internal needs (building distribution artifacts etc.)
148    # so we can restrict the number of libraries/targets that are buildable using the Makefile.
149    # Other targets can be built with cmake or bazel.
150    filtered_libs = [grpc_lib, ] + [lib_maps[lib] for lib in sys_libs if lib != 'libssl']
151  %>
152
153  comma := ,
154
155
156  # Basic platform detection
157  HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
158  SYSTEM ?= $(HOST_SYSTEM)
159  ifeq ($(SYSTEM),MSYS)
160  SYSTEM = MINGW32
161  endif
162  ifeq ($(SYSTEM),MINGW64)
163  SYSTEM = MINGW32
164  endif
165
166  MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
167  ifndef BUILDDIR
168  BUILDDIR_ABSOLUTE = $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))
169  else
170  BUILDDIR_ABSOLUTE = $(abspath $(BUILDDIR))
171  endif
172
173  HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false)
174  HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false)
175  HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false)
176
177  ifeq ($(HAS_CC),true)
178  DEFAULT_CC = cc
179  DEFAULT_CXX = c++
180  else
181  ifeq ($(HAS_GCC),true)
182  DEFAULT_CC = gcc
183  DEFAULT_CXX = g++
184  else
185  ifeq ($(HAS_CLANG),true)
186  DEFAULT_CC = clang
187  DEFAULT_CXX = clang++
188  else
189  DEFAULT_CC = no_c_compiler
190  DEFAULT_CXX = no_c++_compiler
191  endif
192  endif
193  endif
194
195
196  BINDIR = $(BUILDDIR_ABSOLUTE)/bins
197  OBJDIR = $(BUILDDIR_ABSOLUTE)/objs
198  LIBDIR = $(BUILDDIR_ABSOLUTE)/libs
199  GENDIR = $(BUILDDIR_ABSOLUTE)/gens
200
201  # Configurations (as defined under "configs" section in build_handwritten.yaml)
202
203  % for name, args in configs.items():
204  VALID_CONFIG_${name} = 1
205  %  if args.get('compile_the_world', False):
206  REQUIRE_CUSTOM_LIBRARIES_${name} = 1
207  %  endif
208  %  for tool, default in [('CC', 'CC'), ('CXX', 'CXX'), ('LD', 'CC'), ('LDXX', 'CXX')]:
209  ${tool}_${name} = ${args.get(tool, '$(DEFAULT_%s)' % default)}
210  %  endfor
211  %  for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES']:
212  %   if args.get(arg, None) is not None:
213  ${arg}_${name} = ${args.get(arg)}
214  %   endif
215  %  endfor
216
217  % endfor
218
219
220  # General settings.
221  # You may want to change these depending on your system.
222
223  prefix ?= /usr/local
224
225  DTRACE ?= dtrace
226  CONFIG ?= opt
227  # Doing X ?= Y is the same as:
228  # ifeq ($(origin X), undefined)
229  #  X = Y
230  # endif
231  # but some variables, such as CC, CXX, LD or AR, have defaults.
232  # So instead of using ?= on them, we need to check their origin.
233  # See:
234  #  https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
235  #  https://www.gnu.org/software/make/manual/html_node/Flavors.html#index-_003f_003d
236  #  https://www.gnu.org/software/make/manual/html_node/Origin-Function.html
237  ifeq ($(origin CC), default)
238  CC = $(CC_$(CONFIG))
239  endif
240  ifeq ($(origin CXX), default)
241  CXX = $(CXX_$(CONFIG))
242  endif
243  ifeq ($(origin LD), default)
244  LD = $(LD_$(CONFIG))
245  endif
246  LDXX ?= $(LDXX_$(CONFIG))
247  ARFLAGS ?= rcs
248  ifeq ($(SYSTEM),Linux)
249  ifeq ($(origin AR), default)
250  AR = ar
251  endif
252  STRIP ?= strip --strip-unneeded
253  else
254  ifeq ($(SYSTEM),Darwin)
255  ifeq ($(origin AR), default)
256  AR = libtool
257  ARFLAGS = -no_warning_for_no_symbols -o
258  endif
259  STRIP ?= strip -x
260  else
261  ifeq ($(SYSTEM),MINGW32)
262  ifeq ($(origin AR), default)
263  AR = ar
264  endif
265  STRIP ?= strip --strip-unneeded
266  else
267  ifeq ($(origin AR), default)
268  AR = ar
269  endif
270  STRIP ?= strip
271  endif
272  endif
273  endif
274  INSTALL ?= install
275  RM ?= rm -f
276  PKG_CONFIG ?= pkg-config
277  RANLIB ?= ranlib
278  ifeq ($(SYSTEM),Darwin)
279  APPLE_RANLIB = $(shell [[ "`$(RANLIB) -V 2>/dev/null`" == "Apple Inc."* ]]; echo $$?)
280  ifeq ($(APPLE_RANLIB),0)
281  RANLIBFLAGS = -no_warning_for_no_symbols
282  endif
283  endif
284
285  ifndef VALID_CONFIG_$(CONFIG)
286  $(error Invalid CONFIG value '$(CONFIG)')
287  endif
288
289  # The HOST compiler settings are used to compile the protoc plugins.
290  # In most cases, you won't have to change anything, but if you are
291  # cross-compiling, you can override these variables from GNU make's
292  # command line: make CC=cross-gcc HOST_CC=gcc
293
294  HOST_CC ?= $(CC)
295  HOST_CXX ?= $(CXX)
296  HOST_LD ?= $(LD)
297  HOST_LDXX ?= $(LDXX)
298
299  CFLAGS += -std=c11
300  CXXFLAGS += -std=c++14
301  ifeq ($(SYSTEM),Darwin)
302  CXXFLAGS += -stdlib=libc++
303  LDFLAGS += -framework CoreFoundation
304  endif
305  % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'COREFLAGS', 'LDFLAGS', 'DEFINES']:
306  %  if defaults.get('global', []).get(arg, None) is not None:
307  ${arg} += ${defaults.get('global').get(arg)}
308  %  endif
309  % endfor
310
311  CPPFLAGS += $(CPPFLAGS_$(CONFIG))
312  CFLAGS += $(CFLAGS_$(CONFIG))
313  CXXFLAGS += $(CXXFLAGS_$(CONFIG))
314  DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\"
315  LDFLAGS += $(LDFLAGS_$(CONFIG))
316
317  ifneq ($(SYSTEM),MINGW32)
318  PIC_CPPFLAGS = -fPIC
319  CPPFLAGS += -fPIC
320  LDFLAGS += -fPIC
321  endif
322
323  INCLUDES = . include $(GENDIR)
324  LDFLAGS += -Llibs/$(CONFIG)
325
326  ifeq ($(SYSTEM),Darwin)
327  ifneq ($(wildcard /usr/local/ssl/include),)
328  INCLUDES += /usr/local/ssl/include
329  endif
330  ifneq ($(wildcard /opt/local/include),)
331  INCLUDES += /opt/local/include
332  endif
333  ifneq ($(wildcard /usr/local/include),)
334  INCLUDES += /usr/local/include
335  endif
336  LIBS = m z
337  ifneq ($(wildcard /usr/local/ssl/lib),)
338  LDFLAGS += -L/usr/local/ssl/lib
339  endif
340  ifneq ($(wildcard /opt/local/lib),)
341  LDFLAGS += -L/opt/local/lib
342  endif
343  ifneq ($(wildcard /usr/local/lib),)
344  LDFLAGS += -L/usr/local/lib
345  endif
346  endif
347
348  ifeq ($(SYSTEM),Linux)
349  LIBS = dl rt m pthread
350  LDFLAGS += -pthread
351  endif
352
353  ifeq ($(SYSTEM),MINGW32)
354  LIBS = m pthread ws2_32 crypt32 iphlpapi dbghelp bcrypt
355  LDFLAGS += -pthread
356  endif
357
358  #
359  # The steps for cross-compiling are as follows:
360  # First, clone and make install of grpc using the native compilers for the host.
361  # Also, install protoc (e.g., from a package like apt-get)
362  # Then clone a fresh grpc for the actual cross-compiled build
363  # Set the environment variable GRPC_CROSS_COMPILE to true
364  # Set CC, CXX, LD, LDXX, AR, and STRIP to the cross-compiling binaries
365  # Also set PROTOBUF_CONFIG_OPTS to indicate cross-compilation to protobuf (e.g.,
366  #  PROTOBUF_CONFIG_OPTS="--host=arm-linux --with-protoc=/usr/local/bin/protoc" )
367  # Set HAS_PKG_CONFIG=false
368  # Make sure that you enable building shared libraries and set your prefix to
369  # something useful like /usr/local/cross
370  # You will also need to set GRPC_CROSS_LDOPTS and GRPC_CROSS_AROPTS to hold
371  # additional required arguments for LD and AR (examples below)
372  # Then you can do a make from the cross-compiling fresh clone!
373  #
374  ifeq ($(GRPC_CROSS_COMPILE),true)
375  LDFLAGS += $(GRPC_CROSS_LDOPTS) # e.g. -L/usr/local/lib -L/usr/local/cross/lib
376  ARFLAGS += $(GRPC_CROSS_AROPTS) # e.g., rc --target=elf32-little
377  USE_BUILT_PROTOC = false
378  endif
379
380  # V=1 can be used to print commands run by make
381  ifeq ($(V),1)
382  E = @:
383  Q =
384  else
385  E = @echo
386  Q = @
387  endif
388
389  CORE_VERSION = ${settings.core_version}
390  CPP_VERSION = ${settings.cpp_version}
391
392  CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES))
393  CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)
394
395  LDFLAGS += $(ARCH_FLAGS)
396  LDLIBS += $(addprefix -l, $(LIBS))
397  LDLIBSXX += $(addprefix -l, $(LIBSXX))
398
399
400  % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES', 'LDLIBS']:
401  ${arg} += $(EXTRA_${arg})
402  % endfor
403
404  HOST_CPPFLAGS += $(CPPFLAGS)
405  HOST_CFLAGS += $(CFLAGS)
406  HOST_CXXFLAGS += $(CXXFLAGS)
407  HOST_LDFLAGS += $(LDFLAGS)
408  HOST_LDLIBS += $(LDLIBS)
409
410  # These are automatically computed variables.
411  # There shouldn't be any need to change anything from now on.
412
413  -include cache.mk
414
415  CACHE_MK =
416
417  ifeq ($(SYSTEM),MINGW32)
418  EXECUTABLE_SUFFIX = .exe
419  SHARED_EXT_CORE = dll
420  SHARED_EXT_CPP = dll
421
422  SHARED_PREFIX =
423  SHARED_VERSION_CORE = -${settings.core_version.major}
424  SHARED_VERSION_CPP = -${settings.cpp_version.major}
425  else ifeq ($(SYSTEM),Darwin)
426  EXECUTABLE_SUFFIX =
427  SHARED_EXT_CORE = dylib
428  SHARED_EXT_CPP = dylib
429  SHARED_PREFIX = lib
430  SHARED_VERSION_CORE =
431  SHARED_VERSION_CPP =
432  else
433  EXECUTABLE_SUFFIX =
434  SHARED_EXT_CORE = so.$(CORE_VERSION)
435  SHARED_EXT_CPP = so.$(CPP_VERSION)
436  SHARED_PREFIX = lib
437  SHARED_VERSION_CORE =
438  SHARED_VERSION_CPP =
439  endif
440
441  ifeq ($(wildcard .git),)
442  IS_GIT_FOLDER = false
443  else
444  IS_GIT_FOLDER = true
445  endif
446
447  # Setup zlib dependency
448
449  ifeq ($(wildcard third_party/zlib/zlib.h),)
450  HAS_EMBEDDED_ZLIB = false
451  else
452  HAS_EMBEDDED_ZLIB = true
453  endif
454
455  # for zlib, we support building both from submodule
456  # and from system-installed zlib. In some builds,
457  # embedding zlib is not desirable.
458  # By default we use the system zlib (to match legacy behavior)
459  EMBED_ZLIB ?= false
460
461  ifeq ($(EMBED_ZLIB),true)
462  ZLIB_DEP = $(LIBDIR)/$(CONFIG)/libz.a
463  ZLIB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libz.a
464  ZLIB_MERGE_OBJS = $(LIBZ_OBJS)
465  CPPFLAGS += -Ithird_party/zlib
466  else
467  LIBS += z
468  endif
469
470  # Setup boringssl dependency
471
472  ifeq ($(wildcard third_party/boringssl-with-bazel/src/include/openssl/ssl.h),)
473  HAS_EMBEDDED_OPENSSL = false
474  else
475  HAS_EMBEDDED_OPENSSL = true
476  endif
477
478  ifeq ($(HAS_EMBEDDED_OPENSSL),true)
479  EMBED_OPENSSL ?= true
480  else
481  # only support building boringssl from submodule
482  DEP_MISSING += openssl
483  EMBED_OPENSSL ?= broken
484  endif
485
486  ifeq ($(EMBED_OPENSSL),true)
487  OPENSSL_DEP += $(LIBDIR)/$(CONFIG)/libboringssl.a
488  OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/libboringssl.a
489  OPENSSL_MERGE_OBJS += $(LIBBORINGSSL_OBJS)
490  # need to prefix these to ensure overriding system libraries
491  CPPFLAGS := -Ithird_party/boringssl-with-bazel/src/include $(CPPFLAGS)
492  ifeq ($(DISABLE_ALPN),true)
493  CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0
494  LIBS_SECURE = $(OPENSSL_LIBS)
495  endif # DISABLE_ALPN
496  endif # EMBED_OPENSSL
497
498  LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
499
500  ifeq ($(MAKECMDGOALS),clean)
501  NO_DEPS = true
502  endif
503
504  ifeq ($(DEP_MISSING),)
505  all: static shared
506
507  dep_error:
508  	@echo "You shouldn't see this message - all of your dependencies are correct."
509  else
510  all: dep_error git_update stop
511
512  dep_error:
513  	@echo
514  	@echo "DEPENDENCY ERROR"
515  	@echo
516  	@echo "You are missing system dependencies that are essential to build grpc,"
517  	@echo "and the third_party directory doesn't have them:"
518  	@echo
519  	@echo "  $(DEP_MISSING)"
520  	@echo
521  	@echo "Installing the development packages for your system will solve"
522  	@echo "this issue. Please consult INSTALL to get more information."
523  	@echo
524  	@echo "If you need information about why these tests failed, run:"
525  	@echo
526  	@echo "  make run_dep_checks"
527  	@echo
528  endif
529
530  git_update:
531  ifeq ($(IS_GIT_FOLDER),true)
532  	@echo "Additionally, since you are in a git clone, you can download the"
533  	@echo "missing dependencies in third_party by running the following command:"
534  	@echo
535  	@echo "  git submodule update --init"
536  	@echo
537  endif
538
539  openssl_dep_error: openssl_dep_message git_update stop
540
541  openssl_dep_message:
542  	@echo
543  	@echo "DEPENDENCY ERROR"
544  	@echo
545  	@echo "The target you are trying to run requires an OpenSSL implementation."
546  	@echo "Your system doesn't have one, and either the third_party directory"
547  	@echo "doesn't have it, or your compiler can't build BoringSSL."
548  	@echo
549  	@echo "Please consult BUILDING.md to get more information."
550  	@echo
551  	@echo "If you need information about why these tests failed, run:"
552  	@echo
553  	@echo "  make run_dep_checks"
554  	@echo
555
556  systemtap_dep_error:
557  	@echo
558  	@echo "DEPENDENCY ERROR"
559  	@echo
560  	@echo "Under the '$(CONFIG)' configuration, the target you are trying "
561  	@echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other "
562  	@echo "platforms such as Solaris and *BSD). "
563  	@echo
564  	@echo "Please consult BUILDING.md to get more information."
565  	@echo
566
567  install_not_supported_message:
568  	@echo
569  	@echo "Installing via 'make' is no longer supported. Use cmake or bazel instead."
570  	@echo
571  	@echo "Please consult BUILDING.md to get more information."
572  	@echo
573
574  install_not_supported_error: install_not_supported_message stop
575
576  stop:
577  	@false
578
579  run_dep_checks:
580  	@echo "run_dep_checks target has been deprecated."
581
582  static: static_c static_cxx
583
584  static_c: cache.mk \
585  % for lib in filtered_libs:
586  % if 'Makefile' in lib.get('build_system', ['Makefile']):
587  % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
588   $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
589  % endif
590  % endif
591  % endfor
592
593
594  static_cxx: cache.mk \
595  % for lib in filtered_libs:
596  % if 'Makefile' in lib.get('build_system', ['Makefile']):
597  % if lib.build == 'all' and lib.language == 'c++':
598   $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
599  % endif
600  % endif
601  % endfor
602
603
604  shared: shared_c shared_cxx
605
606  shared_c: cache.mk\
607  % for lib in filtered_libs:
608  % if 'Makefile' in lib.get('build_system', ['Makefile']):
609  % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None):
610   $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)\
611  % endif
612  % endif
613  % endfor
614
615  shared_cxx: cache.mk\
616  % for lib in filtered_libs:
617  % if 'Makefile' in lib.get('build_system', ['Makefile']):
618  % if lib.build == 'all' and lib.language == 'c++':
619   $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)\
620  % endif
621  % endif
622  % endfor
623
624
625  privatelibs: privatelibs_c privatelibs_cxx
626
627  privatelibs_c: \
628  % for lib in filtered_libs:
629  % if 'Makefile' in lib.get('build_system', ['Makefile']):
630  % if lib.build == 'private' and lib.language == 'c' and not lib.get('external_deps', None) and not lib.boringssl:
631   $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
632  % endif
633  % endif
634  % endfor
635
636  ifeq ($(EMBED_OPENSSL),true)
637  privatelibs_cxx: \
638  % for lib in filtered_libs:
639  % if 'Makefile' in lib.get('build_system', ['Makefile']):
640  % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None):
641   $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
642  % endif
643  % endif
644  % endfor
645
646  else
647  privatelibs_cxx: \
648  % for lib in filtered_libs:
649  % if 'Makefile' in lib.get('build_system', ['Makefile']):
650  % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None) and not lib.boringssl:
651   $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\
652  % endif
653  % endif
654  % endfor
655
656  endif
657
658
659  strip: strip-static strip-shared
660
661  strip-static: strip-static_c strip-static_cxx
662
663  strip-shared: strip-shared_c strip-shared_cxx
664
665  strip-static_c: static_c
666  ifeq ($(CONFIG),opt)
667  % for lib in filtered_libs:
668  % if 'Makefile' in lib.get('build_system', ['Makefile']):
669  % if lib.language == "c":
670  % if lib.build == "all":
671  % if not lib.get('external_deps', None):
672  	$(E) "[STRIP]   Stripping lib${lib.name}.a"
673  	$(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
674  % endif
675  % endif
676  % endif
677  % endif
678  % endfor
679  endif
680
681  strip-static_cxx: static_cxx
682  ifeq ($(CONFIG),opt)
683  % for lib in filtered_libs:
684  % if 'Makefile' in lib.get('build_system', ['Makefile']):
685  % if lib.language == "c++":
686  % if lib.build == "all":
687  	$(E) "[STRIP]   Stripping lib${lib.name}.a"
688  	$(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
689  % endif
690  % endif
691  % endif
692  % endfor
693  endif
694
695  strip-shared_c: shared_c
696  ifeq ($(CONFIG),opt)
697  % for lib in filtered_libs:
698  % if 'Makefile' in lib.get('build_system', ['Makefile']):
699  % if lib.language == "c":
700  % if lib.build == "all":
701  % if not lib.get('external_deps', None):
702  	$(E) "[STRIP]   Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)"
703  	$(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)
704  % endif
705  % endif
706  % endif
707  % endif
708  % endfor
709  endif
710
711  strip-shared_cxx: shared_cxx
712  ifeq ($(CONFIG),opt)
713  % for lib in filtered_libs:
714  % if 'Makefile' in lib.get('build_system', ['Makefile']):
715  % if lib.language == "c++":
716  % if lib.build == "all":
717  	$(E) "[STRIP]   Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)"
718  	$(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)
719  % endif
720  % endif
721  % endif
722  % endfor
723  endif
724
725  cache.mk::
726  	$(E) "[MAKE]    Generating $@"
727  	$(Q) echo "$(CACHE_MK)" | tr , '\n' >$@
728
729  $(OBJDIR)/$(CONFIG)/%.o : %.c
730  	$(E) "[C]       Compiling $<"
731  	$(Q) mkdir -p `dirname $@`
732  	$(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
733
734  $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc
735  	$(E) "[CXX]     Compiling $<"
736  	$(Q) mkdir -p `dirname $@`
737  	$(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
738
739  $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc
740  	$(E) "[HOSTCXX] Compiling $<"
741  	$(Q) mkdir -p `dirname $@`
742  	$(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
743
744  $(OBJDIR)/$(CONFIG)/src/core/%.o : src/core/%.cc
745  	$(E) "[CXX]     Compiling $<"
746  	$(Q) mkdir -p `dirname $@`
747  	$(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
748
749  $(OBJDIR)/$(CONFIG)/%.o : %.cc
750  	$(E) "[CXX]     Compiling $<"
751  	$(Q) mkdir -p `dirname $@`
752  	$(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
753
754  $(OBJDIR)/$(CONFIG)/%.o : %.cpp
755  	$(E) "[CXX]     Compiling $<"
756  	$(Q) mkdir -p `dirname $@`
757  	$(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
758
759  install: install_not_supported_error
760
761  install_c: install_not_supported_error
762
763  install_cxx: install_not_supported_error
764
765  install-static: install_not_supported_error
766
767  install-certs: install_not_supported_error
768
769  clean:
770  	$(E) "[CLEAN]   Cleaning build directories."
771  	$(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk
772
773
774  # The various libraries
775
776  % for lib in filtered_libs:
777  % if 'Makefile' in lib.get('build_system', ['Makefile']):
778  ${makelib(lib)}
779  % endif
780  % endfor
781
782  <%def name="makelib(lib)">
783  # start of build recipe for library "${lib.name}" (generated by makelib(lib) template function)
784  # deps: ${lib.get('deps', [])}
785  # transitive_deps: ${lib.get('transitive_deps', [])}
786  LIB${lib.name.upper()}_SRC = \\
787
788  % for src in sorted(lib.src):
789      ${src} \\
790
791  % endfor
792
793  % if "public_headers" in lib:
794  % if lib.language == "c++":
795  PUBLIC_HEADERS_CXX += \\
796
797  % else:
798  PUBLIC_HEADERS_C += \\
799
800  % endif
801  % for hdr in sorted(lib.public_headers):
802      ${hdr} \\
803
804  % endfor
805  % endif
806
807  LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC))))
808
809  % if lib.get('defaults', None):
810  %  for name, value in defaults.get(lib.defaults).items():
811  $(LIB${lib.name.upper()}_OBJS): ${name} += ${value}
812  %  endfor
813  % endif
814
815  ## If the library requires OpenSSL, let's add some restrictions.
816  % if 'libssl' in lib.get('transitive_deps', []):
817  ifeq ($(NO_SECURE),true)
818
819  # You can't build secure libraries if you don't have OpenSSL.
820
821  $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error
822
823  % if lib.build == "all":
824  $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}): openssl_dep_error
825  % endif
826
827  else
828
829  ## The following endif corresponds to the "If the library requires OpenSSL" above
830  % endif
831  # static library for "${lib.name}"
832  $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: ${get_make_rule_static_lib_deps(lib)}
833  	$(E) "[AR]      Creating $@"
834  	$(Q) mkdir -p `dirname $@`
835  	$(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
836  	$(Q) $(AR) $(ARFLAGS) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) ${get_merge_objs_for_deps(lib)}
837  ifeq ($(SYSTEM),Darwin)
838  	$(Q) $(RANLIB) $(RANLIBFLAGS) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a
839  endif
840  <%
841    ld = '$(LDXX)'
842
843    out_mingbase = '$(LIBDIR)/$(CONFIG)/' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
844    out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')'
845
846    ldflags = '$(LDFLAGS)'
847    if lib.get('LDFLAGS', None):
848      ldflags += ' ' + lib['LDFLAGS']
849  %>
850  # shared library for "${lib.name}"
851  % if lib.build == "all":
852  ifeq ($(SYSTEM),MINGW32)
853  ${out_mingbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): ${get_make_rule_shared_lib_deps(lib)}
854  	$(E) "[LD]      Linking $@"
855  	$(Q) mkdir -p `dirname $@`
856  	$(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]}) ${get_shared_lib_linklibs(lib)}
857  else
858  ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): ${get_make_rule_shared_lib_deps(lib)}
859  	$(E) "[LD]      Linking $@"
860  	$(Q) mkdir -p `dirname $@`
861  ifeq ($(SYSTEM),Darwin)
862  	$(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]}) ${get_shared_lib_linklibs(lib)}
863  else
864  	$(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]}) ${get_shared_lib_linklibs(lib)}
865  	$(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}
866  	$(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) ${out_libbase}.so
867  endif
868  endif
869  % endif
870  % if 'libssl' in lib.get('transitive_deps', []):
871  ## If the lib was secure, we have to close the Makefile's ifeq that tested
872  ## the presence of OpenSSL.
873
874  endif  # corresponds to the "ifeq ($(NO_SECURE),true)" above
875  % endif
876
877  % if 'libssl' in lib.get('transitive_deps', []):
878  ifneq ($(NO_SECURE),true)
879  % endif
880  ifneq ($(NO_DEPS),true)
881  -include $(LIB${lib.name.upper()}_OBJS:.o=.dep)
882  endif
883  % if 'libssl' in lib.get('transitive_deps', []):
884  endif
885  % endif
886  # end of build recipe for library "${lib.name}"
887  </%def>
888
889  .PHONY: all strip tools \
890  dep_error openssl_dep_error openssl_dep_message git_update stop \
891  buildtests buildtests_c buildtests_cxx \
892  test test_c test_cxx \
893  install install_c install_cxx install-static install-certs \
894  strip strip-shared strip-static \
895  strip_c strip-shared_c strip-static_c \
896  strip_cxx strip-shared_cxx strip-static_cxx \
897  dep_c dep_cxx bins_dep_c bins_dep_cxx \
898  clean
899
900  .PHONY: printvars
901  printvars:
902  	@$(foreach V,$(sort $(.VARIABLES)),                 \
903  	  $(if $(filter-out environment% default automatic, \
904  	  $(origin $V)),$(warning $V=$($V) ($(value $V)))))
905