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 # We have to do this mangling using the shell, because words may contain
83 # spaces and GNU make doesn't have any quoting interpretation.
84 ifneq ($$(strip $$($1_$2_DEP_INCLUDE_DIRS)),)
85 $1_$2_CC_INC_FLAGS:=$$(shell for i in $$($1_$2_DEP_INCLUDE_DIRS); do echo $$($1_$2_DEP_INCLUDE_DIRS_FLAG)\"$$$$i\"; done)
88 # The CONF_CC_OPTS_STAGE$4 options are what we use to get gcc to
89 # behave correctly, but they are specific to the gcc that we are using.
90 # If GHC is compiling C code then it will take care of that for us,
91 # and in the case of the stage 0 compiler it may be using a different
92 # gcc, so we don't want to use our gcc-specific options.
93 $1_$2_DIST_GCC_CC_OPTS = \
94 $$(CONF_CC_OPTS_STAGE$4) \
95 $$($1_$2_DIST_CC_OPTS)
97 $1_$2_DIST_CC_OPTS = \
100 $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
101 $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
104 $$($1_$2_CC_INC_FLAGS) \
105 $$($1_$2_DEP_CC_OPTS)
107 ifneq ($$(strip $$($1_$2_DEP_LIB_DIRS)),)
108 $1_$2_DIST_LD_LIB_DIRS:=$$(shell for i in $$($1_$2_DEP_LIB_DIRS); do echo \"-L$$$$i\"; done)
111 $1_$2_DIST_LD_OPTS = \
112 $$(CONF_GCC_LINKER_OPTS_STAGE$4) \
116 $$($1_$2_DIST_LD_LIB_DIRS) \
117 $$(foreach opt,$$($1_$2_DEP_EXTRA_LIBS),-l$$(opt)) \
118 $$($1_$2_DEP_LD_OPTS)
120 # c.f. Cabal's Distribution.Simple.PreProcess.ppHsc2hs
121 # We use '' around cflags and lflags to handle paths with backslashes in
123 ifneq ($$(strip $$($1_$2_DIST_GCC_CC_OPTS)),)
124 $1_$2_$3_HSC2HS_CC_OPTS:=$$(shell for i in $$($1_$2_DIST_GCC_CC_OPTS); do echo \'--cflag=$$$$i\'; done)
126 ifneq ($$(strip $$($1_$2_DIST_LD_OPTS)),)
127 $1_$2_$3_HSC2HS_LD_OPTS:=$$(shell for i in $$($1_$2_DIST_LD_OPTS); do echo \'--lflag=$$$$i\'; done)
130 $1_$2_$3_ALL_HSC2HS_OPTS = \
131 --cc=$$(WhatGccIsCalled) \
132 --ld=$$(WhatGccIsCalled) \
133 $$(CONF_HSC2HS_OPTS) \
134 $$(SRC_HSC2HS_OPTS) \
135 $$(WAY_$3_HSC2HS_OPTS) \
136 --cflag=-D__GLASGOW_HASKELL__=$$(ProjectVersionInt) \
137 $$($1_$2_$3_HSC2HS_CC_OPTS) \
138 $$($1_$2_$3_HSC2HS_LD_OPTS) \
139 $$($$(basename $$<)_HSC2HS_OPTS) \
140 $$(EXTRA_HSC2HS_OPTS)
142 $1_$2_$3_ALL_CC_OPTS = \
144 $$($1_$2_DIST_GCC_CC_OPTS) \
145 $$($1_$2_$3_CC_OPTS) \
146 $$($$(basename $$<)_CC_OPTS) \
149 $1_$2_$3_GHC_CC_OPTS = \
150 $$(addprefix -optc, \
152 $$($1_$2_DIST_CC_OPTS) \
153 $$($1_$2_$3_CC_OPTS) \
154 $$($$(basename $$<)_CC_OPTS) \
156 $$($1_$2_$3_MOST_HC_OPTS)
158 $1_$2_$3_ALL_AS_OPTS = \
164 $$($1_$2_$3_AS_OPTS) \
167 $1_$2_$3_ALL_ALEX_OPTS = \
170 $$(WAY_$3_ALEX_OPTS) \
172 $$($1_$2_ALEX_OPTS) \
173 $$($1_$2_$3_ALEX_OPTS) \
176 $1_$2_$3_ALL_HAPPY_OPTS = \
177 $$(CONF_HAPPY_OPTS) \
179 $$(WAY_$3_HAPPY_OPTS) \
181 $$($1_$2_HAPPY_OPTS) \
182 $$($1_$2_$3_HAPPY_OPTS) \