Make $(my-dir) fail if it's called after including $(CLEAR_VARS)
diff --git a/core/definitions.mk b/core/definitions.mk
index a16ce03..297e6b7 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -109,7 +109,14 @@
 
 # Figure out where we are.
 define my-dir
-$(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST),$(MAKEFILE_LIST))))
+$(strip \
+  $(eval md_file_ := $$(lastword $$(MAKEFILE_LIST))) \
+  $(if $(filter $(CLEAR_VARS),$(md_file_)), \
+    $(error LOCAL_PATH must be set before including $$(CLEAR_VARS)) \
+   , \
+    $(patsubst %/,%,$(dir $(md_file_))) \
+   ) \
+ )
 endef
 
 ###########################################################