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 Cabal for libraries/base
25 # - libraries/base_MORE_HC_OPTS options from elsewhere in the build
26 # system for libraries/base for all ways
27 # - libraries/base_v_HC_OPTS options from libraries/base for way v
28 # - WAY_v_HC_OPTS options for this way
29 # - EXTRA_HC_OPTS options from the command-line
30 # - -Idir1 -Idir2 ... include-dirs from this package
31 # - -odir/-hidir/-stubdir put the output files under $3/build
32 # - -osuf/-hisuf/-hcsuf suffixes for the output files in this way
34 $1_$2_$3_MOST_HC_OPTS = \
39 $$($1_$2_HC_PKGCONF) \
40 $$(if $$($1_$2_PROG),, \
41 $$(if $$($1_PACKAGE),-package-name $$($1_PACKAGE)-$$($1_$2_VERSION))) \
42 $$(if $$($1_PACKAGE),-hide-all-packages) \
43 -i $$(if $$($1_$2_HS_SRC_DIRS),$$(foreach dir,$$($1_$2_HS_SRC_DIRS),-i$1/$$(dir)),-i$1) \
44 -i$1/$2/build -i$1/$2/build/autogen \
45 -I$1/$2/build -I$1/$2/build/autogen \
46 $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
47 $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
48 $$(foreach inc,$$($1_$2_INCLUDE),-\#include "$$(inc)") \
49 $$(foreach opt,$$($1_$2_CPP_OPTS),-optP$$(opt)) \
50 $$(if $$($1_PACKAGE),-optP-include -optP$1/$2/build/autogen/cabal_macros.h) \
51 $$(foreach pkg,$$($1_$2_DEPS),-package $$(pkg)) \
52 $$(if $$(findstring YES,$$($1_$2_SplitObjs)),$$(if $$(findstring dyn,$3),,-split-objs),) \
54 $$($1_$2_MORE_HC_OPTS) \
55 $$($1_$2_EXTRA_HC_OPTS) \
56 $$($1_$2_$3_HC_OPTS) \
57 $$($$(basename $$<)_HC_OPTS) \
60 # For real Haskell compilations we add -hidir etc.
61 $1_$2_$3_ALL_HC_OPTS = \
62 $$($1_$2_$3_MOST_HC_OPTS) \
63 -odir $1/$2/build -hidir $1/$2/build -stubdir $1/$2/build \
64 -hisuf $$($3_hisuf) -osuf $$($3_osuf) -hcsuf $$($3_hcsuf)
67 # This is a bit of a hack.
68 # If we are compiling something with the bootstrapping compiler on
69 # cygwin, and it uses an include file from the rts (say), then we
70 # need to stop mkdependC from generating a dependincy on
71 # c:/ghc/rts/include/Rts.h
72 # as that confuses make. So we use -isystem instead of -I, which stops
73 # these dependencies from being generated. Technically this is wrong if
74 # we depend on a library that is built inside the build tree, and we
75 # use headers from that library, but currently I don't think that's the
77 $1_$2_DEP_INCLUDE_DIRS_FLAG = -isystem
79 $1_$2_DEP_INCLUDE_DIRS_FLAG = -I
82 ifneq ($$(strip $$($1_$2_DEP_INCLUDE_DIRS_SINGLE_QUOTED)),)
83 $1_$2_CC_INC_FLAGS := $$(subst $$(space)',$$(space)$$($1_$2_DEP_INCLUDE_DIRS_FLAG)',$$(space)$$($1_$2_DEP_INCLUDE_DIRS_SINGLE_QUOTED))
86 # The CONF_CC_OPTS_STAGE$4 options are what we use to get gcc to
87 # behave correctly, but they are specific to the gcc that we are using.
88 # If GHC is compiling C code then it will take care of that for us,
89 # and in the case of the stage 0 compiler it may be using a different
90 # gcc, so we don't want to use our gcc-specific options.
91 $1_$2_DIST_GCC_CC_OPTS = \
92 $$(CONF_CC_OPTS_STAGE$4) \
93 $$($1_$2_DIST_CC_OPTS)
95 $1_$2_DIST_CC_OPTS = \
98 $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
99 $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
102 $$($1_$2_CC_INC_FLAGS) \
103 $$($1_$2_DEP_CC_OPTS)
105 ifneq ($$(strip $$($1_$2_DEP_LIB_DIRS_SINGLE_QUOTED)),)
106 $1_$2_DIST_LD_LIB_DIRS := $$(subst $$(space)',$$(space)-L',$$(space)$$($1_$2_DEP_LIB_DIRS_SINGLE_QUOTED))
109 $1_$2_DIST_LD_OPTS = \
110 $$(CONF_GCC_LINKER_OPTS_STAGE$4) \
114 $$($1_$2_DIST_LD_LIB_DIRS) \
115 $$(foreach opt,$$($1_$2_DEP_EXTRA_LIBS),-l$$(opt)) \
116 $$($1_$2_DEP_LD_OPTS)
118 # c.f. Cabal's Distribution.Simple.PreProcess.ppHsc2hs
119 # We use '' around cflags and lflags to handle paths with backslashes in
121 ifneq ($$(strip $$($1_$2_DIST_GCC_CC_OPTS)),)
122 $1_$2_$3_HSC2HS_CC_OPTS:=$$(shell for i in $$($1_$2_DIST_GCC_CC_OPTS); do echo \'--cflag=$$$$i\'; done)
124 ifneq ($$(strip $$($1_$2_DIST_LD_OPTS)),)
125 $1_$2_$3_HSC2HS_LD_OPTS:=$$(shell for i in $$($1_$2_DIST_LD_OPTS); do echo \'--lflag=$$$$i\'; done)
128 $1_$2_$3_ALL_HSC2HS_OPTS = \
129 --cc=$$(WhatGccIsCalled) \
130 --ld=$$(WhatGccIsCalled) \
131 $$(CONF_HSC2HS_OPTS) \
132 $$(SRC_HSC2HS_OPTS) \
133 $$(WAY_$3_HSC2HS_OPTS) \
134 --cflag=-D__GLASGOW_HASKELL__=$$(ProjectVersionInt) \
135 $$($1_$2_$3_HSC2HS_CC_OPTS) \
136 $$($1_$2_$3_HSC2HS_LD_OPTS) \
137 $$($$(basename $$<)_HSC2HS_OPTS) \
138 $$(EXTRA_HSC2HS_OPTS)
140 $1_$2_$3_ALL_CC_OPTS = \
142 $$($1_$2_DIST_GCC_CC_OPTS) \
143 $$($1_$2_$3_CC_OPTS) \
144 $$($$(basename $$<)_CC_OPTS) \
147 $1_$2_$3_GHC_CC_OPTS = \
148 $$(addprefix -optc, \
150 $$($1_$2_DIST_CC_OPTS) \
151 $$($1_$2_$3_CC_OPTS) \
152 $$($$(basename $$<)_CC_OPTS) \
154 $$($1_$2_$3_MOST_HC_OPTS)
156 $1_$2_$3_ALL_AS_OPTS = \
162 $$($1_$2_$3_AS_OPTS) \
165 $1_$2_$3_ALL_ALEX_OPTS = \
168 $$(WAY_$3_ALEX_OPTS) \
170 $$($1_$2_ALEX_OPTS) \
171 $$($1_$2_$3_ALEX_OPTS) \
174 $1_$2_$3_ALL_HAPPY_OPTS = \
175 $$(CONF_HAPPY_OPTS) \
177 $$(WAY_$3_HAPPY_OPTS) \
179 $$($1_$2_HAPPY_OPTS) \
180 $$($1_$2_$3_HAPPY_OPTS) \