Merge branch 'master' of http://darcs.haskell.org/ghc
[ghc.git] / ghc / ghc.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009-2012 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 ghc_USES_CABAL = YES
14 ghc_PACKAGE = ghc-bin
15
16 ghc_stage1_CONFIGURE_OPTS += --flags=stage1
17 ghc_stage2_CONFIGURE_OPTS += --flags=stage2
18 ghc_stage3_CONFIGURE_OPTS += --flags=stage3
19
20 ifeq "$(GhcWithInterpreter)" "YES"
21 ghc_stage2_CONFIGURE_OPTS += --flags=ghci
22 ghc_stage3_CONFIGURE_OPTS += --flags=ghci
23 endif
24
25 ifeq "$(compiler_stage1_VERSION_MUNGED)" "YES"
26 # If we munge the stage1 version, and we're using a devel snapshot for
27 # stage0, then stage1 may actually have an earlier version than stage0
28 # (e.g. boot with ghc-7.5.20120316, building ghc-7.5). We therefore
29 # need to tell Cabal to use version 7.5 of the ghc package when building
30 # in ghc/stage1
31 ghc_stage1_CONFIGURE_OPTS += --constraint "ghc == $(compiler_stage1_MUNGED_VERSION)"
32 endif
33
34 ghc_stage1_MORE_HC_OPTS = $(GhcStage1HcOpts)
35 ghc_stage2_MORE_HC_OPTS = $(GhcStage2HcOpts)
36 ghc_stage3_MORE_HC_OPTS = $(GhcStage3HcOpts)
37
38 # We need __GLASGOW_HASKELL__ in hschooks.c, so we have to build C
39 # sources with GHC:
40 ghc_stage1_UseGhcForCC = YES
41 ghc_stage2_UseGhcForCC = YES
42 ghc_stage3_UseGhcForCC = YES
43
44 ghc_stage1_C_FILES_NODEPS = ghc/hschooks.c
45
46 ghc_stage2_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES
47 ghc_stage3_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES
48
49 ifeq "$(GhcDebugged)" "YES"
50 ghc_stage1_MORE_HC_OPTS += -debug
51 ghc_stage2_MORE_HC_OPTS += -debug
52 ghc_stage3_MORE_HC_OPTS += -debug
53 endif
54
55 ifeq "$(GhcDynamic)" "YES"
56 ghc_stage2_MORE_HC_OPTS += -dynamic
57 ghc_stage3_MORE_HC_OPTS += -dynamic
58 endif
59
60 ifeq "$(GhcThreaded)" "YES"
61 # Use threaded RTS with GHCi, so threads don't get blocked at the prompt.
62 ghc_stage2_MORE_HC_OPTS += -threaded
63 ghc_stage3_MORE_HC_OPTS += -threaded
64 endif
65
66 ifeq "$(GhcProfiled)" "YES"
67 ghc_stage2_PROGRAM_WAY = p
68 endif
69
70 ghc_stage1_PROG = ghc-stage1$(exeext)
71 ghc_stage2_PROG = ghc-stage2$(exeext)
72 ghc_stage3_PROG = ghc-stage3$(exeext)
73
74 ghc_stage1_SHELL_WRAPPER = YES
75 ghc_stage2_SHELL_WRAPPER = YES
76 ghc_stage3_SHELL_WRAPPER = YES
77 ghc_stage1_SHELL_WRAPPER_NAME = ghc/ghc.wrapper
78 ghc_stage2_SHELL_WRAPPER_NAME = ghc/ghc.wrapper
79 ghc_stage3_SHELL_WRAPPER_NAME = ghc/ghc.wrapper
80 ghc_stage1_INSTALL_INPLACE = YES
81 ghc_stage2_INSTALL_INPLACE = YES
82 ghc_stage3_INSTALL_INPLACE = YES
83
84 ghc_stage$(INSTALL_GHC_STAGE)_INSTALL = YES
85 ghc_stage$(INSTALL_GHC_STAGE)_INSTALL_SHELL_WRAPPER_NAME = ghc-$(ProjectVersion)
86
87 # We override the program name to be ghc, rather than ghc-stage2.
88 # This means the right program name is used in error messages etc.
89 define ghc_stage$(INSTALL_GHC_STAGE)_INSTALL_SHELL_WRAPPER_EXTRA
90 echo 'executablename="$$exedir/ghc"' >> "$(WRAPPER)"
91 endef
92
93 # if stage is set to something other than "1" or "", disable stage 1
94 ifneq "$(filter-out 1,$(stage))" ""
95 ghc_stage1_NOT_NEEDED = YES
96 endif
97 # if stage is set to something other than "2" or "", disable stage 2
98 ifneq "$(filter-out 2,$(stage))" ""
99 ghc_stage2_NOT_NEEDED = YES
100 endif
101 # When cross-compiling, the stage 1 compiler is our release compiler, so omit stage 2
102 ifeq "$(Stage1Only)" "YES"
103 ghc_stage2_NOT_NEEDED = YES
104 endif
105 # stage 3 has to be requested explicitly with stage=3
106 ifneq "$(stage)" "3"
107 ghc_stage3_NOT_NEEDED = YES
108 endif
109 $(eval $(call build-prog,ghc,stage1,0))
110 $(eval $(call build-prog,ghc,stage2,1))
111 $(eval $(call build-prog,ghc,stage3,2))
112
113 ifneq "$(BINDIST)" "YES"
114
115 ghc/stage1/build/tmp/$(ghc_stage1_PROG) : $(BOOT_LIBS)
116 ifeq "$(GhcProfiled)" "YES"
117 ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(compiler_stage2_p_LIB)
118 ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_p_LIB))
119 endif
120
121 # Modules here import HsVersions.h, so we need ghc_boot_platform.h
122 $(ghc_stage1_depfile_haskell) : compiler/stage1/$(PLATFORM_H)
123 $(ghc_stage2_depfile_haskell) : compiler/stage2/$(PLATFORM_H)
124 $(ghc_stage3_depfile_haskell) : compiler/stage3/$(PLATFORM_H)
125
126 all_ghc_stage1 : $(GHC_STAGE1)
127 all_ghc_stage2 : $(GHC_STAGE2)
128 all_ghc_stage3 : $(GHC_STAGE3)
129
130 $(INPLACE_LIB)/settings : settings
131 "$(CP)" $< $@
132
133 $(INPLACE_LIB)/platformConstants: $(includes_GHCCONSTANTS_HASKELL_VALUE)
134 "$(CP)" $< $@
135
136 # The GHC programs need to depend on all the helper programs they might call,
137 # and the settings files they use
138
139 GHC_DEPENDENCIES += $(UNLIT)
140 GHC_DEPENDENCIES += $(INPLACE_LIB)/settings
141 GHC_DEPENDENCIES += $(INPLACE_LIB)/platformConstants
142
143 $(GHC_STAGE1) : | $(GHC_DEPENDENCIES)
144 $(GHC_STAGE2) : | $(GHC_DEPENDENCIES)
145 $(GHC_STAGE3) : | $(GHC_DEPENDENCIES)
146
147 ifeq "$(GhcUnregisterised)" "NO"
148 $(GHC_STAGE1) : | $(SPLIT)
149 $(GHC_STAGE2) : | $(SPLIT)
150 $(GHC_STAGE3) : | $(SPLIT)
151 endif
152
153 ifeq "$(Windows)" "YES"
154 $(GHC_STAGE1) : | $(TOUCHY)
155 $(GHC_STAGE2) : | $(TOUCHY)
156 $(GHC_STAGE3) : | $(TOUCHY)
157 endif
158
159 ifeq "$(BootingFromHc)" "YES"
160 $(GHC_STAGE2) : $(ALL_STAGE1_LIBS)
161 ghc_stage2_OTHER_OBJS += $(compiler_stage2_v_LIB) $(ALL_STAGE1_LIBS) $(ALL_STAGE1_LIBS) $(ALL_STAGE1_LIBS) $(ALL_RTS_LIBS) $(libffi_STATIC_LIB)
162 endif
163
164 endif
165
166 INSTALL_LIBS += settings
167
168 ifeq "$(Windows)" "NO"
169 install: install_ghc_link
170 .PHONY: install_ghc_link
171 install_ghc_link:
172 $(call removeFiles,"$(DESTDIR)$(bindir)/$(CrossCompilePrefix)ghc")
173 $(LN_S) $(CrossCompilePrefix)ghc-$(ProjectVersion) "$(DESTDIR)$(bindir)/$(CrossCompilePrefix)ghc"
174 else
175 # On Windows we install the main binary as $(bindir)/ghc.exe
176 # To get ghc-<version>.exe we have a little C program in driver/ghc
177 install: install_ghc_post
178 .PHONY: install_ghc_post
179 install_ghc_post: install_bins
180 $(call removeFiles,$(DESTDIR)$(bindir)/ghc.exe)
181 "$(MV)" -f $(DESTDIR)$(bindir)/ghc-stage$(INSTALL_GHC_STAGE).exe $(DESTDIR)$(bindir)/$(CrossCompilePrefix)ghc.exe
182 endif
183