关于kbuild中KERNELRELEASE的疑问

雁子依然 2013-07-02 02:48:53
有个小问题,关于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,那就会编译出错,但是应该不会有人这么做吧,或者说不会出现这样的情况吧?

可以帮住解答一下么?
...全文
65 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
雁子依然 2013-07-03
  • 打赏
  • 举报
回复
求指点啊,要沉下去了

21,600

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