Akagi201 发表于 2012-09-28 11:58

我的Linux驱动以及应用的通用Makefile,请帮忙挑bug

本帖最后由 Akagi201 于 2012-09-28 19:22 编辑

放在博客里没人看啊, 最近一直在修改,调试,不知道还有没有可以改进和修改的地方了,与大家新人们一起分享下。

希望高手们可以指点下。

博客地址:(不断修改完善)
http://blog.csdn.net/akagi201/article/details/8019809
http://blog.csdn.net/akagi201/article/details/8014704
http://blog.csdn.net/akagi201/article/details/8014697

代码的目录结构
|
|-project/
|----app/
|-----Makefile(app Makefile)
|----dev/
|-----Makefile(dev Makefile)
|----Makefile(Top Makefile)
###############################################################################
# @file Makefile
# @note HangZhou Hikvision Digital Technology Co., Ltd. All Right Reserved.
# @brief Top Generic Mkefile
#
# @author   liuboyf1
# @data   2012-09-26
# @versionV1.0.0
# @note   History:
# @note   <author>    <time>       <version>    <desc>
# @note   liuboyf1    2012-09-11   V1.0.0       创建文件
# @note   liuboyf1    2012-09-26   V1.0.1       添加make app make dev分别编译功能
###############################################################################

PWD = $(shell pwd)
all: app dev
app:
        make -C $(PWD)/app
dev:
        make -C $(PWD)/dev
clean:
        make clean -C $(PWD)/app
        make clean -C $(PWD)/dev
.PHONY: all app dev clean

###############################################################################
# @file Makefile
# @note HangZhou Hikvision Digital Technology Co., Ltd. All Right Reserved.
# @brief    Linux Device Driver Generic Makefile
#
# @author   liuboyf1
# @data   2012-09-28
# @versionV1.0.2
# @note   History:
# @note   <author>    <time>       <version>    <desc>
# @note   liuboyf1    2012-08-30   V1.0.0       创建文件
# @note   liuboyf1    2012-09-26   V1.0.1       修改了CFLAGS为EXTRA_CFLAGS
# @note   liuboyf1    2012-09-26   V1.0.2       简化了调试宏部分
# @note   liuboyf1    2010-09-28   V1.0.3       修改rm为-rm
###############################################################################

# Comment/uncomment the following line to enable/disable debugging
#DEBUG = y
ifeq ($(DEBUG),y)
        DEBFLAGS = -O -g # "-O" is needed to expand inlines
        DEBFLAGS += -DDEBUG # 控制是否打印调试和错误信息
else
        DEBFLAGS = -O2
endif

# The prefix to be added before the GNU compiler tools (optionally including
# path), i.e. "arm-linux-" or "/opt/bin/arm-linux-".
#TOOL_DIR = /opt/v5t_le-mv401_uc
# 交叉编译工具
#TOOL_PREFIX = $(TOOL_DIR)/bin/arm_v5t_le-

CC = $(TOOL_PREFIX)gcc
#AR:= $(TOOL_PREFIX)ar -rv
EXTRA_CFLAGS += $(DEBFLAGS)
#EXTRA_CFLAGS += -I$(LDDINC)

MODULE_NAME = mycdev
ifneq ($(KERNELRELEASE),)


obj-m := $(MODULE_NAME).o
#$(MODULE_NAME)-objs := file_opr.o mem_proc.o main.o

else

# in my Debian6 2.6.32
KERNELDIR ?=/lib/modules/2.6.32/build
# in my IPC 2.6.18
#KERNELDIR ?= /home/akagi201/kernel_step

PWD := $(shell pwd)

modules:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
        cp $(MODULE_NAME).ko $(PWD)/..

modules_install:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
endif

clean:
        -rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.* .*.o.cmd .*.ko.cmd .tmp_versions Module.symvers modules.order
# 减号忽略部分文件出现的问题,继续后面的工作
.PHONY: modules modules_install clean

depend .depend dep:
        $(CC) $(EXTRA_CFLAGS) -M *.c > .depend


ifeq (.depend,$(wildcard .depend))
include .depend
endif


###############################################################################
# @file Makefile
# @note HangZhou Hikvision Digital Technology Co., Ltd. All Right Reserved.
# @brief    Linux Application Generic Makefile
#
# @author   liuboyf1
# @data   2012-09-28
# @versionV1.0.3
# @note   History:
# @note   <author>    <time>       <version>    <desc>
# @note   liuboyf1    2012-09-03   V1.0.0       创建文件
# @note   liuboyf1    2012-09-26   V1.0.1       修复了DEBFLAGS调试
# @note   liuboyf1    2012-09-28   V1.0.2       修改rm为-rm更健壮
# @note   liuboyf1    2010-09-28   V1.0.3       修改了部分注释
###############################################################################

SRCS = $(wildcard *.c) # 当前目录下所有以.c结尾的源文件,wildcard 扩展通配符
OBJS = $(SRCS:.c = .o) # .c=.o是做一个替换,把变量$(sources)所有[.c]的字串都替换成.o

# The prefix to be added before the GNU compiler tools (optionally including
# path), i.e. "arm-linux-" or "/opt/bin/arm-linux-".
#TOOL_DIR = /opt/v5t_le-mv401_uc
# 交叉编译工具
#TOOL_PREFIX = $(TOOL_DIR)/bin/arm_v5t_le-

CC = $(TOOL_PREFIX)gcc

# 包含的头文件,和非系统链接库
#INCLUDES = -I/xxx
#LIBS = -lpthread

CFLAGS = -g -Wall -O2

# Comment/uncomment the following line to enable/disable debugging
DEBUG = y
ifeq ($(DEBUG),y)
        DEBFLAGS = -O -g # "-O" is needed to expand inlines
        DEBFLAGS += -DDEBUG # 控制是否打印调试和错误信息
else
        DEBFLAGS = -O2
endif

PWD := $(shell pwd)

# 生成的可执行文件名称
TARGET = test
$(TARGET) : $(OBJS)
        $(CC) $^ -o $@ $(CFLAGS) $(DEBFLAGS) $(INCLUDES) $(LIBS)
        cp $(TARGET) $(PWD)/..

%.o : %.c
        $(CC) -c $< $(CFLAGS) $(DEBFLAGS)

clean :
        -rm -f *.o $(TARGET) # 忽略某些文件问题,继续做后面的事情

.PHONY : clean

页: [1]
查看完整版本: 我的Linux驱动以及应用的通用Makefile,请帮忙挑bug