add a simple trace facility to the build system
[ghc.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 # We don't install things compiled by stage 0, so no need to put them
64 # in the bindist.
65 ifneq "$$(BINDIST) $3" "YES 0"
66
67 $(call all-target,$1,all_$1_$2)
68 # This give us things like
69 # all_libraries: all_libraries/base_dist-install
70 ifneq "$$($1_$2_GROUP)" ""
71 all_$$($1_$2_GROUP): all_$1_$2
72 endif
73
74 ifneq "$$(CHECKED_$1)" "YES"
75 CHECKED_$1 = YES
76 check_packages: check_$1
77 .PHONY: check_$1
78 check_$1: $$(GHC_CABAL_INPLACE)
79 $$(GHC_CABAL_INPLACE) check $1
80 endif
81
82 # --- CONFIGURATION
83
84 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
85 include $1/$2/package-data.mk
86 endif
87
88 $(call package-config,$1,$2,$3)
89
90 ifeq "$$($1_$2_DISABLE)" "YES"
91
92 ifeq "$$(DEBUG)" "YES"
93 $$(warning $1/$2 disabled)
94 endif
95
96 # A package is disabled when we want to bring its package-data.mk file
97 # up-to-date first, or due to other build dependencies.
98
99 $(call all-target,$1_$2,$1/$2/package-data.mk)
100
101 ifneq "$$(BINDIST)" "YES"
102 # We have a rule for package-data.mk only when the package is
103 # disabled, because we want the build to fail if we haven't run phase 0.
104 $(call build-package-data,$1,$2,$3)
105 endif
106
107 else
108
109 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
110 ifeq "$$($1_$2_VERSION)" ""
111 $$(error phase ordering error: $1/$2 is enabled, but $1/$2/package-data.mk does not exist)
112 endif
113 endif
114
115 # Sometimes we need to modify the automatically-generated package-data.mk
116 # bindings in a special way for the GHC build system, so allow that here:
117 $($1_PACKAGE_MAGIC)
118
119 # Bootstrapping libs are only built one way
120 ifeq "$3" "0"
121 $1_$2_WAYS = v
122 else
123 $1_$2_WAYS = $$(GhcLibWays)
124 endif
125
126 $(call hs-sources,$1,$2)
127 $(call c-sources,$1,$2)
128 $(call includes-sources,$1,$2)
129
130 # --- DEPENDENCIES
131
132 # We must use a different dependency file if $(GhcLibWays) changes, so
133 # encode the ways into the name of the file.
134 $1_$2_WAYS_DASHED = $$(subst $$(space),,$$(patsubst %,-%,$$(strip $$($1_$2_WAYS))))
135 $1_$2_depfile_base = $1/$2/build/.depend$$($1_$2_WAYS_DASHED)
136
137 $(call build-dependencies,$1,$2,$3)
138
139 # --- BUILDING
140
141 # We don't bother splitting the bootstrap packages (built with stage 0)
142 ifeq "$$($1_$2_SplitObjs)" ""
143 ifeq "$$(SplitObjs) $3" "YES 1"
144 $1_$2_SplitObjs = YES
145 else
146 $1_$2_SplitObjs = NO
147 endif
148 endif
149
150 # C and S files are possibly built the "dyn" way.
151 ifeq "$$(BuildSharedLibs)" "YES"
152 $(call c-objs,$1,$2,dyn)
153 $(call c-suffix-rules,$1,$2,dyn,YES)
154 endif
155
156 # Now generate all the build rules for each way in this directory:
157 $$(foreach way,$$($1_$2_WAYS),$$(eval \
158 $$(call c-objs,$1,$2,$$(way)) \
159 $$(call c-suffix-rules,$1,$2,$$(way),YES) \
160 $$(call cmm-objs,$1,$2,$$(way)) \
161 $$(call cmm-suffix-rules,$1,$2,$$(way)) \
162 $$(call build-package-way,$1,$2,$$(way),$3) \
163 ))
164
165 ifneq "$$($1_$2_HADDOCK_ME)" "NO"
166 $(call haddock,$1,$2)
167 endif
168
169 endif # package-data.mk exists
170
171 # Don't put bootstrapping packages in the bindist
172 ifneq "$3" "0"
173 BINDIST_EXTRAS += $1/*.cabal $$(wildcard $1/*.buildinfo) $1/$2/setup-config $1/LICENSE
174 BINDIST_EXTRAS += $$($1_$2_INSTALL_INCLUDES_SRCS)
175 endif
176
177 endif
178
179 endef
180