LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Building kernel module from multiple source file in 2.6 kernel (http://www.linuxquestions.org/questions/programming-9/building-kernel-module-from-multiple-source-file-in-2-6-kernel-268356/)

yogeshwar_s 12-20-2004 07:31 AM

Building kernel module from multiple source file in 2.6 kernel
 
hello,

i am working on 2.6 kernel (driver programming).
actually i am not able to understand what the makefile for 2.6 is doing when its compiling....
its accessing source path of running kernel.....

but that makefile is working fine for one source file
now if i have multiple source files , and i want a module, build from all of them...
how do i do this?

each file should be compiled to produce .o file then all must be linked to produce the final module....
help me in this matter....

one more question - if anyone knows command replacement for the makefile to compile the module?

jtshaw 12-20-2004 10:31 AM

Code:

# This Makefile will compile this thing standalone providing that your kernel
# Source include resides in /usr/src/linux/include.
KCFLAGS = -c -g -Wall -I/usr/src/linux/include -D__KERNEL__ -DMODULE
CC = gcc

M_OBJS = alloc.o file.o dir.o inode.o
M_TARGET = t4fs.ko

$(M_TARGET) : $(M_OBJS)
        ld -r -o $@ $(M_OBJS)

$(M_OBJS) : %.o : %.c
        $(CC) $(KCFLAGS) -o $@ $<

all: t4fs

indent:
        indent -kr -i8 *.c
        indent -kr -i8 *.h
        rm *.c~ *.h~

clean:
        rm $(M_OBJS) *.log

Here is an example of my Makefile for a little filesystem I wrote. M_OBJS is all the object files that the M_TARGET relies on. M_TARGET is the main module.


All times are GMT -5. The time now is 03:52 AM.