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