build: import qcom_utils and qcom_targets from android-7.1

build: Add Qualcomm's helper macros

 * This is used everywhere in Qualcomm's code. There's no reason we need
   to constantly replace it with uglier stuff in our Makefiles.

Change-Id: I0183a338470ec96a38f356a47bae65a0d3fb2c95

build: Add QCOM target-specific config

 * Needed to support global DirectTract config on legacy targets
 * Let's also eliminate some boilerplate

Change-Id: I668a79e3900219faf2c0b220895700d51a50d813

build: Add board platforms to qcom_utils

Change-Id: I85458167bf2b9c04b029d09b87bf791ff4cfd04d

Add new version to qcom_utils.mk

Change-Id: I1ca1532fd4968450715ecd0cca7729e0e6d507ef

build: fix usage of qcom_target

Change-Id: I5fbcf7d3b6de2a90a56cd0d695a97df2289830b2

buils: readd 8992 8994 and 8996 to QCOM_BOARD_PLATFORMS

Change-Id: Iece3bac53ce10a9ae9b14202a2bf12f9cb9c731c

build: qcom utils define is-platform-sdk-version-at-least

widely used by qcom hals

thanx to CM

Change-Id: I33333c29124a242daf41a7178b745a2fa226d2a8

qcom_utils: Add msm8226 to the list of known boards

Change-Id: Ic252210b25b2a4448315829aa65ee41994fe58aa

Add msm8909 & msm8952 to QCOM_BOARD_PLATFORMS

These used to be here, but apparently got lost in the bringup

Change-Id: Ie7e8ab96d9e50efd2c21679756caab8f558952c6

build: Add msm8952 to MSM_VIDC_TARGET_LIST

Change-Id: I8c2a4d22db8d14e078c7e07bb77c3a3817f5bf95

Add msm8998 to qcom devices

The S835 devices are coming!

Change-Id: I124a925aca1a32bfaa88eda7a60bf9c061999f2d

qcom_utils: Add msm8937 to QCOM_BOARD_PLATFORMS

Change-Id: If68bc8c10368b8c5542b2bc7412f76dbe55c304e

Add msm8953 to QCOM devices & msms8937 to QCOM target

Change-Id: I98a42e42868a8d91b3992b2c7f8177e2c86a3a3b

core: qcom_utils: Add missing target boards

Change-Id: I22a3b857945d31d752d6891621fedaf359206887

core: qcom_utils: Add msm8939 to target boards

Change-Id: I5b7f723f88b9eb5ae35b45840f86fcedf8b7b496

Add apq8084 as qcom platform

Change-Id: I991bb06c1fdd99516204e0764690b3d770ffb310
Signed-off-by: Corinna Vinschen <xda@vinschen.de>

qcom_utils: add up-to-date SDK versions

Change-Id: If3b62c052191374aad7fa4915bc666de24793a1d

qcom_target: change global flag names

