网上有朋友询问多目录下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) |