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