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 include $(TOP)/mk/boilerplate.mk
26 ifeq "$(GhcThreaded)$(GhcProfiled)" "YESYES"
27 $(error Cannot make GHC both threaded and profiled)
31 #-----------------------------------------------------------------------------
32 # Counting source code lines
34 USER_SRCS = $(filter-out $(DERIVED_SRCS),$(SRCS))
36 ./count_lines $(USER_SRCS)
38 # -----------------------------------------------------------------------------
41 # The stage1/stage2/stage3 business is quite delicate. Here's how it works:
43 # - the variable $(stage) holds the current stage number. To build a
44 # particular stage, you say 'make stage=N' where N is 1, 2, or 3.
47 # - for stage N, object files and .hi files are placed inside
48 # the directory stageN, in subdirectories as per the sources.
50 # - .hi-boot files are *linked* into the stageN tree, because in GHC 5.05+
51 # the .hi-boot file must reside in the same place as the .hi file.
53 # - we use explicit -o and -ohi options to direct the output from C &
54 # Haskell compilations.
56 # - we generate a different .depend file for each build. They need to be
57 # different, because each stage might include different files: stage1
58 # might not include GHCi, for example. For each stage, a normal .depend
59 # file is generated, and then post-processed to add the correct stageN/
60 # prefix to each object and .hi filename. The resulting .depend file
61 # is named .depend-$(stage). See the end of this Makefile for details.
63 # - normal implicit rules don't work any more, because they're of the form
67 # whereas we really need
71 # so suffix.mk now defines the appropriate suffix rules when
72 # $(odir) is set to a non-empty value. Here we set $(odir) to
73 # stage1, stage2, or stage3.
75 # There are other plausible designs that might work, but each has different
78 # - using -odir and -hidir: GHC <= 4.08 doesn't support -hidir, and
79 # anyway -odir puts all the objects in one directory (strips off the
80 # subdirectory part), which eventually forces us to use VPATH to find
81 # the sources. I have a really bad feeling about VPATH.
83 # - invoke make in the stageN subdirectory. This probably requires VPATH
86 # - create a link tree. The problem with requiring link trees is that
87 # Windows doesn't support symbolic links.
93 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
105 $(MKDIRHIER) stage$(stage)
106 for i in $(ALL_DIRS); do \
107 $(MKDIRHIER) stage$(stage)/$$i; \
110 ifeq "$(stage) $(ghc_ge_603)" "1 YES"
113 ifneq "$(findstring $(stage), 2 3)" ""
121 # On Windows, we can't use symbolic links for the -hi-boot files
122 # because GHC itself is a Mingw program and does not understand
123 # symbolic links. So we have to copy the files instead of link them.
124 # That means that if you modify a .hi-boot file in Windows, you
125 # have to to say 'make boot' again.
127 # PS: 'ln -s foo baz' takes 'foo' relative to the path to 'baz'
128 # whereas 'cp foo baz' treats the two paths independently.
129 # Hence the "../.." in the ln command line
130 ifeq "$(UsingHsBoot)" "NO"
131 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
132 for i in */*hi-boot*; do \
133 cp -u -f $$i stage$(stage)/$$i; \
136 for i in */*hi-boot*; do \
137 ($(RM) -f stage$(stage)/$$i \
138 && $(LN_S) ../../$$i stage$(stage)/$$i) || true ; \
166 SRC_HC_OPTS += $(patsubst %, -i$(odir)/%, $(ALL_DIRS))
169 SRC_HC_OPTS += -Wall -fno-warn-name-shadowing
172 HS_OBJS = $(patsubst %, $(odir)/%, $(addsuffix .$(way_)o,$(basename $(HS_SRCS))))
173 C_OBJS = $(patsubst %, $(odir)/%, $(addsuffix .$(way_)o,$(basename $(C_SRCS))))
175 # Our standard cleaning rules don't know that we're doing our output
176 # into $(odir), so we have to augment CLEAN_FILES appropriateliy.
178 CLEAN_FILES += $(odir)/*/*.hi $(odir)/*/*.hi-boot $(odir)/*/*.o-boot
180 ifeq "$(UsingHsBoot)" "YES"
181 CLEAN_FILES += $(odir)/*/*.hi-boot $(odir)/*/*.o-boot
185 mostlyclean clean distclean maintainer-clean ::
190 # -----------------------------------------------------------------------------
193 # Note: there have been reports of people running up against the ARG_MAX limit
194 # when linking ghc with all its constituent object files. The likely source of
195 # the problem is that the environment is a bit too big, so a workaround could
196 # be to do `env PATH=$(PATH) make ghc' to minimise the environment. (or the
197 # equivalent of `env' if it doesn't exist locally).
200 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
201 GHC_PROG=$(odir)/ghc$(_way)-$(ProjectVersion)
203 GHC_PROG=$(odir)/ghc$(_way)
206 GHC_PROG=$(odir)/ghc-$(ProjectVersion)
210 HS_PROG = $(GHC_PROG)
213 # -----------------------------------------------------------------------------
214 # Create compiler configuration
216 # The 'echo' commands simply spit the values of various make variables
217 # into Config.hs, whence they can be compiled and used by GHC itself
219 CONFIG_HS = main/Config.hs
222 $(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk
223 @$(RM) -f $(CONFIG_HS)
224 @echo "Creating $(CONFIG_HS) ... "
225 @echo "{-# OPTIONS_GHC -w #-}" >>$(CONFIG_HS)
226 @echo "module Config where" >>$(CONFIG_HS)
227 @echo "cProjectName = \"$(ProjectName)\"" >> $(CONFIG_HS)
228 @echo "cProjectVersion = \"$(ProjectVersion)\"" >> $(CONFIG_HS)
229 @echo "cProjectVersionInt = \"$(ProjectVersionInt)\"" >> $(CONFIG_HS)
230 @echo "cProjectPatchLevel = \"$(ProjectPatchLevel)\"" >> $(CONFIG_HS)
231 @echo "cBooterVersion = \"$(GhcVersion)\"" >> $(CONFIG_HS)
232 @echo "cStage = STAGE" >> $(CONFIG_HS)
233 @echo "cHscIfaceFileVersion = \"$(HscIfaceFileVersion)\"" >> $(CONFIG_HS)
234 @echo "cSplitObjs = \"$(SplitObjs)\"" >> $(CONFIG_HS)
235 @echo "cGhcWithInterpreter = \"$(GhcWithInterpreter)\"" >> $(CONFIG_HS)
236 @echo "cGhcWithNativeCodeGen = \"$(GhcWithNativeCodeGen)\"" >> $(CONFIG_HS)
237 @echo "cGhcWithSMP = \"$(GhcWithSMP)\"" >> $(CONFIG_HS)
238 @echo "cGhcRTSWays = \"$(GhcRTSWays)\"" >> $(CONFIG_HS)
239 @echo "cGhcUnregisterised = \"$(GhcUnregisterised)\"" >> $(CONFIG_HS)
240 @echo "cGhcEnableTablesNextToCode = \"$(GhcEnableTablesNextToCode)\"" >> $(CONFIG_HS)
241 @echo "cLeadingUnderscore = \"$(LeadingUnderscore)\"" >> $(CONFIG_HS)
242 @echo "cRAWCPP_FLAGS = \"$(RAWCPP_FLAGS)\"" >> $(CONFIG_HS)
243 @echo "cGCC = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
244 @echo "cMKDLL = \"$(BLD_DLL)\"" >> $(CONFIG_HS)
245 @echo "cLdIsGNULd = \"$(LdIsGNULd)\"" >> $(CONFIG_HS)
246 @echo "cLD_X = \"$(LD_X)\"" >> $(CONFIG_HS)
247 @echo "cPROJECT_DIR = \"$(PROJECT_DIR)\"" >> $(CONFIG_HS)
248 @echo "cGHC_DRIVER_DIR_REL = \"$(GHC_DRIVER_DIR_REL)\"" >> $(CONFIG_HS)
249 @echo "cGHC_TOUCHY_PGM = \"$(GHC_TOUCHY_PGM)\"" >> $(CONFIG_HS)
250 @echo "cGHC_TOUCHY_DIR_REL = \"$(GHC_TOUCHY_DIR_REL)\"" >> $(CONFIG_HS)
251 @echo "cGHC_UNLIT_PGM = \"$(GHC_UNLIT_PGM)\"" >> $(CONFIG_HS)
252 @echo "cGHC_UNLIT_DIR_REL = \"$(GHC_UNLIT_DIR_REL)\"" >> $(CONFIG_HS)
253 @echo "cGHC_MANGLER_PGM = \"$(GHC_MANGLER_PGM)\"" >> $(CONFIG_HS)
254 @echo "cGHC_MANGLER_DIR_REL = \"$(GHC_MANGLER_DIR_REL)\"" >> $(CONFIG_HS)
255 @echo "cGHC_SPLIT_PGM = \"$(GHC_SPLIT_PGM)\"" >> $(CONFIG_HS)
256 @echo "cGHC_SPLIT_DIR_REL = \"$(GHC_SPLIT_DIR_REL)\"" >> $(CONFIG_HS)
257 @echo "cGHC_SYSMAN_PGM = \"$(GHC_SYSMAN)\"" >> $(CONFIG_HS)
258 @echo "cGHC_SYSMAN_DIR_REL = \"$(GHC_SYSMAN_DIR)\"" >> $(CONFIG_HS)
259 @echo "cGHC_CP = \"$(GHC_CP)\"" >> $(CONFIG_HS)
260 @echo "cGHC_PERL = \"$(GHC_PERL)\"" >> $(CONFIG_HS)
261 ifeq ($(GhcWithIlx),YES)
262 @echo "cILX2IL = \"$(ILX2IL)\"" >> $(CONFIG_HS)
263 @echo "cILASM = \"$(ILASM)\"" >> $(CONFIG_HS)
265 @echo "cEnableWin32DLLs = \"$(EnableWin32DLLs)\"" >> $(CONFIG_HS)
266 @echo "cCONTEXT_DIFF = \"$(CONTEXT_DIFF)\"" >> $(CONFIG_HS)
267 @echo "cUSER_WAY_NAMES = \"$(USER_WAY_NAMES)\"" >> $(CONFIG_HS)
268 @echo "cUSER_WAY_OPTS = \"$(USER_WAY_OPTS)\"" >> $(CONFIG_HS)
269 @echo "cDEFAULT_TMPDIR = \"$(DEFAULT_TMPDIR)\"" >> $(CONFIG_HS)
270 @echo "cDocDir = \"$(docdir)\"" >> $(CONFIG_HS)
273 CLEAN_FILES += $(CONFIG_HS)
275 # -----------------------------------------------------------------------------
276 # Create platform includes
278 # Here we generate a little header file containing CPP symbols that GHC
279 # uses to determine which platform it is building on/for. The platforms
280 # can differ between stage1 and stage2 if we're cross-compiling, so we
281 # need one of these header files per stage.
283 PLATFORM_H = ghc_boot_platform.h
285 stage1/$(PLATFORM_H) : stage_dirs $(FPTOOLS_TOP)/mk/config.mk
286 @echo "Creating $@..."
288 @echo "#ifndef __PLATFORM_H__" >$@
289 @echo "#define __PLATFORM_H__" >>$@
291 @echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
292 @echo "#define HostPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
293 @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
295 @echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
296 @echo "#define $(HostPlatform_CPP)_HOST 1" >> $@
297 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
299 @echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
300 @echo "#define $(HostArch_CPP)_HOST_ARCH 1" >> $@
301 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
302 @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
303 @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
304 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
306 @echo "#define $(BuildOS_CPP)_BUILD_OS 1" >> $@
307 @echo "#define $(HostOS_CPP)_HOST_OS 1" >> $@
308 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
309 @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
310 @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
311 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
312 ifeq "$(HostOS_CPP)" "irix"
313 @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS " >> $@
314 @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
315 @echo "#endif " >> $@
318 @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
319 @echo "#define $(HostVendor_CPP)_HOST_VENDOR 1" >> $@
320 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
321 @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
322 @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
323 @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
325 @echo "#endif /* __PLATFORM_H__ */" >> $@
328 # For stage2 and above, the BUILD platform is the HOST of stage1, and
329 # the HOST platform is the TARGET of stage1. The TARGET remains the same
330 # (stage1 is the cross-compiler, not stage2).
331 stage2/$(PLATFORM_H) : stage_dirs $(FPTOOLS_TOP)/mk/config.mk
332 @echo "Creating $@..."
334 @echo "#ifndef __PLATFORM_H__" >$@
335 @echo "#define __PLATFORM_H__" >>$@
337 @echo "#define BuildPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
338 @echo "#define HostPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
339 @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
341 @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
342 @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
343 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
345 @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
346 @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
347 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
348 @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
349 @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
350 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
352 @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
353 @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
354 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
355 @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
356 @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
357 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
358 ifeq "$(HostOS_CPP)" "irix"
359 @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS " >> $@
360 @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
361 @echo "#endif " >> $@
364 @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
365 @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
366 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
367 @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
368 @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
369 @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
371 @echo "#endif /* __PLATFORM_H__ */" >> $@
374 stage3/$(PLATFORM_H) : stage_dirs stage2/$(PLATFORM_H)
375 $(CP) stage2/$(PLATFORM_H) stage3/$(PLATFORM_H)
377 STAGE_PLATFORM_H = stage$(stage)/$(PLATFORM_H)
379 boot :: $(STAGE_PLATFORM_H)
381 SRC_HC_OPTS += -Istage$(stage)
383 # -----------------------------------------------------------------------------
386 # First figure out ALL_DIRS, the source sub-directories
389 utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
390 vectorise specialise simplCore stranal stgSyn simplStg codeGen main \
391 profiling parser cprAnalysis ndpFlatten iface cmm
393 # Make sure we include Config.hs even if it doesn't exist yet...
394 ALL_SRCS += $(CONFIG_HS)
396 # HsGeneric.hs is not used just now
397 EXCLUDED_SRCS += hsSyn/HsGeneric.hs
399 ifeq ($(GhcWithNativeCodeGen),YES)
400 ALL_DIRS += nativeGen
402 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
405 ifeq ($(GhcWithIlx),YES)
410 ifeq ($(GhcWithJavaGen),YES)
412 SRC_HC_OPTS += -DJAVA
415 ifeq "$(BootingFromHc)" "YES"
416 # HC files are always from a self-booted compiler
419 ifneq "$(findstring $(stage), 2 3)" ""
426 # -----------------------------------------------------------------------------
427 # Building a compiler with interpreter support
429 # The interpreter, GHCi interface, Template Haskell and Hpc are only
430 # enabled when we are bootstrapping with the same version of GHC, and
431 # the interpreter is supported on this platform.
433 ifeq "$(bootstrapped)" "YES"
434 SRC_HC_OPTS += -package hpc -package bytestring
435 PKG_DEPENDS += hpc bytestring
438 ifeq "$(GhcWithInterpreter) $(bootstrapped)" "YES YES"
440 # Yes, include the interepreter, readline, and Template Haskell extensions
441 SRC_HC_OPTS += -DGHCI -package template-haskell
442 PKG_DEPENDS += template-haskell
444 # Should GHCI be building info tables in the TABLES_NEXT_TO_CODE style
446 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
447 SRC_HC_OPTS += -DGHCI_TABLES_NEXT_TO_CODE
450 ifeq "$(GhcThreaded)" "YES"
451 # Use threaded RTS with GHCi, so threads don't get blocked at the prompt.
452 SRC_LD_OPTS += -threaded
454 ifeq "$(GhcProfiled)" "YES"
457 ifeq "$(GhcDebugged)" "YES"
458 SRC_LD_OPTS += -debug
463 # If we are going to use dynamic libraries instead of .o files for ghci,
464 # we will need to always retain CAFs in the compiler.
465 # ghci/keepCAFsForGHCi contains a GNU C __attribute__((constructor))
466 # function which sets the keepCAFs flag for the RTS before any Haskell
468 ifeq "$(GhcBuildDylibs)" "YES"
470 EXCLUDED_SRCS += ghci/keepCAFsForGHCi.c
473 # Enable readline if either:
474 # - we're building stage 1 and $(GhcHasReadline)="YES"
475 # - we're building stage 2/3, and we have built the readline package
477 # But we don't enable readline on Windows, because readline is fairly
480 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
482 ifeq "$(GhcHasReadline)" "YES"
483 SRC_HC_OPTS += -package readline -DUSE_READLINE
484 PKG_DEPENDS += readline
487 -include $(FPTOOLS_TOP)/libraries/readline/config.mk
488 # readline's config.mk sets PACKAGE, which we don't want here
490 ifeq "$(READLINE_BUILD_PACKAGE)" "yes"
491 SRC_HC_OPTS += -package readline -DUSE_READLINE
492 PKG_DEPENDS += readline
499 # No interpreter, so exclude Template Haskell modules
500 EXCLUDED_SRCS += deSugar/DsMeta.hs typecheck/TcSplice.lhs hsSyn/Convert.lhs
502 endif # bootstrapped with interpreter
504 # -----------------------------------------------
507 # Big Fudge to get around inherent problem that Makefile setup
508 # has got with 'mkdependC'.
510 SRC_MKDEPENDC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
512 # XXX not really correct, hschooks.c actually gets include files like
513 # RtsFlags.c from the installed GHC, but we can't tell mkdependC about that.
514 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
516 # -----------------------------------------------------------------------------
517 # Haskell compilations
520 -cpp -fglasgow-exts -fno-generics -Rghc-timing \
523 # Omitted: -I$(GHC_INCLUDE_DIR)
524 # We should have -I$(GHC_INCLUDE_DIR) in SRC_HC_OPTS,
525 # to avoid the use of an explicit path in GHC source files
526 # (include "../includes/config.h"
527 # But alas GHC 4.08 (and others for all I know) uses this very
528 # same include path when compiling the .hc files it generates.
529 # Disaster! Then the hc file sees the GHC 5.02 (or whatever)
530 # include files. For the moment we've reverted to using
531 # an explicit path in the .hs sources
533 # For the benefit of <5.00 compilers, do include GHC_INCLUDE_DIR
534 # when generating dependencies. (=> it gets passed onto mkdependHS,
536 SRC_MKDEPENDHS_OPTS += -I$(GHC_INCLUDE_DIR)
538 # We need System.Posix (or Posix when ghc < 6.2)
539 ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
540 ifeq "$(bootstrapped)" "YES"
541 SRC_HC_OPTS += -package Win32
545 ifeq "$(bootstrapped) $(ghc_ge_601)" "NO NO"
546 SRC_HC_OPTS += -package posix
548 SRC_HC_OPTS += -package unix
553 # We use the Cabal package in stages 2/3 only; in stage 1 we're using
554 # the libcompat library which provides the Cabal modules.
556 SRC_HC_OPTS += -package Cabal
560 ifeq "$(ghc_ge_603)" "YES"
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
567 SRC_CC_OPTS += -Iparser -I. -O
568 SRC_HC_OPTS += -recomp $(GhcHcOpts) $(GhcStage$(stage)HcOpts)
571 ifeq "$(BootingFromHc)" "YES"
572 SRC_CC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
575 # Special flags for particular modules
576 # The standard suffix rule for compiling a Haskell file
577 # adds these flags to the command line
579 # There used to be a -no-recomp flag on PrimOp, but why?
580 # It's an expensive module to recompile!
581 prelude/PrimOp_HC_OPTS = -H80m
584 main/ParsePkgConf_HC_OPTS += -fno-warn-incomplete-patterns
585 parser/Parser_HC_OPTS += -fno-warn-incomplete-patterns
587 ifeq "$(ghc_ge_603)" "NO"
588 # Use -fvia-C since the NCG can't handle the narrow16Int# (and intToInt16#?)
589 # primops on all platforms.
590 parser/Parser_HC_OPTS += -fvia-C
591 # because the NCG can't handle the 64-bit math in here
592 prelude/PrelRules_HC_OPTS += -fvia-C
593 # ByteCodeItbls uses primops that the NCG doesn't support.
594 ghci/ByteCodeItbls_HC_OPTS += -fvia-C
595 ghci/ByteCodeLink_HC_OPTS += -fvia-C -monly-3-regs
598 # Careful optimisation of the parser: we don't want to throw everything
599 # at it, because that takes too long and doesn't buy much, but we do want
600 # to inline certain key external functions, so we instruct GHC not to
601 # throw away inlinings as it would normally do in -Onot mode:
602 parser/Parser_HC_OPTS += -Onot -fno-ignore-interface-pragmas
604 ifeq "$(HOSTPLATFORM)" "hppa1.1-hp-hpux9"
605 rename/RnMonad_HC_OPTS = -O2 -O2-for-C
608 utils/Digraph_HC_OPTS = -fglasgow-exts
610 basicTypes/SrcLoc_HC_OPTS = -funbox-strict-fields
612 # We always optimise some low-level modules, otherwise performance of
613 # a non-optimised compiler is severely affected.
614 main/BinIface_HC_OPTS += -O
615 utils/Binary_HC_OPTS += -O -funbox-strict-fields
616 utils/FastMutInt_HC_OPTS += -O
617 utils/Encoding_HC_OPTS += -O
618 utils/StringBuffer_HC_OPTS += -O -funbox-strict-fields
619 utils/FastString_HC_OPTS += -O -funbox-strict-fields
621 # ---- Profiling ----
622 #simplCore/Simplify_HC_OPTS = -auto-all
623 #simplCore/SimplEnv_HC_OPTS = -auto-all
624 #simplCore/SimplUtils_HC_OPTS = -auto-all
626 # CSE interacts badly with top-level IORefs (reportedly in DriverState and
627 # DriverMkDepend), causing some of them to be commoned up. We have a fix for
628 # this in 5.00+, but earlier versions of the compiler will need CSE turned off.
629 # To be on the safe side, we disable CSE in *all* modules with top-level IORefs.
630 ghci/InteractiveUI_HC_OPTS = -fno-cse
631 main/CmdLineOpts_HC_OPTS = -fno-cse
632 main/DriverMkDepend_HC_OPTS = -fno-cse
633 main/DriverPipeline_HC_OPTS = -fno-cse
634 main/Finder_HC_OPTS = -fno-cse
635 main/SysTools_HC_OPTS = -fno-cse
636 main/StaticFlags_HC_OPTS = -fno-cse
638 # The #include is vital for the via-C route, else the C
639 # compiler doesn't realise that the stcall foreign imports are indeed
640 # stdcall, and doesn't generate the Foo@8 name for them
641 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
642 main/SysTools_HC_OPTS += '-\#include <windows.h>' '-\#include <process.h>'
645 parser/Lexer_HC_OPTS += -funbox-strict-fields
647 # ghc_strlen percolates through so many modules that it is easier to get its
648 # prototype via a global option instead of a myriad of per-file OPTIONS
649 SRC_HC_OPTS += '-\#include "cutils.h"'
651 # ----------------------------------------------------------------------------
652 # Generate supporting stuff for prelude/PrimOp.lhs
653 # from prelude/primops.txt
655 PRIMOP_BITS=primop-data-decl.hs-incl \
657 primop-list.hs-incl \
658 primop-has-side-effects.hs-incl \
659 primop-out-of-line.hs-incl \
660 primop-commutable.hs-incl \
661 primop-needs-wrapper.hs-incl \
662 primop-can-fail.hs-incl \
663 primop-strictness.hs-incl \
664 primop-primop-info.hs-incl
666 CLEAN_FILES += prelude/primops.txt
667 CLEAN_FILES += $(PRIMOP_BITS)
669 SRC_CPP_OPTS += -I$(GHC_INCLUDE_DIR)
670 SRC_CPP_OPTS += ${GhcCppOpts}
672 ifneq "$(BootingFromHc)" "YES"
673 prelude/PrimOp.lhs $(odir)/prelude/PrimOp.o: $(PRIMOP_BITS)
676 ifneq "$(BootingFromHc)" "YES"
677 depend :: $(PRIMOP_BITS)
680 # This is an ugly hack: we need stage1/$(PLATFORM_H) built before we
681 # preprocess primops.txt.pp, but we don't want to just add that
682 # dependency because we don't want $(PLATFORM_H) built during normal
683 # operations, because we don't have have dependencies from the .hs
684 # sources on it, and we don't want those dependencies because that
685 # would cause everything to be rebuilt every time the Makefile
686 # changed. So here we add the required dependency only when making
688 ifneq "$(findstring boot, $(MAKECMDGOALS))$(findstring depend, $(MAKECMDGOALS))" ""
689 prelude/primops.txt.pp : stage1/$(PLATFORM_H)
692 primop-data-decl.hs-incl: prelude/primops.txt
693 $(GENPRIMOP) --data-decl < $< > $@
694 primop-tag.hs-incl: prelude/primops.txt
695 $(GENPRIMOP) --primop-tag < $< > $@
696 primop-list.hs-incl: prelude/primops.txt
697 $(GENPRIMOP) --primop-list < $< > $@
698 primop-has-side-effects.hs-incl: prelude/primops.txt
699 $(GENPRIMOP) --has-side-effects < $< > $@
700 primop-out-of-line.hs-incl: prelude/primops.txt
701 $(GENPRIMOP) --out-of-line < $< > $@
702 primop-commutable.hs-incl: prelude/primops.txt
703 $(GENPRIMOP) --commutable < $< > $@
704 primop-needs-wrapper.hs-incl: prelude/primops.txt
705 $(GENPRIMOP) --needs-wrapper < $< > $@
706 primop-can-fail.hs-incl: prelude/primops.txt
707 $(GENPRIMOP) --can-fail < $< > $@
708 primop-strictness.hs-incl: prelude/primops.txt
709 $(GENPRIMOP) --strictness < $< > $@
710 primop-primop-info.hs-incl: prelude/primops.txt
711 $(GENPRIMOP) --primop-primop-info < $< > $@
713 # Usages aren't used any more; but the generator
714 # can still generate them if we want them back
715 primop-usage.hs-incl: prelude/primops.txt
716 $(GENPRIMOP) --usage < $< > $@
719 #-----------------------------------------------------------------------------
722 # Include libghccompat in stage1 only. In stage2 onwards, all these
723 # libraries will be available from the main libraries.
726 include $(GHC_COMPAT_DIR)/compat.mk
729 SRC_LD_OPTS += -no-link-chk
731 # -----------------------------------------------------------------------------
732 # create ghc-inplace, a convenient way to run ghc from the build tree...
733 # See comments in $(FPTOOLS_TOP)/utils/ghc-pkg/Makefile for why we use
734 # a real binary here rather than a shell script.
736 INPLACE_PROG = $(odir)/ghc-inplace$(exeext)
737 EXCLUDED_C_SRCS += ghc-inplace.c
739 # FPTOOLS_TOP_ABS platform uses backslashes, at least on Cygwin, but that
740 # will go wrong when we use it in a Haskell string below.
741 TOP_ABS=$(subst \\,/,$(FPTOOLS_TOP_ABS_PLATFORM))
743 GHC_PATH=$(TOP_ABS)/$(GHC_COMPILER_DIR_REL)/$(GHC_PROG)$(exeext)
745 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
746 INPLACE_EXTRA_FLAGS = -optc-DWINDOWS
749 $(INPLACE_PROG): ghc-inplace.c
750 $(HC) -cpp -optc-DGHC_PATH=$(DQ)$(GHC_PATH)$(DQ) -optc-DTOP_ABS=$(DQ)$(TOP_ABS)$(DQ) $(INPLACE_EXTRA_FLAGS) $< -o $@
752 all :: $(INPLACE_PROG)
754 CLEAN_FILES += $(INPLACE_PROG)
757 ghc-inplace : $(INPLACE_PROG)
758 $(RM) -f $@ && $(LN_S) $< $@
762 CLEAN_FILES += ghc-inplace
765 #-----------------------------------------------------------------------------
768 # We don't want ghc treated as an ordinary executable,
769 # but put it together with the libraries.
770 # Also don't want any interface files installed
772 DESTDIR = $(INSTALL_LIBRARY_DIR_GHC)
774 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
775 INSTALL_LIBEXECS += $(GHC_PROG)
777 INSTALL_PROGS += $(GHC_PROG)
780 # ----------------------------------------------------------------------------
783 # rename/RnBinds_HC_OPTS += -auto-all
784 # rename/RnEnv_HC_OPTS += -auto-all
785 # rename/RnExpr_HC_OPTS += -auto-all
786 # rename/RnHiFiles_HC_OPTS += -auto-all
787 # rename/RnHsSyn_HC_OPTS += -auto-all
788 # rename/Rename_HC_OPTS += -auto-all
789 # rename/RnIfaces_HC_OPTS += -auto-all
790 # rename/RnNames_HC_OPTS += -auto-all
791 # rename/RnSource_HC_OPTS += -auto-all
792 # rename/RnTypes_HC_OPTS += -auto-all
794 # typecheck/Inst_HC_OPTS += -auto-all
795 # typecheck/TcBinds_HC_OPTS += -auto-all
796 # typecheck/TcClassDcl_HC_OPTS += -auto-all
797 # typecheck/TcDefaults_HC_OPTS += -auto-all
798 # typecheck/TcDeriv_HC_OPTS += -auto-all
799 # typecheck/TcEnv_HC_OPTS += -auto-all
800 # typecheck/TcExpr_HC_OPTS += -auto-all
801 # typecheck/TcForeign_HC_OPTS += -auto-all
802 # typecheck/TcGenDeriv_HC_OPTS += -auto-all
803 # typecheck/TcHsSyn_HC_OPTS += -auto-all
804 # typecheck/TcIfaceSig_HC_OPTS += -auto-all
805 # typecheck/TcInstDcls_HC_OPTS += -auto-all
806 # typecheck/TcMatches_HC_OPTS += -auto-all
807 # typecheck/TcMonoType_HC_OPTS += -auto-all
808 # typecheck/TcMType_HC_OPTS += -auto-all
809 # typecheck/TcPat_HC_OPTS += -auto-all
810 # typecheck/TcRnDriver_HC_OPTS += -auto-all
811 # #typecheck/TcRnMonad_HC_OPTS += -auto-all
812 # #typecheck/TcRnTypes_HC_OPTS += -auto-all
813 # typecheck/TcRules_HC_OPTS += -auto-all
814 # typecheck/TcSimplify_HC_OPTS += -auto-all
815 # typecheck/TcSplice_HC_OPTS += -auto-all
816 # typecheck/TcTyClsDecls_HC_OPTS += -auto-all
817 # typecheck/TcTyDecls_HC_OPTS += -auto-all
818 # typecheck/TcType_HC_OPTS += -auto-all
819 # typecheck/TcUnify_HC_OPTS += -auto-all
821 # coreSyn/CorePrep_HC_OPTS += -auto-all
822 # parser/Parser_HC_OPTS += -fasm
824 #-----------------------------------------------------------------------------
825 # Building the GHC package
827 # The GHC package is made from the stage 2 build and later.
828 # Fortunately the package build system framework more or less does the
829 # right thing for us here.
831 ifneq "$(findstring $(stage), 2 3)" ""
832 BUILD_GHC_PACKAGE=YES
835 ifeq "$(BUILD_GHC_PACKAGE)" "YES"
837 HIERARCHICAL_LIB = NO
838 VERSION = $(ProjectVersion)
839 PKG_DEPENDS += base haskell98
840 PACKAGE_CPP_OPTS += -DPKG_DEPENDS='$(PKG_DEPENDS)'
841 PACKAGE_CPP_OPTS += -DSTAGE='"$(stage)"'
843 # Omit Main from the library, the client will want to plug their own Main in
844 LIBOBJS = $(filter-out $(odir)/main/Main.o $(odir)/parser/hschooks.o \
845 $(odir)/main/Main.p_o $(odir)/parser/hschooks.p_o, \
848 # disable splitting: it won't really help with GHC, and the specialised
849 # build system for compiler/ isn't set up to handle it.
852 # the package build system likes to set WAYS=$(GhcLibWays), but we don't
853 # really want to build the whole of GHC multiple ways... if you do,
854 # set GhcCompilerWays instead.
855 GhcLibWays = $(GhcCompilerWays)
857 # override $(GhcLibHcOpts): we want GhcStage2HcOpts to take precedence
860 # override default definition of HS_IFACES so we can add $(odir)
861 HS_IFACES = $(addsuffix .$(way_)hi,$(basename $(HS_OBJS)))
863 # Haddock can't handle recursive modules currently, so we disable it for now.
866 # Tell package.mk not to set $(HC)
869 # The stage 2 GHC binary itself is built by compiling main/Main.hs
870 # (the same as used in stage 1) against the GHC package.
872 # This is done by compiling Main.hs separately and linking it with
873 # -package ghc. This is done using a separate Makefile, Makefile.ghcbin
874 # Why? See comments in Makefile.ghcbin
876 # The stage 2 and stage 3 package.conf.in files are different, because they
877 # point to either the stage2/ or stage3/ dirs in import-dirs. Hence before
878 # linking the ghc binary we must install the correct version of the package
879 # configuration. Yeuch... maybe one day this will all be done more cleanly.
880 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
882 ifeq "$(GhcBuildDylibs)" "YES"
883 ifeq "$(darwin_TARGET_OS)" "1"
884 GhcLibraryName=libHS$(PACKAGE)$(_way)_dyn.dylib
886 GhcLibraryName=libHS$(PACKAGE)$(_way)_dyn.so
889 GhcLibraryName=libHS$(PACKAGE)$(_way).a
892 ifneq "$(DOING_BIN_DIST)" "YES"
893 $(GHC_PROG) : $(GhcLibraryName) main/Main.hs
894 $(RM) package.conf.inplace
895 $(RM) $(STAMP_PKG_CONF)
896 $(MAKE) $(STAMP_PKG_CONF)
897 $(MAKE) -f Makefile.ghcbin $(MFLAGS) HS_PROG=$(GHC_PROG) $@
900 # Propagate standard targets to Makefile.ghcbin
901 docs runtests $(BOOT_TARGET) TAGS clean distclean mostlyclean maintainer-clean $(INSTALL_TARGET) $(INSTALL_DOCS_TARGET) html chm HxS ps dvi txt::
902 $(MAKE) -f Makefile.ghcbin $(MFLAGS) $@
905 #-----------------------------------------------------------------------------
908 MAINTAINER_CLEAN_FILES += parser/Parser.info main/ParsePkgConf.info
910 #-----------------------------------------------------------------------------
911 # Include target-rule boilerplate
913 # Don't use the default MKDEPENDHS stuff... we'll do our own, below
917 # Make doesn't work this out for itself, it seems
918 parser/Parser.y : parser/Parser.y.pp
919 EXTRA_SRCS += parser/Parser.y
922 #-----------------------------------------------------------------------------
923 # Source files for tags file generation
925 # We want to excluded derived sources, because they won't be in the source
926 # tree, which is where we are going to move the TAGS file to.a
928 TAGS_HS_SRCS = parser/Parser.y.pp $(filter-out $(DERIVED_SRCS) main/Config.hs parser/Parser.y, $(sort $(SRCS)))
930 include $(TOP)/mk/target.mk
932 ifeq "$(BUILD_GHC_PACKAGE)" "YES"
938 $(odir)/main/Config.$(way_)o: SRC_HC_OPTS+=-DSTAGE=$(DQ)$(stage)$(DQ)
940 #-----------------------------------------------------------------------------
943 ifeq "$(DOING_BIN_DIST)" "YES"
944 # This is derived from the sources when we are in a source tree, but we
945 # don't have any sources in a bindist, so we have to shortcut it
946 HS_IFACES := $(wildcard stage$(stage)/*/*.hi)
950 $(INSTALL_DIR) $(BIN_DIST_DIR)/compiler
951 $(INSTALL_DIR) $(BIN_DIST_DIR)/compiler/stage$(stage)
952 echo "stage=$(stage)" > $(BIN_DIST_DIR)/compiler/Makefile
953 cat Makefile >> $(BIN_DIST_DIR)/compiler/Makefile
954 $(INSTALL_DATA) package.conf.in $(BIN_DIST_DIR)/compiler/
955 set -e; for d in stage$(stage)/*/; do $(INSTALL_DIR) $(BIN_DIST_DIR)/compiler/$$d; done
956 set -e; for f in $(HS_IFACES); do $(INSTALL_DATA) $$f $(BIN_DIST_DIR)/compiler/$$f; done
957 ifneq "$(INSTALL_LIBS)" ""
958 set -e; for f in $(INSTALL_LIBS); do $(INSTALL_DATA) $$f $(BIN_DIST_DIR)/compiler/$$f; done
960 ifneq "$(INSTALL_PROGS)" ""
961 set -e; for f in $(INSTALL_PROGS); do $(INSTALL_PROGRAM) $$f $(BIN_DIST_DIR)/compiler/$$f; done
963 ifneq "$(INSTALL_LIBEXECS)" ""
964 set -e; for f in $(INSTALL_LIBEXECS); do $(INSTALL_PROGRAM) $$f $(BIN_DIST_DIR)/compiler/$$f; done
967 # -----------------------------------------------------------------------------
968 # Explicit dependencies
970 # Some .hs files #include other source files, but since ghc -M doesn't spit out
971 # these dependencies we have to include them manually.
973 # We don't add dependencies on HsVersions.h, ghcautoconf.h, or ghc_boot_platform.h,
974 # because then modifying one of these files would force recompilation of everything,
975 # which is probably not what you want. However, it does mean you have to be
976 # careful to recompile stuff you need if you reconfigure or change HsVersions.h.
978 # Aargh, these don't work properly anyway, because GHC's recompilation checker
979 # just reports "compilation NOT required". Do we have to add -no-recomp for each
980 # of these .hs files? I haven't done anything about this yet.
982 $(odir)/codeGen/Bitmap.$(way_)o : ../includes/MachDeps.h
983 $(odir)/codeGen/CgCallConv.$(way_)o : ../includes/StgFun.h
984 $(odir)/codeGen/CgProf.$(way_)o : ../includes/MachDeps.h
985 $(odir)/codeGen/CgProf.$(way_)o : ../includes/Constants.h
986 $(odir)/codeGen/CgProf.$(way_)o : ../includes/DerivedConstants.h
987 $(odir)/codeGen/CgTicky.$(way_)o : ../includes/DerivedConstants.h
988 $(odir)/codeGen/ClosureInfo.$(way_)o : ../includes/MachDeps.h
989 $(odir)/codeGen/SMRep.$(way_)o : ../includes/MachDeps.h
990 $(odir)/codeGen/SMRep.$(way_)o : ../includes/ClosureTypes.h
991 $(odir)/ghci/ByteCodeAsm.$(way_)o : ../includes/Bytecodes.h
992 $(odir)/ghci/ByteCodeFFI.$(way_)o : nativeGen/NCG.h
993 $(odir)/ghci/ByteCodeInstr.$(way_)o : ../includes/MachDeps.h
994 $(odir)/ghci/ByteCodeItbls.$(way_)o : ../includes/ClosureTypes.h
995 $(odir)/ghci/ByteCodeItbls.$(way_)o : nativeGen/NCG.h
996 $(odir)/main/Constants.$(way_)o : ../includes/MachRegs.h
997 $(odir)/main/Constants.$(way_)o : ../includes/Constants.h
998 $(odir)/main/Constants.$(way_)o : ../includes/MachDeps.h
999 $(odir)/main/Constants.$(way_)o : ../includes/DerivedConstants.h
1000 $(odir)/main/Constants.$(way_)o : ../includes/GHCConstants.h
1001 $(odir)/nativeGen/AsmCodeGen.$(way_)o : nativeGen/NCG.h
1002 $(odir)/nativeGen/MachCodeGen.$(way_)o : nativeGen/NCG.h
1003 $(odir)/nativeGen/MachCodeGen.$(way_)o : ../includes/MachDeps.h
1004 $(odir)/nativeGen/MachInstrs.$(way_)o : nativeGen/NCG.h
1005 $(odir)/nativeGen/MachRegs.$(way_)o : nativeGen/NCG.h
1006 $(odir)/nativeGen/MachRegs.$(way_)o : ../includes/MachRegs.h
1007 $(odir)/nativeGen/PositionIndependentCode.$(way_)o : nativeGen/NCG.h
1008 $(odir)/nativeGen/PprMach.$(way_)o : nativeGen/NCG.h
1009 $(odir)/nativeGen/RegAllocInfo.$(way_)o : nativeGen/NCG.h
1010 $(odir)/typecheck/TcForeign.$(way_)o : nativeGen/NCG.h
1011 $(odir)/utils/Binary.$(way_)o : ../includes/MachDeps.h
1012 $(odir)/utils/FastMutInt.$(way_)o : ../includes/MachDeps.h
1014 # -----------------------------------------------------------------------------
1017 MKDEPENDHS_HC_OPTS = $(patsubst -i$(odir)/%, -i%, $(HC_OPTS))
1021 # Must do this *after* including target.mk, because $(HS_SRCS) isn't set yet.
1022 depend :: $(STAGE_PLATFORM_H) $(HS_SRCS) $(C_SRCS)
1024 ifneq "$(BootingFromHc)" "YES"
1025 $(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)
1027 $(MKDEPENDC) -f .depend-BASE $(MKDEPENDC_OPTS) $(foreach way,$(WAYS),-s $(way)) -- $(CC_OPTS) -- $(C_SRCS)
1028 $(PERL) -pe 'binmode(stdin); binmode(stdout); s@(\S*[._]o)@stage$(stage)/$$1@g; s@(\S*[._]hi)@stage$(stage)/$$1@g; s@^.*/compat.*$$@@g;' <.depend-BASE >.depend-$(stage)
1029 # The binmode stuff tells perl not to add stupid ^M's to the output
1031 # The /lib/compat replacement is to workaround a bug in the
1032 # -optdep--exclude-module flag in GHC 6.4. It is not required for any
1033 # other version of GHC, but doesn't do any harm.
1035 ifeq "$(MakefileDeps)" "YES"
1036 $(CONFIG_HS) : Makefile
1037 stage1/$(PLATFORM_H) : Makefile
1038 stage2/$(PLATFORM_H) : Makefile
1041 -include .depend-$(stage)