Skip to content
Snippets Groups Projects
Commit 69ac39f4 authored by nnoble's avatar nnoble Committed by Nicolas Noble
Browse files

Makefile will now build zlib and/or OpenSSL if needed.

-) Detecting system and embedded presence of zlib and OpenSSL with ALPN.
-) Automatically disabling secure targets if no OpenSSL present
--> make all won't work if no OpenSSL is present, forcing the users to select the nonsecure Makefile targets explicitely.
-) Removing build instructions for OpenSSL - this isn't really necessary anymore.
-) Adding more blurb about OpenSSL and the new Makefile features.
	Change on 2014/12/12 by nnoble <nnoble@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=82020890
parent befd2650
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,9 @@ following command: ...@@ -8,6 +8,9 @@ following command:
$ git submodule update --init $ git submodule update --init
Note that the Makefile makes it much easier for you to compile from sources
if you were to clone recursively our git repository.
grpc core currently depends on zlib and OpenSSL 1.0.2beta3, and also requires grpc core currently depends on zlib and OpenSSL 1.0.2beta3, and also requires
libevent2 for the Linux port. libevent2 for the Linux port.
...@@ -22,30 +25,44 @@ http://http2.github.io/http2-spec/ section 3.3). Our HTTP2 implementation ...@@ -22,30 +25,44 @@ http://http2.github.io/http2-spec/ section 3.3). Our HTTP2 implementation
relies on OpenSSL's implementation. OpenSSL 1.0.2beta3 is the first version relies on OpenSSL's implementation. OpenSSL 1.0.2beta3 is the first version
of OpenSSL that has ALPN support, and this explains our dependency on it. of OpenSSL that has ALPN support, and this explains our dependency on it.
Note that the Makefile supports compiling only the unsecure elements of grpc,
and if you do not have OpenSSL and do not want it, you can still proceed
with installing only the elements you require. However, it is recommended
to encrypt your network traffic, therefore we urge you to not use the unsecure
version of grpc if possible.
Compiling Compiling
========= =========
Currently, you will need to manually install OpenSSL-1.0.2beta3 prior If you have all the dependencies in the third_party subfolder, you should
attempting to compile grpc. To avoid clobbering any system OpenSSL, it is simply be able to go ahead and run "make" to compile grpc. The other targets
preferable to install it in a separate directory. Running binaries however that you might find interesting are "buildtests" and "test".
will require the appropriate LD_LIBRARY_PATH variable set up, as shown later.
To compile OpenSSL 1.0.2beta3: If you didn't clone from git, and thus are unable to get the required
dependencies, you can manually download and unpack the necessary packages,
and let the Makefile build them itself.
$ cd third_party/openssl You may also install the dependencies yourself, from the sources, or from
$ ./config --prefix=/usr/local/openssl-alpn --shared your distribution's package manager.
$ make
$ sudo make install The development packages needed for grpc are libevent2 under Linux, and zlib.
$ cd ../../ The development packages needed for grpc++'s tests are gtests, and gflags.
To the best of our knowledge, no distribution has an OpenSSL package that
supports ALPN yet, so you would still have to depend on installing from source
for that particular dependency.
The recommended version of OpenSSL that provides ALPN support is available
at this URL:
After that step, you can compile grpc: https://www.openssl.org/source/openssl-1.0.2-beta3.tar.gz
$ ssl=/usr/local/openssl-alpn If you want to let the Makefile build them automatically for you, please
$ CPPFLAGS=-I$ssl/include LDFLAGS=-L$ssl/lib make extract them in the third_party folder. You will need to rename the extracted
folder the following way:
This will compile both grpc and grpc++. openssl-1.0.2-beta3 --> openssl
Testing Testing
...@@ -54,8 +71,8 @@ Testing ...@@ -54,8 +71,8 @@ Testing
At the moment, C++ tests aren't fully available yet. If you want to run tests At the moment, C++ tests aren't fully available yet. If you want to run tests
on the C core of grpc, you can do the following: on the C core of grpc, you can do the following:
$ CPPFLAGS=-I$ssl/include LDFLAGS=-L$ssl/lib make buildtests_c $ make buildtests_c
$ LD_LIBRARY_PATH=$ssl/lib make test_c $ make test_c
Installing Installing
......
This diff is collapsed.
...@@ -289,7 +289,7 @@ ...@@ -289,7 +289,7 @@
"test/core/end2end/cq_verifier.c", "test/core/end2end/cq_verifier.c",
"test/core/endpoint/endpoint_tests.c", "test/core/endpoint/endpoint_tests.c",
"test/core/transport/transport_end2end_tests.c", "test/core/transport/transport_end2end_tests.c",
"test/core/statistics/log_tests.c" "test/core/statistics/census_log_tests.c"
] ]
}, },
{ {
...@@ -372,6 +372,7 @@ ...@@ -372,6 +372,7 @@
"name": "cpp_plugin", "name": "cpp_plugin",
"build": "protoc", "build": "protoc",
"c++": true, "c++": true,
"secure": false,
"src": [ "src": [
"src/compiler/cpp_plugin.cpp", "src/compiler/cpp_plugin.cpp",
"src/compiler/cpp_generator.cpp" "src/compiler/cpp_generator.cpp"
...@@ -386,6 +387,7 @@ ...@@ -386,6 +387,7 @@
"name": "ruby_plugin", "name": "ruby_plugin",
"build": "protoc", "build": "protoc",
"c++": true, "c++": true,
"secure": false,
"src": [ "src": [
"src/compiler/ruby_plugin.cpp", "src/compiler/ruby_plugin.cpp",
"src/compiler/ruby_generator.cpp" "src/compiler/ruby_generator.cpp"
......
...@@ -131,8 +131,84 @@ HOST_CXXFLAGS = $(CXXFLAGS) ...@@ -131,8 +131,84 @@ HOST_CXXFLAGS = $(CXXFLAGS)
HOST_LDFLAGS = $(LDFLAGS) HOST_LDFLAGS = $(LDFLAGS)
HOST_LDLIBS = $(LDLIBS) 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_)
ifeq ($(SYSTEM),)
SYSTEM = $(HOST_SYSTEM)
endif
ifeq ($(wildcard .git),)
IS_GIT_FOLDER = false
else
IS_GIT_FOLDER = true
endif
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)
ifeq ($(wildcard third_party/libevent/include/event2/event.h),)
HAS_EMBEDDED_EVENT2 = false
else
HAS_EMBEDDED_EVENT2 = true
endif
ifeq ($(wildcard third_party/openssl/ssl/ssl.h),)
HAS_EMBEDDED_OPENSSL_ALPN = false
else
HAS_EMBEDDED_OPENSSL_ALPN = true
endif
ifeq ($(wildcard third_party/zlib/zlib.h),)
HAS_EMBEDDED_ZLIB = false
else
HAS_EMBEDDED_ZLIB = true
endif
ifneq ($(SYSTEM),MINGW32)
ifeq ($(HAS_SYSTEM_EVENT2),false)
DEP_MISSING += libevent
endif
endif
ifeq ($(HAS_SYSTEM_ZLIB),false)
ifeq ($(HAS_EMBEDDED_ZLIB),true)
ZLIB_DEP = third_party/zlib/libz.a
CPPFLAGS += -Ithird_party/zlib
LDFLAGS += -Lthird_party/zlib
else
DEP_MISSING += zlib
endif
endif
ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false)
ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true)
OPENSSL_DEP = third_party/openssl/libssl.a
CPPFLAGS += -Ithird_party/openssl/include
LDFLAGS += -Lthird_party/openssl
else
NO_SECURE = true
endif
endif
ifneq ($(DEP_MISSING),)
NO_DEPS = true
endif
ifneq ($(MAKECMDGOALS),clean)
NO_DEPS = true
endif
.SECONDARY = %.pb.h %.pb.cc .SECONDARY = %.pb.h %.pb.cc
ifeq ($(DEP_MISSING),)
all: static shared\ all: static shared\
% for tgt in targets: % for tgt in targets:
% if tgt.build == 'all': % if tgt.build == 'all':
...@@ -140,6 +216,70 @@ all: static shared\ ...@@ -140,6 +216,70 @@ all: static shared\
% endif % endif
% endfor % endfor
dep_error:
@echo "You shouldn't see this message - all of your dependencies are correct."
else
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
endif
git_update:
ifeq ($(IS_GIT_FOLDER),true)
@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
endif
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: static_c static_cxx
static_c: dep_c\ static_c: dep_c\
...@@ -196,7 +336,7 @@ privatelibs_cxx: dep_cxx\ ...@@ -196,7 +336,7 @@ privatelibs_cxx: dep_cxx\
buildtests: buildtests_c buildtests_cxx buildtests: buildtests_c buildtests_cxx
buildtests_c: privatelibs_c\ buildtests_c: bin_dep_c privatelibs_c\
% for tgt in targets: % for tgt in targets:
% if tgt.build == 'test' and not tgt.get('c++', False): % if tgt.build == 'test' and not tgt.get('c++', False):
bins/${tgt.name}\ bins/${tgt.name}\
...@@ -204,7 +344,7 @@ buildtests_c: privatelibs_c\ ...@@ -204,7 +344,7 @@ buildtests_c: privatelibs_c\
% endfor % endfor
buildtests_cxx: privatelibs_cxx\ buildtests_cxx: bin_dep_cxx privatelibs_cxx\
% for tgt in targets: % for tgt in targets:
% if tgt.build == 'test' and tgt.get('c++', False): % if tgt.build == 'test' and tgt.get('c++', False):
bins/${tgt.name}\ bins/${tgt.name}\
...@@ -350,6 +490,9 @@ dep_c:\ ...@@ -350,6 +490,9 @@ dep_c:\
deps_lib${lib.name}\ deps_lib${lib.name}\
% endif % endif
% endfor % endfor
bins_dep_c:\
% for tgt in targets: % for tgt in targets:
% if not tgt.get('c++', False): % if not tgt.get('c++', False):
deps_${tgt.name}\ deps_${tgt.name}\
...@@ -363,6 +506,9 @@ dep_cxx:\ ...@@ -363,6 +506,9 @@ dep_cxx:\
deps_lib${lib.name}\ deps_lib${lib.name}\
% endif % endif
% endfor % endfor
bins_dep_cxx:\
% for tgt in targets: % for tgt in targets:
% if tgt.get('c++', False): % if tgt.get('c++', False):
deps_${tgt.name}\ deps_${tgt.name}\
...@@ -446,7 +592,7 @@ ${makelib(lib)} ...@@ -446,7 +592,7 @@ ${makelib(lib)}
% endfor % endfor
# All of the test targets # All of the test targets, and protoc plugins
% for tgt in targets: % for tgt in targets:
${maketarget(tgt)} ${maketarget(tgt)}
...@@ -477,6 +623,16 @@ PUBLIC_HEADERS_C += \\ ...@@ -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()}_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)))) 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)
ifeq ($(NO_SECURE),true)
libs/lib${lib.name}.a: openssl_dep_error
else
% endif
libs/lib${lib.name}.a: $(LIB${lib.name.upper()}_OBJS) libs/lib${lib.name}.a: $(LIB${lib.name.upper()}_OBJS)
$(E) "[AR] Creating $@" $(E) "[AR] Creating $@"
$(Q) mkdir -p `dirname $@` $(Q) mkdir -p `dirname $@`
...@@ -492,17 +648,27 @@ libs/lib${lib.name}.so.$(VERSION): $(LIB${lib.name.upper()}_OBJS) ...@@ -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} \ $(Q) $(LD) $(LDFLAGS) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} \
% endif % endif
-o libs/lib${lib.name}.so.$(VERSION) $(LIB${lib.name.upper()}_OBJS) $(LDLIBS)\ -o libs/lib${lib.name}.so.$(VERSION) $(LIB${lib.name.upper()}_OBJS) $(LDLIBS)\
% if lib.secure: % if lib.get('secure', True):
$(LDLIBS_SECURE)\ $(LDLIBS_SECURE)\
% endif % endif
% endif % endif
% if lib.get('secure', True):
endif
% endif
deps_lib${lib.name}: $(LIB${lib.name.upper()}_DEPS) deps_lib${lib.name}: $(LIB${lib.name.upper()}_DEPS)
ifneq ($(MAKECMDGOALS),clean) % if lib.get('secure', True):
ifneq ($(NO_SECURE),true)
% endif
ifneq ($(NO_DEPS),true)
-include $(LIB${lib.name.upper()}_DEPS) -include $(LIB${lib.name.upper()}_DEPS)
endif endif
% if lib.get('secure', True):
endif
% endif
clean_lib${lib.name}: clean_lib${lib.name}:
$(E) "[CLEAN] Cleaning lib${lib.name} files" $(E) "[CLEAN] Cleaning lib${lib.name} files"
...@@ -523,6 +689,14 @@ ${tgt.name.upper()}_SRC = \\ ...@@ -523,6 +689,14 @@ ${tgt.name.upper()}_SRC = \\
${tgt.name.upper()}_OBJS = $(addprefix objs/, $(addsuffix .o, $(basename $(${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)))) ${tgt.name.upper()}_DEPS = $(addprefix deps/, $(addsuffix .dep, $(basename $(${tgt.name.upper()}_SRC))))
% if tgt.get('secure', True):
ifeq ($(NO_SECURE),true)
bins/${tgt.name}: openssl_dep_error
else
% endif
bins/${tgt.name}: $(${tgt.name.upper()}_OBJS)\ bins/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
% for dep in tgt.deps: % for dep in tgt.deps:
libs/lib${dep}.a\ libs/lib${dep}.a\
...@@ -568,12 +742,22 @@ bins/${tgt.name}: $(${tgt.name.upper()}_OBJS)\ ...@@ -568,12 +742,22 @@ bins/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
$(LDLIBS_SECURE)\ $(LDLIBS_SECURE)\
% endif % endif
-o bins/${tgt.name} -o bins/${tgt.name}
% if tgt.get('secure', True):
endif
% endif
deps_${tgt.name}: $(${tgt.name.upper()}_DEPS) deps_${tgt.name}: $(${tgt.name.upper()}_DEPS)
ifneq ($(MAKECMDGOALS),clean) % if tgt.get('secure', True):
ifneq ($(NO_SECURE),true)
% endif
ifneq ($(NO_DEPS),true)
-include $(${tgt.name.upper()}_DEPS) -include $(${tgt.name.upper()}_DEPS)
endif endif
% if tgt.get('secure', True):
endif
% endif
clean_${tgt.name}: clean_${tgt.name}:
$(E) "[CLEAN] Cleaning ${tgt.name} files" $(E) "[CLEAN] Cleaning ${tgt.name} files"
...@@ -583,6 +767,7 @@ clean_${tgt.name}: ...@@ -583,6 +767,7 @@ clean_${tgt.name}:
</%def> </%def>
.PHONY: all strip tools \ .PHONY: all strip tools \
dep_error openssl_dep_error openssl_dep_message git_update stop \
buildtests buildtests_c buildtests_cxx \ buildtests buildtests_c buildtests_cxx \
test test_c test_cxx \ test test_c test_cxx \
install install_c install_cxx \ install install_c install_cxx \
......
/* This is only a compilation test, to see if we have libevent installed. */
#include <event2/event.h>
int main() {
event_base_new();
return 0;
}
/* This is just a compilation test, to see if we have a version of OpenSSL with
ALPN support installed. */
#include <stdlib.h>
#include <openssl/ssl.h>
int main() {
SSL_get0_alpn_selected(NULL, NULL, NULL);
return 0;
}
/* This is just a compilation test, to see if we have zlib installed. */
#include <stdlib.h>
#include <zlib.h>
int main() {
deflateInit(Z_NULL, Z_DEFAULT_COMPRESSION);
return 0;
}
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
</ClCompile> </ClCompile>
<ClCompile Include="..\..\test\core\transport\transport_end2end_tests.c"> <ClCompile Include="..\..\test\core\transport\transport_end2end_tests.c">
</ClCompile> </ClCompile>
<ClCompile Include="..\..\test\core\statistics\log_tests.c"> <ClCompile Include="..\..\test\core\statistics\census_log_tests.c">
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment