Prepare dph for a vectInfoVar type change
[packages/dph.git] / ghc.mk
1
2 ifneq "$(libraries/dph_NOT_NEEDED)" "YES"
3
4 DPH_DIR = libraries/dph
5
6 # -----------------------------------------------------------------------------
7 # Backend packages.
8 #
9 # These are the packages that we want to compile and install by default.
10 # This doesn't include the dph-examples, dph-test or dph-buildbot, as most
11 # end users won't want these.
12 #
13 DPH_PACKAGES = \
14 dph-base \
15 dph-prim-interface \
16 dph-prim-seq \
17 dph-prim-par \
18 dph-lifted-base \
19 dph-lifted-boxed \
20 dph-lifted-copy \
21 dph-lifted-vseg
22
23
24 # -----------------------------------------------------------------------------
25 # Cleaning rules.
26 #
27 # Generate rules to clean each of the DPH_PACKAGES.
28 #
29 .PHONY: all_$(DPH_DIR)
30 all_$(DPH_DIR) : $(foreach pkg, $(DPH_PACKAGES), all_$(DPH_DIR)/$(pkg))
31
32 clean : clean_$(DPH_DIR)
33 .PHONY: clean_$(DPH_DIR)
34 clean_$(DPH_DIR) : $(foreach pkg, $(DPH_PACKAGES), clean_$(DPH_DIR)/$(pkg))
35 distclean : clean_$(DPH_DIR)
36
37 define dph_package
38 # $1 = package name
39 ifneq "$(CLEANING)" "YES"
40 .PHONY: $(DPH_DIR)/$1
41 $(DPH_DIR)/$1 : all_$(DPH_DIR)/$1
42 endif
43 endef
44
45 $(foreach pkg, $(DPH_PACKAGES), $(eval $(call dph_package,$(pkg))))
46
47
48 # -----------------------------------------------------------------------------
49 # Template Haskell dependencies.
50 #
51 # The dph-lifted-copy package contains some Template Haskell code in TH.Repr.
52 # When compiling modules that use TH.Repr, we will try to run some TH,
53 # which means using the vanilla TH.Repr object files. If we are not
54 # building in the vanilla way then we need to be sure that the vanilla
55 # object files exist. These deps take care of that for us.
56 #
57 define dph_th_deps
58 # $1 = way
59 ifeq "$1" "$${GHCI_WAY}"
60 # Do nothing: This way is the GHCi way
61 else ifeq "$1 $${GHCI_WAY} $${DYNAMIC_TOO}" "v dyn YES"
62 # Do nothing: This way is built at the same time as the GHCi way
63 else ifeq "$1 $${GHCI_WAY} $${DYNAMIC_TOO}" "dyn v YES"
64 # Do nothing: This way is built at the same time as the GHCi way
65 else
66 libraries/dph/dph-lifted-copy/dist-install/build/Data/Array/Parallel/Lifted/TH/Repr.$$($1_osuf): libraries/dph/dph-lifted-copy/dist-install/build/Data/Array/Parallel/Lifted/TH/Repr.$${$${GHCI_WAY}_osuf}
67 libraries/dph/dph-lifted-copy/dist-install/build/Data/Array/Parallel/Lifted/PArray.$${$1_osuf} : libraries/dph/dph-lifted-copy/dist-install/build/Data/Array/Parallel/Lifted/PArray.$${$${GHCI_WAY}_osuf}
68 endif
69
70 # The following modules use Template Haskell, or contain ANN pragmas. Both of
71 # these features use compile-time evaluation. During this evaluation we may
72 # need to load the dph-prim-* packages, but if they haven't been build yet the
73 # compilation will die. This results in a build race, where the compilation
74 # will succeed or not depending on whether another make thread has already
75 # completed building the dph-prim-* packages.
76 #
77 # Note that the GHC build system does NOT respect the package dependencies
78 # present in .cabal files. Even though the dph-lifted-*.cabal files list
79 # the dph-prim-* packages as dependencies, these dependencies are silently
80 # ignored.
81 #
82 # The hack-around is to add the following explicit dependencies:
83 # The .o for every module that uses Template Haskell or annotations must
84 # must depend on the dph-prim-* GHCI libraries, so that they can be
85 # loaded at compile time.
86 #
87 # If the dependencies are wrong you will get a build race that can result in
88 # the following error:
89 #
90 # "inplace/bin/ghc-stage2" ... -o .../Data/Array/Parallel/Lifted/PArray.dyn_o
91 # Loading package dph-prim-seq-0.4.0 ... linking ... done.
92 # 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
93 # (libHSdph-prim-seq-0.4.0-ghc6.13.20091222.so: cannot open shared object file: No such file or directory)
94 #
95
96 # -- modules with TH or ANN in dph-lifted-copy
97 libraries/dph/dph-lifted-copy/dist-install/build/Data/Array/Parallel/Lifted/TH/Repr.$$($1_osuf): \
98 $$(libraries/dph/dph-base_dist-install_GHCI_LIB) \
99 $$(libraries/dph/dph-prim-par_dist-install_GHCI_LIB) \
100 $$(libraries/dph/dph-prim-seq_dist-install_GHCI_LIB) \
101 $$(libraries/dph/dph-prim-interface_dist-install_GHCI_LIB)
102
103 libraries/dph/dph-lifted-copy/dist-install/build/Data/Array/Parallel/PArray/PData.$${$1_osuf} : \
104 $$(libraries/dph/dph-base_dist-install_GHCI_LIB) \
105 $$(libraries/dph/dph-prim-par_dist-install_GHCI_LIB) \
106 $$(libraries/dph/dph-prim-seq_dist-install_GHCI_LIB) \
107 $$(libraries/dph/dph-prim-interface_dist-install_GHCI_LIB)
108
109 libraries/dph/dph-lifted-copy/dist-install/build/Data/Array/Parallel/PArray/Base.$${$1_osuf} : \
110 $$(libraries/dph/dph-base_dist-install_GHCI_LIB) \
111 $$(libraries/dph/dph-prim-par_dist-install_GHCI_LIB) \
112 $$(libraries/dph/dph-prim-seq_dist-install_GHCI_LIB) \
113 $$(libraries/dph/dph-prim-interface_dist-install_GHCI_LIB)
114
115 # -- modules with TH or ANN in dph-lifted-vseg
116 libraries/dph/dph-lifted-vseg/dist-install/build/Data/Array/Parallel/PArray/PData/Base.$${$1_osuf} : \
117 $$(libraries/dph/dph-base_dist-install_GHCI_LIB) \
118 $$(libraries/dph/dph-prim-par_dist-install_GHCI_LIB) \
119 $$(libraries/dph/dph-prim-seq_dist-install_GHCI_LIB) \
120 $$(libraries/dph/dph-prim-interface_dist-install_GHCI_LIB) \
121 $$(libraries/dph/dph-lifted-base_dist-install_GHCI_LIB)
122
123 ifeq "$$(libraries/dph/dph-base_dist-install_GHCI_LIB)" ""
124 ifeq "$(GhcProfiled)" "YES"
125 $$(error Cannot build profiled GHC with DPH; try deleting libraries/dph and trying again)
126 endif
127 $$(error dph_th_deps($1): libraries/dph/dph-base_dist-install_GHCI_LIB not defined!)
128 endif
129
130 endef
131
132 # Instantiate the above dph_th_deps definition for each build way.
133 ifneq "$(CLEANING)" "YES"
134 $(foreach way, $(GhcLibWays), $(eval $(call dph_th_deps,$(way))))
135 endif
136
137 endif
138