f6b9a45b8f640f29f601164acf55ea39c75417ef
[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_HC_OPTS_STAGE$4 GHC options from ./configure mk/config.mk.in
38 # specific to stage $4
39 #
40 # WAY_$3_HC_OPTS GHC options specific to way $3 mk/ways.mk
41 #
42 # SRC_HC_OPTS source-tree-wide GHC options mk/config.mk.in
43 # mk/build.mk
44 # mk/validate.mk
45 # mk/warnings.mk
46 #
47 # SRC_HC_OPTS_STAGE$4 source-tree-wide GHC options, mk/config.mk.in
48 # supplied to the stage $4 mk/build.mk
49 # compiler only mk/validate.mk
50 # mk/warnings.mk
51 #
52 # SRC_HC_WARNING_OPTS source-tree-wide GHC warning mk/config.mk.in
53 # options mk/build.mk
54 # mk/validate.mk
55 # mk/warnings.mk
56 #
57 # SRC_HC_WARNING_OPTS_STAGE$4 mk/config.mk.in
58 # source-tree-wide GHC warning mk/build.mk
59 # options, supplied to the mk/validate.mk
60 # stage $4 compiler only mk/warnings.mk
61 #
62 # EXTRA_HC_OPTS for supplying extra options on make EXTRA_HC_OPTS=...
63 # the command line
64 #
65 # $1_HC_OPTS GHC options specific to this $1/$2/package-data.mk
66 # dir
67 #
68 # $1_$2_HC_OPTS GHC options specific to this $1/$2/package-data.mk
69 # dir and distdir
70 #
71 # $1_$2_$3_HC_OPTS GHC options specific to this $1/$2/package-data.mk
72 # dir, distdir and way
73 #
74 # $1_$2_MORE_HC_OPTS GHC options for this dir/distdir ???
75 #
76 # $1_$2_EXTRA_HC_OPTS GHC options for this dir/distdir mk/build.mk
77 # mk/warnings.mk
78 #
79 # $1_$2_HC_PKGCONF -package-db flag if necessary rules/package-config.mk
80 #
81 # $1_$2_HS_SRC_DIRS dirs relative to $1 containing $1/$2/package-data.mk
82 # source files
83 #
84 # $1_$2_CPP_OPTS CPP options $1/$2/package-data.mk
85 #
86 # <file>_HC_OPTS GHC options for this source $1/$2/ghc.mk
87 # file (without the extension)
88
89 # -----------------------------
90
91 # The actual options passed to a Haskell compilation are defined
92 # below. Note that in general, more specific sets of options come
93 # after the less specific, so that we can override global options
94 # on a per-directory or per-way basis, for example.
95
96 # $1_$2_$3_MOST_HC_OPTS is also passed to C compilations when we use
97 # GHC as the C compiler.
98
99 $1_$2_$4_DEP_OPTS = \
100 $$(foreach pkg,$$($1_$2_DEP_IPIDS),-package-id $$(pkg))
101
102 $1_$2_$3_MOST_HC_OPTS = \
103 $$(WAY_$3_HC_OPTS) \
104 $$(CONF_HC_OPTS) \
105 $$(SRC_HC_OPTS) \
106 $$(SRC_HC_OPTS_STAGE$4) \
107 $$($1_HC_OPTS) \
108 $$($1_$2_HC_PKGCONF) \
109 $$(if $$($1_$2_PROG),, \
110 $$(if $$($1_PACKAGE),-this-package-key $$($1_$2_COMPONENT_ID))) \
111 $$(if $$($1_PACKAGE),-hide-all-packages) \
112 -i $$(if $$($1_$2_HS_SRC_DIRS),$$(foreach dir,$$($1_$2_HS_SRC_DIRS),-i$1/$$(dir)),-i$1) \
113 -i$1/$2/build -i$1/$2/build/autogen \
114 -I$1/$2/build -I$1/$2/build/autogen \
115 $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
116 $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
117 $$(foreach inc,$$($1_$2_INCLUDE),-\#include "$$(inc)") \
118 $$(foreach opt,$$($1_$2_CPP_OPTS),-optP$$(opt)) \
119 $$(if $$($1_PACKAGE),-optP-include -optP$1/$2/build/autogen/cabal_macros.h) \
120 $$($1_$2_$4_DEP_OPTS) \
121 $$($1_$2_HC_OPTS) \
122 $$(CONF_HC_OPTS_STAGE$4) \
123 $$($1_$2_MORE_HC_OPTS) \
124 $$($1_$2_EXTRA_HC_OPTS) \
125 $$($1_$2_$3_HC_OPTS) \
126 $$($$(basename $$(subst ./,,$$<))_HC_OPTS) \
127 $$(SRC_HC_WARNING_OPTS) \
128 $$(SRC_HC_WARNING_OPTS_STAGE$4) \
129 $$(EXTRA_HC_OPTS)
130
131 $1_$2_$3_MOST_DIR_HC_OPTS = \
132 $$($1_$2_$3_MOST_HC_OPTS) \
133 -odir $1/$2/build -hidir $1/$2/build -stubdir $1/$2/build
134
135 # NB. CONF_HC_OPTS_STAGE$4 has to be late enough to override $1_$2_HC_OPTS, so
136 # that -O0 is effective (see #5484)
137
138 # $1_$2_$3_ALL_HC_OPTS: this is all the options we will pass to GHC
139 # for a given ($1,$2,$3).
140 $1_$2_$3_ALL_HC_OPTS = \
141 -hisuf $$($3_hisuf) -osuf $$($3_osuf) -hcsuf $$($3_hcsuf) \
142 $$($1_$2_$3_MOST_DIR_HC_OPTS) \
143 $$(if $$(findstring YES,$$($1_$2_SplitObjs)),$$(if $$(findstring dyn,$3),,-split-objs),) \
144 $$(if $$(findstring YES,$$($1_$2_SplitSections)),$$(if $$(findstring dyn,$3),,-split-sections),) \
145 $$(if $$(findstring YES,$$($1_$2_DYNAMIC_TOO)),$$(if $$(findstring v,$3),-dynamic-too))
146
147 ifeq "$3" "dyn"
148 ifeq "$$(HostOS_CPP)" "mingw32"
149 ifneq "$$($1_$2_dll0_MODULES)" ""
150 $1_$2_$3_ALL_HC_OPTS += -dll-split $1/$2/dll-split
151 endif
152 endif
153 endif
154
155 $1_$2_$3_ALL_CC_OPTS = \
156 $$(WAY_$3_CC_OPTS) \
157 $$($1_$2_DIST_GCC_CC_OPTS) \
158 $$($1_$2_$3_CC_OPTS) \
159 $$($$(basename $$<)_CC_OPTS) \
160 $$($1_$2_EXTRA_CC_OPTS) \
161 $$(EXTRA_CC_OPTS)
162
163 $1_$2_$3_GHC_CC_OPTS = \
164 $$(addprefix -optc, $$($1_$2_$3_ALL_CC_OPTS)) \
165 $$($1_$2_$3_MOST_HC_OPTS)
166
167 # Options for passing to plain ld
168 $1_$2_$3_ALL_LD_OPTS = \
169 $$(WAY_$3_LD_OPTS) \
170 $$($1_$2_DIST_LD_OPTS) \
171 $$($1_$2_$3_LD_OPTS) \
172 $$($1_$2_EXTRA_LD_OPTS) \
173 $$(EXTRA_LD_OPTS)
174
175 # Options for passing to GHC when we use it for linking
176 $1_$2_$3_GHC_LD_OPTS = \
177 $$(addprefix -optl, $$($1_$2_$3_ALL_LD_OPTS)) \
178 $$($1_$2_$3_MOST_HC_OPTS)
179
180 $1_$2_$3_ALL_AS_OPTS = \
181 $$(CONF_AS_OPTS) \
182 $$(SRC_AS_OPTS) \
183 $$(WAY_$3_AS_OPTS) \
184 $$($1_AS_OPTS) \
185 $$($1_$2_AS_OPTS) \
186 $$($1_$2_$3_AS_OPTS) \
187 $$(EXTRA_AS_OPTS)
188
189 ifeq "$3" "dyn"
190 ifneq "$4" "0"
191 ifeq "$$(TargetElf)" "YES"
192 $1_$2_$3_GHC_LD_OPTS += \
193 -fno-use-rpaths \
194 $$(foreach d,$$($1_$2_TRANSITIVE_DEP_COMPONENT_IDS),-optl-Wl$$(comma)-rpath -optl-Wl$$(comma)'$$$$ORIGIN/../$$d') -optl-Wl,-zorigin
195 else ifeq "$$(TargetOS_CPP)" "darwin"
196 $1_$2_$3_GHC_LD_OPTS += \
197 -fno-use-rpaths \
198 $$(foreach d,$$($1_$2_TRANSITIVE_DEP_COMPONENT_IDS),-optl-Wl$$(comma)-rpath -optl-Wl$$(comma)'@loader_path/../$$d')
199 endif
200 endif
201 endif
202
203 endef
204