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