Improvements to record puns, wildcards
[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 # $1 = dir
33 # $2 = distdir
34 # $3 = GHC stage to use (0 == bootstrapping compiler)
35
36 ifeq "$$(findstring $3,0 1 2)" ""
37 $$(error $1/$2: stage argument to build-package should be 0, 1, or 2)
38 endif
39
40 # We don't install things compiled by stage 0, so no need to put them
41 # in the bindist.
42 ifneq "$$(BINDIST) $3" "YES 0"
43
44 $(call all-target,$1,all_$1_$2)
45 $(call clean-target,$1,$2,$1/$2)
46 # This give us things like
47 #     all_libraries: all_libraries/base_dist-install
48 ifneq "$$($1_$2_GROUP)" ""
49 all_$$($1_$2_GROUP): all_$1_$2
50 endif
51
52 ifneq "$$(CHECKED_$1)" "YES"
53 CHECKED_$1 = YES
54 check_packages: check_$1
55 .PHONY: check_$1
56 check_$1: $$(GHC_CABAL_INPLACE)
57         $$(GHC_CABAL_INPLACE) check $1
58 endif
59
60 distclean : clean_$1_$2_config
61
62 maintainer-clean : distclean
63
64 .PHONY: clean_$1_$2_config
65 clean_$1_$2_config:
66         "$$(RM)" $$(RM_OPTS) $1/config.log $1/config.status $1/include/Hs*Config.h
67         "$$(RM)" $$(RM_OPTS) -r $1/autom4te.cache
68
69 # --- CONFIGURATION
70
71 $1_$2_USE_BOOT_LIBS = YES
72 $(call package-config,$1,$2,$3)
73
74 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
75 include $1/$2/package-data.mk
76 endif
77
78 ifeq "$$($1_$2_DISABLE)" "YES"
79
80 ifeq "$$(DEBUG)" "YES"
81 $$(warning $1/$2 disabled)
82 endif
83
84 # A package is disabled when we want to bring its package-data.mk file
85 # up-to-date first, or due to other build dependencies.
86
87 $(call all-target,$1_$2,$1/$2/package-data.mk)
88
89 ifneq "$$(BINDIST)" "YES"
90 # We have a rule for package-data.mk only when the package is
91 # disabled, because we want the build to fail if we haven't run phase 0.
92 $(call build-package-data,$1,$2)
93 endif
94
95 else
96
97 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
98 ifeq "$$($1_$2_VERSION)" ""
99 $$(error phase ordering error: $1/$2 is enabled, but $1/$2/package-data.mk does not exist)
100 endif
101 endif
102
103 # Sometimes we need to modify the automatically-generated package-data.mk
104 # bindings in a special way for the GHC build system, so allow that here:
105 $($1_PACKAGE_MAGIC)
106
107 # Bootstrapping libs are only built one way
108 ifeq "$3" "0"
109 $1_$2_WAYS = v
110 else
111 $1_$2_WAYS = $$(GhcLibWays)
112 endif
113
114 $(call hs-sources,$1,$2)
115 $(call c-sources,$1,$2)
116 $(call includes-sources,$1,$2)
117
118 # --- DEPENDENCIES
119
120 # We must use a different dependency file if $(GhcLibWays) changes, so
121 # encode the ways into the name of the file.
122 $1_$2_WAYS_DASHED = $$(subst $$(space),,$$(patsubst %,-%,$$(strip $$($1_$2_WAYS))))
123 $1_$2_depfile = $1/$2/build/.depend$$($1_$2_WAYS_DASHED)
124
125 $(call build-dependencies,$1,$2)
126
127 # --- BUILDING
128
129 # We don't bother splitting the bootstrap packages (built with stage 0)
130 ifeq "$$($1_$2_SplitObjs)" ""
131 ifeq "$$(SplitObjs) $3" "YES 1"
132 $1_$2_SplitObjs = YES
133 else
134 $1_$2_SplitObjs = NO
135 endif
136 endif
137
138 $(call distdir-opts,$1,$2,$3)
139
140 # C and S files are possibly built the "dyn" way.
141 ifeq "$(BuildSharedLibs)" "YES"
142 $(call c-objs,$1,$2,dyn)
143 $(call c-suffix-rules,$1,$2,dyn,YES)
144 endif
145
146 # Now generate all the build rules for each way in this directory:
147 $$(foreach way,$$($1_$2_WAYS),$$(eval \
148     $$(call c-objs,$1,$2,$$(way)) \
149         $$(call c-suffix-rules,$1,$2,$$(way),YES) \
150     $$(call cmm-objs,$1,$2,$$(way)) \
151     $$(call cmm-suffix-rules,$1,$2,$$(way)) \
152     $$(call build-package-way,$1,$2,$$(way),$3) \
153   ))
154
155 $(call haddock,$1,$2)
156
157 endif # package-data.mk exists
158
159 # Don't put bootstrapping packages in the bindist
160 ifneq "$3" "0"
161 BINDIST_EXTRAS += $1/*.cabal $$(wildcard $1/*.buildinfo) $1/$2/setup-config $1/LICENSE
162 BINDIST_EXTRAS += $$($1_$2_INSTALL_INCLUDES_SRCS)
163 endif
164
165 endif
166
167 endef
168