Merge branch 'master' of darcs.haskell.org:/srv/darcs//ghc
[ghc.git] / rules / distdir-way-opts.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 # Set compilation flags that additionally depend on a particular way
15
16 define distdir-way-opts # args: $1 = dir, $2 = distdir, $3 = way, $4 = stage
17
18 # Here is how the command line for a Haskell compilation is constructed.
19 # $1 is the directory we're building in
20 # $2 is the distdir (e.g. "dist", "dist-install" etc.)
21 # $3 is the way (e.g. "v", "p", etc.)
22 # $4 is the stage ("1", "2", "3")
23 #
24 # -----------------------------
25 # The variables affecting Haskell compilations are as follows, including
26 # the places in the build system that may define them.
27 #
28 # Variable Purpose Defined by
29 # -------------- ------------------------------ --------------
30 # $1_PACKAGE Package name for this dir, $1/$2/ghc.mk
31 # if it is a package
32 #
33 # CONF_HC_OPTS GHC options from ./configure mk/config.mk.in
34 #
35 # CONF_HC_OPTS_STAGE$4 GHC options from ./configure mk/config.mk.in
36 # specific to stage $4
37 #
38 # WAY_$3_HC_OPTS GHC options specific to way $3 mk/ways.mk
39 #
40 # SRC_HC_OPTS source-tree-wide GHC options mk/config.mk.in
41 # mk/build.mk
42 # mk/validate.mk
43 #
44 # SRC_HC_WARNING_OPTS source-tree-wide GHC warning mk/config.mk.in
45 # options mk/build.mk
46 # mk/validate.mk
47 #
48 # EXTRA_HC_OPTS for supplying extra options on make EXTRA_HC_OPTS=...
49 # the command line
50 #
51 # $1_HC_OPTS GHC options specific to this $1/$2/package-data.mk
52 # dir
53 #
54 # $1_$2_HC_OPTS GHC options specific to this $1/$2/package-data.mk
55 # dir and distdir
56 #
57 # $1_$2_$3_HC_OPTS GHC options specific to this $1/$2/package-data.mk
58 # dir, distdir and way
59 #
60 # $1_$2_MORE_HC_OPTS GHC options for this dir/distdir ???
61 #
62 # $1_$2_EXTRA_HC_OPTS GHC options for this dir/distdir mk/build.mk
63 #
64 # $1_$2_HC_PKGCONF -package-conf flag if necessary rules/package-config.mk
65 #
66 # $1_$2_HS_SRC_DIRS dirs relative to $1 containing $1/$2/package-data.mk
67 # source files
68 #
69 # $1_$2_CPP_OPTS CPP options $1/$2/package-data.mk
70 #
71 # <file>_HC_OPTS GHC options for this source $1/$2/ghc.mk
72 # file (without the extension)
73
74 # -----------------------------
75
76 # The actual options passed to a Haskell compilation are defined
77 # below. Note that in general, more specific sets of options come
78 # after the less specific, so that we can override global options
79 # on a per-directory or per-way basis, for example.
80
81 # $1_$2_$3_MOST_HC_OPTS is also passed to C compilations when we use
82 # GHC as the C compiler.
83
84 $1_$2_$3_MOST_HC_OPTS = \
85 $$(WAY_$3_HC_OPTS) \
86 $$(CONF_HC_OPTS) \
87 $$(SRC_HC_OPTS) \
88 $$($1_HC_OPTS) \
89 $$($1_$2_HC_PKGCONF) \
90 $$(if $$($1_$2_PROG),, \
91 $$(if $$($1_PACKAGE),-package-name $$($1_PACKAGE)-$$($1_$2_VERSION))) \
92 $$(if $$($1_PACKAGE),-hide-all-packages) \
93 -i $$(if $$($1_$2_HS_SRC_DIRS),$$(foreach dir,$$($1_$2_HS_SRC_DIRS),-i$1/$$(dir)),-i$1) \
94 -i$1/$2/build -i$1/$2/build/autogen \
95 -I$1/$2/build -I$1/$2/build/autogen \
96 $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
97 $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
98 $$(foreach inc,$$($1_$2_INCLUDE),-\#include "$$(inc)") \
99 $$(foreach opt,$$($1_$2_CPP_OPTS),-optP$$(opt)) \
100 $$(if $$($1_PACKAGE),-optP-include -optP$1/$2/build/autogen/cabal_macros.h) \
101 $$(foreach pkg,$$($1_$2_DEPS),-package $$(pkg)) \
102 $$(if $$(findstring YES,$$($1_$2_SplitObjs)),$$(if $$(findstring dyn,$3),,-split-objs),) \
103 $$($1_$2_HC_OPTS) \
104 $$(CONF_HC_OPTS_STAGE$4) \
105 $$($1_$2_MORE_HC_OPTS) \
106 $$($1_$2_EXTRA_HC_OPTS) \
107 $$($1_$2_$3_HC_OPTS) \
108 $$($$(basename $$<)_HC_OPTS) \
109 $$(SRC_HC_WARNING_OPTS) \
110 $$(EXTRA_HC_OPTS)
111
112 # NB. CONF_HC_OPTS_STAGE$4 has to be late enough to override $1_$2_HC_OPTS, so
113 # that -O0 is effective (see #5484)
114
115 # $1_$2_$3_ALL_HC_OPTS: this is all the options we will pass to GHC
116 # for a given ($1,$2,$3).
117 $1_$2_$3_ALL_HC_OPTS = \
118 $$($1_$2_$3_MOST_HC_OPTS) \
119 -odir $1/$2/build -hidir $1/$2/build -stubdir $1/$2/build \
120 -hisuf $$($3_hisuf) -osuf $$($3_osuf) -hcsuf $$($3_hcsuf)
121
122 ifeq "$4" "0"
123 # This is a bit of a hack.
124 # If we are compiling something with the bootstrapping compiler on
125 # cygwin, and it uses an include file from the rts (say), then we
126 # need to stop mkdependC from generating a dependincy on
127 # c:/ghc/rts/include/Rts.h
128 # as that confuses make. So we use -isystem instead of -I, which stops
129 # these dependencies from being generated. Technically this is wrong if
130 # we depend on a library that is built inside the build tree, and we
131 # use headers from that library, but currently I don't think that's the
132 # case.
133 $1_$2_DEP_INCLUDE_DIRS_FLAG = -isystem
134 else
135 $1_$2_DEP_INCLUDE_DIRS_FLAG = -I
136 endif
137
138 ifneq ($$(strip $$($1_$2_DEP_INCLUDE_DIRS_SINGLE_QUOTED)),)
139 $1_$2_CC_INC_FLAGS := $$(subst $$(space)',$$(space)$$($1_$2_DEP_INCLUDE_DIRS_FLAG)',$$(space)$$($1_$2_DEP_INCLUDE_DIRS_SINGLE_QUOTED))
140 endif
141
142 # The CONF_CC_OPTS_STAGE$4 options are what we use to get gcc to
143 # behave correctly, but they are specific to the gcc that we are using.
144 # If GHC is compiling C code then it will take care of that for us,
145 # and in the case of the stage 0 compiler it may be using a different
146 # gcc, so we don't want to use our gcc-specific options.
147 $1_$2_DIST_GCC_CC_OPTS = \
148 $$(CONF_CC_OPTS_STAGE$4) \
149 $$($1_$2_DIST_CC_OPTS)
150
151 $1_$2_DIST_CC_OPTS = \
152 $$(SRC_CC_OPTS) \
153 $$($1_CC_OPTS) \
154 $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
155 $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
156 $$($1_$2_CC_OPTS) \
157 $$($1_$2_CPP_OPTS) \
158 $$($1_$2_CC_INC_FLAGS) \
159 $$($1_$2_DEP_CC_OPTS) \
160 $$(SRC_CC_WARNING_OPTS)
161
162 ifneq ($$(strip $$($1_$2_DEP_LIB_DIRS_SINGLE_QUOTED)),)
163 $1_$2_DIST_LD_LIB_DIRS := $$(subst $$(space)',$$(space)-L',$$(space)$$($1_$2_DEP_LIB_DIRS_SINGLE_QUOTED))
164 endif
165
166 $1_$2_DIST_LD_OPTS = \
167 $$(CONF_GCC_LINKER_OPTS_STAGE$4) \
168 $$(SRC_LD_OPTS) \
169 $$($1_LD_OPTS) \
170 $$($1_$2_LD_OPTS) \
171 $$($1_$2_DIST_LD_LIB_DIRS) \
172 $$(foreach opt,$$($1_$2_DEP_EXTRA_LIBS),-l$$(opt)) \
173 $$($1_$2_DEP_LD_OPTS)
174
175 # c.f. Cabal's Distribution.Simple.PreProcess.ppHsc2hs
176 # We use '' around cflags and lflags to handle paths with backslashes in
177 # on Windows
178 ifneq ($$(strip $$($1_$2_DIST_GCC_CC_OPTS)),)
179 $1_$2_$3_HSC2HS_CC_OPTS:=$$(shell for i in $$($1_$2_DIST_GCC_CC_OPTS); do echo \'--cflag=$$$$i\'; done)
180 endif
181 ifneq ($$(strip $$($1_$2_DIST_LD_OPTS)),)
182 $1_$2_$3_HSC2HS_LD_OPTS:=$$(shell for i in $$($1_$2_DIST_LD_OPTS); do echo \'--lflag=$$$$i\'; done)
183 endif
184
185 $1_$2_$3_ALL_HSC2HS_OPTS = \
186 --cc=$$(WhatGccIsCalled) \
187 --ld=$$(WhatGccIsCalled) \
188 $$(CONF_HSC2HS_OPTS) \
189 $$(SRC_HSC2HS_OPTS) \
190 $$(WAY_$3_HSC2HS_OPTS) \
191 --cflag=-D__GLASGOW_HASKELL__=$$(if $$(filter 0,$4),$$(GhcCanonVersion),$$(ProjectVersionInt)) \
192 $$($1_$2_$3_HSC2HS_CC_OPTS) \
193 $$($1_$2_$3_HSC2HS_LD_OPTS) \
194 --cflag=-I$1/$2/build/autogen \
195 $$(if $$($1_PACKAGE),--cflag=-include --cflag=$1/$2/build/autogen/cabal_macros.h) \
196 $$($$(basename $$<)_HSC2HS_OPTS) \
197 $$(EXTRA_HSC2HS_OPTS)
198
199 $1_$2_$3_ALL_CC_OPTS = \
200 $$(WAY_$3_CC_OPTS) \
201 $$($1_$2_DIST_GCC_CC_OPTS) \
202 $$($1_$2_$3_CC_OPTS) \
203 $$($$(basename $$<)_CC_OPTS) \
204 $$(EXTRA_CC_OPTS)
205
206 $1_$2_$3_GHC_CC_OPTS = \
207 $$(addprefix -optc, \
208 $$(WAY_$3_CC_OPTS) \
209 $$($1_$2_DIST_CC_OPTS) \
210 $$($1_$2_$3_CC_OPTS) \
211 $$($$(basename $$<)_CC_OPTS) \
212 $$(EXTRA_CC_OPTS)) \
213 $$($1_$2_$3_MOST_HC_OPTS)
214
215 $1_$2_$3_ALL_AS_OPTS = \
216 $$(CONF_AS_OPTS) \
217 $$(SRC_AS_OPTS)
218 $$(WAY_$3_AS_OPTS) \
219 $$($1_AS_OPTS) \
220 $$($1_$2_AS_OPTS) \
221 $$($1_$2_$3_AS_OPTS) \
222 $$(EXTRA_AS_OPTS)
223
224 $1_$2_$3_ALL_ALEX_OPTS = \
225 $$(CONF_ALEX_OPTS) \
226 $$(SRC_ALEX_OPTS)
227 $$(WAY_$3_ALEX_OPTS) \
228 $$($1_ALEX_OPTS) \
229 $$($1_$2_ALEX_OPTS) \
230 $$($1_$2_$3_ALEX_OPTS) \
231 $$(EXTRA_ALEX_OPTS)
232
233 $1_$2_$3_ALL_HAPPY_OPTS = \
234 $$(CONF_HAPPY_OPTS) \
235 $$(SRC_HAPPY_OPTS) \
236 $$(WAY_$3_HAPPY_OPTS) \
237 $$($1_HAPPY_OPTS) \
238 $$($1_$2_HAPPY_OPTS) \
239 $$($1_$2_$3_HAPPY_OPTS) \
240 $$(EXTRA_HAPPY_OPTS)
241
242 endef
243