$(Q)$(rule_cmd)
endef
-# TODO: Include __goals.omk.inc only in the subtree
--include $(shell true; find $(BUILD_OMK_DIR) -name '*.omk.inc') # `true' is a hack for MinGW
+# Goals are included only for this directory and all subdirectories
+# TODO: What if a target depends on a library from different
+# subtree. Then the library would be remade even if it should not
+# because its __goals.omk.inc is not included.
+-include $(shell true; find $(OMK_WORK_DIR) -name '__goals.omk.inc') # `true' is a hack for MinGW
+
+# Definition of rules is included everywhere to allow multi-directory
+# targets.
+-include $(shell true; find $(BUILD_OMK_DIR) -name '*.omk.inc' -not -name '__goals.omk.inc') # `true' is a hack for MinGW
+
# FIXME: Disable automatic remake of included files
$(foreach rule,$(prepared_rules),$(eval $(call build_rule,$(rule))))