生成静态库的通用makefile

#Set project name

PRJ_NAME = FileSystem.a

#set project type
PRJ_TYPE = ar rcs

#set Debug or Release
Compile_Flag Debug

#set output path
Output := bin

#set source folder
SRC := Source


#add lib used

#combine output folder
FinalOutput := $(Output)/$(Compile_Flag)/


#filags in makefile
DEBUG_FLAG := -O0  -g -Wall -c
RELEASE_FLAG :=  -O3   -Wall   -c
RM := rm   $(FinalOutput)*


#set compile flag
#ifeq($(Compile_Flag),Debug)
CFLAGS := $(DEBUG_FLAG)
#else
#CFLAGS := $(RELEASE_FLAG)
#endif


#prepare files
CPP_SRCS := $(shell find ./$(SRC)   -name   *.cpp)
OBJS := $(CPP_SRCS:./$(SRC)/%.cpp = $(FinalOutput)%.o)


#all target
#.PHONY all
all: dir $(FinalOutput)$(PRJ_NAME)


dir:
    mkdir -p $(FinalOutput)
#echo $(CPP_SRCS)
#echo $(OBJS)


$(FinalOutput)$(PRJ_NAME): $(OBJS)
    $(PRJ_TYPE)   $@   $^



$(FinalOutput)%o: ./$(SRC)/%cpp
    g++ $(CFLAGS)   $^   -o   $@    -D    _IPHONE


clean:

    -$(RM)



说明:

1) 所有源文件放在FileSystem目录下的Source目录中.

2) 本makefile文件放在FileSystem目录中.

3) 生成的.o文件和静态库文件FileSystem.a放在FileSystem/bin/Debug/目录中.

4) 参考文章: http://hi.baidu.com/hawthorne/blog/item/39328cb3b5194fafd9335acd.html

    在实际编写和运行时, 遇到一些问题, 故根据实际需要作出一些调整.    


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值