build system: Include CONF_LD_LINKER_OPTS in ALL_LD_OPTS
[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://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://ghc.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 ("0", "1", "2") that the options are passed to
23 # See Note [Stage number in build variables]
24 # in mk/config.mk.in.
25 #
26 # -----------------------------
27 # The variables affecting Haskell compilations are as follows, including
28 # the places in the build system that may define them.
29 #
30 # Variable Purpose Defined by
31 # -------------- ------------------------------ --------------
32 # $1_PACKAGE Package name for this dir, $1/$2/ghc.mk
33 # if it is a package
34 #
35 # CONF_HC_OPTS GHC options from ./configure mk/config.mk.in
36 #
37 # CONF_CPP_OPTS_STAGE$4 CPP options from ./configure mk/config.mk.in
38 #
39 # CONF_CC_OPTS_STAGE$4 C compiler options from mk/config.mk.in
40 # ./configure
41 #
42 # CONF_HC_OPTS_STAGE$4 GHC options from ./configure mk/config.mk.in
43 # specific to stage $4
44 #
45 # CONF_LD_LINKER_OPTS_STAGE$4
46 # GHC options from ./configure mk/config.mk.in
47 # specific to stage $4
48 #
49 # WAY_$3_HC_OPTS GHC options specific to way $3 mk/ways.mk
50 #
51 # SRC_HC_OPTS source-tree-wide GHC options mk/config.mk.in
52 # mk/build.mk
53 # mk/validate.mk
54 # mk/warnings.mk
55 #
56 # SRC_HC_OPTS_STAGE$4 source-tree-wide GHC options, mk/config.mk.in
57 # supplied to the stage $4 mk/build.mk
58 # compiler only mk/validate.mk
59 # mk/warnings.mk
60 #
61 # SRC_HC_WARNING_OPTS source-tree-wide GHC warning mk/config.mk.in
62 # options mk/build.mk
63 # mk/validate.mk
64 # mk/warnings.mk
65 #
66 # SRC_HC_WARNING_OPTS_STAGE$4 mk/config.mk.in
67 # source-tree-wide GHC warning mk/build.mk
68 # options, supplied to the mk/validate.mk
69 # stage $4 compiler only mk/warnings.mk
70 #
71 # EXTRA_HC_OPTS for supplying extra options on make EXTRA_HC_OPTS=...
72 # the command line
73 #
74 # $1_HC_OPTS GHC options specific to this $1/$2/package-data.mk
75 # dir
76 #
77 # $1_$2_HC_OPTS GHC options specific to this $1/$2/package-data.mk
78 # dir and distdir
79 #
80 # $1_$2_$3_HC_OPTS GHC options specific to this $1/$2/package-data.mk
81 # dir, distdir and way
82 #
83 # $1_$2_MORE_HC_OPTS GHC options for this dir/distdir ???
84 #
85 # $1_$2_EXTRA_HC_OPTS GHC options for this dir/distdir mk/build.mk
86 # mk/warnings.mk
87 #
88 # $1_$2_HC_PKGCONF -package-db flag if necessary rules/package-config.mk
89 #
90 # $1_$2_HS_SRC_DIRS dirs relative to $1 containing $1/$2/package-data.mk
91 # source files
92 #
93 # $1_$2_CPP_OPTS CPP options $1/$2/package-data.mk
94 #
95 # <file>_HC_OPTS GHC options for this source $1/$2/ghc.mk
96 # file (without the extension)
97
98 # -----------------------------
99
100 # The actual options passed to a Haskell compilation are defined
101 # below. Note that in general, more specific sets of options come
102 # after the less specific, so that we can override global options
103 # on a per-directory or per-way basis, for example.
104
105 # $1_$2_$3_MOST_HC_OPTS is also passed to C compilations when we use
106 # GHC as the C compiler.
107
108 ifeq "$(SUPPORTS_THIS_UNIT_ID)" "NO"
109 ifeq "$4" "0"
110 $4_USE_THIS_UNIT_ID=NO
111 endif
112 endif
113
114 $1_$2_$4_DEP_OPTS = \
115 $$(foreach pkg,$$($1_$2_DEP_IPIDS),-package-id $$(pkg))
116
117 ifeq "$($4_USE_THIS_UNIT_ID)" "NO"
118 $4_THIS_UNIT_ID = -this-package-key
119 else
120 $4_THIS_UNIT_ID = -this-unit-id
121 endif
122
123 $1_$2_$3_MOST_HC_OPTS = \
124 $$(WAY_$3_HC_OPTS) \
125 $$(CONF_HC_OPTS) \
126 $$(SRC_HC_OPTS) \
127 $$(SRC_HC_OPTS_STAGE$4) \
128 $$($1_HC_OPTS) \
129 $$($1_$2_HC_PKGCONF) \
130 $$(if $$($1_$2_PROG),, \
131 $$(if $$($1_PACKAGE),$$($4_THIS_UNIT_ID) $$($1_$2_COMPONENT_ID))) \
132 $$(if $$($1_PACKAGE),-hide-all-packages) \
133 -i $$(if $$($1_$2_HS_SRC_DIRS),$$(foreach dir,$$($1_$2_HS_SRC_DIRS),-i$1/$$(dir)),-i$1) \
134 -i$1/$2/build \
135 -I$1/$2/build \
136 -i$1/$2/build/$$(or $$($1_EXECUTABLE),$$($1_$2_PROGNAME),.)/autogen \
137 -I$1/$2/build/$$(or $$($1_EXECUTABLE),$$($1_$2_PROGNAME),.)/autogen \
138 $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
139 $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
140 $$(foreach inc,$$($1_$2_INCLUDE),-\#include "$$(inc)") \
141 $$(foreach opt,$$($1_$2_CPP_OPTS),-optP$$(opt)) \
142 $$(if $$($1_PACKAGE),-optP-include \
143 -optP$1/$2/build/$$(or $$($1_EXECUTABLE),$$($1_$2_PROGNAME),.)/autogen/cabal_macros.h) \
144 $$($1_$2_$4_DEP_OPTS) \
145 $$($1_$2_HC_OPTS) \
146 $$(CONF_HC_OPTS_STAGE$4) \
147 $$($1_$2_MORE_HC_OPTS) \
148 $$($1_$2_EXTRA_HC_OPTS) \
149 $$($1_$2_$3_HC_OPTS) \
150 $$($$(basename $$(subst ./,,$$<))_HC_OPTS) \
151 $$(SRC_HC_WARNING_OPTS) \
152 $$(SRC_HC_WARNING_OPTS_STAGE$4) \
153 $$(EXTRA_HC_OPTS)
154
155 # What is going on with $1_EXECUTABLE? Recent version of Cabal
156 # place the cabal_macros.h for executables in build/exename/autogen
157 # rather than the traditional build/autogen. This is Right(TM)
158 # thing to do, but we have to accommodate it. Usually, it suffices
159 # to look in the PROGNAME, but for ghc the PROGNAME is ghc-stage1
160 # while Cabal puts it in 'ghc', so we $1_EXECUTABLE is for that
161 # case.
162
163 $1_$2_$3_MOST_DIR_HC_OPTS = \
164 $$($1_$2_$3_MOST_HC_OPTS) \
165 -odir $1/$2/build -hidir $1/$2/build -stubdir $1/$2/build
166
167 # NB. CONF_HC_OPTS_STAGE$4 has to be late enough to override $1_$2_HC_OPTS, so
168 # that -O0 is effective (see #5484)
169
170 # $1_$2_$3_ALL_HC_OPTS: this is all the options we will pass to GHC
171 # for a given ($1,$2,$3).
172 $1_$2_$3_ALL_HC_OPTS = \
173 -hisuf $$($3_hisuf) -osuf $$($3_osuf) -hcsuf $$($3_hcsuf) \
174 $$($1_$2_$3_MOST_DIR_HC_OPTS) \
175 $$(if $$(findstring YES,$$($1_$2_SplitObjs)),$$(if $$(findstring dyn,$3),,-split-objs),) \
176 $$(if $$(findstring YES,$$($1_$2_SplitSections)),$$(if $$(findstring dyn,$3),,-split-sections),) \
177 $$(if $$(findstring YES,$$($1_$2_DYNAMIC_TOO)),$$(if $$(findstring v,$3),-dynamic-too))
178
179 ifeq "$3" "dyn"
180 ifeq "$$(HostOS_CPP)" "mingw32"
181 ifneq "$$($1_$2_dll0_MODULES)" ""
182 $1_$2_$3_ALL_HC_OPTS += -dll-split $1/$2/dll-split
183 endif
184 endif
185 endif
186
187 $1_$2_$3_ALL_CC_OPTS = \
188 $$(WAY_$3_CC_OPTS) \
189 $$($1_$2_DIST_GCC_CC_OPTS) \
190 $$($1_$2_$3_CC_OPTS) \
191 $$($$(basename $$<)_CC_OPTS) \
192 $$($1_$2_EXTRA_CC_OPTS) \
193 $$(EXTRA_CC_OPTS)
194
195 $1_$2_$3_GHC_CC_OPTS = \
196 $$(addprefix -optc, $$($1_$2_$3_ALL_CC_OPTS)) \
197 $$($1_$2_$3_MOST_HC_OPTS)
198
199 # Options for passing to plain ld
200 $1_$2_$3_ALL_LD_OPTS = \
201 $$(WAY_$3_LD_OPTS) \
202 $$($1_$2_DIST_LD_OPTS) \
203 $$($1_$2_$3_LD_OPTS) \
204 $$($1_$2_EXTRA_LD_OPTS) \
205 $$(EXTRA_LD_OPTS) \
206 $$(CONF_LD_LINKER_OPTS_STAGE$4)
207
208 # Options for passing to GHC when we use it for linking
209 $1_$2_$3_GHC_LD_OPTS = \
210 $$(addprefix -optl, $$($1_$2_$3_ALL_LD_OPTS)) \
211 $$($1_$2_$3_MOST_HC_OPTS)
212
213 $1_$2_$3_ALL_AS_OPTS = \
214 $$(CONF_AS_OPTS) \
215 $$(SRC_AS_OPTS) \
216 $$(WAY_$3_AS_OPTS) \
217 $$($1_AS_OPTS) \
218 $$($1_$2_AS_OPTS) \
219 $$($1_$2_$3_AS_OPTS) \
220 $$(EXTRA_AS_OPTS)
221
222 ifeq "$3" "dyn"
223 ifneq "$4" "0"
224 ifeq "$$(TargetElf)" "YES"
225 $1_$2_$3_GHC_LD_OPTS += \
226 -fno-use-rpaths \
227 $$(foreach d,$$($1_$2_TRANSITIVE_DEP_COMPONENT_IDS),-optl-Wl$$(comma)-rpath -optl-Wl$$(comma)'$$$$ORIGIN/../$$d') -optl-Wl,-zorigin
228 else ifeq "$$(TargetOS_CPP)" "darwin"
229 $1_$2_$3_GHC_LD_OPTS += \
230 -fno-use-rpaths \
231 $$(foreach d,$$($1_$2_TRANSITIVE_DEP_COMPONENT_IDS),-optl-Wl$$(comma)-rpath -optl-Wl$$(comma)'@loader_path/../$$d')
232 endif
233 endif
234 endif
235
236 endef
237