0

I'm trying to build some kernel module acts like simple firewall for practicing kernel programming. I'm trying to build my module split to multiple c and header files but it won't finish build with error that I didn't define licence even I defined with MODULE_LICENSE("GPL"); My Make file is

obj-m += firewall.o

firewall-objs := fileio.o plstring.o rulemanager.o

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

Is there any way to build kernel module split to multiple files? I have tried to define licence to every c files but it didn't work.

1
  • Better asked/searched for in Linux specific venue, e.g. in Corbet et al "Linux Device Drivers" (O'Reilly, 3rd edition 1998).
    – vonbrand
    Aug 16, 2019 at 15:01

1 Answer 1

1

Here, You can use my Makefile as a reference.

INSTALL_DIR=modules
ifneq (${KERNELRELEASE},)
        obj-m :=cdd107.o
cdd107-objs := init.o clean.o opendev.o allocdev.o writedev.o readdev.o seekdev.o

else
        KERNELDIR ?= /lib/modules/$(shell uname -r)/build
        PWD := $(shell pwd)
default:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
        @rm -rf ${INSTALL_DIR}
        @mkdir ${INSTALL_DIR}
        @mv -f *.o *.ko *.mod.c .*.cmd ${INSTALL_DIR}
clean:
        rm -rf ${INSTALL_DIR}
endif

and build finished without an error

refernce log :-

make -C /lib/modules/4.4.0-31-generic/build M=/home/vijay/Downloads/intro modules
make[1]: Entering directory '/usr/src/linux-headers-4.4.0-31-generic'
  CC [M]  /home/vijay/Downloads/intro/init.o
  CC [M]  /home/vijay/Downloads/intro/clean.o
  CC [M]  /home/vijay/Downloads/intro/opendev.o
  CC [M]  /home/vijay/Downloads/intro/allocdev.o
  CC [M]  /home/vijay/Downloads/intro/writedev.o
  CC [M]  /home/vijay/Downloads/intro/readdev.o
  CC [M]  /home/vijay/Downloads/intro/seekdev.o
  LD [M]  /home/vijay/Downloads/intro/cdd107.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/vijay/Downloads/intro/cdd107.mod.o
  LD [M]  /home/vijay/Downloads/intro/cdd107.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.4.0-31-generic'

I hope this help you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .