当前位置: 技术问答>linux和unix
最简单的模块makefile
来源: 互联网 发布时间:2016-12-21
本文导语: # If KERNELRELEASE is defined, we've been invoked from the # kernel build system and can use its language. ifneq ($(KERNELRELEASE),) obj-m := hello.o # Otherwise we were called directly from the command # line; invoke the kernel build system. else KERNELDIR ?= /...
# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
书上说这个makefile会被调用两次,为什么呢?
高手可否详细说一下
|
可以参考
http://yijiuzai.blog.163.com/blog/static/1037567272010101883750636/
http://blog.sina.com.cn/s/blog_602f87700100dq1u.html
|
解释:
KERNELRELEASE:由Kernel顶层Makefile中定义。
第一次运行中,KERNELRELEASE没有被定义,所以进入else
$(MAKE) -C $(KERNELDIR) M=$(PWD)
此处读取KERNELDIR中的顶层Makefile。读取后又返回本目录。继续执行本目录Makefile。
则此时KERNELRELEASE被定义。进入if.
if和else之间的为kbuild语法的语句.
KERNELRELEASE:由Kernel顶层Makefile中定义。
第一次运行中,KERNELRELEASE没有被定义,所以进入else
$(MAKE) -C $(KERNELDIR) M=$(PWD)
此处读取KERNELDIR中的顶层Makefile。读取后又返回本目录。继续执行本目录Makefile。
则此时KERNELRELEASE被定义。进入if.
if和else之间的为kbuild语法的语句.