Merge _stub.o files into the main .o file (Fixes #3687 and #706)
[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 $(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 maintainer-clean : distclean
47
48 .PHONY: clean_$1_$2_config
49 clean_$1_$2_config:
50         "$$(RM)" $$(RM_OPTS) $1/config.log $1/config.status $1/include/Hs*Config.h
51         "$$(RM)" $$(RM_OPTS_REC) $1/autom4te.cache
52
53 ifneq "$$($1_$2_NOT_NEEDED)" "YES"
54 $$(eval $$(call build-package-helper,$1,$2,$3))
55 endif
56 $(call profEnd, build-package($1,$2,$3))
57 endef
58
59
60 define build-package-helper
61 # $1 = dir
62 # $2 = distdir
63 # $3 = GHC stage to use (0 == bootstrapping compiler)
64
65 # --- CONFIGURATION
66
67 $(call package-config,$1,$2,$3)
68
69 # Bootstrapping libs are only built one way
70 ifeq "$3" "0"
71 $1_$2_WAYS = v
72 else
73 $1_$2_WAYS = $$(GhcLibWays)
74 endif
75
76 # We must use a different dependency file if $(GhcLibWays) changes, so
77 # encode the ways into the name of the file.
78 $1_$2_WAYS_DASHED = $$(subst $$(space),,$$(patsubst %,-%,$$(strip $$($1_$2_WAYS))))
79 $1_$2_depfile_base = $1/$2/build/.depend$$($1_$2_WAYS_DASHED)
80
81 $(call build-package-data,$1,$2,$3)
82 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
83 ifeq "$3" "0"
84 include $1/$2/package-data.mk
85 else ifeq "$(phase)" "final"
86 include $1/$2/package-data.mk
87 endif
88 endif
89
90 # We don't bother splitting the bootstrap packages (built with stage 0)
91 ifeq "$$($1_$2_SplitObjs)" ""
92 ifeq "$$(SplitObjs) $3" "YES 1"
93 $1_$2_SplitObjs = YES
94 else
95 $1_$2_SplitObjs = NO
96 endif
97 endif
98
99 $(call hs-sources,$1,$2)
100 $(call c-sources,$1,$2)
101 $(call includes-sources,$1,$2)
102
103 # --- DEPENDENCIES
104 # We always have the dependency rules available, as we need to know
105 # how to build hsc2hs's dependency file in phase 0
106 $(call build-dependencies,$1,$2,$3)
107 ifneq "$(phase)" "0"
108 # From phase 1 we actually include the dependency files for the
109 # bootstrapping stuff
110 ifeq "$3" "0"
111 $(call include-dependencies,$1,$2,$3)
112 else ifeq "$(phase)" "final"
113 # In the final phase, we also include the dependency files for
114 # everything else
115 $(call include-dependencies,$1,$2,$3)
116 endif
117 endif
118
119 # Now generate all the build rules for each way in this directory:
120 $$(foreach way,$$($1_$2_WAYS),$$(eval \
121     $$(call c-objs,$1,$2,$$(way)) \
122     $$(call c-suffix-rules,$1,$2,$$(way),YES) \
123     $$(call cmm-objs,$1,$2,$$(way)) \
124     $$(call cmm-suffix-rules,$1,$2,$$(way)) \
125     $$(call build-package-way,$1,$2,$$(way),$3) \
126   ))
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 "$$(CHECKED_$1)" "YES"
142 CHECKED_$1 = YES
143 check_packages: check_$1
144 .PHONY: check_$1
145 check_$1: $$(GHC_CABAL_INPLACE)
146         $$(GHC_CABAL_INPLACE) check $1
147 endif
148
149 $(call haddock,$1,$2)
150
151 # Don't put bootstrapping packages in the bindist
152 ifneq "$3" "0"
153 BINDIST_EXTRAS += $1/*.cabal $$(wildcard $1/*.buildinfo) $1/$2/setup-config $1/LICENSE
154 BINDIST_EXTRAS += $$($1_$2_INSTALL_INCLUDES_SRCS)
155 endif
156
157 endef
158