1 # -----------------------------------------------------------------------------
2 # Main compiler Makefile
6 # all builds stage1 compiler
8 # boot stage=N generate build dirs and dependencies for stage N.
9 # NB. Must be done before 'make stageN'.
10 # NB. Cannot 'make boot stage=2' until stage1 has
11 # been built (similarly for stage3).
13 # stage1 (or stage=1) builds stage1 compiler
14 # stage2 (or stage=2) builds stage2 compiler
15 # stage3 (or stage=3) builds stage3 compiler
20 # Use GHC for compiling C bits (NB. must be before boilerplate include)
24 # We don't want to compile stage1 in multiple ways
25 ifeq "$(findstring $(stage), 2 3)" ""
29 include $(TOP)/mk/boilerplate.mk
31 ifeq "$(GhcThreaded)$(GhcProfiled)" "YESYES"
32 $(error Cannot make GHC both threaded and profiled)
36 #-----------------------------------------------------------------------------
37 # Counting source code lines
39 USER_SRCS = $(filter-out $(DERIVED_SRCS),$(SRCS))
41 ./count_lines $(USER_SRCS)
43 # -----------------------------------------------------------------------------
46 # The stage1/stage2/stage3 business is quite delicate. Here's how it works:
48 # - the variable $(stage) holds the current stage number. To build a
49 # particular stage, you say 'make stage=N' where N is 1, 2, or 3.
52 # - for stage N, object files and .hi files are placed inside
53 # the directory stageN, in subdirectories as per the sources.
55 # - we use explicit -o and -ohi options to direct the output from C &
56 # Haskell compilations.
58 # - we generate a different .depend file for each build. They need to be
59 # different, because each stage might include different files: stage1
60 # might not include GHCi, for example. For each stage, a normal .depend
61 # file is generated, and then post-processed to add the correct stageN/
62 # prefix to each object and .hi filename. The resulting .depend file
63 # is named .depend-$(stage). See the end of this Makefile for details.
65 # - normal implicit rules don't work any more, because they're of the form
69 # whereas we really need
73 # so suffix.mk now defines the appropriate suffix rules when
74 # $(odir) is set to a non-empty value. Here we set $(odir) to
75 # stage1, stage2, or stage3.
77 # There are other plausible designs that might work, but each has different
80 # - using -odir and -hidir:
81 # -odir puts all the objects in one directory (strips off the
82 # subdirectory part), which eventually forces us to use VPATH to find
83 # the sources. I have a really bad feeling about VPATH.
85 # - invoke make in the stageN subdirectory. This probably requires VPATH
88 # - create a link tree. The problem with requiring link trees is that
89 # Windows doesn't support symbolic links.
97 $(MKDIRHIER) stage$(stage)
98 for i in $(ALL_DIRS); do \
99 $(MKDIRHIER) stage$(stage)/$$i; \
105 ifneq "$(findstring $(stage), 2 3)" ""
137 SRC_HC_OPTS += $(patsubst %, -i$(odir)/%, $(ALL_DIRS))
139 SRC_HC_OPTS += -Wall -fno-warn-name-shadowing -fno-warn-orphans
141 HS_OBJS = $(patsubst %, $(odir)/%, $(addsuffix .$(way_)o,$(basename $(HS_SRCS))))
142 C_OBJS = $(patsubst %, $(odir)/%, $(addsuffix .$(way_)o,$(basename $(C_SRCS))))
144 # Our standard cleaning rules don't know that we're doing our output
145 # into $(odir), so we have to augment CLEAN_FILES appropriateliy.
147 CLEAN_FILES += $(odir)/*/*.$(way_)hi $(odir)/*/*.$(way_)hi-boot $(odir)/*/*.$(way_)o-boot
149 ifeq "$(UsingHsBoot)" "YES"
150 CLEAN_FILES += $(odir)/*/*.hi-boot $(odir)/*/*.o-boot
154 mostlyclean clean distclean maintainer-clean ::
159 # -----------------------------------------------------------------------------
162 # Note: there have been reports of people running up against the ARG_MAX limit
163 # when linking ghc with all its constituent object files. The likely source of
164 # the problem is that the environment is a bit too big, so a workaround could
165 # be to do `env PATH=$(PATH) make ghc' to minimise the environment. (or the
166 # equivalent of `env' if it doesn't exist locally).
168 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
169 GHC_PROG=$(odir)/ghc$(_way)-$(ProjectVersion)
171 GHC_PROG=$(odir)/ghc$(_way)
175 HS_PROG = $(GHC_PROG)
178 # -----------------------------------------------------------------------------
179 # Create compiler configuration
181 # The 'echo' commands simply spit the values of various make variables
182 # into Config.hs, whence they can be compiled and used by GHC itself
184 CONFIG_HS = main/Config.hs
187 $(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk
188 @$(RM) -f $(CONFIG_HS)
189 @echo "Creating $(CONFIG_HS) ... "
190 @echo "module Config where" >>$(CONFIG_HS)
191 @echo "cProjectName :: String" >> $(CONFIG_HS)
192 @echo "cProjectName = \"$(ProjectName)\"" >> $(CONFIG_HS)
193 @echo "cProjectVersion :: String" >> $(CONFIG_HS)
194 @echo "cProjectVersion = \"$(ProjectVersion)\"" >> $(CONFIG_HS)
195 @echo "cProjectVersionInt :: String" >> $(CONFIG_HS)
196 @echo "cProjectVersionInt = \"$(ProjectVersionInt)\"" >> $(CONFIG_HS)
197 @echo "cProjectPatchLevel :: String" >> $(CONFIG_HS)
198 @echo "cProjectPatchLevel = \"$(ProjectPatchLevel)\"" >> $(CONFIG_HS)
199 @echo "cBooterVersion :: String" >> $(CONFIG_HS)
200 @echo "cBooterVersion = \"$(GhcVersion)\"" >> $(CONFIG_HS)
201 @echo "cStage :: String" >> $(CONFIG_HS)
202 @echo "cStage = STAGE" >> $(CONFIG_HS)
203 @echo "cHscIfaceFileVersion :: String" >> $(CONFIG_HS)
204 @echo "cHscIfaceFileVersion = \"$(HscIfaceFileVersion)\"" >> $(CONFIG_HS)
205 @echo "cSplitObjs :: String" >> $(CONFIG_HS)
206 @echo "cSplitObjs = \"$(SplitObjs)\"" >> $(CONFIG_HS)
207 @echo "cGhcWithInterpreter :: String" >> $(CONFIG_HS)
208 @echo "cGhcWithInterpreter = \"$(GhcWithInterpreter)\"" >> $(CONFIG_HS)
209 @echo "cGhcWithNativeCodeGen :: String" >> $(CONFIG_HS)
210 @echo "cGhcWithNativeCodeGen = \"$(GhcWithNativeCodeGen)\"" >> $(CONFIG_HS)
211 @echo "cGhcWithSMP :: String" >> $(CONFIG_HS)
212 @echo "cGhcWithSMP = \"$(GhcWithSMP)\"" >> $(CONFIG_HS)
213 @echo "cGhcRTSWays :: String" >> $(CONFIG_HS)
214 @echo "cGhcRTSWays = \"$(GhcRTSWays)\"" >> $(CONFIG_HS)
215 @echo "cGhcUnregisterised :: String" >> $(CONFIG_HS)
216 @echo "cGhcUnregisterised = \"$(GhcUnregisterised)\"" >> $(CONFIG_HS)
217 @echo "cGhcEnableTablesNextToCode :: String" >> $(CONFIG_HS)
218 @echo "cGhcEnableTablesNextToCode = \"$(GhcEnableTablesNextToCode)\"" >> $(CONFIG_HS)
219 @echo "cLeadingUnderscore :: String" >> $(CONFIG_HS)
220 @echo "cLeadingUnderscore = \"$(LeadingUnderscore)\"" >> $(CONFIG_HS)
221 @echo "cRAWCPP_FLAGS :: String" >> $(CONFIG_HS)
222 @echo "cRAWCPP_FLAGS = \"$(RAWCPP_FLAGS)\"" >> $(CONFIG_HS)
223 @echo "cGCC :: String" >> $(CONFIG_HS)
224 @echo "cGCC = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
225 @echo "cMKDLL :: String" >> $(CONFIG_HS)
226 @echo "cMKDLL = \"$(BLD_DLL)\"" >> $(CONFIG_HS)
227 @echo "cLdIsGNULd :: String" >> $(CONFIG_HS)
228 @echo "cLdIsGNULd = \"$(LdIsGNULd)\"" >> $(CONFIG_HS)
229 @echo "cLD_X :: String" >> $(CONFIG_HS)
230 @echo "cLD_X = \"$(LD_X)\"" >> $(CONFIG_HS)
231 @echo "cGHC_DRIVER_DIR_REL :: String" >> $(CONFIG_HS)
232 @echo "cGHC_DRIVER_DIR_REL = \"$(GHC_DRIVER_DIR_REL)\"" >> $(CONFIG_HS)
233 @echo "cGHC_TOUCHY_PGM :: String" >> $(CONFIG_HS)
234 @echo "cGHC_TOUCHY_PGM = \"$(GHC_TOUCHY_PGM)\"" >> $(CONFIG_HS)
235 @echo "cGHC_TOUCHY_DIR_REL :: String" >> $(CONFIG_HS)
236 @echo "cGHC_TOUCHY_DIR_REL = \"$(GHC_TOUCHY_DIR_REL)\"" >> $(CONFIG_HS)
237 @echo "cGHC_UNLIT_PGM :: String" >> $(CONFIG_HS)
238 @echo "cGHC_UNLIT_PGM = \"$(GHC_UNLIT_PGM)\"" >> $(CONFIG_HS)
239 @echo "cGHC_UNLIT_DIR_REL :: String" >> $(CONFIG_HS)
240 @echo "cGHC_UNLIT_DIR_REL = \"$(GHC_UNLIT_DIR_REL)\"" >> $(CONFIG_HS)
241 @echo "cGHC_MANGLER_PGM :: String" >> $(CONFIG_HS)
242 @echo "cGHC_MANGLER_PGM = \"$(GHC_MANGLER_PGM)\"" >> $(CONFIG_HS)
243 @echo "cGHC_MANGLER_DIR_REL :: String" >> $(CONFIG_HS)
244 @echo "cGHC_MANGLER_DIR_REL = \"$(GHC_MANGLER_DIR_REL)\"" >> $(CONFIG_HS)
245 @echo "cGHC_SPLIT_PGM :: String" >> $(CONFIG_HS)
246 @echo "cGHC_SPLIT_PGM = \"$(GHC_SPLIT_PGM)\"" >> $(CONFIG_HS)
247 @echo "cGHC_SPLIT_DIR_REL :: String" >> $(CONFIG_HS)
248 @echo "cGHC_SPLIT_DIR_REL = \"$(GHC_SPLIT_DIR_REL)\"" >> $(CONFIG_HS)
249 @echo "cGHC_SYSMAN_PGM :: String" >> $(CONFIG_HS)
250 @echo "cGHC_SYSMAN_PGM = \"$(GHC_SYSMAN)\"" >> $(CONFIG_HS)
251 @echo "cGHC_SYSMAN_DIR_REL :: String" >> $(CONFIG_HS)
252 @echo "cGHC_SYSMAN_DIR_REL = \"$(GHC_SYSMAN_DIR)\"" >> $(CONFIG_HS)
253 @echo "cGHC_CP :: String" >> $(CONFIG_HS)
254 @echo "cGHC_CP = \"$(GHC_CP)\"" >> $(CONFIG_HS)
255 @echo "cGHC_PERL :: String" >> $(CONFIG_HS)
256 @echo "cGHC_PERL = \"$(GHC_PERL)\"" >> $(CONFIG_HS)
257 @echo "cEnableWin32DLLs :: String" >> $(CONFIG_HS)
258 @echo "cEnableWin32DLLs = \"$(EnableWin32DLLs)\"" >> $(CONFIG_HS)
259 @echo "cCONTEXT_DIFF :: String" >> $(CONFIG_HS)
260 @echo "cCONTEXT_DIFF = \"$(CONTEXT_DIFF)\"" >> $(CONFIG_HS)
261 @echo "cUSER_WAY_NAMES :: String" >> $(CONFIG_HS)
262 @echo "cUSER_WAY_NAMES = \"$(USER_WAY_NAMES)\"" >> $(CONFIG_HS)
263 @echo "cUSER_WAY_OPTS :: String" >> $(CONFIG_HS)
264 @echo "cUSER_WAY_OPTS = \"$(USER_WAY_OPTS)\"" >> $(CONFIG_HS)
265 @echo "cDEFAULT_TMPDIR :: String" >> $(CONFIG_HS)
266 @echo "cDEFAULT_TMPDIR = \"$(DEFAULT_TMPDIR)\"" >> $(CONFIG_HS)
267 @echo "cRelocatableBuild :: Bool" >> $(CONFIG_HS)
268 ifeq "$(RelocatableBuild)" "YES"
269 @echo "cRelocatableBuild = True" >> $(CONFIG_HS)
271 @echo "cRelocatableBuild = False" >> $(CONFIG_HS)
273 @echo "cLibFFI :: Bool" >> $(CONFIG_HS)
274 ifeq "$(UseLibFFIForAdjustors)" "YES"
275 @echo "cLibFFI = True" >> $(CONFIG_HS)
277 @echo "cLibFFI = False" >> $(CONFIG_HS)
281 CLEAN_FILES += $(CONFIG_HS)
283 # -----------------------------------------------------------------------------
284 # Create platform includes
286 # Here we generate a little header file containing CPP symbols that GHC
287 # uses to determine which platform it is building on/for. The platforms
288 # can differ between stage1 and stage2 if we're cross-compiling, so we
289 # need one of these header files per stage.
291 PLATFORM_H = ghc_boot_platform.h
293 stage1/$(PLATFORM_H) : stage_dirs $(FPTOOLS_TOP)/mk/config.mk
294 @echo "Creating $@..."
296 @echo "#ifndef __PLATFORM_H__" >$@
297 @echo "#define __PLATFORM_H__" >>$@
299 @echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
300 @echo "#define HostPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
301 @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
303 @echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
304 @echo "#define $(HostPlatform_CPP)_HOST 1" >> $@
305 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
307 @echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
308 @echo "#define $(HostArch_CPP)_HOST_ARCH 1" >> $@
309 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
310 @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
311 @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
312 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
314 @echo "#define $(BuildOS_CPP)_BUILD_OS 1" >> $@
315 @echo "#define $(HostOS_CPP)_HOST_OS 1" >> $@
316 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
317 @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
318 @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
319 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
320 ifeq "$(HostOS_CPP)" "irix"
321 @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS " >> $@
322 @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
323 @echo "#endif " >> $@
326 @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
327 @echo "#define $(HostVendor_CPP)_HOST_VENDOR 1" >> $@
328 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
329 @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
330 @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
331 @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
333 @echo "#endif /* __PLATFORM_H__ */" >> $@
336 # For stage2 and above, the BUILD platform is the HOST of stage1, and
337 # the HOST platform is the TARGET of stage1. The TARGET remains the same
338 # (stage1 is the cross-compiler, not stage2).
339 stage2/$(PLATFORM_H) : stage_dirs $(FPTOOLS_TOP)/mk/config.mk
340 @echo "Creating $@..."
342 @echo "#ifndef __PLATFORM_H__" >$@
343 @echo "#define __PLATFORM_H__" >>$@
345 @echo "#define BuildPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
346 @echo "#define HostPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
347 @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
349 @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
350 @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
351 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
353 @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
354 @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
355 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
356 @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
357 @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
358 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
360 @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
361 @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
362 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
363 @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
364 @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
365 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
366 ifeq "$(HostOS_CPP)" "irix"
367 @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS " >> $@
368 @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
369 @echo "#endif " >> $@
372 @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
373 @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
374 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
375 @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
376 @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
377 @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
379 @echo "#endif /* __PLATFORM_H__ */" >> $@
382 stage3/$(PLATFORM_H) : stage_dirs stage2/$(PLATFORM_H)
383 $(CP) stage2/$(PLATFORM_H) stage3/$(PLATFORM_H)
385 STAGE_PLATFORM_H = stage$(stage)/$(PLATFORM_H)
387 boot :: $(STAGE_PLATFORM_H)
389 SRC_HC_OPTS += -Istage$(stage)
391 # -----------------------------------------------------------------------------
394 # First figure out ALL_DIRS, the source sub-directories
397 utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
398 vectorise specialise simplCore stranal stgSyn simplStg codeGen main \
399 profiling parser cprAnalysis iface cmm
401 # Make sure we include Config.hs even if it doesn't exist yet...
402 ALL_SRCS += $(CONFIG_HS)
404 # HsGeneric.hs is not used just now
405 EXCLUDED_SRCS += hsSyn/HsGeneric.hs
407 ifeq ($(GhcWithNativeCodeGen),YES)
408 ALL_DIRS += nativeGen
410 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
413 ifeq "$(BootingFromHc)" "YES"
414 # HC files are always from a self-booted compiler
417 ifneq "$(findstring $(stage), 2 3)" ""
424 # Beyond stage 1, honour any Mac OS X depolyment target options. If we use
425 # these options in stage 1 we get a linker error if the bootstrap compiler is
426 # for a more recent OS version
427 ifneq "$(findstring $(stage), 2 3)" ""
428 SRC_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
429 SRC_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
430 SRC_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
433 # -----------------------------------------------------------------------------
434 # Building a compiler with interpreter support
436 # The interpreter, GHCi interface, Template Haskell and Hpc are only
437 # enabled when we are bootstrapping with the same version of GHC, and
438 # the interpreter is supported on this platform.
440 ifeq "$(bootstrapped)" "YES"
441 SRC_HC_OPTS += -package bytestring
442 PKG_DEPENDS += bytestring
445 SRC_HC_OPTS += -package hpc
448 ifeq "$(GhcWithInterpreter) $(bootstrapped)" "YES YES"
450 # Yes, include the interepreter and Template Haskell extensions
451 SRC_HC_OPTS += -DGHCI -package template-haskell
452 PKG_DEPENDS += template-haskell
454 # Should GHCI be building info tables in the TABLES_NEXT_TO_CODE style
456 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
457 SRC_HC_OPTS += -DGHCI_TABLES_NEXT_TO_CODE
460 ifeq "$(GhcThreaded)" "YES"
461 # Use threaded RTS with GHCi, so threads don't get blocked at the prompt.
462 SRC_LD_OPTS += -threaded
464 ifeq "$(GhcProfiled)" "YES"
467 ifeq "$(GhcDebugged)" "YES"
468 SRC_LD_OPTS += -debug
471 SRC_HC_OPTS += -I$(FPTOOLS_TOP)/libffi/build/include
472 SRC_HSC2HS_OPTS += -I$(FPTOOLS_TOP)/libffi/build/include
476 # If we are going to use dynamic libraries instead of .o files for ghci,
477 # we will need to always retain CAFs in the compiler.
478 # ghci/keepCAFsForGHCi contains a GNU C __attribute__((constructor))
479 # function which sets the keepCAFs flag for the RTS before any Haskell
481 ifeq "$(GhcBuildDylibs)" "YES"
483 EXCLUDED_SRCS += ghci/keepCAFsForGHCi.c
486 # Enable editline if either:
487 # - we're building stage 1 and $(GhcHasEditline)="YES"
488 # - we're building stage 2/3, and we have built the editline package
490 # But we don't enable editline on Windows, as Windows terminals have
491 # editline-like support builtin.
493 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
495 ifeq "$(GhcHasEditline)" "YES"
496 SRC_HC_OPTS += -package editline -DUSE_EDITLINE
497 PKG_DEPENDS += editline
500 ifeq "$(wildcard $(FPTOOLS_TOP_ABS)/libraries/editline/unbuildable)" ""
501 SRC_HC_OPTS += -package editline -DUSE_EDITLINE
502 PKG_DEPENDS += editline
509 # No interpreter, so exclude Template Haskell modules
510 EXCLUDED_SRCS += deSugar/DsMeta.hs typecheck/TcSplice.lhs hsSyn/Convert.lhs
512 endif # bootstrapped with interpreter
514 # -----------------------------------------------
517 # Big Fudge to get around inherent problem that Makefile setup
518 # has got with 'mkdependC'.
520 SRC_MKDEPENDC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
522 # XXX not really correct, hschooks.c actually gets include files like
523 # RtsFlags.c from the installed GHC, but we can't tell mkdependC about that.
524 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
526 # -----------------------------------------------------------------------------
527 # Haskell compilations
529 SRC_HC_OPTS += -cpp -fglasgow-exts -Rghc-timing -I. -Iparser -Iutil
531 ifeq "$(ghc_ge_609)" "NO"
532 SRC_HC_OPTS += -fno-generics
534 SRC_HC_OPTS += -XNoGenerics
537 # Omitted: -I$(GHC_INCLUDE_DIR)
538 # We should have -I$(GHC_INCLUDE_DIR) in SRC_HC_OPTS,
539 # to avoid the use of an explicit path in GHC source files
540 # (include "../includes/config.h"
541 # But alas GHC 4.08 (and others for all I know) uses this very
542 # same include path when compiling the .hc files it generates.
543 # Disaster! Then the hc file sees the GHC 5.02 (or whatever)
544 # include files. For the moment we've reverted to using
545 # an explicit path in the .hs sources
547 # We need System.Posix (or Posix when ghc < 6.2)
548 ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
549 ifeq "$(bootstrapped)" "YES"
550 SRC_HC_OPTS += -package Win32
554 SRC_HC_OPTS += -package unix
558 SRC_HC_OPTS += -package Cabal
561 # Ignore lang, to avoid potential clash with the Generics module if
562 # lang happens to be a dependency of some exposed package in the local
563 # GHC installation (eg. wxHaskell did this around 6.4).
564 SRC_HC_OPTS += -ignore-package lang
566 SRC_CC_OPTS += -Iparser -I. -O
567 SRC_HC_OPTS += $(GhcHcOpts) $(GhcStage$(stage)HcOpts)
570 ifeq "$(BootingFromHc)" "YES"
571 SRC_CC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
574 # ---- Profiling ----
575 #simplCore/Simplify_HC_OPTS = -auto-all
576 #simplCore/SimplEnv_HC_OPTS = -auto-all
577 #simplCore/SimplUtils_HC_OPTS = -auto-all
579 # The #include is vital for the via-C route, else the C
580 # compiler doesn't realise that the stcall foreign imports are indeed
581 # stdcall, and doesn't generate the Foo@8 name for them
582 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
583 main/SysTools_HC_OPTS += '-\#include <windows.h>' '-\#include <process.h>'
586 # ghc_strlen percolates through so many modules that it is easier to get its
587 # prototype via a global option instead of a myriad of per-file OPTIONS
588 SRC_HC_OPTS += '-\#include "cutils.h"'
590 # ----------------------------------------------------------------------------
591 # Generate supporting stuff for prelude/PrimOp.lhs
592 # from prelude/primops.txt
594 PRIMOP_BITS=primop-data-decl.hs-incl \
596 primop-list.hs-incl \
597 primop-has-side-effects.hs-incl \
598 primop-out-of-line.hs-incl \
599 primop-commutable.hs-incl \
600 primop-needs-wrapper.hs-incl \
601 primop-can-fail.hs-incl \
602 primop-strictness.hs-incl \
603 primop-primop-info.hs-incl
605 CLEAN_FILES += prelude/primops.txt
606 CLEAN_FILES += $(PRIMOP_BITS)
608 SRC_CPP_OPTS += -I$(GHC_INCLUDE_DIR)
609 SRC_CPP_OPTS += ${GhcCppOpts}
611 ifneq "$(BootingFromHc)" "YES"
612 prelude/PrimOp.lhs $(odir)/prelude/PrimOp.o: $(PRIMOP_BITS)
615 ifneq "$(BootingFromHc)" "YES"
616 depend :: $(PRIMOP_BITS)
619 # This is an ugly hack: we need stage1/$(PLATFORM_H) built before we
620 # preprocess primops.txt.pp, but we don't want to just add that
621 # dependency because we don't want $(PLATFORM_H) built during normal
622 # operations, because we don't have have dependencies from the .hs
623 # sources on it, and we don't want those dependencies because that
624 # would cause everything to be rebuilt every time the Makefile
625 # changed. So here we add the required dependency only when making
627 ifneq "$(findstring boot, $(MAKECMDGOALS))$(findstring depend, $(MAKECMDGOALS))" ""
628 prelude/primops.txt.pp : stage1/$(PLATFORM_H)
631 primop-data-decl.hs-incl: prelude/primops.txt
632 $(GENPRIMOP) --data-decl < $< > $@
633 primop-tag.hs-incl: prelude/primops.txt
634 $(GENPRIMOP) --primop-tag < $< > $@
635 primop-list.hs-incl: prelude/primops.txt
636 $(GENPRIMOP) --primop-list < $< > $@
637 primop-has-side-effects.hs-incl: prelude/primops.txt
638 $(GENPRIMOP) --has-side-effects < $< > $@
639 primop-out-of-line.hs-incl: prelude/primops.txt
640 $(GENPRIMOP) --out-of-line < $< > $@
641 primop-commutable.hs-incl: prelude/primops.txt
642 $(GENPRIMOP) --commutable < $< > $@
643 primop-needs-wrapper.hs-incl: prelude/primops.txt
644 $(GENPRIMOP) --needs-wrapper < $< > $@
645 primop-can-fail.hs-incl: prelude/primops.txt
646 $(GENPRIMOP) --can-fail < $< > $@
647 primop-strictness.hs-incl: prelude/primops.txt
648 $(GENPRIMOP) --strictness < $< > $@
649 primop-primop-info.hs-incl: prelude/primops.txt
650 $(GENPRIMOP) --primop-primop-info < $< > $@
652 # Usages aren't used any more; but the generator
653 # can still generate them if we want them back
654 primop-usage.hs-incl: prelude/primops.txt
655 $(GENPRIMOP) --usage < $< > $@
658 #-----------------------------------------------------------------------------
661 ifeq "$(GhcUnregisterised)" "NO"
662 ifeq "$(HOSTPLATFORM)" "ia64-unknown-linux"
663 # needed for generating proper relocation in large binaries: trac #856
664 SRC_LD_OPTS += -optl-Wl,--relax
668 # -----------------------------------------------------------------------------
669 # create ghc-inplace, a convenient way to run ghc from the build tree...
670 # See comments in $(FPTOOLS_TOP)/utils/ghc-pkg/Makefile for why we use
671 # a real binary here rather than a shell script.
673 INPLACE_SRC = $(odir)/ghc-inplace.c
674 INPLACE_PROG = $(odir)/ghc-inplace$(_way)$(exeext)
675 INPLACE_EXTRA_FLAGS = -I$(TOP)/includes
676 EXCLUDED_C_SRCS += ghc-inplace.c
678 CLEAN_FILES += $(INPLACE_SRC)
680 GHC_PATH=$(FPTOOLS_TOP_ABS)/$(GHC_COMPILER_DIR_REL)/$(GHC_PROG)$(exeext)
682 $(INPLACE_PROG): ghc-inplace.c
683 $(SED) -e "s@GHC_PATH@$(GHC_PATH)@g" -e "s@TOP_ABS@$(FPTOOLS_TOP_ABS)@g" < $< > $(INPLACE_SRC)
684 $(HC) -cpp $(INPLACE_EXTRA_FLAGS) $(INPLACE_SRC) -o $@
686 all :: $(INPLACE_PROG)
688 CLEAN_FILES += $(INPLACE_PROG)
691 ghc-inplace : $(INPLACE_PROG)
692 $(RM) -f $@ && $(LN_S) $< $@
696 CLEAN_FILES += ghc-inplace
699 #-----------------------------------------------------------------------------
702 # We don't want ghc treated as an ordinary executable,
703 # but put it together with the libraries.
704 # Also don't want any interface files installed
706 DESTDIR = $(INSTALL_LIBRARY_DIR_GHC)
708 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
709 INSTALL_LIBEXECS += $(GHC_PROG)
711 INSTALL_PROGS += $(GHC_PROG)
714 # ----------------------------------------------------------------------------
717 # rename/RnBinds_HC_OPTS += -auto-all
718 # rename/RnEnv_HC_OPTS += -auto-all
719 # rename/RnExpr_HC_OPTS += -auto-all
720 # rename/RnHiFiles_HC_OPTS += -auto-all
721 # rename/RnHsSyn_HC_OPTS += -auto-all
722 # rename/Rename_HC_OPTS += -auto-all
723 # rename/RnIfaces_HC_OPTS += -auto-all
724 # rename/RnNames_HC_OPTS += -auto-all
725 # rename/RnSource_HC_OPTS += -auto-all
726 # rename/RnTypes_HC_OPTS += -auto-all
728 # typecheck/Inst_HC_OPTS += -auto-all
729 # typecheck/TcBinds_HC_OPTS += -auto-all
730 # typecheck/TcClassDcl_HC_OPTS += -auto-all
731 # typecheck/TcDefaults_HC_OPTS += -auto-all
732 # typecheck/TcDeriv_HC_OPTS += -auto-all
733 # typecheck/TcEnv_HC_OPTS += -auto-all
734 # typecheck/TcExpr_HC_OPTS += -auto-all
735 # typecheck/TcForeign_HC_OPTS += -auto-all
736 # typecheck/TcGenDeriv_HC_OPTS += -auto-all
737 # typecheck/TcHsSyn_HC_OPTS += -auto-all
738 # typecheck/TcIfaceSig_HC_OPTS += -auto-all
739 # typecheck/TcInstDcls_HC_OPTS += -auto-all
740 # typecheck/TcMatches_HC_OPTS += -auto-all
741 # typecheck/TcMonoType_HC_OPTS += -auto-all
742 # typecheck/TcMType_HC_OPTS += -auto-all
743 # typecheck/TcPat_HC_OPTS += -auto-all
744 # typecheck/TcRnDriver_HC_OPTS += -auto-all
745 # #typecheck/TcRnMonad_HC_OPTS += -auto-all
746 # #typecheck/TcRnTypes_HC_OPTS += -auto-all
747 # typecheck/TcRules_HC_OPTS += -auto-all
748 # typecheck/TcSimplify_HC_OPTS += -auto-all
749 # typecheck/TcSplice_HC_OPTS += -auto-all
750 # typecheck/TcTyClsDecls_HC_OPTS += -auto-all
751 # typecheck/TcTyDecls_HC_OPTS += -auto-all
752 # typecheck/TcType_HC_OPTS += -auto-all
753 # typecheck/TcUnify_HC_OPTS += -auto-all
755 # coreSyn/CorePrep_HC_OPTS += -auto-all
757 #-----------------------------------------------------------------------------
758 # Building the GHC package
760 # The GHC package is made from the stage 2 build and later.
761 # Fortunately the package build system framework more or less does the
762 # right thing for us here.
764 ifneq "$(findstring $(stage), 2 3)" ""
765 BUILD_GHC_PACKAGE=YES
768 ifeq "$(BUILD_GHC_PACKAGE)" "YES"
770 HIERARCHICAL_LIB = NO
771 VERSION = $(ProjectVersion)
772 PKG_DEPENDS += base haskell98
773 LIB_LD_OPTS += $(foreach pkg,$(PKG_DEPENDS),-package $(pkg))
774 # We have to expand each package dependency with its version, which we
775 # can do by calling "ghc-pkg list $pkg --simple-output".
776 PACKAGE_CPP_OPTS += -DPKG_DEPENDS='$(foreach pkg,$(PKG_DEPENDS),$(shell $(GHC_PKG_INPLACE) latest --global $(pkg)))'
777 # We want to define STAGE to be like "2" in the Haskell code, so we need
778 # to quote the "s so that they don't get interpreted by the shell.
779 PACKAGE_CPP_OPTS += -DSTAGE='"$(stage)"'
781 # Omit Main from the library, the client will want to plug their own Main in
782 LIBOBJS = $(filter-out $(odir)/main/Main.$(way_)o $(odir)/parser/hschooks.$(way_)o, $(OBJS))
784 # disable splitting: it won't really help with GHC, and the specialised
785 # build system for compiler/ isn't set up to handle it.
788 # the package build system likes to set WAYS=$(GhcLibWays), but we don't
789 # really want to build the whole of GHC multiple ways... if you do,
790 # set GhcCompilerWays instead.
791 GhcLibWays = $(GhcCompilerWays)
793 # override $(GhcLibHcOpts): we want GhcStage2HcOpts to take precedence
796 ifeq "$(DOING_BIN_DIST)" "YES"
797 # This is derived from the sources when we are in a source tree, but we
798 # don't have any sources in a bindist, so we have to shortcut it
799 HS_IFACES := $(wildcard stage$(stage)/*/*.hi)
801 # override default definition of HS_IFACES so we can add $(odir)
802 HS_IFACES = $(addsuffix .$(way_)hi,$(basename $(HS_OBJS)))
805 # Haddock can't handle recursive modules currently, so we disable it for now.
806 override HADDOCK_DOCS = NO
808 # Tell package.mk not to set $(HC)
811 # The stage 2 GHC binary itself is built by compiling main/Main.hs
812 # (the same as used in stage 1) against the GHC package.
814 # This is done by compiling Main.hs separately and linking it with
815 # -package ghc. This is done using a separate Makefile, Makefile.ghcbin
816 # Why? See comments in Makefile.ghcbin
818 # The stage 2 and stage 3 package.conf.in files are different, because they
819 # point to either the stage2/ or stage3/ dirs in import-dirs. Hence before
820 # linking the ghc binary we must install the correct version of the package
821 # configuration. Yeuch... maybe one day this will all be done more cleanly.
822 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
824 # Propagate standard targets to Makefile.ghcbin
825 docs runtests $(BOOT_TARGET) TAGS clean distclean mostlyclean maintainer-clean $(INSTALL_TARGET) $(INSTALL_DOCS_TARGET) html chm HxS ps dvi txt::
826 $(MAKE) -f Makefile.ghcbin $(MFLAGS) $@
829 #-----------------------------------------------------------------------------
832 MAINTAINER_CLEAN_FILES += parser/Parser.info main/ParsePkgConf.info
834 #-----------------------------------------------------------------------------
835 # Include target-rule boilerplate
837 # Don't use the default MKDEPENDHS stuff... we'll do our own, below
841 # Make doesn't work this out for itself, it seems
842 parser/Parser.y : parser/Parser.y.pp
843 EXTRA_SRCS += parser/Parser.y
846 #-----------------------------------------------------------------------------
847 # Source files for tags file generation
849 # We want to excluded derived sources, because they won't be in the source
850 # tree, which is where we are going to move the TAGS file to.a
852 TAGS_HS_SRCS = parser/Parser.y.pp $(filter-out $(DERIVED_SRCS) main/Config.hs parser/Parser.y, $(sort $(SRCS)))
854 WRONG_GHCTAGS_HS_SRCS = $(filter-out $(DERIVED_SRCS) main/Config.hs parser/Parser.y, $(sort $(SRCS)))
855 # above is wrong because of the following problem:
856 # module `main:DataCon' is defined in multiple files: basicTypes/DataCon.lhs
857 # basicTypes/DataCon.lhs-boot
859 GHCTAGS_HS_SRCS = $(HS_SRCS)
860 GHCTAGS_HC_OPTS = $(patsubst -i$(odir)/%, -i%, $(HC_OPTS))
861 GHCTAGS_HC_OPTS += -DSTAGE='"$(stage)"'
863 #------------------------------------------------------------
868 ghctags :: $(GHCTAGS_HS_SRCS) $(TAGS_C_SRCS)
869 @if [ "$(stage)" != 2 ]; then echo "Must use 'make stage=2 ghctags'"; exit 1; fi
872 @echo SOURCES ARE "$(GHCTAGS_HS_SRCS)"
873 : ifneq "$(GHCTAGS_HS_SRCS)" ""
874 @echo TIME TO ROCK AND ROLL
875 # $(GHCTAGS_INPLACE) -- $(MKDEPENDHS_OPTS) $(filter-out -split-objs, $(MKDEPENDHS_HC_OPTS)) -- $(GHCTAGS_HS_SRCS)
876 $(GHCTAGS_INPLACE) -- $(GHCTAGS_HC_OPTS) -- $(GHCTAGS_HS_SRCS)
878 ifneq "$(TAGS_C_SRCS)" ""
879 etags -a $(TAGS_C_SRCS)
881 @( DEREFFED=`ls -l Makefile | sed -e 's/.*-> \(.*\)/\1/g'` && $(RM) `dirname $$DEREFFED`/TAGS && $(CP) TAGS `dirname $$DEREFFED` ) 2>/dev/null || echo TAGS file generated, perhaps copy over to source tree?
883 include $(TOP)/mk/target.mk
885 ifeq "$(BUILD_GHC_PACKAGE)" "YES"
889 $(odir)/main/Config.$(way_)o: SRC_HC_OPTS+=-DSTAGE='"$(stage)"'
891 ifneq "$(findstring $(stage), 2 3)" ""
892 $(warning LIBRARY is $(LIBRARY))
894 ifneq "$(DOING_BIN_DIST)" "YES"
895 $(GHC_PROG) : $(LIBRARY) main/Main.hs
896 $(RM) package.conf.inplace
897 $(RM) $(STAMP_PKG_CONF)
898 $(MAKE) way="" $(STAMP_PKG_CONF)
899 $(MAKE) -f Makefile.ghcbin $(MFLAGS) HS_PROG=$(GHC_PROG) $@
904 #-----------------------------------------------------------------------------
908 $(INSTALL_DIR) $(BIN_DIST_DIR)/compiler
909 $(INSTALL_DIR) $(BIN_DIST_DIR)/compiler/stage$(stage)
910 echo "stage=$(stage)" > $(BIN_DIST_DIR)/compiler/Makefile
911 cat Makefile >> $(BIN_DIST_DIR)/compiler/Makefile
912 $(INSTALL_DATA) package.conf.in $(BIN_DIST_DIR)/compiler/
913 set -e; for d in stage$(stage)/*/; do $(INSTALL_DIR) $(BIN_DIST_DIR)/compiler/$$d; done
914 set -e; for f in $(HS_IFACES); do $(INSTALL_DATA) $$f $(BIN_DIST_DIR)/compiler/$$f; done
915 ifneq "$(INSTALL_LIBS)" ""
916 set -e; for f in $(INSTALL_LIBS); do $(INSTALL_DATA) $$f $(BIN_DIST_DIR)/compiler/$$f; done
918 ifneq "$(INSTALL_PROGS)" ""
919 set -e; for f in $(INSTALL_PROGS); do $(INSTALL_PROGRAM) $$f $(BIN_DIST_DIR)/compiler/$$f; done
921 ifneq "$(INSTALL_LIBEXECS)" ""
922 set -e; for f in $(INSTALL_LIBEXECS); do $(INSTALL_PROGRAM) $$f $(BIN_DIST_DIR)/compiler/$$f; done
925 # -----------------------------------------------------------------------------
926 # Explicit dependencies
928 # Some .hs files #include other source files, but since ghc -M doesn't spit out
929 # these dependencies we have to include them manually.
931 # We don't add dependencies on HsVersions.h, ghcautoconf.h, or ghc_boot_platform.h,
932 # because then modifying one of these files would force recompilation of everything,
933 # which is probably not what you want. However, it does mean you have to be
934 # careful to recompile stuff you need if you reconfigure or change HsVersions.h.
936 # Aargh, these don't work properly anyway, because GHC's recompilation checker
937 # just reports "compilation NOT required". Do we have to add -fforce-recomp for each
938 # of these .hs files? I haven't done anything about this yet.
940 $(odir)/codeGen/Bitmap.$(way_)o : ../includes/MachDeps.h
941 $(odir)/codeGen/CgCallConv.$(way_)o : ../includes/StgFun.h
942 $(odir)/codeGen/CgProf.$(way_)o : ../includes/MachDeps.h
943 $(odir)/codeGen/CgProf.$(way_)o : ../includes/Constants.h
944 $(odir)/codeGen/CgProf.$(way_)o : ../includes/DerivedConstants.h
945 $(odir)/codeGen/CgTicky.$(way_)o : ../includes/DerivedConstants.h
946 $(odir)/codeGen/ClosureInfo.$(way_)o : ../includes/MachDeps.h
947 $(odir)/codeGen/SMRep.$(way_)o : ../includes/MachDeps.h
948 $(odir)/codeGen/SMRep.$(way_)o : ../includes/ClosureTypes.h
949 $(odir)/ghci/ByteCodeAsm.$(way_)o : ../includes/Bytecodes.h
950 $(odir)/ghci/ByteCodeFFI.$(way_)o : nativeGen/NCG.h
951 $(odir)/ghci/ByteCodeInstr.$(way_)o : ../includes/MachDeps.h
952 $(odir)/ghci/ByteCodeItbls.$(way_)o : ../includes/ClosureTypes.h
953 $(odir)/ghci/ByteCodeItbls.$(way_)o : nativeGen/NCG.h
954 $(odir)/main/Constants.$(way_)o : ../includes/MachRegs.h
955 $(odir)/main/Constants.$(way_)o : ../includes/Constants.h
956 $(odir)/main/Constants.$(way_)o : ../includes/MachDeps.h
957 $(odir)/main/Constants.$(way_)o : ../includes/DerivedConstants.h
958 $(odir)/main/Constants.$(way_)o : ../includes/GHCConstants.h
959 $(odir)/nativeGen/AsmCodeGen.$(way_)o : nativeGen/NCG.h
960 $(odir)/nativeGen/MachCodeGen.$(way_)o : nativeGen/NCG.h
961 $(odir)/nativeGen/MachCodeGen.$(way_)o : ../includes/MachDeps.h
962 $(odir)/nativeGen/MachInstrs.$(way_)o : nativeGen/NCG.h
963 $(odir)/nativeGen/MachRegs.$(way_)o : nativeGen/NCG.h
964 $(odir)/nativeGen/MachRegs.$(way_)o : ../includes/MachRegs.h
965 $(odir)/nativeGen/PositionIndependentCode.$(way_)o : nativeGen/NCG.h
966 $(odir)/nativeGen/PprMach.$(way_)o : nativeGen/NCG.h
967 $(odir)/nativeGen/RegAllocInfo.$(way_)o : nativeGen/NCG.h
968 $(odir)/typecheck/TcForeign.$(way_)o : nativeGen/NCG.h
969 $(odir)/utils/Binary.$(way_)o : ../includes/MachDeps.h
970 $(odir)/utils/FastMutInt.$(way_)o : ../includes/MachDeps.h
972 # -----------------------------------------------------------------------------
975 MKDEPENDHS_HC_OPTS = $(patsubst -i$(odir)/%, -i%, $(HC_OPTS))
979 # Must do this *after* including target.mk, because $(HS_SRCS) isn't set yet.
980 depend :: $(STAGE_PLATFORM_H) $(HS_SRCS) $(C_SRCS)
982 ifneq "$(BootingFromHc)" "YES"
983 $(MKDEPENDHS) -M -optdep-f -optdep.depend-BASE $(foreach way,$(WAYS),-optdep-s -optdep$(way)) $(foreach obj,$(MKDEPENDHS_OBJ_SUFFICES),-osuf $(obj)) $(MKDEPENDHS_OPTS) $(filter-out -split-objs, $(MKDEPENDHS_HC_OPTS)) $(HS_SRCS)
985 $(MKDEPENDC) -f .depend-BASE $(MKDEPENDC_OPTS) $(foreach way,$(WAYS),-s $(way)) -- $(CC_OPTS) -- $(C_SRCS)
986 $(PERL) -pe 'binmode(stdin); binmode(stdout); s@(\S*[._]o)@stage$(stage)/$$1@g; s@(\S*[._]hi)@stage$(stage)/$$1@g;' <.depend-BASE >.depend-$(stage)
987 # The binmode stuff tells perl not to add stupid ^M's to the output
989 ifeq "$(MakefileDeps)" "YES"
990 $(CONFIG_HS) : Makefile
991 stage1/$(PLATFORM_H) : Makefile
992 stage2/$(PLATFORM_H) : Makefile
995 -include .depend-$(stage)