Updates to handle new Cabal
[ghc.git] / rules / distdir-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://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://ghc.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-opts # args: $1 = dir, $2 = distdir, $3 = stage
17
18 ifeq "$3" ""
19 $$(error Stage not given for distdir-opts $1 $2)
20 endif
21
22 ifneq ($$(strip $$($1_$2_DEP_INCLUDE_DIRS_SINGLE_QUOTED)),)
23 $1_$2_CC_INC_FLAGS := $$(subst $$(space)',$$(space)-I',$$(space)$$($1_$2_DEP_INCLUDE_DIRS_SINGLE_QUOTED))
24 endif
25
26 # The CONF_CC_OPTS_STAGE$3 options are what we use to get gcc to
27 # behave correctly, but they are specific to the gcc that we are using.
28 # If GHC is compiling C code then it will take care of that for us,
29 # and in the case of the stage 0 compiler it may be using a different
30 # gcc, so we don't want to use our gcc-specific options.
31 $1_$2_DIST_GCC_CC_OPTS = \
32 $$(CONF_CC_OPTS_STAGE$3) \
33 $$($1_$2_DIST_CC_OPTS)
34
35 $1_$2_DIST_CC_OPTS = \
36 $$(SRC_CC_OPTS) \
37 $$($1_CC_OPTS) \
38 -I$1/$2/build/$$(or $$($1_EXECUTABLE),$$($1_$2_PROGNAME),.)/autogen \
39 $$(foreach dir,$$(filter-out /%,$$($1_$2_INCLUDE_DIRS)),-I$1/$$(dir)) \
40 $$(foreach dir,$$(filter /%,$$($1_$2_INCLUDE_DIRS)),-I$$(dir)) \
41 $$($1_$2_CC_OPTS) \
42 $$($1_$2_CPP_OPTS) \
43 $$($1_$2_CC_INC_FLAGS) \
44 $$($1_$2_DEP_CC_OPTS) \
45 $$(SRC_CC_WARNING_OPTS)
46
47 ifneq ($$(strip $$($1_$2_DEP_LIB_DIRS_SINGLE_QUOTED)),)
48 $1_$2_DIST_LD_LIB_DIRS := $$(subst $$(space)',$$(space)-L',$$(space)$$($1_$2_DEP_LIB_DIRS_SINGLE_QUOTED))
49 endif
50
51 $1_$2_DIST_LD_OPTS = \
52 $$(SRC_LD_OPTS) \
53 $$($1_LD_OPTS) \
54 $$($1_$2_LD_OPTS) \
55 $$($1_$2_DIST_LD_LIB_DIRS) \
56 $$(foreach opt,$$($1_$2_DEP_EXTRA_LIBS),-l$$(opt)) \
57 $$($1_$2_DEP_LD_OPTS)
58
59 # c.f. Cabal's Distribution.Simple.PreProcess.ppHsc2hs
60 # We use '' around cflags and lflags to handle paths with backslashes in
61 # on Windows
62 ifneq ($$(strip $$($1_$2_DIST_GCC_CC_OPTS)),)
63 $1_$2_HSC2HS_CC_OPTS:=$$(shell for i in $$($1_$2_DIST_GCC_CC_OPTS); do echo \'--cflag=$$$$i\'; done)
64 endif
65 ifneq ($$(strip $$($1_$2_DIST_LD_OPTS)),)
66 $1_$2_HSC2HS_LD_OPTS:=$$(shell for i in $$($1_$2_DIST_LD_OPTS); do echo \'--lflag=$$$$i\'; done)
67 endif
68
69 $1_$2_ALL_HSC2HS_OPTS = \
70 '--cc=$$(CC_STAGE$3)' \
71 '--ld=$$(CC_STAGE$3)' \
72 $$(CONF_HSC2HS_OPTS) \
73 $$(SRC_HSC2HS_OPTS) \
74 $$(SRC_HSC2HS_OPTS_STAGE$3) \
75 --cflag=-D__GLASGOW_HASKELL__=$$(if $$(filter 0,$3),$$(GhcCanonVersion),$$(ProjectVersionInt)) \
76 $$($1_$2_HSC2HS_CC_OPTS) \
77 $$($1_$2_HSC2HS_LD_OPTS) \
78 --cflag=-I$1/$2/build/$$(or $$($1_EXECUTABLE),$$($1_$2_PROGNAME),.)/autogen \
79 $$(if $$($1_PACKAGE),--cflag=-include --cflag=$1/$2/build/$$(or $$($1_EXECUTABLE),$$($1_$2_PROGNAME),.)/autogen/cabal_macros.h) \
80 $$($$(basename $$<)_HSC2HS_OPTS) \
81 $$(EXTRA_HSC2HS_OPTS)
82
83 $1_$2_ALL_ALEX_OPTS = \
84 $$(CONF_ALEX_OPTS) \
85 $$(SRC_ALEX_OPTS) \
86 $$($1_ALEX_OPTS) \
87 $$($1_$2_ALEX_OPTS) \
88 $$(EXTRA_ALEX_OPTS)
89
90 $1_$2_ALL_HAPPY_OPTS = \
91 $$(CONF_HAPPY_OPTS) \
92 $$(SRC_HAPPY_OPTS) \
93 $$($1_HAPPY_OPTS) \
94 $$($1_$2_HAPPY_OPTS) \
95 $$(EXTRA_HAPPY_OPTS)
96
97 endef
98