dph-lifted-vseg: shift reference implementation harness to its own module and cleanup
[packages/dph.git] / ghc.mk
1 DPH_DIR = libraries/dph
2 DPH_WAYS = par seq
3
4 # Backend packages that are only compiled in one way.
5 DPH_BASE_PACKAGES = \
6 dph-base \
7 dph-prim-interface \
8 dph-prim-seq \
9 dph-prim-par
10
11 # Frontend packages are compiled multiple times against the different backend packages.
12 DPH_PACKAGES = \
13 $(DPH_BASE_PACKAGES) \
14 $(foreach way, $(DPH_WAYS), dph-lifted-copy-$(way))
15
16
17 # -----------------------------------------------------------------------------
18 # Create stubs for the front-end packages.
19 define dph_create
20
21 ifneq "$(BINDIST)" "YES"
22 ifneq "$(CLEANING)" "YES"
23 $(DPH_DIR)/dph-$1/dph-$1.cabal : $(DPH_DIR)/dph-common/ghc.mk $(DPH_DIR)/dph-common/GNUmakefile $(DPH_DIR)/dph-common/dph-common.cabal
24 $$(RM) $$(RM_OPTS_REC) $(DPH_DIR)/dph-$1 $(DPH_DIR)/dph-$1.tmp
25 mkdir $(DPH_DIR)/dph-$1.tmp
26 cp $(DPH_DIR)/dph-common/Setup.hs $(DPH_DIR)/dph-$1.tmp/Setup.hs
27 cp $(DPH_DIR)/dph-common/LICENSE $(DPH_DIR)/dph-$1.tmp/LICENSE
28
29 sed "s/DPHWAY/$1/g" $(DPH_DIR)/dph-common/dph-common.cabal > $(DPH_DIR)/dph-$1.tmp/dph-$1.cabal
30 sed "s/common/$1/g" $(DPH_DIR)/dph-common/ghc.mk > $(DPH_DIR)/dph-$1.tmp/ghc.mk
31 sed "s/common/$1/g" $(DPH_DIR)/dph-common/GNUmakefile > $(DPH_DIR)/dph-$1.tmp/GNUmakefile
32
33 mv $(DPH_DIR)/dph-$1.tmp $(DPH_DIR)/dph-$1
34
35 $(DPH_DIR)/dph-$1/ghc.mk : $(DPH_DIR)/dph-$1/dph-$1.cabal
36 $(DPH_DIR)/dph-$1/GNUmakefile : $(DPH_DIR)/dph-$1/dph-$1.cabal
37 endif
38 endif
39
40 endef
41
42 $(foreach way, $(DPH_WAYS), $(eval $(call dph_create,$(way))))
43
44
45 # -----------------------------------------------------------------------------
46 .PHONY: all_$(DPH_DIR)
47 all_$(DPH_DIR) : $(foreach pkg, $(DPH_PACKAGES), all_$(DPH_DIR)/$(pkg))
48
49 clean : clean_$(DPH_DIR)
50 .PHONY: clean_$(DPH_DIR)
51 clean_$(DPH_DIR) : $(foreach pkg, $(DPH_BASE_PACKAGES), clean_$(DPH_DIR)/$(pkg))
52 $(RM) $(RM_OPTS_REC) $(foreach way, $(DPH_WAYS), $(DPH_DIR)/dph-$(way))
53
54 distclean : clean_$(DPH_DIR)
55
56 define dph_package
57 ifneq "$(CLEANING)" "YES"
58 .PHONY: $(DPH_DIR)/$1
59 $(DPH_DIR)/$1 : all_$(DPH_DIR)/$1
60 endif
61 endef
62
63 $(foreach pkg, $(DPH_PACKAGES), $(eval $(call dph_package,$(pkg))))
64
65
66
67 # -----------------------------------------------------------------------------
68 # When compiling modules that use TH.Repr, we will try to run some TH,
69 # which means using the vanilla TH.Repr object files. If we are not
70 # building in the vanilla way then we need to be sure that the vanilla
71 # object files exist. These deps take care of that for us.
72 #
73 define dph_th_deps
74 # $1 = way $2 = par/seq
75 ifneq "$1" "v"
76 libraries/dph/dph-$2/dist-install/build/Data/Array/Parallel/Lifted/TH/Repr.$$($1_osuf): libraries/dph/dph-$2/dist-install/build/Data/Array/Parallel/Lifted/TH/Repr.o
77 libraries/dph/dph-$2/dist-install/build/Data/Array/Parallel/Lifted/PArray.$${$1_osuf} : libraries/dph/dph-$2/dist-install/build/Data/Array/Parallel/Lifted/PArray.$${v_osuf}
78 endif
79
80 # HACKS -----------------------------------------------------------------------
81 # The following modules use Template Haskell, or contain ANN pragmas. Both of
82 # these features use compile-time evaluation. During this evaluation we may
83 # need to load the dph-prim-* packages, but if they haven't been build yet the
84 # compilation will die. This results in a build race, where the compilation
85 # will succeed or not depending on whether another make thread has already
86 # completed building the dph-prim-* packages.
87 #
88 # Note that the GHC build system does NOT respect the package dependencies
89 # present in .cabal files. Even though the dph-common.cabal file lists
90 # the dph-prim-* packages as dependencies, these dependencies are silently
91 # ignored.
92 #
93 # The hack-around is to add the following explicit dependencies:
94 # The .o for every module that uses Template Haskell or annotations must
95 # must depend on the dph-prim-* GHCI libraries, so that they can be
96 # loaded at compile time.
97 #
98 # If the dependencies are wrong you will get a build race that can result in
99 # the following error:
100 #
101 # "inplace/bin/ghc-stage2" ... -o .../Data/Array/Parallel/Lifted/PArray.dyn_o
102 # Loading package dph-prim-seq-0.4.0 ... linking ... done.
103 # Loading package dph-prim-par-0.4.0 ... <command line>: can't load .so/.DLL for: HSdph-prim-par-0.4.0-ghc6.13.20091222
104 # (libHSdph-prim-seq-0.4.0-ghc6.13.20091222.so: cannot open shared object file: No such file or directory)
105 #
106 libraries/dph/dph-$2/dist-install/build/Data/Array/Parallel/Lifted/TH/Repr.$$($1_osuf): \
107 $$(libraries/dph/dph-base_dist-install_GHCI_LIB) \
108 $$(libraries/dph/dph-prim-par_dist-install_GHCI_LIB) \
109 $$(libraries/dph/dph-prim-seq_dist-install_GHCI_LIB) \
110 $$(libraries/dph/dph-prim-interface_dist-install_GHCI_LIB)
111
112 libraries/dph/dph-$2/dist-install/build/Data/Array/Parallel/PArray/PData.$${$1_osuf} : \
113 $$(libraries/dph/dph-base_dist-install_GHCI_LIB) \
114 $$(libraries/dph/dph-prim-par_dist-install_GHCI_LIB) \
115 $$(libraries/dph/dph-prim-seq_dist-install_GHCI_LIB) \
116 $$(libraries/dph/dph-prim-interface_dist-install_GHCI_LIB)
117
118 libraries/dph/dph-$2/dist-install/build/Data/Array/Parallel/PArray/Base.$${$1_osuf} : \
119 $$(libraries/dph/dph-base_dist-install_GHCI_LIB) \
120 $$(libraries/dph/dph-prim-par_dist-install_GHCI_LIB) \
121 $$(libraries/dph/dph-prim-seq_dist-install_GHCI_LIB) \
122 $$(libraries/dph/dph-prim-interface_dist-install_GHCI_LIB)
123
124 ifeq "$$(libraries/dph/dph-base_dist-install_GHCI_LIB)" ""
125 $$(error dph_th_deps($1,$2): libraries/dph/dph-base_dist-install_GHCI_LIB not defined!)
126 endif
127
128 endef
129
130 ifneq "$(CLEANING)" "YES"
131 $(foreach way, $(GhcLibWays), $(eval $(call dph_th_deps,$(way),seq)))
132 $(foreach way, $(GhcLibWays), $(eval $(call dph_th_deps,$(way),par)))
133 endif