|
|
|
@ -24,31 +24,11 @@ |
|
|
|
|
import re
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
def is_absl_lib(target_name):
|
|
|
|
|
"""Returns True if the target name is one of the abseil libraries."""
|
|
|
|
|
return target_name.startswith("absl/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def collapse_absl_deps(deps):
|
|
|
|
|
"""Replace first occurrence of absl dependency with grpc_abseil and remove the remaining absl dependencies."""
|
|
|
|
|
result = []
|
|
|
|
|
absl_dep_added = False
|
|
|
|
|
for dep in deps:
|
|
|
|
|
if is_absl_lib(dep):
|
|
|
|
|
if not absl_dep_added:
|
|
|
|
|
result.append('grpc_abseil')
|
|
|
|
|
absl_dep_added = True
|
|
|
|
|
else:
|
|
|
|
|
result.append(dep)
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_dep_expression(dep):
|
|
|
|
|
"""For given dependency, return the expression to be used in Makefile rule dependencies."""
|
|
|
|
|
if dep == 'z':
|
|
|
|
|
return "$(ZLIB_DEP)"
|
|
|
|
|
elif dep == 'grpc_abseil':
|
|
|
|
|
return "$(GRPC_ABSEIL_DEP)"
|
|
|
|
|
elif dep == 'libssl':
|
|
|
|
|
return "$(OPENSSL_DEP)"
|
|
|
|
|
else:
|
|
|
|
@ -59,8 +39,6 @@ |
|
|
|
|
"""For given dependency, return the lib archive expression to be used when linking."""
|
|
|
|
|
if dep == 'z':
|
|
|
|
|
return "$(ZLIB_MERGE_LIBS)"
|
|
|
|
|
elif dep == 'grpc_abseil':
|
|
|
|
|
return "$(GRPC_ABSEIL_MERGE_LIBS)"
|
|
|
|
|
elif dep == 'libssl':
|
|
|
|
|
return "$(OPENSSL_MERGE_LIBS)"
|
|
|
|
|
else:
|
|
|
|
@ -71,8 +49,6 @@ |
|
|
|
|
"""For given dependency, return the expression with variable that has list of all object files."""
|
|
|
|
|
if dep == 'z':
|
|
|
|
|
return "$(ZLIB_MERGE_OBJS)"
|
|
|
|
|
elif dep == 'grpc_abseil':
|
|
|
|
|
return "$(LIBGRPC_ABSEIL_OBJS)"
|
|
|
|
|
elif dep == 'libssl':
|
|
|
|
|
return "$(OPENSSL_MERGE_OBJS)"
|
|
|
|
|
else:
|
|
|
|
@ -83,8 +59,7 @@ |
|
|
|
|
"""Generate make rule dependency list for given library, when building as static."""
|
|
|
|
|
|
|
|
|
|
make_rule_deps = []
|
|
|
|
|
|
|
|
|
|
collapsed_deps = collapse_absl_deps(lib.get('transitive_deps', []))
|
|
|
|
|
collapsed_deps = lib.get('transitive_deps', [])
|
|
|
|
|
|
|
|
|
|
# depend on static libraries
|
|
|
|
|
for dep in collapsed_deps:
|
|
|
|
@ -103,7 +78,7 @@ |
|
|
|
|
def get_merge_objs_for_deps(lib):
|
|
|
|
|
"""Get list of merge objs for all deps of a given library."""
|
|
|
|
|
result = []
|
|
|
|
|
collapsed_deps = collapse_absl_deps(lib.get('transitive_deps', []))
|
|
|
|
|
collapsed_deps = lib.get('transitive_deps', [])
|
|
|
|
|
|
|
|
|
|
for dep in collapsed_deps:
|
|
|
|
|
result.append(get_objs_expression(dep))
|
|
|
|
@ -115,7 +90,7 @@ |
|
|
|
|
"""Generate make rule dependency list given library, when built as shared."""
|
|
|
|
|
make_rule_deps = []
|
|
|
|
|
|
|
|
|
|
collapsed_deps = collapse_absl_deps(lib.get('transitive_deps', []))
|
|
|
|
|
collapsed_deps = lib.get('transitive_deps', [])
|
|
|
|
|
|
|
|
|
|
# depend of obj files of this library itself
|
|
|
|
|
make_rule_deps.append(get_objs_expression(lib.name))
|
|
|
|
@ -131,7 +106,7 @@ |
|
|
|
|
"""Generate list of libraries to link given library, when built as shared."""
|
|
|
|
|
result = []
|
|
|
|
|
|
|
|
|
|
collapsed_deps = collapse_absl_deps(lib.get('transitive_deps', []))
|
|
|
|
|
collapsed_deps = lib.get('transitive_deps', [])
|
|
|
|
|
|
|
|
|
|
# depend of obj files of this library itself
|
|
|
|
|
result.append(get_objs_expression(lib.name))
|
|
|
|
@ -148,37 +123,31 @@ |
|
|
|
|
return " ".join(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sources_that_need_openssl = set()
|
|
|
|
|
sources_that_don_t_need_openssl = set()
|
|
|
|
|
|
|
|
|
|
# warnings we'd like, but that don't exist in all compilers
|
|
|
|
|
PREFERRED_WARNINGS=['extra-semi']
|
|
|
|
|
CHECK_WARNINGS=PREFERRED_WARNINGS + ['no-shift-negative-value', 'no-unused-but-set-variable', 'no-maybe-uninitialized', 'no-unknown-warning-option']
|
|
|
|
|
|
|
|
|
|
def warning_var(fmt, warning):
|
|
|
|
|
return fmt % warning.replace('-', '_').replace('+', 'X').upper()
|
|
|
|
|
|
|
|
|
|
def neg_warning(warning):
|
|
|
|
|
if warning[0:3] == 'no-':
|
|
|
|
|
return warning[3:]
|
|
|
|
|
else:
|
|
|
|
|
return 'no-' + warning
|
|
|
|
|
|
|
|
|
|
lang_to_var = {
|
|
|
|
|
'c': 'CORE',
|
|
|
|
|
'c++': 'CPP',
|
|
|
|
|
}
|
|
|
|
|
%>
|
|
|
|
|
<%
|
|
|
|
|
lib_maps = {lib.name: lib for lib in libs}
|
|
|
|
|
sys_libs = ['boringssl', 'cares', 'libssl', 'z']
|
|
|
|
|
|
|
|
|
|
# Build a new gRPC target which embeds sources of all dependencies except system libraries such as libz
|
|
|
|
|
grpc_lib = lib_maps.get('grpc', None)
|
|
|
|
|
for dep in set(grpc_lib.transitive_deps) - set(sys_libs):
|
|
|
|
|
dep_lib = lib_maps.get(dep, None)
|
|
|
|
|
if dep_lib:
|
|
|
|
|
grpc_lib.src += dep_lib.src
|
|
|
|
|
grpc_lib.headers += dep_lib.headers
|
|
|
|
|
grpc_lib.src = list(sorted(set(grpc_lib.src)))
|
|
|
|
|
grpc_lib.headers = list(sorted(set(grpc_lib.headers)))
|
|
|
|
|
grpc_lib.deps = list(sorted(list(set(grpc_lib.deps) & set(sys_libs))))
|
|
|
|
|
grpc_lib.transitive_deps = list(sorted(list(set(grpc_lib.transitive_deps) & set(sys_libs))))
|
|
|
|
|
|
|
|
|
|
# Makefile is only intended for internal needs (building distribution artifacts etc.)
|
|
|
|
|
# so we can restrict the number of libraries/targets that are buildable using the Makefile.
|
|
|
|
|
# Other targets can be built with cmake or bazel.
|
|
|
|
|
# TODO(jtattermusch): Figure out how to avoid the need to list the dependencies explicitly.
|
|
|
|
|
# Currently it is necessary because some dependencies are marked as "build: private" in build.yaml
|
|
|
|
|
# (which itself is correct, as they are not "public" libraries from our perspective and cmake
|
|
|
|
|
# needs to have them marked as such)
|
|
|
|
|
filtered_libs = [lib for lib in libs if (lib.build in ['all'] and lib.language != 'c++') or lib.name in ['cares', 'boringssl', 'z']]
|
|
|
|
|
filtered_targets = [tgt for tgt in targets if tgt.build in ['all'] and lib.language != 'c++']
|
|
|
|
|
filtered_libs = [grpc_lib, ] + [lib_maps[lib] for lib in sys_libs if lib != 'libssl']
|
|
|
|
|
%>
|
|
|
|
|
|
|
|
|
|
comma := ,
|
|
|
|
@ -317,27 +286,6 @@ |
|
|
|
|
$(error Invalid CONFIG value '$(CONFIG)')
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
ifeq ($(SYSTEM),Linux)
|
|
|
|
|
TMPOUT = /dev/null
|
|
|
|
|
else
|
|
|
|
|
TMPOUT = `mktemp /tmp/test-out-XXXXXX`
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
HAS_WORKING_NO_CXX14_COMPAT = $(shell $(CHECK_NO_CXX14_COMPAT_WORKS_CMD) 2> /dev/null && echo true || echo false)
|
|
|
|
|
ifeq ($(HAS_WORKING_NO_CXX14_COMPAT),true)
|
|
|
|
|
W_NO_CXX14_COMPAT=-Wno-c++14-compat
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
%for warning in CHECK_WARNINGS:
|
|
|
|
|
${warning_var('CHECK_%s_WORKS_CMD', warning)} = $(CC) -std=c99 -Werror -W${warning} -o $(TMPOUT) -c test/build/${warning}.c
|
|
|
|
|
${warning_var('HAS_WORKING_%s', warning)} = $(shell $(${warning_var('CHECK_%s_WORKS_CMD', warning)}) 2> /dev/null && echo true || echo false)
|
|
|
|
|
ifeq ($(${warning_var('HAS_WORKING_%s', warning)}),true)
|
|
|
|
|
${warning_var('W_%s', warning)}=-W${warning}
|
|
|
|
|
${warning_var('NO_W_%s', warning)}=-W${neg_warning(warning)}
|
|
|
|
|
endif
|
|
|
|
|
%endfor
|
|
|
|
|
|
|
|
|
|
# The HOST compiler settings are used to compile the protoc plugins.
|
|
|
|
|
# In most cases, you won't have to change anything, but if you are
|
|
|
|
|
# cross-compiling, you can override these variables from GNU make's
|
|
|
|
@ -348,7 +296,7 @@ |
|
|
|
|
HOST_LD ?= $(LD)
|
|
|
|
|
HOST_LDXX ?= $(LDXX)
|
|
|
|
|
|
|
|
|
|
CFLAGS += -std=c11 ${' '.join(warning_var('$(W_%s)', warning) for warning in PREFERRED_WARNINGS)}
|
|
|
|
|
CFLAGS += -std=c11
|
|
|
|
|
CXXFLAGS += -std=c++14
|
|
|
|
|
ifeq ($(SYSTEM),Darwin)
|
|
|
|
|
CXXFLAGS += -stdlib=libc++
|
|
|
|
@ -519,36 +467,6 @@ |
|
|
|
|
LIBS += z
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
# Setup c-ares dependency
|
|
|
|
|
|
|
|
|
|
ifeq ($(wildcard third_party/cares/cares/include/ares.h),)
|
|
|
|
|
HAS_EMBEDDED_CARES = false
|
|
|
|
|
else
|
|
|
|
|
HAS_EMBEDDED_CARES = true
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
ifeq ($(HAS_EMBEDDED_CARES),true)
|
|
|
|
|
EMBED_CARES ?= true
|
|
|
|
|
else
|
|
|
|
|
# only building with c-ares from submodule is supported
|
|
|
|
|
DEP_MISSING += cares
|
|
|
|
|
EMBED_CARES ?= broken
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
ifeq ($(EMBED_CARES),true)
|
|
|
|
|
CPPFLAGS := -Ithird_party/cares/cares/include -Ithird_party/cares -Ithird_party/cares/cares $(CPPFLAGS)
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
# Setup address_sorting dependency
|
|
|
|
|
|
|
|
|
|
# TODO(jtattermusch): should the include be added elsewhere?
|
|
|
|
|
CPPFLAGS := -Ithird_party/address_sorting/include $(CPPFLAGS)
|
|
|
|
|
|
|
|
|
|
# Setup abseil dependency
|
|
|
|
|
|
|
|
|
|
GRPC_ABSEIL_DEP = $(LIBDIR)/$(CONFIG)/libgrpc_abseil.a
|
|
|
|
|
GRPC_ABSEIL_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libgrpc_abseil.a
|
|
|
|
|
|
|
|
|
|
# Setup boringssl dependency
|
|
|
|
|
|
|
|
|
|
ifeq ($(wildcard third_party/boringssl-with-bazel/src/include/openssl/ssl.h),)
|
|
|
|
@ -576,22 +494,15 @@ |
|
|
|
|
LIBS_SECURE = $(OPENSSL_LIBS)
|
|
|
|
|
endif # DISABLE_ALPN
|
|
|
|
|
endif # EMBED_OPENSSL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE))
|
|
|
|
|
|
|
|
|
|
ifeq ($(MAKECMDGOALS),clean)
|
|
|
|
|
NO_DEPS = true
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
.SECONDARY = %.pb.h %.pb.cc
|
|
|
|
|
|
|
|
|
|
ifeq ($(DEP_MISSING),)
|
|
|
|
|
all: static shared\
|
|
|
|
|
% for tgt in filtered_targets:
|
|
|
|
|
% if tgt.build == 'all':
|
|
|
|
|
$(BINDIR)/$(CONFIG)/${tgt.name}\
|
|
|
|
|
% endif
|
|
|
|
|
% endfor
|
|
|
|
|
all: static shared
|
|
|
|
|
|
|
|
|
|
dep_error:
|
|
|
|
|
@echo "You shouldn't see this message - all of your dependencies are correct."
|
|
|
|
@ -665,10 +576,6 @@ |
|
|
|
|
stop:
|
|
|
|
|
@false
|
|
|
|
|
|
|
|
|
|
% for tgt in filtered_targets:
|
|
|
|
|
${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
|
|
|
|
|
% endfor
|
|
|
|
|
|
|
|
|
|
run_dep_checks:
|
|
|
|
|
@echo "run_dep_checks target has been deprecated."
|
|
|
|
|
|
|
|
|
@ -839,11 +746,6 @@ |
|
|
|
|
$(Q) mkdir -p `dirname $@`
|
|
|
|
|
$(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
|
|
|
|
|
|
|
|
|
|
$(OBJDIR)/$(CONFIG)/test/core/%.o : test/core/%.cc
|
|
|
|
|
$(E) "[CXX] Compiling $<"
|
|
|
|
|
$(Q) mkdir -p `dirname $@`
|
|
|
|
|
$(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
|
|
|
|
|
|
|
|
|
|
$(OBJDIR)/$(CONFIG)/%.o : %.cc
|
|
|
|
|
$(E) "[CXX] Compiling $<"
|
|
|
|
|
$(Q) mkdir -p `dirname $@`
|
|
|
|
@ -877,41 +779,13 @@ |
|
|
|
|
% endif
|
|
|
|
|
% endfor
|
|
|
|
|
|
|
|
|
|
# Add private ABSEIL target which contains all sources used by all baselib libraries.
|
|
|
|
|
<%
|
|
|
|
|
# Collect all abseil source and header files used by gpr, grpc, so on.
|
|
|
|
|
used_abseil_rules = set()
|
|
|
|
|
for lib in libs:
|
|
|
|
|
if lib.get("baselib"):
|
|
|
|
|
for dep in lib.transitive_deps:
|
|
|
|
|
if is_absl_lib(dep):
|
|
|
|
|
used_abseil_rules.add(dep)
|
|
|
|
|
used_abseil_srcs = []
|
|
|
|
|
used_abseil_hdrs = []
|
|
|
|
|
for lib in libs:
|
|
|
|
|
if lib.name in used_abseil_rules:
|
|
|
|
|
used_abseil_srcs.extend(lib.get("src", []))
|
|
|
|
|
used_abseil_hdrs.extend(lib.get("hdr", []))
|
|
|
|
|
# Create `grpc_abseil` rule with collected files.
|
|
|
|
|
lib_type = type(libs[0])
|
|
|
|
|
grpc_abseil_lib = lib_type({
|
|
|
|
|
"name": "grpc_abseil",
|
|
|
|
|
"build": "private",
|
|
|
|
|
"language": "c",
|
|
|
|
|
"defaults": "abseil",
|
|
|
|
|
"src": sorted(used_abseil_srcs),
|
|
|
|
|
"hdr": sorted(used_abseil_hdrs),
|
|
|
|
|
})
|
|
|
|
|
%>
|
|
|
|
|
${makelib(grpc_abseil_lib)}
|
|
|
|
|
|
|
|
|
|
<%def name="makelib(lib)">
|
|
|
|
|
# start of build recipe for library "${lib.name}" (generated by makelib(lib) template function)
|
|
|
|
|
# deps: ${collapse_absl_deps(lib.get('deps', []))}
|
|
|
|
|
# transitive_deps: ${collapse_absl_deps(lib.get('transitive_deps', []))}
|
|
|
|
|
# deps: ${lib.get('deps', [])}
|
|
|
|
|
# transitive_deps: ${lib.get('transitive_deps', [])}
|
|
|
|
|
LIB${lib.name.upper()}_SRC = \\
|
|
|
|
|
|
|
|
|
|
% for src in lib.src:
|
|
|
|
|
% for src in sorted(lib.src):
|
|
|
|
|
${src} \\
|
|
|
|
|
|
|
|
|
|
% endfor
|
|
|
|
@ -924,7 +798,7 @@ |
|
|
|
|
PUBLIC_HEADERS_C += \\
|
|
|
|
|
|
|
|
|
|
% endif
|
|
|
|
|
% for hdr in lib.public_headers:
|
|
|
|
|
% for hdr in sorted(lib.public_headers):
|
|
|
|
|
${hdr} \\
|
|
|
|
|
|
|
|
|
|
% endfor
|
|
|
|
@ -972,13 +846,6 @@ |
|
|
|
|
ldflags = '$(LDFLAGS)'
|
|
|
|
|
if lib.get('LDFLAGS', None):
|
|
|
|
|
ldflags += ' ' + lib['LDFLAGS']
|
|
|
|
|
|
|
|
|
|
if 'libssl' in lib.get('transitive_deps', []):
|
|
|
|
|
for src in lib.src:
|
|
|
|
|
sources_that_need_openssl.add(src)
|
|
|
|
|
else:
|
|
|
|
|
for src in lib.src:
|
|
|
|
|
sources_that_don_t_need_openssl.add(src)
|
|
|
|
|
%>
|
|
|
|
|
# shared library for "${lib.name}"
|
|
|
|
|
% if lib.build == "all":
|
|
|
|
@ -1019,18 +886,6 @@ |
|
|
|
|
# end of build recipe for library "${lib.name}"
|
|
|
|
|
</%def>
|
|
|
|
|
|
|
|
|
|
# TODO(jtattermusch): is there a way to get around this hack?
|
|
|
|
|
ifneq ($(OPENSSL_DEP),)
|
|
|
|
|
# This is to ensure the embedded OpenSSL is built beforehand, properly
|
|
|
|
|
# installing headers to their final destination on the drive. We need this
|
|
|
|
|
# otherwise parallel compilation will fail if a source is compiled first.
|
|
|
|
|
% for src in sorted(sources_that_need_openssl):
|
|
|
|
|
% if src not in sources_that_don_t_need_openssl:
|
|
|
|
|
${src}: $(OPENSSL_DEP)
|
|
|
|
|
% endif
|
|
|
|
|
% endfor
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
.PHONY: all strip tools \
|
|
|
|
|
dep_error openssl_dep_error openssl_dep_message git_update stop \
|
|
|
|
|
buildtests buildtests_c buildtests_cxx \
|
|
|
|
|