4ca3c6e66f91b2c03d607fedf52248b8fb375c3e
[ghc-hetmet.git] / rules / build-package.mk
1
2 # Build a package with the stage-1 compiler, multiple ways.  A typical
3 # libraries/foo/ghc.mk will look like this:
4 #
5 # $(eval $(call build-package,libraries/base,dist-install))
6 #
7 # The package metadata is generated from the .cabal file and placed in
8 # package-data.mk.  It will look something like this:
9 #
10 # libraries/base_dist_MODULES = GHC.Base Data.Tuple ...
11 # libraries/base_dist_PACKAGE = base
12 # libraries/base_dist_VERSION = 4.0.0.0
13 # libraries/base_dist_HC_OPTS = -package ghc-prim-0.1.0.0 -XRank2Types ...
14 # libraries/base_dist_C_SRCS  = cbits/PrelIOUtils.c ...
15 # libraries/base_dist_S_SRCS  = cbits/foo.S ...
16 # libraries/base_dist_CC_OPTS = -Iinclude ...
17 # libraries/base_dist_LD_OPTS = -package ghc-prim-0.1.0.0
18
19 # TODO: soext
20
21 define build-package
22 # $1 = dir
23 # $2 = distdir
24 # $3 = GHC stage to use (0 == bootstrapping compiler)
25
26 ifeq "$$(findstring $3,0 1 2)" ""
27 $$(error $1/$2: stage argument to build-package should be 0, 1, or 2)
28 endif
29
30 # We don't install things compiled by stage 0, so no need to put them
31 # in the bindist.
32 ifneq "$(BINDIST) $3" "YES 0"
33
34 $(call all-target,$1,all_$1_$2)
35
36 $(call clean-target,$1,$2,$1/$2)
37
38 distclean : clean_$1_$2_config
39
40 .PHONY: clean_$1_$2_config
41 clean_$1_$2_config:
42         $(RM) $1/config.log $1/config.status $1/include/Hs*Config.h
43         $(RM) -r $1/autom4te.cache
44
45 # --- CONFIGURATION
46
47 $1_$2_USE_BOOT_LIBS = YES
48 $(call package-config,$1,$2,$3)
49
50 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
51 include $1/$2/package-data.mk
52 endif
53
54 ifeq "$$($1_$2_DISABLE)" "YES"
55
56 ifeq "$$(DEBUG)" "YES"
57 $$(warning $1/$2 disabled)
58 endif
59
60 # A package is disabled when we want to bring its package-data.mk file
61 # up-to-date first, or due to other build dependencies.
62
63 $(call all-target,$1_$2,$1/$2/package-data.mk)
64
65 ifneq "$(BINDIST)" "YES"
66 # We have a rule for package-data.mk only when the package is
67 # disabled, because we want the build to fail if we haven't run phase 0.
68 $(call build-package-data,$1,$2)
69 endif
70
71 else
72
73 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
74 ifeq "$$($1_$2_VERSION)" ""
75 $$(error phase ordering error: $1/$2 is enabled, but $1/$2/package-data.mk does not exist)
76 endif
77 endif
78
79 # Sometimes we need to modify the automatically-generated package-data.mk
80 # bindings in a special way for the GHC build system, so allow that here:
81 $($1_PACKAGE_MAGIC)
82
83 # Bootstrapping libs are only built one way
84 ifeq "$3" "0"
85 $1_$2_WAYS = v
86 else
87 $1_$2_WAYS = $$(GhcLibWays)
88 endif
89
90 $(call hs-sources,$1,$2)
91 $(call c-sources,$1,$2)
92 $(call includes-sources,$1,$2)
93
94 # --- DEPENDENCIES
95
96 # We must use a different dependency file if $(GhcLibWays) changes, so
97 # encode the ways into the name of the file.
98 $1_$2_WAYS_DASHED = $$(subst $$(space),,$$(patsubst %,-%,$$(strip $$($1_$2_WAYS))))
99 $1_$2_depfile = $1/$2/build/.depend$$($1_$2_WAYS_DASHED)
100
101 $(call build-dependencies,$1,$2)
102
103 # --- BUILDING
104
105 # We don't bother splitting the bootstrap packages (built with stage 0)
106 ifeq "$$($1_$2_SplitObjs)" ""
107 ifeq "$$(SplitObjs) $3" "YES 1"
108 $1_$2_SplitObjs = YES
109 else
110 $1_$2_SplitObjs = NO
111 endif
112 endif
113
114 # C and S files are built only once, not once per way
115 $(call c-objs,$1,$2)
116 $(call distdir-opts,$1,$2,$3)
117 $(call c-suffix-rules,$1,$2,v,YES)
118
119 # Now generate all the build rules for each way in this directory:
120 $$(foreach way,$$($1_$2_WAYS),$$(eval $$(call build-package-way,$1,$2,$$(way),$3)))
121
122 $(call haddock,$1,$2)
123
124 endif # package-data.mk exists
125
126 # Don't put bootstrapping packages in the bindist
127 ifeq "$3" "1"
128 BINDIST_EXTRAS += $1/*.cabal $1/$2/setup-config $1/LICENSE
129 BINDIST_EXTRAS += $$($1_$2_INSTALL_INCLUDES_SRCS)
130 endif
131
132 endif
133
134 endef
135