d8e6b4224a21a74e495593d6ffa520f0b69d97c9
[ghc-hetmet.git] / rules / hs-sources.mk
1
2 define hs-sources # args: $1 = dir, $2 = distdir
3
4 ifeq "$$($1_$2_HS_SRC_DIRS)" ""
5 $1_$2_HS_SRC_DIRS = .
6 endif
7
8 # Here we collect all the .hs/.lhs source files that we can find.  If
9 # we can't find a Haskell source file for a given module, then presumably
10 # it can be generated by preprocessing something (.hsc, .y, .x etc.), so
11 # we depend on dist/build/Foo.hs in anticipation that the implicit rules
12 # will put the preprocessed source file there.
13 #
14 # NB. use :=, we only want this thing evaluated once.
15 #
16 $1_$2_HS_SRCS := $$(foreach file,$$($1_$2_SLASH_MODS),\
17                  $$(firstword \
18                    $$(wildcard \
19                      $$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
20                         $1/$$(dir)/$$(file).hs $1/$$(dir)/$$(file).lhs)) \
21                    $1/$2/build/$$(file).hs))
22
23 # .hs-boot files must be in the same place as the .hs file they go
24 # with (GHC assumes this).  When we preprocess a source file, and
25 # that module has a .hs-boot or .lhs-boot file, we must arrange to
26 # copy the file into the distdir so that it ends up alongside the
27 # preprocessed .hs file.  This complicated macro figures out for which
28 # files we need to do this, so we can add them as dependencies of the
29 # .depend file rule.
30 #
31 # for each .hs file in the build dir,
32 # if there is a .hs-boot or .lhs-boot file for it in a source dir,
33 # we want that file in the build dir.
34 #
35 # NB. use :=, we only want this thing evaluated once.
36 #
37 $1_$2_HS_BOOT_SRCS := $$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
38                        $$(subst $1/$$(dir),$1/$2/build,\
39                         $$(wildcard \
40                          $$(subst $1/$2/build,$1/$$(dir),\
41                           $$(foreach file,\
42                            $$(filter $1/$2/build%,$$($1_$2_HS_SRCS)),\
43                            $$(patsubst %.hs,%.hs-boot,$$(file)) \
44                            $$(patsubst %.hs,%.lhs-boot,$$(file)))))))
45
46 endef