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