Implement function-sections for Haskell code, #8405
[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 ("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-db 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 ifeq "$(SUPPORTS_COMPONENT_ID)" "NO"
85 ifeq "$4" "0"
86 $4_USE_COMPONENT_ID=NO
87 endif
88 endif
89
90 $1_$2_$4_DEP_OPTS = \
91 $$(foreach pkg,$$($1_$2_DEP_IPIDS),-package-id $$(pkg))
92
93 ifeq "$($4_USE_COMPONENT_ID)" "NO"
94 $4_THIS_COMPONENT_ID = -package-name
95 else
96 $4_THIS_COMPONENT_ID = -this-package-key
97 endif
98
99 $1_$2_$3_MOST_HC_OPTS = \
100 $$(WAY_$3_HC_OPTS) \
101 $$(CONF_HC_OPTS) \
102 $$(SRC_HC_OPTS) \
103 $$($1_HC_OPTS) \
104 $$($1_$2_HC_PKGCONF) \
105 $$(if $$($1_$2_PROG),, \
106 $$(if $$($1_PACKAGE),$$($4_THIS_COMPONENT_ID) $$($1_$2_COMPONENT_ID))) \
107 $$(if $$($1_PACKAGE),-hide-all-packages) \
108 -i $$(if $$($1_$2_HS_SRC_DIRS),$$(foreach dir,$$($1_$2_HS_SRC_DIRS),-i$1/$$(dir)),-i$1) \
109 -i$1/$2/build -i$1/$2/build/autogen \
110 -I$1/$2/build -I$1/$2/build/autogen \
111 $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
112 $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
113 $$(foreach inc,$$($1_$2_INCLUDE),-\#include "$$(inc)") \
114 $$(foreach opt,$$($1_$2_CPP_OPTS),-optP$$(opt)) \
115 $$(if $$($1_PACKAGE),-optP-include -optP$1/$2/build/autogen/cabal_macros.h) \
116 $$($1_$2_$4_DEP_OPTS) \
117 $$($1_$2_HC_OPTS) \
118 $$(CONF_HC_OPTS_STAGE$4) \
119 $$($1_$2_MORE_HC_OPTS) \
120 $$($1_$2_EXTRA_HC_OPTS) \
121 $$($1_$2_$3_HC_OPTS) \
122 $$($$(basename $$(subst ./,,$$<))_HC_OPTS) \
123 $$(SRC_HC_WARNING_OPTS) \
124 $$(EXTRA_HC_OPTS)
125
126 $1_$2_$3_MOST_DIR_HC_OPTS = \
127 $$($1_$2_$3_MOST_HC_OPTS) \
128 -odir $1/$2/build -hidir $1/$2/build -stubdir $1/$2/build
129
130 # NB. CONF_HC_OPTS_STAGE$4 has to be late enough to override $1_$2_HC_OPTS, so
131 # that -O0 is effective (see #5484)
132
133 # $1_$2_$3_ALL_HC_OPTS: this is all the options we will pass to GHC
134 # for a given ($1,$2,$3).
135 $1_$2_$3_ALL_HC_OPTS = \
136 -hisuf $$($3_hisuf) -osuf $$($3_osuf) -hcsuf $$($3_hcsuf) \
137 $$($1_$2_$3_MOST_DIR_HC_OPTS) \
138 $$(if $$(findstring YES,$$($1_$2_SplitObjs)),$$(if $$(findstring dyn,$3),,-split-objs),) \
139 $$(if $$(findstring YES,$$($1_$2_SplitSections)),$$(if $$(findstring dyn,$3),,-split-sections),) \
140 $$(if $$(findstring YES,$$($1_$2_DYNAMIC_TOO)),$$(if $$(findstring v,$3),-dynamic-too))
141
142 ifeq "$3" "dyn"
143 ifeq "$$(HostOS_CPP)" "mingw32"
144 ifneq "$$($1_$2_dll0_MODULES)" ""
145 $1_$2_$3_ALL_HC_OPTS += -dll-split $1/$2/dll-split
146 endif
147 endif
148 endif
149
150 $1_$2_$3_ALL_CC_OPTS = \
151 $$(WAY_$3_CC_OPTS) \
152 $$($1_$2_DIST_GCC_CC_OPTS) \
153 $$($1_$2_$3_CC_OPTS) \
154 $$($$(basename $$<)_CC_OPTS) \
155 $$($1_$2_EXTRA_CC_OPTS) \
156 $$(EXTRA_CC_OPTS)
157
158 $1_$2_$3_GHC_CC_OPTS = \
159 $$(addprefix -optc, $$($1_$2_$3_ALL_CC_OPTS)) \
160 $$($1_$2_$3_MOST_HC_OPTS)
161
162 # Options for passing to plain ld
163 $1_$2_$3_ALL_LD_OPTS = \
164 $$(WAY_$3_LD_OPTS) \
165 $$($1_$2_DIST_LD_OPTS) \
166 $$($1_$2_$3_LD_OPTS) \
167 $$($1_$2_EXTRA_LD_OPTS) \
168 $$(EXTRA_LD_OPTS)
169
170 # Options for passing to GHC when we use it for linking
171 $1_$2_$3_GHC_LD_OPTS = \
172 $$(addprefix -optl, $$($1_$2_$3_ALL_LD_OPTS)) \
173 $$($1_$2_$3_MOST_HC_OPTS)
174
175 $1_$2_$3_ALL_AS_OPTS = \
176 $$(CONF_AS_OPTS) \
177 $$(SRC_AS_OPTS) \
178 $$(WAY_$3_AS_OPTS) \
179 $$($1_AS_OPTS) \
180 $$($1_$2_AS_OPTS) \
181 $$($1_$2_$3_AS_OPTS) \
182 $$(EXTRA_AS_OPTS)
183
184 ifeq "$3" "dyn"
185 ifneq "$4" "0"
186 ifeq "$$(TargetElf)" "YES"
187 $1_$2_$3_GHC_LD_OPTS += \
188 -fno-use-rpaths \
189 $$(foreach d,$$($1_$2_TRANSITIVE_DEP_COMPONENT_IDS),-optl-Wl$$(comma)-rpath -optl-Wl$$(comma)'$$$$ORIGIN/../$$d') -optl-Wl,-zorigin
190 else ifeq "$$(TargetOS_CPP)" "darwin"
191 $1_$2_$3_GHC_LD_OPTS += \
192 -fno-use-rpaths \
193 $$(foreach d,$$($1_$2_TRANSITIVE_DEP_COMPONENT_IDS),-optl-Wl$$(comma)-rpath -optl-Wl$$(comma)'@loader_path/../$$d')
194 endif
195 endif
196 endif
197
198 endef
199