distdir-way-opts.mk 7.78 KB
Newer Older
1 2 3 4 5 6 7
# -----------------------------------------------------------------------------
#
# (c) 2009 The University of Glasgow
#
# This file is part of the GHC build system.
#
# To understand how the build system works and how to modify it, see
8 9
#      http://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
#      http://ghc.haskell.org/trac/ghc/wiki/Building/Modifying
10 11 12
#
# -----------------------------------------------------------------------------

Ian Lynagh's avatar
Ian Lynagh committed
13 14 15

# Set compilation flags that additionally depend on a particular way

16
define distdir-way-opts # args: $1 = dir, $2 = distdir, $3 = way, $4 = stage
Ian Lynagh's avatar
Ian Lynagh committed
17

Simon Marlow's avatar
Simon Marlow committed
18 19 20 21
# Here is how the command line for a Haskell compilation is constructed.
#   $1 is the directory we're building in
#   $2 is the distdir (e.g. "dist", "dist-install" etc.)
#   $3 is the way (e.g. "v", "p", etc.)
22 23 24
#   $4 is the stage ("0", "1", "2") that the options are passed to
#                                   See Note [Stage number in build variables]
#                                   in mk/config.mk.in.
Simon Marlow's avatar
Simon Marlow committed
25 26 27 28 29 30 31 32
# 
# -----------------------------
# The variables affecting Haskell compilations are as follows, including
# the places in the build system that may define them.
#
#  Variable              Purpose                           Defined by
#  --------------        ------------------------------    --------------
#  $1_PACKAGE            Package name for this dir,        $1/$2/ghc.mk
33 34
#                        if it is a package   
#   
Simon Marlow's avatar
Simon Marlow committed
35
#  CONF_HC_OPTS          GHC options from ./configure      mk/config.mk.in
36
#   
Simon Marlow's avatar
Simon Marlow committed
37
#  CONF_HC_OPTS_STAGE$4  GHC options from ./configure      mk/config.mk.in
38 39
#                        specific to stage $4   
#   
Simon Marlow's avatar
Simon Marlow committed
40
#  WAY_$3_HC_OPTS        GHC options specific to way $3    mk/ways.mk
41
#   
Simon Marlow's avatar
Simon Marlow committed
42 43 44
#  SRC_HC_OPTS           source-tree-wide GHC options      mk/config.mk.in
#                                                          mk/build.mk
#                                                          mk/validate.mk
45 46 47 48 49 50 51
#                                                          mk/warnings.mk
#
#  SRC_HC_OPTS_STAGE$4   source-tree-wide GHC options,     mk/config.mk.in
#                        supplied to the stage $4          mk/build.mk
#                        compiler only                     mk/validate.mk
#                                                          mk/warnings.mk
#
Ian Lynagh's avatar
Ian Lynagh committed
52 53 54
#  SRC_HC_WARNING_OPTS   source-tree-wide GHC warning      mk/config.mk.in
#                        options                           mk/build.mk
#                                                          mk/validate.mk
55 56 57 58 59 60
#                                                          mk/warnings.mk
#
#  SRC_HC_WARNING_OPTS_STAGE$4                             mk/config.mk.in
#                        source-tree-wide GHC warning      mk/build.mk
#                        options, supplied to the          mk/validate.mk
#                        stage $4 compiler only            mk/warnings.mk
Ian Lynagh's avatar
Ian Lynagh committed
61
#   
Simon Marlow's avatar
Simon Marlow committed
62
#  EXTRA_HC_OPTS         for supplying extra options on    make EXTRA_HC_OPTS=...
63 64
#                        the command line   
#   
Simon Marlow's avatar
Simon Marlow committed
65 66
#  $1_HC_OPTS            GHC options specific to this      $1/$2/package-data.mk
#                        dir
67
#   
Simon Marlow's avatar
Simon Marlow committed
68 69
#  $1_$2_HC_OPTS         GHC options specific to this      $1/$2/package-data.mk
#                        dir and distdir
70
#   
Simon Marlow's avatar
Simon Marlow committed
71 72
#  $1_$2_$3_HC_OPTS      GHC options specific to this      $1/$2/package-data.mk
#                        dir, distdir and way
73
#   
Simon Marlow's avatar
Simon Marlow committed
74
#  $1_$2_MORE_HC_OPTS    GHC options for this dir/distdir  ???
75
#   
Simon Marlow's avatar
Simon Marlow committed
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
#   
Simon Marlow's avatar
Simon Marlow committed
81
#  $1_$2_HS_SRC_DIRS     dirs relative to $1 containing    $1/$2/package-data.mk
82 83
#                        source files   
#   
Simon Marlow's avatar
Simon Marlow committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97
#  $1_$2_CPP_OPTS        CPP options                       $1/$2/package-data.mk
#  
#  <file>_HC_OPTS        GHC options for this source       $1/$2/ghc.mk
#                        file (without the extension)

