1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
| $ cat Makefile
obj-m := mod_name.o
KERNEL_DIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all: mod_name
mod_name:
$(MAKE) -C $(KERNEL_DIR) M=$(PWD) LDDINC=$(PWD) modules
clean:
rm -rf .*.cmd *.o *.mod.c *.cmd *.ko .tmp_versions modules.order Module.symvers
############样式输出
CROSS_COMPILE=
#arm-linux-
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
######### DEBUG部分
#DEBUG = y
ifeq ($(DEBUG), y)
DEBFLAGS = -O -g
else
DEBFLAGS = -O1
endif
#########驱动模块名称以及源文件部分
# module name here
MODULE = VSD_FOR_RAID
# obj-m = module
# obj-y = into kernel
# foo.o -> foo.ko
ifneq ($(KERNELRELEASE), )
obj-m := $(MODULE).o
# 驱动源代码文件,.o形式
# your obj file(s) here
KBUILD_EXTRA_SYMBOLS=$(common_symbol)
$(MODULE)-objs := vsd.o\
vsd_manager.o \
vsd_ctl.o vsd_event.o vsd_io.o\
vsd_io_create_remove.o vsd_io_get_put.o \
vsd_io_rw.o\
vsd_request.o vsd_request_disk.o\
vsd_super.o\
vsd_bbr.o\
$(COMMON_OBJ)
else
#KERNELDIR ?= /usr/src/linux-headers-3.2.0-4-amd64
#../git/kernel/linux-3.4.13/
# ../linux-2.6.38.8/linux-2.6.38.8/
PWD := $(shell pwd)
##########真正编译部分,添加了if语句
all:
ln -nsf ../common/*.[ch] ./
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules;
rm -f $(COMMON_SRC)
endif
#####这个clean把生成的杂七杂八文件都删除,可用ls –al查看
clean:
rm -rf $(COMMON_SRC) *.bak *~ *.o *.ko *.symvers *.mod.c *.html *.order .*.cmd .tmp_versions
rm -rf ./user_test/*.bak
########伪目标部分
install:
modules:
modules_install:
.PHONY: all clean install modules modules_install
############# Makefile end here
|