1 # -----------------------------------------------------------------------------
3 # (c) 2009 The University of Glasgow
5 # This file is part of the GHC build system.
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
11 # -----------------------------------------------------------------------------
14 # Set compilation flags that additionally depend on a particular way
16 define distdir-way-opts # args: $1 = dir, $2 = distdir, $3 = way, $4 = stage
18 # Options for a Haskell compilation:
19 # - CONF_HC_OPTS source-tree-wide options, selected at
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
31 $1_$2_$3_MOST_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),) \
51 $$($1_$2_EXTRA_HC_OPTS) \
52 $$($1_$2_$3_HC_OPTS) \
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)
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
73 $1_$2_DEP_INCLUDE_DIRS_FLAG = -isystem
75 $1_$2_DEP_INCLUDE_DIRS_FLAG = -I
78 $1_$2_DIST_CC_OPTS = \
82 $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
83 $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
86 $$(foreach dir,$$($1_$2_DEP_INCLUDE_DIRS),$$($1_$2_DEP_INCLUDE_DIRS_FLAG)$$(dir)) \
89 $1_$2_DIST_LD_OPTS = \
94 $$(foreach opt,$$($1_$2_DEP_LIB_DIRS),-L$$(opt)) \
95 $$(foreach opt,$$($1_$2_DEP_EXTRA_LIBS),-l$$(opt)) \
98 # c.f. Cabal's Distribution.Simple.PreProcess.ppHsc2hs
99 # We use '' around cflags and lflags to handle paths with backslashes in
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)
113 $1_$2_$3_ALL_CC_OPTS = \
115 $$($1_$2_DIST_CC_OPTS) \
116 $$($1_$2_$3_CC_OPTS) \
120 $1_$2_$3_GHC_CC_OPTS = \
121 $$(addprefix -optc, $$($1_$2_$3_ALL_CC_OPTS)) \
122 $$($1_$2_$3_MOST_HC_OPTS)
124 $1_$2_$3_ALL_AS_OPTS = \
130 $$($1_$2_$3_AS_OPTS) \
133 $1_$2_$3_ALL_ALEX_OPTS = \
136 $$(WAY_$3_ALEX_OPTS) \
138 $$($1_$2_ALEX_OPTS) \
139 $$($1_$2_$3_ALEX_OPTS) \
142 $1_$2_$3_ALL_HAPPY_OPTS = \
143 $$(CONF_HAPPY_OPTS) \
145 $$(WAY_$3_HAPPY_OPTS) \
147 $$($1_$2_HAPPY_OPTS) \
148 $$($1_$2_$3_HAPPY_OPTS) \