-# C and S files are built the "v" vanlilla way and possibly also the "dyn" way.
-$(call c-objs,$1,$2,v)
-$(call distdir-opts,$1,$2,$3)
-$(call c-suffix-rules,$1,$2,v,YES)
-ifeq "$(BuildSharedLibs)" "YES"
+$(call hs-sources,$1,$2)
+$(call c-sources,$1,$2)
+$(call includes-sources,$1,$2)
+
+# --- DEPENDENCIES
+# We always have the dependency rules available, as we need to know
+# how to build hsc2hs's dependency file in phase 0
+$(call build-dependencies,$1,$2,$3)
+ifneq "$(phase)" "0"
+# From phase 1 we actually include the dependency files for the
+# bootstrapping stuff
+ifeq "$3" "0"
+$(call include-dependencies,$1,$2,$3)
+else ifeq "$(phase)" ""
+# In the final phase, we also include the dependency files for
+# everything else
+$(call include-dependencies,$1,$2,$3)
+endif
+endif
+
+# Now generate all the build rules for each way in this directory:
+$$(foreach way,$$($1_$2_WAYS),$$(eval \
+ $$(call c-objs,$1,$2,$$(way)) \
+ $$(call c-suffix-rules,$1,$2,$$(way),YES) \
+ $$(call cmm-objs,$1,$2,$$(way)) \
+ $$(call cmm-suffix-rules,$1,$2,$$(way)) \
+ $$(call build-package-way,$1,$2,$$(way),$3) \
+ ))
+
+# C and S files are possibly built the "dyn" way.
+ifeq "$$(BuildSharedLibs)" "YES"