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