Change-Id: I4e8e61ebb276765c4400dc60a21f63e0dfeb8c86
diff --git a/build/core/qcom_target.mk b/build/core/qcom_target.mk
new file mode 100644
index 0000000..980e17b
--- /dev/null
+++ b/build/core/qcom_target.mk
@@ -0,0 +1,24 @@
+# Target-specific configuration
+ifeq ($(BOARD_USES_QCOM_HARDWARE),true)
+    qcom_flags := -DQCOM_HARDWARE
+    ifeq ($(TARGET_USES_QCOM_BSP),true)
+        qcom_flags += -DQCOM_BSP
+        qcom_flags += -DQTI_BSP
+    endif
+
+#    TARGET_GLOBAL_CFLAGS += $(qcom_flags)
+#    TARGET_GLOBAL_CPPFLAGS += $(qcom_flags)
+    PRIVATE_TARGET_GLOBAL_CFLAGS += $(qcom_flags)
+    PRIVATE_TARGET_GLOBAL_CPPFLAGS += $(qcom_flags)
+
+    # Multiarch needs these too..
+#    2ND_TARGET_GLOBAL_CFLAGS += $(qcom_flags)
+#    2ND_TARGET_GLOBAL_CPPFLAGS += $(qcom_flags)
+#    2ND_CLANG_TARGET_GLOBAL_CFLAGS += $(qcom_flags)
+#    2ND_CLANG_TARGET_GLOBAL_CPPFLAGS += $(qcom_flags)
+
+    TARGET_COMPILE_WITH_MSM_KERNEL := true
+    MSM_VIDC_TARGET_LIST := msm8974 msm8610 msm8226 apq8084 msm8916 msm8937 msm8952 msm8953 msm8994 msm8909 msm8992 msm8996 msm8998
+endif
+
+
diff --git a/build/core/qcom_utils.mk b/build/core/qcom_utils.mk
new file mode 100755
index 0000000..fdd0d31
--- /dev/null
+++ b/build/core/qcom_utils.mk
@@ -0,0 +1,239 @@
+# Board platforms lists to be used for
+# TARGET_BOARD_PLATFORM specific featurization
+QCOM_BOARD_PLATFORMS := msm7627_surf
+QCOM_BOARD_PLATFORMS += msm7627_6x
+QCOM_BOARD_PLATFORMS += msm7627a
+QCOM_BOARD_PLATFORMS += msm7630_surf
+QCOM_BOARD_PLATFORMS += msm7630_fusion
+QCOM_BOARD_PLATFORMS += msm8226
+QCOM_BOARD_PLATFORMS += msm8660
+QCOM_BOARD_PLATFORMS += msm8909
+QCOM_BOARD_PLATFORMS += msm8916
+QCOM_BOARD_PLATFORMS += msm8939
+QCOM_BOARD_PLATFORMS += msm8937
+QCOM_BOARD_PLATFORMS += msm8952
+QCOM_BOARD_PLATFORMS += msm8953
+QCOM_BOARD_PLATFORMS += msm8960
+QCOM_BOARD_PLATFORMS += msm8974
+QCOM_BOARD_PLATFORMS += msm8992
+QCOM_BOARD_PLATFORMS += msm8994
+QCOM_BOARD_PLATFORMS += msm8996
+QCOM_BOARD_PLATFORMS += msm8998
+QCOM_BOARD_PLATFORMS += apq8084
+
+MSM7K_BOARD_PLATFORMS := msm7630_surf
+MSM7K_BOARD_PLATFORMS += msm7630_fusion
+MSM7K_BOARD_PLATFORMS += msm7627_surf
+MSM7K_BOARD_PLATFORMS += msm7627_6x
+MSM7K_BOARD_PLATFORMS += msm7627a
+MSM7K_BOARD_PLATFORMS += msm7k
+
+QSD8K_BOARD_PLATFORMS := qsd8k
+
+
+# vars for use by utils
+empty :=
+space := $(empty) $(empty)
+colon := $(empty):$(empty)
+underscore := $(empty)_$(empty)
+
+# $(call match-word,w1,w2)
+# checks if w1 == w2
+# How it works
+#   if (w1-w2 not empty or w2-w1 not empty) then not_match else match
+#
+# returns true or empty
+#$(warning :$(1): :$(2): :$(subst $(1),,$(2)):) \
+#$(warning :$(2): :$(1): :$(subst $(2),,$(1)):) \
+#
+define match-word
+$(strip \
+  $(if $(or $(subst $(1),$(empty),$(2)),$(subst $(2),$(empty),$(1))),,true) \
+)
+endef
+
+# $(call find-word-in-list,w,wlist)
+# finds an exact match of word w in word list wlist
+#
+# How it works
+#   fill wlist spaces with colon
+#   wrap w with colon
+#   search word w in list wl, if found match m, return stripped word w
+#
+# returns stripped word or empty
+define find-word-in-list
+$(strip \
+  $(eval wl:= $(colon)$(subst $(space),$(colon),$(strip $(2)))$(colon)) \
+  $(eval w:= $(colon)$(strip $(1))$(colon)) \
+  $(eval m:= $(findstring $(w),$(wl))) \
+  $(if $(m),$(1),) \
+)
+endef
+
+# $(call match-word-in-list,w,wlist)
+# does an exact match of word w in word list wlist
+# How it works
+#   if the input word is not empty
+#     return output of an exact match of word w in wordlist wlist
+#   else
+#     return empty
+# returns true or empty
+define match-word-in-list
+$(strip \
+  $(if $(strip $(1)), \
+    $(call match-word,$(call find-word-in-list,$(1),$(2)),$(strip $(1))), \
+  ) \
+)
+endef
+
+# $(call match-prefix,p,delim,w/wlist)
+# matches prefix p in wlist using delimiter delim
+#
+# How it works
+#   trim the words in wlist w
+#   if find-word-in-list returns not empty
+#     return true
+#   else
+#     return empty
+#
+define match-prefix
+$(strip \
+  $(eval w := $(strip $(1)$(strip $(2)))) \
+  $(eval text := $(patsubst $(w)%,$(1),$(3))) \
+  $(if $(call match-word-in-list,$(1),$(text)),true,) \
+)
+endef
+
+# ----
+# The following utilities are meant for board platform specific
+# featurisation
+
+# $(call get-vendor-board-platforms,v)
+# returns list of board platforms for vendor v
+define get-vendor-board-platforms
+$($(1)_BOARD_PLATFORMS)
+endef
+
+# $(call is-board-platform,bp)
+# returns true or empty
+define is-board-platform
+$(call match-word,$(1),$(TARGET_BOARD_PLATFORM))
+endef
+
+# $(call is-not-board-platform,bp)
+# returns true or empty
+define is-not-board-platform
+$(if $(call match-word,$(1),$(TARGET_BOARD_PLATFORM)),,true)
+endef
+
+# $(call is-board-platform-in-list,bpl)
+# returns true or empty
+define is-board-platform-in-list
+$(call match-word-in-list,$(TARGET_BOARD_PLATFORM),$(1))
+endef
+
+# $(call is-vendor-board-platform,vendor)
+# returns true or empty
+define is-vendor-board-platform
+$(strip \
+  $(call match-word-in-list,$(TARGET_BOARD_PLATFORM),\
+    $(call get-vendor-board-platforms,$(1)) \
+  ) \
+)
+endef
+
+# $(call is-chipset-in-board-platform,chipset)
+# does a prefix match of chipset in TARGET_BOARD_PLATFORM
+# uses underscore as a delimiter
+#
+# returns true or empty
+define is-chipset-in-board-platform
+$(call match-prefix,$(1),$(underscore),$(TARGET_BOARD_PLATFORM))
+endef
+
+# $(call is-chipset-prefix-in-board-platform,prefix)
+# does a chipset prefix match in TARGET_BOARD_PLATFORM
+# assumes '_' and 'a' as the delimiter to the chipset prefix
+#
+# How it works
+#   if ($(prefix)_ or $(prefix)a match in board platform)
+#     return true
+#   else
+#     return empty
+#
+define is-chipset-prefix-in-board-platform
+$(strip \
+  $(eval delim_a := $(empty)a$(empty)) \
+  $(if \
+    $(or \
+      $(call match-prefix,$(1),$(delim_a),$(TARGET_BOARD_PLATFORM)), \
+      $(call match-prefix,$(1),$(underscore),$(TARGET_BOARD_PLATFORM)), \
+    ), \
+    true, \
+  ) \
+)
+endef
+
+#----
+# The following utilities are meant for Android Code Name
+# specific featurisation
+#
+# refer http://source.android.com/source/build-numbers.html
+# for code names and associated sdk versions
+CUPCAKE_SDK_VERSIONS := 3
+DONUT_SDK_VERSIONS   := 4
+ECLAIR_SDK_VERSIONS  := 5 6 7
+FROYO_SDK_VERSIONS   := 8
+GINGERBREAD_SDK_VERSIONS := 9 10
+HONEYCOMB_SDK_VERSIONS := 11 12 13
+ICECREAM_SANDWICH_SDK_VERSIONS := 14 15
+JELLY_BEAN_SDK_VERSIONS := 16 17 18
+KITKAT_SDK_VERSIONS := 19
+LOLLIPOP_SDK_VERSIONS := 21 22
+MARSHMALLOW_SDK_VERSIONS := 23
+NOUGAT_SDK_VERSIONS := 24 25
+OREO_SDK_VERSIONS := 26
+
+# $(call is-platform-sdk-version-at-least,version)
+# version is a numeric SDK_VERSION defined above
+define is-platform-sdk-version-at-least
+$(strip \
+  $(if $(filter 1,$(shell echo "$$(( $(PLATFORM_SDK_VERSION) >= $(1) ))" )), \
+    true, \
+  ) \
+)
+endef
+
+# $(call is-android-codename,codename)
+# codename is one of cupcake,donut,eclair,froyo,gingerbread,icecream
+# please refer the $(codename)_SDK_VERSIONS declared above
+define is-android-codename
+$(strip \
+  $(if \
+    $(call match-word-in-list,$(PLATFORM_SDK_VERSION),$($(1)_SDK_VERSIONS)), \
+    true, \
+  ) \
+)
+endef
+
+# $(call is-android-codename-in-list,cnlist)
+# cnlist is combination/list of android codenames
+define is-android-codename-in-list
+$(strip \
+  $(eval acn := $(empty)) \
+    $(foreach \
+      i,$(1),\
+      $(eval acn += \
+        $(if \
+          $(call \
+            match-word-in-list,\
+            $(PLATFORM_SDK_VERSION),\
+            $($(i)_SDK_VERSIONS)\
+          ),\
+          true,\
+        )\
+      )\
+    ) \
+  $(if $(strip $(acn)),true,) \
+)
+endef