e346dffda32617a3f0848df710a4e8f1af91aa7e
[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 $1_$2_CC_INC_FLAGS:=$$(shell for i in $$($1_$2_DEP_INCLUDE_DIRS); do echo $$($1_$2_DEP_INCLUDE_DIRS_FLAG)\"$$$$i\"; done)
81
82 $1_$2_DIST_CC_OPTS = \
83  $$(CONF_CC_OPTS) \
84  $$(SRC_CC_OPTS) \
85  $$($1_CC_OPTS) \
86  $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
87  $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
88  $$($1_$2_CC_OPTS) \
89  $$($1_$2_CPP_OPTS) \
90  $$($1_$2_CC_INC_FLAGS) \
91  $$($1_$2_DEP_CC_OPTS)
92
93 $1_$2_DIST_LD_LIB_DIRS:=$$(shell for i in $$($1_$2_DEP_LIB_DIRS); do echo \"-L$$$$i\"; done)
94
95 $1_$2_DIST_LD_OPTS = \
96  $$(CONF_LD_OPTS) \
97  $$(SRC_LD_OPTS) \
98  $$($1_LD_OPTS) \
99  $$($1_$2_LD_OPTS) \
100  $$($1_$2_DIST_LD_LIB_DIRS) \
101  $$(foreach opt,$$($1_$2_DEP_EXTRA_LIBS),-l$$(opt)) \
102  $$($1_$2_DEP_LD_OPTS)
103
104 # c.f. Cabal's Distribution.Simple.PreProcess.ppHsc2hs
105 # We use '' around cflags and lflags to handle paths with backslashes in
106 # on Windows
107 $1_$2_$3_HSC2HS_CC_OPTS:=$$(shell for i in $$($1_$2_DIST_CC_OPTS); do echo \'--cflag=$$$$i\'; done)
108 $1_$2_$3_HSC2HS_LD_OPTS:=$$(shell for i in $$($1_$2_DIST_LD_OPTS); do echo \'--lflag=$$$$i\'; done)
109
110 $1_$2_$3_ALL_HSC2HS_OPTS = \
111  --cc=$$(WhatGccIsCalled) \
112  --ld=$$(WhatGccIsCalled) \
113  $$(CONF_HSC2HS_OPTS) \
114  $$(SRC_HSC2HS_OPTS) \
115  $$(WAY_$3_HSC2HS_OPTS) \
116  --cflag=-D__GLASGOW_HASKELL__=$$(ProjectVersionInt) \
117  $$($1_$2_$3_HSC2HS_CC_OPTS) \
118  $$($1_$2_$3_HSC2HS_LD_OPTS) \
119  $$($$(basename $$<)_HSC2HS_OPTS) \
120  $$(EXTRA_HSC2HS_OPTS)
121
122 $1_$2_$3_ALL_CC_OPTS = \
123  $$(WAY_$3_CC_OPTS) \
124  $$($1_$2_DIST_CC_OPTS) \
125  $$($1_$2_$3_CC_OPTS) \
126  $$($$(basename $$<)_CC_OPTS) \
127  $$(EXTRA_CC_OPTS)
128
129 $1_$2_$3_GHC_CC_OPTS = \
130  $$(addprefix -optc, $$($1_$2_$3_ALL_CC_OPTS)) \
131  $$($1_$2_$3_MOST_HC_OPTS)
132
133 $1_$2_$3_ALL_AS_OPTS = \
134  $$(CONF_AS_OPTS) \
135  $$(SRC_AS_OPTS)
136  $$(WAY_$3_AS_OPTS) \
137  $$($1_AS_OPTS) \
138  $$($1_$2_AS_OPTS) \
139  $$($1_$2_$3_AS_OPTS) \
140  $$(EXTRA_AS_OPTS)
141
142 $1_$2_$3_ALL_ALEX_OPTS = \
143  $$(CONF_ALEX_OPTS) \
144  $$(SRC_ALEX_OPTS)
145  $$(WAY_$3_ALEX_OPTS) \
146  $$($1_ALEX_OPTS) \
147  $$($1_$2_ALEX_OPTS) \
148  $$($1_$2_$3_ALEX_OPTS) \
149  $$(EXTRA_ALEX_OPTS)
150
151 $1_$2_$3_ALL_HAPPY_OPTS = \
152  $$(CONF_HAPPY_OPTS) \
153  $$(SRC_HAPPY_OPTS) \
154  $$(WAY_$3_HAPPY_OPTS) \
155  $$($1_HAPPY_OPTS) \
156  $$($1_$2_HAPPY_OPTS) \
157  $$($1_$2_$3_HAPPY_OPTS) \
158  $$(EXTRA_HAPPY_OPTS)
159
160 endef
161