通用的makefile

372阅读 0评论2011-07-28 waderwang
分类:LINUX


#this make file can auto maticly make all c and cpp files in a folder.
#no need to modify this file, it can work well.
#autor: Chunrui Wang
#date: 2011-07-28



# The executeable file name
APP = Target

# source file name . include C and Cpp
SRCS = $(wildcard *.cpp) $(wildcard *.c)

#object files
OBJS = $(patsubst %.cpp,%.o,$(patsubst %.c,%.o,$(SRCS)))

#header depandence files.
DEPS = $(patsubst %.cpp,%.d~,$(patsubst %.c,%.d~,$(SRCS)))

        
#support mutiple target here.
.PHONY : all
all : $(APP)

$(APP):$(OBJS)
    #$(CXX) $(CFLAGS) -o $(APP) $(OBJS) $(LDFLAGS)
    #$(AR) r "lib$(APP).a" $(OBJS)
    $(CXX) -shared -o "lib$(APP).so" $(OBJS)




#generate the header depandence for each cpp file.
#Delete the hint rule of makefile for Cpp file.
.SUFFIXES : .cpp
.cpp.o:
    $(CXX) $(CFLGAS) -MMD -MF $*.d~ -c -o $@ $<


#generate the header depandence for each c file.
#Delete the hint rule of makefile for C file.
.SUFFIXES : .c
.c.o:
    $(CXX) $(CFLGAS) -MMD -MF $*.d~ -c -o $@ $<


#this is very important
-include $(DEPS)



#Deleting some files to make the project clean.
.PHONY : clean
clean :
    rm -rf *.o
    rm -rf $(APP)
    rm -rf *~



上一篇:Win7下打开dbgPrint
下一篇:没有了