More modules that need LANGUAGE BangPatterns
[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  $$($$(basename $$<)_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 # We have to do this mangling using the shell, because words may contain
79 # spaces and GNU make doesn't have any quoting interpretation.
80 ifneq ($$(strip $$($1_$2_DEP_INCLUDE_DIRS)),)
81 $1_$2_CC_INC_FLAGS:=$$(shell for i in $$($1_$2_DEP_INCLUDE_DIRS); do echo $$($1_$2_DEP_INCLUDE_DIRS_FLAG)\"$$$$i\"; done)
82 endif
83
84 # The CONF_CC_OPTS_STAGE$4 options are what we use to get gcc to
85 # behave correctly, but they are specific to the gcc that we are using.
86 # If GHC is compiling C code then it will take care of that for us,
87 # and in the case of the stage 0 compiler it may be using a different
88 # gcc, so we don't want to use our gcc-specific options.
89 $1_$2_DIST_GCC_CC_OPTS = \
90  $$(CONF_CC_OPTS_STAGE$4) \
91  $$($1_$2_DIST_CC_OPTS)
92
93 $1_$2_DIST_CC_OPTS = \
94  $$(SRC_CC_OPTS) \
95  $$($1_CC_OPTS) \
96  $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
97  $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
98  $$($1_$2_CC_OPTS) \
99  $$($1_$2_CPP_OPTS) \
100  $$($1_$2_CC_INC_FLAGS) \
101  $$($1_$2_DEP_CC_OPTS)
102
103 ifneq ($$(strip $$($1_$2_DEP_LIB_DIRS)),)
104 $1_$2_DIST_LD_LIB_DIRS:=$$(shell for i in $$($1_$2_DEP_LIB_DIRS); do echo \"-L$$$$i\"; done)
105 endif
106
107 $1_$2_DIST_LD_OPTS = \
108  $$(CONF_LD_OPTS_STAGE$4) \
109  $$(SRC_LD_OPTS) \
110  $$($1_LD_OPTS) \
111  $$($1_$2_LD_OPTS) \
112  $$($1_$2_DIST_LD_LIB_DIRS) \
113  $$(foreach opt,$$($1_$2_DEP_EXTRA_LIBS),-l$$(opt)) \
114  $$($1_$2_DEP_LD_OPTS)
115
116 # c.f. Cabal's Distribution.Simple.PreProcess.ppHsc2hs
117 # We use '' around cflags and lflags to handle paths with backslashes in
118 # on Windows
119 ifneq ($$(strip $$($1_$2_DIST_GCC_CC_OPTS)),)
120 $1_$2_$3_HSC2HS_CC_OPTS:=$$(shell for i in $$($1_$2_DIST_GCC_CC_OPTS); do echo \'--cflag=$$$$i\'; done)
121 endif
122 ifneq ($$(strip $$($1_$2_DIST_LD_OPTS)),)
123 $1_$2_$3_HSC2HS_LD_OPTS:=$$(shell for i in $$($1_$2_DIST_LD_OPTS); do echo \'--lflag=$$$$i\'; done)
124 endif
125
126 $1_$2_$3_ALL_HSC2HS_OPTS = \
127  --cc=$$(WhatGccIsCalled) \
128  --ld=$$(WhatGccIsCalled) \
129  $$(CONF_HSC2HS_OPTS) \
130  $$(SRC_HSC2HS_OPTS) \
131  $$(WAY_$3_HSC2HS_OPTS) \
132  --cflag=-D__GLASGOW_HASKELL__=$$(ProjectVersionInt) \
133  $$($1_$2_$3_HSC2HS_CC_OPTS) \
134  $$($1_$2_$3_HSC2HS_LD_OPTS) \
135  $$($$(basename $$<)_HSC2HS_OPTS) \
136  $$(EXTRA_HSC2HS_OPTS)
137
138 $1_$2_$3_ALL_CC_OPTS = \
139  $$(WAY_$3_CC_OPTS) \
140  $$($1_$2_DIST_GCC_CC_OPTS) \
141  $$($1_$2_$3_CC_OPTS) \
142  $$($$(basename $$<)_CC_OPTS) \
143  $$(EXTRA_CC_OPTS)
144
145 $1_$2_$3_GHC_CC_OPTS = \
146  $$(addprefix -optc, \
147      $$(WAY_$3_CC_OPTS) \
148      $$($1_$2_DIST_CC_OPTS) \
149      $$($1_$2_$3_CC_OPTS) \
150      $$($$(basename $$<)_CC_OPTS) \
151      $$(EXTRA_CC_OPTS)) \
152  $$($1_$2_$3_MOST_HC_OPTS)
153
154 $1_$2_$3_ALL_AS_OPTS = \
155  $$(CONF_AS_OPTS) \
156  $$(SRC_AS_OPTS)
157  $$(WAY_$3_AS_OPTS) \
158  $$($1_AS_OPTS) \
159  $$($1_$2_AS_OPTS) \
160  $$($1_$2_$3_AS_OPTS) \
161  $$(EXTRA_AS_OPTS)
162
163 $1_$2_$3_ALL_ALEX_OPTS = \
164  $$(CONF_ALEX_OPTS) \
165  $$(SRC_ALEX_OPTS)
166  $$(WAY_$3_ALEX_OPTS) \
167  $$($1_ALEX_OPTS) \
168  $$($1_$2_ALEX_OPTS) \
169  $$($1_$2_$3_ALEX_OPTS) \
170  $$(EXTRA_ALEX_OPTS)
171
172 $1_$2_$3_ALL_HAPPY_OPTS = \
173  $$(CONF_HAPPY_OPTS) \
174  $$(SRC_HAPPY_OPTS) \
175  $$(WAY_$3_HAPPY_OPTS) \
176  $$($1_HAPPY_OPTS) \
177  $$($1_$2_HAPPY_OPTS) \
178  $$($1_$2_$3_HAPPY_OPTS) \
179  $$(EXTRA_HAPPY_OPTS)
180
181 endef
182