Merge remote branch 'origin/master' into monad-comp
[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 # Options for a Haskell compilation:
19 # - CONF_HC_OPTS source-tree-wide options, selected at
20 # configure-time
21 # - SRC_HC_OPTS source-tree-wide options from build.mk
22 # (optimisation, heap settings)
23 # - libraries/base_HC_OPTS options from Cabal for libraries/base
24 # for all ways
25 # - libraries/base_MORE_HC_OPTS options from elsewhere in the build
26 # system for libraries/base for all ways
27 # - libraries/base_v_HC_OPTS options from libraries/base for way v
28 # - WAY_v_HC_OPTS options for this way
29 # - EXTRA_HC_OPTS options from the command-line
30 # - -Idir1 -Idir2 ... include-dirs from this package
31 # - -odir/-hidir/-stubdir put the output files under $3/build
32 # - -osuf/-hisuf/-hcsuf suffixes for the output files in this way
33
34 $1_$2_$3_MOST_HC_OPTS = \
35 $$(WAY_$3_HC_OPTS) \
36 $$(CONF_HC_OPTS) \
37 $$(SRC_HC_OPTS) \
38 $$($1_HC_OPTS) \
39 $$($1_$2_HC_PKGCONF) \
40 $$(if $$($1_$2_PROG),, \
41 $$(if $$($1_PACKAGE),-package-name $$($1_PACKAGE)-$$($1_$2_VERSION))) \
42 $$(if $$($1_PACKAGE),-hide-all-packages) \
43 -i $$(if $$($1_$2_HS_SRC_DIRS),$$(foreach dir,$$($1_$2_HS_SRC_DIRS),-i$1/$$(dir)),-i$1) \
44 -i$1/$2/build -i$1/$2/build/autogen \
45 -I$1/$2/build -I$1/$2/build/autogen \
46 $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
47 $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
48 $$(foreach inc,$$($1_$2_INCLUDE),-\#include "$$(inc)") \
49 $$(foreach opt,$$($1_$2_CPP_OPTS),-optP$$(opt)) \
50 $$(if $$($1_PACKAGE),-optP-include -optP$1/$2/build/autogen/cabal_macros.h) \
51 $$(foreach pkg,$$($1_$2_DEPS),-package $$(pkg)) \
52 $$(if $$(findstring YES,$$($1_$2_SplitObjs)),$$(if $$(findstring dyn,$3),,-split-objs),) \
53 $$($1_$2_HC_OPTS) \
54 $$($1_$2_MORE_HC_OPTS) \
55 $$($1_$2_EXTRA_HC_OPTS) \
56 $$($1_$2_$3_HC_OPTS) \
57 $$($$(basename $$<)_HC_OPTS) \
58 $$(EXTRA_HC_OPTS)
59
60 # For real Haskell compilations we add -hidir etc.
61 $1_$2_$3_ALL_HC_OPTS = \
62 $$($1_$2_$3_MOST_HC_OPTS) \
63 -odir $1/$2/build -hidir $1/$2/build -stubdir $1/$2/build \
64 -hisuf $$($3_hisuf) -osuf $$($3_osuf) -hcsuf $$($3_hcsuf)
65
66 ifeq "$4" "0"
67 # This is a bit of a hack.
68 # If we are compiling something with the bootstrapping compiler on
69 # cygwin, and it uses an include file from the rts (say), then we
70 # need to stop mkdependC from generating a dependincy on
71 # c:/ghc/rts/include/Rts.h
72 # as that confuses make. So we use -isystem instead of -I, which stops
73 # these dependencies from being generated. Technically this is wrong if
74 # we depend on a library that is built inside the build tree, and we
75 # use headers from that library, but currently I don't think that's the
76 # case.
77 $1_$2_DEP_INCLUDE_DIRS_FLAG = -isystem
78 else
79 $1_$2_DEP_INCLUDE_DIRS_FLAG = -I
80 endif
81
82 ifneq ($$(strip $$($1_$2_DEP_INCLUDE_DIRS_SINGLE_QUOTED)),)
83 $1_$2_CC_INC_FLAGS := $$(subst $$(space)',$$(space)$$($1_$2_DEP_INCLUDE_DIRS_FLAG)',$$(space)$$($1_$2_DEP_INCLUDE_DIRS_SINGLE_QUOTED))
84 endif
85
86 # The CONF_CC_OPTS_STAGE$4 options are what we use to get gcc to
87 # behave correctly, but they are specific to the gcc that we are using.
88 # If GHC is compiling C code then it will take care of that for us,
89 # and in the case of the stage 0 compiler it may be using a different
90 # gcc, so we don't want to use our gcc-specific options.
91 $1_$2_DIST_GCC_CC_OPTS = \
92 $$(CONF_CC_OPTS_STAGE$4) \
93 $$($1_$2_DIST_CC_OPTS)
94
95 $1_$2_DIST_CC_OPTS = \
96 $$(SRC_CC_OPTS) \
97 $$($1_CC_OPTS) \
98 $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
99 $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
100 $$($1_$2_CC_OPTS) \
101 $$($1_$2_CPP_OPTS) \
102 $$($1_$2_CC_INC_FLAGS) \
103 $$($1_$2_DEP_CC_OPTS)
104
105 ifneq ($$(strip $$($1_$2_DEP_LIB_DIRS_SINGLE_QUOTED)),)
106 $1_$2_DIST_LD_LIB_DIRS := $$(subst $$(space)',$$(space)-L',$$(space)$$($1_$2_DEP_LIB_DIRS_SINGLE_QUOTED))
107 endif
108
109 $1_$2_DIST_LD_OPTS = \
110 $$(CONF_GCC_LINKER_OPTS_STAGE$4) \
111 $$(SRC_LD_OPTS) \
112 $$($1_LD_OPTS) \
113 $$($1_$2_LD_OPTS) \
114 $$($1_$2_DIST_LD_LIB_DIRS) \
115 $$(foreach opt,$$($1_$2_DEP_EXTRA_LIBS),-l$$(opt)) \
116 $$($1_$2_DEP_LD_OPTS)
117
118 # c.f. Cabal's Distribution.Simple.PreProcess.ppHsc2hs
119 # We use '' around cflags and lflags to handle paths with backslashes in
120 # on Windows
121 ifneq ($$(strip $$($1_$2_DIST_GCC_CC_OPTS)),)
122 $1_$2_$3_HSC2HS_CC_OPTS:=$$(shell for i in $$($1_$2_DIST_GCC_CC_OPTS); do echo \'--cflag=$$$$i\'; done)
123 endif
124 ifneq ($$(strip $$($1_$2_DIST_LD_OPTS)),)
125 $1_$2_$3_HSC2HS_LD_OPTS:=$$(shell for i in $$($1_$2_DIST_LD_OPTS); do echo \'--lflag=$$$$i\'; done)
126 endif
127
128 $1_$2_$3_ALL_HSC2HS_OPTS = \
129 --cc=$$(WhatGccIsCalled) \
130 --ld=$$(WhatGccIsCalled) \
131 $$(CONF_HSC2HS_OPTS) \
132 $$(SRC_HSC2HS_OPTS) \
133 $$(WAY_$3_HSC2HS_OPTS) \
134 --cflag=-D__GLASGOW_HASKELL__=$$(ProjectVersionInt) \
135 $$($1_$2_$3_HSC2HS_CC_OPTS) \
136 $$($1_$2_$3_HSC2HS_LD_OPTS) \
137 --cflag=-I$1/$2/build/autogen \
138 $$(if $$($1_PACKAGE),--cflag=-include --cflag=$1/$2/build/autogen/cabal_macros.h) \
139 $$($$(basename $$<)_HSC2HS_OPTS) \
140 $$(EXTRA_HSC2HS_OPTS)
141
142 $1_$2_$3_ALL_CC_OPTS = \
143 $$(WAY_$3_CC_OPTS) \
144 $$($1_$2_DIST_GCC_CC_OPTS) \
145 $$($1_$2_$3_CC_OPTS) \
146 $$($$(basename $$<)_CC_OPTS) \
147 $$(EXTRA_CC_OPTS)
148
149 $1_$2_$3_GHC_CC_OPTS = \
150 $$(addprefix -optc, \
151 $$(WAY_$3_CC_OPTS) \
152 $$($1_$2_DIST_CC_OPTS) \
153 $$($1_$2_$3_CC_OPTS) \
154 $$($$(basename $$<)_CC_OPTS) \
155 $$(EXTRA_CC_OPTS)) \
156 $$($1_$2_$3_MOST_HC_OPTS)
157
158 $1_$2_$3_ALL_AS_OPTS = \
159 $$(CONF_AS_OPTS) \
160 $$(SRC_AS_OPTS)
161 $$(WAY_$3_AS_OPTS) \
162 $$($1_AS_OPTS) \
163 $$($1_$2_AS_OPTS) \
164 $$($1_$2_$3_AS_OPTS) \
165 $$(EXTRA_AS_OPTS)
166
167 $1_$2_$3_ALL_ALEX_OPTS = \
168 $$(CONF_ALEX_OPTS) \
169 $$(SRC_ALEX_OPTS)
170 $$(WAY_$3_ALEX_OPTS) \
171 $$($1_ALEX_OPTS) \
172 $$($1_$2_ALEX_OPTS) \
173 $$($1_$2_$3_ALEX_OPTS) \
174 $$(EXTRA_ALEX_OPTS)
175
176 $1_$2_$3_ALL_HAPPY_OPTS = \
177 $$(CONF_HAPPY_OPTS) \
178 $$(SRC_HAPPY_OPTS) \
179 $$(WAY_$3_HAPPY_OPTS) \
180 $$($1_HAPPY_OPTS) \
181 $$($1_$2_HAPPY_OPTS) \
182 $$($1_$2_$3_HAPPY_OPTS) \
183 $$(EXTRA_HAPPY_OPTS)
184
185 endef
186