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