update submodules for GHC.HetMet.GArrow -> Control.GArrow renaming
[ghc-hetmet.git] / rules / build-prog.mk
index 99b24de..99093d3 100644 (file)
@@ -21,6 +21,7 @@
 
 define build-prog
 $(call trace, build-prog($1,$2,$3))
+$(call profStart, build-prog($1,$2,$3))
 # $1 = dir
 # $2 = distdir
 # $3 = GHC stage to use (0 == bootstrapping compiler)
@@ -40,6 +41,7 @@ $(call clean-target,$1,$2,$1/$2)
 ifneq "$$($1_$2_NOT_NEEDED)" "YES"
 $$(eval $$(call build-prog-helper,$1,$2,$3))
 endif
+$(call profEnd, build-prog($1,$2,$3))
 endef
 
 
@@ -54,6 +56,8 @@ endif
 
 $(call package-config,$1,$2,$3)
 
+$1_$2_depfile_base = $1/$2/build/.depend
+
 ifeq "$$($1_$2_INSTALL_INPLACE)" "NO"
 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
 $1_$2_INPLACE = $$(error $1_$2 should not be installed inplace, but INPLACE var evaluated)
@@ -73,44 +77,13 @@ endif
 endif
 endif
 
-########################################
-ifeq "$$($1_$2_CONFIGURE_PHASE)" ""
-$$(error No configure phase for $1_$2)
-else ifeq "$$($1_$2_CONFIGURE_PHASE)" "$$(phase)"
-
-ifeq "$$(DEBUG)" "YES"
-$$(warning $1/$2 configure phase)
-endif
-
-ifneq "$$(BINDIST)" "YES"
-$(call build-package-data,$1,$2,$3)
-endif
-
 ifeq "$$($1_$2_USES_CABAL)" "YES"
+$(call build-package-data,$1,$2,$3)
 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
+ifeq "$3" "0"
 include $1/$2/package-data.mk
-endif
-endif
-
-# INPLACE_BIN might be empty if we're distcleaning
-ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
-ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
-$$($1_$2_INPLACE) :
-       $$(error $1_$2 is configuring, but trying to build $$($1_$2_INPLACE)")
-endif
-endif
-
-else ifeq "$$(phase_$$($1_$2_CONFIGURE_PHASE)_or_later)" "YES"
-
-ifeq "$$(DEBUG)" "YES"
-$$(warning $1/$2 build phase)
-endif
-
-ifeq "$$($1_$2_USES_CABAL)" "YES"
-ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
+else ifeq "$(phase)" "final"
 include $1/$2/package-data.mk
-ifeq "$$($1_$2_VERSION)" ""
-$$(error No version for $1_$2 found)
 endif
 endif
 endif
@@ -127,39 +100,13 @@ $$($1_$2_INPLACE) : $1/$2/build/tmp/$$($1_$2_PROG) | $$$$(dir $$$$@)/.
 endif
 endif
 
-else
-
-ifeq "$$(DEBUG)" "YES"
-$$(warning $1/$2 disabled phase)
-endif
-
-# INPLACE_BIN might be empty if we're distcleaning
-ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
-ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
-$$($1_$2_INPLACE) :
-       $$(error $1_$2 is disabled, but trying to build $$($1_$2_INPLACE)")
-endif
-endif
-
-endif
-########################################
-
 $(call shell-wrapper,$1,$2)
 
-ifeq "$$(phase_$$($1_$2_CONFIGURE_PHASE)_done)" "YES"
-
-ifneq "$$(BINDIST)" "YES"
 $1_$2_WAYS = v
 
 $(call hs-sources,$1,$2)
 $(call c-sources,$1,$2)
 
-# --- DEPENDENCIES
-
-$1_$2_depfile_base = $1/$2/build/.depend
-
-$(call build-dependencies,$1,$2,$3)
-
 # --- IMPLICIT RULES
 
 # Just the 'v' way for programs
@@ -192,20 +139,24 @@ ifeq "$$($1_$2_v_HS_OBJS)" ""
 $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
-ifeq "$3" "0"
-$1/$2/build/tmp/$$($1_$2_PROG) : $$(foreach dep,$$($1_$2_DEP_NAMES),$$$$(libraries/$$(dep)_dist-boot_v_LIB))
-else
-$1/$2/build/tmp/$$($1_$2_PROG) : $$(foreach dep,$$($1_$2_DEP_NAMES),$$$$(libraries/$$(dep)_dist-install_v_LIB))
-endif
+$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))
+       "$$($1_$2_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
 
 # Note [lib-depends] if this program is built with stage1 or greater, we
@@ -222,15 +173,13 @@ endif
 $1/$2/build/tmp/$$($1_$2_PROG) : $$(ALL_STAGE1_LIBS) $$(ALL_RTS_LIBS) $$(OTHER_LIBS)
 endif
 endif
+endif
 
 ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
 $(call all-target,$1_$2,$$($1_$2_INPLACE))
 endif
 $(call clean-target,$1,$2_inplace,$$($1_$2_INPLACE))
 
-# touch is necessary; cp doesn't update the file time.
-endif
-
 ifeq "$$($1_$2_INSTALL)" "YES"
 ifeq "$$($1_$2_TOPDIR)" "YES"
 INSTALL_TOPDIRS += $1/$2/build/tmp/$$($1_$2_PROG)
@@ -239,6 +188,6 @@ INSTALL_BINS += $1/$2/build/tmp/$$($1_$2_PROG)
 endif
 endif
 
-endif # package-data.mk exists
+$(call dependencies,$1,$2,$3)
 
 endef