Make "make clean" in ghc/ only clean the stage we want to clean
[ghc-hetmet.git] / ghc / Makefile
1
2 TOP=..
3 include $(TOP)/mk/boilerplate.mk
4 include $(TOP)/mk/cabal-flags.mk
5
6 ifeq "$(stage)" ""
7 stage=1
8 endif
9
10 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
11 INSTALL_FLAGS =
12 else
13 INSTALL_FLAGS = --enable-shell-wrappers
14 endif
15
16 # Don't strip the inplace versions, we might need to debug them
17 INPLACE_INSTALL_FLAGS += --disable-executable-stripping
18
19 boot:: boot.stage.$(stage)
20
21 all:: build.stage.$(stage)
22
23 rebuild ::
24         -$(CABAL) clean --distpref dist-stage$(stage)
25         $(RM) -rf stage$(stage)-inplace
26         $(MAKE) boot all
27
28 stage1 ::
29         $(MAKE) stage=1
30
31 stage2 ::
32         $(MAKE) stage=2
33
34 stage3 ::
35         $(MAKE) stage=3
36
37 ifeq "$(CLEAN_ALL_STAGES)" "YES"
38 clean distclean:: clean.stage.1 clean.stage.2 clean.stage.3
39 else
40 clean distclean:: clean.stage.$(stage)
41 endif
42
43 clean.stage.%:
44         -$(CABAL) clean --distpref dist-stage$*
45         $(RM) -rf stage$*-inplace
46
47 # XXX This should be defined somewhere more central
48 INPLACE_DATA_DIR = $(FPTOOLS_TOP_ABS)/inplace-datadir
49
50 CONFIGURE_FLAGS_STAGE1 += --flags=-ghci
51
52 ifeq "$(GhcWithInterpreter)" "YES"
53 CONFIGURE_FLAGS_STAGE2 += --flags=ghci
54 else
55 CONFIGURE_FLAGS_STAGE2 += --flags=-ghci
56 endif
57
58 ifeq "$(GhcProfiled)" "YES"
59 CONFIGURE_FLAGS_STAGE2 += --enable-executable-profiling
60 endif
61 ifeq "$(GhcDebugged)" "YES"
62 CONFIGURE_FLAGS_STAGE2 += --ghc-option=-debug
63 endif
64 ifeq "$(GhcThreaded)" "YES"
65 # Use threaded RTS with GHCi, so threads don't get blocked at the prompt.
66 CONFIGURE_FLAGS_STAGE2 += --ghc-option=-threaded
67 endif
68
69 ifeq "$(BuildSharedLibs)" "YES"
70 CONFIGURE_FLAGS_STAGE2 += --ghc-option=-dynamic
71 endif
72
73 CONFIGURE_FLAGS_STAGE3 = $(CONFIGURE_FLAGS_STAGE2)
74
75 CONFIGURE_FLAGS_STAGE1 += $(USE_BOOT_CONFIGURE_FLAGS)
76 CONFIGURE_FLAGS_STAGE2 += $(USE_STAGE1_CONFIGURE_FLAGS)
77 CONFIGURE_FLAGS_STAGE3 += $(USE_STAGE2_CONFIGURE_FLAGS)
78
79 # Allow EXTRA_HC_OPTS to be used from the command line to add options 
80 # when building (e.g. -v)
81 BUILD_FLAGS=$(patsubst %, --ghc-option=%, $(EXTRA_HC_OPTS))
82
83 # XXX In stage2+ we should really use the inplace ghc-pkg
84 # It works because installPackage doesn't actually use ghc-pkg, as there's
85 # no library to register
86
87 ifeq "$(stage)" "1"
88 # GHC 6.9+ can handle cross-package recompilation checking, but
89 # we don't rely on the bootstrapping compiler being able to do this.
90 TOUCH_MAIN = $(RM) dist-stage1/build/ghc/ghc-tmp/Main.o
91 endif
92
93 boot.stage.%:
94         $(CABAL) configure --distpref dist-stage$*         \
95                            $(INSTALL_DIRS_CONFIGURE_FLAGS) \
96                            $(CONFIGURE_FLAGS_STAGE$*)      \
97                            $(COMMON_CONFIGURE_FLAGS)       \
98                            --libsubdir=.                   \
99                            --datadir='$$libdir'            \
100                            --datasubdir=.
101
102 build.stage.%:
103         $(TOUCH_MAIN)
104         $(CABAL) build     --distpref dist-stage$* $(BUILD_FLAGS)
105         $(INSTALL_PACKAGE) install '$(GHC_PKG_PROG)' 'XXX/package.conf' "" \
106                            $(FPTOOLS_TOP_ABS)/ghc/stage$*-inplace          \
107                            $(FPTOOLS_TOP_ABS)/ghc/stage$*-inplace          \
108                            '$$prefix'                                      \
109                            '$(INPLACE_DATA_DIR)'                           \
110                            '$$prefix/libexec'                              \
111                            '$$prefix/dynlib'                               \
112                            '$(INPLACE_DATA_DIR)'                           \
113                            '$$prefix/doc'                                  \
114                            '$$prefix/html'                                 \
115                            '$$prefix/haddock'                              \
116                            --distpref dist-stage$*                         \
117                            $(INPLACE_INSTALL_FLAGS)                        \
118                            $(INSTALL_FLAGS)
119
120 # XXX For now we always install the stage 2 compiler
121 install:
122         $(INSTALL_PACKAGE) install UNUSED UNUSED '$(DESTDIR)' '$(prefix)' \
123                            '$(prefix)' '$(bindir)' '$(libdir)'            \
124                        '$(libexecdir)' '$(dynlibdir)' '$(datadir)'    \
125                        '$(docdir)' '$(htmldir)' '$(haddockdir)'       \
126                            --distpref dist-stage2                         \
127                            $(INSTALL_FLAGS)
128
129 include $(TOP)/mk/bindist.mk
130 EXE_DIST_DIR = dist-stage$(stage)
131