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