Build the stage0 ghc-pkg with Cabal
[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 $(call profStart, build-package($1,$2,$3))
34 # $1 = dir
35 # $2 = distdir
36 # $3 = GHC stage to use (0 == bootstrapping compiler)
37
38 ifeq "$$(findstring $3,0 1 2)" ""
39 $$(error $1/$2: stage argument to build-package should be 0, 1, or 2)
40 endif
41
42 $(call clean-target,$1,$2,$1/$2)
43
44 distclean : clean_$1_$2_config
45
46 .PHONY: clean_$1_$2_config
47 clean_$1_$2_config:
48 $$(call removeFiles,$1/config.log $1/config.status $(wildcard $1/include/Hs*Config.h))
49 $$(call removeTrees,$1/autom4te.cache)
50
51 ifneq "$$($1_$2_NOT_NEEDED)" "YES"
52 $$(eval $$(call build-package-helper,$1,$2,$3))
53 endif
54 $(call profEnd, build-package($1,$2,$3))
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 ifeq "$3" "1"
68 $$($1_PACKAGE)_INSTALL_INFO = $1_$2
69 endif
70
71 # Bootstrapping libs are only built one way
72 ifeq "$3" "0"
73 $1_$2_WAYS = v
74 else
75 $1_$2_WAYS = $$(filter-out $$($1_$2_EXCLUDED_WAYS),$$(GhcLibWays))
76 endif
77
78 # We must use a different dependency file if $(GhcLibWays) changes, so
79 # encode the ways into the name of the file.
80 $1_$2_WAYS_DASHED = $$(subst $$(space),,$$(patsubst %,-%,$$(strip $$($1_$2_WAYS))))
81 $1_$2_depfile_base = $1/$2/build/.depend$$($1_$2_WAYS_DASHED)
82
83 $(call build-package-data,$1,$2,$3)
84 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
85 ifeq "$3" "0"
86 include $1/$2/package-data.mk
87 else ifeq "$(phase)" "final"
88 include $1/$2/package-data.mk
89 endif
90 # Each Haskell compilation in this package will depend on the
91 # package-data.mk file because e.g. if the version of the package
92 # changes we need to recompile everything in it.
93 $1_$2_PKGDATA_DEP = $1/$2/package-data.mk
94 endif
95
96 # We don't bother splitting the bootstrap packages (built with stage 0)
97 ifeq "$$($1_$2_SplitObjs)" ""
98 ifeq "$$(SplitObjs) $3" "YES 1"
99 $1_$2_SplitObjs = YES
100 else
101 $1_$2_SplitObjs = NO
102 endif
103 endif
104
105 $(call hs-sources,$1,$2)
106 $(call c-sources,$1,$2)
107 $(call includes-sources,$1,$2)
108
109 $(call dependencies,$1,$2,$3)
110
111 # Now generate all the build rules for each way in this directory:
112 $$(foreach way,$$($1_$2_WAYS),$$(eval \
113 $$(call c-objs,$1,$2,$$(way)) \
114 $$(call c-suffix-rules,$1,$2,$$(way),YES) \
115 $$(call cmm-objs,$1,$2,$$(way)) \
116 $$(call cmm-suffix-rules,$1,$2,$$(way)) \
117 $$(call build-package-way,$1,$2,$$(way),$3) \
118 ))
119
120 # Programs will need to depend on either the vanilla lib (if -static
121 # is the default) or the dyn lib (if -dynamic is the default). We
122 # conservatively make them depend on both, to keep things simple.
123 # If dyn libs are not being built then $$($1_$2_dyn_LIB) will just
124 # expand to the empty string, and be ignored.
125 $1_$2_PROGRAM_DEP_LIB = $$($1_$2_v_LIB) $$($1_$2_dyn_LIB)
126 $$($1_PACKAGE)-$$($1_$2_VERSION)_$2_PROGRAM_DEP_LIB = $$($1_$2_PROGRAM_DEP_LIB)
127
128 # C and S files are possibly built the "dyn" way.
129 ifeq "$$(BuildSharedLibs)" "YES"
130 $(call c-objs,$1,$2,dyn)
131 $(call c-suffix-rules,$1,$2,dyn,YES)
132 endif
133
134 $(call all-target,$1,all_$1_$2)
135 # This give us things like
136 # all_libraries: all_libraries/base_dist-install
137 ifneq "$$($1_$2_GROUP)" ""
138 all_$$($1_$2_GROUP): all_$1_$2
139 endif
140
141 ifneq "$3" "0"
142 $(call haddock,$1,$2)
143 endif
144
145 # Don't put bootstrapping packages in the bindist
146 ifneq "$3" "0"
147 BINDIST_EXTRAS += $1/*.cabal $$(wildcard $1/*.buildinfo) $1/$2/setup-config $1/LICENSE
148 BINDIST_EXTRAS += $$($1_$2_INSTALL_INCLUDES_SRCS)
149 endif
150
151 endef
152