Fix #3741, simplifying things in the process
[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 ghc_stage2_CC_OPTS = -Iincludes
22 ghc_stage3_CC_OPTS = -Iincludes
23
24 ghc_stage1_C_FILES_NODEPS = ghc/hschooks.c
25
26 ghc_stage2_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES
27 ghc_stage3_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES
28
29 ifeq "$(GhcWithInterpreter)" "YES"
30 ghc_stage2_HC_OPTS += -DGHCI
31 ghc_stage3_HC_OPTS += -DGHCI
32 endif
33
34 ifeq "$(GhcDebugged)" "YES"
35 ghc_HC_OPTS += -debug
36 endif
37
38 ifeq "$(GhcThreaded)" "YES"
39 # Use threaded RTS with GHCi, so threads don't get blocked at the prompt.
40 ghc_stage2_HC_OPTS += -threaded
41 ghc_stage3_HC_OPTS += -threaded
42 endif
43
44 ifeq "$(GhcProfiled)" "YES"
45 ghc_stage2_HC_OPTS += -prof
46 endif
47
48 ghc_stage1_MODULES = Main
49
50 ghc_stage2_MODULES = $(ghc_stage1_MODULES)
51 ifeq "$(GhcWithInterpreter)" "YES"
52 ghc_stage2_MODULES += GhciMonad GhciTags InteractiveUI
53 endif
54 ghc_stage3_MODULES = $(ghc_stage2_MODULES)
55
56 ghc_stage1_C_SRCS = hschooks.c
57 ghc_stage2_C_SRCS = hschooks.c
58 ghc_stage3_C_SRCS = hschooks.c
59
60 ghc_stage1_PROG = ghc-stage1$(exeext)
61 ghc_stage2_PROG = ghc-stage2$(exeext)
62 ghc_stage3_PROG = ghc-stage3$(exeext)
63
64 # ToDo: perhaps use ghc-cabal to configure ghc-bin
65 ghc_stage1_HC_OPTS += -package $(compiler_PACKAGE)-$(compiler_stage1_VERSION)
66 ghc_stage2_HC_OPTS += -package $(compiler_PACKAGE)-$(compiler_stage2_VERSION)
67 ghc_stage3_HC_OPTS += -package $(compiler_PACKAGE)-$(compiler_stage3_VERSION)
68 ghc_stage2_HC_OPTS += -package haskeline
69 ghc_stage3_HC_OPTS += -package haskeline
70
71 ghc_language_extension_flags = -XCPP \
72                                -XPatternGuards \
73                                -XForeignFunctionInterface \
74                                -XUnboxedTuples \
75                                -XFlexibleInstances \
76                                -XMagicHash
77 ghc_stage1_HC_OPTS += $(ghc_language_extension_flags)
78 ghc_stage2_HC_OPTS += $(ghc_language_extension_flags)
79 ghc_stage3_HC_OPTS += $(ghc_language_extension_flags)
80
81 # In stage1 we might not benefit from cross-package dependencies and
82 # recompilation checking.  We must force recompilation here, otherwise
83 # Main.o won't necessarily be rebuilt when the ghc package has changed:
84 ghc_stage1_HC_OPTS += -fforce-recomp
85
86 # Further dependencies we need only in stage 1, due to no
87 # cross-package dependencies or recompilation checking.
88 ghc/stage1/build/Main.o : $(compiler_stage1_v_LIB)
89
90 ghc_stage1_SHELL_WRAPPER = YES
91 ghc_stage2_SHELL_WRAPPER = YES
92 ghc_stage3_SHELL_WRAPPER = YES
93 ghc_stage1_SHELL_WRAPPER_NAME = ghc/ghc.wrapper
94 ghc_stage2_SHELL_WRAPPER_NAME = ghc/ghc.wrapper
95 ghc_stage3_SHELL_WRAPPER_NAME = ghc/ghc.wrapper
96
97 ghc_stage$(INSTALL_GHC_STAGE)_INSTALL_SHELL_WRAPPER = YES
98 ghc_stage$(INSTALL_GHC_STAGE)_INSTALL_SHELL_WRAPPER_NAME = ghc-$(ProjectVersion)
99
100 # We override the program name to be ghc, rather than ghc-stage2.
101 # This means the right program name is used in error messages etc.
102 define ghc_stage$(INSTALL_GHC_STAGE)_INSTALL_SHELL_WRAPPER_EXTRA
103 echo 'executablename="$$exedir/ghc"' >> "$(WRAPPER)"
104 endef
105
106 # stage 1 is enabled unless $(stage) is set to something other than 1
107 ifeq "$(filter-out 1,$(stage))" ""
108 $(eval $(call build-prog,ghc,stage1,0))
109 endif
110
111 # stage 2 is enabled unless $(stage) is set to something other than 2
112 ifeq "$(filter-out 2,$(stage))" ""
113 $(eval $(call build-prog,ghc,stage2,1))
114 endif
115
116 # stage 3 has to be requested explicitly with stage=3
117 ifeq "$(stage)" "3"
118 $(eval $(call build-prog,ghc,stage3,2))
119 endif
120
121 ifneq "$(BINDIST)" "YES"
122
123 # ToDo: should we add these in the build-prog macro?
124 ghc/stage1/build/tmp/$(ghc_stage1_PROG) : $(compiler_stage1_v_LIB)
125 ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(compiler_stage2_v_LIB)
126 ghc/stage3/build/tmp/$(ghc_stage3_PROG) : $(compiler_stage3_v_LIB)
127
128 # Modules here import HsVersions.h, so we need ghc_boot_platform.h
129 $(ghc_stage1_depfile_haskell) : compiler/stage1/$(PLATFORM_H)
130 $(ghc_stage2_depfile_haskell) : compiler/stage2/$(PLATFORM_H)
131 $(ghc_stage3_depfile_haskell) : compiler/stage3/$(PLATFORM_H)
132
133 all_ghc_stage1 : $(GHC_STAGE1)
134 all_ghc_stage2 : $(GHC_STAGE2)
135 all_ghc_stage3 : $(GHC_STAGE3)
136
137 $(INPLACE_LIB)/extra-gcc-opts : extra-gcc-opts
138         "$(CP)" $< $@
139
140 # The GHC programs need to depend on all the helper programs they might call
141 ifeq "$(GhcUnregisterised)" "NO"
142 $(GHC_STAGE1) : $(MANGLER) $(SPLIT)
143 $(GHC_STAGE2) : $(MANGLER) $(SPLIT)
144 $(GHC_STAGE3) : $(MANGLER) $(SPLIT)
145 endif
146
147 $(GHC_STAGE1) : $(INPLACE_LIB)/extra-gcc-opts
148 $(GHC_STAGE2) : $(INPLACE_LIB)/extra-gcc-opts
149 $(GHC_STAGE3) : $(INPLACE_LIB)/extra-gcc-opts
150
151 ifeq "$(Windows)" "YES"
152 $(GHC_STAGE1) : $(TOUCHY)
153 $(GHC_STAGE2) : $(TOUCHY)
154 $(GHC_STAGE3) : $(TOUCHY)
155 endif
156
157 ifeq "$(BootingFromHc)" "YES"
158 $(GHC_STAGE2) : $(ALL_STAGE1_LIBS)
159 ghc_stage2_OTHER_OBJS += $(compiler_stage2_v_LIB) $(ALL_STAGE1_LIBS) $(ALL_STAGE1_LIBS) $(ALL_STAGE1_LIBS) $(ALL_RTS_LIBS) $(libffi_STATIC_LIB)
160 endif
161
162 endif
163
164 INSTALL_LIBS += extra-gcc-opts
165
166 ifeq "$(Windows)" "NO"
167 install: install_ghc_link
168 .PNONY: install_ghc_link
169 install_ghc_link: 
170         "$(RM)" $(RM_OPTS) "$(DESTDIR)$(bindir)/ghc"
171         $(LN_S) ghc-$(ProjectVersion) "$(DESTDIR)$(bindir)/ghc"
172 else
173 # On Windows we install the main binary as $(bindir)/ghc.exe
174 # To get ghc-<version>.exe we have a little C program in driver/ghc
175 install: install_ghc_post
176 .PHONY: install_ghc_post
177 install_ghc_post: install_bins
178         "$(RM)" $(RM_OPTS) $(DESTDIR)$(bindir)/ghc.exe
179         "$(MV)" -f $(DESTDIR)$(bindir)/ghc-stage$(INSTALL_GHC_STAGE).exe $(DESTDIR)$(bindir)/ghc.exe
180 endif
181