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