Unable to compile the kernel module

2019-09-21 17:54发布

问题:

I am trying to build a simple kernel in ubuntu,following are the errors getting while doing this.

make -C /lib/modules/3.13.0-52-generic/build M= modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-52-generic'
make[1]: Makefile: No such file or directory
make[1]: *** No rule to make target `Makefile'.  Stop.
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-52-generic'
make: *** [all] Error 2

My Make file:

obj-m := module1.o 
KERNEL = $(shell uname -r)
all: 
    make -C /lib/modules/$(KERNEL)/build M=$(PWD) modules
clean: 
    make -C /lib/modules/$(KERNEL)/build M=$(PWD) clean

Can anybody help me out.

Note: I have already downloaded the kernel source code

回答1:

You should set PWD variable in your Makefile before using it. E.g.

PWD = $(shell pwd)

UPDATE: Also, your Makefile mix lines for two modes: KBuild mode (obj-m := module1.o) and common makefile mode(all other lines). Your should either distinguish modes(using if) or use two different files for two modes:

Makefile:

KERNEL = $(shell uname -r)
PWD = $(shell pwd)
all: 
    make -C /lib/modules/$(KERNEL)/build M=$(PWD) modules
clean: 
    make -C /lib/modules/$(KERNEL)/build M=$(PWD) clean

Kbuild:

obj-m := module1.o


标签: kernel