在makefile中添加宏
Makefile
...
MAC=
CFLAGE= $(MAC)
...
如果要添加宏MAC: make MAC=-DMAC
===========================================
********test.c ****************
#define MODULE
#include
int init_module(void)
{
printk("<1>Hello, world \n");
return 0;
}
void cleanup_module(void)
{
printk("<1>Goodbye cruel world\n");
}
********Makefile 我的PC是用2.6****************
obj-m := test.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
rm -rf *.o *.cmd *.ko *.mod.c .tmp_versions
=====================================================
********exart.c ****************
#ifndef __KERNEL__
# define __KERNEL__
#endif
#ifndef MODULE
# define MODULE
#endif
#if defined (CONFIG_SMP)
#define __SMP__
#endif
#include
#include
#include
#include
#include /* everything... */
#include
#include /* error codes */
#include
#include
static int exart_major = 0;
MODULE_PARM(exart_major, "i");
MODULE_AUTHOR("Terry.xia");
MODULE_LICENSE("GPL");
#define PHYS_BASE 0x02000000
#define PHYS_MAX 0x02000100
static void *io_base;
int exart_open(struct inode *inode, struct file *filp)
{
MOD_INC_USE_COUNT;
return 0;
}
int exart_release(struct inode *inode, struct file *filp)
{
MOD_DEC_USE_COUNT;
return 0;
}
struct file_operations exart_fops = {
open: exart_open,
release: exart_release,
};
int exart_init(void)
{
int result = register_chrdev(exart_major, "exart", &exart_fops);
if (result < 0) {
printk("<1>exart: can't get major number\n");
return result;
}
if (exart_major == 0)
exart_major = result;
SET_MODULE_OWNER(&exart_fops);
io_base = ioremap(PHYS_BASE, PHYS_MAX - PHYS_BASE);
return 0;
}
void exart_cleanup(void)
{
iounmap(io_base);
unregister_chrdev(exart_major, "exart");
}
module_init(exart_init);
module_exit(exart_cleanup);
********Makefile (kernel 2.4)****************
CC = ppc_8xx-gcc
#CC = arm-elf-gcc
KERDIR = /opt/eldk/ppc_8xx/usr/src/linux-2.4.25
#KERDIR = /home/terry/Fom/kernel/W90N740-uClinux/uClinux-dist/linux-2.4.x
OFLAG = -Wall -D__KERNEL__ -DMODULE -I$(KERDIR)/include -O2 -c -o
all: exart.o
exart.o: exart.c
$(CC) $(OFLAG) $@ $<
clean:
rm -f *.o
================================================================
阅读(423) | 评论(0) | 转发(0) |