@ -131,8 +131,84 @@ HOST_CXXFLAGS = $(CXXFLAGS)
HOST_LDFLAGS = $( LDFLAGS)
HOST_LDLIBS = $( LDLIBS)
# These are automatically computed variables.
# There shouldn't be any need to change anything from now on.
HOST_SYSTEM = $( shell uname | cut -f 1 -d_)
i f e q ( $( SYSTEM ) , )
SYSTEM = $( HOST_SYSTEM)
e n d i f
i f e q ( $( wildcard .git ) , )
IS_GIT_FOLDER = false
e l s e
IS_GIT_FOLDER = true
e n d i f
EVENT2_CHECK_CMD = $( CC) $( CFLAGS) $( CPPFLAGS) -o /dev/null test/build/event2.c -levent $( LDFLAGS)
OPENSSL_ALPN_CHECK_CMD = $( CC) $( CFLAGS) $( CPPFLAGS) -o /dev/null test/build/openssl-alpn.c -levent $( LDFLAGS) $( LDLIBS_SECURE)
ZLIB_CHECK_CMD = $( CC) $( CFLAGS) $( CPPFLAGS) -o /dev/null test/build/event2.c -levent $( LDFLAGS)
HAS_SYSTEM_EVENT2 = $( shell $( EVENT2_CHECK_CMD) >& /dev/null && echo true || echo false )
HAS_SYSTEM_OPENSSL_ALPN = $( shell $( OPENSSL_ALPN_CHECK_CMD) >& /dev/null && echo true || echo false )
HAS_SYSTEM_ZLIB = $( shell $( ZLIB_CHECK_CMD) >& /dev/null && echo true || echo false )
i f e q ( $( wildcard third_party /libevent /include /event 2/event .h ) , )
HAS_EMBEDDED_EVENT2 = false
e l s e
HAS_EMBEDDED_EVENT2 = true
e n d i f
i f e q ( $( wildcard third_party /openssl /ssl /ssl .h ) , )
HAS_EMBEDDED_OPENSSL_ALPN = false
e l s e
HAS_EMBEDDED_OPENSSL_ALPN = true
e n d i f
i f e q ( $( wildcard third_party /zlib /zlib .h ) , )
HAS_EMBEDDED_ZLIB = false
e l s e
HAS_EMBEDDED_ZLIB = true
e n d i f
i f n e q ( $( SYSTEM ) , M I N G W 3 2 )
i f e q ( $( HAS_SYSTEM_EVENT 2) , f a l s e )
DEP_MISSING += libevent
e n d i f
e n d i f
i f e q ( $( HAS_SYSTEM_ZLIB ) , f a l s e )
i f e q ( $( HAS_EMBEDDED_ZLIB ) , t r u e )
ZLIB_DEP = third_party/zlib/libz.a
CPPFLAGS += -Ithird_party/zlib
LDFLAGS += -Lthird_party/zlib
e l s e
DEP_MISSING += zlib
e n d i f
e n d i f
i f e q ( $( HAS_SYSTEM_OPENSSL_ALPN ) , f a l s e )
i f e q ( $( HAS_EMBEDDED_OPENSSL_ALPN ) , t r u e )
OPENSSL_DEP = third_party/openssl/libssl.a
CPPFLAGS += -Ithird_party/openssl/include
LDFLAGS += -Lthird_party/openssl
e l s e
NO_SECURE = true
e n d i f
e n d i f
i f n e q ( $( DEP_MISSING ) , )
NO_DEPS = true
e n d i f
i f n e q ( $( MAKECMDGOALS ) , c l e a n )
NO_DEPS = true
e n d i f
.SECONDARY = %.pb.h %.pb.cc
i f e q ( $( DEP_MISSING ) , )
all : static shared \
% for tgt in targets :
% if tgt.build == 'all' :
@ -140,6 +216,70 @@ all: static shared\
% e n d i f
% e n d f o r
dep_error :
@echo "You shouldn't see this message - all of your dependencies are correct."
e l s e
all : dep_error git_update stop
dep_error :
@echo
@echo "DEPENDENCY ERROR"
@echo
@echo "You are missing system dependencies that are essential to build grpc,"
@echo "and the third_party directory doesn't have them:"
@echo
@echo " $( DEP_MISSING) "
@echo
@echo "Installing the development packages for your system will solve"
@echo "this issue. Please consult INSTALL to get more information."
@echo
@echo "If you need information about why these tests failed, run:"
@echo
@echo " make run_dep_checks"
@echo
e n d i f
git_update :
i f e q ( $( IS_GIT_FOLDER ) , t r u e )
@echo "Additionally, since you are in a git clone, you can download the"
@echo "missing dependencies in third_party by running the following command:"
@echo
@echo " git submodule --init update"
@echo
e n d i f
openssl_dep_error : openssl_dep_message git_update stop
openssl_dep_message :
@echo
@echo "DEPENDENCY ERROR"
@echo
@echo "The target you are trying to run requires OpenSSL with ALPN support."
@echo "Your system doesn't have it, and neither does the third_party directory."
@echo
@echo "Please consult INSTALL to get more information."
@echo
@echo "If you need information about why these tests failed, run:"
@echo
@echo " make run_dep_checks"
@echo
stop :
@false
run_dep_checks :
$( EVENT2_CHECK_CMD) || true
$( OPENSSL_ALPN_CHECK_CMD) || true
$( ZLIB_CHECK_CMD) || true
third_party/zlib/libz.a :
( cd third_party/zlib ; CFLAGS = "-fPIC -fvisibility=hidden" ./configure --static)
$( MAKE) -C third_party/zlib
third_party/openssl/libssl.a :
( cd third_party/openssl ; CC = " $( CC) -fPIC -fvisibility=hidden " ./config)
$( MAKE) -C third_party/openssl build_crypto build_ssl
static : static_c static_cxx
static_c : dep_c \
@ -196,7 +336,7 @@ privatelibs_cxx: dep_cxx\
buildtests : buildtests_c buildtests_cxx
buildtests_c : privatelibs_c \
buildtests_c : bin_dep_c privatelibs_c \
% for tgt in targets :
% if tgt.build == 'test' and not tgt.get('c++', False) :
bins/${ tgt .name } \
@ -204,7 +344,7 @@ buildtests_c: privatelibs_c\
% e n d f o r
buildtests_cxx : privatelibs_cxx \
buildtests_cxx : bin_dep_cxx privatelibs_cxx \
% for tgt in targets :
% if tgt.build == 'test' and tgt.get('c++', False) :
bins/${ tgt .name } \
@ -350,6 +490,9 @@ dep_c:\
deps_lib${ lib .name } \
% e n d i f
% e n d f o r
bins_dep_c : \
% for tgt in targets :
% if not tgt.get('c++', False) :
deps_${ tgt .name } \
@ -363,6 +506,9 @@ dep_cxx:\
deps_lib${ lib .name } \
% e n d i f
% e n d f o r
bins_dep_cxx : \
% for tgt in targets :
% if tgt.get('c++', False) :
deps_${ tgt .name } \
@ -446,7 +592,7 @@ ${makelib(lib)}
% e n d f o r
# All of the test targets
# All of the test targets, and protoc plugins
% for tgt in targets :
$ { m a k e t a r g e t ( t g t ) }
@ -477,6 +623,16 @@ PUBLIC_HEADERS_C += \\
LIB${lib.name.upper()}_OBJS = $( addprefix objs/, $( addsuffix .o, $( basename $( LIB${ lib .name.upper() } _SRC) ) ) )
LIB${lib.name.upper()}_DEPS = $( addprefix deps/, $( addsuffix .dep, $( basename $( LIB${ lib .name.upper() } _SRC) ) ) )
% if lib.get('secure', True) :
LIB${lib.name.upper()}_OBJS += $( OPENSSL_DEP)
i f e q ( $( NO_SECURE ) , t r u e )
libs/lib${lib.name}.a : openssl_dep_error
e l s e
% e n d i f
libs/lib${lib.name}.a : $( LIB $ {lib .name .upper ( ) }_OBJS )
$( E) " [AR] Creating $@ "
$( Q) mkdir -p ` dirname $@ `
@ -492,17 +648,27 @@ libs/lib${lib.name}.so.$(VERSION): $(LIB${lib.name.upper()}_OBJS)
$( Q) $( LD) $( LDFLAGS) -shared -Wl,-soname,lib${ lib .name } .so.${ settings .version.major } \
% e n d i f
- o l i b s / l i b $ { l i b . n a m e } . s o . $( VERSION ) $( LIB $ {lib .name .upper ( ) }_OBJS ) $( LDLIBS ) \
% if lib.secure :
% if lib.get(' secure', True) :
$( LDLIBS_SECURE) \
% e n d i f
% e n d i f
% if lib.get('secure', True) :
e n d i f
% e n d i f
deps_lib${lib.name} : $( LIB $ {lib .name .upper ( ) }_DEPS )
i f n e q ( $( MAKECMDGOALS ) , c l e a n )
% if lib.get('secure', True) :
i f n e q ( $( NO_SECURE ) , t r u e )
% e n d i f
i f n e q ( $( NO_DEPS ) , t r u e )
- i n c l u d e $( LIB $ {lib .name .upper ( ) }_DEPS )
e n d i f
% if lib.get('secure', True) :
e n d i f
% e n d i f
clean_lib${lib.name} :
$( E) " [CLEAN] Cleaning lib ${ lib .name } files "
@ -523,6 +689,14 @@ ${tgt.name.upper()}_SRC = \\
${tgt.name.upper()}_OBJS = $( addprefix objs/, $( addsuffix .o, $( basename $( ${ tgt .name.upper() } _SRC) ) ) )
${tgt.name.upper()}_DEPS = $( addprefix deps/, $( addsuffix .dep, $( basename $( ${ tgt .name.upper() } _SRC) ) ) )
% if tgt.get('secure', True) :
i f e q ( $( NO_SECURE ) , t r u e )
bins/${tgt.name} : openssl_dep_error
e l s e
% e n d i f
bins/${tgt.name} : $( $ {tgt .name .upper ( ) }_OBJS ) \
% for dep in tgt.deps :
libs/lib${ dep } .a\
@ -568,12 +742,22 @@ bins/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
$( LDLIBS_SECURE) \
% e n d i f
-o bins/${ tgt .name }
% if tgt.get('secure', True) :
e n d i f
% e n d i f
deps_${tgt.name} : $( $ {tgt .name .upper ( ) }_DEPS )
i f n e q ( $( MAKECMDGOALS ) , c l e a n )
% if tgt.get('secure', True) :
i f n e q ( $( NO_SECURE ) , t r u e )
% e n d i f
i f n e q ( $( NO_DEPS ) , t r u e )
- i n c l u d e $( $ {tgt .name .upper ( ) }_DEPS )
e n d i f
% if tgt.get('secure', True) :
e n d i f
% e n d i f
clean_${tgt.name} :
$( E) " [CLEAN] Cleaning ${ tgt .name } files "
@ -583,6 +767,7 @@ clean_${tgt.name}:
< / % d e f >
.PHONY : all strip tools \
d e p _ e r r o r o p e n s s l _ d e p _ e r r o r o p e n s s l _ d e p _ m e s s a g e g i t _ u p d a t e s t o p \
b u i l d t e s t s b u i l d t e s t s _ c b u i l d t e s t s _ c x x \
t e s t t e s t _ c t e s t _ c x x \
i n s t a l l i n s t a l l _ c i n s t a l l _ c x x \