Makefile

# if not defined KERNELRELEASE, command is running from command line,need invoke kbuild system.

ifeq ($(KERNELRELEASE),)  

  KERNELDIR ?= /linux-2.6.30.4 # the directory of kernel source file  

  PWD := $(shell pwd) # the directory of module source file

modules:  

  $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

modules_install:  

  $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install

clean:  

  rm -rf *.o *~core.depend.*.cmd *.ko *.mod.c.tmp_versions

.PHONY: modules modules_install clean # if defined KERNELRELEASE, kbuild running

else  

  obj-m:= hello.o # the source file of module endif

#################################################################

 

该Makefile 在模块构造过程中一般将被调用两次。使用make 时,第一次 KERNELRELEASE 尚未定义。KERNELDIR 将被定义为内核源码路径,PWD 将被赋值为模块源码文件所在路径。然后通过 $(MAKE) -C $(KERNELDIR) M=$(PWD) modules进入内核源码目录调用顶层Makefile 。顶层Makefile 会通过 M=$(PWD) 获得指定的模块源码所在路径,并调用其下的 Makefile。即该Makefile 将被调用第二次,此时将会执行else 后的语句,通过内核顶层Makefile 构建出模块。

 

相关文章:

  • 2021-06-27
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
猜你喜欢
  • 2022-03-03
  • 2021-12-28
  • 2021-11-23
  • 2021-12-26
  • 2022-02-07
  • 2021-09-18
相关资源
相似解决方案