Don't build the ghc DLL on Windows; works around trac #5987
[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) | $$$$(dir $$$$@)/.
98 "$$(CP)" -p $$< $$@
99 endif
100 endif
101
102 $(call shell-wrapper,$1,$2)
103
104 $1_$2_WAYS = v
105
106 $(call hs-sources,$1,$2)
107 $(call c-sources,$1,$2)
108
109 # --- IMPLICIT RULES
110
111 # Just the 'v' way for programs
112 $(call distdir-way-opts,$1,$2,v,$3)
113
114 ifeq "$3" "0"
115 # For stage 0, we use GHC to compile C sources so that we don't have to
116 # worry about where the RTS header files are
117 $(call c-suffix-rules,$1,$2,v,YES)
118 else
119 ifeq "$$($1_$2_UseGhcForCC)" "YES"
120 $(call c-suffix-rules,$1,$2,v,YES)
121 else
122 $(call c-suffix-rules,$1,$2,v,NO)
123 endif
124 endif
125
126 $(call hs-suffix-rules,$1,$2,v)
127 $$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
128 $$(eval $$(call hs-suffix-rules-srcdir,$1,$2,v,$$(dir))))
129
130 $(call c-objs,$1,$2,v)
131 $(call hs-objs,$1,$2,v)
132
133 $1_$2_LINK_WITH_GCC = NO
134 ifeq "$$(BootingFromHc)" "YES"
135 $1_$2_LINK_WITH_GCC = YES
136 endif
137
138 ifeq "$$($1_$2_v_HS_OBJS)" ""
139 # We don't want to link the GHC RTS into C-only programs. There's no
140 # point, and it confuses the test that all GHC-compiled programs
141 # were compiled with the right GHC.
142 $1_$2_GHC_LD_OPTS = -no-auto-link-packages -no-hs-main
143 endif
144
145 ifneq "$$(BINDIST)" "YES"
146 # The quadrupled $'s here are because the _v_LIB variables aren't
147 # necessarily set when this part of the makefile is read
148 $1/$2/build/tmp/$$($1_$2_PROG) : \
149 $$(foreach dep,$$($1_$2_DEP_NAMES),\
150 $$(if $$(filter ghc,$$(dep)),\
151 $(if $(filter 0,$3),$$(compiler_stage1_v_LIB),\
152 $(if $(filter 1,$3),$$(compiler_stage2_v_LIB),\
153 $(if $(filter 2,$3),$$(compiler_stage2_v_LIB),\
154 $$(error Bad build stage)))),\
155 $$$$(libraries/$$(dep)_dist-$(if $(filter 0,$3),boot,install)_v_LIB)))
156
157 ifeq "$$($1_$2_LINK_WITH_GCC)" "NO"
158 $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 $$$$@)/.
159 $$(call cmd,$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))
160 else
161 $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 $$$$@)/.
162 $$(call cmd,$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))
163 endif
164
165 # Note [lib-depends] if this program is built with stage1 or greater, we
166 # need to depend on the libraries too. NB. since $(ALL_STAGE1_LIBS) and
167 # $(ALL_RTS_LIBS) are not defined until after libraries/*/ghc.mk have
168 # been included, this introduces an ordering dependency.
169 ifneq "$$(CLEANING)" "YES"
170 ifneq "$3" "0"
171 ifneq "$$($1_$2_HS_SRCS)" ""
172 ifeq "$$(strip $$(ALL_STAGE1_LIBS))" ""
173 $$(error ordering failure in $1 ($2): ALL_STAGE1_LIBS is empty)
174 endif
175 endif
176 $1/$2/build/tmp/$$($1_$2_PROG) : $$(ALL_STAGE1_LIBS) $$(ALL_RTS_LIBS) $$(OTHER_LIBS)
177 endif
178 endif
179 endif
180
181 ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
182 $(call all-target,$1_$2,$$($1_$2_INPLACE))
183 endif
184 $(call clean-target,$1,$2_inplace,$$($1_$2_INPLACE))
185
186 ifeq "$$($1_$2_INSTALL)" "YES"
187 ifeq "$$($1_$2_TOPDIR)" "YES"
188 INSTALL_TOPDIRS += $1/$2/build/tmp/$$($1_$2_PROG)
189 else
190 INSTALL_BINS += $1/$2/build/tmp/$$($1_$2_PROG)
191 endif
192 endif
193
194 $(call dependencies,$1,$2,$3)
195
196 endef