I am a beginner in linux kernel development and trying to load a simple module in linux. I have created an hello.c file, to be loaded as kernel module.
#include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("A Simple Hello World module"); static int __init hello_init(void) { printk(KERN_INFO "Hello world!\n"); return 0; } static void __exit hello_cleanup(void) { printk(KERN_INFO "Cleaning up module.\n"); } module_init(hello_init); module_exit(hello_cleanup);
this hello.c and the makefile both, I have kept in /home/linux/ directory.
makefile
obj-m +=hello.o src= /usr/src/linux-headers-3.5.0-17-generic all: $(MAKE) -C $(src) SUBDIR-$(PWD) modules clean: rm -rf *.o *.ko
to generate .ko file, when I run the make command on terminal from the /home/linux directory , I get following error
h2o@h2o-Vostro-1015:~/linux$ make make -C /usr/src/linux-headers-3.5.0-17-generic SUBDIR-/home/h2o/linux modules make[1]: Entering directory `/usr/src/linux-headers-3.5.0-17-generic' make[1]: *** No rule to make target `SUBDIR-/home/h2o/linux'. Stop. make[1]: Leaving directory `/usr/src/linux-headers-3.5.0-17-generic' make: *** [all] Error 2
kindly advise what am I missing or doing wrong..