嵌入式项目Makefile设计的一般方法

http://blog.csdn.net/embeddedsoft/article/details/1583571转自

本文以视频会议项目为背景,讨论如何使用WindRiver Tornado2.2的GNU工具链中的make工具编译各个模块的源代码,为嵌入式项目创建Makefile提供一般的设计方法。

具体方法如下:
1.先为所有模块,如下图中的code/source/appl目录下dp_new、gc、mc等编写一个全局的Makefile,取名为Makefile.global,放在code/include中。这个全局MAKEFILE用于指明工具链、各个子模块的相对路径、obj文件存放的位置,要引用的头文件和库文件目录等。
2.为各个模块如dp_new,gc,mc等编写子Makefile。在这些子Makefile使用include引用Makefile.global并指明要编译的源文件和编译规则已经最终要生成的目标,这里以gc模块为例,来说明如何书写便宜规则!

# Description:Global makefile  for sub-modules 
# Author:http: // blog.sina.com.cn/embeddedsoft
         http: // blog.csdn.net/embeddedsoft


#here define CPU type, compiler    tools faimly, compile rule
CPU                                        = PPC603
TOOL                                    = gnu
TOOL_FAMILY                        = gnu
DEFAULT_RULE                    = vxWorks

AR                                        = arppc
AS                                        = ccppc
BOOT_EXTRA                        =
CC                                        = ccppc
CPPC                                    = c++ppc

# Modify path when the path    of source code was changed
WIND_CODE_BASE                = E:/cvsroot2/MCU500/code

WIND_PROJECT_BASE            = $(WIND_CODE_BASE)/build
WIND_SOURCE_BASE            = $(WIND_CODE_BASE)/source

PRJ_ROOT_DIR                     = $(WIND_PROJECT_BASE)
SRC_ROOT_DIR                     = $(WIND_SOURCE_BASE)
INC_ROOT_DIR                     = $(WIND_CODE_BASE)/include
LIB_ROOT_DIR                     = $(WIND_CODE_BASE)/lib

# target and bsp module
TARGET_DIR                        = $(WIND_BASE)/target
TARGET_INCLUDE_DIR        = $(TARGET_DIR)/h
TARGET_COMPS_SRC_DIR    = $(TARGET_DIR)/config/comps/src
TARGET_DRV_SRC_DIR        = $(TARGET_DIR)/src/drv

BSP_DIR                                = $(SRC_ROOT_DIR)/bsp/nw8260_323

BSP_INCLUDE_DIR                = $(BSP_DIR)/nwh

# MainCtrl module
MC_DIR                            = $(SRC_ROOT_DIR)/appl/mc
MC_INCLUDE_DIR           = $(MC_DIR)/include
MC_SOURCE_DIR            = $(MC_DIR)/source

# Console module
CONSOLE_DIR                        = $(SRC_ROOT_DIR)/appl/ui/console
CONSOLE_INCLUDE_DIR     = $(CONSOLE_DIR)/include
CONSOLE_SOURCE_DIR       = $(CONSOLE_DIR)/source

# rs module
RS_DIR                                = $(SRC_ROOT_DIR)/appl/ui/rs
RS_INCLUDE_DIR             = $(RS_DIR)/include
RS_SOURCE_DIR              = $(RS_DIR)/source

# Comm module
COMM_DIR                            = $(SRC_ROOT_DIR)/ base/comm_new
COMM_INCLUDE_DIR          = $(COMM_DIR)/include
COMM_SOURCE_DIR            = $(COMM_DIR)/source

# stack module
STACK_DIR                            = $(SRC_ROOT_DIR)/appl/stack

# DataProcess module
DP_DIR                                = $(SRC_ROOT_DIR)/appl/dp_new
DP_INCLUDE_DIR                = $(DP_DIR)/include
DP_SOURCE_DIR                    = $(DP_DIR)/source

