Add dist.mk for Excelsior

- Based off of Enterprise's file, with excelsior artifacts. Made the
copy into the dist folder recursive, since one of our targets is a
folder.

Change-Id: I0f770488da14511a6ee517376628ba0960e006b7
diff --git a/dist.mk b/dist.mk
new file mode 100644
index 0000000..6d1fbd0
--- /dev/null
+++ b/dist.mk
@@ -0,0 +1,54 @@
+# Copyright 2018 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+ifeq ($(ROOTDIR),)
+$(error $$ROOTDIR IS NOT DEFINED -- don\'t forget to source setup.sh)
+endif
+
+include $(ROOTDIR)/build/preamble.mk
+
+DATESTAMP       := $(shell TZ='UTC' date +%Y%m%d%H%M%S)
+DISTDIR         := $(PRODUCT_OUT)/dist
+DIST_BASENAME   := excelsior-$(RELEASE_NAME)-$(DATESTAMP)
+DIST_ZIPNAME    := $(DISTDIR)/$(DIST_BASENAME).zip
+DIST_SHA256NAME := $(DISTDIR)/$(DIST_BASENAME).sha256
+
+DIST_FILES      := \
+	$(PRODUCT_OUT)/bl2_2G.img \
+	$(PRODUCT_OUT)/boot_arm64.img \
+	$(PRODUCT_OUT)/dl_addr.ini \
+	$(PRODUCT_OUT)/fip.bin \
+	$(PRODUCT_OUT)/lk_2G.bin \
+	$(PRODUCT_OUT)/partition-table.img \
+	$(PRODUCT_OUT)/rootfs_arm64.img \
+	$(PRODUCT_OUT)/u-boot-env.bin \
+	$(ROOTDIR)/board/flashtools \
+	$(ROOTDIR)/board/flash.sh
+
+package-images: $(DIST_ZIPNAME)
+sign-images: $(DIST_SHA256NAME)
+
+dirs:
+	mkdir -p $(PRODUCT_OUT)/obj/DIST
+	mkdir -p $(PRODUCT_OUT)/obj/DIST/$(DIST_BASENAME)
+	mkdir -p $(DISTDIR)
+
+$(DIST_ZIPNAME): $(DIST_FILES) dirs
+	cp -r $(DIST_FILES) $(PRODUCT_OUT)/obj/DIST/$(DIST_BASENAME)
+	pushd $(PRODUCT_OUT)/obj/DIST; zip -9r $(DIST_ZIPNAME) $(DIST_BASENAME); popd
+
+$(DIST_SHA256NAME): $(DIST_ZIPNAME) | dirs
+	sha256sum $(DIST_ZIPNAME) > $(DIST_SHA256NAME)
+
+.PHONY:: package-images sign-images dirs