diff mbox

[RFC,v2] greybus: Changes required for integrating into the Android build

Message ID 1412911635-6014-1-git-send-email-john.stultz@linaro.org
State New
Headers show

Commit Message

John Stultz Oct. 10, 2014, 3:27 a.m. UTC
In order to easily integrate into the Android build, include
an Android.mk and some extra conditionals in the Makefile
to get the proper kerneldir.

Signed-off-by: John Stultz <john.stultz@linaro.org>
---

v2: 
Some cleanups suggested by Rob and Greg. Unfortunately the
resulting module here still doesn't load, due to a
reallocation issue, but I'll continue looking at that
tomorrow and hopefully have something to officially submit
then.

 Android.mk | 28 ++++++++++++++++++++++++++++
 Makefile   |  8 +++++---
 2 files changed, 33 insertions(+), 3 deletions(-)
 create mode 100644 Android.mk
diff mbox

Patch

diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..189ca0c
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,28 @@ 
+.PHONY: build-greybus
+
+$(PRODUCT_OUT)/ramdisk.img: build-greybus
+
+include $(CLEAR_VARS)
+GREYBUS_SRC_PATH := $(ANDROID_BUILD_TOP)/external/greybus/
+LOCAL_PATH := $(GREYBUS_SRC_PATH)
+LOCAL_SRC_FILES := greybus.ko
+LOCAL_MODULE := $(LOCAL_SRC_FILES)
+LOCAL_MODULE_CLASS := EXECUTABLES
+LOCAL_MODULE_PATH := $(PRODUCT_OUT)/root/lib/modules
+$(LOCAL_PATH)/$(LOCAL_SRC_FILES): build-greybus
+include $(BUILD_PREBUILT)
+
+KDIRARG := KERNELDIR="${ANDROID_PRODUCT_OUT}/obj/kernel"
+ifneq ($(ANDROID_64),)
+  ARCHARG := ARCHLINE="ARCH=arm64"
+else
+  ARCHARG := ARCHLINE="ARCH=arm"
+endif
+ARGS := $(KDIRARG) $(ARCHARG)
+
+build-greybus: android_kernel
+	make clean -C $(GREYBUS_SRC_PATH)
+	cd $(GREYBUS_SRC_PATH) &&\
+	$(MAKE) -j$(MAKE_JOBS) CROSS_COMPILE=$(KERNEL_TOOLS_PREFIX) $(ARGS)
+	mkdir -p $(PRODUCT_OUT)/root/lib/modules
+	cp $(GREYBUS_SRC_PATH)/greybus.ko $(PRODUCT_OUT)/root/lib/modules
diff --git a/Makefile b/Makefile
index 42a3944..5edd297 100644
--- a/Makefile
+++ b/Makefile
@@ -18,17 +18,19 @@  obj-m += greybus.o
 obj-m += es1-ap-usb.o
 obj-m += test_sink.o
 
+ifeq ($(KERNELDIR), )
 KERNELVER		?= $(shell uname -r)
 KERNELDIR 		?= /lib/modules/$(KERNELVER)/build
+endif
 PWD			:= $(shell pwd)
 
 all: module
 
 module:
-	$(MAKE) -C $(KERNELDIR) M=$(PWD)
+	$(MAKE) -C $(KERNELDIR) M=$(PWD) $(ARCHLINE)
 
 check:
-	$(MAKE) -C $(KERNELDIR) M=$(PWD) C=2 CF="-D__CHECK_ENDIAN__"
+	$(MAKE) -C $(KERNELDIR) M=$(PWD) C=2 CF="-D__CHECK_ENDIAN__" $(ARCHLINE)
 
 clean:
 	rm -f *.o *~ core .depend .*.cmd *.ko *.mod.c
@@ -36,5 +38,5 @@  clean:
 	rm -rf .tmp_versions Modules.symvers
 
 coccicheck:
-	$(MAKE) -C $(KERNELDIR) M=$(PWD) coccicheck
+	$(MAKE) -C $(KERNELDIR) M=$(PWD) $(ARCHLINE) coccicheck