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 ifeq "$$($1_$2_INSTALL_INPLACE)" "NO"
58 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
59 $1_$2_INPLACE = $$(error $1_$2 should not be installed inplace, but INPLACE var evaluated)
64 # Where do we install the inplace version?
65 ifeq "$$($1_$2_SHELL_WRAPPER) $$(Windows)" "YES NO"
66 $1_$2_INPLACE = $$(INPLACE_LIB)/$$($1_$2_PROG)
68 ifeq "$$($1_$2_TOPDIR)" "YES"
69 $1_$2_INPLACE = $$(INPLACE_TOPDIR)/$$($1_$2_PROG)
71 $1_$2_INPLACE = $$(INPLACE_BIN)/$$($1_$2_PROG)
76 ########################################
77 ifeq "$$($1_$2_CONFIGURE_PHASE)" ""
78 $$(error No configure phase for $1_$2)
79 else ifeq "$$($1_$2_CONFIGURE_PHASE)" "$$(phase)"
81 ifeq "$$(DEBUG)" "YES"
82 $$(warning $1/$2 configure phase)
85 ifneq "$$(BINDIST)" "YES"
86 $(call build-package-data,$1,$2,$3)
89 ifeq "$$($1_$2_USES_CABAL)" "YES"
90 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
91 include $1/$2/package-data.mk
95 # INPLACE_BIN might be empty if we're distcleaning
96 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
97 ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
99 $$(error $1_$2 is configuring, but trying to build $$($1_$2_INPLACE)")
103 else ifeq "$$(phase_$$($1_$2_CONFIGURE_PHASE)_or_later)" "YES"
105 ifeq "$$(DEBUG)" "YES"
106 $$(warning $1/$2 build phase)
109 ifeq "$$($1_$2_USES_CABAL)" "YES"
110 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
111 include $1/$2/package-data.mk
112 ifeq "$$($1_$2_VERSION)" ""
113 $$(error No version for $1_$2 found)
118 $(call all-target,$1,all_$1_$2)
119 $(call all-target,$1_$2,$1/$2/build/tmp/$$($1_$2_PROG))
121 # INPLACE_BIN might be empty if we're distcleaning
122 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
123 ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
124 $$($1_$2_INPLACE) : $1/$2/build/tmp/$$($1_$2_PROG) | $$$$(dir $$$$@)/.
132 ifeq "$$(DEBUG)" "YES"
133 $$(warning $1/$2 disabled phase)
136 # INPLACE_BIN might be empty if we're distcleaning
137 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
138 ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
140 $$(error $1_$2 is disabled, but trying to build $$($1_$2_INPLACE)")
145 ########################################
147 $(call shell-wrapper,$1,$2)
149 ifeq "$$(phase_$$($1_$2_CONFIGURE_PHASE)_done)" "YES"
151 ifneq "$$(BINDIST)" "YES"
154 $(call hs-sources,$1,$2)
155 $(call c-sources,$1,$2)
159 $1_$2_depfile_base = $1/$2/build/.depend
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