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