在Android环境下独立编译.ko文件,这和在Linux下模块化编译驱动程序相同,Makefile文件写法如下:
ifneq ($(KERNELRELEASE),)
obj-m += KmemleakTest.o
KmemleakTest-objs := kmemleak_test.o
else
KERNELDIR ?= <源码目录>/out/target/product/poplar/obj/KERNEL_OBJ
PWD ?= $(shell pwd)
ARCH = arm64
CROSS_COMPILE=<源码目录>/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-
.PHONY: modules clean
modules:
$(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(PWD) modules
clean:
@rm -rf *.o *.order *.symvers *.mod.* .*.o.cmd .*.mod.o.cmd .*.ko.cmd .tmp_versions *.ko
endif