Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kernel module makefile output name

I am trying to compile my kernel module. The .c file name is file1.c, but I need the .ko file name to be mod1.ko.

How can I do that?

My current makefile:

obj-m := mod1.o
KDIR :=/lib/modules/$(shell uname -r)/build
PDW := $(shell pwd)

all:
    $(MAKE) -C $(KDIR) M=$(PDW) modules

clean:
    $(MAKE) -C $(KDIR) M=$(PDW) clean
like image 965
Tomer Amir Avatar asked Dec 24 '22 19:12

Tomer Amir


2 Answers

You should change your first line to something like this:

obj-m += module_name.o
module_name-y := file1.o

Where module_name is the module file name (in this example the output will be module_name.ko) and it will be build from file1.c. You can add more than one source file to the 2nd line, so it could be:

module_name-y := file1.o file2.o file3.o

In this case module_name.ko will be build from file1.c, file2.c and file3.c.

You should read this document if you want to fully understand Linux kernel makefiles. Your problem is described somewhere around line 190.

like image 140
Krzysztof Adamski Avatar answered Jan 03 '23 05:01

Krzysztof Adamski


The solution looks like this:

obj-m += mod1.o
mod1-objs := file1.o

KBUILD_CPPFLAGS += -I$(PWD)/

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

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
like image 45
Tomer Amir Avatar answered Jan 03 '23 05:01

Tomer Amir