关于kernel module的makefile

cjhacker 2009-03-07 06:05:09
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
这句话是什么意思?为什么要先cd KERNELDIR,编译器去那里做什么工作?
希望有人能够详细解答,谢谢!
...全文
909 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
独孤过儿 2009-03-26
  • 打赏
  • 举报
回复
你需要先check一下Makefile裏面,關於編譯器的定義,linux的內核是支持多種架構的,自然也能生成針對于特定

架構的binary file,包括ARM的。只是這個check的過程比較複雜。

又或者可能是寫在configure的script裏面,然後在./configure的時候會自動判定硬件的架構,make的時候可以

根據特定的硬件,選擇特定的target了

你的問題描述的信息少了點,具體的情形我也判斷不出來,你需要提供更多的信息
ling1874 2009-03-26
  • 打赏
  • 举报
回复
太 感谢 fetag大了
顺便再问一句
make −C /lib/modules/$(shell uname −r)/build M=$(PWD) modules
这句的确是对的
但是整个make中并没有提及要用arm-linux-gcc编译,但是生成的文件的确是 arm系统的
难道是到内核目录的时候用到的??
xgfhahaha 2009-03-26
  • 打赏
  • 举报
回复
fetag完美正解、、、
^_^
独孤过儿 2009-03-25
  • 打赏
  • 举报
回复
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

1、所有$(*)這種形式的,都表示一個变量,而用$()就是取得这个变量的值。比如,如果定义了MAKE="make",那

么$(MAKE)就可以替换为make了。而KERNELDIR这个是系统默认定义的,指的是系统的内核头文件目录,通常在

/usr/src/下面。$(PWD)也是系统默认的命令pwd

2、-C 是切换目录的意思,是切换到内核头文件目录里面去,执行那下面的Makefile,这是Makefile的递归调用性。

3、moudles是编译模块的意思。至于为什么要内核头文件目录,可以参考7楼老兵的回答。

4、顺便回答一下八楼的问题:“system.map”,这个确实是调试时候用的,而且是调试内核crash的时候的,

linux下有个工具叫crash,就是用来调试内核crash的。而system.map里面保存的是内核函数的一些类似于标签

的信息,调试内核的时候,用这些信息对应crash的地方大概在源代码中的位置。

5、貌似楼主这个命令写错了吧?驱动通常的这一行是这样写的啊:

make −C /lib/modules/$(shell uname −r)/build M=$(PWD) modules
ling1874 2009-03-25
  • 打赏
  • 举报
回复
正在研究这个 问题 呢
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
有一点不明白就是 后面为什么带上modules??
make的时候总是报错说 不存在此文件
bxhzct 2009-03-20
  • 打赏
  • 举报
回复
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
KERNELDIR跟MAKE应该都是你主makefile里定义好的环境变量.
把该makefile同目录下的 modules 给到M,执行make指令

同意此观点
c++plus 2009-03-19
  • 打赏
  • 举报
回复
makefile里指定目录吧
softwarewander 2009-03-11
  • 打赏
  • 举报
回复
mingtianhui
  • 打赏
  • 举报
回复
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
KERNELDIR跟MAKE应该都是你主makefile里定义好的环境变量.
把该makefile同目录下的 modules 给到M,执行make指令.
cjhacker 2009-03-09
  • 打赏
  • 举报
回复
up........
joyself 2009-03-09
  • 打赏
  • 举报
回复
ldd3rd 有说一些,你可以看看2.4

# 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


Once again, we are seeing the extended GNU make syntax in action. This makefile is read twice on a typical build. When the makefile is invoked from the command line, it notices that the KERNELRELEASE variable has not been set. It locates the kernel source directory by taking advantage of the fact that the symbolic link build in the installed modules directory points back at the kernel build tree. If you are not actually running the kernel that you are building for, you can supply a KERNELDIR= option on the command line, set the KERNELDIR environment variable, or rewrite the line that sets KERNELDIR in the makefile. Once the kernel source tree has been found, the makefile invokes the default: target, which runs a second make command (parameterized in the makefile as $(MAKE)) to invoke the kernel build system as described previously. On the second reading, the makefile sets obj-m, and the kernel makefiles take care of actually building the module.
cjhacker 2009-03-09
  • 打赏
  • 举报
回复
我怎么看书上说不用system.map,这个只是调试工具用的
hefuhua 2009-03-09
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 cjhacker 的回复:]
为什么要去Kerneldir溜达一圈?
[/Quote]

驱动编译成模块,其实也是内核的一个部分,那么编译前就必须找到相应的内核版本及其相应的关系,如相关的头文件和System.map函数分配地址.
cjhacker 2009-03-09
  • 打赏
  • 举报
回复
为什么要去Kerneldir溜达一圈?
Goolin 2009-03-09
  • 打赏
  • 举报
回复
-C $(KERNELDIR) -C 用来改变make的执行目录,即在KERNELDIR(内核源码目录)下找到顶层的makefile
M=$(PWD) modules 这个是使makefile在试图生成模块之前,回到模块源码目录,
cjhacker 2009-03-09
  • 打赏
  • 举报
回复
把该makefile同目录下的 modules 给到M
这是什么意思?
erigido 2009-03-09
  • 打赏
  • 举报
回复
楼上正解
前面应该有一个类似的环境变量设置:
KERNELDIR := /lib/modules/2.6.23.1-42.fc8/build

4,436

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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