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