+# Create $O, $B, $L and $(INCLUDE_DIR) directories and replicate the directory
+# structure of the project into $O. Create one symlink "last" to the current
+# build directory.
+#
+# NOTE: the second mkdir can yield no arguments if the project don't have any
+# subdirectories, that's why the current directory "." is included, so it
+# won't show an error message in case of no subdirectories.
+setup_build_dir__ := $(shell \
+ mkdir -p $O $B $L $(INCLUDE_DIR); \
+ mkdir -p . $(addprefix $O,$(patsubst $T%,%,\
+ $(shell find $T -type d -not -path '$D*'))); \
+ test -L $D/last || ln -s $F $D/last )
+
+
+# Automatic rebuilding when flags or commands changes
+######################################################
+
+# Re-compile C files if one of this variables changes
+COMPILE.c.FLAGS += $(CC) ~ $(CPPFLAGS) ~ $(CFLAGS) ~ $(TARGET_ARCH) ~ $(prefix)
+
+# Re-compile C++ files if one of this variables changes
+COMPILE.cpp.FLAGS += $(CXX) ~ $(CPPFLAGS) ~ $(CXXFLAGS) ~ $(TARGET_ARCH) \
+ ~ $(prefix)
+
+# Re-link binaries and libraries if one of this variables changes
+LINK.o.FLAGS += $(LD) ~ $(LDFLAGS) ~ $(TARGET_ARCH)
+