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))
25 # $3 = GHC stage to use (0 == bootstrapping compiler)
27 ifneq "$$(CLEANING)" "YES"
28 ifeq "$$($1_$2_PROG)" ""
29 $$(error $1_$2_PROG is not set)
33 ifeq "$$(findstring $3,0 1 2)" ""
34 $$(error $1/$2: stage argument to build-prog should be 0, 1, or 2)
37 $(call clean-target,$1,$2,$1/$2)
39 ifneq "$$($1_$2_NOT_NEEDED)" "YES"
40 $$(eval $$(call build-prog-helper,$1,$2,$3))
45 define build-prog-helper
48 # $3 = GHC stage to use (0 == bootstrapping compiler)
50 $(call all-target,$1,all_$1_$2)
52 ifeq "$$($1_USES_CABAL)" "YES"
53 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
54 include $1/$2/package-data.mk
58 $(call package-config,$1,$2,$3)
60 ifeq "$$($1_USES_CABAL)$$($1_$2_VERSION)" "YES"
64 ifeq "$$($1_$2_DISABLE)" "YES"
66 ifeq "$$(DEBUG)" "YES"
67 $$(warning $1/$2 disabled)
70 # The following code to build the package all depends on settings
71 # obtained from package-data.mk. If we don't have package-data.mk
72 # yet, then don't try to do anything else with this package. Make will
73 # try to build package-data.mk, then restart itself and we'll be in business.
75 $(call all-target,$1_$2,$1/$2/package-data.mk)
77 # We have a rule for package-data.mk only when the package is
78 # disabled, because we want the build to fail if we haven't run phase 0.
79 ifneq "$$(BINDIST)" "YES"
80 $(call build-package-data,$1,$2,$3)
85 ifneq "$$(BINDIST)" "YES"
88 $(call hs-sources,$1,$2)
89 $(call c-sources,$1,$2)
93 $1_$2_depfile_base = $1/$2/build/.depend
95 $(call build-dependencies,$1,$2,$3)
99 # Just the 'v' way for programs
100 $(call distdir-way-opts,$1,$2,v,$3)
102 $(call c-suffix-rules,$1,$2,v,YES)
104 $(call hs-suffix-rules,$1,$2,v)
105 $$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
106 $$(eval $$(call hs-suffix-rules-srcdir,$1,$2,v,$$(dir))))
108 $(call c-objs,$1,$2,v)
109 $(call hs-objs,$1,$2,v)
111 ifeq "$$(BootingFromHc)" "NO"
112 $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 $$$$@)/.
113 "$$($1_$2_HC)" -o $$@ $$($1_$2_v_ALL_HC_OPTS) $$(LD_OPTS) $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS)
115 $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 $$$$@)/.
116 "$$(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)
119 # Note [lib-depends] if this program is built with stage1 or greater, we
120 # need to depend on the libraries too. NB. since $(ALL_STAGE1_LIBS) and
121 # $(ALL_RTS_LIBS) are not defined until after libraries/*/ghc.mk have
122 # been included, this introduces an ordering dependency.
124 ifeq "$$(ALL_STAGE1_LIBS)" ""
125 $$(error ordering failure in $1: $$(ALL_STAGE1_LIBS) is empty)
127 $1/$2/build/tmp/$$($1_$2_PROG) : $$(ALL_STAGE1_LIBS) $$(ALL_RTS_LIBS) $$(OTHER_LIBS)
131 ifeq "$$($1_$2_INSTALL_INPLACE)" "NO"
132 $(call all-target,$1_$2,$1/$2/build/tmp/$$($1_$2_PROG))
134 # Where do we install the inplace version?
135 ifeq "$$($1_$2_SHELL_WRAPPER) $$(Windows)" "YES NO"
136 $1_$2_INPLACE = $$(INPLACE_LIB)/$$($1_$2_PROG)
138 ifeq "$$($1_$2_TOPDIR)" "YES"
139 $1_$2_INPLACE = $$(INPLACE_TOPDIR)/$$($1_$2_PROG)
141 $1_$2_INPLACE = $$(INPLACE_BIN)/$$($1_$2_PROG)
145 $(call all-target,$1_$2,$$($1_$2_INPLACE))
146 $(call clean-target,$1,$2_inplace,$$($1_$2_INPLACE))
148 # INPLACE_BIN might be empty if we're distcleaning
149 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
150 $$($1_$2_INPLACE) : $1/$2/build/tmp/$$($1_$2_PROG) | $$$$(dir $$$$@)/.
155 # touch is necessary; cp doesn't update the file time.
158 $(call shell-wrapper,$1,$2)
160 ifeq "$$($1_$2_INSTALL)" "YES"
161 ifeq "$$($1_$2_TOPDIR)" "YES"
162 INSTALL_TOPDIRS += $1/$2/build/tmp/$$($1_$2_PROG)
164 INSTALL_BINS += $1/$2/build/tmp/$$($1_$2_PROG)
168 endif # package-data.mk exists