2009年2月4日 星期三

hello world 3 #ifdef


一樣是分開成兩個檔案
再多上#ifdef的用法
[root@localhost driver]# cd hello3
[root@localhost hello3]# ls
Makefile start.c stop.c

###########################################################
[root@localhost hello3]# cat start.c
#include < linux/kernel.h >
#include < linux/module.h >
#include < linux/init.h >

static int __init hello_init(void){
#ifdef __TEST__
printk("<1>Hello, World!!TEST\n");
#else
printk("<1>not __TEST__\n");
#endif
return 0;
}

module_init(hello_init);
[root@localhost hello3]#

###########################################################
[root@localhost hello3]# cat stop.c
#include < linux/kernel.h >
#include < linux/module.h >
#include < linux/init.h >

static void __exit hello_exit(void){
printk("<1>Bye!Bye!!\n");
}

module_exit(hello_exit);
[root@localhost hello3]#

###########################################################
[root@localhost hello3]# cat Makefile
obj-m += startstop.o
startstop-objs := start.o stop.o
EXTRA_CFLAGS += -D__TEST__
# makefile上多上這行等於是#define __TEST__
# 或等於在gcc上 多加上-D__TEST__這行
all:
make -C /lib/modules/2.6.9/build M=/mnt/driver/hello3 modules
clean:
make -C /lib/modules/2.6.9/build M=/mnt/driver/hello3 clean

[root@localhost hello3]#


沒有留言:

張貼留言