Makefile Linux device drivers

A typical module Makefile as follows;

 1 ifneq ($(KERNELRELEASE),)
 2         obj-m := hello.o
 3 else
 4         KERNELDIR ?=/lib/modules/$(shell uname -r)/build
 5         PWD :=$(shell pwd)
 6 default:
 7         $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
 8 clean:
 9         @rm -rf *.o *.mod.c *.ko *.symvers *.order *.makers
10 endif

 

The Makefile is read twice during construction; perform the following steps:

1. When invoked from the command line Makefile, its attention back KERNELRELEASE has not been set, then execution else's KERNELDIR and PWD settings;

2. The default target is then performed, make the first switch to the specified directory -C KERNELDIR, Makefile performed under that directory, KERNELRELEASE KERNELDIR defined in the Makefile, KERNELRELEASE has been set after the execution;

M = 3 then switch back to the specified directory PWD, PWD second reading execution directory Makefile, this time because KERNELRELEASE has been defined, kbuild also be started to resolve kbuild statement syntax, make reads before else's content, content before else is kbuild syntax of the statement, dependency is indicated in each module source files, as well as to generate the target module name;

The above rules start the real building blocks;

Guess you like

Origin www.cnblogs.com/wanpengcoder/p/11755787.html