how write my Makefile for a hello kernel module
I have compile the hello program,but failed. in my directory hello, I have include and src directory. In include directory there is hello.h file. In src directory ,there are hello.c Makefile fils.
my hello.h file is as bellow:
#ifndef HELLO_H
#define HELLO_H
#define A 10
#endif
My hello.c is as bellow:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include "hello.h"
MODULE_LICENSE("GPL");
static int hello_init(void)
{
printk("Hello World!\n");
printk("a=%d\n", A);
return 0;
}
static void hello_exit(void)
{
printk("Good bye!\n");
}
module_init(hello_init);
module_exit(hello_exit);
My Makfile is as bellow:
KDIR:=/lib/modules/$(shell uname -r)/build
PWD :=$(shell pwd)
obj-m:=hello.o
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
$(RM) .*.cmd *.o *.ko -r .tmp*
when i was in src directory , i run make ,but have some errons;
[y041138@302wan hello]$ make
make -C /lib/modules/2.6.8.1/build SUBDIRS=/home/y041138/hello modules
make[1]: Entering directory `/usr/src/linux-2.6.8.1'
CC [M] /home/y041138/hello/hello.o
/home/y041138/hello/hello.c:4:19: hello.h: No such file or directory
/home/y041138/hello/hello.c: In function `hello_init':
/home/y041138/hello/hello.c:10: error: `A' undeclared (first use in this functi)
/home/y041138/hello/hello.c:10: error: (Each undeclared identifier is reported e
/home/y041138/hello/hello.c:10: error: for each function it appears in.)
make[2]: *** [/home/y041138/hello/hello.o] Error 1
make[1]: *** [_module_/home/y041138/hello] Error 2
make[1]: Leaving directory `/usr/src/linux-2.6.8.1'
make: *** [default] Error 2
[y041138@302wan hello]$
there is hello.h file in include ,why said that there is no hello.h file??
I guess there is something wrong in my Makefile
can you help me ,and write a right Makefile or let me get pass the compiler
but if the hell.h hell.c Makefile are in the same directory, i can pass the compile if i run make in the src directory.