2 define hs-sources # args: $1 = dir, $2 = distdir
4 ifeq "$$($1_$2_HS_SRC_DIRS)" ""
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.
14 # NB. use :=, we only want this thing evaluated once.
16 $1_$2_HS_SRCS := $$(foreach file,$$($1_$2_SLASH_MODS),\
19 $$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
20 $1/$$(dir)/$$(file).hs $1/$$(dir)/$$(file).lhs)) \
21 $1/$2/build/$$(file).hs))
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
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.
35 # NB. use :=, we only want this thing evaluated once.
37 $1_$2_HS_BOOT_SRCS := $$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
38 $$(subst $1/$$(dir),$1/$2/build,\
40 $$(subst $1/$2/build,$1/$$(dir),\
42 $$(filter $1/$2/build%,$$($1_$2_HS_SRCS)),\
43 $$(patsubst %.hs,%.hs-boot,$$(file)) \
44 $$(patsubst %.hs,%.lhs-boot,$$(file)))))))