1 # -----------------------------------------------------------------------------
2 # $Id: Makefile,v 1.219 2002/06/14 08:23:57 simonpj Exp $
6 # Use GHC for compiling C bits (NB. must be before boilerplate include)
8 ifneq "$(BootingFromHc)" "YES"
12 include $(TOP)/mk/boilerplate.mk
14 USER_SRCS = $(filter-out $(DERIVED_SRCS),$(SRCS))
16 ./count_lines $(USER_SRCS)
18 #-----------------------------------------------------------------------------
19 # Building ghc different ways (default is just `normal' sequential)
20 WAYS=$(GhcCompilerWays)
22 # -----------------------------------------------------------------------------
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).
32 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
33 HS_PROG=ghc$(_way)-$(ProjectVersion)
38 HS_PROG=ghc-$(ProjectVersion)
41 # -----------------------------------------------------------------------------
42 # Create compiler configuration
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
47 CONFIG_HS = main/Config.hs
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)
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)
94 CLEAN_FILES += $(CONFIG_HS)
96 # -----------------------------------------------------------------------------
99 # First figure out ALL_DIRS, the source sub-directories
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
106 # Make sure we include Config.hs even if it doesn't exist yet...
107 ALL_SRCS += $(CONFIG_HS)
109 ifeq ($(GhcWithNativeCodeGen),YES)
110 ALL_DIRS += nativeGen
112 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
115 ifeq ($(GhcWithIlx),YES)
120 ifeq ($(GhcWithJavaGen),YES)
122 SRC_HC_OPTS += -DJAVA
125 ifeq "$(BootingFromHc)" "YES"
126 # HC files are always from a self-booted compiler
128 compiling_with_4xx=NO
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)
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
142 # There are some C files to include in HS_PROG, so add these to HS_OBJS
145 # -----------------------------------------------
148 # Big Fudge to get around inherent problem that Makefile setup
149 # has got with 'mkdependC'.
151 SRC_MKDEPENDC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt) -I$(GHC_INCLUDE_DIR)
153 # -----------------------------------------------------------------------------
154 # Haskell compilations
157 # Compiler to use for building ghc, use the build tree
158 # driver when booting.
162 # magic from GNU make manual to convert a list of values
163 # into a colon-separated list
165 space:= $(empty) $(empty)
168 -cpp -fglasgow-exts -Rghc-timing \
169 -I. -IcodeGen -InativeGen -Iparser \
170 -i$(subst $(space),:,$(ALL_DIRS))
172 # Omitted: -I$(GHC_INCLUDE_DIR)
173 # We should have -I$(GHC_INCLUDE_DIR) in SRC_HC_OPTS,
174 # to avoid the use of an explicit path in GHC source files
175 # (include "../includes/config.h"
176 # But alas GHC 4.08 (and others for all I know) uses this very
177 # same include path when compiling the .hc files it generates.
178 # Disaster! Then the hc file sees the GHC 5.02 (or whatever)
179 # include files. For the moment we've reverted to using
180 # an explicit path in the .hs sources
182 # For the benefit of <5.00 compilers, do include GHC_INCLUDE_DIR
183 # when generating dependencies. (=> it gets passed onto mkdependHS,
185 SRC_MKDEPENDHS_OPTS += -I$(GHC_INCLUDE_DIR)
187 ifneq "$(mingw32_HOST_OS)" "1"
188 SRC_HC_OPTS += -package concurrent -package posix -package util
190 SRC_HC_OPTS += -package concurrent -package util
193 SRC_CC_OPTS += -Iparser -I. -I$(TOP)/includes -O
194 SRC_HC_OPTS += -recomp $(GhcHcOpts)
197 ifeq "$(BootingFromHc)" "YES"
198 SRC_CC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
201 # Special flags for particular modules
202 # The standard suffix rule for compiling a Haskell file
203 # adds these flags to the command line
205 # not sure if this is required --SDM
206 main/Main_HC_OPTS = -fvia-C
208 prelude/PrimOp_HC_OPTS = -no-recomp -H80m
210 # because the NCG can't handle the 64-bit math in here
211 prelude/PrelRules_HC_OPTS = -fvia-C
213 main/ParsePkgConf_HC_OPTS += -fno-warn-incomplete-patterns
214 # Use -fvia-C since the NCG can't handle the narrow16Int# (and intToInt16#?)
215 # primops on all platforms.
216 parser/Parser_HC_OPTS += -Onot -fno-warn-incomplete-patterns -fvia-C
218 # The latest GHC version doesn't have a -K option yet, and it doesn't
219 # seem to be necessary anymore for the modules below.
220 ifeq "$(compiling_with_4xx)" "YES"
221 parser/Parser_HC_OPTS += -K2m
224 ifeq "$(HOSTPLATFORM)" "hppa1.1-hp-hpux9"
225 rename/RnMonad_HC_OPTS = -O2 -O2-for-C
228 utils/StringBuffer_HC_OPTS = -fvia-C -fno-prune-tydecls
229 utils/Digraph_HC_OPTS = -fglasgow-exts
231 ifeq "$(bootstrapped)" "YES"
232 utils/Binary_HC_OPTS = -funbox-strict-fields
235 # flags for PrimPacked:
238 # because it contains 'ccall strlen' and 'ccall memcmp', which gets
239 # inlined by gcc, causing a lack of registers.
241 utils/PrimPacked_HC_OPTS = -fvia-C
243 # ByteCodeItbls uses primops that the NCG doesn't support yet.
244 ghci/ByteCodeItbls_HC_OPTS = -fvia-C
245 ghci/ByteCodeLink_HC_OPTS = -fvia-C -monly-3-regs
247 # CSE interacts badly with top-level IORefs (reportedly in DriverState and
248 # DriverMkDepend), causing some of them to be commoned up. We have a fix for
249 # this in 5.00+, but earlier versions of the compiler will need CSE turned off.
250 # To be on the safe side, we disable CSE in *all* modules with top-level IORefs.
251 compMan/CompManager_HC_OPTS = -fno-cse
252 ghci/InteractiveUI_HC_OPTS = -fno-cse
253 main/CmdLineOpts_HC_OPTS = -fno-cse
254 main/DriverFlags_HC_OPTS = -fno-cse
255 main/DriverMkDepend_HC_OPTS = -fno-cse
256 main/DriverPipeline_HC_OPTS = -fno-cse
257 main/DriverState_HC_OPTS = -fno-cse
258 main/DriverUtil_HC_OPTS = -fno-cse
259 main/Finder_HC_OPTS = -fno-cse
260 main/SysTools_HC_OPTS = -fno-cse
262 # The #include is vital for the via-C route, else the C
263 # compiler doesn't realise that the stcall foreign imports are indeed
264 # stdcall, and doesn't generate the Foo@8 name for them
265 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
266 main/SysTools_HC_OPTS += '-\#include <windows.h>' '-\#include <process.h>'
269 # ghc_strlen percolates through so many modules that it is easier to get its
270 # prototype via a global option instead of a myriad of per-file OPTIONS
271 SRC_HC_OPTS += '-\#include "hschooks.h"'
273 # ----------------------------------------------------------------------------
274 # Generate supporting stuff for prelude/PrimOp.lhs
275 # from prelude/primops.txt
277 GENPOC=$(TOP)/utils/genprimopcode/genprimopcode
279 PRIMOP_BITS=primop-data-decl.hs-incl \
281 primop-list.hs-incl \
282 primop-has-side-effects.hs-incl \
283 primop-out-of-line.hs-incl \
284 primop-commutable.hs-incl \
285 primop-needs-wrapper.hs-incl \
286 primop-can-fail.hs-incl \
287 primop-strictness.hs-incl \
288 primop-usage.hs-incl \
289 primop-primop-info.hs-incl
291 CLEAN_FILES += prelude/primops.txt
292 CLEAN_FILES += $(PRIMOP_BITS)
294 SRC_CPP_OPTS += -I$(GHC_INCLUDE_DIR) -traditional
295 SRC_CPP_OPTS += ${GhcCppOpts}
297 ifneq "$(BootingFromHc)" "YES"
298 prelude/PrimOp.lhs prelude/PrimOp.o: $(PRIMOP_BITS)
301 ifneq "$(BootingFromHc)" "YES"
302 depend :: $(PRIMOP_BITS)
305 primop-data-decl.hs-incl: prelude/primops.txt
306 $(GENPOC) --data-decl < $< > $@
307 primop-tag.hs-incl: prelude/primops.txt
308 $(GENPOC) --primop-tag < $< > $@
309 primop-list.hs-incl: prelude/primops.txt
310 $(GENPOC) --primop-list < $< > $@
311 primop-has-side-effects.hs-incl: prelude/primops.txt
312 $(GENPOC) --has-side-effects < $< > $@
313 primop-out-of-line.hs-incl: prelude/primops.txt
314 $(GENPOC) --out-of-line < $< > $@
315 primop-commutable.hs-incl: prelude/primops.txt
316 $(GENPOC) --commutable < $< > $@
317 primop-needs-wrapper.hs-incl: prelude/primops.txt
318 $(GENPOC) --needs-wrapper < $< > $@
319 primop-can-fail.hs-incl: prelude/primops.txt
320 $(GENPOC) --can-fail < $< > $@
321 primop-strictness.hs-incl: prelude/primops.txt
322 $(GENPOC) --strictness < $< > $@
323 primop-usage.hs-incl: prelude/primops.txt
324 $(GENPOC) --usage < $< > $@
325 primop-primop-info.hs-incl: prelude/primops.txt
326 $(GENPOC) --primop-primop-info < $< > $@
330 # ----------------------------------------------------------------------------
333 SRC_HAPPY_OPTS += +RTS -K2m -H16m -RTS $(GHC_HAPPY_OPTS)
335 #-----------------------------------------------------------------------------
338 SRC_LD_OPTS += -no-link-chk
340 # -----------------------------------------------------------------------------
341 # create ghc-inplace, a convenient way to run ghc from the build tree...
345 ghc-inplace : $(HS_PROG)
347 echo '#!/bin/sh' >>$@
348 echo exec $(FPTOOLS_TOP_ABS)/ghc/compiler/$(HS_PROG) '-B$(subst \,\\,$(FPTOOLS_TOP_ABS_PLATFORM))' '"$$@"' >>$@
351 CLEAN_FILES += ghc-inplace
353 #-----------------------------------------------------------------------------
356 # We don't want ghc treated as an ordinary executable,
357 # but put it together with the libraries.
358 # Also don't want any interface files installed
360 DESTDIR = $(INSTALL_LIBRARY_DIR_GHC)
362 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
363 INSTALL_LIBEXECS += $(HS_PROG)
365 INSTALL_PROGS += $(HS_PROG)
368 # ----------------------------------------------------------------------------
371 rename/Rename_HC_OPTS += -auto-all
372 rename/RnEnv_HC_OPTS += -auto-all
373 rename/RnHiFiles_HC_OPTS += -auto-all
374 rename/RnSource_HC_OPTS += -auto-all
376 #-----------------------------------------------------------------------------
379 MAINTAINER_CLEAN_FILES += parser/Parser.info main/ParsePkgConf.info
381 #-----------------------------------------------------------------------------
382 # Include target-rule boilerplate
384 include $(TOP)/mk/target.mk