makefile依赖文件和输出文件到指定目录

include ../makefile_public

#CXX = /usr/bin/g++
CXXFLAGS = $(CPPFLAGS) -DDEBUG
CXXLFLAGS = $(LDFLAGS) -lpthread -lutility

OUTPUT=./.objs
CPP_FILE = $(wildcard ./*.cpp)
#O_CPPFILE = $(patsubst ./%.cpp, ./.objs/%.o, $(CPP_FILE))
O_CPPFILE = $(patsubst ./%.cpp, %.o, $(CPP_FILE))

OBJS=$(addprefix $(OUTPUT)/, $(O_CPPFILE))
#OBJS=$(O_CPPFILE)

DEPS = $(OBJS:%.o=%.d)

ALL_TARGETS = gamesvrd

all: $(ALL_TARGETS)

include $(DEPS)

$(DEPS): $(OUTPUT)/%.d: %.cpp
    @$(CXX) -M $(CXXFLAGS) $< > $@.$$$$; sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; rm -f $@.$$$$

$(OBJS): $(OUTPUT)/%.o: %.cpp
    $(CXX) -c $(CXXFLAGS) $< -o $@

$(ALL_TARGETS): $(OBJS)
    $(CXX) $(OBJS) -o $@ $(CXXLFLAGS)

clean:
    @rm -rf *.o $(OBJS) $(ALL_TARGETS) core *~


你可能感兴趣的:(makefile依赖文件和输出文件到指定目录)