Enable shared libs on OpenBSD
[ghc-hetmet.git] / mk / config.mk.in
index e8429e9..3882c26 100644 (file)
@@ -12,9 +12,7 @@
 # DO NOT EDIT THIS FILE!
 #
 #      - config.mk is auto-generated from config.mk.in by configure.
-#        This may be triggered automatically by the build system (say
-#        if config.mk.in has changed more recently than config.mk),
-#        so if you edit config.mk your changes will be spammed.
+#        If you edit config.mk your changes will be spammed.
 #
 #      - Settings in this file may be overriden by giving replacement
 #        definitions in build.mk.  See build.mk.sample for a good
 #
 #        If you don't have a build.mk file then you get defaults for everything.
 #        The defaults should provide a reasonable vanilla build.
-#
-# This is one of only two files that configure generates (the other is config.h)
-#
 
-ifneq "$(findstring 3.7, $(MAKE_VERSION))" ""
-ifeq "$(findstring 3.79.1, $(MAKE_VERSION))" ""
-$(error GNU make version 3.79.1 or later is required.)
-endif
-endif
-
-################################################################################
-#
-# GHC Version
-#
-
-# ProjectVersion    is treated as a *string*
-# ProjectVersionInt is treated as an *integer* (for cpp defines)
+# TOP: the top of the fptools hierarchy, absolute path.
+# On Windows this is a c:/foo/bar style path.
+TOP            = @hardtop@
 
-# Versioning scheme: A.B.C
-#         A: major version, decimal, any number of digits
-#         B: minor version, decimal, any number of digits
-#        C: patchlevel, one digit, omitted if zero.
-#
-# ProjectVersionInt does *not* contain the patchlevel (rationale: this
-# figure is used for conditional compilations, and library interfaces
-# etc. are not supposed to change between patchlevels).
-#
-# The ProjectVersionInt is included in interface files, and GHC
-# checks that it's reading interface generated by the same ProjectVersion
-# as itself. It does this even though interface file syntax may not 
-# change between versions.  Rationale: calling conventions or other 
-# random .o-file stuff might change even if the .hi syntax doesn't
-
-ProjectName       = @ProjectName@
-ProjectTags       =
-ProjectVersion    = @ProjectVersion@$(ProjectTags)
-ProjectVersionInt = @ProjectVersionInt@
-ProjectPatchLevel = @ProjectPatchLevel@
-
-################################################################################
-#
-#              Platform variables
-#
-################################################################################
-
-# A "platform" is the GNU cpu-type/manufacturer/operating-system target machine
-# specifier.  E.g. sparc-sun-solaris2
-#
-# Build  platform: the platform on which we are doing this build
-# Host   platform: the platform on which these binaries will run
-# Target platform: the platform for which this compiler will generate code
-#
-# We don't support build & host being different, because the build
-# process creates binaries that are run during the build, and also
-# installed.
-#
-# If host & target are different, then we are building a compiler
-# which will generate intermediate .hc files to port to the target
-# architecture for bootstrapping.  The libraries and stage 2 compiler
-# will be built as HC files for the target system, and likely won't
-# build on this host platform.
-#
-# An important invariant is that for any piece of source code, the
-# platform on which the code is going to run is the HOST platform,
-# and the platform on which we are building is the BUILD platform.
-# Additionally for the compiler, the platform this compiler will
-# generate code for is the TARGET.  TARGET is not meaningful outside
-# the compiler sources.
-#
-# Guidelines for when to use HOST vs. TARGET:
-#
-#  - In the build system (Makefile, foo.mk), normally we should test
-#    $(HOSTPLATFORM).  There are some cases (eg. installation), where
-#    we expect $(HOSTPLATFORM)==$(TARGETPLATFORM), so in those cases it
-#    doesn't matter which is used.
-#
-#  - In the compiler itself, we should test HOST or TARGET depending
-#    on whether the conditional relates to the code being generated, or
-#    the platform on which the compiler is running.  See the section
-#    on "Coding Style" in the commentary for more details.
-#
-#  - In all other code, we should be testing HOST only.
-#
-# NOTE: cross-compiling is not well supported by the build system.
-# You have to do a lot of work by hand to cross compile: see the
-# section on "Porting GHC" in the Building Guide.
-
-HOSTPLATFORM                   = @HostPlatform@
-TARGETPLATFORM                 = @TargetPlatform@
-BUILDPLATFORM                  = @BuildPlatform@
-
-# Hack alert:
-# in one or two places, we need to get at the OS version (major and
-# perhaps even minor), HostOS_Full is the OS name reported by
-# AC_CANONICAL_SYSTEM.
-#
-HostPlatform_CPP               = @HostPlatform_CPP@
-HostArch_CPP                   = @HostArch_CPP@
-HostOS_CPP                     = @HostOS_CPP@
-HostOS_Full                    = @HostOS_Full@
-HostVendor_CPP                 = @HostVendor_CPP@
-
-TargetPlatform_CPP             = @TargetPlatform_CPP@
-TargetArch_CPP                 = @TargetArch_CPP@
-TargetOS_CPP                   = @TargetOS_CPP@
-TargetVendor_CPP                = @TargetVendor_CPP@
-
-BuildPlatform_CPP              = @BuildPlatform_CPP@
-BuildArch_CPP                  = @BuildArch_CPP@
-BuildOS_CPP                    = @BuildOS_CPP@
-BuildVendor_CPP                 = @BuildVendor_CPP@
-
-@HostPlatform_CPP@_HOST           = 1
-@TargetPlatform_CPP@_TARGET       = 1
-@BuildPlatform_CPP@_BUILD         = 1
-
-@HostArch_CPP@_HOST_ARCH          = 1
-@TargetArch_CPP@_TARGET_ARCH      = 1
-@BuildArch_CPP@_BUILD_ARCH        = 1
-
-@HostOS_CPP@_HOST_OS              = 1
-@TargetOS_CPP@_TARGET_OS          = 1
-@BuildOS_CPP@_BUILD_OS            = 1
-
-@HostVendor_CPP@_HOST_VENDOR      = 1
-@TargetVendor_CPP@_TARGET_VENDOR  = 1
-@BuildVendor_CPP@_BUILD_VENDOR    = 1
+include $(TOP)/mk/project.mk
 
 ################################################################################
 #
@@ -156,37 +33,12 @@ BuildVendor_CPP                 = @BuildVendor_CPP@
 #
 ################################################################################
 
-# Leading underscores on symbol names in object files
-# Valid options: YES/NO
-#
-LeadingUnderscore=@LeadingUnderscore@
-
-# Pin a suffix on executables? If so, what (Windows only).
-exeext=@exeext@
-soext=@soext@
-
-# Windows=YES if on a Windows platform
-ifneq "$(findstring $(HostOS_CPP), mingw32 cygwin32)" ""
-Windows=YES
-else
-Windows=NO
-endif
-
 # BootingFromHc - build GHC and the libraries from .hc files?
+# (unregisterised only)
 BootingFromHc = @BootingFromHc@
 
-# BootingFromUnregisterisedHc - treat .hc files as containing unregisterised
-# rather than registerised code, i.e., disable the mangler?
-BootingFromUnregisterisedHc = @BootingFromUnregisterisedHc@
-
-#
-# Which ways should DocBook XML documents be built?
-# options are: dvi ps pdf html chm HxS
-#
-XMLDocWays=
-
-# Should we build haddock docs?
-HADDOCK_DOCS = YES
+NO_INCLUDE_DEPS = NO
+NO_INCLUDE_PKGDATA = NO
 
 # Should we build latex docs?
 LATEX_DOCS = NO
@@ -245,14 +97,19 @@ GhcStage1HcOpts=
 GhcStage2HcOpts=-O2
 GhcStage3HcOpts=-O2
 
-GhcProfiled=NO
 GhcDebugged=NO
-GhcLibProfiled=$(if $(filter p,$(GhcLibWays)),YES,NO)
+GhcDynamic=NO
+
+# GhcProfiled=YES means compile a profiled stage-2 compiler
+GhcProfiled=NO
 
