libweave: Build with Makefile instead of GYP.

Mitigates the need for *.gyp, *.gypi, src/empty.cc, examples/build.sh,
examples/prerequisites.sh, but does not remove those files. Conditions
for clang have not been added yet.

"make" generates libweave.so
"make test" builds and runs tests
"make clean" does what you expect
"make third_party/lib/libevent.a" downloads and builds libevent
"make cleanall" runs clean, and cleans libevent and googletest

BUG: 26508278

Change-Id: I505f0b1275b6cf074a06d29c658367c257faf142
Reviewed-on: https://weave-review.googlesource.com/2167
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..0eb4e12
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,81 @@
+# Copyright 2015 The Weave Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Run make with BUILD_MODE=Release for release.
+BUILD_MODE ?= Debug
+
+DEFS_Debug := \
+	-D_DEBUG
+
+DEFS_Release := \
+	-DNDEBUG
+
+INCLUDES := \
+	-I. \
+	-Iinclude \
+	-Ithird_party/chromium \
+	-Ithird_party/include \
+	-Ithird_party/libuweave \
+	-Ithird_party/modp_b64/modp_b64
+
+CFLAGS := \
+	-fno-exceptions \
+	-fPIC \
+	-fvisibility=hidden \
+	-Wall \
+	-Werror \
+	-Wextra \
+	-Wl,--exclude-libs,ALL \
+	-Wno-char-subscripts \
+	-Wno-format-nonliteral \
+	-Wno-missing-field-initializers \
+	-Wno-unused-local-typedefs \
+	-Wno-unused-parameter \
+	-Wpacked \
+	-Wpointer-arith \
+	-Wwrite-strings
+
+CFLAGS_Debug := \
+	-O0   \
+	-g3
+
+CFLAGS_Release := \
+	-Os
+
+CFLAGS_C := \
+	-std=c99
+
+CFLAGS_CC := \
+	-std=c++11
+
+include file_lists.mk third_party.mk examples.mk tests.mk
+
+###
+# libweave.so
+
+out/$(BUILD_MODE)/libweave.so : out/$(BUILD_MODE)/libweave_common.a
+	$(CXX) -shared -Wl,-soname=libweave.so -o $@ -Wl,--whole-archive $^ -Wl,--no-whole-archive -lcrypto -lexpat -lpthread -lrt
+
+###
+# src/
+
+weave_obj_files := $(WEAVE_SRC_FILES:%.cc=out/$(BUILD_MODE)/%.o)
+
+$(weave_obj_files) : out/$(BUILD_MODE)/%.o : %.cc
+	mkdir -p $(dir $@)
+	$(CXX) $(DEFS_$(BUILD_MODE)) $(INCLUDES) $(CFLAGS) $(CFLAGS_$(BUILD_MODE)) $(CFLAGS_CC) -c -o $@ $<
+
+out/$(BUILD_MODE)/libweave_common.a : $(weave_obj_files) $(third_party_chromium_base_obj_files) $(third_party_chromium_crypto_obj_files) $(third_party_modp_b64_obj_files) $(third_party_libuweave_obj_files)
+	rm -f $@
+	$(AR) crsT $@ $^
+
+all : out/$(BUILD_MODE)/libweave.so out/$(BUILD_MODE)/libweave_exports_testrunner out/$(BUILD_MODE)/libweave_testrunner all-examples
+
+clean :
+	rm -rf out
+
+cleanall : clean clean-gtest clean-libevent
+
+.PHONY : clean cleanall all
+