# -----------------------------

# The actual options passed to a Haskell compilation are defined
# below.  Note that in general, more specific sets of options come
# after the less specific, so that we can override global options
# on a per-directory or per-way basis, for example.

# $1_$2_$3_MOST_HC_OPTS is also passed to C compilations when we use
# GHC as the C compiler.
Ian Lynagh's avatar
Ian Lynagh committed
98

99
ifeq "$(SUPPORTS_COMPONENT_ID)" "NO"
100
ifeq "$4" "0"
101
$4_USE_COMPONENT_ID=NO
102 103 104
endif
endif

105
$1_$2_$4_DEP_OPTS = \
106 107
 $$(foreach pkg,$$($1_$2_DEP_IPIDS),-package-id $$(pkg))

108 109
ifeq "$($4_USE_COMPONENT_ID)" "NO"
$4_THIS_COMPONENT_ID = -package-name
110
else
111
$4_THIS_COMPONENT_ID = -this-package-key
112 113
endif

Ian Lynagh's avatar
Ian Lynagh committed
114 115
$1_$2_$3_MOST_HC_OPTS = \
 $$(WAY_$3_HC_OPTS) \
116 117
 $$(CONF_HC_OPTS) \
 $$(SRC_HC_OPTS) \
118
 $$(SRC_HC_OPTS_STAGE$4) \
119 120 121
 $$($1_HC_OPTS) \
 $$($1_$2_HC_PKGCONF) \
 $$(if $$($1_$2_PROG),, \
122
        $$(if $$($1_PACKAGE),$$($4_THIS_COMPONENT_ID) $$($1_$2_COMPONENT_ID))) \
