关于kbuild中KERNELRELEASE的疑问

雁子依然 雁子依然 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
有个小问题,关于KERNELRELEASE,我的理解是不是也可以不用去判断这个变量的定义呢?
LDD3里面hello的例子makefile如下



# To build modules outside of the kernel tree, we run "make"
# in the kernel source tree; the Makefile these then includes this
# Makefile once again.
# This conditional selects whether we are being included from the
# kernel Makefile or not.
ifeq ($(KERNELRELEASE),)

# Assume the source tree is where the running kernel was built
# You should set KERNELDIR in the environment if it's elsewhere
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
# The current directory is passed to sub-makes as argument
PWD := $(shell pwd)

modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install

clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

.PHONY: modules modules_install clean

else
# called from kernel build system: just declare what our modules are
obj-m := hello.o hellop.o seq.o jit.o jiq.o sleepy.o complete.o \
silly.o faulty.o kdatasize.o kdataalign.o
endif



我试着把ifeq else endif这三行注释,也可以编译成功,我理解是不是这样:
1. 在模块所在目录执行make,根据makefile规则,会先去找第一个目标modules,执行后面的命令$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

2. 进入kernel目录,kbuild开始工作
3. 根据M=参数,生成模块之前回到当前目录再次读取makefile里面的obj-m

所以是不是说KERNELRELEASE定义与否,效果都是一样的呢

当然有一个例外就是,如果在当前目录下make的时候直接就make KERNELRELEASE=y,那就会编译出错,但是应该不会有人这么做吧,或者说不会出现这样的情况吧?

可以帮住解答一下么?
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部