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