cmakefilekernel-module

Building a kernel module from multiple source files


I'm having some trouble with the bane of my existance, the Makefile. I'm trying to create a kernel module (.ko file) called "can.ko". I'm compiling a dozen or so source files:

TARGET = can
OBJS = can_core.o can_open.o can_select.o can_sysctl.o can_write.o can_close.o \
       can_ioctl.o can_read.o can_util.o can_debug.o can_error.o can_async.o
KDIR = /lib/modules/3.1.10-1.16-desktop/build
PWD := $(shell pwd)

obj-m += $(TARGET).o

default:
make -C $(KDIR) M=$(PWD) modules
$(TARGET).o : $(OBJS)

The compiler spits out that it can't find. "can.c".

make[4]: *** No rule to make target `/home/mike/iCOM-SDKv1.11.000/framework/drivers/can/can.c', needed by `/home/mike/iCOM-SDKv1.11.000/framework/drivers/can/can.o'.  Stop.

I'm pretty sure I don't need to name the output object after a source file, so clearly something is wrong. I did some serching around on getting more than 1 source file together and found this as another option:

TARGET = can
can-objs := can_core.c can_open.c can_select.c can_sysctl.c can_write.c \
   can_close.c can_ioctl.c can_read.c can_util.c \
   can_debug.c can_error.c \
   can_async.c
KDIR = /lib/modules/3.1.10-1.16-desktop/build
PWD := $(shell pwd)

obj-m += $(TARGET).o

default:
make -C $(KDIR) M=$(PWD) modules

This time I'm being told that it doesn't know what to do with .c files:

LD [M]  /home/mike/iCOM-SDKv1.11.000/framework/drivers/can/can.o
/home/mike/iCOM-SDKv1.11.000/framework/drivers/can/can_core.c: file not recognized: File format not recognized

Can anyone help me get this thing working?


Solution

  • can-objs needs to refer to .o files, not .c files.

    can-objs := can_core.o can_open.o can_select.o can_sysctl.o can_write.o \
        can_close.o can_ioctl.o can_read.o can_util.o \
        can_debug.o can_error.o \
        can_async.o