Use touchy rather than touch when building on Windows
[ghc.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 $(call trace, build-prog($1,$2,$3))
24 $(call profStart, build-prog($1,$2,$3))
25 # $1 = dir
26 # $2 = distdir
27 # $3 = GHC stage to use (0 == bootstrapping compiler)
28
29 ifneq "$$(CLEANING)" "YES"
30 ifeq "$$($1_$2_PROG)" ""
31 $$(error $1_$2_PROG is not set)
32 endif
33 endif
34
35 ifeq "$$(findstring $3,0 1 2)" ""
36 $$(error $1/$2: stage argument to build-prog should be 0, 1, or 2)
37 endif
38
39 $(call clean-target,$1,$2,$1/$2)
40
41 ifneq "$$($1_$2_NOT_NEEDED)" "YES"
42 $$(eval $$(call build-prog-helper,$1,$2,$3))
43 endif
44 $(call profEnd, build-prog($1,$2,$3))
45 endef
46
47
48 define build-prog-helper
49 # $1 = dir
50 # $2 = distdir
51 # $3 = GHC stage to use (0 == bootstrapping compiler)
52
53 ifeq "$$($1_USES_CABAL)" "YES"
54 $1_$2_USES_CABAL = YES
55 endif
56
57 $(call package-config,$1,$2,$3)
58
59 $1_$2_depfile_base = $1/$2/build/.depend
60
61 ifeq "$$($1_$2_INSTALL_INPLACE)" "NO"
62 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
63 $1_$2_INPLACE = $$(error $1_$2 should not be installed inplace, but INPLACE var evaluated)
64 else
65 $1_$2_INPLACE =
66 endif
67 else
68 # Where do we install the inplace version?
69 ifeq "$$($1_$2_SHELL_WRAPPER) $$(Windows)" "YES NO"
70 $1_$2_INPLACE = $$(INPLACE_LIB)/$$($1_$2_PROG)
71 else
72 ifeq "$$($1_$2_TOPDIR)" "YES"
73 $1_$2_INPLACE = $$(INPLACE_TOPDIR)/$$($1_$2_PROG)
74 else
75 $1_$2_INPLACE = $$(INPLACE_BIN)/$$($1_$2_PROG)
76 endif
77 endif
78 endif
79
80 ifeq "$$($1_$2_USES_CABAL)" "YES"
81 $(call build-package-data,$1,$2,$3)
82 ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
83 ifeq "$3" "0"
84 include $1/$2/package-data.mk
85 else ifeq "$(phase)" "final"
86 include $1/$2/package-data.mk
87 endif
88 endif
89 endif
90
91 $(call all-target,$1,all_$1_$2)
92 $(call all-target,$1_$2,$1/$2/build/tmp/$$($1_$2_PROG))
93
94 # INPLACE_BIN might be empty if we're distcleaning
95 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
96 ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
97 $$($1_$2_INPLACE) : $1/$2/build/tmp/$$($1_$2_PROG) $$(TOUCH_DEP) | $$$$(dir $$$$@)/.
98 "$$(CP)" -p $$< $$@
99 "$$(TOUCH_CMD)" $$@
100 endif
101 endif
102
103 $(call shell-wrapper,$1,$2)
104
105 $1_$2_WAYS = v
106
107 $(call hs-sources,$1,$2)
108 $(call c-sources,$1,$2)
109
110 # --- IMPLICIT RULES
111
112 # Just the 'v' way for programs
113 $(call distdir-way-opts,$1,$2,v,$3)
114
115 ifeq "$3" "0"
116 # For stage 0, we use GHC to compile C sources so that we don't have to
117 # worry about where the RTS header files are
118 $(call c-suffix-rules,$1,$2,v,YES)
119 else
120 ifeq "$$($1_$2_UseGhcForCC)" "YES"
121 $(call c-suffix-rules,$1,$2,v,YES)
122 else
123 $(call c-suffix-rules,$1,$2,v,NO)
124 endif
125 endif
126
127 $(call hs-suffix-rules,$1,$2,v)
128 $$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
129 $$(eval $$(call hs-suffix-rules-srcdir,$1,$2,v,$$(dir))))
130
131 $(call c-objs,$1,$2,v)
132 $(call hs-objs,$1,$2,v)
133
134 $1_$2_LINK_WITH_GCC = NO
135 ifeq "$$(BootingFromHc)" "YES"
136 $1_$2_LINK_WITH_GCC = YES
137 endif
138
139 ifeq "$$($1_$2_v_HS_OBJS)" ""
140 # We don't want to link the GHC RTS into C-only programs. There's no
141 # point, and it confuses the test that all GHC-compiled programs
142 # were compiled with the right GHC.
143 $1_$2_GHC_LD_OPTS = -no-auto-link-packages -no-hs-main
144 endif
145
146 ifneq "$$(BINDIST)" "YES"
147 # The quadrupled $'s here are because the _v_LIB variables aren't
148 # necessarily set when this part of the makefile is read
149 $1/$2/build/tmp/$$($1_$2_PROG) : \
150 $$(foreach dep,$$($1_$2_DEP_NAMES),\
151 $$(if $$(filter ghc,$$(dep)),\
152 $(if $(filter 0,$3),$$(compiler_stage1_v_LIB),\
153 $(if $(filter 1,$3),$$(compiler_stage2_v_LIB),\
154 $(if $(filter 2,$3),$$(compiler_stage2_v_LIB),\
155 $$(error Bad build stage)))),\
156 $$$$(libraries/$$(dep)_dist-$(if $(filter 0,$3),boot,install)_v_LIB)))
157
158 ifeq "$$($1_$2_LINK_WITH_GCC)" "NO"
159 $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 $$$$@)/.
160 "$$($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))
161 else
162 $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 $$$$@)/.
163 "$$($1_$2_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))
164 endif
165
166 # Note [lib-depends] if this program is built with stage1 or greater, we
167 # need to depend on the libraries too. NB. since $(ALL_STAGE1_LIBS) and
168 # $(ALL_RTS_LIBS) are not defined until after libraries/*/ghc.mk have
169 # been included, this introduces an ordering dependency.
170 ifneq "$$(CLEANING)" "YES"
171 ifneq "$3" "0"
172 ifneq "$$($1_$2_HS_SRCS)" ""
173 ifeq "$$(strip $$(ALL_STAGE1_LIBS))" ""
174 $$(error ordering failure in $1 ($2): ALL_STAGE1_LIBS is empty)
175 endif
176 endif
177 $1/$2/build/tmp/$$($1_$2_PROG) : $$(ALL_STAGE1_LIBS) $$(ALL_RTS_LIBS) $$(OTHER_LIBS)
178 endif
179 endif
180 endif
181
182 ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
183 $(call all-target,$1_$2,$$($1_$2_INPLACE))
184 endif
185 $(call clean-target,$1,$2_inplace,$$($1_$2_INPLACE))
186
187 ifeq "$$($1_$2_INSTALL)" "YES"
188 ifeq "$$($1_$2_TOPDIR)" "YES"
189 INSTALL_TOPDIRS += $1/$2/build/tmp/$$($1_$2_PROG)
190 else
191 INSTALL_BINS += $1/$2/build/tmp/$$($1_$2_PROG)
192 endif
193 endif
194
195 $(call dependencies,$1,$2,$3)
196
197 endef