从linux内核2.6开始,内核编译采用Kbuild系统。在内核里面,Makefile分为三种,一种是kernel Makefile,一种是Kbuild Makefile,一种是ARCH Makefile。
Kbuild Makefile主要指明哪些代码编译进内核,哪些代码编译进模块。下面是linux-3.7-rc2版的最新内核中btrfs文件夹下面的Makefile,我做一下注解,有利于理Kbuid Makefile的语法。
obj-$(CONFIG_BTRFS_FS) := btrfs.o
#等号右边表示该模块为btrfs模块。
#obj-表示如何编译。obj-y表示btrfs模块将被编译进内核,-m表示编译成模块,-n表示不编译。
#如果CONFIG_BTRFS_FS被配置为y,则btrfs模块被编译进内核。
#(我所见的其他文件系统这里用得是+=)
btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \
file-item.o inode-item.o inode-map.o disk-io.o \
transaction.o inode.o file.o tree-defrag.o \
extent_map.o sysfs.o struct-funcs.o xattr.o ordered-data.o \
extent