作业帮 > 综合 > 作业

如何编写makefile

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/28 05:36:17
如何编写makefile
我的一个简单的linux内核模块,包含了,init.h,module.h,sched.h,现要编译,makefile怎么都通不过,
1.请问这个makefile怎么写?
2.以及如果用gcc编译的话应该如何写?
答案如果试了下可行的话追加分哦~
是这样包含的:
#include
#include
#include
1 # To build modules outside of the kernel tree,we run "make"
2 # in the kernel source tree; the Makefile these then includes this
3 # Makefile once again.
4 # This conditional selects whether we are being included from the
5 # kernel Makefile or not.
6 ifeq ($(KERNELRELEASE),)
7
8 # Assume the source tree is where the running kernel was built
9 # You should set KERNELDIR in the environment if it's elsewhere
10 KERNELDIR = /lib/modules/$(shell uname -r)/build
11 # The current directory is passed to sub-makes as argument
12 PWD := $(shell pwd)
13
14 modules:
15 $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
16
17 modules_install:
18 $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
19
20 clean:
21 rm -rf *.o core .depend .*.cmd *.ko *.mod.c .tmp_versions
22
23 .PHONY:modules modules_install clean
24
25 else
26 # called from kernel build system:just declare what our modules are
27 obj-m := hello.o
28 endif
在lwn上可以找到这个例子,你可以把以上两个文件放在你的某个目录下,然后执行make,也许你不一定能成功,因为linux kernel 2.6要求你编译模块之前,必须先在内核源代码目录下执行make,换言之,你必须先配置过内核,执行过make,然后才能make你自己的模块.原因我就不细说了,你按着她要求的这么去做就行了.
另外注意命令前面必须是tab
什么是命令?
类似于这种
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules