micro-opt: replace stmGetEnclosingTRec() with a field access
[ghc-hetmet.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 libraries/base for all ways
24 #   - libraries/base_v_HC_OPTS     options from libraries/base for way v
25 #   - WAY_v_HC_OPTS                options for this way
26 #   - EXTRA_HC_OPTS                options from the command-line
27 #   - -Idir1 -Idir2 ...            include-dirs from this package
28 #   - -odir/-hidir/-stubdir        put the output files under $3/build
29 #   - -osuf/-hisuf/-hcsuf          suffixes for the output files in this way
30
31 $1_$2_$3_MOST_HC_OPTS = \
32  $$(WAY_$3_HC_OPTS) \
33  $$(CONF_HC_OPTS) \
34  $$(SRC_HC_OPTS) \
35  $$($1_HC_OPTS) \
36  $$($1_$2_HC_PKGCONF) \
37  $$(if $$($1_$2_PROG),, \
38         $$(if $$($1_PACKAGE),-package-name $$($1_PACKAGE)-$$($1_$2_VERSION))) \
39  $$(if $$($1_PACKAGE),-hide-all-packages) \
40  -i $$(if $$($1_$2_HS_SRC_DIRS),$$(foreach dir,$$($1_$2_HS_SRC_DIRS),-i$1/$$(dir)),-i$1) \
41  -i$1/$2/build -i$1/$2/build/autogen \
42  -I$1/$2/build -I$1/$2/build/autogen \
43  $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
44  $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
45  $$(foreach inc,$$($1_$2_INCLUDE),-\#include "$$(inc)") \
46  $$(foreach opt,$$($1_$2_CPP_OPTS),-optP$$(opt)) \
47  $$(if $$($1_PACKAGE),-optP-include -optP$1/$2/build/autogen/cabal_macros.h) \
48  $$(foreach pkg,$$($1_$2_DEPS),-package $$(pkg)) \
49  $$(if $$(findstring YES,$$($1_$2_SplitObjs)),$$(if $$(findstring dyn,$3),,-split-objs),) \
50  $$($1_$2_HC_OPTS) \
51  $$($1_$2_EXTRA_HC_OPTS) \
52  $$($1_$2_$3_HC_OPTS) \
53  $$($$*_HC_OPTS) \
54  $$(EXTRA_HC_OPTS)
55
56 # For real Haskell compilations we add -hidir etc.
57 $1_$2_$3_ALL_HC_OPTS = \
58  $$($1_$2_$3_MOST_HC_OPTS) \
59  -odir $1/$2/build -hidir $1/$2/build -stubdir $1/$2/build \
60  -hisuf $$($3_hisuf) -osuf  $$($3_osuf) -hcsuf $$($3_hcsuf)
61
62 ifeq "$4" "0"
63 # This is a bit of a hack.
64 # If we are compiling something with the bootstrapping compiler on
65 # cygwin, and it uses an include file from the rts (say), then we
66 # need to stop mkdependC from generating a dependincy on
67 #     c:/ghc/rts/include/Rts.h
68 # as that confuses make. So we use -isystem instead of -I, which stops
69 # these dependencies from being generated. Technically this is wrong if
70 # we depend on a library that is built inside the build tree, and we
71 # use headers from that library, but currently I don't think that's the
72 # case.
73 $1_$2_DEP_INCLUDE_DIRS_FLAG = -isystem
74 else
75 $1_$2_DEP_INCLUDE_DIRS_FLAG = -I
76 endif
77
78 $1_$2_DIST_CC_OPTS = \
79  $$(CONF_CC_OPTS) \
80  $$(SRC_CC_OPTS) \
81  $$($1_CC_OPTS) \
82  $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
83  $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
84  $$($1_$2_CC_OPTS) \
85  $$($1_$2_CPP_OPTS) \
86  $$(foreach dir,$$($1_$2_DEP_INCLUDE_DIRS),$$($1_$2_DEP_INCLUDE_DIRS_FLAG)$$(dir)) \
87  $$($1_$2_DEP_CC_OPTS)
88
89 $1_$2_DIST_LD_OPTS = \
90  $$(CONF_LD_OPTS) \
91  $$(SRC_LD_OPTS) \
92  $$($1_LD_OPTS) \
93  $$($1_$2_LD_OPTS) \
94  $$(foreach opt,$$($1_$2_DEP_LIB_DIRS),-L$$(opt)) \
95  $$(foreach opt,$$($1_$2_DEP_EXTRA_LIBS),-l$$(opt)) \
96  $$($1_$2_DEP_LD_OPTS)
97
98 # c.f. Cabal's Distribution.Simple.PreProcess.ppHsc2hs
99 # We use '' around cflags and lflags to handle paths with backslashes in
100 # on Windows
101 $1_$2_$3_ALL_HSC2HS_OPTS = \
102  --cc=$$(WhatGccIsCalled) \
103  --ld=$$(WhatGccIsCalled) \
104  $$(CONF_HSC2HS_OPTS) \
105  $$(SRC_HSC2HS_OPTS) \
106  $$(WAY_$3_HSC2HS_OPTS) \
107  --cflag=-D__GLASGOW_HASKELL__=$$(ProjectVersionInt) \
108  $$(foreach opt,$$($1_$2_DIST_CC_OPTS),'--cflag=$$(opt)') \
109  $$(foreach opt,$$($1_$2_DIST_LD_OPTS),'--lflag=$$(opt)') \
110  $$($$*_HSC2HS_OPTS) \
111  $$(EXTRA_HSC2HS_OPTS)
112
113 $1_$2_$3_ALL_CC_OPTS = \
114  $$(WAY_$3_CC_OPTS) \
115  $$($1_$2_DIST_CC_OPTS) \
116  $$($1_$2_$3_CC_OPTS) \
117  $$($$*_CC_OPTS) \
118  $$(EXTRA_CC_OPTS)
119
120 $1_$2_$3_GHC_CC_OPTS = \
121  $$(addprefix -optc, $$($1_$2_$3_ALL_CC_OPTS)) \
122  $$($1_$2_$3_MOST_HC_OPTS)
123
124 $1_$2_$3_ALL_AS_OPTS = \
125  $$(CONF_AS_OPTS) \
126  $$(SRC_AS_OPTS)
127  $$(WAY_$3_AS_OPTS) \
128  $$($1_AS_OPTS) \
129  $$($1_$2_AS_OPTS) \
130  $$($1_$2_$3_AS_OPTS) \
131  $$(EXTRA_AS_OPTS)
132
133 $1_$2_$3_ALL_ALEX_OPTS = \
134  $$(CONF_ALEX_OPTS) \
135  $$(SRC_ALEX_OPTS)
136  $$(WAY_$3_ALEX_OPTS) \
137  $$($1_ALEX_OPTS) \
138  $$($1_$2_ALEX_OPTS) \
139  $$($1_$2_$3_ALEX_OPTS) \
140  $$(EXTRA_ALEX_OPTS)
141
142 $1_$2_$3_ALL_HAPPY_OPTS = \
143  $$(CONF_HAPPY_OPTS) \
144  $$(SRC_HAPPY_OPTS) \
145  $$(WAY_$3_HAPPY_OPTS) \
146  $$($1_HAPPY_OPTS) \
147  $$($1_$2_HAPPY_OPTS) \
148  $$($1_$2_$3_HAPPY_OPTS) \
149  $$(EXTRA_HAPPY_OPTS)
150
151 endef
152