+$1_$2_LINK_WITH_GCC = NO
+ifeq "$$(BootingFromHc)" "YES"
+$1_$2_LINK_WITH_GCC = YES
+endif
+
+ifeq "$$($1_$2_v_HS_OBJS)" ""
+# We don't want to link the GHC RTS into C-only programs. There's no
+# point, and it confuses the test that all GHC-compiled programs
+# were compiled with the right GHC.
+$1_$2_GHC_LD_OPTS = -no-auto-link-packages -no-hs-main
+endif
+
+ifneq "$$(BINDIST)" "YES"
+# The quadrupled $'s here are because the _v_LIB variables aren't
+# necessarily set when this part of the makefile is read
+$1/$2/build/tmp/$$($1_$2_PROG) : \
+ $$(foreach dep,$$($1_$2_DEP_NAMES),\
+ $$(if $$(filter ghc,$$(dep)),\
+ $(if $(filter 0,$3),$$(compiler_stage1_v_LIB),\
+ $(if $(filter 1,$3),$$(compiler_stage2_v_LIB),\
+ $(if $(filter 2,$3),$$(compiler_stage2_v_LIB),\
+ $$(error Bad build stage)))),\
+ $$$$(libraries/$$(dep)_dist-$(if $(filter 0,$3),boot,install)_v_LIB)))
+
+ifeq "$$($1_$2_LINK_WITH_GCC)" "NO"
+$1/$2/build/tmp/$$($1_$2_PROG) : $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) | $$$$(dir $$$$@)/.
+ "$$($1_$2_HC)" -o $$@ $$($1_$2_v_ALL_HC_OPTS) $$(LD_OPTS) $$($1_$2_GHC_LD_OPTS) $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES))
+else
+$1/$2/build/tmp/$$($1_$2_PROG) : $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) | $$$$(dir $$$$@)/.
+ "$$(CC)" -o $$@ $$($1_$2_v_ALL_CC_OPTS) $$(LD_OPTS) $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) $$($1_$2_v_EXTRA_CC_OPTS) $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES))
+endif