If SUBDIRS is set manually on the command line, the contents of
.tmp_versions are not deleted before descending and can accumulate
stale entries. Print a warning if that case is detected, but deal with
it gracefully.
#
-modules := $(shell cd $(MODVERDIR); cat *.mod)
+__modules := $(shell cd $(MODVERDIR); cat *.mod)
+modules := $(patsubst %.o,%.ko,$(wildcard $(__modules:.ko=.o)))
+
+ifneq ($(filter-out $(modules),$(__modules)),)
+ $(warning *** Uh-oh, you have stale module entries. You messed with SUBDIRS, don't complain if something goes wrong.)
+endif
__modversions: $(modules)
@: