[PATCH] Allow for file moves in dependency generation

The dependency generation was causing problems whenever I wanted to move a
file from the NQ or QW dirs to the shared include dir. This problem has been
solved before by others smarter than myself, so I nabbed the solution from
http://make.paulandlesley.org/autodep.html.

diff -urN -X exclude a/Makefile head/Makefile
--- a/Makefile	2006-06-10 21:34:53.000000000 +0930
+++ head/Makefile	2006-06-13 20:35:55.000000000 +0930
@@ -195,7 +195,19 @@
 	@$(cmd_mkdir);
 endef
 
-cmd_cc_dep_c = $(CC) -MM -MT $@ $(CPPFLAGS) -o $(@D)/.$(@F).d $<
+# cmd_fixdep => Turn all pre-requisites into targets with no commands, to
+# prevent errors when moving files around between builds (e.g. from NQ or QW
+# dirs to the common dir.)
+cmd_fixdep = \
+	cp $(@D)/.$(@F).d $(@D)/.$(@F).d.tmp ; \
+	sed -e 's/\#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' -e '/^$$/ d' \
+	    -e 's/$$/ :/' < $(@D)/.$(@F).d.tmp >> $(@D)/.$(@F).d ; \
+	rm -f $(@D)/.$(@F).d.tmp
+
+cmd_cc_dep_c = \
+	$(CC) -MM -MT $@ $(CPPFLAGS) -o $(@D)/.$(@F).d $< ; \
+	$(cmd_fixdep)
+
 quiet_cmd_cc_o_c = '  CC      $@'
       cmd_cc_o_c = $(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
 
@@ -205,7 +217,10 @@
 	@$(cmd_cc_o_c);
 endef
 
-cmd_cc_dep_rc = $(CC) -x c-header -MM -MT $@ $(CPPFLAGS) -o $(@D)/.$(@F).d $<
+cmd_cc_dep_rc = \
+	$(CC) -x c-header -MM -MT $@ $(CPPFLAGS) -o $(@D)/.$(@F).d $< ; \
+	$(cmd_fixdep)
+
 quiet_cmd_windres_res_rc = '  WINDRES $@'
       cmd_windres_res_rc = windres -I $(<D) -i $< -O coff -o $@
 
