0
votes

include

#include<linux/module.h>
#include<linux/init.h>

int my_init(void){
        printk("<1> Angus : Module Insertion is successful!");
        return 0;
}

void my_cleanup(void){
        printk("<1> Angus : Module unloading successful!");
}

module_init(my_init);
module_cleanup(my_cleanup);

Makefile :

obj-m:=simple.o
aoll:
        make -C /usr/src/linux-headers-3.2.0-25-generic-pae/ M=$(PWD) modules
clean:

        make -C /usr/src/linux-headers-3.2.0-25-generic-pae/ M=$(PWD) clean

make -C => will change to the directory before doing a make, In this path /usr/src/linux-headers-3.2.0-25-generic-pae/ I have Makefile , why is the M=$(PWD) needed ? what does it do, where I can check for $PWD ? The Makefile inside the /usr/src/linux-headers-3.2.0-25-generic-pae/ has the target all:modules and target modules and has the target clean. What is obj-m ?

3

3 Answers

2
votes

You'd better to read the paragraph at page 24 of the book Linux Device Drivers, 3rd edition (freely available at http://oreilly.com/openbook/linuxdrive3/book/index.html).

The -C option makes it change the directory to the one provided. There, it finds the kernel's top-level Makefile. Then, the M= option causes that Makefile to move back to your module source directory before trying to build the modules target ($PWD is a variable containing the path of your current directory).

obj-m is a variable containing the list of kernel modules to be build (see https://www.kernel.org/doc/Documentation/kbuild/makefiles.txt) .

1
votes

why is the M=$(PWD) needed ?

The M= option causes that makefile to move back into your module source directory before trying to build the modules target. This target, in turn, refers to the list of modules found in the obj-m variable.

What is obj-m ?

The assignment above states that there is one module to be built from the object file hello.o. The resulting module is named hello.ko after being built from the object file.

1
votes

You could change your Makefile rules:

aoll:
    (cd /usr/src/linux-headers-3.2.0-25-generic-pae/;echo $(PWD);make m=$(PWD) module)