First Edition
#
# Description:
# Makefile for 2.6 device drivers
#
# Comment/uncomment the following line to disable/enable debugging
#DEBUG = y
# Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
DEBFLAGS = -O -g -DCAN_DEBUG
# "-O" is needed to expand inlines
else
DEBFLAGS = -O2
endif
#CFLAGS += $(DEBFLAGS) //i am not sure how to use this line
ifneq ($(KERNELRELEASE),)
# call from kernel build system
obj-m := hello.o //编译模块的名称
else
KERNELDIR ?= /home/boboo/Tools/hfrk/linux-2.6.14 //你所使用内核的目录
PWD := $(shell pwd)
CC := arm-linux-gcc
HOSTCC := gcc
export CC HOSTCC
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
clean:
rm -rf *.o *.ko
Second Edition
EXEC = demomodule
OBJS = demomodule.o
SRC = demomodule.c
INCLUDE = /***/***/2.4.18-rmk7/include
#ÒÔÉÏÊÇÄãÄںˎúÂëËùÔڵĿâÎÄŒþµÄ·Ÿ£¬ÄãÐŽµÄÄÇžö²ÎÊýÊÇpcµÄ2.4.20ϵģ¬²»ÊÇÄãÄ¿±ê»úÏÂÒªÓõİ江µÄ¿â¡£
CC = arm-linux-gcc
LD = arm-linux-ld
MODEFLAGS = -DMODULE -D__KERNEL__ -I$(INCLUDE) -g -Wall -Wstrict-prototypes /
-Wno-trigraphs -Os -mapcs -fno-strict-aliasing -fno-common -fno-common /
-pipe -mapcs-32 -march=armv4 -mtune=arm9tdmi -mshort-load-bytes -msoft-float /
LDFLAGS =
all:$(OBJS)
$(EXEC):$(OBJS)
$(LD) $(LDFLAGS) -o $ @ $(OBJS)
%.o:%.c
$(CC) $(MODEFLAGS) -c $(SRC)
clean:
-rm -f $(EXEC) *.elf *.o *.gdb
Third Edition
CROSSDIR = /usr/crosstool/gcc-3.4.5-glibc-2.3.6/arm-linux
INSTALLDIR = $(TFTPDIR)
KERNELDIR =/root/linux-kernel-2.6.14
MODDEV = usb_driver
CROSS=arm-linux-
CC = $(CROSS)gcc
AS = $(CROSS)as
LD = $(CROSS)ld
ifneq ($(KERNELRELEASE),)
obj-m := $(MODDEV).o
else
PWD := $(shell pwd)
all:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
install:
cp $(MODDEV).ko $(INSTALLDIR)
endif