Building a kernel module from several source files which one of them has the same name as the module

I found a solution, I placed my source file in a sub folder:

Makefile
src/mymodule.c
src/mymodule_func.c

#Makefile
obj-m += mymodule.o
mymodule-objs := ./src/mymodule.o ./src/mymodule_func.o

all:
    make -C $(KERNEL_PATH) M=$(PWD) modules

clean:
    make -C $(KERNEL_PATH) M=$(PWD) clean

Leave a Comment