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/tests.mk b/tests.mk
new file mode 100644
index 0000000..64fc622
--- /dev/null
+++ b/tests.mk
@@ -0,0 +1,48 @@
+# 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.
+
+###
+# tests
+
+weave_test_obj_files := $(WEAVE_TEST_SRC_FILES:%.cc=out/$(BUILD_MODE)/%.o)
+
+# We don't need libgtest.a, but the headers files in third_party/include.
+$(weave_test_obj_files) : out/$(BUILD_MODE)/%.o : %.cc third_party/lib/libgtest.a
+	mkdir -p $(dir $@)
+	$(CXX) $(DEFS_$(BUILD_MODE)) $(INCLUDES) $(CFLAGS) $(CFLAGS_$(BUILD_MODE)) $(CFLAGS_CC) -c -o $@ $<
+
+out/$(BUILD_MODE)/libweave-test.a : $(weave_test_obj_files)
+	$(AR) crs $@ $^
+
+weave_unittest_obj_files := $(WEAVE_UNITTEST_SRC_FILES:%.cc=out/$(BUILD_MODE)/%.o)
+
+# We don't need libgtest.a, but the headers files in third_party/include.
+$(weave_unittest_obj_files) : out/$(BUILD_MODE)/%.o : %.cc third_party/lib/libgtest.a
+	mkdir -p $(dir $@)
+	$(CXX) $(DEFS_$(BUILD_MODE)) $(INCLUDES) $(CFLAGS) $(CFLAGS_$(BUILD_MODE)) $(CFLAGS_CC) -c -o $@ $<
+
+out/$(BUILD_MODE)/libweave_testrunner : $(weave_unittest_obj_files) $(third_party_chromium_crypto_unittest_obj_files) $(third_party_chromium_base_unittest_obj_files) out/$(BUILD_MODE)/libweave_common.a out/$(BUILD_MODE)/libweave-test.a
+	$(CXX) -o $@ $^ -lcrypto -lexpat -lgmock -lgtest -lpthread -lrt -Lthird_party/lib
+
+test : out/$(BUILD_MODE)/libweave_testrunner
+	$<
+
+###
+# export tests
+
+weave_exports_unittest_obj_files := $(WEAVE_EXPORTS_UNITTEST_SRC_FILES:%.cc=out/$(BUILD_MODE)/%.o)
+
+# We don't need libgtest.a, but the headers files in third_party/include.
+$(weave_exports_unittest_obj_files) : out/$(BUILD_MODE)/%.o : %.cc third_party/lib/libgtest.a
+	mkdir -p $(dir $@)
+	$(CXX) $(DEFS_$(BUILD_MODE)) $(INCLUDES) $(CFLAGS) $(CFLAGS_$(BUILD_MODE)) $(CFLAGS_CC) -c -o $@ $<
+
+out/$(BUILD_MODE)/libweave_exports_testrunner : $(weave_exports_unittest_obj_files) out/$(BUILD_MODE)/libweave.so out/$(BUILD_MODE)/libweave-test.a out/$(BUILD_MODE)/src/test/weave_testrunner.o
+	$(CXX) -o $@ $^ -lcrypto -lexpat -lgmock -lgtest -lpthread -lrt -Lthird_party/lib -Wl,-rpath=out/$(BUILD_MODE)/
+
+export-test : out/$(BUILD_MODE)/libweave_exports_testrunner
+	$<
+
+.PHONY : test export-test
+