Makefile -C 和M选项

下面这段代码摘自奔跑吧Linux

BASEINCLUDE ?= /home/ben/work/runninglinuxkernel_4.0
#BASEINCLUDE ?= /lib/modules/`uname -r`/build

mydemo_misc-objs := mydemodrv_misc.o 

obj-m	:=   mydemo_misc.o
all : 
	$(MAKE) -C $(BASEINCLUDE) M=$(PWD) modules;

clean:
	$(MAKE) -C $(BASEINCLUDE) SUBDIRS=$(PWD) clean;
	rm -f *.ko;

当make的目标为all时,-C ( B A S E I N C L U D E ) 指 明 跳 转 到 内 核 源 码 目 录 下 读 取 那 里 的 M a k e f i l e ; M = (BASEINCLUDE) 指明跳转到内核源码目录下读取那里的Makefile;M= (BASEINCLUDE)MakefileM=(PWD) 表明然后返回到当前 目录继续 读入、执行 当前的Makefile。

经过编译最终会生成mydemo_misc.ko。

另外:
mydemo_misc-objs:=mydemodrv_misc.o 前面的mydemo_misc为编译文件名,应该是固定写法,修改后编译不通过

猜你喜欢

转载自blog.csdn.net/xingzhibo/article/details/109094602
今日推荐