Chinaunix首页 | 论坛 | 博客
  • 博客访问: 145183
  • 博文数量: 44
  • 博客积分: 2085
  • 博客等级: 大尉
  • 技术积分: 455
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-31 11:03
文章分类

全部博文(44)

文章存档

2013年(3)

2011年(8)

2010年(11)

2009年(22)

我的朋友

分类:

2009-10-13 10:17:07

在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


================================================================
阅读(396) | 评论(0) | 转发(0) |
0

上一篇:Jffs2文件系统

下一篇:RAM FileSystem and expand

给主人留下些什么吧!~~