123 124 125 126 127 128 129 130 131
 $$(if $$($1_PACKAGE),-hide-all-packages) \
 -i $$(if $$($1_$2_HS_SRC_DIRS),$$(foreach dir,$$($1_$2_HS_SRC_DIRS),-i$1/$$(dir)),-i$1) \
 -i$1/$2/build -i$1/$2/build/autogen \
 -I$1/$2/build -I$1/$2/build/autogen \
 $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
 $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
 $$(foreach inc,$$($1_$2_INCLUDE),-\#include "$$(inc)") \
 $$(foreach opt,$$($1_$2_CPP_OPTS),-optP$$(opt)) \
 $$(if $$($1_PACKAGE),-optP-include -optP$1/$2/build/autogen/cabal_macros.h) \
132
 $$($1_$2_$4_DEP_OPTS) \
133
 $$($1_$2_HC_OPTS) \
134
 $$(CONF_HC_OPTS_STAGE$4) \
135
 $$($1_$2_MORE_HC_OPTS) \
136
 $$($1_$2_EXTRA_HC_OPTS) \
Ian Lynagh's avatar
Ian Lynagh committed
137
 $$($1_$2_$3_HC_OPTS) \
Ian Lynagh's avatar
Ian Lynagh committed
138
 $$($$(basename $$(subst ./,,$$<))_HC_OPTS) \
Ian Lynagh's avatar
Ian Lynagh committed
139
 $$(SRC_HC_WARNING_OPTS) \
140
 $$(SRC_HC_WARNING_OPTS_STAGE$4) \
Ian Lynagh's avatar
Ian Lynagh committed
141 142
 $$(EXTRA_HC_OPTS)

143 144 145 146
$1_$2_$3_MOST_DIR_HC_OPTS = \
 $$($1_$2_$3_MOST_HC_OPTS) \
 -odir $1/$2/build -hidir $1/$2/build -stubdir $1/$2/build

Simon Marlow's avatar
Simon Marlow committed
147 148 149 150
# NB. CONF_HC_OPTS_STAGE$4 has to be late enough to override $1_$2_HC_OPTS, so
# that -O0 is effective (see #5484)

# $1_$2_$3_ALL_HC_OPTS: this is all the options we will pass to GHC
151
# for a given ($1,$2,$3).
Ian Lynagh's avatar
Ian Lynagh committed
152
$1_$2_$3_ALL_HC_OPTS = \
153 154 155
 -hisuf $$($3_hisuf) -osuf  $$($3_osuf) -hcsuf $$($3_hcsuf) \
 $$($1_$2_$3_MOST_DIR_HC_OPTS) \
 $$(if $$(findstring YES,$$($1_$2_SplitObjs)),$$(if $$(findstring dyn,$3),,-split-objs),) \
156
 $$(if $$(findstring YES,$$($1_$2_SplitSections)),$$(if $$(findstring dyn,$3),,-split-sections),) \
157
 $$(if $$(findstring YES,$$($1_$2_DYNAMIC_TOO)),$$(if $$(findstring v,$3),-dynamic-too))
Ian Lynagh's avatar
Ian Lynagh committed
158

159 160 161 162 163 164 165 166
ifeq "$3" "dyn"
ifeq "$$(HostOS_CPP)" "mingw32"
ifneq "$$($1_$2_dll0_MODULES)" ""
$1_$2_$3_ALL_HC_OPTS += -dll-split $1/$2/dll-split
endif
endif
endif

Ian Lynagh's avatar
Ian Lynagh committed
167 168
$1_$2_$3_ALL_CC_OPTS = \
 $$(WAY_$3_CC_OPTS) \
169
 $$($1_$2_DIST_GCC_CC_OPTS) \
Ian Lynagh's avatar
Ian Lynagh committed
170
 $$($1_$2_$3_CC_OPTS) \
171
 $$($$(basename $$<)_CC_OPTS) \
172
 $$($1_$2_EXTRA_CC_OPTS) \
Ian Lynagh's avatar
Ian Lynagh committed
173 174 175
 $$(EXTRA_CC_OPTS)

$1_$2_$3_GHC_CC_OPTS = \
176 177 178 179 180 181 182 183 184 185 186 187 188 189
 $$(addprefix -optc, $$($1_$2_$3_ALL_CC_OPTS)) \
 $$($1_$2_$3_MOST_HC_OPTS)

# Options for passing to plain ld
$1_$2_$3_ALL_LD_OPTS = \
 $$(WAY_$3_LD_OPTS) \
 $$($1_$2_DIST_LD_OPTS) \
 $$($1_$2_$3_LD_OPTS) \
 $$($1_$2_EXTRA_LD_OPTS) \
 $$(EXTRA_LD_OPTS)

# Options for passing to GHC when we use it for linking
$1_$2_$3_GHC_LD_OPTS = \
 $$(addprefix -optl, $$($1_$2_$3_ALL_LD_OPTS)) \
Ian Lynagh's avatar
Ian Lynagh committed
190 191 192
 $$($1_$2_$3_MOST_HC_OPTS)

$1_$2_$3_ALL_AS_OPTS = \
193
 $$(CONF_AS_OPTS) \
194
 $$(SRC_AS_OPTS) \
Ian Lynagh's avatar
Ian Lynagh committed
195 196 197 198 199 200
 $$(WAY_$3_AS_OPTS) \
 $$($1_AS_OPTS) \
 $$($1_$2_AS_OPTS) \
 $$($1_$2_$3_AS_OPTS) \
 $$(EXTRA_AS_OPTS)

201 202 203 204 205
ifeq "$3" "dyn"
ifneq "$4" "0"
ifeq "$$(TargetElf)" "YES"
$1_$2_$3_GHC_LD_OPTS += \
    -fno-use-rpaths \
206
    $$(foreach d,$$($1_$2_TRANSITIVE_DEP_COMPONENT_IDS),-optl-Wl$$(comma)-rpath -optl-Wl$$(comma)'$$$$ORIGIN/../$$d') -optl-Wl,-zorigin
207 208 209
else ifeq "$$(TargetOS_CPP)" "darwin"
$1_$2_$3_GHC_LD_OPTS += \
    -fno-use-rpaths \
210
    $$(foreach d,$$($1_$2_TRANSITIVE_DEP_COMPONENT_IDS),-optl-Wl$$(comma)-rpath -optl-Wl$$(comma)'@loader_path/../$$d')
211 212 213 214
endif
endif
endif

Ian Lynagh's avatar
Ian Lynagh committed
215 216
endef