Fix build on cygwin: Normalise slashes in .depend files to be /
[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 ifneq "$$(CLEANING)" "YES"
28 ifeq "$$($1_$2_PROG)" ""
29 $$(error $1_$2_PROG is not set)
30 endif
31 endif
32
33 ifeq "$$(findstring $3,0 1 2)" ""
34 $$(error $1/$2: stage argument to build-prog should be 0, 1, or 2)
35 endif
36
37 $(call clean-target,$1,$2,$1/$2)
38
39 ifneq "$$($1_$2_NOT_NEEDED)" "YES"
40 $$(eval $$(call build-prog-helper,$1,$2,$3))
41 endif
42 endef
43
44
45 define build-prog-helper
46 # $1 = dir
47 # $2 = distdir
48 # $3 = GHC stage to use (0 == bootstrapping compiler)
49
50 $(call all-target,$1,all_$1_$2)
51
52 ifeq "$$($1_USES_CABAL)" "YES"
53 $1_$2_USES_CABAL = YES
54 endif
55
56 ifeq "$$($1_$2_USES_CABAL)" "YES"
57 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
58 include $1/$2/package-data.mk
59 endif
60 endif
61
62 $(call package-config,$1,$2,$3)
63
64 ifeq "$$($1_$2_USES_CABAL)$$($1_$2_VERSION)" "YES"
65 $1_$2_DISABLE = YES
66 endif
67
68 ifeq "$$($1_$2_DISABLE)" "YES"
69
70 ifeq "$$(DEBUG)" "YES"
71 $$(warning $1/$2 disabled)
72 endif
73
74 # The following code to build the package all depends on settings
75 # obtained from package-data.mk.  If we don't have package-data.mk
76 # yet, then don't try to do anything else with this package.  Make will
77 # try to build package-data.mk, then restart itself and we'll be in business.
78
79 $(call all-target,$1_$2,$1/$2/package-data.mk)
80
81 # We have a rule for package-data.mk only when the package is
82 # disabled, because we want the build to fail if we haven't run phase 0.
83 ifneq "$$(BINDIST)" "YES"
84 $(call build-package-data,$1,$2,$3)
85 endif
86
87 else
88
89 ifneq "$$(BINDIST)" "YES"
90 $1_$2_WAYS = v
91
92 $(call hs-sources,$1,$2)
93 $(call c-sources,$1,$2)
94
95 # --- DEPENDENCIES
96
97 $1_$2_depfile_base = $1/$2/build/.depend
98
99 $(call build-dependencies,$1,$2,$3)
100
101 # --- IMPLICIT RULES
102
103 # Just the 'v' way for programs
104 $(call distdir-way-opts,$1,$2,v,$3)
105
106 ifeq "$3" "0"
107 # For stage 0, we use GHC to compile C sources so that we don't have to
108 # worry about where the RTS header files are
109 $(call c-suffix-rules,$1,$2,v,YES)
110 else
111 $(call c-suffix-rules,$1,$2,v,NO)
112 endif
113
114 $(call hs-suffix-rules,$1,$2,v)
115 $$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
116   $$(eval $$(call hs-suffix-rules-srcdir,$1,$2,v,$$(dir))))
117
118 $(call c-objs,$1,$2,v)
119 $(call hs-objs,$1,$2,v)
120
121 $1_$2_LINK_WITH_GCC = NO
122 ifeq "$$(BootingFromHc)" "YES"
123 $1_$2_LINK_WITH_GCC = YES
124 endif
125 ifeq "$$($1_$2_v_HS_OBJS)" ""
126 $1_$2_LINK_WITH_GCC = YES
127 endif
128
129 ifeq "$$($1_$2_LINK_WITH_GCC)" "NO"
130 $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 $$$$@)/.
131         "$$($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)
132 else
133 $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 $$$$@)/.
134         "$$(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)
135 endif
136
137 # Note [lib-depends] if this program is built with stage1 or greater, we
138 # need to depend on the libraries too.  NB. since $(ALL_STAGE1_LIBS) and
139 # $(ALL_RTS_LIBS) are not defined until after libraries/*/ghc.mk have
140 # been included, this introduces an ordering dependency.
141 ifneq "$3" "0"
142 ifeq "$$(ALL_STAGE1_LIBS)" ""
143 $$(error ordering failure in $1: $$(ALL_STAGE1_LIBS) is empty)
144 endif
145 $1/$2/build/tmp/$$($1_$2_PROG) : $$(ALL_STAGE1_LIBS) $$(ALL_RTS_LIBS) $$(OTHER_LIBS)
146 endif
147 endif
148
149 ifeq "$$($1_$2_INSTALL_INPLACE)" "NO"
150 $(call all-target,$1_$2,$1/$2/build/tmp/$$($1_$2_PROG))
151 else
152 # Where do we install the inplace version?
153 ifeq "$$($1_$2_SHELL_WRAPPER) $$(Windows)" "YES NO"
154 $1_$2_INPLACE = $$(INPLACE_LIB)/$$($1_$2_PROG)
155 else
156 ifeq "$$($1_$2_TOPDIR)" "YES"
157 $1_$2_INPLACE = $$(INPLACE_TOPDIR)/$$($1_$2_PROG)
158 else
159 $1_$2_INPLACE = $$(INPLACE_BIN)/$$($1_$2_PROG)
160 endif
161 endif
162
163 $(call all-target,$1_$2,$$($1_$2_INPLACE))
164 $(call clean-target,$1,$2_inplace,$$($1_$2_INPLACE))
165
166 # INPLACE_BIN might be empty if we're distcleaning
167 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
168 $$($1_$2_INPLACE) : $1/$2/build/tmp/$$($1_$2_PROG) | $$$$(dir $$$$@)/.
169         "$$(CP)" -p $$< $$@
170         touch $$@
171 endif
172
173 # touch is necessary; cp doesn't update the file time.
174 endif
175
176 $(call shell-wrapper,$1,$2)
177
178 ifeq "$$($1_$2_INSTALL)" "YES"
179 ifeq "$$($1_$2_TOPDIR)" "YES"
180 INSTALL_TOPDIRS += $1/$2/build/tmp/$$($1_$2_PROG)
181 else
182 INSTALL_BINS += $1/$2/build/tmp/$$($1_$2_PROG)
183 endif
184 endif
185
186 endif # package-data.mk exists
187
188 endef