-# Build shared and/or static libs?
-BuildSharedLibs=@BuildSharedLibs@
-# ToDo later:
-# BuildStaticLibs=@BuildStaticLibs@
+# Do we support shared libs?
+PlatformSupportsSharedLibs = $(if $(filter $(TARGETPLATFORM),\
+       i386-unknown-linux x86_64-unknown-linux \
+       i386-unknown-freebsd x86_64-unknown-freebsd \
+       i386-unknown-openbsd x86_64-unknown-openbsd \
+       i386-unknown-mingw32 \
+       i386-apple-darwin powerpc-apple-darwin),YES,NO)
 
 # Build a compiler that will build *unregisterised* libraries and
 # binaries by default.  Unregisterised code is supposed to compile and
@@ -279,9 +136,8 @@ endif
 #
 # Target platforms supported:
 #   i386, powerpc
-#   sparc has bitrotted
 #   AIX is not supported 
-ArchSupportsNCG=$(strip $(patsubst $(HostArch_CPP), YES, $(findstring $(HostArch_CPP), i386 x86_64 powerpc)))
+ArchSupportsNCG=$(strip $(patsubst $(HostArch_CPP), YES, $(findstring $(HostArch_CPP), i386 x86_64 powerpc sparc)))
 OsSupportsNCG=$(strip $(patsubst $(HostOS_CPP), YES, $(patsubst aix,,$(HostOS_CPP))))
 
 # lazy test, because $(GhcUnregisterised) might be set in build.mk later.
@@ -289,10 +145,13 @@ GhcWithNativeCodeGen=$(strip\
     $(if $(filter YESYESNO,\
                  $(OsSupportsNCG)$(ArchSupportsNCG)$(GhcUnregisterised)),YES,NO))
 
+# Build a compiler with the llvm code generator backend
+GhcWithLlvmCodeGen=NO
+
 HaveLibDL = @HaveLibDL@
 
 # ArchSupportsSMP should be set iff there is support for that arch in
-# includes/SMP.h
+# includes/stg/SMP.h
 ArchSupportsSMP=$(strip $(patsubst $(HostArch_CPP), YES, $(findstring $(HostArch_CPP), i386 x86_64 sparc powerpc)))
 
 # lazy test, because $(GhcUnregisterised) might be set in build.mk later.
@@ -301,7 +160,7 @@ GhcWithSMP=$(strip $(if $(filter YESNO, $(ArchSupportsSMP)$(GhcUnregisterised)),
 # Whether to include GHCi in the compiler.  Depends on whether the RTS linker
 # has support for this OS/ARCH combination.
 
-OsSupportsGHCi=$(strip $(patsubst $(HostOS_CPP), YES, $(findstring $(HostOS_CPP), mingw32 cygwin32 linux solaris2 freebsd netbsd openbsd darwin)))
+OsSupportsGHCi=$(strip $(patsubst $(HostOS_CPP), YES, $(findstring $(HostOS_CPP), mingw32 cygwin32 linux solaris2 freebsd dragonfly netbsd openbsd darwin)))
 ArchSupportsGHCi=$(strip $(patsubst $(HostArch_CPP), YES, $(findstring $(HostArch_CPP), i386 x86_64 powerpc sparc sparc64)))
 
 ifeq "$(OsSupportsGHCi)$(ArchSupportsGHCi)" "YESYES"
@@ -321,6 +180,16 @@ else
 GhcEnableTablesNextToCode=YES
 endif
 
+# Whether to use libffi for adjustors (foreign import "wrapper") or
+# not.  If we have built-in support (rts/Adjustor.c) then we use that,
+# otherwise we fall back on libffi, which is slightly slower.
+ArchHasAdjustorSupport = $(if $(findstring $(HostArch_CPP),i386 x86_64),YES,NO)
+ifeq "$(ArchHasAdjustorSupport)" "YES"
+UseLibFFIForAdjustors=NO
+else
+UseLibFFIForAdjustors=YES
+endif
+
 # On Windows we normally want to make a relocatable bindist, to we
 # ignore flags like libdir
 ifeq "$(Windows)" "YES"
@@ -329,6 +198,9 @@ else
 RelocatableBuild = NO
 endif
 
+# needs to be after $(RelocatableBuild) is set above
+include $(TOP)/mk/install.mk
+
 # When building bindists we set this to yes so that the binaries are as
 # portable as possible.
 BeConservative = NO
@@ -339,45 +211,28 @@ BeConservative = NO
 BuildingParallel=$(subst mp,YES,$(filter mp,$(WAYS)))
 BuildingGranSim=$(subst mg,YES,$(filter mg,$(WAYS)))
 
-# Interface file version (hi-boot files only)
-#
-# A GHC built with HscIfaceFileVersion=n will look for 
-#      M.hi-boot-n, and only then for 
-#      M.hi-boot.
-# (It'll be happy with the latter if the former doesn't exist.)
-#
-#
-# This variable is used ONLY for hi-boot files.  Its only purpose is
-# to allow you to have a single directory with multiple .hi-boot files
-# for the same module, each corresponding to a different version of
-# GHC.
-#
-# HscIfaceFileVersion is propagated to hsc via
-# compiler/main/Config.hs, which is automatically generated by
-# compiler/Makefile.
-
-HscIfaceFileVersion=6
-
 #------------------------------------------------------------------------------
 # Options for Libraries
 
 # Which directory (in libraries/) contains the integer library?
 INTEGER_LIBRARY=integer-gmp
 
-# What extra ways to build the libraries in
+# We build the libraries at least the "vanilla" way (way "v")
+GhcLibWays = v
+
 # In addition to the normal sequential way, the default is to also build
-# profiled prelude libraries.
-# When booting from .hc files, turn this off.
-ifeq "$(BootingFromHc)" "YES"
-GhcLibWays=
-else
-GhcLibWays=p
+# profiled prelude libraries unless we are booting from .hc files
+ifneq "$(BootingFromHc)" "YES"
+GhcLibWays += p
 endif
 
-ifeq "$(BuildSharedLibs)" "YES"
+ifeq "$(PlatformSupportsSharedLibs)" "YES"
 GhcLibWays += dyn
 endif
 
+# Handy way to test whether we're building shared libs or not.
+BuildSharedLibs=$(strip $(if $(findstring dyn,$(GhcLibWays)),YES,NO))
+
 # In addition, the RTS is built in some further variations.  Ways that
 # make sense here:
 # 
@@ -387,24 +242,22 @@ endif
 #   debug_p     : debugging profiled
 #   thr_debug   : debugging threaded
 #   thr_debug_p : debugging threaded profiled
-#   t          : ticky-ticky profiling
-#   debug_t    : debugging ticky-ticky profiling
+#   l           : event logging
+#   thr_l       : threaded and event logging
 #
-GhcRTSWays=
+GhcRTSWays=l
 
 # Usually want the debug version
 ifeq "$(BootingFromHc)" "NO"
 GhcRTSWays += debug 
 endif
 
-ifeq "$(BuildSharedLibs)" "YES"
-GhcRTSWays += dyn debug_dyn thr_dyn thr_debug_dyn
-endif
-
 # Want the threaded versions unless we're unregisterised
 # Defer the check until later by using $(if..), because GhcUnregisterised might
 # be set in build.mk, which hasn't been read yet.
-GhcRTSWays += $(if $(findstring NO, $(GhcUnregisterised)),thr thr_p thr_debug,)
+GhcRTSWays += $(if $(findstring NO, $(GhcUnregisterised)),thr thr_debug thr_l,)
+GhcRTSWays += $(if $(findstring p, $(GhcLibWays)),$(if $(findstring NO, $(GhcUnregisterised)),thr_p,),)
+GhcRTSWays += $(if $(findstring dyn, $(GhcLibWays)), dyn debug_dyn $(if $(findstring NO, $(GhcUnregisterised)),thr_dyn thr_debug_dyn),)
 
 # We can only build GHCi threaded if we have a threaded RTS:
 GhcThreaded = $(if $(findstring thr,$(GhcRTSWays)),YES,NO)
@@ -422,10 +275,7 @@ GhcThreaded = $(if $(findstring thr,$(GhcRTSWays)),YES,NO)
 #              but we switch it on for the libraries so that we generate
 #              the code in case someone importing wants it
 
-GhcLibHcOpts=-O2 -Rghc-timing -XGenerics
-
-# Win32 only: Enable the RTS and libraries to be built as DLLs
-DLLized=@EnableWin32DLLs@
+GhcLibHcOpts=-O2 -XGenerics
 
 # Strip local symbols from libraries?  This can make the libraries smaller,
 # but makes debugging somewhat more difficult.  Doesn't work with all ld's.
@@ -445,25 +295,32 @@ PackageSourceURL = http://darcs.haskell.org/packages/$(PACKAGE)/%{FILE}
 #              system needs to do other special magic if you are
 #              doing object-file splitting
 
+ArchSupportsSplitObjs=$(strip $(if $(filter $(TargetArch_CPP),i386 x86_64 powerpc sparc),YES,NO))
+# Object splitting is disabled on darwin due to #4013
+OsSupportsSplitObjs=$(strip $(if $(filter $(TargetOS_CPP),mingw32 cygwin32 linux solaris2 freebsd dragonfly netbsd openbsd),YES,NO))
+
 # lazy test, so that $(GhcUnregisterised) can be set in build.mk
-SplitObjs=$(strip $(if $(filter $(TargetArch_CPP),i386 x86_64 powerpc sparc),\
-                   $(if $(filter YES,$(BootingFromHC)),\
-                     NO,\
-                     $(if $(filter NO,$(GhcUnregisterised)),\
-                       YES,\
-                       NO)),\
-                   NO))
-
-# Math library
-LIBM=@LIBM@
-
-# .NET interop support?
-#
-DotnetSupport=@DotnetSupport@
+SupportsSplitObjs=$(strip \
+                    $(if $(and $(filter YES,$(ArchSupportsSplitObjs)),\
+                               $(filter YES,$(OsSupportsSplitObjs)),\
+                               $(filter NO,$(BootingFromHc)),\
+                               $(filter NO,$(GhcUnregisterised))),\
+                          YES,NO))
 
-# Build unix package?
-#
-GhcLibsWithUnix=@GhcLibsWithUnix@
+# By default, enable SplitObjs for the libraries if this build supports it
+SplitObjs=$(SupportsSplitObjs)
+
+# ----------------------------------------------------------------------------
+# Package-related things
+
+# Extra packages to add to the build, in dependency order
+EXTRA_PACKAGES =
+
+# Whether to install $(EXTRA_PACKAGES)
+InstallExtraPackages = NO
+
+# Run "ghc-pkg check" on each package
+CHECK_PACKAGES = NO
 
 # ----------------------------------------------------------------------------
 # Options for GHC's RTS
@@ -484,38 +341,6 @@ PapiIncludeDir=
 
 ################################################################################
 #
-#              nofib
-#
-#      nofib specific options
-#
-################################################################################
-
-WithNofibHc = $(GHC_INPLACE)
-
-# NoFibSubDirs controls which set of tests should be run
-# You can run one or more of
-#      imaginary 
-#      spectral
-#      real
-#      parallel
-#      PRIVATE
-#      PENDING
-#      UNUSED
-NoFibSubDirs = imaginary spectral real
-
-# The different ways to build nofib. Default is just to mirror
-# what is done for the ghc prelude libraries.
-#
-NoFibWays = $(GhcLibWays)
-
-# Haskell compiler options for nofib
-NoFibHcOpts = -O
-
-# Number of times to run each program
-NoFibRuns = 5
-
-################################################################################
-#
 #              Paths (see paths.mk)
 #
 ################################################################################
@@ -538,162 +363,15 @@ ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
 DEFAULT_TMPDIR         = /C/TEMP
 endif
 
-# FPTOOLS_TOP_ABS: the top of the fptools hierarchy, absolute path.
-# On Windows this is a c:/foo/bar style path.
-FPTOOLS_TOP_ABS                = @hardtop@
-
-BIN_DIST_TOPDIR_ABS=$(FPTOOLS_TOP_ABS)
-BIN_DIST_DIR=$(BIN_DIST_TOPDIR_ABS)/$(BIN_DIST_NAME)
-
-BIN_DIST_NAME=ghc-$(ProjectVersion)
-BIN_DIST_TAR=$(FPTOOLS_TOP_ABS)/$(BIN_DIST_NAME)-$(TARGETPLATFORM).tar
-BIN_DIST_TAR_BZ2=$(BIN_DIST_TAR).bz2
-BIN_DIST_PREP_DIR=$(FPTOOLS_TOP_ABS)/bindist-prep
-BIN_DIST_PREP=$(BIN_DIST_PREP_DIR)/$(BIN_DIST_NAME)
-BIN_DIST_LIST=$(FPTOOLS_TOP_ABS)/bindist-list
-
-# Definition of installation directories, we don't use half of these, but since
-# the configure script has them on offer while passing through, we might as well
-# set them. Note that we have to be careful, because the GNU coding standards
-# have changed a bit over the course of time, and autoconf development reflects
-# this.
-#
-# A little bit of history regarding autoconf and GNU coding standards, use this
-# as a cheat-sheet for the stuff below:
-#
-# variable    | default < 2.60     | default >= 2.60
-# ------------+--------------------+--------------------------------------
-# exec_prefix | ${prefix}          | ${prefix}
-# libdir      | ${exec_prefix}/lib | ${exec_prefix}/lib
-# datarootdir | NONE!              | ${prefix}/share
-# datadir     | ${prefix}/share    | ${datarootdir}
-# infodir     | ${prefix}/info     | ${datarootdir}/info
-# mandir      | ${prefix}/man      | ${datarootdir}/man
-# docdir      | NONE!              | ${datarootdir}/doc/${PACKAGE_TARNAME}
-# htmldir     | NONE!              | ${docdir}
-# dvidir      | NONE!              | ${docdir}
-# pdfdir      | NONE!              | ${docdir}
-# psdir       | NONE!              | ${docdir}
-#
-# NOTE: The default e.g. ${docdir} above means that autoconf substitutes the
-# string "${docdir}", not the value of docdir! This is crucial for the GNU
-# coding standards.
-
-# This gets used in the default docdir when autoconf >= 2.60 is used
-PACKAGE_TARNAME := @PACKAGE_TARNAME@
-
-prefix          := @prefix@
-
-# New autoconf (>= 2.60?) make a configure with a --datarootdir=DIR flag.
-# However, in order to support older autoconf's we don't use it.
-# datarootdir is set lower down instead.
-# But, as datadir is defined in terms of datarootdir, we also need to
-# set it to the value (if any) that configure gives it here.
-datarootdir     := @datarootdir@
-
-exec_prefix     := @exec_prefix@
-bindir          := @bindir@
-datadir0        := @datadir@
-libdir0         := @libdir@
-includedir      := @includedir@
-mandir          := @mandir@
-dynlibdir       := @libdir@
-
-ifeq "$(RelocatableBuild)" "YES"
-
-# Hack: our directory layouts tend to be different on Windows, so
-# hack around configure's bogus assumptions here.
-datarootdir := $(prefix)
-datadir     := $(prefix)
-libdir      := $(prefix)
-
-docdir    := $(prefix)/doc
-htmldir   := $(docdir)
-dvidir    := $(docdir)
-pdfdir    := $(docdir)
-psdir     := $(docdir)
-
-else
-
-# Unix: override libdir and datadir to put ghc-specific stuff in
-# a subdirectory with the version number included.
-#
-# datadir is set to libdir here as GHC needs package.conf and unlit
-# to be in the same place (and things like ghc-pkg need to agree on
-# where package.conf is, so we just set it globally).
-#
-datarootdir := $(datadir0)
-libdir      := $(libdir0)/ghc-$(ProjectVersion)
-datadir     := $(libdir)
-
-# New autoconf (>= 2.60?) make a configure with --docdir=DIR etc flags.
-# However, in order to support older autoconf's we don't use them.
-
-#docdir    := @docdir@
-#htmldir   := @htmldir@
-#dvidir    := @dvidir@
-#pdfdir    := @pdfdir@
-#psdir     := @psdir@
-
-docdir    := $(datarootdir)/doc/ghc
-htmldir   := $(docdir)
-dvidir    := $(docdir)
-pdfdir    := $(docdir)
-psdir     := $(docdir)
-
-endif # Windows
-
-headerdir := $(libdir)/include
-
-# Default place for putting interface files is $(libdir)
-# (overriden for packages in package.mk)
-ifacedir               = $(libdir)
-
-# NOTE: by intention, libexecdir and libdir point to 
-# the same place.
-#  => Only way to override this is to set libexecdir= on the command line.
-#     (NOTE: configure script setting is ignored).
-libexecdir             = $(libdir)
-
-GHC_PKG_PROG = $(FPTOOLS_TOP_ABS)/$(GHC_PKG_DIR_REL)/install-inplace/bin/ghc-pkg
-
-#-----------------------------------------------------------------------------
-# install configuration
-
-#
-# Set this to have files installed with a specific owner
-#
-INSTALL_OWNER =
-
-# 
-# Set this to have files installed with a specific group
-#
-INSTALL_GROUP =
+BIN_DIST_NAME         = ghc-$(ProjectVersion)
+BIN_DIST_PREP_DIR     = bindistprep/$(BIN_DIST_NAME)
+BIN_DIST_PREP_TAR     = bindistprep/$(BIN_DIST_NAME)-$(TARGETPLATFORM).tar
+BIN_DIST_PREP_TAR_BZ2 = $(BIN_DIST_PREP_TAR).bz2
+BIN_DIST_TAR_BZ2      = $(BIN_DIST_NAME)-$(TARGETPLATFORM).tar.bz2
+BIN_DIST_LIST         = bindist-list
 
-#
-# Invocations of `install' for the four different classes
-# of targets:
-#
-INSTALL_PROGRAM = $(INSTALL) -m 755
-INSTALL_SCRIPT  = $(INSTALL) -m 755
-INSTALL_SHLIB   = $(INSTALL) -m 755
-INSTALL_DATA    = $(INSTALL) -m 644
-INSTALL_HEADER  = $(INSTALL) -m 644
-INSTALL_MAN     = $(INSTALL) -m 644
-INSTALL_DIR     = $(MKDIRHIER)
-
-#
-# runhaskell and hsc2hs are special, in that other compilers besides
-# GHC might provide them.  Systems with a package manager often come
-# with tools to manage this kind of clash, e.g. RPM's
-# update-alternatives.  When building a distribution for such a system,
-# we recommend setting both of the following to 'YES'.
-#
-# NO_INSTALL_RUNHASKELL = YES
-# NO_INSTALL_HSC2HS     = YES
-#
-# NB. we use negative tests here because for binary-distributions we cannot
-# test build-time variables at install-time, so they must default to on.
+WINDOWS_INSTALLER_BASE = ghc-$(ProjectVersion)-i386-windows
+WINDOWS_INSTALLER = $(WINDOWS_INSTALLER_BASE)$(exeext)
 
 # -----------------------------------------------------------------------------
 # Utilities programs: flags 
@@ -713,10 +391,6 @@ SRC_HC_OPTS += -H32m -O
 # These flags make flex 8-bit
 SRC_FLEX_OPTS  += -8
 
-# lint gets all CPP's flags too
-SRC_LINT_OPTS          += -axz -DLINT $(SRC_CPP_OPTS)
-WAY$(_way)_LINT_OPTS   += WAY$(_way)_CPP_OPTS
-
 # Default fptools options for dllwrap.
 SRC_BLD_DLL_OPTS += --target=i386-mingw32
 
@@ -724,127 +398,28 @@ SRC_BLD_DLL_OPTS += --target=i386-mingw32
 GC_CPP_OPTS += -P -E -x c -traditional -D__GLASGOW_HASKELL__
 
 
-################################################################################
-#
-#      Layout of the source tree
-#
-################################################################################
-
-# Here we provide defines for the various directories in the source tree,
-# so we can move things around more easily.  A define $(GHC_FOO_DIR_REL)
-# indicates a directory relative to the top of the source tree, whereas
-# $(GHC_FOO_DIR) is a directory relative to the current directory.
-# $(GHC_FOO_DIR_ABS) is the absolute path to the directory.
-
-GHC_UTILS_DIR_REL      = utils
-GHC_INCLUDE_DIR_REL    = includes
-GHC_COMPILER_DIR_REL = ghc
-GHC_RTS_DIR_REL                = rts
-GHC_UTILS_DIR_REL      = utils
-GHC_DRIVER_DIR_REL     = driver
-GHC_COMPAT_DIR_REL     = compat
-
-GHC_MKDEPENDC_DIR_REL  = $(GHC_UTILS_DIR_REL)/mkdependC
-GHC_LTX_DIR_REL                = $(GHC_UTILS_DIR_REL)/ltx
-GHC_RUNTEST_DIR_REL    = $(GHC_UTILS_DIR_REL)/runstdtest
-GHC_LNDIR_DIR_REL      = $(GHC_UTILS_DIR_REL)/lndir
-GHC_MKDIRHIER_DIR_REL  = $(GHC_UTILS_DIR_REL)/mkdirhier
-GHC_DOCBOOK_DIR_REL    = $(GHC_UTILS_DIR_REL)/docbook
-GHC_UNLIT_DIR_REL      = $(GHC_UTILS_DIR_REL)/unlit
-GHC_HP2PS_DIR_REL      = $(GHC_UTILS_DIR_REL)/hp2ps
-GHC_HSTAGS_DIR_REL     = $(GHC_UTILS_DIR_REL)/hasktags
-GHC_GHCTAGS_DIR_REL    = $(GHC_UTILS_DIR_REL)/ghctags
-GHC_HSC2HS_DIR_REL     = $(GHC_UTILS_DIR_REL)/hsc2hs
-GHC_TOUCHY_DIR_REL     = $(GHC_UTILS_DIR_REL)/touchy
-GHC_PKG_DIR_REL                = $(GHC_UTILS_DIR_REL)/ghc-pkg
-GHC_GENPRIMOP_DIR_REL  = $(GHC_UTILS_DIR_REL)/genprimopcode
-GHC_GENAPPLY_DIR_REL   = $(GHC_UTILS_DIR_REL)/genapply
-
-GHC_MANGLER_DIR_REL    = $(GHC_DRIVER_DIR_REL)/mangler
-GHC_SPLIT_DIR_REL      = $(GHC_DRIVER_DIR_REL)/split
-GHC_SYSMAN_DIR_REL     = $(GHC_RTS_DIR_REL)/parallel
-
-INPLACE_DATA_DIR       = $(FPTOOLS_TOP_ABS)/inplace-datadir
-
-GHC_UTILS_DIR          = $(FPTOOLS_TOP)/$(GHC_UTILS_DIR_REL)
-GHC_INCLUDE_DIR                = $(FPTOOLS_TOP)/$(GHC_INCLUDE_DIR_REL)
-GHC_COMPILER_DIR       = $(FPTOOLS_TOP)/$(GHC_COMPILER_DIR_REL)
-GHC_RTS_DIR            = $(FPTOOLS_TOP)/$(GHC_RTS_DIR_REL)
-GHC_UTILS_DIR          = $(FPTOOLS_TOP)/$(GHC_UTILS_DIR_REL)
-GHC_DRIVER_DIR         = $(FPTOOLS_TOP)/$(GHC_DRIVER_DIR_REL)
-GHC_COMPAT_DIR         = $(FPTOOLS_TOP)/$(GHC_COMPAT_DIR_REL)
-
-GHC_MKDEPENDC_DIR      = $(FPTOOLS_TOP)/$(GHC_MKDEPENDC_DIR_REL)
-GHC_LTX_DIR            = $(FPTOOLS_TOP)/$(GHC_LTX_DIR_REL)
-GHC_RUNTEST_DIR                = $(FPTOOLS_TOP)/$(GHC_RUNTEST_DIR_REL)
-GHC_LNDIR_DIR          = $(FPTOOLS_TOP)/$(GHC_LNDIR_DIR_REL)
-GHC_MKDIRHIER_DIR      = $(FPTOOLS_TOP)/$(GHC_MKDIRHIER_DIR_REL)
-GHC_DOCBOOK_DIR                = $(FPTOOLS_TOP)/$(GHC_DOCBOOK_DIR_REL)
-GHC_UNLIT_DIR          = $(FPTOOLS_TOP)/$(GHC_UNLIT_DIR_REL)
-GHC_HP2PS_DIR          = $(FPTOOLS_TOP)/$(GHC_HP2PS_DIR_REL)
-GHC_HSTAGS_DIR         = $(FPTOOLS_TOP)/$(GHC_HSTAGS_DIR_REL)
-GHC_GHCTAGS_DIR                = $(FPTOOLS_TOP)/$(GHC_GHCTAGS_DIR_REL)
-GHC_HSC2HS_DIR         = $(FPTOOLS_TOP_ABS)/$(GHC_HSC2HS_DIR_REL)
-GHC_TOUCHY_DIR         = $(FPTOOLS_TOP)/$(GHC_TOUCHY_DIR_REL)
-GHC_PKG_DIR            = $(FPTOOLS_TOP)/$(GHC_PKG_DIR_REL)
-GHC_GENPRIMOP_DIR      = $(FPTOOLS_TOP)/$(GHC_GENPRIMOP_DIR_REL)
-GHC_GENAPPLY_DIR       = $(FPTOOLS_TOP)/$(GHC_GENAPPLY_DIR_REL)
-
-GHC_MANGLER_DIR                = $(FPTOOLS_TOP)/$(GHC_MANGLER_DIR_REL)
-GHC_SPLIT_DIR          = $(FPTOOLS_TOP)/$(GHC_SPLIT_DIR_REL)
-GHC_SYSMAN_DIR         = $(FPTOOLS_TOP)/$(GHC_SYSMAN_DIR_REL)
-
-GHC_UTILS_DIR_ABS      = $(FPTOOLS_TOP_ABS)/$(GHC_UTILS_DIR_REL)
-GHC_INCLUDE_DIR_ABS    = $(FPTOOLS_TOP_ABS)/$(GHC_INCLUDE_DIR_REL)
-GHC_COMPILER_DIR_ABS   = $(FPTOOLS_TOP_ABS)/$(GHC_COMPILER_DIR_REL)
-GHC_RTS_DIR_ABS                = $(FPTOOLS_TOP_ABS)/$(GHC_RTS_DIR_REL)
-GHC_UTILS_DIR_ABS      = $(FPTOOLS_TOP_ABS)/$(GHC_UTILS_DIR_REL)
-GHC_DRIVER_DIR_ABS     = $(FPTOOLS_TOP_ABS)/$(GHC_DRIVER_DIR_REL)
-GHC_COMPAT_DIR_ABS     = $(FPTOOLS_TOP_ABS)/$(GHC_COMPAT_DIR_REL)
-
-GHC_MKDEPENDC_DIR_ABS  = $(FPTOOLS_TOP_ABS)/$(GHC_MKDEPENDC_DIR_REL)
-GHC_LTX_DIR_ABS                = $(FPTOOLS_TOP_ABS)/$(GHC_LTX_DIR_REL)
-GHC_RUNTEST_DIR_ABS    = $(FPTOOLS_TOP_ABS)/$(GHC_RUNTEST_DIR_REL)
-GHC_LNDIR_DIR_ABS      = $(FPTOOLS_TOP_ABS)/$(GHC_LNDIR_DIR_REL)
-GHC_MKDIRHIER_DIR_ABS  = $(FPTOOLS_TOP_ABS)/$(GHC_MKDIRHIER_DIR_REL)
-GHC_DOCBOOK_DIR_ABS    = $(FPTOOLS_TOP_ABS)/$(GHC_DOCBOOK_DIR_REL)
-GHC_UNLIT_DIR          = $(FPTOOLS_TOP_ABS)/$(GHC_UNLIT_DIR_REL)
-GHC_HP2PS_DIR_ABS      = $(FPTOOLS_TOP_ABS)/$(GHC_HP2PS_DIR_REL)
-GHC_HSTAGS_DIR_ABS     = $(FPTOOLS_TOP_ABS)/$(GHC_HSTAGS_DIR_REL)
-GHC_GHCTAGS_DIR_ABS    = $(FPTOOLS_TOP_ABS)/$(GHC_GHCTAGS_DIR_REL)
-GHC_HSC2HS_DIR_ABS     = $(FPTOOLS_TOP_ABS)/$(GHC_HSC2HS_DIR_REL)
-GHC_TOUCHY_DIR_ABS     = $(FPTOOLS_TOP_ABS)/$(GHC_TOUCHY_DIR_REL)
-GHC_PKG_DIR_ABS                = $(FPTOOLS_TOP_ABS)/$(GHC_PKG_DIR_REL)
-GHC_GENPRIMOP_DIR_ABS  = $(FPTOOLS_TOP_ABS)/$(GHC_GENPRIMOP_DIR_REL)
-GHC_GENAPPLY_DIR_ABS   = $(FPTOOLS_TOP_ABS)/$(GHC_GENAPPLY_DIR_REL)
-GHC_COMPILER_DIR_ABS   = $(FPTOOLS_TOP_ABS)/$(GHC_COMPILER_DIR_REL)
-
-GHC_MANGLER_DIR_ABS    = $(FPTOOLS_TOP_ABS)/$(GHC_MANGLER_DIR_REL)
-GHC_SYSMAN_DIR_ABS     = $(FPTOOLS_TOP_ABS)/$(GHC_SYSMAN_DIR_REL)
-GHC_SPLIT_DIR_ABS      = $(FPTOOLS_TOP_ABS)/$(GHC_SPLIT_DIR_REL)
-
 # -----------------------------------------------------------------------------
 # Names of programs in the GHC tree
 #
-#      xxx_PGM         the name of an executable, without the path
-#      xxx             the executable relative to the current dir
-
-GHC_UNLIT_PGM          = unlit$(exeext)
-GHC_HP2PS_PGM          = hp2ps
-GHC_HSTAGS_PGM         = hasktags
-GHC_GHCTAGS_INPLACE_PGM        = ghctags-inplace
-GHC_HSC2HS_INPLACE_PGM = hsc2hs
-GHC_TOUCHY_PGM         = touchy$(exeext)
-GHC_MANGLER_PGM                = ghc-asm
-GHC_SPLIT_PGM          = ghc-split
-GHC_SYSMAN_PGM                 = SysMan
-GHC_GENPRIMOP_PGM      = genprimopcode
-GHC_GENAPPLY_PGM       = genapply
-GHC_MKDEPENDC_PGM      = mkdependC
-GHC_LTX_PGM            = ltx
-GHC_MKDIRHIER_PGM      = mkdirhier
-GHC_LNDIR_PGM          = lndir
-GHC_RUNTEST_PGM                = runstdtest
+#      xxx_PGM          the name of an executable, without the path
+#      xxx              the executable relative to the current dir
+
+GHC_UNLIT_PGM           = unlit$(exeext)
+GHC_HP2PS_PGM           = hp2ps$(exeext)
+GHC_GHCTAGS_PGM         = ghctags$(exeext)
+GHC_HSC2HS_PGM          = hsc2hs$(exeext)
+GHC_TOUCHY_PGM          = touchy$(exeext)
+GHC_MANGLER_PGM         = ghc-asm
+GHC_SPLIT_PGM           = ghc-split
+GHC_SYSMAN_PGM          = SysMan
+GHC_GENPRIMOP_PGM       = genprimopcode$(exeext)
+GHC_GENAPPLY_PGM        = genapply$(exeext)
+GHC_CABAL_PGM           = ghc-cabal$(exeext)
+GHC_PKG_PGM             = ghc-pkg$(exeext)
+GHC_LTX_PGM             = ltx$(exeext)
+GHC_MKDIRHIER_PGM       = mkdirhier
+GHC_LNDIR_PGM           = lndir
+GHC_DUMMY_GHC_PGM       = dummy-ghc$(exeext)
 
 ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
 GHC_CP                 = "xcopy /y"
@@ -854,22 +429,23 @@ GHC_CP                    = $(CP)
 GHC_PERL               = $(PERL)
 endif
 
-UNLIT                  = $(GHC_UNLIT_DIR)/$(GHC_UNLIT_PGM)
 HP2PS                  = $(GHC_HP2PS_DIR)/$(GHC_HP2PS_PGM)
-HSTAGS                 = $(GHC_HSTAGS_DIR)/$(GHC_HSTAGS_PGM)
-GHCTAGS_INPLACE                = $(GHC_GHCTAGS_DIR)/$(GHC_GHCTAGS_INPLACE_PGM)
-HSC2HS_INPLACE         = $(GHC_HSC2HS_DIR)/install-inplace/bin/$(GHC_HSC2HS_INPLACE_PGM)
-MANGLER                        = $(GHC_MANGLER_DIR)/$(GHC_MANGLER_PGM)
-SPLIT                  = $(GHC_SPLIT_DIR)/$(GHC_SPLIT_PGM)
+MANGLER                        = $(INPLACE_LIB)/$(GHC_MANGLER_PGM)
+SPLIT                  = $(INPLACE_LIB)/$(GHC_SPLIT_PGM)
 SYSMAN                         = $(GHC_SYSMAN_DIR)/$(GHC_SYSMAN_PGM)
-GHC_PKG_INPLACE                = $(GHC_PKG_PROG)
-GENPRIMOP              = $(GHC_GENPRIMOP_DIR)/$(GHC_GENPRIMOP_PGM)
-GENAPPLY               = $(GHC_GENAPPLY_DIR)/$(GHC_GENAPPLY_PGM)
-MKDEPENDC              = $(GHC_MKDEPENDC_DIR)/$(GHC_MKDEPENDC_PGM)
 LTX                    = $(GHC_LTX_DIR)/$(GHC_LTX_PGM)
-MKDIRHIER              = $(GHC_MKDIRHIER_DIR)/$(GHC_MKDIRHIER_PGM)
 LNDIR                  = $(GHC_LNDIR_DIR)/$(GHC_LNDIR_PGM)
-RUNTEST                        = $(GHC_RUNTEST_DIR)/$(GHC_RUNTEST_PGM)
+
+UNLIT                  = $(INPLACE_LIB)/$(GHC_UNLIT_PGM)
+TOUCHY                  = $(INPLACE_LIB)/$(GHC_TOUCHY_PGM)
+MKDIRHIER              = $(INPLACE_BIN)/$(GHC_MKDIRHIER_PGM)
+GHC_CABAL_INPLACE      = $(INPLACE_BIN)/$(GHC_CABAL_PGM)
+GENAPPLY_INPLACE       = $(INPLACE_BIN)/$(GHC_GENAPPLY_PGM)
+GHC_PKG_INPLACE                = $(INPLACE_BIN)/$(GHC_PKG_PGM)
+GHCTAGS_INPLACE                = $(INPLACE_BIN)/$(GHC_GHCTAGS_PGM)
+HSC2HS_INPLACE         = $(INPLACE_BIN)/$(GHC_HSC2HS_PGM)
+GENPRIMOP_INPLACE      = $(INPLACE_BIN)/$(GHC_GENPRIMOP_PGM)
+DUMMY_GHC_INPLACE      = $(INPLACE_BIN)/$(GHC_DUMMY_GHC_PGM)
 
 GENERATED_FILE  = chmod a-w
 EXECUTABLE_FILE = chmod +x
@@ -886,7 +462,14 @@ EXECUTABLE_FILE = chmod +x
 # NOTE: Don't override $(GHC) in build.mk, use configure --with-ghc instead
 # (because the version numbers have to be calculated).
 
-GHC            = @WithGhc@
+GHC := @WithGhc@
+# If we have a make dependency on c:/ghc/ghc, and the file is actually
+# called c:/ghc/ghc.exe, then make will think that ghc doesn't exist
+# and that it doesn't know how to create it.
+ifneq "$(wildcard $(GHC).exe)" ""
+GHC := $(GHC).exe
+endif
+
 GhcDir          = $(dir $(GHC))
 
 # Set to YES if $(GHC) has the editline package installed
@@ -900,65 +483,33 @@ NHC               = @NHC@
 # tree).  We can refer to "this ghc" as $(GHC_INPLACE):
 
 GHC_INPLACE = $(GHC_STAGE1)
-GHC_STAGE1  = $(GHC_COMPILER_DIR_ABS)/stage1-inplace/ghc
-GHC_STAGE2  = $(GHC_COMPILER_DIR_ABS)/stage2-inplace/ghc
-GHC_STAGE3  = $(GHC_COMPILER_DIR_ABS)/stage3-inplace/ghc
-# XXX All those used to have -no-user-package-conf, but then we can't
-# pass them to Cabal
 
-BOOTSTRAPPING_CONF = $(FPTOOLS_TOP_ABS)/libraries/bootstrapping.conf
+GHC_STAGE0_ABS = $(GHC)
+GHC_STAGE1_ABS = $(TOP)/$(INPLACE_BIN)/ghc-stage1$(exeext)
+GHC_STAGE2_ABS = $(TOP)/$(INPLACE_BIN)/ghc-stage2$(exeext)
+GHC_STAGE3_ABS = $(TOP)/$(INPLACE_BIN)/ghc-stage3$(exeext)
 
-# NOTE: add -no-user-package-conf for stage 1-3 above, so that
-# we avoid picking up any packages the user might happen to have
-# installed for this GHC version.  They are bound to be incompatible
-# with the packages we built in the tree.
+GHC_STAGE0  = $(GHC)
+GHC_STAGE1  = $(INPLACE_BIN)/ghc-stage1$(exeext)
+GHC_STAGE2  = $(INPLACE_BIN)/ghc-stage2$(exeext)
+GHC_STAGE3  = $(INPLACE_BIN)/ghc-stage3$(exeext)
 
-ifeq "$(stage)" "2"
-  UseStage1 = YES
-endif
-ifneq "$(findstring YES, $(UseStage1) $(BootingFromHc))" ""
-
-# We are using the stage1 compiler to compile Haskell code, set up
-# some variables appropriately:
-HC             =$(GHC_STAGE1)
-MKDEPENDHS     =$(GHC_STAGE1)
-USE_NEW_MKDEPEND_FLAGS = YES
-GhcVersion     = @ProjectVersion@
-GhcPatchLevel  = @ProjectPatchLevel@
-# oops, these are wrong:
-GhcMajVersion  = @GhcMajVersion@
-GhcMinVersion  = @GhcMinVersion@
-
-ghc_ge_605 = YES
-ghc_ge_607 = YES
-ghc_ge_609 = YES
+# Install stage 2 by default, can be changed to 3
+INSTALL_GHC_STAGE=2
 
-else # not UseStage1 or BootingFromHc
+BOOTSTRAPPING_CONF = libraries/bootstrapping.conf
 
-# Some useful GHC version predicates:
-ghc_ge_605 = @ghc_ge_605@
-ghc_ge_607 = @ghc_ge_607@
-ghc_ge_609 = @ghc_ge_609@
+INPLACE_PACKAGE_CONF = $(INPLACE_LIB)/package.conf.d
 
-HC             = @WithHc@
-MKDEPENDHS     = $(GHC)
-USE_NEW_MKDEPEND_FLAGS = $(ghc_ge_609)
 GhcVersion     = @GhcVersion@
 GhcPatchLevel  = @GhcPatchLevel@
 GhcMajVersion  = @GhcMajVersion@
 GhcMinVersion  = @GhcMinVersion@
 
-# We build a few packages using the installed GHC as part of the
-# bootstrapping process.  These are installed into a local
-# package.conf file, $(BOOTSTRAPPING_CONF).  When we invoke the
-# installed GHC we need to pass it -package-conf $(BOOTSTRAPPING_CONF).
-# So the following variables expand to -package-conf $(BOOTSTRAPPING_CONF)
-# when $(HC) does *not* point to one of the GHC binaries built in
-# the local tree.
-#
-BOOTSTRAPPING_PACKAGE_CONF_HC_OPTS =$(if $(findstring inplace, $(HC)),,-package-conf $(BOOTSTRAPPING_CONF))
-BOOTSTRAPPING_PACKAGE_CONF_MKDEPENDHS_OPTS =$(if $(findstring inplace, $(MKDEPENDHS)),,-package-conf $(BOOTSTRAPPING_CONF))
-endif
+# Keep this in sync with the variables in package-config.mk
+ghc_ge_6102 = @ghc_ge_6102@
+ghc_ge_611 = @ghc_ge_611@
+ghc_ge_613 = @ghc_ge_613@
 
 # Canonicalised ghc version number, used for easy (integer) version
 # comparisons.  We must expand $(GhcMinVersion) to two digits by
@@ -980,43 +531,37 @@ HaveGcc   = @HaveGcc@
 UseGcc         = YES
 WhatGccIsCalled = @WhatGccIsCalled@
 GccVersion      = @GccVersion@
+GccLT34                = @GccLT34@
 ifeq "$(strip $(HaveGcc))" "YES"
 ifneq "$(strip $(UseGcc))"  "YES"
   CC   = cc
 else
   CC   = $(WhatGccIsCalled)
-  GccDir = $(dir $(WhatGccIsCalled))
 endif
 endif
 
-# default C compiler flags
-SRC_CC_OPTS = @SRC_CC_OPTS@
+# C compiler and linker flags from configure (e.g. -m<blah> to select
+# correct C compiler backend). The stage number is the stage of GHC
+# that is being used to compile with.
+CONF_CC_OPTS_STAGE0 = @CONF_CC_OPTS_STAGE0@
+CONF_CC_OPTS_STAGE1 = @CONF_CC_OPTS_STAGE1@
+CONF_CC_OPTS_STAGE2 = @CONF_CC_OPTS_STAGE2@
+CONF_LD_OPTS_STAGE0 = @CONF_LD_OPTS_STAGE0@
+CONF_LD_OPTS_STAGE1 = @CONF_LD_OPTS_STAGE1@
+CONF_LD_OPTS_STAGE2 = @CONF_LD_OPTS_STAGE2@
 
 ifeq "$(TARGETPLATFORM)" "ia64-unknown-linux"
-SRC_CC_OPTS += -G0
+CONF_CC_OPTS += -G0
 endif
 
-SRC_HSC2HS_OPTS += $(addprefix --cflag=,$(filter-out -O,$(SRC_CC_OPTS)))
+SRC_HSC2HS_OPTS += $(addprefix --cflag=,$(filter-out -O,$(SRC_CC_OPTS) $(CONF_CC_OPTS_STAGE0)))
 SRC_HSC2HS_OPTS += $(foreach d,$(GMP_INCLUDE_DIRS),-I$(d))
 
 #-----------------------------------------------------------------------------
-# GMP Library (version 2.0.x or above)
-#
-HaveLibGmp     = @HaveLibGmp@
-LibGmp         = @LibGmp@
-
-GMP_INCLUDE_DIRS=@GMP_INCLUDE_DIRS@
-GMP_LIB_DIRS=@GMP_LIB_DIRS@
-
-#-----------------------------------------------------------------------------
-# GMP framework (Mac OS X)
-#
-HaveFrameworkGMP = @HaveFrameworkGMP@
-
-#-----------------------------------------------------------------------------
 # Mingwex Library
 #
 HaveLibMingwEx = @HaveLibMingwEx@
+DLLTOOL                        = inplace/mingw/bin/dlltool.exe
 
 #-----------------------------------------------------------------------------
 # Flex (currently unused, could be moved to glafp-utils)
@@ -1030,12 +575,16 @@ HaveLibMingwEx   = @HaveLibMingwEx@
 # Other standard (ha!) Unix utilities
 
 AR                     = @ArCmd@
+AR_OPTS                        = @ArArgs@
 ArSupportsInput                = @ArSupportsInput@
+ArSupportsAtFile = @ArSupportsAtFile@
 # Yuckage: for ghc/utils/parallel -- todo: nuke this dependency!!
 BASH                    = /usr/local/bin/bash
 
 CONTEXT_DIFF           = @ContextDiffCmd@
 CP                     = cp
+# It's not easy to separate the CPP program from its flags, as
+# AC_PROG_CPP defines CPP as "/usr/bin/gcc -E"
 CPP                    = @CPP@ @CPPFLAGS@
 CTAGS                  = $(ETAGS)
 #
@@ -1051,13 +600,11 @@ INSTALL                  = @INSTALL@
 # install-sh script (if chosen). This not terribly useful to us, so we convert
 # it into an abs. path.
 # 
-INSTALL                        := $(subst .././install-sh,$(FPTOOLS_TOP_ABS)/install-sh,$(INSTALL))
+INSTALL                        := $(subst .././install-sh,$(TOP)/install-sh,$(INSTALL))
 LATEX                  = latex
-HEVEA                  = hevea
-HACHA                  = hacha
+PDFLATEX        = pdflatex
+BIBTEX          = bibtex
 LN_S                   = @LN_S@
-MANMACROS              = -man
-MSMACROS               = -ms
 MV                     = mv
 NROFF                  = nroff
 PERL                   = @PerlCmd@
@@ -1065,11 +612,15 @@ PYTHON                   = @PythonCmd@
 PIC                    = pic
 PREPROCESSCMD          = $(CC) -E
 RANLIB                 = @RANLIB@
-RM                     = rm -f
 SED                    = @SedCmd@
+TR                     = tr
 SHELL                  = /bin/sh
 
-LD                     = @LdCmd@
+HaveDtrace             = @HaveDtrace@
+DTRACE                 = @DtraceCmd@
+
+LD = @LdCmd@
+NM = @NmCmd@
 
 # Some ld's support the -x flag and some don't, so the configure
 # script detects which we have and sets LdXFlag to "-x" or ""
@@ -1080,6 +631,17 @@ LD_X                      = @LdXFlag@
 # overflowing command-line length limits.
 LdIsGNULd              = @LdIsGNULd@
 
+# On MSYS, building with SplitObjs=YES fails with 
+#   ar: Bad file number
+# see #3201.  We need to specify a smaller max command-line size
+# to work around it.  32767 doesn't work; 30000 does, but says
+#     xargs: value for -s option should be < 28153
+# so we now use 20000 to be comfortably below this bound
+XARGS = xargs
+ifeq "$(Windows)" "YES"
+XARGS_OPTS = -s 20000
+endif
+
 #
 # In emergency situations, REAL_SHELL is used to perform shell commands
 # from within the ghc driver script, by scribbling the command line to
@@ -1102,50 +664,39 @@ LdIsGNULd                = @LdIsGNULd@
 # with REAL_SHELL set to something else than /bin/sh, for instance, your favourite
 # command shell.
 #
-REAL_SHELL=$(SHELL)
-SIZE                   = size
-STRIP                  = strip
-TAR                    = @TarCmd@
-ZIP                    = zip
+REAL_SHELL     = $(SHELL)
 
-HSCOLOUR = @HSCOLOUR@
+STRIP_CMD      = strip
+PATCH_CMD      = @PatchCmd@
+TAR_CMD        = @TarCmd@
+BZIP2_CMD      = bzip2
+GZIP_CMD       = gzip
 
-#
-# This is special to literate/, ToDo: add literate-specific
-# configure setup to literate/.
-#
-TBL                    = tbl
-TEX                    = tex
-TGRIND                         = tgrind
-TGRIND_HELPER          = /usr/local/lib/tgrind/tfontedpr # XXX
-TIB                    = tib
+HSCOLOUR_CMD   = @HSCOLOUR@
 
-TIME                   = @TimeCmd@
-TROFF                  = troff
-UNAME                  = uname
+TIME_CMD       = @TimeCmd@
 
 # GTK+
-GTK_CONFIG = @GTK_CONFIG@
+GTK_CONFIG_CMD = @GTK_CONFIG@
 
 # Set this if you want to use Inno Setup to build a Windows installer
 # when you make a bindist
-ISCC                    =
+ISCC_CMD       =
 
 #-----------------------------------------------------------------------------
 # DocBook XML stuff
 
-XSLTPROC               = @XsltprocCmd@
-XMLLINT                        = @XmllintCmd@
-FOP                    = @FopCmd@
-XMLTEX                 = @XmltexCmd@
-PDFXMLTEX              = @PdfxmltexCmd@
-DVIPS                  = @DvipsCmd@
-
-DIR_DOCBOOK_XSL                = @DIR_DOCBOOK_XSL@
-
-XSLTPROC_LABEL_OPTS    = --stringparam toc.section.depth 3 \
-                         --stringparam section.autolabel 1 \
-                         --stringparam section.label.includes.component.label 1
+BUILD_DOCBOOK_HTML       = @BUILD_DOCBOOK_HTML@
+BUILD_DOCBOOK_PS         = @BUILD_DOCBOOK_PS@
+BUILD_DOCBOOK_PDF        = @BUILD_DOCBOOK_PDF@
+DBLATEX                  = @DblatexCmd@
+XSLTPROC                 = @XsltprocCmd@
+XMLLINT                  = @XmllintCmd@
+HAVE_DOCBOOK_XSL        = @HAVE_DOCBOOK_XSL@
+XSLTPROC_HTML_STYLESHEET = http://docbook.sourceforge.net/release/xsl/current/html/chunk.xsl
+XSLTPROC_LABEL_OPTS     = --stringparam toc.section.depth 3 \
+                          --stringparam section.autolabel 1 \
+                          --stringparam section.label.includes.component.label 1
 
 #-----------------------------------------------------------------------------
 #              FPtools support software
@@ -1153,23 +704,11 @@ XSLTPROC_LABEL_OPTS      = --stringparam toc.section.depth 3 \
 BLD_DLL                        = dllwrap
 
 #
-# .NET support software
-#
-ILX2IL                  = ilx2il
-ILASM                   = ilasm
-
-#
 # ghc-pkg
 #
 GHC_PKG                        = @GhcPkgCmd@
 
 #
-# GreenCard
-#
-GREENCARD              = @GreenCardCmd@
-GREENCARD_VERSION      = @GreenCardVersion@            
-
-#
 # Happy
 #
 HAPPY                  = @HappyCmd@
@@ -1177,11 +716,11 @@ HAPPY_VERSION            = @HappyVersion@
 #
 # Options to pass to Happy when we're going to compile the output with GHC
 #
-GHC_HAPPY_OPTS         = -agc --strict
+SRC_HAPPY_OPTS         = -agc --strict
 
 # Temp. to work around performance problems in the HEAD around 8/12/2003,
 # A Happy compiled with this compiler needs more stack.
-SRC_HAPPY_OPTS         = +RTS -K2m -RTS
+SRC_HAPPY_OPTS         += +RTS -K2m -RTS
 
 #
 # Alex
@@ -1191,162 +730,18 @@ ALEX_VERSION            = @AlexVersion@
 #
 # Options to pass to Happy when we're going to compile the output with GHC
 #
-GHC_ALEX_OPTS          = -g
+SRC_ALEX_OPTS          = -g
 
-#
-# Options for compiling in different `ways'. 
-# 
-# To configure up your own way, have a look at some of the standard ways
-# such as profiling, and create your own set of WAY_*_OPTS defs below.
-# After having done that, add your way string to WAYS, and after having
-# run the configure script, the different projects will add the new way
-# to the list of ways they support.
-#
-
-#
-# Definitions of the different ways:
-#   
-#   * their name:
-#          - tag, e.g., p
-#          - description, e.g., profiling
-#   * what they mean to the driver:
-#          - WAY_p_HC_OPTS gives the list of command-line options
-#            to the driver.
-#
+HSTAGS = @HstagsCmd@
 
-#
-# The ways currently defined.
-#
-ALL_WAYS=p t s mp mg a b c d e f g h i j k l m n o A B
-USER_WAYS=a b c d e f g h j k l m n o A B
-
-#
-# The following ways currently have treated specially, p t mg,
-# as the driver script treats these guys specially and needs to carefully be told
-# about the options for these. Hence, we hide the required command line options
-# for these in the driver, as this is the only place they are needed.
-# 
-# If you want to add to these default options, fill in the variables below:
-
-# Way 'i':
-WAY_i_NAME=ILX
-WAY_i_HC_OPTS= -filx -fruntime-types
-
-# Way 'p':
-WAY_p_NAME=profiling
-WAY_p_HC_OPTS= -prof
-
-# Way 't':
-WAY_t_NAME=ticky-ticky profiling
-WAY_t_HC_OPTS= -ticky
-
-# Way `mp': 
-WAY_mp_NAME=parallel
-WAY_mp_HC_OPTS=-parallel
-
-# Way `mg': 
-WAY_mg_NAME=GranSim
-WAY_mg_HC_OPTS=-gransim
-
-#
-# These ways apply to the RTS only:
-#
-
-# Way 'thr':
-WAY_thr_NAME=threaded
-WAY_thr_HC_OPTS=-optc-DTHREADED_RTS
-
-# Way 'thr_p':
-WAY_thr_p_NAME=threaded profiled
-WAY_thr_p_HC_OPTS=-optc-DTHREADED_RTS -prof
-
-# Way 'debug':
-WAY_debug_NAME=debug
-WAY_debug_HC_OPTS=-optc-DDEBUG
-
-# Way 'debug_p':
-WAY_debug_p_NAME=debug profiled
-WAY_debug_p_HC_OPTS=-optc-DDEBUG -prof
-
-# Way 'debug_t':
-WAY_debug_t_NAME=debug ticky-ticky profiling
-WAY_debug_t_HC_OPTS= -ticky -optc-DDEBUG
-
-# Way 'thr_debug':
-WAY_thr_debug_NAME=threaded
-WAY_thr_debug_HC_OPTS=-optc-DTHREADED_RTS -optc-DDEBUG
-
-# Way 'thr_debug_p':
-WAY_thr_debug_p_NAME=threaded debug profiling
-WAY_thr_debug_p_HC_OPTS=-optc-DTHREADED_RTS -optc-DDEBUG -prof
-
-# Way 'dyn': build dynamic shared libraries
-WAY_dyn_NAME=dyn
-WAY_dyn_HC_OPTS=-fPIC -dynamic
-WAY_dyn_LIB_TARGET=libHSrts-gcc661.so
-
-# Way 'thr_dyn':
-WAY_thr_dyn_NAME=thr_dyn
-WAY_thr_dyn_HC_OPTS=-fPIC -dynamic -optc-DTHREADED_RTS
-
-# Way 'thr_debug_dyn':
-WAY_thr_debug_dyn_NAME=thr_dyn
-WAY_thr_debug_dyn_HC_OPTS=-fPIC -dynamic -optc-DTHREADED_RTS -optc-DDEBUG
-
-# Way 'debug_dyn':
-WAY_debug_dyn_NAME=thr_dyn
-WAY_debug_dyn_HC_OPTS=-fPIC -dynamic -optc-DDEBUG
-
-#
-# Add user-way configurations here:
-#
-WAY_A_NAME=
-WAY_A_HC_OPTS=
-
-WAY_B_NAME=
-WAY_B_HC_OPTS=
-
-WAY_a_NAME=
-WAY_a_HC_OPTS=
-
-WAY_b_NAME=
-WAY_b_HC_OPTS=
-
-WAY_c_NAME=
-WAY_c_HC_OPTS=
-
-WAY_d_NAME=
-WAY_d_HC_OPTS=
-
-WAY_e_NAME=
-WAY_e_HC_OPTS=
-
-WAY_f_NAME=
-WAY_f_HC_OPTS=
-
-WAY_g_NAME=
-WAY_g_HC_OPTS=
-
-WAY_h_NAME=
-WAY_h_HC_OPTS=
-
-WAY_j_NAME=
-WAY_j_HC_OPTS=
-
-WAY_k_NAME=
-WAY_k_HC_OPTS=
-
-WAY_l_NAME=
-WAY_l_HC_OPTS=
-
-WAY_m_NAME=
-WAY_m_HC_OPTS=
-
-WAY_n_NAME=
-WAY_n_HC_OPTS=
-
-WAY_o_NAME=
-WAY_o_HC_OPTS=
+# Should we build haddock docs?
+HADDOCK_DOCS = YES
+# And HsColour the sources?
+ifeq "$(HSCOLOUR_CMD)" ""
+HSCOLOUR_SRCS = NO
+else
+HSCOLOUR_SRCS = YES
+endif
 
 ################################################################################
 #
@@ -1377,16 +772,12 @@ CONFIGURE_ARGS = @CONFIGURE_ARGS@
 
 ################################################################################
 #
-#    Bindist testing directory
+#    To be passed to sub-builds
 #
 ################################################################################
 
-ifeq "$(Windows)" "YES"
-BIN_DIST_INST_SUBDIR = "install dir"
-else
-# I very much doubt that paths with spaces will work on Unix
-BIN_DIST_INST_SUBDIR = installed
-endif
-
-BIN_DIST_INST_DIR = $(FPTOOLS_TOP_ABS)/bindisttest/$(BIN_DIST_INST_SUBDIR)
+ICONV_INCLUDE_DIRS = @ICONV_INCLUDE_DIRS@
+ICONV_LIB_DIRS = @ICONV_LIB_DIRS@
 
+GMP_INCLUDE_DIRS = @GMP_INCLUDE_DIRS@
+GMP_LIB_DIRS = @GMP_LIB_DIRS@