本人近期大概浏览了一下GNU makefile手册,对makefile有了一点点了解。但是看Linux2.6.x内核下的makefile文件,想了解下Linux内核编译过程时遇到了一些问题,怎么也不明白。望高手给小弟指教。
1. 编译内核时,首先“make menuconfig”会产生.config配置文件。我要问的是这个文件在哪里?我在内核根目录里没有发现这个文件。
2. 整个内核目录树中,几乎每一个目录中都存在一个makefile文件,他描述该目录下文件的编译规则。由于目录中还存在着子目录,那么执行子目录中的make定会用到makefile的递归调用。问题是并没有用到递归调用,而是简单用一个obj变量的追加。如: 如果ext2是一个子目录,fs目录下的Makefile将使用以下赋值语句使编译系统编译ext2子目录。 obj-$(CONFIG_EXT2_FS) += ext2/ 。我想问的是,这是什么规则?是隐含规则吗?还是Linux内核下makefile文件所独有的特性?
3. 在内核根目录下除了有一个根makefile文件还有一个kbuild文件,这个文件是作什么用的?
linux2.6.x 内核中makefile文件问题,求解!!!
-
- 帖子: 38
- 注册时间: 2007-04-01 17:55
- 来自: 中国大陆
linux2.6.x 内核中makefile文件问题,求解!!!
Anyting is possible!!!
- 543082593
- 帖子: 234
- 注册时间: 2008-11-07 8:41
Re: linux2.6.x 内核中makefile文件问题,求解!!!
同样的问题 我也很困惑 ubuntu刚装完的系统里的内核 是不是不能编译啊 跟楼上的一样 好多makefile
所以我索性从网上下了一个内核源代码包 然后 自己编译
成功了
但是 对 内核里的makefile 还是不太清楚 尤其是 ubuntu /usr/src/ 里的内核文件
所以我索性从网上下了一个内核源代码包 然后 自己编译
成功了
但是 对 内核里的makefile 还是不太清楚 尤其是 ubuntu /usr/src/ 里的内核文件
fall again
smooth criminal
they don't care about us
billie jean
beat it
dangerous
the lost children
childhood
ben
i will be there
speechless
she is out of my life
rock with you
...
LOVE U FOREVER
smooth criminal
they don't care about us
billie jean
beat it
dangerous
the lost children
childhood
ben
i will be there
speechless
she is out of my life
rock with you
...
LOVE U FOREVER
- microtiger
- 帖子: 27
- 注册时间: 2006-09-14 10:57
- 来自: http://szmicrotiger.blogspot.com/
Re: linux2.6.x 内核中makefile文件问题,求解!!!
1、.config配置文件是隐藏文件,使用#ls -al即可看到;
2、编译的时候是Makefile和Kconfig两个文件共同起作用的结果,最好结合起来看!要想选择某一个内核功能就要用到Kconfig文件,要想使用这个功能就要用到Makefile编译之;
3、至于kbuild麻烦请看linux/documents/kbuild目录下文件。
2、编译的时候是Makefile和Kconfig两个文件共同起作用的结果,最好结合起来看!要想选择某一个内核功能就要用到Kconfig文件,要想使用这个功能就要用到Makefile编译之;
3、至于kbuild麻烦请看linux/documents/kbuild目录下文件。
I want to be a complete engineer:technical genius and sensitive humanist all in one!
- xhy
- 帖子: 3916
- 注册时间: 2005-12-28 1:16
- 系统: Ubuntu 12.10 X64
- 来自: 火星
- microtiger
- 帖子: 27
- 注册时间: 2006-09-14 10:57
- 来自: http://szmicrotiger.blogspot.com/
Re: linux2.6.x 内核中makefile文件问题,求解!!!
2.6的内核使用Kbuild来编译内核模块。Kbuild能够编译内核树目录内的内核模块,也能够编译内核树目录外的内核模块(外部内核模块)。2.6内核和2.4内核差别太大,重新理清概念学习吧!
.编译外部内核模块的命令:
#cd <your-module-dir>
#make -C <path-to-kernel> M=`pwd`
其中<your-module-dir>为要编译的内核模块所在目录,<path-to-kernel> 为内核源码所在的目录。
对于发行版本的Linux,可以用:
#make -C /lib/modules/`uname -r`/build M=`pwd`
注意:使用Kbuild之前,必须先成功编译过内核源码。
说明:
.#make -C <path-to-kernel> M=`pwd` modules
作用与上面的命令一样
.以前的内核版本可以使用
#make -C <path-to-kernel> SUBDIRS=`pwd` modules
.安装外部内核模块
#make -C <path-to-kernel> M=`pwd` modules_install
默认安装目录为:/lib/modules/`uname -r`/extra,可以通过INSTALL_MOD_PATH宏在默认安装路径前加前缀。
例如:
#make -C <path-to-kernel> INSTALL_MOD_PATH=/opt M=`pwd` modules_install
则编译后的模块会放在/opt/lib/modules/`uname -r`/extra
通过宏INSTALL_MOD_DIR可以修改是否放在'extra'下,例如:
#make -C <path-to-kernel> INSTALL_MOD_DIR=golf M=`pwd` modules_install
则编译后的模块会放在/lib/modules/`uname -r`/golf
.编译单个文件
#make -C <path-to-kernel> M=`pwd` <filename>
.其他命令
#make -C <path-to-kernel> M=`pwd` clean
#make -C <path-to-kernel> M=`pwd` help
.Kbuild文件
Linux的Kbuild会在内核模块目录下查找Kbuild文件,如果有,则在编译时会使用该文件。
示例:
假设有这么几个文件:8123_if.c 8123_if.h 8123_pci.c 8123_bin.o_shipped(二进制的模块文件)
Kbuild文件的内容:
obj-m := 8123.o
8123-y:8123_if.o 8123_pci.o 8123_bin.o
Makefile的内容:
#为了兼容旧版本的Kbuild
ifneq($(KERNELRELEASE),)
include Kbuild
else
#正常的Makefile
KDIR:=/lib/modules/`uname -r`/build
all::
$(MAKE) -C $(KDIR) M=`pwd` $@
#其他target
genbin:
echo "X" > 8123_bin_shipped
endif
注意,没有源码的二进制.o文件必须以原文件名加_shipped结尾,例如8123_bin.o_shipped,KBuild会把8123_bin.o_shipped
复制为8123_bin.o,然后一起编译。
.Makefile中如何包括自己的include文件
由于采用Kbuild编译外部内核模块时,编译路径切换到了内核源码树的目录,因此如果在Makefile中使用相对路径来包含另一个文件
时,会找不到该文件。因此,不能用
include ../config.mk
应该用:
ifeq ($(obj),)
obj= .
endif
include $(obj)/../config.mk
.编译外部内核模块的命令:
#cd <your-module-dir>
#make -C <path-to-kernel> M=`pwd`
其中<your-module-dir>为要编译的内核模块所在目录,<path-to-kernel> 为内核源码所在的目录。
对于发行版本的Linux,可以用:
#make -C /lib/modules/`uname -r`/build M=`pwd`
注意:使用Kbuild之前,必须先成功编译过内核源码。
说明:
.#make -C <path-to-kernel> M=`pwd` modules
作用与上面的命令一样
.以前的内核版本可以使用
#make -C <path-to-kernel> SUBDIRS=`pwd` modules
.安装外部内核模块
#make -C <path-to-kernel> M=`pwd` modules_install
默认安装目录为:/lib/modules/`uname -r`/extra,可以通过INSTALL_MOD_PATH宏在默认安装路径前加前缀。
例如:
#make -C <path-to-kernel> INSTALL_MOD_PATH=/opt M=`pwd` modules_install
则编译后的模块会放在/opt/lib/modules/`uname -r`/extra
通过宏INSTALL_MOD_DIR可以修改是否放在'extra'下,例如:
#make -C <path-to-kernel> INSTALL_MOD_DIR=golf M=`pwd` modules_install
则编译后的模块会放在/lib/modules/`uname -r`/golf
.编译单个文件
#make -C <path-to-kernel> M=`pwd` <filename>
.其他命令
#make -C <path-to-kernel> M=`pwd` clean
#make -C <path-to-kernel> M=`pwd` help
.Kbuild文件
Linux的Kbuild会在内核模块目录下查找Kbuild文件,如果有,则在编译时会使用该文件。
示例:
假设有这么几个文件:8123_if.c 8123_if.h 8123_pci.c 8123_bin.o_shipped(二进制的模块文件)
Kbuild文件的内容:
obj-m := 8123.o
8123-y:8123_if.o 8123_pci.o 8123_bin.o
Makefile的内容:
#为了兼容旧版本的Kbuild
ifneq($(KERNELRELEASE),)
include Kbuild
else
#正常的Makefile
KDIR:=/lib/modules/`uname -r`/build
all::
$(MAKE) -C $(KDIR) M=`pwd` $@
#其他target
genbin:
echo "X" > 8123_bin_shipped
endif
注意,没有源码的二进制.o文件必须以原文件名加_shipped结尾,例如8123_bin.o_shipped,KBuild会把8123_bin.o_shipped
复制为8123_bin.o,然后一起编译。
.Makefile中如何包括自己的include文件
由于采用Kbuild编译外部内核模块时,编译路径切换到了内核源码树的目录,因此如果在Makefile中使用相对路径来包含另一个文件
时,会找不到该文件。因此,不能用
include ../config.mk
应该用:
ifeq ($(obj),)
obj= .
endif
include $(obj)/../config.mk
-
- 帖子: 38
- 注册时间: 2007-04-01 17:55
- 来自: 中国大陆
-
- 帖子: 38
- 注册时间: 2007-04-01 17:55
- 来自: 中国大陆
Re: linux2.6.x 内核中makefile文件问题,求解!!!
你是说2.6内核的makefile是通过autotools自动的吗?xhy 写了:makefile是自动生成的
能详细说说吗?
Anyting is possible!!!