Linux内核动态模块的Makefile编写

export ARCH=arm
export CROSS_COMPILE=/home/toolchain/usr/bin/arm-buildroot-linux-gnueabihf-  #工具链路径

ifeq ($(KERNELRELEASE),)

KERNELDIR ?= /home/work/linux_source	#内核源码路径

PWD := $(shell pwd)

modules:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
	$(CROSS_COMPILE)gcc -o test.out test.c  #C文件编译

modules_install:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
	
clean:
	rm -rf *.out *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions modules.* Module*

.PHONY: modules modules_install clean

else
	obj-m := hello.o
endif

猜你喜欢

转载自blog.csdn.net/baidu_38410526/article/details/105845580