2 # Build a program with the stage-1 compiler. Invoke like this:
4 # utils/genapply_MODULES = Main
5 # utils/genapply_HC_OPTS = -package Cabal
6 # utils/genapply_dist_PROG = genapply
8 # $(eval $(call build-prog,utils/genapply,dist-install))
13 # $3 = GHC stage to use (0 == bootstrapping compiler)
15 ifeq "$$($1_$2_PROG)" ""
16 $$(error $1_$2_PROG is not set)
19 ifeq "$$(findstring $3,0 1 2)" ""
20 $$(error $1/$2: stage argument to build-prog should be 0, 1, or 2)
23 $(call all-target,$1,all_$1_$2)
25 $(call clean-target,$1,$2,$1/$2)
27 $(call package-config,$1,$2,$3)
29 ifeq "$$($1_USES_CABAL)" "YES"
30 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
31 include $1/$2/package-data.mk
35 ifeq "$$($1_USES_CABAL)$$($1_$2_VERSION)" "YES"
39 ifeq "$$($1_$2_DISABLE)" "YES"
41 ifeq "$$(DEBUG)" "YES"
42 $$(warning $1/$2 disabled)
45 # The following code to build the package all depends on settings
46 # obtained from package-data.mk. If we don't have package-data.mk
47 # yet, then don't try to do anything else with this package. Make will
48 # try to build package-data.mk, then restart itself and we'll be in business.
50 $(call all-target,$1_$2,$1/$2/package-data.mk)
52 # We have a rule for package-data.mk only when the package is
53 # disabled, because we want the build to fail if we haven't run phase 0.
54 ifneq "$(BINDIST)" "YES"
55 $(call build-package-data,$1,$2)
60 ifneq "$(BINDIST)" "YES"
61 $(call hs-sources,$1,$2)
62 $(call c-sources,$1,$2)
66 $1_$2_depfile = $1/$2/build/.depend
68 $(call build-dependencies,$1,$2)
72 $(call distdir-opts,$1,$2,$3)
74 # Just the 'v' way for programs
75 $(call distdir-way-opts,$1,$2,v)
77 $(call c-suffix-rules,$1,$2,v,YES)
79 $(call hs-suffix-rules,$1,$2,v)
80 $$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
81 $$(eval $$(call hs-suffix-rules-srcdir,$1,$2,v,$$(dir))))
84 $(call hs-objs,$1,$2,v)
86 $1/$2/build/tmp/$$($1_$2_PROG) : $$($1_$2_v_HS_OBJS) $$($1_$2_C_OBJS) $$($1_$2_S_OBJS) $$($1_$2_OTHER_OBJS)
87 $$(MKDIRHIER) $$(dir $$@)
88 $$($1_$2_HC) -o $$@ $$($1_$2_v_ALL_HC_OPTS) $$(LD_OPTS) $$($1_$2_v_HS_OBJS) $$($1_$2_C_OBJS) $$($1_$2_S_OBJS) $$($1_$2_OTHER_OBJS)
90 # Note [lib-depends] if this program is built with stage1 or greater, we
91 # need to depend on the libraries too. NB. since $(ALL_LIBS) and
92 # $(ALL_RTS_LIBS) are not defined until after libraries/*/ghc.mk have
93 # been included, this introduces an ordering dependency.
95 ifeq "$$(ALL_LIBS)" ""
96 $$(error ordering failure in $1: $$(ALL_LIBS) is empty)
98 $1/$2/build/tmp/$($1_$2_PROG) : $$(ALL_LIBS) $$(ALL_RTS_LIBS) $$(OTHER_LIBS)
102 ifeq "$$($1_$2_INSTALL_INPLACE)" "NO"
103 $(call all-target,$1_$2,$1/$2/build/tmp/$$($1_$2_PROG))
105 # Where do we install the inplace version?
106 ifeq "$$($1_$2_SHELL_WRAPPER) $$(Windows)" "YES NO"
107 $1_$2_INPLACE = $$(INPLACE_LIB)/$$($1_$2_PROG)
109 ifeq "$$($1_$2_LIBEXEC)" "YES"
110 $1_$2_INPLACE = $$(INPLACE_LIB)/$$($1_$2_PROG)
112 $1_$2_INPLACE = $$(INPLACE_BIN)/$$($1_$2_PROG)
116 $(call all-target,$1_$2,$$($1_$2_INPLACE))
117 $(call clean-target,$1,$2_inplace,$$($1_$2_INPLACE))
119 $$($1_$2_INPLACE) : $1/$2/build/tmp/$$($1_$2_PROG) $$(MKDIRHIER)
120 $$(MKDIRHIER) $$(dir $$@)
124 # touch is necessary; cp doesn't update the file time.
127 $(call shell-wrapper,$1,$2)
129 ifeq "$$($1_$2_INSTALL)" "YES"
130 ifeq "$$($1_$2_LIBEXEC)" "YES"
131 INSTALL_LIBEXECS += $1/$2/build/tmp/$$($1_$2_PROG)
133 INSTALL_BINS += $1/$2/build/tmp/$$($1_$2_PROG)
137 endif # package-data.mk exists