- 論壇徽章:
- 0
|
本帖最后由 Akagi201 于 2012-09-28 19:22 編輯
放在博客里沒(méi)人看啊, 最近一直在修改,調(diào)試,不知道還有沒(méi)有可以改進(jìn)和修改的地方了,與大家新人們一起分享下。
希望高手們可以指點(diǎn)下。
博客地址:(不斷修改完善)
http://blog.csdn.net/akagi201/article/details/8019809
http://blog.csdn.net/akagi201/article/details/8014704
http://blog.csdn.net/akagi201/article/details/8014697
代碼的目錄結(jié)構(gòu)
|
|-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
- # @version V1.0.0
- # @note History:
- # @note <author> <time> <version> <desc>
- # @note liuboyf1 2012-09-11 V1.0.0 創(chuàng)建文件
- # @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
復(fù)制代碼
- ###############################################################################
- # @file Makefile
- # @note HangZhou Hikvision Digital Technology Co., Ltd. All Right Reserved.
- # @brief Linux Device Driver Generic Makefile
- #
- # @author liuboyf1
- # @data 2012-09-28
- # @version V1.0.2
- # @note History:
- # @note <author> <time> <version> <desc>
- # @note liuboyf1 2012-08-30 V1.0.0 創(chuàng)建文件
- # @note liuboyf1 2012-09-26 V1.0.1 修改了CFLAGS為EXTRA_CFLAGS
- # @note liuboyf1 2012-09-26 V1.0.2 簡(jiǎn)化了調(diào)試宏部分
- # @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 # 控制是否打印調(diào)試和錯(cuò)誤信息
- 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
- # 減號(hào)忽略部分文件出現(xiàn)的問(wèn)題,繼續(xù)后面的工作
- .PHONY: modules modules_install clean
- depend .depend dep:
- $(CC) $(EXTRA_CFLAGS) -M *.c > .depend
- ifeq (.depend,$(wildcard .depend))
- include .depend
- endif
復(fù)制代碼
- ###############################################################################
- # @file Makefile
- # @note HangZhou Hikvision Digital Technology Co., Ltd. All Right Reserved.
- # @brief Linux Application Generic Makefile
- #
- # @author liuboyf1
- # @data 2012-09-28
- # @version V1.0.3
- # @note History:
- # @note <author> <time> <version> <desc>
- # @note liuboyf1 2012-09-03 V1.0.0 創(chuàng)建文件
- # @note liuboyf1 2012-09-26 V1.0.1 修復(fù)了DEBFLAGS調(diào)試
- # @note liuboyf1 2012-09-28 V1.0.2 修改rm為-rm更健壯
- # @note liuboyf1 2010-09-28 V1.0.3 修改了部分注釋
- ###############################################################################
- SRCS = $(wildcard *.c) # 當(dāng)前目錄下所有以.c結(jié)尾的源文件,wildcard 擴(kuò)展通配符
- OBJS = $(SRCS:.c = .o) # .c=.o是做一個(gè)替換,把變量$(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
- # 包含的頭文件,和非系統(tǒng)鏈接庫(kù)
- #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 # 控制是否打印調(diào)試和錯(cuò)誤信息
- else
- DEBFLAGS = -O2
- endif
- PWD := $(shell pwd)
- # 生成的可執(zhí)行文件名稱(chēng)
- TARGET = test
- $(TARGET) : $(OBJS)
- $(CC) $^ -o $@ $(CFLAGS) $(DEBFLAGS) $(INCLUDES) $(LIBS)
- cp $(TARGET) $(PWD)/..
- %.o : %.c
- $(CC) -c $< $(CFLAGS) $(DEBFLAGS)
- clean :
- -rm -f *.o $(TARGET) # 忽略某些文件問(wèn)題,繼續(xù)做后面的事情
- .PHONY : clean
復(fù)制代碼 |
|