1 # -----------------------------------------------------------------------------
3 # (c) 2009 The University of Glasgow
5 # This file is part of the GHC build system.
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
11 # -----------------------------------------------------------------------------
14 # Build a program. Invoke like this:
16 # utils/genapply_MODULES = Main
17 # utils/genapply_HC_OPTS = -package Cabal
18 # utils/genapply_dist_PROG = genapply
20 # $(eval $(call build-prog,utils/genapply,dist-install,1))
23 $(call trace, build-prog($1,$2,$3))
26 # $3 = GHC stage to use (0 == bootstrapping compiler)
28 ifneq "$$(CLEANING)" "YES"
29 ifeq "$$($1_$2_PROG)" ""
30 $$(error $1_$2_PROG is not set)
34 ifeq "$$(findstring $3,0 1 2)" ""
35 $$(error $1/$2: stage argument to build-prog should be 0, 1, or 2)
38 $(call clean-target,$1,$2,$1/$2)
40 ifneq "$$($1_$2_NOT_NEEDED)" "YES"
41 $$(eval $$(call build-prog-helper,$1,$2,$3))
46 define build-prog-helper
49 # $3 = GHC stage to use (0 == bootstrapping compiler)
51 ifeq "$$($1_USES_CABAL)" "YES"
52 $1_$2_USES_CABAL = YES
55 $(call package-config,$1,$2,$3)
57 $1_$2_depfile_base = $1/$2/build/.depend
59 ifeq "$$($1_$2_INSTALL_INPLACE)" "NO"
60 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
61 $1_$2_INPLACE = $$(error $1_$2 should not be installed inplace, but INPLACE var evaluated)
66 # Where do we install the inplace version?
67 ifeq "$$($1_$2_SHELL_WRAPPER) $$(Windows)" "YES NO"
68 $1_$2_INPLACE = $$(INPLACE_LIB)/$$($1_$2_PROG)
70 ifeq "$$($1_$2_TOPDIR)" "YES"
71 $1_$2_INPLACE = $$(INPLACE_TOPDIR)/$$($1_$2_PROG)
73 $1_$2_INPLACE = $$(INPLACE_BIN)/$$($1_$2_PROG)
78 ########################################
79 ifeq "$$($1_$2_CONFIGURE_PHASE)" ""
80 $$(error No configure phase for $1_$2)
81 else ifeq "$$($1_$2_CONFIGURE_PHASE)" "$$(phase)"
83 ifeq "$$(DEBUG)" "YES"
84 $$(warning $1/$2 configure phase)
87 ifneq "$$(BINDIST)" "YES"
88 $(call build-package-data,$1,$2,$3)
91 ifeq "$$($1_$2_USES_CABAL)" "YES"
92 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
93 include $1/$2/package-data.mk
97 # INPLACE_BIN might be empty if we're distcleaning
98 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
99 ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
101 $$(error $1_$2 is configuring, but trying to build $$($1_$2_INPLACE)")
105 else ifeq "$$(phase_$$($1_$2_CONFIGURE_PHASE)_or_later)" "YES"
107 ifeq "$$(DEBUG)" "YES"
108 $$(warning $1/$2 build phase)
111 ifeq "$$($1_$2_USES_CABAL)" "YES"
112 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
113 include $1/$2/package-data.mk
114 ifeq "$$($1_$2_VERSION)" ""
115 $$(error No version for $1_$2 found)
120 $(call all-target,$1,all_$1_$2)
121 $(call all-target,$1_$2,$1/$2/build/tmp/$$($1_$2_PROG))
123 # INPLACE_BIN might be empty if we're distcleaning
124 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
125 ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
126 $$($1_$2_INPLACE) : $1/$2/build/tmp/$$($1_$2_PROG) | $$$$(dir $$$$@)/.
134 ifeq "$$(DEBUG)" "YES"
135 $$(warning $1/$2 disabled phase)
138 # INPLACE_BIN might be empty if we're distcleaning
139 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
140 ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
142 $$(error $1_$2 is disabled, but trying to build $$($1_$2_INPLACE)")
147 ########################################
149 $(call shell-wrapper,$1,$2)
151 ifeq "$$(phase_$$($1_$2_CONFIGURE_PHASE)_done)" "YES"
153 ifneq "$$(BINDIST)" "YES"
156 $(call hs-sources,$1,$2)
157 $(call c-sources,$1,$2)
161 $(call build-dependencies,$1,$2,$3)
165 # Just the 'v' way for programs
166 $(call distdir-way-opts,$1,$2,v,$3)
169 # For stage 0, we use GHC to compile C sources so that we don't have to
170 # worry about where the RTS header files are
171 $(call c-suffix-rules,$1,$2,v,YES)
173 $(call c-suffix-rules,$1,$2,v,NO)
176 $(call hs-suffix-rules,$1,$2,v)
177 $$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
178 $$(eval $$(call hs-suffix-rules-srcdir,$1,$2,v,$$(dir))))
180 $(call c-objs,$1,$2,v)
181 $(call hs-objs,$1,$2,v)
183 $1_$2_LINK_WITH_GCC = NO
184 ifeq "$$(BootingFromHc)" "YES"
185 $1_$2_LINK_WITH_GCC = YES
188 ifeq "$$($1_$2_v_HS_OBJS)" ""
189 # We don't want to link the GHC RTS into C-only programs. There's no
190 # point, and it confuses the test that all GHC-compiled programs
191 # were compiled with the right GHC.
192 $1_$2_GHC_LD_OPTS = -no-auto-link-packages -no-hs-main
195 # The quadrupled $'s here are because the _v_LIB variables aren't
196 # necessarily set when this part of the makefile is read
197 $1/$2/build/tmp/$$($1_$2_PROG) : \
198 $$(foreach dep,$$($1_$2_DEP_NAMES),\
199 $$(if $$(filter ghc,$$(dep)),\
200 $(if $(filter 0,$3),$$(compiler_stage1_v_LIB),\
201 $(if $(filter 1,$3),$$(compiler_stage2_v_LIB),\
202 $(if $(filter 2,$3),$$(compiler_stage2_v_LIB),\
203 $$(error Bad build stage)))),\
204 $$$$(libraries/$$(dep)_dist-$(if $(filter 0,$3),boot,install)_v_LIB)))
206 ifeq "$$($1_$2_LINK_WITH_GCC)" "NO"
207 $1/$2/build/tmp/$$($1_$2_PROG) : $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) | $$$$(dir $$$$@)/.
208 "$$($1_$2_HC)" -o $$@ $$($1_$2_v_ALL_HC_OPTS) $$(LD_OPTS) $$($1_$2_GHC_LD_OPTS) $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES))
210 $1/$2/build/tmp/$$($1_$2_PROG) : $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) | $$$$(dir $$$$@)/.
211 "$$(CC)" -o $$@ $$($1_$2_v_ALL_CC_OPTS) $$(LD_OPTS) $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) $$($1_$2_v_EXTRA_CC_OPTS) $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES))
214 # Note [lib-depends] if this program is built with stage1 or greater, we
215 # need to depend on the libraries too. NB. since $(ALL_STAGE1_LIBS) and
216 # $(ALL_RTS_LIBS) are not defined until after libraries/*/ghc.mk have
217 # been included, this introduces an ordering dependency.
218 ifneq "$$(CLEANING)" "YES"
220 ifneq "$$($1_$2_HS_SRCS)" ""
221 ifeq "$$(strip $$(ALL_STAGE1_LIBS))" ""
222 $$(error ordering failure in $1 ($2): ALL_STAGE1_LIBS is empty)
225 $1/$2/build/tmp/$$($1_$2_PROG) : $$(ALL_STAGE1_LIBS) $$(ALL_RTS_LIBS) $$(OTHER_LIBS)
229 ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
230 $(call all-target,$1_$2,$$($1_$2_INPLACE))
232 $(call clean-target,$1,$2_inplace,$$($1_$2_INPLACE))
234 # touch is necessary; cp doesn't update the file time.
237 ifeq "$$($1_$2_INSTALL)" "YES"
238 ifeq "$$($1_$2_TOPDIR)" "YES"
239 INSTALL_TOPDIRS += $1/$2/build/tmp/$$($1_$2_PROG)
241 INSTALL_BINS += $1/$2/build/tmp/$$($1_$2_PROG)
245 endif # package-data.mk exists