Ticket #3683: distdir-way-opts.mk

File distdir-way-opts.mk, 5.6 KB (added by maeder, 6 years ago)

fixed version

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