Skip to content

Instantly share code, notes, and snippets.

@beanyoung
Created December 15, 2011 05:18
Show Gist options
  • Save beanyoung/1479930 to your computer and use it in GitHub Desktop.
Save beanyoung/1479930 to your computer and use it in GitHub Desktop.
make file template
CXX:=g++
SOURCE:=local-global-snake.cpp \
snake.cpp \
image-process.cpp
PROJECT_NAME:=local-global-snake
SOURCE_DIR:=source
RELEASE_DIR:=release
DEBUG_DIR:=debug
INCLUDE:=-I/usr/include/opencv
LIBPATH:=-L/usr/lib
LIBS:=-lcv -lhighgui -lcxcore
CXXFLAGS:=-c -Wall
OBJ:=$(SOURCE:%.cpp=%.o)
DEBUG_OBJ:=$(SOURCE:%.cpp=%.debug.o)
DEPENDENCY:=$(OBJ:.o=.d) $(DEBUG_OBJ:.debug.o=.debug.d)
VPATH:=source:release:debug
-include $(DEPENDENCY)
all: release debug
@echo "Build all done!"
release: $(OBJ)
@cd $(RELEASE_DIR); $(CXX) -O4 -o $(PROJECT_NAME) $(OBJ) $(INCLUDE) $(LIBPATH) $(LIBS)
@echo "Build release done!"
debug: $(DEBUG_OBJ)
@cd $(DEBUG_DIR); $(CXX) -g -o $(PROJECT_NAME) $(DEBUG_OBJ) $(INCLUDE) $(LIBPATH) $(LIBS)
@echo "Build debug done!"
%.o: %.cpp
@$(CXX) $(CXXFLAGS) -O4 $< $(INCLUDE) -I$(SOURCE_DIR) $(LIBPATH) $(LIBS) -o $(RELEASE_DIR)/$@
%.debug.o: %.cpp
@$(CXX) $(CXXFLAGS) -g -DDEBUG $< $(INCLUDE) -I$(SOURCE_DIR) $(LIBPATH) $(LIBS) -o $(DEBUG_DIR)/$@
%.d: %.cpp
@if [ ! -d $(RELEASE_DIR) ] ; then \
mkdir $(RELEASE_DIR); \
fi
@set -e; rm -f $(RELEASE_DIR)/$@;\
$(CXX) -MM $< > $(RELEASE_DIR)/$@.$$$$;\
sed 's,\($*\)\.o[ :]*, $(RELEASE_DIR)/\1.o $(RELEASE_DIR)/$@ : ,g' < $(RELEASE_DIR)/$@.$$$$ > $(RELEASE_DIR)/$@;\
rm -f $(RELEASE_DIR)/$@.$$$$
%.debug.d: %.cpp
@if [ ! -d $(DEBUG_DIR) ] ; then \
mkdir $(DEBUG_DIR); \
fi
@set -e; rm -f $(DEBUG_DIR)/$@;\
$(CXX) -MM $< > $(DEBUG_DIR)/$@.$$$$;\
sed 's,\($*\)\.o[ :]*, $(DEBUG_DIR)/\1.debug.o $(DEBUG_DIR)/$@ : ,g' < $(DEBUG_DIR)/$@.$$$$ > $(DEBUG_DIR)/$@;\
rm -f $(DEBUG_DIR)/$@.$$$$
.PHONY: clean
clean:
@-rm -rf $(DEBUG_DIR)/* $(RELEASE_DIR)/*
@echo "Clean done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment