android: introduce Android.common.mk to reduce boilerplate

... across the makefiles. Currently this isn't much but that will change
shortly.

As an added bonus this fixes all present and future cases where we've
forgotten to strip out the headers from LOCAL_SRC_FILES.

In a couple of cases (the tests) we start setting
LOCAL_EXPORT_C_INCLUDE_DIRS, which shouldn't be an issue.

Cc: Chih-Wei Huang <cwhuang@android-x86.org>
Cc: Rob Herring <robh@kernel.org>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Rob Herring <robh@kernel.org>
diff --git a/Android.common.mk b/Android.common.mk
new file mode 100644
index 0000000..c6ab8f5
--- /dev/null
+++ b/Android.common.mk
@@ -0,0 +1,6 @@
+LOCAL_CFLAGS += \
+	-DHAVE_LIBDRM_ATOMIC_PRIMITIVES=1
+
+# Quiet down the build system and remove any .h files from the sources
+LOCAL_SRC_FILES := $(patsubst %.h, , $(LOCAL_SRC_FILES))
+LOCAL_EXPORT_C_INCLUDE_DIRS += $(LOCAL_PATH)
diff --git a/Android.mk b/Android.mk
index 6ecc4e1..ec6d532 100644
--- a/Android.mk
+++ b/Android.mk
@@ -21,6 +21,8 @@
 # IN THE SOFTWARE.
 #
 
+LIBDRM_COMMON_MK := $(call my-dir)/Android.common.mk
+
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 
@@ -31,7 +33,7 @@
 include $(CLEAR_VARS)
 LOCAL_MODULE := libdrm
 
-LOCAL_SRC_FILES := $(patsubst %.h, , $(LIBDRM_FILES))
+LOCAL_SRC_FILES := $(LIBDRM_FILES)
 LOCAL_EXPORT_C_INCLUDE_DIRS := \
 	$(LOCAL_PATH) \
 	$(LOCAL_PATH)/include/drm
@@ -40,25 +42,26 @@
 	$(LOCAL_PATH)/include/drm
 
 LOCAL_CFLAGS := \
-	-DHAVE_VISIBILITY=1 \
-	-DHAVE_LIBDRM_ATOMIC_PRIMITIVES=1
+	-DHAVE_VISIBILITY=1
+
+include $(LIBDRM_COMMON_MK)
 include $(BUILD_STATIC_LIBRARY)
 
 # Shared library for the device
 include $(CLEAR_VARS)
 LOCAL_MODULE := libdrm
 
-LOCAL_SRC_FILES := $(patsubst %.h, , $(LIBDRM_FILES))
+LOCAL_SRC_FILES := $(LIBDRM_FILES)
 LOCAL_EXPORT_C_INCLUDE_DIRS := \
-        $(LOCAL_PATH) \
         $(LOCAL_PATH)/include/drm
 
 LOCAL_C_INCLUDES := \
         $(LOCAL_PATH)/include/drm
 
 LOCAL_CFLAGS := \
-        -DHAVE_VISIBILITY=1 \
-        -DHAVE_LIBDRM_ATOMIC_PRIMITIVES=1
+	-DHAVE_VISIBILITY=1
+
+include $(LIBDRM_COMMON_MK)
 include $(BUILD_SHARED_LIBRARY)
 
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/amdgpu/Android.mk b/amdgpu/Android.mk
index 332d957..bf0611b 100644
--- a/amdgpu/Android.mk
+++ b/amdgpu/Android.mk
@@ -8,10 +8,7 @@
 
 LOCAL_SHARED_LIBRARIES := libdrm
 
-LOCAL_SRC_FILES := $(patsubst %.h, , $(LIBDRM_AMDGPU_FILES))
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
+LOCAL_SRC_FILES := $(LIBDRM_AMDGPU_FILES)
 
-LOCAL_CFLAGS := \
-	-DHAVE_LIBDRM_ATOMIC_PRIMITIVES=1
-
+include $(LIBDRM_COMMON_MK)
 include $(BUILD_SHARED_LIBRARY)
diff --git a/etnaviv/Android.mk b/etnaviv/Android.mk
index a70eeac..390f9a9 100644
--- a/etnaviv/Android.mk
+++ b/etnaviv/Android.mk
@@ -8,10 +8,7 @@
 
 LOCAL_SHARED_LIBRARIES := libdrm
 
-LOCAL_SRC_FILES := $(patsubst %.h, , $(LIBDRM_ETNAVIV_FILES))
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
+LOCAL_SRC_FILES := $(LIBDRM_ETNAVIV_FILES)
 
-LOCAL_CFLAGS := \
-	-DHAVE_LIBDRM_ATOMIC_PRIMITIVES=1
-
+include $(LIBDRM_COMMON_MK)
 include $(BUILD_SHARED_LIBRARY)
diff --git a/freedreno/Android.mk b/freedreno/Android.mk
index d7e80e1..2b582ae 100644
--- a/freedreno/Android.mk
+++ b/freedreno/Android.mk
@@ -8,10 +8,7 @@
 
 LOCAL_SHARED_LIBRARIES := libdrm
 
-LOCAL_SRC_FILES := $(patsubst %.h, , $(LIBDRM_FREEDRENO_FILES))
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
+LOCAL_SRC_FILES := $(LIBDRM_FREEDRENO_FILES)
 
-LOCAL_CFLAGS := \
-	-DHAVE_LIBDRM_ATOMIC_PRIMITIVES=1
-
+include $(LIBDRM_COMMON_MK)
 include $(BUILD_SHARED_LIBRARY)
