-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
63 lines (59 loc) · 1.62 KB
/
Makefile
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
# Kernel Version Check
KVER := $(shell uname -r | cut -c1-3 | sed 's/2\.[56]/2\.6/')
# Makefile for a basic kernel module - 2.4.x
KINC=
ifeq ($(KINC),)
KINC := $(shell uname -r)
endif
CC := gcc
MODCFLAGS := -DMODULE -D__KERNEL__ -DLINUX -DOLDKERNEL -O -I/usr/src/linux-$(KINC)/include
# Makefile for a basic kernel module - 2.6.x
obj-m := plcm_drv.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
# MODULE -- This tells the header files to give the appropriate
# definitions for a kernel module.
#
# __KERNEL__ -- This tells the header files that this code will
# be run in kernel mode not as part of a user process.
#
# LINUX -- Technically speaking, this is not necessary. However,
# if you ever want to write a serious kernel module which will
# compile on more than one operating system, you'll be happy you
# did. This will allow you to do conditional compilation on the
# parts which are OS dependant.
#
default:
ifeq ($(wildcard /dev/plcm_drv),)
mknod /dev/plcm_drv c 241 0
endif
gcc -O2 plcm_test.c -o plcm_test
gcc -O2 plcm_cursor_char.c -o plcm_cursor_char
ifeq ($(KVER),2.6)
$(MAKE) -C $(KDIR) M=$(PWD) modules
endif
ifeq ($(KVER),2.4)
$(CC) $(MODCFLAGS) -c plcm_drv.c
endif
ifeq ($(wildcard Test),)
echo "rmmod plcm_drv" > Test
ifeq ($(KVER),2.6)
echo "insmod plcm_drv.ko" >> Test
endif
ifeq ($(KVER),2.4)
echo "insmod plcm_drv.o" >> Test
endif
echo "./plcm_test" >> Test
echo "./plcm_test -stop" >> Test
echo "rmmod plcm_drv" >> Test
chmod 777 Test
endif
clean:
rm -f plcm_test
rm -f plcm_cursor_char
ifeq ($(KVER),2.6)
$(MAKE) -C $(KDIR) M=$(PWD) clean
endif
ifeq ($(KVER),2.4)
rm -f *.o *.ko
endif