Add some missing dependencies
[ghc-hetmet.git] / rules / build-package.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://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
9 #      http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
10 #
11 # -----------------------------------------------------------------------------
12
13
14 # Build a package with the stage-1 compiler, multiple ways.  A typical
15 # libraries/foo/ghc.mk will look like this:
16 #
17 # $(eval $(call build-package,libraries/base,dist-install))
18 #
19 # The package metadata is generated from the .cabal file and placed in
20 # package-data.mk.  It will look something like this:
21 #
22 # libraries/base_dist_MODULES = GHC.Base Data.Tuple ...
23 # libraries/base_dist_PACKAGE = base
24 # libraries/base_dist_VERSION = 4.0.0.0
25 # libraries/base_dist_HC_OPTS = -package ghc-prim-0.1.0.0 -XRank2Types ...
26 # libraries/base_dist_C_SRCS  = cbits/PrelIOUtils.c ...
27 # libraries/base_dist_S_SRCS  = cbits/foo.S ...
28 # libraries/base_dist_CC_OPTS = -Iinclude ...
29 # libraries/base_dist_LD_OPTS = -package ghc-prim-0.1.0.0
30
31 define build-package
32 $(call trace, build-package($1,$2,$3))
33 # $1 = dir
34 # $2 = distdir
35 # $3 = GHC stage to use (0 == bootstrapping compiler)
36
37 ifeq "$$(findstring $3,0 1 2)" ""
38 $$(error $1/$2: stage argument to build-package should be 0, 1, or 2)
39 endif
40
41 $(call clean-target,$1,$2,$1/$2)
42
43 distclean : clean_$1_$2_config
44
45 maintainer-clean : distclean
46
47 .PHONY: clean_$1_$2_config
48 clean_$1_$2_config:
49         "$$(RM)" $$(RM_OPTS) $1/config.log $1/config.status $1/include/Hs*Config.h
50         "$$(RM)" $$(RM_OPTS_REC) $1/autom4te.cache
51
52 ifneq "$$($1_$2_NOT_NEEDED)" "YES"
53 $$(eval $$(call build-package-helper,$1,$2,$3))
54 endif
55 endef
56
57
58 define build-package-helper
59 # $1 = dir
60 # $2 = distdir
61 # $3 = GHC stage to use (0 == bootstrapping compiler)
62
63 # --- CONFIGURATION
64
65 $(call package-config,$1,$2,$3)
66
67 # Bootstrapping libs are only built one way
68 ifeq "$3" "0"
69 $1_$2_WAYS = v
70 else
71 $1_$2_WAYS = $$(GhcLibWays)
72 endif
73
74 # We must use a different dependency file if $(GhcLibWays) changes, so
75 # encode the ways into the name of the file.
76 $1_$2_WAYS_DASHED = $$(subst $$(space),,$$(patsubst %,-%,$$(strip $$($1_$2_WAYS))))
77 $1_$2_depfile_base = $1/$2/build/.depend$$($1_$2_WAYS_DASHED)
78
79 $(call build-package-data,$1,$2,$3)
80 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
81 ifeq "$3" "0"
82 include $1/$2/package-data.mk
83 else ifeq "$(phase)" ""
84 include $1/$2/package-data.mk
85 endif
86 endif
87
88 # We don't bother splitting the bootstrap packages (built with stage 0)
89 ifeq "$$($1_$2_SplitObjs)" ""
90 ifeq "$$(SplitObjs) $3" "YES 1"
91 $1_$2_SplitObjs = YES
92 else
93 $1_$2_SplitObjs = NO
94 endif
95 endif
96
97 $(call hs-sources,$1,$2)
98 $(call c-sources,$1,$2)
99 $(call includes-sources,$1,$2)
100
101 # --- DEPENDENCIES
102 # We always have the dependency rules available, as we need to know
103 # how to build hsc2hs's dependency file in phase 0
104 $(call build-dependencies,$1,$2,$3)
105 ifneq "$(phase)" "0"
106 # From phase 1 we actually include the dependency files for the
107 # bootstrapping stuff
108 ifeq "$3" "0"
109 $(call include-dependencies,$1,$2,$3)
110 else ifeq "$(phase)" ""
111 # In the final phase, we also include the dependency files for
112 # everything else
113 $(call include-dependencies,$1,$2,$3)
114 endif
115 endif
116
117 # Now generate all the build rules for each way in this directory:
118 $$(foreach way,$$($1_$2_WAYS),$$(eval \
119     $$(call c-objs,$1,$2,$$(way)) \
120     $$(call c-suffix-rules,$1,$2,$$(way),YES) \
121     $$(call cmm-objs,$1,$2,$$(way)) \
122     $$(call cmm-suffix-rules,$1,$2,$$(way)) \
123     $$(call build-package-way,$1,$2,$$(way),$3) \
124   ))
125
126 # C and S files are possibly built the "dyn" way.
127 ifeq "$$(BuildSharedLibs)" "YES"
128 $(call c-objs,$1,$2,dyn)
129 $(call c-suffix-rules,$1,$2,dyn,YES)
130 endif
131
132 $(call all-target,$1,all_$1_$2)
133 # This give us things like
134 #     all_libraries: all_libraries/base_dist-install
135 ifneq "$$($1_$2_GROUP)" ""
136 all_$$($1_$2_GROUP): all_$1_$2
137 endif
138
139 ifneq "$$(CHECKED_$1)" "YES"
140 CHECKED_$1 = YES
141 check_packages: check_$1
142 .PHONY: check_$1
143 check_$1: $$(GHC_CABAL_INPLACE)
144         $$(GHC_CABAL_INPLACE) check $1
145 endif
146
147 $(call haddock,$1,$2)
148
149 # Don't put bootstrapping packages in the bindist
150 ifneq "$3" "0"
151 BINDIST_EXTRAS += $1/*.cabal $$(wildcard $1/*.buildinfo) $1/$2/setup-config $1/LICENSE
152 BINDIST_EXTRAS += $$($1_$2_INSTALL_INCLUDES_SRCS)
153 endif
154
155 endef
156