display: makefile fixes

* Deprecate LOCAL_COPY_HEADERS on newer builds
* Use a display header export path instead
* Consolidate cflags

CRs-Fixed: 2023356
Change-Id: Ibb8900a77fc3fa47e6e54cd1649503eba12de8cd
diff --git a/common.mk b/common.mk
index 3a55cca..941b0a4 100644
--- a/common.mk
+++ b/common.mk
@@ -6,59 +6,17 @@
 common_flags += -Wconversion -Wall -Werror -std=c++11
 ifneq ($(TARGET_IS_HEADLESS), true)
     common_flags += -DCOMPILE_DRM
+else
+    common_flags += -DTARGET_HEADLESS
+    LOCAL_CLANG := false
 endif
 
 ifeq ($(TARGET_USES_COLOR_METADATA), true)
-common_flags += -DUSE_COLOR_METADATA
+    common_flags += -DUSE_COLOR_METADATA
 endif
 
-CHECK_VERSION_LE = $(shell if [ $(1) -le $(2) ] ; then echo true ; else echo false ; fi)
-PLATFORM_SDK_NOUGAT = 25
-ifeq "REL" "$(PLATFORM_VERSION_CODENAME)"
-ifeq ($(call CHECK_VERSION_LE, $(PLATFORM_SDK_VERSION), $(PLATFORM_SDK_NOUGAT)), true)
-version_flag := -D__NOUGAT__
-endif
-endif
-
-use_hwc2 := false
-ifeq ($(TARGET_USES_HWC2), true)
-    use_hwc2 := true
-    common_flags += -DVIDEO_MODE_DEFER_RETIRE_FENCE
-endif
-
-common_includes := $(display_top)/libqdutils
-common_includes += $(display_top)/libqservice
-common_includes += $(display_top)/gpu_tonemapper
-ifneq ($(TARGET_IS_HEADLESS), true)
-    common_includes += $(display_top)/libcopybit
-    common_includes += $(display_top)/libdrmutils
-endif
-
-common_includes += $(display_top)/include
-common_includes += $(display_top)/sdm/include
-common_includes += system/core/base/include
-
-common_header_export_path := qcom/display
-
-#Common libraries external to display HAL
-common_libs := liblog libutils libcutils libhardware
-
-ifeq ($(TARGET_IS_HEADLESS), true)
-    LOCAL_CLANG := false
-else
-    LOCAL_CLANG := true
-endif
-
-ifneq ($(TARGET_USES_GRALLOC1), true)
-    common_flags += -isystem $(display_top)/libgralloc
-else
-    common_flags += -isystem $(display_top)/libgralloc1
-    common_flags += -DUSE_GRALLOC1
-endif
-
-ifeq ($(TARGET_USES_POST_PROCESSING),true)
-    common_flags     += -DUSES_POST_PROCESSING
-    common_includes  += $(TARGET_OUT_HEADERS)/pp/inc
+ifeq ($(TARGET_USES_QCOM_BSP),true)
+    common_flags += -DQTI_BSP
 endif
 
 ifeq ($(ARCH_ARM_HAVE_NEON),true)
@@ -69,19 +27,45 @@
     common_flags += -DMASTER_SIDE_CP
 endif
 
+use_hwc2 := false
+ifeq ($(TARGET_USES_HWC2), true)
+    use_hwc2 := true
+    common_flags += -DVIDEO_MODE_DEFER_RETIRE_FENCE
+endif
+
+ifeq ($(TARGET_USES_GRALLOC1), true)
+    common_flags += -DUSE_GRALLOC1
+endif
+
+common_includes := system/core/base/include
+CHECK_VERSION_LE = $(shell if [ $(1) -le $(2) ] ; then echo true ; else echo false ; fi)
+PLATFORM_SDK_NOUGAT = 25
+ifeq "REL" "$(PLATFORM_VERSION_CODENAME)"
+ifeq ($(call CHECK_VERSION_LE, $(PLATFORM_SDK_VERSION), $(PLATFORM_SDK_NOUGAT)), true)
+version_flag := -D__NOUGAT__
+
+# These include paths are deprecated post N
+common_includes += $(display_top)/libqdutils
+common_includes += $(display_top)/libqservice
+common_includes += $(display_top)/gpu_tonemapper
+ifneq ($(TARGET_IS_HEADLESS), true)
+    common_includes += $(display_top)/libcopybit
+    common_includes += $(display_top)/libdrmutils
+endif
+
+common_includes += $(display_top)/include
+common_includes += $(display_top)/sdm/include
+common_flags += -isystem $(TARGET_OUT_HEADERS)/qcom/display
+endif
+endif
+
+common_header_export_path := qcom/display
+
+#Common libraries external to display HAL
+common_libs := liblog libutils libcutils libhardware
 common_deps  :=
 kernel_includes :=
 
-# Executed only on QCOM BSPs
-ifeq ($(TARGET_USES_QCOM_BSP),true)
-# Enable QCOM Display features
-   common_flags += -DQTI_BSP
-endif
-
-ifeq ($(TARGET_IS_HEADLESS),true)
-    common_flags += -DTARGET_HEADLESS
-endif
-
 ifeq ($(TARGET_COMPILE_WITH_MSM_KERNEL),true)
 # This check is to pick the kernel headers from the right location.
 # If the macro above is defined, we make the assumption that we have the kernel
diff --git a/hdmi_cec/Android.mk b/hdmi_cec/Android.mk
index 3b794e3..6539933 100644
--- a/hdmi_cec/Android.mk
+++ b/hdmi_cec/Android.mk
@@ -6,6 +6,7 @@
 LOCAL_MODULE_RELATIVE_PATH    := hw
 LOCAL_MODULE_TAGS             := optional
 LOCAL_C_INCLUDES              := $(common_includes)
+LOCAL_HEADER_LIBRARIES        := display_headers
 LOCAL_SHARED_LIBRARIES        := $(common_libs) libqservice libbinder libqdutils
 
 LOCAL_CFLAGS                  := $(common_flags) -DLOG_TAG=\"qdhdmi_cec\" -Wno-sign-conversion
diff --git a/include/Android.mk b/include/Android.mk
index 4d0d9f7..95c5d25 100644
--- a/include/Android.mk
+++ b/include/Android.mk
@@ -7,3 +7,19 @@
 
 include $(BUILD_COPY_HEADERS)
 
+include $(CLEAR_VARS)
+#TODO move all exported headers to this directory
+LOCAL_MODULE := display_headers
+LOCAL_EXPORT_C_INCLUDE_DIRS   := $(LOCAL_PATH) \
+                                 $(display_top)/libcopybit \
+                                 $(display_top)/libdrmutils \
+                                 $(display_top)/libqdutils \
+                                 $(display_top)/libqservice \
+                                 $(display_top)/sdm/include
+
+ifeq ($(TARGET_USES_GRALLOC1), true)
+    LOCAL_EXPORT_C_INCLUDE_DIRS += $(display_top)/libgralloc1
+else
+    LOCAL_EXPORT_C_INCLUDE_DIRS += $(display_top)/libgralloc
+endif
+include $(BUILD_HEADER_LIBRARY)
diff --git a/libgralloc1/Android.mk b/libgralloc1/Android.mk
index fb8c74a..6bbbda4 100644
--- a/libgralloc1/Android.mk
+++ b/libgralloc1/Android.mk
@@ -9,6 +9,7 @@
 LOCAL_C_INCLUDES              := $(common_includes) \
                                  external/libcxx/include/
 
+LOCAL_HEADER_LIBRARIES        := display_headers
 LOCAL_SHARED_LIBRARIES        := $(common_libs) libqdMetaData libsync libqdutils
 ifneq ($(TARGET_IS_HEADLESS), true)
 LOCAL_SHARED_LIBRARIES        += libdrmutils
diff --git a/libqdutils/Android.mk b/libqdutils/Android.mk
index cc0b013..fb8a776 100644
--- a/libqdutils/Android.mk
+++ b/libqdutils/Android.mk
@@ -6,6 +6,7 @@
 LOCAL_MODULE_TAGS             := optional
 LOCAL_SHARED_LIBRARIES        := $(common_libs) libbinder libqservice
 LOCAL_C_INCLUDES              := $(common_includes) $(kernel_includes)
+LOCAL_HEADER_LIBRARIES        := display_headers
 LOCAL_CFLAGS                  := $(common_flags) -DLOG_TAG=\"qdutils\" -Wno-sign-conversion
 LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
 LOCAL_COPY_HEADERS_TO         := $(common_header_export_path)
@@ -21,6 +22,7 @@
 LOCAL_COPY_HEADERS              := qdMetaData.h
 LOCAL_SHARED_LIBRARIES          := liblog libcutils
 LOCAL_C_INCLUDES                := $(common_includes)
+LOCAL_HEADER_LIBRARIES          := display_headers
 LOCAL_ADDITIONAL_DEPENDENCIES   := $(common_deps)
 LOCAL_SRC_FILES                 := qdMetaData.cpp
 LOCAL_CFLAGS                    := $(common_flags) -Wno-sign-conversion
diff --git a/sdm/libs/core/Android.mk b/sdm/libs/core/Android.mk
index 114fcaf..abdd958 100644
--- a/sdm/libs/core/Android.mk
+++ b/sdm/libs/core/Android.mk
@@ -4,7 +4,8 @@
 
 LOCAL_MODULE                  := libsdmcore
 LOCAL_MODULE_TAGS             := optional
-LOCAL_C_INCLUDES              := $(common_includes) $(kernel_includes) $(common_header_export_path)
+LOCAL_C_INCLUDES              := $(common_includes) $(kernel_includes)
+LOCAL_HEADER_LIBRARIES        := display_headers
 LOCAL_CFLAGS                  := -Wno-unused-parameter -DLOG_TAG=\"SDM\" \
                                  $(common_flags)
 ifeq ($(use_hwc2),false)
diff --git a/sdm/libs/hwc2/Android.mk b/sdm/libs/hwc2/Android.mk
index d4ff53c..aeb2558 100644
--- a/sdm/libs/hwc2/Android.mk
+++ b/sdm/libs/hwc2/Android.mk
@@ -8,6 +8,7 @@
 LOCAL_MODULE_RELATIVE_PATH    := hw
 LOCAL_MODULE_TAGS             := optional
 LOCAL_C_INCLUDES              := $(common_includes)
+LOCAL_HEADER_LIBRARIES        := display_headers
 
 LOCAL_CFLAGS                  := -Wno-missing-field-initializers -Wno-unused-parameter \
                                  -std=c++11 -fcolor-diagnostics\
diff --git a/sdm/libs/utils/Android.mk b/sdm/libs/utils/Android.mk
index f7f30a9..9b7f531 100644
--- a/sdm/libs/utils/Android.mk
+++ b/sdm/libs/utils/Android.mk
@@ -5,6 +5,7 @@
 LOCAL_MODULE                  := libsdmutils
 LOCAL_MODULE_TAGS             := optional
 LOCAL_C_INCLUDES              := $(common_includes)
+LOCAL_HEADER_LIBRARIES        := display_headers
 LOCAL_CFLAGS                  := -DLOG_TAG=\"SDM\" $(common_flags)
 LOCAL_SRC_FILES               := debug.cpp \
                                  rect.cpp \