免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1422 | 回复: 0
打印 上一主题 下一主题

如何修改Makefile和Kconfig [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-05-31 19:21 |只看该作者 |倒序浏览

参考《linux设备驱动开发详解》
在./drivers目录下新增为ARM体系结构编写test驱动程序,树形结构为:
|-- test
    |-- cpu
    |   `-- cpu.c
    |-- test.c
    |-- test_client.c
    |-- test_ioctl.c
    |-- test_proc.c
    `-- test_queue.c
1、修改需要使用test驱动的目录下的Kconfig
在 arch/arm/Kconfig 增加下面内容
[color="#ff0000"]source "drivers/test/Kconfig"

2、修改test父目录下的Makefile
在./drivers/Makefile 增加下面内容
[color="#ff0000"]obj-$(CONFIG_TEST) +=test/
3、新增test目录下的Kconfig
[color="#ff0000"]##########################
# TEST driver configurations
##########################
[color="#ff0000"]menu "TEST Driver"
comment "TEST Driver"
config CONFIG_TEST
      bool "TEST support"
config CONFIG_TEST_USER
      tristate "TEST usr-space interface"
      depend on CONFIG_TEST
endmenu
4、在test目录下新增Makefile
[color="#ff0000"]#drivers/test/Makefile
#
# Makefile for the TEST
#
obj-$(CONFIG_TEST) += test.o test_queue.o test_client.o
obj-$(CONFIG_TEST_USER) += test_ioctl.o
obj-$(CONFIG_PROC_FS) += test_proc.o
obj-$(CONFIG_TEST_CPU) += cpu/
5、在cpu子目录下新增Makefile
[color="#ff0000"]# Makefile for the TEST CPU
#
obj-$(CONFIG_TEST_CPU) += cpu.o

至此Konfig和Makefile 修改完成
Documentation/kbuild/makefiles.txt
=== 3 The kbuild files
Most Makefiles within the kernel are kbuild Makefiles that use the
kbuild infrastructure. This chapter introduces the syntax used in the
kbuild makefiles.
The preferred name for the kbuild files are 'Makefile' but 'Kbuild' can
be used and if both a 'Makefile' and a 'Kbuild' file exists, then the 'Kbuild'
file will be used.
Section 3.1 "Goal definitions" is a quick intro, further chapters provide
more details, with real examples.
--- 3.1 Goal definitions
Goal definitions are the main part (heart) of the kbuild Makefile.
These lines define the files to be built, any special compilation
options, and any subdirectories to be entered recursively.
The most simple kbuild makefile contains one line:
Example:
  obj-y += foo.o
This tells kbuild that there is one object in that directory, named
foo.o. foo.o will be built from foo.c or foo.S.
If foo.o shall be built as a module, the variable obj-m is used.
Therefore the following pattern is often used:
Example:
  obj-$(CONFIG_FOO) += foo.o
$(CONFIG_FOO) evaluates to either [color="#ff0000"]y (for built-in) or m (for module).
If CONFIG_FOO is neither y nor m, then the file will not be compiled
nor linked.
--- 3.2 Built-in object goals - obj-y
The kbuild Makefile specifies object files for vmlinux
in the[color="#ff0000"] $(obj-y) lists.  These lists depend on the kernel
configuration.
Kbuild compiles all the $(obj-y) files.  It then calls
[color="#ff0000"]"$(LD) -r" to merge these files into one [color="#ff0000"]built-in.o file.
built-in.o is later linked into [color="#ff0000"]vmlinux by the parent Makefile.
The order of files in $(obj-y) is significant.  Duplicates in
the lists are allowed: the first instance will be linked into
built-in.o and succeeding instances will be ignored.
Link order is significant, because certain functions
(module_init() / __initcall) will be called during boot in the
order they appear. So keep in mind that changing the link
order may e.g. change the order in which your SCSI
controllers are detected, and thus your disks are renumbered.
--- 3.3 Loadable module goals - obj-m
[color="#ff0000"]$(obj-m) specify object files which are built as loadable
kernel modules.
A module may be built from one source file or several source
files. In the case of one source file, the kbuild makefile
simply adds the file to $(obj-m).
Example:
  #drivers/isdn/i4l/Makefile
  obj-$(CONFIG_ISDN_PPP_BSDCOMP) += isdn_bsdcomp.o
Note: In this example $(CONFIG_ISDN_PPP_BSDCOMP) evaluates to 'm'
If a kernel module is built from several source files, you specify
that you want to build a module in the same way as above.
Kbuild needs to know which the parts that you want to build your
module from, so you have to tell it by setting an
[color="#ff0000"]$(-objs) variable.
Example:
  #drivers/isdn/i4l/Makefile
  obj-$(CONFIG_ISDN) += isdn.o
  isdn-objs := isdn_net_lib.o isdn_v110.o isdn_common.o
In this example, the module name will be isdn.o. Kbuild will
compile the objects listed in $(isdn-objs) and then run
"$(LD) -r" on the list of these files to generate isdn.o.
Kbuild recognises objects used for composite objects by the suffix
-objs, and the suffix -y. This allows the Makefiles to use
the value of a [color="#ff0000"]CONFIG_ symbol to determine if an object is part
of a composite object.
Example:
  #fs/ext2/Makefile
         obj-$(CONFIG_EXT2_FS)        += ext2.o
  ext2-y                       := balloc.o bitmap.o
         ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o
In this example, xattr.o is only part of the composite object
ext2.o if $(CONFIG_EXT2_FS_XATTR) evaluates to 'y'.
Note: Of course, when you are building objects into the kernel,
the syntax above will also work. So, if you have CONFIG_EXT2_FS=y,
kbuild will build an ext2.o file for you out of the individual
parts and then link this into built-in.o, as you would expect.
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/58463/showart_1950656.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP