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))
168 HS_OBJS = $(patsubst %, $(odir)/%, $(addsuffix .$(way_)o,$(basename $(HS_SRCS))))
169 C_OBJS = $(patsubst %, $(odir)/%, $(addsuffix .$(way_)o,$(basename $(C_SRCS))))
171 # Our standard cleaning rules don't know that we're doing our output
172 # into $(odir), so we have to augment CLEAN_FILES appropriateliy.
174 CLEAN_FILES += $(odir)/*/*.hi $(odir)/*/*.hi-boot $(odir)/*/*.o-boot
176 ifeq "$(UsingHsBoot)" "YES"
177 CLEAN_FILES += $(odir)/*/*.hi-boot $(odir)/*/*.o-boot
181 mostlyclean clean distclean maintainer-clean ::
186 # -----------------------------------------------------------------------------
189 # Note: there have been reports of people running up against the ARG_MAX limit
190 # when linking ghc with all its constituent object files. The likely source of
191 # the problem is that the environment is a bit too big, so a workaround could
192 # be to do `env PATH=$(PATH) make ghc' to minimise the environment. (or the
193 # equivalent of `env' if it doesn't exist locally).
196 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
197 GHC_PROG=$(odir)/ghc$(_way)-$(ProjectVersion)
199 GHC_PROG=$(odir)/ghc$(_way)
202 GHC_PROG=$(odir)/ghc-$(ProjectVersion)
206 HS_PROG = $(GHC_PROG)
209 # -----------------------------------------------------------------------------
210 # Create compiler configuration
212 # The 'echo' commands simply spit the values of various make variables
213 # into Config.hs, whence they can be compiled and used by GHC itself
215 CONFIG_HS = main/Config.hs
218 $(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk
219 @$(RM) -f $(CONFIG_HS)
220 @echo "Creating $(CONFIG_HS) ... "
221 @echo "module Config where" >>$(CONFIG_HS)
222 @echo "cProjectName = \"$(ProjectName)\"" >> $(CONFIG_HS)
223 @echo "cProjectVersion = \"$(ProjectVersion)\"" >> $(CONFIG_HS)
224 @echo "cProjectVersionInt = \"$(ProjectVersionInt)\"" >> $(CONFIG_HS)
225 @echo "cProjectPatchLevel = \"$(ProjectPatchLevel)\"" >> $(CONFIG_HS)
226 @echo "cBooterVersion = \"$(GhcVersion)\"" >> $(CONFIG_HS)
227 @echo "cStage = STAGE" >> $(CONFIG_HS)
228 @echo "cHscIfaceFileVersion = \"$(HscIfaceFileVersion)\"" >> $(CONFIG_HS)
229 @echo "cSplitObjs = \"$(SplitObjs)\"" >> $(CONFIG_HS)
230 @echo "cGhcWithInterpreter = \"$(GhcWithInterpreter)\"" >> $(CONFIG_HS)
231 @echo "cGhcWithNativeCodeGen = \"$(GhcWithNativeCodeGen)\"" >> $(CONFIG_HS)
232 @echo "cGhcWithSMP = \"$(GhcWithSMP)\"" >> $(CONFIG_HS)
233 @echo "cGhcRTSWays = \"$(GhcRTSWays)\"" >> $(CONFIG_HS)
234 @echo "cGhcUnregisterised = \"$(GhcUnregisterised)\"" >> $(CONFIG_HS)
235 @echo "cGhcEnableTablesNextToCode = \"$(GhcEnableTablesNextToCode)\"" >> $(CONFIG_HS)
236 @echo "cLeadingUnderscore = \"$(LeadingUnderscore)\"" >> $(CONFIG_HS)
237 @echo "cRAWCPP_FLAGS = \"$(RAWCPP_FLAGS)\"" >> $(CONFIG_HS)
238 @echo "cGCC = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
239 @echo "cMKDLL = \"$(BLD_DLL)\"" >> $(CONFIG_HS)
240 @echo "cLdIsGNULd = \"$(LdIsGNULd)\"" >> $(CONFIG_HS)
241 @echo "cLD_X = \"$(LD_X)\"" >> $(CONFIG_HS)
242 @echo "cPROJECT_DIR = \"$(PROJECT_DIR)\"" >> $(CONFIG_HS)
243 @echo "cGHC_DRIVER_DIR_REL = \"$(GHC_DRIVER_DIR_REL)\"" >> $(CONFIG_HS)
244 @echo "cGHC_TOUCHY_PGM = \"$(GHC_TOUCHY_PGM)\"" >> $(CONFIG_HS)
245 @echo "cGHC_TOUCHY_DIR_REL = \"$(GHC_TOUCHY_DIR_REL)\"" >> $(CONFIG_HS)
246 @echo "cGHC_UNLIT_PGM = \"$(GHC_UNLIT_PGM)\"" >> $(CONFIG_HS)
247 @echo "cGHC_UNLIT_DIR_REL = \"$(GHC_UNLIT_DIR_REL)\"" >> $(CONFIG_HS)
248 @echo "cGHC_MANGLER_PGM = \"$(GHC_MANGLER_PGM)\"" >> $(CONFIG_HS)
249 @echo "cGHC_MANGLER_DIR_REL = \"$(GHC_MANGLER_DIR_REL)\"" >> $(CONFIG_HS)
250 @echo "cGHC_SPLIT_PGM = \"$(GHC_SPLIT_PGM)\"" >> $(CONFIG_HS)
251 @echo "cGHC_SPLIT_DIR_REL = \"$(GHC_SPLIT_DIR_REL)\"" >> $(CONFIG_HS)
252 @echo "cGHC_SYSMAN_PGM = \"$(GHC_SYSMAN)\"" >> $(CONFIG_HS)
253 @echo "cGHC_SYSMAN_DIR_REL = \"$(GHC_SYSMAN_DIR)\"" >> $(CONFIG_HS)
254 @echo "cGHC_CP = \"$(GHC_CP)\"" >> $(CONFIG_HS)
255 @echo "cGHC_PERL = \"$(GHC_PERL)\"" >> $(CONFIG_HS)
256 ifeq ($(GhcWithIlx),YES)
257 @echo "cILX2IL = \"$(ILX2IL)\"" >> $(CONFIG_HS)
258 @echo "cILASM = \"$(ILASM)\"" >> $(CONFIG_HS)
260 @echo "cEnableWin32DLLs = \"$(EnableWin32DLLs)\"" >> $(CONFIG_HS)
261 @echo "cCONTEXT_DIFF = \"$(CONTEXT_DIFF)\"" >> $(CONFIG_HS)
262 @echo "cUSER_WAY_NAMES = \"$(USER_WAY_NAMES)\"" >> $(CONFIG_HS)
263 @echo "cUSER_WAY_OPTS = \"$(USER_WAY_OPTS)\"" >> $(CONFIG_HS)
264 @echo "cDEFAULT_TMPDIR = \"$(DEFAULT_TMPDIR)\"" >> $(CONFIG_HS)
267 CLEAN_FILES += $(CONFIG_HS)
269 # -----------------------------------------------------------------------------
270 # Create platform includes
272 # Here we generate a little header file containing CPP symbols that GHC
273 # uses to determine which platform it is building on/for. The platforms
274 # can differ between stage1 and stage2 if we're cross-compiling, so we
275 # need one of these header files per stage.
277 PLATFORM_H = ghc_boot_platform.h
279 stage1/$(PLATFORM_H) : stage_dirs $(FPTOOLS_TOP)/mk/config.mk
280 @echo "Creating $@..."
282 @echo "#ifndef __PLATFORM_H__" >$@
283 @echo "#define __PLATFORM_H__" >>$@
285 @echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
286 @echo "#define HostPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
287 @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
289 @echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
290 @echo "#define $(HostPlatform_CPP)_HOST 1" >> $@
291 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
293 @echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
294 @echo "#define $(HostArch_CPP)_HOST_ARCH 1" >> $@
295 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
296 @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
297 @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
298 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
300 @echo "#define $(BuildOS_CPP)_BUILD_OS 1" >> $@
301 @echo "#define $(HostOS_CPP)_HOST_OS 1" >> $@
302 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
303 @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
304 @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
305 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
306 ifeq "$(HostOS_CPP)" "irix"
307 @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS " >> $@
308 @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
309 @echo "#endif " >> $@
312 @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
313 @echo "#define $(HostVendor_CPP)_HOST_VENDOR 1" >> $@
314 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
315 @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
316 @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
317 @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
319 @echo "#endif /* __PLATFORM_H__ */" >> $@
322 # For stage2 and above, the BUILD platform is the HOST of stage1, and
323 # the HOST platform is the TARGET of stage1. The TARGET remains the same
324 # (stage1 is the cross-compiler, not stage2).
325 stage2/$(PLATFORM_H) : stage_dirs $(FPTOOLS_TOP)/mk/config.mk
326 @echo "Creating $@..."
328 @echo "#ifndef __PLATFORM_H__" >$@
329 @echo "#define __PLATFORM_H__" >>$@
331 @echo "#define BuildPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
332 @echo "#define HostPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
333 @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
335 @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
336 @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
337 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
339 @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
340 @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
341 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
342 @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
343 @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
344 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
346 @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
347 @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
348 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
349 @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
350 @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
351 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
352 ifeq "$(HostOS_CPP)" "irix"
353 @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS " >> $@
354 @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
355 @echo "#endif " >> $@
358 @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
359 @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
360 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
361 @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
362 @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
363 @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
365 @echo "#endif /* __PLATFORM_H__ */" >> $@
368 stage3/$(PLATFORM_H) : stage_dirs stage2/$(PLATFORM_H)
369 $(CP) stage2/$(PLATFORM_H) stage3/$(PLATFORM_H)
371 STAGE_PLATFORM_H = stage$(stage)/$(PLATFORM_H)
373 boot :: $(STAGE_PLATFORM_H)
375 SRC_HC_OPTS += -Istage$(stage)
377 # -----------------------------------------------------------------------------
380 # First figure out ALL_DIRS, the source sub-directories
383 utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
384 vectorise specialise simplCore stranal stgSyn simplStg codeGen main \
385 profiling parser cprAnalysis ndpFlatten iface cmm
387 # Make sure we include Config.hs even if it doesn't exist yet...
388 ALL_SRCS += $(CONFIG_HS)
390 # HsGeneric.hs is not used just now
391 EXCLUDED_SRCS += hsSyn/HsGeneric.hs
393 ifeq ($(GhcWithNativeCodeGen),YES)
394 ALL_DIRS += nativeGen
396 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
399 ifeq ($(GhcWithIlx),YES)
404 ifeq ($(GhcWithJavaGen),YES)
406 SRC_HC_OPTS += -DJAVA
409 ifeq "$(BootingFromHc)" "YES"
410 # HC files are always from a self-booted compiler
413 ifneq "$(findstring $(stage), 2 3)" ""
420 # -----------------------------------------------------------------------------
421 # Building a compiler with interpreter support
423 # The interpreter, GHCi interface, Template Haskell and Hpc are only
424 # enabled when we are bootstrapping with the same version of GHC, and
425 # the interpreter is supported on this platform.
427 ifeq "$(bootstrapped)" "YES"
428 SRC_HC_OPTS += -package hpc -package bytestring
429 PKG_DEPENDS += hpc bytestring
432 ifeq "$(GhcWithInterpreter) $(bootstrapped)" "YES YES"
434 # Yes, include the interepreter, readline, and Template Haskell extensions
435 SRC_HC_OPTS += -DGHCI -package template-haskell
436 PKG_DEPENDS += template-haskell
438 # Should GHCI be building info tables in the TABLES_NEXT_TO_CODE style
440 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
441 SRC_HC_OPTS += -DGHCI_TABLES_NEXT_TO_CODE
444 ifeq "$(GhcThreaded)" "YES"
445 # Use threaded RTS with GHCi, so threads don't get blocked at the prompt.
446 SRC_LD_OPTS += -threaded
448 ifeq "$(GhcProfiled)" "YES"
451 ifeq "$(GhcDebugged)" "YES"
452 SRC_LD_OPTS += -debug
457 # If we are going to use dynamic libraries instead of .o files for ghci,
458 # we will need to always retain CAFs in the compiler.
459 # ghci/keepCAFsForGHCi contains a GNU C __attribute__((constructor))
460 # function which sets the keepCAFs flag for the RTS before any Haskell
462 ifeq "$(GhcBuildDylibs)" "YES"
464 EXCLUDED_SRCS += ghci/keepCAFsForGHCi.c
467 # Enable readline if either:
468 # - we're building stage 1 and $(GhcHasReadline)="YES"
469 # - we're building stage 2/3, and we have built the readline package
471 # But we don't enable readline on Windows, because readline is fairly
474 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
476 ifeq "$(GhcHasReadline)" "YES"
477 SRC_HC_OPTS += -package readline -DUSE_READLINE
478 PKG_DEPENDS += readline
481 -include $(FPTOOLS_TOP)/libraries/readline/config.mk
482 # readline's config.mk sets PACKAGE, which we don't want here
484 ifeq "$(READLINE_BUILD_PACKAGE)" "yes"
485 SRC_HC_OPTS += -package readline -DUSE_READLINE
486 PKG_DEPENDS += readline
493 # No interpreter, so exclude Template Haskell modules
494 EXCLUDED_SRCS += deSugar/DsMeta.hs typecheck/TcSplice.lhs hsSyn/Convert.lhs
496 endif # bootstrapped with interpreter
498 # -----------------------------------------------
501 # Big Fudge to get around inherent problem that Makefile setup
502 # has got with 'mkdependC'.
504 SRC_MKDEPENDC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
506 # XXX not really correct, hschooks.c actually gets include files like
507 # RtsFlags.c from the installed GHC, but we can't tell mkdependC about that.
508 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
510 # -----------------------------------------------------------------------------
511 # Haskell compilations
514 -cpp -fglasgow-exts -fno-generics -Rghc-timing \
517 # Omitted: -I$(GHC_INCLUDE_DIR)
518 # We should have -I$(GHC_INCLUDE_DIR) in SRC_HC_OPTS,
519 # to avoid the use of an explicit path in GHC source files
520 # (include "../includes/config.h"
521 # But alas GHC 4.08 (and others for all I know) uses this very
522 # same include path when compiling the .hc files it generates.
523 # Disaster! Then the hc file sees the GHC 5.02 (or whatever)
524 # include files. For the moment we've reverted to using
525 # an explicit path in the .hs sources
527 # For the benefit of <5.00 compilers, do include GHC_INCLUDE_DIR
528 # when generating dependencies. (=> it gets passed onto mkdependHS,
530 SRC_MKDEPENDHS_OPTS += -I$(GHC_INCLUDE_DIR)
532 # We need System.Posix (or Posix when ghc < 6.2)
533 ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
534 ifeq "$(bootstrapped)" "YES"
535 SRC_HC_OPTS += -package Win32
539 ifeq "$(bootstrapped) $(ghc_ge_601)" "NO NO"
540 SRC_HC_OPTS += -package posix
542 SRC_HC_OPTS += -package unix
547 # We use the Cabal package in stages 2/3 only; in stage 1 we're using
548 # the libcompat library which provides the Cabal modules.
550 SRC_HC_OPTS += -package Cabal
554 ifeq "$(ghc_ge_603)" "YES"
555 # Ignore lang, to avoid potential clash with the Generics module if
556 # lang happens to be a dependency of some exposed package in the local
557 # GHC installation (eg. wxHaskell did this around 6.4).
558 SRC_HC_OPTS += -ignore-package lang
561 SRC_CC_OPTS += -Iparser -I. -O
562 SRC_HC_OPTS += -recomp $(GhcHcOpts) $(GhcStage$(stage)HcOpts)
565 ifeq "$(BootingFromHc)" "YES"
566 SRC_CC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
569 # Special flags for particular modules
570 # The standard suffix rule for compiling a Haskell file
571 # adds these flags to the command line
573 # There used to be a -no-recomp flag on PrimOp, but why?
574 # It's an expensive module to recompile!
575 prelude/PrimOp_HC_OPTS = -H80m
578 main/ParsePkgConf_HC_OPTS += -fno-warn-incomplete-patterns
579 parser/Parser_HC_OPTS += -fno-warn-incomplete-patterns
581 ifeq "$(ghc_ge_603)" "NO"
582 # Use -fvia-C since the NCG can't handle the narrow16Int# (and intToInt16#?)
583 # primops on all platforms.
584 parser/Parser_HC_OPTS += -fvia-C
585 # because the NCG can't handle the 64-bit math in here
586 prelude/PrelRules_HC_OPTS += -fvia-C
587 # ByteCodeItbls uses primops that the NCG doesn't support.
588 ghci/ByteCodeItbls_HC_OPTS += -fvia-C
589 ghci/ByteCodeLink_HC_OPTS += -fvia-C -monly-3-regs
592 # Careful optimisation of the parser: we don't want to throw everything
593 # at it, because that takes too long and doesn't buy much, but we do want
594 # to inline certain key external functions, so we instruct GHC not to
595 # throw away inlinings as it would normally do in -Onot mode:
596 parser/Parser_HC_OPTS += -Onot -fno-ignore-interface-pragmas
598 ifeq "$(HOSTPLATFORM)" "hppa1.1-hp-hpux9"
599 rename/RnMonad_HC_OPTS = -O2 -O2-for-C
602 utils/Digraph_HC_OPTS = -fglasgow-exts
604 basicTypes/SrcLoc_HC_OPTS = -funbox-strict-fields
606 # We always optimise some low-level modules, otherwise performance of
607 # a non-optimised compiler is severely affected.
608 main/BinIface_HC_OPTS += -O
609 utils/Binary_HC_OPTS += -O -funbox-strict-fields
610 utils/FastMutInt_HC_OPTS += -O
611 utils/Encoding_HC_OPTS += -O
612 utils/StringBuffer_HC_OPTS += -O -funbox-strict-fields
613 utils/FastString_HC_OPTS += -O -funbox-strict-fields
615 # ---- Profiling ----
616 #simplCore/Simplify_HC_OPTS = -auto-all
617 #simplCore/SimplEnv_HC_OPTS = -auto-all
618 #simplCore/SimplUtils_HC_OPTS = -auto-all
620 # CSE interacts badly with top-level IORefs (reportedly in DriverState and
621 # DriverMkDepend), causing some of them to be commoned up. We have a fix for
622 # this in 5.00+, but earlier versions of the compiler will need CSE turned off.
623 # To be on the safe side, we disable CSE in *all* modules with top-level IORefs.
624 ghci/InteractiveUI_HC_OPTS = -fno-cse
625 main/CmdLineOpts_HC_OPTS = -fno-cse
626 main/DriverMkDepend_HC_OPTS = -fno-cse
627 main/DriverPipeline_HC_OPTS = -fno-cse
628 main/Finder_HC_OPTS = -fno-cse
629 main/SysTools_HC_OPTS = -fno-cse
630 main/StaticFlags_HC_OPTS = -fno-cse
632 # The #include is vital for the via-C route, else the C
633 # compiler doesn't realise that the stcall foreign imports are indeed
634 # stdcall, and doesn't generate the Foo@8 name for them
635 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
636 main/SysTools_HC_OPTS += '-\#include <windows.h>' '-\#include <process.h>'
639 parser/Lexer_HC_OPTS += -funbox-strict-fields
641 # ghc_strlen percolates through so many modules that it is easier to get its
642 # prototype via a global option instead of a myriad of per-file OPTIONS
643 SRC_HC_OPTS += '-\#include "cutils.h"'
645 # ----------------------------------------------------------------------------
646 # Generate supporting stuff for prelude/PrimOp.lhs
647 # from prelude/primops.txt
649 PRIMOP_BITS=primop-data-decl.hs-incl \
651 primop-list.hs-incl \
652 primop-has-side-effects.hs-incl \
653 primop-out-of-line.hs-incl \
654 primop-commutable.hs-incl \
655 primop-needs-wrapper.hs-incl \
656 primop-can-fail.hs-incl \
657 primop-strictness.hs-incl \
658 primop-primop-info.hs-incl
660 CLEAN_FILES += prelude/primops.txt
661 CLEAN_FILES += $(PRIMOP_BITS)
663 SRC_CPP_OPTS += -I$(GHC_INCLUDE_DIR)
664 SRC_CPP_OPTS += ${GhcCppOpts}
666 ifneq "$(BootingFromHc)" "YES"
667 prelude/PrimOp.lhs $(odir)/prelude/PrimOp.o: $(PRIMOP_BITS)
670 ifneq "$(BootingFromHc)" "YES"
671 depend :: $(PRIMOP_BITS)
674 # This is an ugly hack: we need stage1/$(PLATFORM_H) built before we
675 # preprocess primops.txt.pp, but we don't want to just add that
676 # dependency because we don't want $(PLATFORM_H) built during normal
677 # operations, because we don't have have dependencies from the .hs
678 # sources on it, and we don't want those dependencies because that
679 # would cause everything to be rebuilt every time the Makefile
680 # changed. So here we add the required dependency only when making
682 ifneq "$(findstring boot, $(MAKECMDGOALS))$(findstring depend, $(MAKECMDGOALS))" ""
683 prelude/primops.txt.pp : stage1/$(PLATFORM_H)
686 primop-data-decl.hs-incl: prelude/primops.txt
687 $(GENPRIMOP) --data-decl < $< > $@
688 primop-tag.hs-incl: prelude/primops.txt
689 $(GENPRIMOP) --primop-tag < $< > $@
690 primop-list.hs-incl: prelude/primops.txt
691 $(GENPRIMOP) --primop-list < $< > $@
692 primop-has-side-effects.hs-incl: prelude/primops.txt
693 $(GENPRIMOP) --has-side-effects < $< > $@
694 primop-out-of-line.hs-incl: prelude/primops.txt
695 $(GENPRIMOP) --out-of-line < $< > $@
696 primop-commutable.hs-incl: prelude/primops.txt
697 $(GENPRIMOP) --commutable < $< > $@
698 primop-needs-wrapper.hs-incl: prelude/primops.txt
699 $(GENPRIMOP) --needs-wrapper < $< > $@
700 primop-can-fail.hs-incl: prelude/primops.txt
701 $(GENPRIMOP) --can-fail < $< > $@
702 primop-strictness.hs-incl: prelude/primops.txt
703 $(GENPRIMOP) --strictness < $< > $@
704 primop-primop-info.hs-incl: prelude/primops.txt
705 $(GENPRIMOP) --primop-primop-info < $< > $@
707 # Usages aren't used any more; but the generator
708 # can still generate them if we want them back
709 primop-usage.hs-incl: prelude/primops.txt
710 $(GENPRIMOP) --usage < $< > $@
713 #-----------------------------------------------------------------------------
716 # Include libghccompat in stage1 only. In stage2 onwards, all these
717 # libraries will be available from the main libraries.
720 include $(GHC_COMPAT_DIR)/compat.mk
723 SRC_LD_OPTS += -no-link-chk
725 # -----------------------------------------------------------------------------
726 # create ghc-inplace, a convenient way to run ghc from the build tree...
727 # See comments in $(FPTOOLS_TOP)/utils/ghc-pkg/Makefile for why we use
728 # a real binary here rather than a shell script.
730 INPLACE_PROG = $(odir)/ghc-inplace$(exeext)
731 EXCLUDED_C_SRCS += ghc-inplace.c
733 # FPTOOLS_TOP_ABS platform uses backslashes, at least on Cygwin, but that
734 # will go wrong when we use it in a Haskell string below.
735 TOP_ABS=$(subst \\,/,$(FPTOOLS_TOP_ABS_PLATFORM))
737 GHC_PATH=$(TOP_ABS)/$(GHC_COMPILER_DIR_REL)/$(GHC_PROG)$(exeext)
739 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
740 INPLACE_EXTRA_FLAGS = -optc-DWINDOWS
743 $(INPLACE_PROG): ghc-inplace.c
744 $(HC) -cpp -optc-DGHC_PATH=$(DQ)$(GHC_PATH)$(DQ) -optc-DTOP_ABS=$(DQ)$(TOP_ABS)$(DQ) $(INPLACE_EXTRA_FLAGS) $< -o $@
746 all :: $(INPLACE_PROG)
748 CLEAN_FILES += $(INPLACE_PROG)
751 ghc-inplace : $(INPLACE_PROG)
752 $(RM) -f $@ && $(LN_S) $< $@
756 CLEAN_FILES += ghc-inplace
759 #-----------------------------------------------------------------------------
762 # We don't want ghc treated as an ordinary executable,
763 # but put it together with the libraries.
764 # Also don't want any interface files installed
766 DESTDIR = $(INSTALL_LIBRARY_DIR_GHC)
768 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
769 INSTALL_LIBEXECS += $(GHC_PROG)
771 INSTALL_PROGS += $(GHC_PROG)
774 # ----------------------------------------------------------------------------
777 # rename/RnBinds_HC_OPTS += -auto-all
778 # rename/RnEnv_HC_OPTS += -auto-all
779 # rename/RnExpr_HC_OPTS += -auto-all
780 # rename/RnHiFiles_HC_OPTS += -auto-all
781 # rename/RnHsSyn_HC_OPTS += -auto-all
782 # rename/Rename_HC_OPTS += -auto-all
783 # rename/RnIfaces_HC_OPTS += -auto-all
784 # rename/RnNames_HC_OPTS += -auto-all
785 # rename/RnSource_HC_OPTS += -auto-all
786 # rename/RnTypes_HC_OPTS += -auto-all
788 # typecheck/Inst_HC_OPTS += -auto-all
789 # typecheck/TcBinds_HC_OPTS += -auto-all
790 # typecheck/TcClassDcl_HC_OPTS += -auto-all
791 # typecheck/TcDefaults_HC_OPTS += -auto-all
792 # typecheck/TcDeriv_HC_OPTS += -auto-all
793 # typecheck/TcEnv_HC_OPTS += -auto-all
794 # typecheck/TcExpr_HC_OPTS += -auto-all
795 # typecheck/TcForeign_HC_OPTS += -auto-all
796 # typecheck/TcGenDeriv_HC_OPTS += -auto-all
797 # typecheck/TcHsSyn_HC_OPTS += -auto-all
798 # typecheck/TcIfaceSig_HC_OPTS += -auto-all
799 # typecheck/TcInstDcls_HC_OPTS += -auto-all
800 # typecheck/TcMatches_HC_OPTS += -auto-all
801 # typecheck/TcMonoType_HC_OPTS += -auto-all
802 # typecheck/TcMType_HC_OPTS += -auto-all
803 # typecheck/TcPat_HC_OPTS += -auto-all
804 # typecheck/TcRnDriver_HC_OPTS += -auto-all
805 # #typecheck/TcRnMonad_HC_OPTS += -auto-all
806 # #typecheck/TcRnTypes_HC_OPTS += -auto-all
807 # typecheck/TcRules_HC_OPTS += -auto-all
808 # typecheck/TcSimplify_HC_OPTS += -auto-all
809 # typecheck/TcSplice_HC_OPTS += -auto-all
810 # typecheck/TcTyClsDecls_HC_OPTS += -auto-all
811 # typecheck/TcTyDecls_HC_OPTS += -auto-all
812 # typecheck/TcType_HC_OPTS += -auto-all
813 # typecheck/TcUnify_HC_OPTS += -auto-all
815 # coreSyn/CorePrep_HC_OPTS += -auto-all
816 # parser/Parser_HC_OPTS += -fasm
818 #-----------------------------------------------------------------------------
819 # Building the GHC package
821 # The GHC package is made from the stage 2 build and later.
822 # Fortunately the package build system framework more or less does the
823 # right thing for us here.
825 ifneq "$(findstring $(stage), 2 3)" ""
826 BUILD_GHC_PACKAGE=YES
829 ifeq "$(BUILD_GHC_PACKAGE)" "YES"
831 HIERARCHICAL_LIB = NO
832 VERSION = $(ProjectVersion)
833 PKG_DEPENDS += base haskell98
834 PACKAGE_CPP_OPTS += -DPKG_DEPENDS='$(PKG_DEPENDS)'
835 PACKAGE_CPP_OPTS += -DSTAGE='"$(stage)"'
837 # Omit Main from the library, the client will want to plug their own Main in
838 LIBOBJS = $(filter-out $(odir)/main/Main.o $(odir)/parser/hschooks.o \
839 $(odir)/main/Main.p_o $(odir)/parser/hschooks.p_o, \
842 # disable splitting: it won't really help with GHC, and the specialised
843 # build system for compiler/ isn't set up to handle it.
846 # the package build system likes to set WAYS=$(GhcLibWays), but we don't
847 # really want to build the whole of GHC multiple ways... if you do,
848 # set GhcCompilerWays instead.
849 GhcLibWays = $(GhcCompilerWays)
851 # override $(GhcLibHcOpts): we want GhcStage2HcOpts to take precedence
854 # override default definition of HS_IFACES so we can add $(odir)
855 HS_IFACES = $(addsuffix .$(way_)hi,$(basename $(HS_OBJS)))
857 # Haddock can't handle recursive modules currently, so we disable it for now.
860 # Tell package.mk not to set $(HC)
863 # The stage 2 GHC binary itself is built by compiling main/Main.hs
864 # (the same as used in stage 1) against the GHC package.
866 # This is done by compiling Main.hs separately and linking it with
867 # -package ghc. This is done using a separate Makefile, Makefile.ghcbin
868 # Why? See comments in Makefile.ghcbin
870 # The stage 2 and stage 3 package.conf.in files are different, because they
871 # point to either the stage2/ or stage3/ dirs in import-dirs. Hence before
872 # linking the ghc binary we must install the correct version of the package
873 # configuration. Yeuch... maybe one day this will all be done more cleanly.
874 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
876 ifeq "$(GhcBuildDylibs)" "YES"
877 ifeq "$(darwin_TARGET_OS)" "1"
878 GhcLibraryName=libHS$(PACKAGE)$(_way)_dyn.dylib
880 GhcLibraryName=libHS$(PACKAGE)$(_way)_dyn.so
883 GhcLibraryName=libHS$(PACKAGE)$(_way).a
886 ifneq "$(DOING_BIN_DIST)" "YES"
887 $(GHC_PROG) : $(GhcLibraryName) main/Main.hs
888 $(RM) package.conf.inplace
889 $(RM) $(STAMP_PKG_CONF)
890 $(MAKE) $(STAMP_PKG_CONF)
891 $(MAKE) -f Makefile.ghcbin $(MFLAGS) HS_PROG=$(GHC_PROG) $@
894 # Propagate standard targets to Makefile.ghcbin
895 docs runtests $(BOOT_TARGET) TAGS clean distclean mostlyclean maintainer-clean $(INSTALL_TARGET) $(INSTALL_DOCS_TARGET) html chm HxS ps dvi txt::
896 $(MAKE) -f Makefile.ghcbin $(MFLAGS) $@
899 #-----------------------------------------------------------------------------
902 MAINTAINER_CLEAN_FILES += parser/Parser.info main/ParsePkgConf.info
904 #-----------------------------------------------------------------------------
905 # Include target-rule boilerplate
907 # Don't use the default MKDEPENDHS stuff... we'll do our own, below
911 # Make doesn't work this out for itself, it seems
912 parser/Parser.y : parser/Parser.y.pp
913 EXTRA_SRCS += parser/Parser.y
916 #-----------------------------------------------------------------------------
917 # Source files for tags file generation
919 # We want to excluded derived sources, because they won't be in the source
920 # tree, which is where we are going to move the TAGS file to.a
922 TAGS_HS_SRCS = parser/Parser.y.pp $(filter-out $(DERIVED_SRCS) main/Config.hs parser/Parser.y, $(sort $(SRCS)))
924 include $(TOP)/mk/target.mk
926 ifeq "$(BUILD_GHC_PACKAGE)" "YES"
932 $(odir)/main/Config.$(way_)o: SRC_HC_OPTS+=-DSTAGE=$(DQ)$(stage)$(DQ)
934 #-----------------------------------------------------------------------------
937 ifeq "$(DOING_BIN_DIST)" "YES"
938 # This is derived from the sources when we are in a source tree, but we
939 # don't have any sources in a bindist, so we have to shortcut it
940 HS_IFACES := $(wildcard stage$(stage)/*/*.hi)
944 $(INSTALL_DIR) $(BIN_DIST_DIR)/compiler
945 $(INSTALL_DIR) $(BIN_DIST_DIR)/compiler/stage$(stage)
946 echo "stage=$(stage)" > $(BIN_DIST_DIR)/compiler/Makefile
947 cat Makefile >> $(BIN_DIST_DIR)/compiler/Makefile
948 $(INSTALL_DATA) package.conf.in $(BIN_DIST_DIR)/compiler/
949 set -e; for d in stage$(stage)/*/; do $(INSTALL_DIR) $(BIN_DIST_DIR)/compiler/$$d; done
950 set -e; for f in $(HS_IFACES); do $(INSTALL_DATA) $$f $(BIN_DIST_DIR)/compiler/$$f; done
951 ifneq "$(INSTALL_LIBS)" ""
952 set -e; for f in $(INSTALL_LIBS); do $(INSTALL_DATA) $$f $(BIN_DIST_DIR)/compiler/$$f; done
954 ifneq "$(INSTALL_PROGS)" ""
955 set -e; for f in $(INSTALL_PROGS); do $(INSTALL_PROGRAM) $$f $(BIN_DIST_DIR)/compiler/$$f; done
957 ifneq "$(INSTALL_LIBEXECS)" ""
958 set -e; for f in $(INSTALL_LIBEXECS); do $(INSTALL_PROGRAM) $$f $(BIN_DIST_DIR)/compiler/$$f; done
961 # -----------------------------------------------------------------------------
962 # Explicit dependencies
964 # Some .hs files #include other source files, but since ghc -M doesn't spit out
965 # these dependencies we have to include them manually.
967 # We don't add dependencies on HsVersions.h, ghcautoconf.h, or ghc_boot_platform.h,
968 # because then modifying one of these files would force recompilation of everything,
969 # which is probably not what you want. However, it does mean you have to be
970 # careful to recompile stuff you need if you reconfigure or change HsVersions.h.
972 # Aargh, these don't work properly anyway, because GHC's recompilation checker
973 # just reports "compilation NOT required". Do we have to add -no-recomp for each
974 # of these .hs files? I haven't done anything about this yet.
976 $(odir)/codeGen/Bitmap.$(way_)o : ../includes/MachDeps.h
977 $(odir)/codeGen/CgCallConv.$(way_)o : ../includes/StgFun.h
978 $(odir)/codeGen/CgProf.$(way_)o : ../includes/MachDeps.h
979 $(odir)/codeGen/CgProf.$(way_)o : ../includes/Constants.h
980 $(odir)/codeGen/CgProf.$(way_)o : ../includes/DerivedConstants.h
981 $(odir)/codeGen/CgTicky.$(way_)o : ../includes/DerivedConstants.h
982 $(odir)/codeGen/ClosureInfo.$(way_)o : ../includes/MachDeps.h
983 $(odir)/codeGen/SMRep.$(way_)o : ../includes/MachDeps.h
984 $(odir)/codeGen/SMRep.$(way_)o : ../includes/ClosureTypes.h
985 $(odir)/ghci/ByteCodeAsm.$(way_)o : ../includes/Bytecodes.h
986 $(odir)/ghci/ByteCodeFFI.$(way_)o : nativeGen/NCG.h
987 $(odir)/ghci/ByteCodeInstr.$(way_)o : ../includes/MachDeps.h
988 $(odir)/ghci/ByteCodeItbls.$(way_)o : ../includes/ClosureTypes.h
989 $(odir)/ghci/ByteCodeItbls.$(way_)o : nativeGen/NCG.h
990 $(odir)/main/Constants.$(way_)o : ../includes/MachRegs.h
991 $(odir)/main/Constants.$(way_)o : ../includes/Constants.h
992 $(odir)/main/Constants.$(way_)o : ../includes/MachDeps.h
993 $(odir)/main/Constants.$(way_)o : ../includes/DerivedConstants.h
994 $(odir)/main/Constants.$(way_)o : ../includes/GHCConstants.h
995 $(odir)/nativeGen/AsmCodeGen.$(way_)o : nativeGen/NCG.h
996 $(odir)/nativeGen/MachCodeGen.$(way_)o : nativeGen/NCG.h
997 $(odir)/nativeGen/MachCodeGen.$(way_)o : ../includes/MachDeps.h
998 $(odir)/nativeGen/MachInstrs.$(way_)o : nativeGen/NCG.h
999 $(odir)/nativeGen/MachRegs.$(way_)o : nativeGen/NCG.h
1000 $(odir)/nativeGen/MachRegs.$(way_)o : ../includes/MachRegs.h
1001 $(odir)/nativeGen/PositionIndependentCode.$(way_)o : nativeGen/NCG.h
1002 $(odir)/nativeGen/PprMach.$(way_)o : nativeGen/NCG.h
1003 $(odir)/nativeGen/RegAllocInfo.$(way_)o : nativeGen/NCG.h
1004 $(odir)/typecheck/TcForeign.$(way_)o : nativeGen/NCG.h
1005 $(odir)/utils/Binary.$(way_)o : ../includes/MachDeps.h
1006 $(odir)/utils/FastMutInt.$(way_)o : ../includes/MachDeps.h
1008 # -----------------------------------------------------------------------------
1011 MKDEPENDHS_HC_OPTS = $(patsubst -i$(odir)/%, -i%, $(HC_OPTS))
1015 # Must do this *after* including target.mk, because $(HS_SRCS) isn't set yet.
1016 depend :: $(STAGE_PLATFORM_H) $(HS_SRCS) $(C_SRCS)
1018 ifneq "$(BootingFromHc)" "YES"
1019 $(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)
1021 $(MKDEPENDC) -f .depend-BASE $(MKDEPENDC_OPTS) $(foreach way,$(WAYS),-s $(way)) -- $(CC_OPTS) -- $(C_SRCS)
1022 $(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)
1023 # The binmode stuff tells perl not to add stupid ^M's to the output
1025 # The /lib/compat replacement is to workaround a bug in the
1026 # -optdep--exclude-module flag in GHC 6.4. It is not required for any
1027 # other version of GHC, but doesn't do any harm.
1029 ifeq "$(MakefileDeps)" "YES"
1030 $(CONFIG_HS) : Makefile
1031 stage1/$(PLATFORM_H) : Makefile
1032 stage2/$(PLATFORM_H) : Makefile
1035 -include .depend-$(stage)