Another question on SO为单个目标描述了一个非常优雅的makefile:
CXX = g++ # compiler
CXXFLAGS = -g -Wall -MMD # compiler flags
OBJECTS = x.o y.o z.o # object files forming executable
DEPENDS = ${OBJECTS:.o=.d} # substitutes ".o" with ".d"
EXEC = a.out # executable name
${EXEC} : ${OBJECTS} # link step
${CXX} ${OBJECTS} -o ${EXEC}
-include ${DEPENDS} # copies files x.d, y.d, z.d (if they exist)
我的问题是:我们如何才能针对多个目标进行调整?
答案 0 :(得分:1)
您的解决方案看起来不错,但是如果有很多目标,那么这个目标更容易扩展:
EXECS = exec_x exec_y
exec_x: a.o b.o c.o
exec_y: d.o e.o f.o
$(EXECS):
${LINK}
答案 1 :(得分:0)
我已经破解了一个似乎有用的解决方案,但我很想知道这是否是合适的技术。
CXX = g++ # compiler
CXXFLAGS = -g -Wall -MMD # compiler flags
LINK = ${CXX} $^ -o $@ # link step
exec_x: a.o b.o c.o
${LINK}
exec_y: d.o e.o f.o
${LINK}
-include *.d