2af90bed282d5ff8dde7feeaf1595dd10f2dba98
[ghc.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 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 ghc_stage1_MORE_HC_OPTS = $(GhcStage1HcOpts)
26 ghc_stage2_MORE_HC_OPTS = $(GhcStage2HcOpts)
27 ghc_stage3_MORE_HC_OPTS = $(GhcStage3HcOpts)
28
29 # We need __GLASGOW_HASKELL__ in hschooks.c, so we have to build C
30 # sources with GHC:
31 ghc_stage1_UseGhcForCC = YES
32 ghc_stage2_UseGhcForCC = YES
33 ghc_stage3_UseGhcForCC = YES
34
35 ghc_stage1_C_FILES_NODEPS = ghc/hschooks.c
36
37 ghc_stage2_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES
38 ghc_stage3_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES
39
40 ifeq "$(GhcDebugged)" "YES"
41 ghc_stage1_MORE_HC_OPTS += -debug
42 ghc_stage2_MORE_HC_OPTS += -debug
43 ghc_stage3_MORE_HC_OPTS += -debug
44 endif
45
46 ifeq "$(GhcDynamic)" "YES"
47 ghc_stage2_MORE_HC_OPTS += -dynamic
48 ghc_stage3_MORE_HC_OPTS += -dynamic
49 endif
50
51 ifeq "$(GhcThreaded)" "YES"
52 # Use threaded RTS with GHCi, so threads don't get blocked at the prompt.
53 ghc_stage2_MORE_HC_OPTS += -threaded
54 ghc_stage3_MORE_HC_OPTS += -threaded
55 endif
56
57 ifeq "$(GhcProfiled)" "YES"
58 ghc_stage2_MORE_HC_OPTS += -prof
59 endif
60
61 ghc_stage1_PROG = ghc-stage1$(exeext)
62 ghc_stage2_PROG = ghc-stage2$(exeext)
63 ghc_stage3_PROG = ghc-stage3$(exeext)
64
65 ghc_stage1_SHELL_WRAPPER = YES
66 ghc_stage2_SHELL_WRAPPER = YES
67 ghc_stage3_SHELL_WRAPPER = YES
68 ghc_stage1_SHELL_WRAPPER_NAME = ghc/ghc.wrapper
69 ghc_stage2_SHELL_WRAPPER_NAME = ghc/ghc.wrapper
70 ghc_stage3_SHELL_WRAPPER_NAME = ghc/ghc.wrapper
71
72 ghc_stage$(INSTALL_GHC_STAGE)_INSTALL_SHELL_WRAPPER = YES
73 ghc_stage$(INSTALL_GHC_STAGE)_INSTALL_SHELL_WRAPPER_NAME = ghc-$(ProjectVersion)
74
75 # We override the program name to be ghc, rather than ghc-stage2.
76 # This means the right program name is used in error messages etc.
77 define ghc_stage$(INSTALL_GHC_STAGE)_INSTALL_SHELL_WRAPPER_EXTRA
78 echo 'executablename="$$exedir/ghc"' >> "$(WRAPPER)"
79 endef
80
81 # if stage is set to something other than "1" or "", disable stage 1
82 ifneq "$(filter-out 1,$(stage))" ""
83 ghc_stage1_NOT_NEEDED = YES
84 endif
85 # if stage is set to something other than "2" or "", disable stage 2
86 ifneq "$(filter-out 2,$(stage))" ""
87 ghc_stage2_NOT_NEEDED = YES
88 endif
89 # stage 3 has to be requested explicitly with stage=3
90 ifneq "$(stage)" "3"
91 ghc_stage3_NOT_NEEDED = YES
92 endif
93 $(eval $(call build-prog,ghc,stage1,0))
94 $(eval $(call build-prog,ghc,stage2,1))
95 $(eval $(call build-prog,ghc,stage3,2))
96
97 ifneq "$(BINDIST)" "YES"
98
99 ghc/stage1/build/tmp/$(ghc_stage1_PROG) : $(BOOT_LIBS)
100 ifeq "$(GhcProfiled)" "YES"
101 ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(compiler_stage2_p_LIB)
102 ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(foreach lib,$(PACKAGES_STAGE1),$(libraries/$(lib)_dist-install_p_LIB))
103 endif
104
105 # Modules here import HsVersions.h, so we need ghc_boot_platform.h
106 $(ghc_stage1_depfile_haskell) : compiler/stage1/$(PLATFORM_H)
107 $(ghc_stage2_depfile_haskell) : compiler/stage2/$(PLATFORM_H)
108 $(ghc_stage3_depfile_haskell) : compiler/stage3/$(PLATFORM_H)
109
110 all_ghc_stage1 : $(GHC_STAGE1)
111 all_ghc_stage2 : $(GHC_STAGE2)
112 all_ghc_stage3 : $(GHC_STAGE3)
113
114 $(INPLACE_LIB)/settings : settings
115 "$(CP)" $< $@
116
117 # The GHC programs need to depend on all the helper programs they might call,
118 # and the settings files they use
119
120 $(GHC_STAGE1) : | $(UNLIT) $(INPLACE_LIB)/settings
121 $(GHC_STAGE2) : | $(UNLIT) $(INPLACE_LIB)/settings
122 $(GHC_STAGE3) : | $(UNLIT) $(INPLACE_LIB)/settings
123
124 ifeq "$(GhcUnregisterised)" "NO"
125 $(GHC_STAGE1) : | $(SPLIT)
126 $(GHC_STAGE2) : | $(SPLIT)
127 $(GHC_STAGE3) : | $(SPLIT)
128 endif
129
130 ifeq "$(Windows)" "YES"
131 $(GHC_STAGE1) : | $(TOUCHY)
132 $(GHC_STAGE2) : | $(TOUCHY)
133 $(GHC_STAGE3) : | $(TOUCHY)
134 endif
135
136 ifeq "$(BootingFromHc)" "YES"
137 $(GHC_STAGE2) : $(ALL_STAGE1_LIBS)
138 ghc_stage2_OTHER_OBJS += $(compiler_stage2_v_LIB) $(ALL_STAGE1_LIBS) $(ALL_STAGE1_LIBS) $(ALL_STAGE1_LIBS) $(ALL_RTS_LIBS) $(libffi_STATIC_LIB)
139 endif
140
141 endif
142
143 INSTALL_LIBS += settings
144
145 ifeq "$(Windows)" "NO"
146 install: install_ghc_link
147 .PNONY: install_ghc_link
148 install_ghc_link:
149 $(call removeFiles,"$(DESTDIR)$(bindir)/ghc")
150 $(LN_S) ghc-$(ProjectVersion) "$(DESTDIR)$(bindir)/ghc"
151 else
152 # On Windows we install the main binary as $(bindir)/ghc.exe
153 # To get ghc-<version>.exe we have a little C program in driver/ghc
154 install: install_ghc_post
155 .PHONY: install_ghc_post
156 install_ghc_post: install_bins
157 $(call removeFiles,$(DESTDIR)$(bindir)/ghc.exe)
158 "$(MV)" -f $(DESTDIR)$(bindir)/ghc-stage$(INSTALL_GHC_STAGE).exe $(DESTDIR)$(bindir)/ghc.exe
159 endif
160