RE: how do I compile a single file in kernel?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> On Thu, Mar 03, 2005 at 09:57:54AM +0530, Srinivas G. wrote:
> > If you are using 2.6.x kernel then you have to use the following
make
> > file to compile a single file. If you are using 2.4.x then it
varies.
> [...]
> 
> > default:
> > 	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
> 
> It's slightly different since linux-2.6.7:
> 
> default:
> 	$(MAKE) -C $(KDIR) M=$(PWD) modules
> 

Erik,

I am using the Fedora Core 3 with 2.6.9-1.667 kernel. I used the same
make to compile the program in my environment. I tested the make with
small hello.c program also. Please see the following hello.c file and
its related make file.

hello.c
------------------------------------------
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>

MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
	printk("Hello World!\n");
	return 0;
}

static void hello_exit(void)
{
	printk("Good bye!\n");
}

module_init(hello_init);
module_exit(hello_exit);

-----------------------------------------------------
#
# Makefile for hello.c file
#
KDIR:=/lib/modules/$(shell uname -r)/build
TRGT:=hello_world
OBJS:=hello.o

obj-m += $(TRGT).o
$(TRGT)-objs := $(OBJS)

default:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
	$(RM) .*.cmd *.mod.c *.ko *.o -r .tmp*

----------------------------------------------------

It is working fine for my environment. If you want test it please copy
the files and test them. My system configuration is Intel Pentium III
with 128MB SD RAM and 10GB Hard disk.

Regards,
Srinivas G

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux