您的位置:首页 > 运维架构 > Linux

常用的Linux内核模块的Makefile模板

2010-01-02 13:14 330 查看
经常会写一些Kernel Module,项目中Module的Makefile由于各种依赖比较复杂,因此就写了个简单的Makefile模板,方便每次Copy&Paste。

以下就是Linux 2.6下的内核模块Makefile模板:

KERNEL_DIR := /usr/src/linux-2.6.18.x86_64
#if build for a running kernel
#KERNEL_DIR := /lib/modules/`uname -r`/build

#depends on your platform
ARCH=x86_64

PWD := $(shell pwd)

#for module specific flags, such -I/include/dir...
EXTRA_CFLAGS +=
EXTRA_LDFLAGS +=

#
#modules and objects definition
#
obj-m := mymodule.o
mymodule-y := uaccess.o init.o # xxx.o ...
#for subdirectories
mymodule-y += ./subdir/xxx.o
#

all:
$(MAKE) -C $(KERNEL_DIR) M=$(PWD) ARCH=$(ARCH) modules

help:
@echo "My module description here"
$(MAKE) -C $(KERNEL_DIR) M=$(PWD) ARCH=$(ARCH) help

#customize the install directory with INSTALL_MOD_PATH and INSTALL_MOD_DIR
#or the default /lib/modules/$(KERNELRELEASE)/extra
#install:
#	$(MAKE) -C $(KERNEL_DIR) M=$(PWD) ARCH=$(ARCH) modules_install

clean:
$(MAKE) -C $(KERNEL_DIR) M=$(PWD) ARCH=$(ARCH) clean


通常使用时只要修改其中"modules and objects definition"就好。
其实可以将obj-m的定义放到单独的kbuild文件中,但为了不多出一个文件就放到了一起。

更多高级选项和用法可以参考linuxsrc/Documentation/kbuild/*.txt。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: