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