Improve error messages for type functions
[ghc-hetmet.git] / rules / build-prog.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 program.  Invoke like this:
15 #
16 # utils/genapply_MODULES = Main
17 # utils/genapply_HC_OPTS = -package Cabal
18 # utils/genapply_dist_PROG = genapply
19 #
20 # $(eval $(call build-prog,utils/genapply,dist-install,1))
21
22 define build-prog
23 # $1 = dir
24 # $2 = distdir
25 # $3 = GHC stage to use (0 == bootstrapping compiler)
26
27 ifeq "$$($1_$2_PROG)" ""
28 $$(error $1_$2_PROG is not set)
29 endif
30
31 ifeq "$$(findstring $3,0 1 2)" ""
32 $$(error $1/$2: stage argument to build-prog should be 0, 1, or 2)
33 endif
34
35 $(call all-target,$1,all_$1_$2)
36
37 $(call clean-target,$1,$2,$1/$2)
38
39 $(call package-config,$1,$2,$3)
40
41 ifeq "$$($1_USES_CABAL)" "YES"
42 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
43 include $1/$2/package-data.mk
44 endif
45 endif
46
47 ifeq "$$($1_USES_CABAL)$$($1_$2_VERSION)" "YES"
48 $1_$2_DISABLE = YES
49 endif
50
51 ifeq "$$($1_$2_DISABLE)" "YES"
52
53 ifeq "$$(DEBUG)" "YES"
54 $$(warning $1/$2 disabled)
55 endif
56
57 # The following code to build the package all depends on settings
58 # obtained from package-data.mk.  If we don't have package-data.mk
59 # yet, then don't try to do anything else with this package.  Make will
60 # try to build package-data.mk, then restart itself and we'll be in business.
61
62 $(call all-target,$1_$2,$1/$2/package-data.mk)
63
64 # We have a rule for package-data.mk only when the package is
65 # disabled, because we want the build to fail if we haven't run phase 0.
66 ifneq "$(BINDIST)" "YES"
67 $(call build-package-data,$1,$2)
68 endif
69
70 else
71
72 ifneq "$(BINDIST)" "YES"
73 $(call hs-sources,$1,$2)
74 $(call c-sources,$1,$2)
75
76 # --- DEPENDENCIES
77
78 $1_$2_depfile = $1/$2/build/.depend
79
80 $(call build-dependencies,$1,$2)
81
82 # --- IMPLICIT RULES
83
84 $(call distdir-opts,$1,$2,$3)
85
86 # Just the 'v' way for programs
87 $(call distdir-way-opts,$1,$2,v)
88
89 $(call c-suffix-rules,$1,$2,v,YES)
90
91 $(call hs-suffix-rules,$1,$2,v)
92 $$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
93   $$(eval $$(call hs-suffix-rules-srcdir,$1,$2,v,$$(dir))))
94
95 $(call c-objs,$1,$2,v)
96 $(call hs-objs,$1,$2,v)
97
98 $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)
99         $$(MKDIRHIER) $$(dir $$@)
100         $$($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)
101
102 # Note [lib-depends] if this program is built with stage1 or greater, we
103 # need to depend on the libraries too.  NB. since $(ALL_LIBS) and
104 # $(ALL_RTS_LIBS) are not defined until after libraries/*/ghc.mk have
105 # been included, this introduces an ordering dependency.
106 ifneq "$3" "0"
107 ifeq "$$(ALL_LIBS)" ""
108 $$(error ordering failure in $1: $$(ALL_LIBS) is empty)
109 endif
110 $1/$2/build/tmp/$($1_$2_PROG) : $$(ALL_LIBS) $$(ALL_RTS_LIBS) $$(OTHER_LIBS)
111 endif
112 endif
113
114 ifeq "$$($1_$2_INSTALL_INPLACE)" "NO"
115 $(call all-target,$1_$2,$1/$2/build/tmp/$$($1_$2_PROG))
116 else
117 # Where do we install the inplace version?
118 ifeq "$$($1_$2_SHELL_WRAPPER) $$(Windows)" "YES NO"
119 $1_$2_INPLACE = $$(INPLACE_LIB)/$$($1_$2_PROG)
120 else
121 ifeq "$$($1_$2_LIBEXEC)" "YES"
122 $1_$2_INPLACE = $$(INPLACE_LIB)/$$($1_$2_PROG)
123 else
124 $1_$2_INPLACE = $$(INPLACE_BIN)/$$($1_$2_PROG)
125 endif
126 endif
127
128 $(call all-target,$1_$2,$$($1_$2_INPLACE))
129 $(call clean-target,$1,$2_inplace,$$($1_$2_INPLACE))
130
131 $$($1_$2_INPLACE) : $1/$2/build/tmp/$$($1_$2_PROG) $$(MKDIRHIER)
132         $$(MKDIRHIER) $$(dir $$@)
133         $$(CP) -p $$< $$@
134         touch $$@
135
136 # touch is necessary; cp doesn't update the file time.
137 endif
138
139 $(call shell-wrapper,$1,$2)
140
141 ifeq "$$($1_$2_INSTALL)" "YES"
142 ifeq "$$($1_$2_LIBEXEC)" "YES"
143 INSTALL_LIBEXECS += $1/$2/build/tmp/$$($1_$2_PROG)
144 else
145 INSTALL_BINS += $1/$2/build/tmp/$$($1_$2_PROG)
146 endif
147 endif
148
149 endif # package-data.mk exists
150
151 endef