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