-# determine the dependencies of a given source and language, but route link
-# issues to /dev/null since we will generate them later
-# can pass an optional third argument for additional opts
-define SRC_LANG_DEPS =
-$(shell $($2_C) -MM -MG $(if $3,-I$3) $($2_FLAGS) $1 2> /dev/null\
-| sed -e 's@^.*\.o: @@' -e 's@\\@@')
-endef
-
-# create a list of module object archives associated with the given files,
-# if any, filtering out any drivers or non-module objects
-define FLIST_MODULEOBJS =
-$(sort $(shell echo $(filter-out .%,$(filter-out $(DRIVER_DIR)/%,$1))\
- | sed -e 's@^\([a-Z\-\+]*\)/*@\1.$(c_OBJ)@g' ))
-endef
-
-# establish a dependency rule given a source and language. if passed a
-# directory name as the third argument, will prefix all header files in the
-# dependency with the local lib
-define SRC_LANG_DEPRULE =
-$(eval $1_$2_DEPS := $(call SRC_LANG_DEPS,$1,$2,$3))
-$(foreach hdr,$(filter %.h,$($1_$2_DEPS)),\
-$(if $(word 2,$(subst /, ,$(hdr))),,\
-$(eval $1_$2_DEPS := $($1_$2_DEPS:$(hdr)=$3/$(hdr)))\
-))
-$(basename $1).$($2_OBJ): $($1_$2_DEPS)
+# Given a source and a language, generate a rule to make the object. The second
+# invocation of gcc per file lists only its local includes, and filters out
+# anything already caught. Anything remaining should be considered to be
+# available in the current working directory of the source file(i.e. if you
+# '#include "something.h"' in 'mymodule/horseradish.c', you would expect to
+# include 'mymodule/something.h'. this check lets that happen), otherwise it is
+# some kind of user error
+define SRC_LANG_RULE =
+$(eval MOD := $(firstword $(subst /, ,$(dir $1))))\
+$(eval DEPS := $(filter $(MODULES:%=%/%),$(shell $($2_C) -I$(MOD) -M -MG $1 2> /dev/null)))\
+$(eval LOST := $(filter-out %: $(MODULES:%=%/%),$(shell $($2_C) -I$(MOD) -MM -MG $1 2> /dev/null)))\
+$(eval DEPS += $(LOST:%=$(dir $1)%))\
+$(if $($1),,$(eval $1 := t)\
+$(basename $1).$($2_OBJ): $(DEPS)
+ $($2_C) $$($2_FLAGS) -I$(MOD) -c -o $$@ $1
+)