#web module
EWSMCU_INCLUDE_DIR       = $(SRC_ROOT_DIR)/appl/ui/web/EWS_MCU/include
EWSMCU_SOURCE_DIR          = $(SRC_ROOT_DIR)/appl/ui/web/EWS_MCU/source

# common module
COMMON_DIR                        = $(SRC_ROOT_DIR)/ base/common


# application
PRJ_DIR                                = $(PRJ_ROOT_DIR)
OBJ_DIR                                = $(PRJ_ROOT_DIR)/binary
APP_INCLUDE_DIR                = $(WIND_CODE_BASE)/include

CFLAGS                                 = -g     
                                            -mcpu=603 -mstrict-align 
                                            -ansi    -fno-builtin  
                                            -DCPU=PPC603 
                                            -DTOOL_FAMILY=gnu 
                                            -DTOOL=gnu    
                                            -DPRJ_BUILD    
                                            -D__VXWORKS__ 
                                            -DCODEC_RTOS
                                            -DVXWORKS 
                                            -DUEMF 
                                            -DWEBS_PAGE_ROM 
                                            -DWEBS 
                                            -D__NO_PACK 
                                            -DDEVICE_MCU 

INCLUDE_DIR                        = -I$(BSP_DIR)
                                            -I$(BSP_INCLUDE_DIR)
                                            -I$(INC_ROOT_DIR)
                                            -I$(TARGET_INCLUDE_DIR)
                                            -I$(BSP_INCLUDE_DIR)
                                            -I$(TARGET_DRV_SRC_DIR)
                                            -I$(PRJ_DIR)
                                            -I$(OBJ_DIR)
                                            -I$(MC_DIR)
                                            -I$(MC_INCLUDE_DIR)
                                            -I$(MC_SOURCE_DIR)
                                            -I$(DP_DIR)
                                            -I$(DP_INCLUDE_DIR)
                                            -I$(DP_SOURCE_DIR)
                                            -I$(CONSOLE_DIR)
                                            -I$(CONSOLE_INCLUDE_DIR)
                                            -I$(CONSOLE_SOURCE_DIR)
                                            -I$(EWSMCU_INCLUDE_DIR)
                                            -I$(EWSMCU_SOURCE_DIR)
                                            -I$(COMM_INCLUDE_DIR)
                                            -I$(COMM_SOURCE_DIR)
                                            -I$(RS_INCLUDE_DIR)
                                            -I$(RS_SOURCE_DIR)


CFLAGS                                 += $(INCLUDE_DIR)

MAKE                                     = $(WIND_BASE)/host/x86-win32/bin/make
RM                                         = rm
CP                                         = $(WIND_BASE)/host/x86-win32/bin/cp

 

# Description:Makefile used to build GC module 
# Author:http: // blog.sina.com.cn/embeddedsoft
         http: // blog.csdn.net/embeddedsoft

include     ../../../include/Makefile. global
 
APP_GC    =     $(LIB_ROOT_DIR)/gc.a

SRCS    =     gcaddrbook.c
        gccallhistory.c
        gccapacity.c
        gcconftemplate.c
        gcdevice.c
        gcendpointinfo.c
        gcgateway.c
        gcgk.c
        gcglobal.c
        gcmulticast.c
        gcnet.c
        gcresethistory.c
        gcrs.c
        gcupdate.c
        gcweb.c        

OBJS2     :=     $(SRCS:.c=.o)
OBJS    :=     $(addprefix $(OBJ_DIR)/,$(OBJS2))

$(APP_GC):$(OBJS) 
        $(RM) -f $(APP_GC)
        $(AR) -r $(APP_GC) $(OBJS)        
                    
$(OBJ_DIR)/%.o: %.c
        $(CC) -c -o $@ $(CFLAGS) $<
clean:
        $(RM) $(APP_GC) $(OBJS) 

你可能感兴趣的:(嵌入式项目Makefile设计的一般方法)