6df7c0cd27be9cb6311176df00ad1ab211afe63d
[ghc-hetmet.git] / ghc / ghc.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://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
9 #      http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
10 #
11 # -----------------------------------------------------------------------------
12
13 # ToDo
14 ghc_USES_CABAL = NO
15 # ghc_PACKAGE = ghc-bin
16
17 ghc_stage1_HC_OPTS = $(GhcStage1HcOpts)
18 ghc_stage2_HC_OPTS = $(GhcStage2HcOpts)
19 ghc_stage3_HC_OPTS = $(GhcStage3HcOpts)
20
21 ifeq "$(GhcWithInterpreter)" "YES"
22 ghc_stage2_HC_OPTS += -DGHCI
23 ghc_stage3_HC_OPTS += -DGHCI
24 endif
25
26 ifeq "$(GhcDebugged)" "YES"
27 ghc_HC_OPTS += -debug
28 endif
29
30 ifeq "$(GhcThreaded)" "YES"
31 # Use threaded RTS with GHCi, so threads don't get blocked at the prompt.
32 ghc_stage2_HC_OPTS += -threaded
33 ghc_stage3_HC_OPTS += -threaded
34 endif
35
36 # XXX ToDp
37 # ifeq "$(GhcProfiled)" "YES"
38
39 ghc_stage1_MODULES = Main
40
41 ghc_stage2_MODULES = $(ghc_stage1_MODULES) GhciMonad GhciTags InteractiveUI
42 ghc_stage3_MODULES = $(ghc_stage2_MODULES)
43
44 ghc_stage1_PROG = ghc-stage1$(exeext)
45 ghc_stage2_PROG = ghc-stage2$(exeext)
46 ghc_stage3_PROG = ghc-stage3$(exeext)
47
48 # ToDo: perhaps use ghc-cabal to configure ghc-bin
49 ghc_stage1_USE_BOOT_LIBS = YES
50 ghc_stage1_HC_OPTS += -package $(compiler_PACKAGE)-$(compiler_stage1_VERSION)
51 ghc_stage2_HC_OPTS += -package $(compiler_PACKAGE)-$(compiler_stage2_VERSION)
52 ghc_stage3_HC_OPTS += -package $(compiler_PACKAGE)-$(compiler_stage3_VERSION)
53 ghc_stage2_HC_OPTS += -package haskeline
54 ghc_stage3_HC_OPTS += -package haskeline
55
56 ghc_language_extension_flags = -XCPP \
57                                -XPatternGuards \
58                                -XForeignFunctionInterface \
59                                -XUnboxedTuples \
60                                -XFlexibleInstances \
61                                -XMagicHash
62 ghc_stage1_HC_OPTS += $(ghc_language_extension_flags)
63 ghc_stage2_HC_OPTS += $(ghc_language_extension_flags)
64 ghc_stage3_HC_OPTS += $(ghc_language_extension_flags)
65
66 # In stage1 we might not benefit from cross-package dependencies and
67 # recompilation checking.  We must force recompilation here, otherwise
68 # Main.o won't necessarily be rebuilt when the ghc package has changed:
69 ghc_stage1_HC_OPTS += -fforce-recomp
70
71 # Further dependencies we need only in stage 1, due to no
72 # cross-package dependencies or recompilation checking.
73 ghc/stage1/build/Main.o : $(compiler_stage1_v_LIB)
74
75 ghc_stage1_SHELL_WRAPPER = YES
76 ghc_stage2_SHELL_WRAPPER = YES
77 ghc_stage3_SHELL_WRAPPER = YES
78 ghc_stage1_SHELL_WRAPPER_NAME = ghc/ghc.wrapper
79 ghc_stage2_SHELL_WRAPPER_NAME = ghc/ghc.wrapper
80 ghc_stage3_SHELL_WRAPPER_NAME = ghc/ghc.wrapper
81
82 ghc_stage$(INSTALL_GHC_STAGE)_INSTALL_SHELL_WRAPPER = YES
83 ghc_stage$(INSTALL_GHC_STAGE)_INSTALL_SHELL_WRAPPER_NAME = ghc-$(ProjectVersion)
84
85 # stage 1 is enabled unless $(stage) is set to something other than 1
86 ifeq "$(filter-out 1,$(stage))" ""
87 $(eval $(call build-prog,ghc,stage1,0))
88 endif
89
90 # stage 2 is enabled unless $(stage) is set to something other than 2
91 ifeq "$(filter-out 2,$(stage))" ""
92 $(eval $(call build-prog,ghc,stage2,1))
93 endif
94
95 # stage 3 has to be requested explicitly with stage=3
96 ifeq "$(stage)" "3"
97 $(eval $(call build-prog,ghc,stage3,2))
98 endif
99
100 ifneq "$(BINDIST)" "YES"
101
102 # ToDo: should we add these in the build-prog macro?
103 ghc/stage1/build/tmp/$(ghc_stage1_PROG) : $(compiler_stage1_v_LIB)
104 ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(compiler_stage2_v_LIB)
105 ghc/stage3/build/tmp/$(ghc_stage3_PROG) : $(compiler_stage3_v_LIB)
106
107 all_ghc_stage1 : $(GHC_STAGE1)
108 all_ghc_stage2 : $(GHC_STAGE2)
109 all_ghc_stage3 : $(GHC_STAGE3)
110
111 $(INPLACE_LIB)/extra-gcc-opts : extra-gcc-opts
112         $(CP) $< $@
113
114 # The GHC programs need to depend on all the helper programs they might call
115 $(GHC_STAGE1) : $(INPLACE_LIB)/extra-gcc-opts $(MANGLER) $(SPLIT)
116 $(GHC_STAGE2) : $(INPLACE_LIB)/extra-gcc-opts $(MANGLER) $(SPLIT)
117 $(GHC_STAGE3) : $(INPLACE_LIB)/extra-gcc-opts $(MANGLER) $(SPLIT)
118
119 ifeq "$(Windows)" "YES"
120 $(GHC_STAGE1) : $(TOUCHY) $(INPLACE)/stamp-mingw $(INPLACE_LIB)/perl.exe
121 $(GHC_STAGE2) : $(TOUCHY) $(INPLACE)/stamp-mingw $(INPLACE_LIB)/perl.exe
122 $(GHC_STAGE3) : $(TOUCHY) $(INPLACE)/stamp-mingw $(INPLACE_LIB)/perl.exe
123 endif
124
125 endif
126
127 INSTALL_LIBS += extra-gcc-opts
128
129 ifeq "$(Windows)" "NO"
130 install: install_ghc_link
131 .PNONY: install_ghc_link
132 install_ghc_link: 
133         $(RM) -f $(DESTDIR)$(bindir)/ghc
134         $(LN_S) ghc-$(ProjectVersion) $(DESTDIR)$(bindir)/ghc
135 else
136 # On Windows we install the main binary as $(bindir)/ghc.exe
137 # To get ghc-<version>.exe we have a little C program in driver/ghc
138 install: install_ghc_post
139 .PHONY: install_ghc_post
140 install_ghc_post: install_bins
141         $(RM) -f $(DESTDIR)$(bindir)/ghc.exe
142         $(MV) -f $(DESTDIR)$(bindir)/ghc-stage$(INSTALL_GHC_STAGE).exe $(DESTDIR)$(bindir)/ghc.exe
143 endif
144