xdwjack 发表于 2003-5-27 17:07:13

关于写Makefile

我在topdir/security/下面建了一个jack文件夹,即topdir/security/jack
在该文件夹下面有a.c ,b.c,b.h
a.c中的函数调用了b.c中实现的函数
a.h放在了topdir/include/linux/下面
security下面的一个文件dummy.c调用了a.c,包含了<linux/a.h>

我想把我建的jack文件夹中的东西编译到内核中,所以需要自己写Makefile文件
我参考了其他文件夹中的Makefile文件,写出了如下的代码.

O_TARGET := jack.o

obj-y := a.o b.o

include $(TOPDIR)/Rules.make

在security中的Makefile中的obj-y中加入jack/jack.o

我对Makefile了解的不好,而且我阅读了有关Makefile的很多文章,但是没有指导内核的.好像内核的Makefile的实现和通常的还不太一样.

我编译内核的时候提示 cannot open jack/jack.o No such file or directory

请高手指点,谢谢!

Dragonfly 发表于 2003-5-27 22:50:28

see this one /usr/src/linux/Documentation/kbuild/makefiles.txt

"在security中的Makefile中的obj-y中加入jack/jack.o " this is wrong.
see drivers/block/Makefile how to include the paride
subdir-$(CONFIG_PARIDE) += paride
and see the makefile under paride subdir.

xdwjack 发表于 2003-5-28 10:24:10

perfect! Thank you very much.i will try my best to study it!

Dragonfly 发表于 2003-5-28 10:35:57

welcome. if u learn some, try to post u notes here, that is the best way to say thank to anybody here.
:-D:-D:-D

xdwjack 发表于 2003-5-28 20:35:15

以下是我的体会,如果有错的地方,希望高手指正.

实际上,内核中Makefile有5个部分
1)Makefile: top Makefile,就是源代码文件夹根目录中的
2).config:和1)在同一个目录下,是make menuconfig的时候产生的.里面都是CONFIG_*_*是否被设置了的情况.
3)arch/*/makefile
4)子目录中的makefile
5)Rules.make:提供所有子目录中的makefile共同使用的规则
========================================================================================
可以通过make menuconfig配置的项目,都是可选的,用户或者选择直接编译到内核中,或者作为可装载模块来编译.总而言之是和CONFIG_相关的.

这样在top makefile中就会有DRIVERS-$(CONFIG_*_*)+= *.O这样的语句,也就是说,如果配置了CONFIG_*_*,就要将*.o编进去.

同样的道理,在drivers/block/Makefile中有语句subdir-$(CONFIG_PARIDE)+=paride说明只要配置了paride ,就要深入到paride目录中去.

在drivers/block/paride/Makefile中有语句obj-$(CONFIG_PARIDE)+=paride.o和L_TARGET=paride.a也就是说如果配置了paride,就将paride.o编译到paride.a中.

在topdir/Makefile中有语句DRIVERS-$(CONFIG_PARIDE)+= drivers/block/paride/paride.a说明如果配置了paride,就使用paride.a作驱动.

============================================================================================
如果要加入内核的东西是一定要编译到内核中的,是没有权力通过make menuconfig来选择的,那么就要在top makefile中的CORE_FILES=.....中加入需要编译到内核的东西,比如我这里就是security/vmlinux-obj.o,这个东西是打入lsm包之后自动加上的.
我在上面的最初的贴子中建立的文件夹security/jack.我可以在security/Makefile中写入subdir-y=jack标明无论如何都要访问文件夹,和obj-y := .........jack/jack.o标明jack.o是必须要编译到vmlinux-obj.o中的东西.

在jack/Makefile中还是原来那样写

O_TARGET := jack.o
obj-y := a.o b.o
include $(TOPDIR)/Rules.make
就可以了

Dragonfly 发表于 2003-5-28 21:30:27

u can further modify the COnfig.in to include u code as an option as well.

xdwjack 发表于 2003-5-29 17:47:40

我学习了Config.in的相关知识,感觉不错,不过有一个问题:

make menuconfig之后首先出现的第一个界面是如何形成的,读的是什么文件,是根据什么来决定哪个菜单放在第一层,放置的顺序是如何决定的?使用哪个Config.in都是在别的Config.in中用source指定的吗?最上层的Config.in文件在什么地方?

谢谢!

Dragonfly 发表于 2003-5-29 21:38:36

dragonfly linux # make menuconfig
rm -f include/asm
( cd include ; ln -sf asm-i386 asm)
make -C scripts/lxdialog all
make: Entering directory `/usr/src/linux-2.4.20/scripts/lxdialog'
make: Leaving directory `/usr/src/linux-2.4.20/scripts/lxdialog'
/bin/sh scripts/Menuconfig arch/i386/config.in
Using defaults found in .config
Preparing scripts: functions, parsing.........................................................................done.

------------------------------------
so the interface is lxdialog, the first interface is arch/i386/config.in
页: [1]
查看完整版本: 关于写Makefile