Hello World 的makefile模板及其分析

makefile模板:

ifeq ($(KERNELRELEASE),)   //判断KERNELRELEASE是否为空,只有执行make的当前目录为内核源代码目录时,该变量才不为空。

KERNELDIR ?=/linux-2.6.29.4/linux-2.6.29.4

PWD := $(shell pwd)

modules:
     $(MAKE) -C $(KERNELDIR) M=$(PWD) modules  //make -C 内核路径 M=模块路径 modules

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

clean:
     rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions *.order Module*

.PHONY: modules modules_install clean

else
    obj-m := hello.o
endif

makefile文件的执行过程如下:

原文地址:https://www.cnblogs.com/hello2mhb/p/3364089.html