Understanding Makefile of Linux Device Driver

Following is the Makefile we used in our Hello World Device Driver Program.



Let's try to understand this file

When you run make on the command line, it will execute the following command:

make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

1. C option to change the directory to /lib/modules/$(shell uname -r)/build
2. make will then read the Makefile present in that location 
3. M will specify the location of the source code of the module
4. The kernel Makefile will read our Makefile to find out what to build, we specify that by writing obj-m += hello.o

To understand this reading Makefile again, we can simply have a Makefile with the following content:
obj-m += hello.o

And on the command line run the following command:
$ make -C /lib/modules/$(uname -r)/build M=$(pwd) modules

It will generate the modules for you.

Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

PR, PN and PV Variable in Yocto