#################################################################
# 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-
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 = attr
# 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 := sysdemo.o
else
KERNELDIR ?= /home/xiaoge/sdb1/ralink/MT7620/RT288x_SDK/source/linux-2.6.36.x
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
linux drver Makefile模板
最新推荐文章于 2025-02-28 17:02:59 发布
