Project import
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e52e9f9
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,27 @@
+#
+#    Copyright (c) 2017 Nest Labs, Inc.
+#    All rights reserved.
+#
+#    This document is the property of Nest. It is considered
+#    confidential and proprietary information.
+#
+#    This document may not be reproduced or transmitted in any form,
+#    in whole or in part, without the express written permission of
+#    Nest.
+#
+#    Description:
+#      This file is the make file for protobuf
+#
+
+include pre.mak
+
+ifeq ($(BUILD_FEATURE_SIMULATOR),1)
+SubMakefiles = Makefile.host
+else
+SubMakefiles = Makefile.host \
+               Makefile.target
+endif
+
+include post.mak
+
+Makefile.target: $(filter Makefile.host,$(SubMakefiles))
diff --git a/Makefile.host b/Makefile.host
new file mode 100644
index 0000000..9066563
--- /dev/null
+++ b/Makefile.host
@@ -0,0 +1,131 @@
+#
+#    Copyright (c) 2017 Nest Labs, Inc.
+#    All rights reserved.
+#
+#    This document is the property of Nest. It is considered
+#    confidential and proprietary information.
+#
+#    This document may not be reproduced or transmitted in any form,
+#    in whole or in part, without the express written permission of
+#    Nest.
+#
+#    Description:
+#    This file is the protobuf makefile for the host.  On a cross compile
+#    we need to build protoc for the host that we can auto-generate source
+#    code from the proto files.
+#
+
+ifneq ($(BUILD_FEATURE_SIMULATOR),1)
+override BuildProduct   := diamondsim
+SaveBuildMode       := $(BuildMode)
+override BuildMode  := snapshot
+endif
+
+include pre.mak
+
+PackageName		:= protobuf
+
+PackageExtension	:= tar.gz
+PackageSeparator	:= -
+
+PackagePatchArgs	:= -p1
+
+PackageArchive		:= $(PackageName).$(PackageExtension)
+PackageSourceDir	:= $(PackageName)$(PackageSeparator)$(PackageVersion)
+
+PackageBuildMakefile	= $(call GenerateBuildPaths,Makefile)
+
+PackageResultPath = $(call GenerateResultPaths,,usr)
+
+PackageBuildSrcDir = $(ProtobufSourcesPath)/$(BuildBaseDirectory)/Makefile.host/$(ConditionalBuildTuple)/src
+
+CleanPaths		+= $(PackageLicenseFile)
+
+SOURCEDIRS                      = $(PackageSourceDir)
+$(PackageSourceDir)_RULE_TARGET = $(BuildDirectory)/configure_empty
+
+ifeq ($(call IsYes,$(ForceLibStdCPP)),Y)
+CLANGCXXFLAGS = -stdlib=libstdc++
+endif
+
+all: $(PackageDefaultGoal)
+
+$(ResultDirectory)/lib:
+	$(create-directory)
+
+$(ResultDirectory)/include:
+	$(create-directory)
+
+# Generate the package license contents.
+
+$(PackageSourceDir)/COPYING: source
+
+$(PackageLicenseFile): $(PackageSourceDir)/COPYING
+	$(copy-result)
+
+# Extract the source from the archive and apply patches, if any.
+
+$(PackageSourceDir): $(PackageArchive) $(PackagePatchPaths)
+	$(expand-and-patch-package)
+
+# Prepare the sources.
+
+.PHONY: source
+source: $(BuildDirectory)/source_empty
+$(BuildDirectory)/source_empty: | $(PackageSourceDir) $(BuildDirectory)
+	$(Verbose)touch $@
+
+.PHONY: patch
+patch: $(BuildDirectory)/patch_empty
+$(BuildDirectory)/patch_empty: $(BuildDirectory)/source_empty | $(BuildDirectory)
+	$(Verbose)touch $@
+
+$(PackageBuildMakefile): | $(PackageSourceDir) $(BuildDirectory)
+	$(call create-links,$(CURDIR)/$(PackageSourceDir),$(BuildDirectory))
+
+# I had to add CLANGCXXFLAGS directly to CXX because the atrocious protobuf configure script
+# fails to pass LD and LDFLAGS to the makefile for linking.  We need this flags since we're
+# linking against C++ on darwin.  Uggghhh.
+.PHONY: configure
+configure: $(BuildDirectory)/configure_empty
+$(BuildDirectory)/configure_empty: $(BuildDirectory)/source_empty $(PackageBuildMakefile) | $(BuildDirectory)
+	$(Verbose)cd $(BuildDirectory) && \
+	$(CURDIR)/$(PackageSourceDir)/configure \
+	CC="$(CC) $(CPPOPTFLAGS)" CXX="$(CXX) $(CPPOPTFLAGS) $(CLANGCXXFLAGS)" AR="$(AR)" RANLIB="$(RANLIB)" STRIP="$(STRIP)" \
+	INSTALL="$(INSTALL) $(INSTALLFLAGS)" \
+	--build=$(HostTuple) \
+	--host=$(TargetTuple) \
+	--prefix=$(PackageResultPath) \
+	--sysconfdir=/etc \
+	--localstatedir=/var \
+	--enable-static=no \
+	--enable-shared=yes \
+	--without-zlib
+	$(Verbose)touch $@
+
+.PHONY: build
+build: $(BuildDirectory)/build_empty
+$(BuildDirectory)/build_empty: $(BuildDirectory)/configure_empty | $(BuildDirectory)
+	$(Verbose)unset MAKEFLAGS && \
+	$(MAKE) $(JOBSFLAG) -C $(BuildDirectory) \
+	all
+	$(Verbose)touch $@
+
+.PHONY: stage
+stage: $(BuildDirectory)/stage_empty
+$(BuildDirectory)/stage_empty: $(BuildDirectory)/build_empty | $(ResultDirectory) $(BuildDirectory)
+	$(Verbose)unset MAKEFLAGS && \
+	$(MAKE) $(JOBSFLAG) -C $(BuildDirectory) \
+	install
+	$(Verbose)touch $@
+
+clean:
+	$(Verbose)$(RM) $(RMFLAGS) -r $(PackageSourceDir)
+	$(Verbose)$(RM) $(RMFLAGS) -r $(BuildDirectory)
+	$(Verbose)$(RM) $(RMFLAGS) -r $(ResultDirectory)
+
+include post.mak
+
+ifneq ($(BUILD_FEATURE_SIMULATOR),1)
+override BuildMode  := $(SaveBuildMode)
+endif
diff --git a/Makefile.target b/Makefile.target
new file mode 100644
index 0000000..afedbcb
--- /dev/null
+++ b/Makefile.target
@@ -0,0 +1,114 @@
+#
+#    Copyright (c) 2017 Nest Labs, Inc.
+#    All rights reserved.
+#
+#    This document is the property of Nest. It is considered
+#    confidential and proprietary information.
+#
+#    This document may not be reproduced or transmitted in any form,
+#    in whole or in part, without the express written permission of
+#    Nest.
+#
+#    Description:
+#    This file is the protobuf makefile for the target.  Once the
+#    automatically generated code is compiled using the cross compiler,
+#    the protobuf shared object will need to reside on the target.
+#
+
+include pre.mak
+
+PackageName		:= protobuf
+
+PackageExtension	:= tar.gz
+PackageSeparator	:= -
+
+PackagePatchArgs	:= -p1
+
+PackageArchive		:= $(PackageName).$(PackageExtension)
+PackageSourceDir	:= $(PackageName)$(PackageSeparator)$(PackageVersion)
+
+PackageBuildMakefile	= $(call GenerateBuildPaths,Makefile)
+
+PackageResultPath = $(call GenerateResultPaths,,usr)
+
+CleanPaths		+= $(PackageLicenseFile)
+
+SOURCEDIRS                      = $(PackageSourceDir)
+$(PackageSourceDir)_RULE_TARGET = $(BuildDirectory)/configure_empty
+
+all: $(PackageDefaultGoal)
+
+$(ResultDirectory)/lib:
+	$(create-directory)
+
+$(ResultDirectory)/include:
+	$(create-directory)
+
+# Generate the package license contents.
+
+$(PackageSourceDir)/COPYING: source
+
+$(PackageLicenseFile): $(PackageSourceDir)/COPYING
+	$(copy-result)
+
+# Extract the source from the archive and apply patches, if any.
+
+$(PackageSourceDir): $(PackageArchive) $(PackagePatchPaths)
+	$(expand-and-patch-package)
+
+# Prepare the sources.
+
+.PHONY: source
+source: $(BuildDirectory)/source_empty
+$(BuildDirectory)/source_empty: | $(PackageSourceDir) $(BuildDirectory)
+	$(Verbose)touch $@
+
+.PHONY: patch
+patch: $(BuildDirectory)/patch_empty
+$(BuildDirectory)/patch_empty: $(BuildDirectory)/source_empty | $(BuildDirectory)
+	$(Verbose)touch $@
+
+$(PackageBuildMakefile): | $(PackageSourceDir) $(BuildDirectory)
+	$(call create-links,$(CURDIR)/$(PackageSourceDir),$(BuildDirectory))
+
+.PHONY: configure
+configure: $(BuildDirectory)/configure_empty
+$(BuildDirectory)/configure_empty: $(BuildDirectory)/source_empty $(PackageBuildMakefile) | $(BuildDirectory)
+	$(Verbose)cd $(BuildDirectory) && \
+	$(CURDIR)/$(PackageSourceDir)/configure \
+	INSTALL="$(INSTALL) $(INSTALLFLAGS)" \
+	CC="$(CC) $(CPPOPTFLAGS)" CXX="$(CXX) $(CPPOPTFLAGS)" AR="$(AR)" RANLIB="$(RANLIB)" STRIP="$(STRIP)" \
+	CPPFLAGS="$(call ToolGenerateIncludeArgument,$(LinuxIncludePath))" \
+	--build=$(HostTuple) \
+	--host=$(TargetTuple) \
+	--prefix=$(PackageResultPath) \
+	--sysconfdir=/etc \
+	--localstatedir=/var \
+	--enable-static=no \
+	--enable-shared=yes \
+	--without-zlib \
+	--with-protoc=$(ProtocExecutableHostResultPath)/protoc
+	$(Verbose)touch $@
+
+.PHONY: build
+build: $(BuildDirectory)/build_empty
+$(BuildDirectory)/build_empty: $(BuildDirectory)/configure_empty | $(BuildDirectory)
+	$(Verbose)unset MAKEFLAGS && \
+	$(MAKE) $(JOBSFLAG) -C $(BuildDirectory) \
+	all
+	$(Verbose)touch $@
+
+.PHONY: stage
+stage: $(BuildDirectory)/stage_empty
+$(BuildDirectory)/stage_empty: $(BuildDirectory)/build_empty | $(ResultDirectory) $(BuildDirectory)
+	$(Verbose)unset MAKEFLAGS && \
+	$(MAKE) $(JOBSFLAG) -C $(BuildDirectory) \
+	install
+	$(Verbose)touch $@
+
+clean:
+	$(Verbose)$(RM) $(RMFLAGS) -r $(PackageSourceDir)
+	$(Verbose)$(RM) $(RMFLAGS) -r $(BuildDirectory)
+	$(Verbose)$(RM) $(RMFLAGS) -r $(ResultDirectory)
+
+include post.mak
diff --git a/protobuf.patches/protobuf-00.description b/protobuf.patches/protobuf-00.description
new file mode 100644
index 0000000..b6b96e0
--- /dev/null
+++ b/protobuf.patches/protobuf-00.description
@@ -0,0 +1,5 @@
+What a fucking nightmare it was to find this.  Protobuf has the most horrendous include search path flag of all-fucking-time.  So their build system, when set up for a cross-compile using --with-protoc, doesn't work in the testing phase because the -I didn't work correctly.  Why?  I have no fucking clue.
+
+For the simulator build (host), it would cd into the src directory, then use -I., and set the paths to the .proto files as google/protobuf/blah.proto.  This worked fine for the simulator build.  This also follows the rule that the -I flag be a prefix of the .proto files, since -I pointed to the pwd (src), and google/protobuf is a subdirectory of that.
+
+For the target build, the build kept failing.  In the host build it cd'ed into the src directory out of convenience.  The protoc executable resides there, along with the built libraries, and the test .proto files are subdirectories (google/protobuf/*.proto).  Since in the target build case we passed in the protoc executable to use for running the test cases (--with-protoc), it wasn't nearly as convenient to cd into this directory, so they didn't.  Instead, they try to get clever with their use of the -I flag and paths to the .proto files.  Instead of being clever, though, it was an enormous bucket of shit.  It exposed how awful their implementation of the -I flag was with the "must encompass blah blah blah" and "too dumb" bullshit.  Fuck you protobuf.  The way the makefile implemented things, as best I could tell, was indeed correct.  The paths to the .proto files was indeed encompassed by -I$(srcdir), but it didn't fucking work.  After much experimentation, a few stackoverflow articles, and nearly setting my hair on fire, I figured out that I needed to prefix the .proto files with the $(srcdir), which is non intuitive given the "encompass" crap given in the warning, and the description of how the half-assed -I flag works.
diff --git a/protobuf.patches/protobuf-00.patch b/protobuf.patches/protobuf-00.patch
new file mode 100644
index 0000000..f357103
--- /dev/null
+++ b/protobuf.patches/protobuf-00.patch
@@ -0,0 +1,12 @@
+diff -Naur a/src/Makefile.in b/src/Makefile.in
+--- a/src/Makefile.in	2014-10-22 13:10:29.000000000 -0700
++++ b/src/Makefile.in	2015-08-17 23:10:49.730533320 -0700
+@@ -3624,7 +3624,7 @@
+ 	rm -f *.loT
+ 
+ @USE_EXTERNAL_PROTOC_TRUE@unittest_proto_middleman: $(protoc_inputs)
+-@USE_EXTERNAL_PROTOC_TRUE@	$(PROTOC) -I$(srcdir) --cpp_out=. $^
++@USE_EXTERNAL_PROTOC_TRUE@	$(PROTOC) -I$(srcdir) --cpp_out=. $(addprefix $(srcdir)/,$^)
+ @USE_EXTERNAL_PROTOC_TRUE@	touch unittest_proto_middleman
+ 
+ # We have to cd to $(srcdir) before executing protoc because $(protoc_inputs) is
diff --git a/protobuf.tar.gz b/protobuf.tar.gz
new file mode 100644
index 0000000..bcd6944
--- /dev/null
+++ b/protobuf.tar.gz
Binary files differ
diff --git a/protobuf.url b/protobuf.url
new file mode 100644
index 0000000..e996a51
--- /dev/null
+++ b/protobuf.url
@@ -0,0 +1 @@
+https://github.com/google/protobuf/releases/download/v3.1.0/protobuf-cpp-3.1.0.tar.gz
diff --git a/protobuf.version b/protobuf.version
new file mode 100644
index 0000000..fd2a018
--- /dev/null
+++ b/protobuf.version
@@ -0,0 +1 @@
+3.1.0