Ответ 1
http://make.paulandlesley.org/autodep.html имеет хорошее решение.
Абсолютно. g++ -MM <your file>
создаст совместимый с GMake список зависимостей. Я использую что-то вроде этого:
# Add .d to Make recognized suffixes.
SUFFIXES += .d
#We don't need to clean up when we're making these targets
NODEPS:=clean tags svn
#Find all the C++ files in the src/ directory
SOURCES:=$(shell find src/ -name "*.cpp")
#These are the dependency files, which make will clean up after it creates them
DEPFILES:=$(patsubst %.cpp,%.d,$(SOURCES))
#Don't create dependencies when we're cleaning, for instance
ifeq (0, $(words $(findstring $(MAKECMDGOALS), $(NODEPS))))
#Chances are, these files don't exist. GMake will create them and
#clean up automatically afterwards
-include $(DEPFILES)
endif
#This is the rule for creating the dependency files
src/%.d: src/%.cpp
$(CXX) $(CXXFLAGS) -MM -MT '$(patsubst src/%.cpp,obj/%.o,$<)' $< -MF [email protected]
#This rule does the compilation
obj/%.o: src/%.cpp src/%.d src/%.h
@$(MKDIR) $(dir [email protected])
$(CXX) $(CXXFLAGS) -o [email protected] -c $<
Это автоматически сгенерирует зависимости для каждого файла, который изменился, и скомпилирует их в соответствии с тем правилом, которое у вас есть. Это позволяет мне просто записывать новые файлы в каталог src/
и автоматически компилировать их, зависимости и все.