diff --git a/intel/Android.mk b/intel/Android.mk
index e7ec5a5..5407ff3 100644
--- a/intel/Android.mk
+++ b/intel/Android.mk
@@ -29,14 +29,11 @@
 
 LOCAL_MODULE := libdrm_intel
 
-LOCAL_SRC_FILES := $(patsubst %.h, , $(LIBDRM_INTEL_FILES))
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-
-LOCAL_CFLAGS := \
-	-DHAVE_LIBDRM_ATOMIC_PRIMITIVES=1
+LOCAL_SRC_FILES := $(LIBDRM_INTEL_FILES)
 
 LOCAL_SHARED_LIBRARIES := \
 	libdrm \
 	libpciaccess
 
+include $(LIBDRM_COMMON_MK)
 include $(BUILD_SHARED_LIBRARY)
diff --git a/libkms/Android.mk b/libkms/Android.mk
index 0259ffb..0be7205 100644
--- a/libkms/Android.mk
+++ b/libkms/Android.mk
@@ -26,7 +26,7 @@
 include $(CLEAR_VARS)
 include $(LOCAL_PATH)/Makefile.sources
 
-LOCAL_SRC_FILES := $(patsubst %.h, , $(LIBKMS_FILES))
+LOCAL_SRC_FILES := $(LIBKMS_FILES)
 
 ifneq ($(filter $(vmwgfx_drivers), $(DRM_GPU_DRIVERS)),)
 LOCAL_SRC_FILES += $(LIBKMS_VMWGFX_FILES)
@@ -47,6 +47,5 @@
 LOCAL_MODULE := libkms
 LOCAL_SHARED_LIBRARIES := libdrm
 
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-
+include $(LIBDRM_COMMON_MK)
 include $(BUILD_SHARED_LIBRARY)
diff --git a/nouveau/Android.mk b/nouveau/Android.mk
index 451f9a7..b430af4 100644
--- a/nouveau/Android.mk
+++ b/nouveau/Android.mk
@@ -8,10 +8,7 @@
 
 LOCAL_SHARED_LIBRARIES := libdrm
 
-LOCAL_SRC_FILES := $(patsubst %.h, , $(LIBDRM_NOUVEAU_FILES))
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
+LOCAL_SRC_FILES := $(LIBDRM_NOUVEAU_FILES)
 
-LOCAL_CFLAGS := \
-	-DHAVE_LIBDRM_ATOMIC_PRIMITIVES=1
-
+include $(LIBDRM_COMMON_MK)
 include $(BUILD_SHARED_LIBRARY)
diff --git a/radeon/Android.mk b/radeon/Android.mk
index 57cbc92..71040da 100644
--- a/radeon/Android.mk
+++ b/radeon/Android.mk
@@ -8,10 +8,7 @@
 
 LOCAL_SHARED_LIBRARIES := libdrm
 
-LOCAL_SRC_FILES := $(patsubst %.h, , $(LIBDRM_RADEON_FILES))
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
+LOCAL_SRC_FILES := $(LIBDRM_RADEON_FILES)
 
-LOCAL_CFLAGS := \
-	-DHAVE_LIBDRM_ATOMIC_PRIMITIVES=1
-
+include $(LIBDRM_COMMON_MK)
 include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/modetest/Android.mk b/tests/modetest/Android.mk
index 6a7f406..c1a71fd 100644
--- a/tests/modetest/Android.mk
+++ b/tests/modetest/Android.mk
@@ -3,11 +3,12 @@
 include $(CLEAR_VARS)
 include $(LOCAL_PATH)/Makefile.sources
 
-LOCAL_SRC_FILES := $(patsubst %.h, , $(MODETEST_FILES))
+LOCAL_SRC_FILES := $(MODETEST_FILES)
 
 LOCAL_MODULE := modetest
 
 LOCAL_SHARED_LIBRARIES := libdrm
 LOCAL_STATIC_LIBRARIES := libdrm_util
 
+include $(LIBDRM_COMMON_MK)
 include $(BUILD_EXECUTABLE)
diff --git a/tests/proptest/Android.mk b/tests/proptest/Android.mk
index badeb58..91a590f 100644
--- a/tests/proptest/Android.mk
+++ b/tests/proptest/Android.mk
@@ -3,11 +3,12 @@
 include $(CLEAR_VARS)
 include $(LOCAL_PATH)/Makefile.sources
 
-LOCAL_SRC_FILES := $(patsubst %.h, , $(PROPTEST_FILES))
+LOCAL_SRC_FILES := $(PROPTEST_FILES)
 
 LOCAL_MODULE := proptest
 
 LOCAL_SHARED_LIBRARIES := libdrm
 LOCAL_STATIC_LIBRARIES := libdrm_util
 
+include $(LIBDRM_COMMON_MK)
 include $(BUILD_EXECUTABLE)
diff --git a/tests/util/Android.mk b/tests/util/Android.mk
index c9d087e..7656c4c 100644
--- a/tests/util/Android.mk
+++ b/tests/util/Android.mk
@@ -30,9 +30,7 @@
 
 LOCAL_SHARED_LIBRARIES := libdrm
 
-LOCAL_SRC_FILES := $(patsubst %.h, , $(UTIL_FILES))
+LOCAL_SRC_FILES := $(UTIL_FILES)
 
-# avoid name clashes by requiring users to include util/*.h
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(dir $(LOCAL_PATH))
-
+include $(LIBDRM_COMMON_MK)
 include $(BUILD_STATIC_LIBRARY)