Chinaunix首页 | 论坛 | 博客
  • 博客访问: 357216
  • 博文数量: 46
  • 博客积分: 4936
  • 博客等级: 上校
  • 技术积分: 575
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-25 20:14
文章分类

全部博文(46)

文章存档

2012年(4)

2011年(1)

2010年(23)

2009年(18)

分类: LINUX

2009-09-07 23:02:23

     网上有朋友询问多目录下Makefile的写法,我把自己使用多年的Makefile奉上。
 
其中make.include放在根目录下:

INCL_PATH = \
  -I/${PRJ_HOME/incl/
        -I.
       
LIB_PATH = -L$(PRJ_HOME)/lib
SYS_INCL_PATH =
SYS_LIB_PATH  =
SYS_LIBS = -lm -lnsl -ldl
CCC=g++
CCFLAGS  = -g -w -DLinux -DDEBUG -D_USE_MACRO  -DSQL_SYBASE -D_CSERVER_DEBUG_\
            ${INCL_PATH} ${SYS_INCL_PATH}
CPPFLAGS = ${LIB_PATH} ${SYS_LIB_PATH}
CPPLIBS  = ${LIBS}  ${SYS_LIBS}
AR       = ar
ARFLAGS  = -ruv
INSTALL_PATH= $(CMS_HOME)/lib
INSTALL_BIN_PATH= $(CMS_HOME)/bin
TARGET_PATH= ./
OBJECTS=${SOURCES:%.cpp=%.o}
all: ${CLIB} ${PROGRAM}
${CLIB}: ${OBJECTS}
 @if [ ! -d ${TARGET_PATH} ]; then mkdir -p ${TARGET_PATH}; fi
 $(AR) ${ARFLAGS} $@ $(OBJECTS)
${PROGRAM}: ${OBJECTS}
 @if [ ! -d ${TARGET_PATH} ]; then mkdir -p ${TARGET_PATH}; fi
 $(CCC) -o $@ ${CPPFLAGS} $(OBJECTS) $(CPPLIBS)
.cpp.o:
 $(CCC) $(CCFLAGS) -o $@ -c $<
install:
 @if [ "x${CLIB}" != "x" ]; then mkdir -p ${INSTALL_PATH}; cp $(CLIB) $(INSTALL_PATH); fi
 @if [ "x${PROGRAM}" != "x" ]; then mkdir -p ${INSTALL_BIN_PATH}; cp $(PROGRAM) $(INSTALL_BIN_PATH); fi
clean:
 @rm -rf ${OBJECTS} ${CLIB} ${PROGRAM}
 @rm -rf SunWS_cache
 @rm -rf ir.out
 @rm -rf core.*
 @rm -rf my
 @rm -rf you
 
每个目录下:

############################################################
## makefile of libtest.a
############################################################
.SUFFIXES: .cpp
SOURCES  = test.cpp
 
PROGRAM  = test
CLIB     = 
LIBS     =
PRJ_HOME = $(HOME)/project
include ${PRJ_HOME}/makefile.include
 
 
 
 
 
阅读(1431) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~