LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 12-20-2004, 06:31 AM   #1
yogeshwar_s
LQ Newbie
 
Registered: Sep 2004
Location: Pune
Posts: 6

Rep: Reputation: 0
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?
 
Old 12-20-2004, 09:31 AM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 65
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error building nvidia kernel module beeblequix Debian 1 10-07-2005 05:21 PM
How to add kernel module to kernel source? cranium2004 Programming 7 05-12-2005 10:34 PM
Problems building a simple kernel module for kernel 2.6.7 atticman Linux - Software 2 12-13-2004 03:35 PM
help for building a kernel from source sh4d0w331 Slackware 5 09-28-2004 01:27 PM
Building a module within a kernel brianvdc Linux - General 1 12-11-2003 08:13 PM


All times are GMT -5. The time now is 11:52 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration