using make to create the objs and deps directories
[physics.git] / src / Makefile
index 1ebf227..14cc64b 100644 (file)
@@ -35,6 +35,9 @@ DEPSDIR := ../deps/
 DEPS    := ${SRCS:.cpp=.d}
 DEPS    := $(addprefix ${DEPSDIR},${DEPS})
 
+BLDDIRS := $(addprefix ${DEPSDIR},${DIRS}) $(addprefix ${OBJSDIR},${DIRS})
+BLDDIRS := $(addsuffix /,${BLDDIRS})
+
 
 VERBOSE := 0
 
@@ -53,17 +56,22 @@ endif
 .PHONY: all
 all: ${TARGET}
 
+# how to link the main target
 ${TARGET}: ${OBJS}
        ${Q1}echo "${CXX}: $@"
        ${Q2}${CXX} ${CXXFLAGS} -o $@ $^ ${LIBS}
 
+# how to make a directory
+${BLDDIRS}:
+       ${Q2}mkdir -p $@
+
 # rule to make a depend file from a .cpp
-${DEPSDIR}%.d: %.cpp
+${DEPSDIR}%.d: %.cpp | ${BLDDIRS}
        ${Q1}echo "DEP: $@"
        ${Q2}${CXX} -MM ${CXXFLAGS} $< | sed 's,\(^.*\):,${OBJSDIR}\1 $@:,' > $@
 
 # rule to make an object file from a .cpp
-${OBJSDIR}%.o: %.cpp
+${OBJSDIR}%.o: %.cpp | ${BLDDIRS}
        ${Q1}echo "${CXX}: $@"
        ${Q2}${CXX} ${CXXFLAGS} -c -o $@ $<