[project @ 2002-01-30 14:05:01 by simonmar]
[ghc-hetmet.git] / ghc / compiler / Makefile
1 # -----------------------------------------------------------------------------
2 # $Id: Makefile,v 1.205 2002/01/30 14:05:01 simonmar Exp $
3
4 TOP = ..
5
6 # Use GHC for compiling C bits (NB. must be before boilerplate include)
7 #
8 ifneq "$(BootingFromHc)" "YES"
9 UseGhcForCc = YES
10 endif
11
12 include $(TOP)/mk/boilerplate.mk
13
14 #-----------------------------------------------------------------------------
15 # Building ghc different ways (default is just `normal' sequential)
16 WAYS=$(GhcCompilerWays)
17
18 # -----------------------------------------------------------------------------
19 #               Set HS_PROG
20
21 # Note: there have been reports of people running up against the ARG_MAX limit
22 # when linking ghc with all its constituent object files. The likely source of 
23 # the problem is that the environment is a bit too big, so a workaround could
24 # be to do `env PATH=$(PATH) make ghc' to minimise the environment. (or the
25 # equivalent of `env' if it doesn't exist locally).
26 #
27 ifneq "$(way)" "dll"
28 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
29 HS_PROG=ghc$(_way)-$(ProjectVersion)
30 else
31 HS_PROG=ghc$(_way)
32 endif
33 else
34 HS_PROG=ghc-$(ProjectVersion)
35 endif
36
37 # -----------------------------------------------------------------------------
38 # Create compiler configuration
39 #
40 # The 'echo' commands simply spit the values of various make variables
41 # into Config.hs, whence they can be compiled and used by GHC itself
42
43 CONFIG_HS       = main/Config.hs
44 boot :: $(CONFIG_HS)
45
46 $(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk Makefile
47         @$(RM) -f $(CONFIG_HS)
48         @echo -n "Creating $(CONFIG_HS) ... "
49         @echo "module Config where" >>$(CONFIG_HS)
50         @echo "cProjectName          = \"$(ProjectName)\"" >> $(CONFIG_HS)
51         @echo "cProjectVersion       = \"$(ProjectVersion)\"" >> $(CONFIG_HS)
52         @echo "cProjectVersionInt    = \"$(ProjectVersionInt)\"" >> $(CONFIG_HS)
53         @echo "cBooterVersion        = \"$(GhcVersion)\"" >> $(CONFIG_HS)
54         @echo "cHscIfaceFileVersion  = \"$(HscIfaceFileVersion)\"" >> $(CONFIG_HS)
55         @echo "cHOSTPLATFORM         = \"$(HOSTPLATFORM)\"" >> $(CONFIG_HS)
56         @echo "cTARGETPLATFORM       = \"$(TARGETPLATFORM)\"" >> $(CONFIG_HS)
57         @echo "cGhcWithNativeCodeGen = \"$(GhcWithNativeCodeGen)\"" >> $(CONFIG_HS)
58         @echo "cGhcUnregisterised    = \"$(GhcUnregisterised)\"" >> $(CONFIG_HS)
59         @echo "cLeadingUnderscore    = \"$(LeadingUnderscore)\"" >> $(CONFIG_HS)
60         @echo "cRAWCPP_FLAGS         = \"$(RAWCPP_FLAGS)\"" >> $(CONFIG_HS)
61         @echo "cGCC                  = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
62         @echo "cMKDLL                = \"$(BLD_DLL)\"" >> $(CONFIG_HS)
63         @echo "cGHC_DRIVER_DIR       = \"$(GHC_DRIVER_DIR)\"" >> $(CONFIG_HS)
64         @echo "cGHC_TOUCHY           = \"$(GHC_TOUCHY)\"" >> $(CONFIG_HS)
65         @echo "cGHC_TOUCHY_DIR       = \"$(GHC_TOUCHY_DIR)\"" >> $(CONFIG_HS)
66         @echo "cGHC_UNLIT            = \"$(GHC_UNLIT)\"" >> $(CONFIG_HS)
67         @echo "cGHC_UNLIT_DIR        = \"$(GHC_UNLIT_DIR)\"" >> $(CONFIG_HS)
68         @echo "cGHC_MANGLER          = \"$(GHC_MANGLER)\"" >> $(CONFIG_HS)
69         @echo "cGHC_MANGLER_DIR      = \"$(GHC_MANGLER_DIR)\"" >> $(CONFIG_HS)
70         @echo "cGHC_SPLIT            = \"$(GHC_SPLIT)\"" >> $(CONFIG_HS)
71         @echo "cGHC_SPLIT_DIR        = \"$(GHC_SPLIT_DIR)\"" >> $(CONFIG_HS)
72         @echo "cGHC_SYSMAN           = \"$(GHC_SYSMAN)\"" >> $(CONFIG_HS)
73         @echo "cGHC_SYSMAN_DIR       = \"$(GHC_SYSMAN_DIR)\"" >> $(CONFIG_HS)
74         @echo "cGHC_CP               = \"$(GHC_CP)\"" >> $(CONFIG_HS)
75         @echo "cGHC_PERL             = \"$(GHC_PERL)\"" >> $(CONFIG_HS)
76 ifeq ($(GhcWithIlx),YES)
77         @echo "cILX2IL               = \"$(ILX2IL)\"" >> $(CONFIG_HS)
78         @echo "cILASM                = \"$(ILASM)\"" >> $(CONFIG_HS)
79 endif
80         @echo "cEnableWin32DLLs      = \"$(EnableWin32DLLs)\"" >> $(CONFIG_HS)
81         @echo "cCONTEXT_DIFF         = \"$(CONTEXT_DIFF)\"" >> $(CONFIG_HS)
82         @echo "cHaveLibGmp           = \"$(HaveLibGmp)\"" >> $(CONFIG_HS)
83         @echo "cUSER_WAY_NAMES       = \"$(USER_WAY_NAMES)\"" >> $(CONFIG_HS)
84         @echo "cUSER_WAY_OPTS        = \"$(USER_WAY_OPTS)\"" >> $(CONFIG_HS)
85         @echo "cDEFAULT_TMPDIR       = \"$(DEFAULT_TMPDIR)\"" >> $(CONFIG_HS)
86         @echo done.
87
88 CLEAN_FILES += $(CONFIG_HS)
89
90 # -----------------------------------------------------------------------------
91 # Set SRCS etc.
92 #
93 # First figure out ALL_DIRS, the source sub-directories
94
95 ALL_DIRS = \
96   utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
97   specialise simplCore stranal stgSyn simplStg codeGen absCSyn main \
98   profiling parser usageSP cprAnalysis compMan
99
100 # Make sure we include Config.hs even if it doesn't exist yet...
101 ALL_SRCS += $(CONFIG_HS)
102
103 ifeq ($(GhcWithNativeCodeGen),YES)
104 ALL_DIRS += nativeGen
105 else
106 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
107 endif
108
109 ifeq ($(GhcWithIlx),YES)
110 ALL_DIRS += ilxGen
111 SRC_HC_OPTS += -DILX
112 endif
113
114 ifeq ($(GhcWithJavaGen),YES)
115 ALL_DIRS += javaGen
116 SRC_HC_OPTS += -DJAVA
117 endif
118
119 ifeq "$(BootingFromHc)" "YES"
120 # HC files are always from a self-booted compiler
121 bootstrapped = YES
122 compiling_with_4xx=NO
123 else
124 bootstrapped = $(shell if (test $(GhcCanonVersion) -ge $(ProjectVersionInt)); then echo YES; else echo NO; fi)
125 compiling_with_4xx = $(shell if (test $(GhcCanonVersion) -lt 500); then echo YES; else echo NO; fi)
126 ghc_502_at_least = $(shell if (test $(GhcCanonVersion) -ge 502); then echo YES; else echo NO; fi)
127 endif
128
129 # Only include GHCi if we're bootstrapping with at least version 411
130 ifeq "$(GhcWithInterpreter)" "YES"
131 ifeq "$(bootstrapped)" "YES"
132 SRC_HC_OPTS += -DGHCI
133 ALL_DIRS += ghci
134 endif
135 endif
136
137 # Enable code that assumes a MSDOSish subshell. See mk/config.mk.in
138 # for explanatory comment as to what this does.
139 ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
140 ghc_501_at_least = $(shell if (test $(GhcVanonVersion) -ge 5010); then echo YES; else echo NO; fi)
141 endif
142
143 # There are some C files to include in HS_PROG, so add these to HS_OBJS
144 HS_OBJS  += $(C_OBJS)
145
146 # -----------------------------------------------
147 # system hack.
148 #
149 # GHCi calls the C procedure 'rawSystem'; but alas GHC 4.08 
150 # does not have this.  Everything is fine if you are compiling
151 # GHC with GHC 5.02 or better, but lacking that we have the following
152 # hack: 
153 #       copy rawSystem.c from hslibs/lang/cbits
154 #       into main/ (where it'll be compiled and linked with the compiler)
155 #       (the Haskell-side code is ifdefed into main/SysTools.lhs)
156
157 ifneq "$(bootstrapped)" "YES"
158 SRC_CC_OPTS += -I$(GHC_LIB_DIR)/std/cbits
159 SRC_MKDEPENDC_OPTS += -I$(GHC_LIB_DIR)/std/cbits
160 ALL_SRCS += main/rawSystem.c
161 main/rawSystem.c : $(FPTOOLS_TOP)/hslibs/lang/cbits/rawSystem.c
162         $(CP) $< main
163 else
164 EXCLUDED_SRCS = main/rawSystem.c
165 endif
166
167 # -----------------------------------------------
168 # mkdependC stuff
169 #
170 # Big Fudge to get around inherent problem that Makefile setup
171 # has got with 'mkdependC'.
172
173 SRC_MKDEPENDC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt) -I$(GHC_INCLUDE_DIR)
174
175 # -----------------------------------------------------------------------------
176 #               Haskell compilations
177
178 #
179 # Compiler to use for building ghc, use the build tree
180 # driver when booting.
181 #
182 HC=$(GHC)
183
184 # magic from GNU make manual to convert a list of values
185 # into a colon-separated list
186 empty:=
187 space:= $(empty) $(empty)
188
189 SRC_HC_OPTS += \
190   -cpp -fglasgow-exts -Rghc-timing \
191   -I. -IcodeGen -InativeGen -Iparser \
192   -i$(subst $(space),:,$(ALL_DIRS)) 
193
194 # Omitted:      -I$(GHC_INCLUDE_DIR)
195 # We should have -I$(GHC_INCLUDE_DIR) in SRC_HC_OPTS, 
196 # to avoid the use of an explicit path in GHC source files
197 #       (include "../includes/config.h"
198 # But alas GHC 4.08 (and others for all I know) uses this very
199 # same include path when compiling the .hc files it generates.
200 # Disaster!  Then the hc file sees the GHC 5.02 (or whatever)
201 # include files.   For the moment we've reverted to using
202 # an explicit path in the .hs sources
203 #
204 # For the benefit of <5.00 compilers, do include GHC_INCLUDE_DIR
205 # when generating dependencies. (=> it gets passed onto mkdependHS,
206 # which needs it).
207 SRC_MKDEPENDHS_OPTS += -I$(GHC_INCLUDE_DIR)
208
209 ifneq "$(mingw32_TARGET_OS)" "1"
210 SRC_HC_OPTS += -package concurrent -package posix -package text -package util
211 else
212 SRC_HC_OPTS += -package concurrent -package text -package util
213 endif
214
215 SRC_CC_OPTS += -Iparser -I. -I$(TOP)/includes -O
216 SRC_HC_OPTS += -recomp $(GhcHcOpts)
217 SRC_HC_OPTS += -H16M
218
219 ifeq "$(BootingFromHc)" "YES"
220 SRC_CC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
221 endif
222
223 #       Special flags for particular modules
224 #       The standard suffix rule for compiling a Haskell file
225 #       adds these flags to the command line
226
227 # not sure if this is required --SDM
228 main/Main_HC_OPTS               = -fvia-C
229
230 prelude/PrimOp_HC_OPTS          = -no-recomp -H80m
231
232 # because the NCG can't handle the 64-bit math in here
233 prelude/PrelRules_HC_OPTS       = -fvia-C
234
235 main/ParsePkgConf_HC_OPTS       += -fno-warn-incomplete-patterns
236 # Use -fvia-C since the NCG can't handle the narrow16Int# (and intToInt16#?)
237 # primops on all platforms.
238 rename/ParseIface_HC_OPTS       += -Onot -H45m -fno-warn-incomplete-patterns -fvia-C
239 parser/Parser_HC_OPTS           += -Onot -fno-warn-incomplete-patterns -fvia-C
240
241 # The latest GHC version doesn't have a -K option yet, and it doesn't
242 # seem to be necessary anymore for the modules below.
243 ifeq "$(compiling_with_4xx)" "YES"
244 rename/ParseIface_HC_OPTS       += -K2m
245 parser/Parser_HC_OPTS           += -K2m
246 endif
247
248 ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
249 rename/RnMonad_HC_OPTS          =  -O2 -O2-for-C
250 endif
251
252 utils/StringBuffer_HC_OPTS      = -fvia-C -fno-prune-tydecls
253 utils/Digraph_HC_OPTS           = -fglasgow-exts 
254
255 # flags for PrimPacked:
256 #
257 # -monly-3-regs 
258 #       because it contains a 'ccall strlen', which gets inlined by
259 #       gcc, causing a lack of registers.
260 #
261 utils/PrimPacked_HC_OPTS        = -fvia-C -monly-3-regs
262
263 # ByteCodeItbls uses primops that the NCG doesn't support yet.
264 ghci/ByteCodeItbls_HC_OPTS      = -fvia-C
265 ghci/ByteCodeLink_HC_OPTS       = -fvia-C -monly-3-regs
266
267 # CSE interacts badly with top-level IORefs (reportedly in DriverState and
268 # DriverMkDepend), causing some of them to be commoned up.  We have a fix for
269 # this in 5.00+, but earlier versions of the compiler will need CSE turned off.
270 # To be on the safe side, we disable CSE in *all* modules with top-level IORefs.
271 compMan/CompManager_HC_OPTS     = -fno-cse
272 ghci/InteractiveUI_HC_OPTS      = -fno-cse
273 main/CmdLineOpts_HC_OPTS        = -fno-cse
274 main/DriverFlags_HC_OPTS        = -fno-cse
275 main/DriverMkDepend_HC_OPTS     = -fno-cse
276 main/DriverPipeline_HC_OPTS     = -fno-cse
277 main/DriverState_HC_OPTS        = -fno-cse
278 main/DriverUtil_HC_OPTS         = -fno-cse
279 main/Finder_HC_OPTS             = -fno-cse
280 main/SysTools_HC_OPTS           = -fno-cse
281
282 # The #include is vital for the via-C route, else the C
283 # compiler doesn't realise that the stcall foreign imports are indeed
284 # stdcall, and doesn't generate the Foo@8 name for them
285 ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
286 main/SysTools_HC_OPTS           += '-\#include <windows.h>' '-\#include <process.h>'
287 endif
288
289 # ----------------------------------------------------------------------------
290 #               Generate supporting stuff for prelude/PrimOp.lhs 
291 #               from prelude/primops.txt
292
293 GENPOC=$(TOP)/utils/genprimopcode/genprimopcode
294
295 PRIMOP_BITS=primop-data-decl.hs-incl \
296             primop-tag.hs-incl  \
297             primop-list.hs-incl  \
298             primop-has-side-effects.hs-incl  \
299             primop-out-of-line.hs-incl  \
300             primop-commutable.hs-incl  \
301             primop-needs-wrapper.hs-incl  \
302             primop-can-fail.hs-incl  \
303             primop-strictness.hs-incl  \
304             primop-usage.hs-incl  \
305             primop-primop-info.hs-incl
306
307 CLEAN_FILES += prelude/primops.txt
308 CLEAN_FILES += $(PRIMOP_BITS)
309
310 SRC_CPP_OPTS += -I$(GHC_INCLUDE_DIR) -traditional
311 SRC_CPP_OPTS += ${GhcCppOpts}
312
313 ifneq "$(BootingFromHc)" "YES"
314 prelude/PrimOp.lhs prelude/PrimOp.o: $(PRIMOP_BITS)
315 endif
316
317 ifneq "$(BootingFromHc)" "YES"
318 depend :: $(PRIMOP_BITS)
319 endif
320
321 primop-data-decl.hs-incl: prelude/primops.txt
322         $(GENPOC) --data-decl          < $< > $@
323 primop-tag.hs-incl: prelude/primops.txt
324         $(GENPOC) --primop-tag         < $< > $@
325 primop-list.hs-incl: prelude/primops.txt
326         $(GENPOC) --primop-list        < $< > $@
327 primop-has-side-effects.hs-incl: prelude/primops.txt
328         $(GENPOC) --has-side-effects   < $< > $@
329 primop-out-of-line.hs-incl: prelude/primops.txt
330         $(GENPOC) --out-of-line        < $< > $@
331 primop-commutable.hs-incl: prelude/primops.txt
332         $(GENPOC) --commutable         < $< > $@
333 primop-needs-wrapper.hs-incl: prelude/primops.txt
334         $(GENPOC) --needs-wrapper      < $< > $@
335 primop-can-fail.hs-incl: prelude/primops.txt
336         $(GENPOC) --can-fail           < $< > $@
337 primop-strictness.hs-incl: prelude/primops.txt
338         $(GENPOC) --strictness         < $< > $@
339 primop-usage.hs-incl: prelude/primops.txt
340         $(GENPOC) --usage              < $< > $@
341 primop-primop-info.hs-incl: prelude/primops.txt
342         $(GENPOC) --primop-primop-info < $< > $@
343
344
345
346 # ----------------------------------------------------------------------------
347 #               Parsers/lexers
348
349 SRC_HAPPY_OPTS += +RTS -K2m -H16m -RTS  $(GHC_HAPPY_OPTS)
350
351 #-----------------------------------------------------------------------------
352 #               Linking
353
354 SRC_LD_OPTS += -no-link-chk 
355
356 # -----------------------------------------------------------------------------
357 # create ghc-inplace, a convenient way to run ghc from the build tree...
358
359 all :: ghc-inplace
360
361 ghc-inplace : $(HS_PROG)
362         @$(RM) $@
363         echo '#!/bin/sh' >>$@
364         echo exec $(FPTOOLS_TOP_ABS)/ghc/compiler/$(HS_PROG) '-B$(subst \,\\,$(FPTOOLS_TOP_ABS_PLATFORM))' '"$$@"' >>$@
365         chmod 755 $@
366
367 CLEAN_FILES += ghc-inplace
368
369 #-----------------------------------------------------------------------------
370 #               install
371
372 # We don't want ghc treated as an ordinary executable,
373 # but put it together with the libraries.
374 # Also don't want any interface files installed
375
376 DESTDIR = $(INSTALL_LIBRARY_DIR_GHC)
377
378 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
379 INSTALL_LIBEXECS += $(HS_PROG)
380 else
381 INSTALL_PROGS += $(HS_PROG)
382 endif
383
384 #-----------------------------------------------------------------------------
385 #               clean
386
387 MAINTAINER_CLEAN_FILES += \
388         parser/Parser.info rename/ParseIface.info main/ParsePkgConf.info
389
390 #-----------------------------------------------------------------------------
391 #               Include target-rule boilerplate
392
393 include $(TOP)/mk/target.mk