[project @ 2002-09-06 14:35:42 by simonmar]
[ghc-hetmet.git] / ghc / compiler / Makefile
1 # -----------------------------------------------------------------------------
2 # $Id: Makefile,v 1.221 2002/09/06 14:35:43 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 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 ifeq ($(GhcWithNativeCodeGen),YES)
110 ALL_DIRS += nativeGen
111 else
112 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
113 endif
114
115 ifeq ($(GhcWithIlx),YES)
116 ALL_DIRS += ilxGen
117 SRC_HC_OPTS += -DILX
118 endif
119
120 ifeq ($(GhcWithJavaGen),YES)
121 ALL_DIRS += javaGen
122 SRC_HC_OPTS += -DJAVA
123 endif
124
125 ifeq "$(BootingFromHc)" "YES"
126 # HC files are always from a self-booted compiler
127 bootstrapped = YES
128 compiling_with_4xx=NO
129 else
130 bootstrapped = $(shell if (test $(GhcCanonVersion) -ge $(ProjectVersionInt) -a $(GhcPatchLevel) -ge $(ProjectPatchLevel)); then echo YES; else echo NO; fi)
131 compiling_with_4xx = $(shell if (test $(GhcCanonVersion) -lt 500); then echo YES; else echo NO; fi)
132 endif
133
134 # Only include GHCi if we're bootstrapping with at least version 411
135 ifeq "$(GhcWithInterpreter)" "YES"
136 ifeq "$(bootstrapped)" "YES"
137 SRC_HC_OPTS += -DGHCI -package readline
138 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
139 SRC_HC_OPTS += -package unix
140 endif
141 ALL_DIRS += ghci
142 endif
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 # mkdependC stuff
150 #
151 # Big Fudge to get around inherent problem that Makefile setup
152 # has got with 'mkdependC'.
153
154 SRC_MKDEPENDC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt) -I$(GHC_INCLUDE_DIR)
155
156 # -----------------------------------------------------------------------------
157 #               Haskell compilations
158
159 #
160 # Compiler to use for building ghc, use the build tree
161 # driver when booting.
162 #
163 HC=$(GHC)
164
165 # magic from GNU make manual to convert a list of values
166 # into a colon-separated list
167 empty:=
168 space:= $(empty) $(empty)
169
170 SRC_HC_OPTS += \
171   -cpp -fglasgow-exts -Rghc-timing \
172   -I. -IcodeGen -InativeGen -Iparser \
173   -i$(subst $(space),:,$(ALL_DIRS)) 
174
175 # Omitted:      -I$(GHC_INCLUDE_DIR)
176 # We should have -I$(GHC_INCLUDE_DIR) in SRC_HC_OPTS, 
177 # to avoid the use of an explicit path in GHC source files
178 #       (include "../includes/config.h"
179 # But alas GHC 4.08 (and others for all I know) uses this very
180 # same include path when compiling the .hc files it generates.
181 # Disaster!  Then the hc file sees the GHC 5.02 (or whatever)
182 # include files.   For the moment we've reverted to using
183 # an explicit path in the .hs sources
184 #
185 # For the benefit of <5.00 compilers, do include GHC_INCLUDE_DIR
186 # when generating dependencies. (=> it gets passed onto mkdependHS,
187 # which needs it).
188 SRC_MKDEPENDHS_OPTS += -I$(GHC_INCLUDE_DIR)
189
190 # When bootstrapped, we don't make use of *any* packages
191 # (except possibly readline if GHCi is enabled, see above)
192 ifneq "$(bootstrapped)" "YES"
193 ifneq "$(mingw32_HOST_OS)" "1"
194 SRC_HC_OPTS += -package concurrent -package posix -package util
195 else
196 SRC_HC_OPTS += -package concurrent -package util
197 endif
198 endif
199
200 SRC_CC_OPTS += -Iparser -I. -I$(TOP)/includes -O
201 SRC_HC_OPTS += -recomp $(GhcHcOpts)
202 SRC_HC_OPTS += -H16M
203
204 ifeq "$(BootingFromHc)" "YES"
205 SRC_CC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
206 endif
207
208 #       Special flags for particular modules
209 #       The standard suffix rule for compiling a Haskell file
210 #       adds these flags to the command line
211
212 # not sure if this is required --SDM
213 main/Main_HC_OPTS               = -fvia-C
214
215 prelude/PrimOp_HC_OPTS          = -no-recomp -H80m
216
217 # because the NCG can't handle the 64-bit math in here
218 prelude/PrelRules_HC_OPTS       = -fvia-C
219
220 main/ParsePkgConf_HC_OPTS       += -fno-warn-incomplete-patterns
221 # Use -fvia-C since the NCG can't handle the narrow16Int# (and intToInt16#?)
222 # primops on all platforms.
223 parser/Parser_HC_OPTS           += -Onot -fno-warn-incomplete-patterns -fvia-C
224
225 # The latest GHC version doesn't have a -K option yet, and it doesn't
226 # seem to be necessary anymore for the modules below.
227 ifeq "$(compiling_with_4xx)" "YES"
228 parser/Parser_HC_OPTS           += -K2m
229 endif
230
231 ifeq "$(HOSTPLATFORM)" "hppa1.1-hp-hpux9"
232 rename/RnMonad_HC_OPTS          =  -O2 -O2-for-C
233 endif
234
235 utils/StringBuffer_HC_OPTS      = -fvia-C -fno-prune-tydecls
236 utils/Digraph_HC_OPTS           = -fglasgow-exts 
237
238 ifeq "$(bootstrapped)" "YES"
239 utils/Binary_HC_OPTS            = -funbox-strict-fields
240 endif
241
242 # ByteCodeItbls uses primops that the NCG doesn't support yet.
243 ghci/ByteCodeItbls_HC_OPTS      = -fvia-C
244 ghci/ByteCodeLink_HC_OPTS       = -fvia-C -monly-3-regs
245
246 # CSE interacts badly with top-level IORefs (reportedly in DriverState and
247 # DriverMkDepend), causing some of them to be commoned up.  We have a fix for
248 # this in 5.00+, but earlier versions of the compiler will need CSE turned off.
249 # To be on the safe side, we disable CSE in *all* modules with top-level IORefs.
250 compMan/CompManager_HC_OPTS     = -fno-cse
251 ghci/InteractiveUI_HC_OPTS      = -fno-cse
252 main/CmdLineOpts_HC_OPTS        = -fno-cse
253 main/DriverFlags_HC_OPTS        = -fno-cse
254 main/DriverMkDepend_HC_OPTS     = -fno-cse
255 main/DriverPipeline_HC_OPTS     = -fno-cse
256 main/DriverState_HC_OPTS        = -fno-cse
257 main/DriverUtil_HC_OPTS         = -fno-cse
258 main/Finder_HC_OPTS             = -fno-cse
259 main/SysTools_HC_OPTS           = -fno-cse
260
261 # The #include is vital for the via-C route, else the C
262 # compiler doesn't realise that the stcall foreign imports are indeed
263 # stdcall, and doesn't generate the Foo@8 name for them
264 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
265 main/SysTools_HC_OPTS           += '-\#include <windows.h>' '-\#include <process.h>'
266 endif
267
268 # ghc_strlen percolates through so many modules that it is easier to get its
269 # prototype via a global option instead of a myriad of per-file OPTIONS
270 SRC_HC_OPTS += '-\#include "hschooks.h"'
271
272 # ----------------------------------------------------------------------------
273 #               Generate supporting stuff for prelude/PrimOp.lhs 
274 #               from prelude/primops.txt
275
276 GENPOC=$(TOP)/utils/genprimopcode/genprimopcode
277
278 PRIMOP_BITS=primop-data-decl.hs-incl \
279             primop-tag.hs-incl  \
280             primop-list.hs-incl  \
281             primop-has-side-effects.hs-incl  \
282             primop-out-of-line.hs-incl  \
283             primop-commutable.hs-incl  \
284             primop-needs-wrapper.hs-incl  \
285             primop-can-fail.hs-incl  \
286             primop-strictness.hs-incl  \
287             primop-usage.hs-incl  \
288             primop-primop-info.hs-incl
289
290 CLEAN_FILES += prelude/primops.txt
291 CLEAN_FILES += $(PRIMOP_BITS)
292
293 SRC_CPP_OPTS += -I$(GHC_INCLUDE_DIR) -traditional
294 SRC_CPP_OPTS += ${GhcCppOpts}
295
296 ifneq "$(BootingFromHc)" "YES"
297 prelude/PrimOp.lhs prelude/PrimOp.o: $(PRIMOP_BITS)
298 endif
299
300 ifneq "$(BootingFromHc)" "YES"
301 depend :: $(PRIMOP_BITS)
302 endif
303
304 primop-data-decl.hs-incl: prelude/primops.txt
305         $(GENPOC) --data-decl          < $< > $@
306 primop-tag.hs-incl: prelude/primops.txt
307         $(GENPOC) --primop-tag         < $< > $@
308 primop-list.hs-incl: prelude/primops.txt
309         $(GENPOC) --primop-list        < $< > $@
310 primop-has-side-effects.hs-incl: prelude/primops.txt
311         $(GENPOC) --has-side-effects   < $< > $@
312 primop-out-of-line.hs-incl: prelude/primops.txt
313         $(GENPOC) --out-of-line        < $< > $@
314 primop-commutable.hs-incl: prelude/primops.txt
315         $(GENPOC) --commutable         < $< > $@
316 primop-needs-wrapper.hs-incl: prelude/primops.txt
317         $(GENPOC) --needs-wrapper      < $< > $@
318 primop-can-fail.hs-incl: prelude/primops.txt
319         $(GENPOC) --can-fail           < $< > $@
320 primop-strictness.hs-incl: prelude/primops.txt
321         $(GENPOC) --strictness         < $< > $@
322 primop-usage.hs-incl: prelude/primops.txt
323         $(GENPOC) --usage              < $< > $@
324 primop-primop-info.hs-incl: prelude/primops.txt
325         $(GENPOC) --primop-primop-info < $< > $@
326
327
328
329 # ----------------------------------------------------------------------------
330 #               Parsers/lexers
331
332 SRC_HAPPY_OPTS += +RTS -K2m -H16m -RTS  $(GHC_HAPPY_OPTS)
333
334 #-----------------------------------------------------------------------------
335 #               Linking
336
337 SRC_LD_OPTS += -no-link-chk 
338
339 # -----------------------------------------------------------------------------
340 # create ghc-inplace, a convenient way to run ghc from the build tree...
341
342 all :: ghc-inplace
343
344 ghc-inplace : $(HS_PROG)
345         @$(RM) $@
346         echo '#!/bin/sh' >>$@
347         echo exec $(FPTOOLS_TOP_ABS)/ghc/compiler/$(HS_PROG) '-B$(subst \,\\,$(FPTOOLS_TOP_ABS_PLATFORM))' '"$$@"' >>$@
348         chmod 755 $@
349
350 CLEAN_FILES += ghc-inplace
351
352 #-----------------------------------------------------------------------------
353 #               install
354
355 # We don't want ghc treated as an ordinary executable,
356 # but put it together with the libraries.
357 # Also don't want any interface files installed
358
359 DESTDIR = $(INSTALL_LIBRARY_DIR_GHC)
360
361 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
362 INSTALL_LIBEXECS += $(HS_PROG)
363 else
364 INSTALL_PROGS += $(HS_PROG)
365 endif
366
367 # ----------------------------------------------------------------------------
368 # profiling.
369
370 # rename/Rename_HC_OPTS += -auto-all
371 # rename/RnEnv_HC_OPTS += -auto-all
372 # rename/RnHiFiles_HC_OPTS += -auto-all
373 # rename/RnIfaces_HC_OPTS += -auto-all
374 # rename/RnSource_HC_OPTS += -auto-all
375 # rename/RnBinds_HC_OPTS += -auto-all
376 # rename/RnExpr_HC_OPTS += -auto-all
377 # rename/RnHsSyn_HC_OPTS += -auto-all
378 # rename/RnNames_HC_OPTS += -auto-all
379 # rename/RnTypes_HC_OPTS += -auto-all
380
381 #-----------------------------------------------------------------------------
382 #               clean
383
384 MAINTAINER_CLEAN_FILES += parser/Parser.info main/ParsePkgConf.info
385
386 #-----------------------------------------------------------------------------
387 #               Include target-rule boilerplate
388
389 include $(TOP)/mk/target.mk