分享一个Makefile

又回到了Linux的编程环境中,不再折腾了,没有意义。把编程技术学好吧。 分享了一个Makefile,这个Makefile,是从TinyXML的工程文件中提取出来的。自己按照自己的需求修改了下。感觉还不错。

#****************************************************************************
# This is a GNU make (gmake) makefile
#****************************************************************************

# DEBUG can be set to YES to include debugging info, or NO otherwise
DEBUG := NO

# PROFILE can be set to YES to include profiling info, or NO otherwise
PROFILE :
= NO

# TINYXML_USE_STL can be used to turn on STL support. NO, then STL
# will not be used. YES will include the STL files.
TINYXML_USE_STL :
= NO

#****************************************************************************

DEBUG_CFLAGS :
= -Wall -Wno-format -g -DDEBUG
RELEASE_CFLAGS :
= -Wall -Wno-unknown-pragmas -Wno-format -O3

DEBUG_CXXFLAGS :
= ${DEBUG_CFLAGS}
RELEASE_CXXFLAGS :
= ${RELEASE_CFLAGS}

DEBUG_LDFLAGS :
= -g
RELEASE_LDFLAGS :
=

ifeq
(YES, ${DEBUG})
CFLAGS :
= ${DEBUG_CFLAGS}
CXXFLAGS :
= ${DEBUG_CXXFLAGS}
LDFLAGS :
= ${DEBUG_LDFLAGS}
else
CFLAGS :
= ${RELEASE_CFLAGS}
CXXFLAGS :
= ${RELEASE_CXXFLAGS}
LDFLAGS :
= ${RELEASE_LDFLAGS}
endif

ifeq
(YES, ${PROFILE})
CFLAGS :
= ${CFLAGS} -pg -O3
CXXFLAGS :
= ${CXXFLAGS} -pg -O3
LDFLAGS :
= ${LDFLAGS} -pg
endif


#****************************************************************************
# 编译器设置
#****************************************************************************

CC :
= gcc
CXX :
= g++
LD :
= g++
AR :
= ar rc
RANLIB :
= ranlib
#CFLAGS := -Wall -Wno-format -g

#****************************************************************************
# Preprocessor directives
#****************************************************************************

ifeq
(YES, ${TINYXML_USE_STL})
DEFS :
= -DTIXML_USE_STL
else
DEFS :
=
endif
#****************************************************************************
# Makefile code common to all platforms
#****************************************************************************

CFLAGS :
= ${CFLAGS} ${DEFS}
CXXFLAGS :
= ${CXXFLAGS} ${DEFS}

#****************************************************************************
# Include paths &&& Lib path
# 在此次添加搜索的路径和库
#****************************************************************************

#INCS := -I/usr/include/g++-2 -I/usr/local/include
CINCLUDE :
= -I ../include
CXXINCLUDE :
= -I ../include
LD_LIBRARY_PATH:
= -L./ \
-L
../lib
LDFLAGS :
= ${LD_LIBRARY_PATH} \
-lgtest
\
-lpthread

#****************************************************************************
# Targets of the build
#****************************************************************************
TARGET :
= algo
all:
$(TARGET)

#****************************************************************************
# Source files
#****************************************************************************
SRCDIRS :
= ./
CSRCS :
= $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.c))
CXXSRCS :
= $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.cpp))
SRCS :
= ${CSRCS} ${CXXSRCS}

OBJS :
= $(addsuffix .o,$(basename ${SRCS}))

#****************************************************************************
# Output
#****************************************************************************
$(TARGET): $(OBJS)
${LD} -o $@ ${OBJS} ${LDFLAGS} ${LIBS} ${EXTRA_LIBS}
@echo $@ Build Success!
# Rules for compiling source files to object files
%
.o : %.cpp
${CXX} -c ${CXXFLAGS} ${CXXINCLUDE} $< ${LDFLAGS} -o $@

%
.o : %.c
${CC} -c ${CFLAGS} ${CINCLUDE} -c $< -o $@

dist:
bash makedistlinux
clean:
-rm -f core
${OBJS} ${TARGET}

posted @ 2010-12-06 13:38  westfly  阅读(403)  评论(0编辑  收藏  举报