编写mipsel mt7620 Led驱动(三,Makefile)
此Makefile可以用于大多数简单驱动代码的编译
#################################################################
# file name: Makefile
# A simple Makefile for driver
# by Late Lee at www.latelee.org
# based on LDD3 and other guys works
# copyleft @ 2010
#
#################################################################
### nothing, just for fun
OFFSET=\x1b[21G # 21 col
COLOR1=\x1b[0;32m # green
COLOR2=\x1b[1;35m #
COLOR3=\x1b[1;31m # red
RESET=\x1b[0m
CLEAN_BEGIN=@echo -e "$(OFFSET)$(COLOR2)Cleaning up ...$(RESET)"
CLEAN_END=@echo -e "$(OFFSET)$(COLOR2)[Done.]$(RESET)"
MAKE_BEGIN=@echo -ne "$(OFFSET)$(COLOR1)Compiling ...$(RESET)"
MAKE_DONE="$(OFFSET)$(COLOR1)[Job done!]$(RESET)";
MAKE_ERR="$(OFFSET)$(COLOR3)[Oops! Error occurred]$(RESET)";
### nothing end here
#CROSS_COMPILE=mipsel-linux-
CROSS_COMPLIE=mipsel-openwrt-linux
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
######### DEBUG部分
#DEBUG = y
ifeq ($(DEBUG), y)
DEBFLAGS = -O -g
else
DEBFLAGS = -O1
endif
# sth wrong here, don’t know why
#EXTRA_CFLAGS += $(DEBFLAGS) -I$(LDDINCDIR)
#########驱动模块名称以及源文件部分
# module name here
MODULE = gpio
#obj-m = module
#obj-y = into kernel
#foo.o -> foo.ko
ifneq ($(KERNELRELEASE), )
obj-m := $(MODULE).o
# 驱动源代码文件,.o形式
# your obj file(s) here
#$(MODULE)-objs += ralink_gpio.o
else
# KERNELDIR ?= /home/yanfa/workspace/openwrt_package/openwrt-2.6.36/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620a/linux-2.6.36
# KERNELDIR ?= /home/yanfa/workspace/openwrt_package/RT288x_SDK/source/linux-2.6.36.x
KERNELDIR ?= /home/yanfa/workspace/openwrt_package/openwrt-mt7620-3.3.8/build_dir/linux-ralink_mt7620/linux-3.3.8
PWD := $(shell pwd)
##########真正编译部分,添加了if语句
all:
$(MAKE_BEGIN)
@echo
@if \
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules;\
then echo -e $(MAKE_DONE)\
else \
echo -e \
$(MAKE_ERR)\
exit 1; \
fi
endif
#####这个clean把生成的杂七杂八文件都删除,可用ls –al查看
clean:
$(CLEAN_BEGIN)
rm -rf *.cmd *.o *.ko *.mod.c *.symvers *.order *.markers .tmp_versions .*.cmd *~
$(CLEAN_END)
########伪目标部分
install:
@echo -e "$(COLOR3) Note:"
@echo -e "To install or not install,that is a question.$(RESET)"
modules:
@echo -e "$(COLOR3)Do not need to do this.$(RESET)"
modules_install:
@echo -e "$(COLOR3)Do not need to do this.$(RESET)"
.PHONY: all clean install modules modules_install
############# Makefile end here

浙公网安备 33010602011771号