build: Add Bliss build support

Squashed also with the following changes:

  Author: Luca Stefani <luca020400@lineageos.org>
  Date:   Thu Aug 17 22:22:13 2017 +0200

    core: Include Bliss pathmap

  Change-Id: Ie25dee383cc5bc9bb6390cff2cb2460d526d80b6

  Author: Simon Shields <simon@lineageos.org>
  Date:   Fri Mar 2 12:55:47 2018 +1100

    build: unconditionally use bliss pathmap

    even if we're not building a bliss target, we need to
    use the bliss pathmap to make things like recovery and ril
    happy

  Change-Id: I974c30ad10d4ff5b7805c3df9c22010f1e002bf1

Change-Id: Iab8b2ef8b644a7bea10bfd28b99d9e69539b1357
diff --git a/core/Makefile b/core/Makefile
index 28c7a9e..ad5e699 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -332,6 +332,7 @@
 	$(hide) TARGET_BUILD_TYPE="$(TARGET_BUILD_VARIANT)" \
 			TARGET_BUILD_FLAVOR="$(TARGET_BUILD_FLAVOR)" \
 			TARGET_DEVICE="$(TARGET_DEVICE)" \
+			BLISS_DEVICE="$(TARGET_DEVICE)" \
 			PRODUCT_NAME="$(TARGET_PRODUCT)" \
 			PRODUCT_BRAND="$(PRODUCT_BRAND)" \
 			PRODUCT_DEFAULT_LOCALE="$(call get-default-product-locale,$(PRODUCT_LOCALES))" \
diff --git a/core/clear_vars.mk b/core/clear_vars.mk
index 8253504..8375d51 100644
--- a/core/clear_vars.mk
+++ b/core/clear_vars.mk
@@ -473,6 +473,9 @@
 LOCAL_CUSTOM_BUILD_STEP_OUTPUT:=
 LOCAL_IS_AUX_MODULE :=
 
+# Include any vendor specific clear_vars.mk file
+-include vendor/*/build/core/clear_vars.mk
+
 # Trim MAKEFILE_LIST so that $(call my-dir) doesn't need to
 # iterate over thousands of entries every time.
 # Leave the current makefile to make sure we don't break anything
diff --git a/core/config.mk b/core/config.mk
index fba81ec..b9010cd 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -224,6 +224,14 @@
 # See envsetup.mk for a description of SCAN_EXCLUDE_DIRS
 FIND_LEAVES_EXCLUDES := $(addprefix --prune=, $(SCAN_EXCLUDE_DIRS) .repo .git)
 
+# General entries for project pathmap.  Any entries listed here should
+# be device and hardware independent.
+$(call project-set-path-variant,ril,TARGET_RIL_VARIANT,hardware/ril)
+
+ifneq ($(BLISS_BUILD),)
+include vendor/bliss/config/BoardConfigBliss.mk
+endif
+
 # The build system exposes several variables for where to find the kernel
 # headers:
 #   TARGET_DEVICE_KERNEL_HEADERS is automatically created for the current
@@ -1086,4 +1094,12 @@
 include $(BUILD_SYSTEM)/soong_config.mk
 endif
 
+ifneq ($(BLISS_BUILD),)
+## We need to be sure the global selinux policies are included
+## last, to avoid accidental resetting by device configs
+$(eval include device/lineage/sepolicy/common/sepolicy.mk)
+endif
+# Include any vendor specific config.mk file
+-include vendor/*/build/core/config.mk
+
 include $(BUILD_SYSTEM)/dumpvar.mk
diff --git a/core/pathmap.mk b/core/pathmap.mk
index af33f5d..5d77721 100644
--- a/core/pathmap.mk
+++ b/core/pathmap.mk
@@ -93,3 +93,5 @@
 #
 FRAMEWORKS_BASE_JAVA_SRC_DIRS := \
 	$(addprefix frameworks/base/,$(FRAMEWORKS_BASE_SUBDIRS))
+
+-include vendor/bliss/build/core/pathmap.mk
diff --git a/envsetup.sh b/envsetup.sh
index 645f69b..d8cf3c8 100644
--- a/envsetup.sh
+++ b/envsetup.sh
@@ -137,6 +137,14 @@
         echo "Couldn't locate the top of the tree.  Try setting TOP." >&2
         return
     fi
+    if (echo -n $1 | grep -q -e "^bliss_") ; then
+        BLISS_BUILD=$(echo -n $1 | sed -e 's/^bliss_//g')
+        export BUILD_NUMBER=$( (date +%s%N ; echo $BLISS_BUILD; hostname) | openssl sha1 | sed -e 's/.*=//g; s/ //g' | cut -c1-10 )
+    else
+        BLISS_BUILD=
+    fi
+    export BLISS_BUILD
+
         TARGET_PRODUCT=$1 \
         TARGET_BUILD_VARIANT= \
         TARGET_BUILD_TYPE= \
@@ -623,6 +631,8 @@
         return 1
     fi
 
+    check_product $product
+
     TARGET_PRODUCT=$product \
     TARGET_BUILD_VARIANT=$variant \
     TARGET_PLATFORM_VERSION=$version \
diff --git a/tools/buildinfo.sh b/tools/buildinfo.sh
index 5a54462..dac3ba9 100755
--- a/tools/buildinfo.sh
+++ b/tools/buildinfo.sh
@@ -61,4 +61,6 @@
 fi
 echo "ro.build.characteristics=$TARGET_AAPT_CHARACTERISTICS"
 
+echo "ro.bliss.device=$BLISS_DEVICE"
+
 echo "# end build properties"