summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2009-04-26 11:42:15 +0000
committerIan Lynagh <igloo@earth.li>2009-04-26 11:42:15 +0000
commit34cc75e1a62638f2833815746ebce0a9114dc26b (patch)
treeef21e8fd7af1356beea9cce7d6efb8a65374e24c
parent74e1368d4688ee16f6decdf2cd3ebe27506b26ba (diff)
downloadhaskell-34cc75e1a62638f2833815746ebce0a9114dc26b.tar.gz
GHC new build system megapatch
-rw-r--r--Makefile746
-rw-r--r--bindisttest/Makefile4
-rw-r--r--boot20
-rw-r--r--compiler/LICENSE31
-rw-r--r--compiler/Makefile507
-rw-r--r--compiler/ghc.cabal.in19
-rw-r--r--compiler/ghc.mk432
-rw-r--r--compiler/main/DriverMkDepend.hs28
-rw-r--r--compiler/main/SysTools.lhs200
-rw-r--r--compiler/rename/RnNames.lhs10
-rw-r--r--configure.ac126
-rw-r--r--distrib/configure-bin.ac4
-rw-r--r--docs/ext-core/Makefile3
-rw-r--r--docs/man/Makefile1
-rw-r--r--docs/users_guide/ghc.mk7
-rw-r--r--driver/ghc-pkg/Makefile18
-rw-r--r--driver/ghc.mk11
-rw-r--r--driver/ghc/ghc.mk10
-rw-r--r--driver/ghci/Makefile66
-rw-r--r--driver/ghci/ghc.mk50
-rw-r--r--driver/mangler/Makefile29
-rw-r--r--driver/mangler/ghc.mk7
-rw-r--r--driver/runhaskell/Makefile14
-rw-r--r--driver/split/Makefile24
-rw-r--r--driver/split/ghc.mk7
-rw-r--r--ghc.mk841
-rw-r--r--ghc.spec.in3
-rw-r--r--ghc/Main.hs2
-rw-r--r--ghc/Makefile161
-rw-r--r--ghc/ghc-bin.cabal.in3
-rw-r--r--ghc/ghc.mk127
-rw-r--r--ghc/ghc.wrapper2
-rw-r--r--gmp/Makefile127
-rw-r--r--gmp/ghc.mk124
-rw-r--r--gmp/gmp-4.2.1-nodoc.tar.gzbin1933064 -> 0 bytes
-rw-r--r--gmp/tarball/gmp-4.2.4-nodoc.tar.bz2bin0 -> 1464108 bytes
-rw-r--r--includes/Makefile205
-rw-r--r--includes/Regs.h2
-rw-r--r--includes/Stg.h2
-rw-r--r--includes/ghc.mk179
-rw-r--r--libffi/Makefile202
-rw-r--r--libffi/ghc.mk193
-rw-r--r--libffi/libffi.autotools-update.patch (renamed from libffi/libffi-autotools-update.patch)0
-rw-r--r--libffi/libffi.dllize-3.0.6.patch (renamed from libffi/libffi-dllize-3.0.6.patch)0
-rw-r--r--libffi/package.conf.in6
-rw-r--r--libffi/tarball/libffi-3.0.6.tar.gz (renamed from libffi/libffi-3.0.6.tar.gz)bin717171 -> 717171 bytes
-rw-r--r--libraries/Makefile441
-rw-r--r--mk/bindist.mk45
-rw-r--r--mk/boilerplate.mk82
-rw-r--r--mk/build.mk.sample8
-rw-r--r--mk/cabal-flags.mk129
-rw-r--r--mk/cabal.mk68
-rw-r--r--mk/config.mk.in459
-rw-r--r--mk/custom-settings.mk8
-rw-r--r--mk/install.mk307
-rw-r--r--mk/old-config.mk.in1416
-rw-r--r--mk/opts.mk109
-rw-r--r--mk/package.mk315
-rw-r--r--mk/paths.mk277
-rw-r--r--mk/project.mk.in143
-rw-r--r--mk/recurse.mk101
-rw-r--r--mk/sub-makefile.mk34
-rw-r--r--mk/suffix.mk392
-rw-r--r--mk/target.mk701
-rw-r--r--mk/validate-settings.mk4
-rw-r--r--rts/Capability.h2
-rw-r--r--rts/Interpreter.c2
-rw-r--r--rts/Makefile499
-rw-r--r--rts/ghc.mk393
-rw-r--r--rts/package.conf.in10
-rw-r--r--rules/all-target.mk7
-rw-r--r--rules/bindist.mk16
-rw-r--r--rules/build-dependencies.mk48
-rw-r--r--rules/build-package-data.mk16
-rw-r--r--rules/build-package-way.mk52
-rw-r--r--rules/build-package.mk135
-rw-r--r--rules/build-perl.mk45
-rw-r--r--rules/build-prog.mk139
-rw-r--r--rules/c-objs.mk5
-rw-r--r--rules/c-sources.mk4
-rw-r--r--rules/c-suffix-rules.mk60
-rw-r--r--rules/clean-target.mk9
-rw-r--r--rules/distdir-opts.mk60
-rw-r--r--rules/distdir-way-opts.mk78
-rw-r--r--rules/docbook.mk24
-rw-r--r--rules/haddock.mk27
-rw-r--r--rules/hi-rule.mk25
-rw-r--r--rules/hs-objs.mk5
-rw-r--r--rules/hs-sources.mk46
-rw-r--r--rules/hs-suffix-rules-srcdir.mk70
-rw-r--r--rules/hs-suffix-rules.mk17
-rw-r--r--rules/includes-sources.mk14
-rw-r--r--rules/manual-package-config.mk33
-rw-r--r--rules/package-config.mk41
-rw-r--r--rules/shell-wrapper.mk63
-rw-r--r--rules/way-prelims.mk13
-rw-r--r--utils/genapply/Makefile32
-rw-r--r--utils/genapply/ghc.mk16
-rw-r--r--utils/genprimopcode/Makefile13
-rw-r--r--utils/genprimopcode/ghc.mk4
-rw-r--r--utils/ghc-cabal/ghc-cabal.hs246
-rw-r--r--utils/ghc-cabal/ghc.mk54
-rw-r--r--utils/ghc-pkg/Main.hs55
-rw-r--r--utils/ghc-pkg/Makefile24
-rw-r--r--utils/ghc-pkg/ghc.mk69
-rw-r--r--utils/hasktags/Makefile8
-rw-r--r--utils/hasktags/ghc.mk10
-rw-r--r--utils/hp2ps/Main.h2
-rw-r--r--utils/hp2ps/Makefile23
-rw-r--r--utils/hp2ps/ghc.mk10
-rw-r--r--utils/hpc/Main.hs (renamed from utils/hpc/Hpc.hs)0
-rw-r--r--utils/hpc/Makefile8
-rw-r--r--utils/hpc/ghc.mk7
-rw-r--r--utils/installPackage/Makefile13
-rw-r--r--utils/installPackage/installPackage.cabal28
-rw-r--r--utils/installPackage/installPackage.hs154
-rw-r--r--utils/mkdependC/Makefile27
-rw-r--r--utils/mkdependC/ghc.mk12
-rw-r--r--utils/mkdependC/mkdependC.prl2
-rw-r--r--utils/mkdirhier/Makefile20
-rw-r--r--utils/mkdirhier/ghc.mk11
-rw-r--r--utils/parallel/Makefile2
-rw-r--r--utils/runghc/Makefile15
-rw-r--r--utils/runghc/ghc.mk29
-rw-r--r--utils/runghc/runghc.hs4
-rw-r--r--utils/touchy/ghc.mk5
-rw-r--r--utils/touchy/touchy.c1
-rw-r--r--utils/unlit/Makefile28
-rw-r--r--utils/unlit/ghc.mk9
-rw-r--r--utils/unlit/unlit.c24
-rw-r--r--validate7
131 files changed, 6150 insertions, 6372 deletions
diff --git a/Makefile b/Makefile
index 14af87418f..726801db02 100644
--- a/Makefile
+++ b/Makefile
@@ -1,663 +1,143 @@
-############################################################################
-#
-# This is the top-level Makefile for GHC
-#
-# Targets:
-#
-# bootstrap (DEFAULT)
-# Builds GHC, then builds the libraries,
-# then uses this GHC ("stage 1") to build itself
-# ("stage 2").
-#
-# bootstrap2
-# Same as bootstrap
-#
-# bootstrap3
-# bootstrap2 + we build GHC one more time ("stage 3")
-#
-# stage1
-# Just build up to stage 1
-#
-# stage2
-# Just build stage 2 (stage 1 must be built)
-#
-# stage3
-# Just build stage 3 (stage 2 must be built)
-#
-# all
-# Same as bootstrap
-#
-# install
-# Install everything, including stage 2 compiler by default
-# (override with stage=3, for example).
-#
-# dist
-# Make a source dist (WARNING: runs 'make distclean' first)
-#
-# binary-dist
-# Builds a binary distribution
-#
-# framework-pkg [MacOS only]
-# Builds /Library/Frameworks/GHC.framework wrapped into a Mac
-# installer package
-#
-# framework-binary-dist [MacOS only]
-# Builds GHC.framework encapsulating a binary distribution
-# (to give a relocatable framework)
-#
-# hc-file-bundle
-# Builds an HC-file bundle, for bootstrapping
-#
-# clean, distclean, maintainer-clean
-# Increasing levels of cleanliness
-#
-############################################################################
-TOP=.
-include $(TOP)/mk/boilerplate.mk
+ifeq "$(wildcard distrib/)" ""
-#
-# Order is important! It's e.g. necessary to descend into include/
-# before the rest to have a config.h, etc.
-#
-# If we're booting from .hc files, swap the order
-# we descend into subdirs - to boot utils must be before driver.
-#
-.PHONY: stage1 stage2 stage3 bootstrap bootstrap2 bootstrap3
+# We're in a bindist
-# We can't 'make boot' in libraries until stage1 is built
-ifeq "$(BootingFromHc)" "YES"
-SUBDIRS_BUILD = includes compiler docs utils driver
-else
-SUBDIRS_BUILD = includes utils driver docs compiler libraries/Cabal/doc
-endif
+.PHONY: default
+default:
+ @echo 'Run "make install" to install'
+ @false
-SUBDIRS = gmp libffi includes utils docs rts compiler ghc driver libraries libraries/Cabal/doc
+.PHONY: install
+install:
+ $(MAKE) -r --no-print-directory -f ghc.mk install BINDIST=YES NO_INCLUDE_DEPS=YES
-check-all: check-packages check-tools
-
-# Sanity check that all the boot libraries are in the tree, to catch
-# failure to run darcs-all.
-check-packages :
- @ds=`grep "^[^# ][^ ]* *[^ ][^ ]* *[^ ][^ ]*$$" packages | sed "s/ .*//"`;\
- for d in $$ds; do \
- if test ! -d $$d; then \
- echo "Looks like you're missing $$d,"; \
- echo "maybe you haven't done './darcs-all get'?"; \
- exit 1; \
- fi \
- done
- @if test ! -f libraries/base/configure; then \
- echo "Looks like you're missing base's configure script."; \
- echo "Did you run 'sh boot' at the top level?"; \
- exit 1; \
- fi
-
-HAVE_EVAL := NO
-$(eval HAVE_EVAL := YES)
-
-check-tools:
-ifeq "$(HSCOLOUR_SRCS) $(HSCOLOUR)" "YES "
- @echo "HsColour needed but wasn't found."
- @echo "Set HSCOLOUR_SRCS=NO if you don't want to use it"
- exit 1
-endif
-ifeq "$(HAVE_EVAL)" "NO"
- @echo "Your make doesn't support eval. You need GNU make >= 3.80"
- exit 1
-endif
- @:
-
-ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-ifneq "$(WhatGccIsCalled)" ""
-GCC_LIB_DEP = stamp.inplace-gcc-lib
-endif
-endif
-
-stage1 : $(GCC_LIB_DEP) check-all
- $(MAKE) -C libraries boot
- $(MAKE) -C gmp all
- $(MAKE) -C utils/mkdependC boot
- $(MAKE) -C utils with-bootstrapping-compiler
- @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
- for i in $(SUBDIRS_BUILD); do \
- echo "------------------------------------------------------------------------"; \
- echo "== $(MAKE) boot $(MFLAGS);"; \
- echo " in $(shell pwd)/$$i"; \
- echo "------------------------------------------------------------------------"; \
- $(MAKE) --no-print-directory -C $$i $(MFLAGS) boot; \
- if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
- done; \
- for i in $(SUBDIRS_BUILD); do \
- echo "------------------------------------------------------------------------"; \
- echo "== $(MAKE) all $(MFLAGS);"; \
- echo " in $(shell pwd)/$$i"; \
- echo "------------------------------------------------------------------------"; \
- $(MAKE) --no-print-directory -C $$i $(MFLAGS) all; \
- if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
- done
- $(MAKE) -C libffi all
- $(MAKE) -C rts boot
- $(MAKE) -C rts
- $(MAKE) -C libraries all
-
-# When making distributions (i.e., whether with binary-dist or using the
-# vanilla install target to create an installer package), we can have problems
-# if some things (e.g. ghc-pkg) are compiled with the bootstrapping compiler
-# and some (e.g. the stage 2 compiler) with the stage1 compiler. See #1860 for
-# an example. Thus, we explicitly build a second version with the stage 1
-# compiler of all utils that get installed and of all extra support binaries
-# includes in binary dists.
-stage2 : check-all
- $(MAKE) -C compiler stage=2 boot
- $(MAKE) -C compiler stage=2
- $(MAKE) -C utils with-stage-2
- $(MAKE) -C libraries stage=2 all
-ifeq "$(HADDOCK_DOCS)" "YES"
- $(MAKE) -C libraries doc
- $(MAKE) -C compiler doc stage=2
-endif
+.PHONY: show
+show:
+ $(MAKE) -r --no-print-directory -f ghc.mk $@
-stage3 : check-all
- $(MAKE) -C compiler stage=3 boot
- $(MAKE) -C compiler stage=3
-
-bootstrap : bootstrap2
-
-bootstrap2 : stage1
- $(MAKE) stage2
-
-bootstrap3 : bootstrap2
- $(MAKE) stage3
-
-ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-ifneq "$(WhatGccIsCalled)" ""
-all :: stamp.inplace-gcc-lib
-
-.PHONY: stamp.inplace-gcc-lib
-
-# This is a hack to make Cabal able to find ld when we run tests with
-# the inplace ghc. We should probably install all the gcc stuff in our
-# tree somewhere, and then have install copy it from there rather than
-# from the filesystem.
-stamp.inplace-gcc-lib:
- $(RM) -r ghc/gcc-lib
- mkdir ghc/gcc-lib
- cp $(LD) ghc/gcc-lib
- touch $@
-
-clean ::
- $(RM) -r ghc/gcc-lib
- $(RM) -f inplace-gcc-lib
-endif
-endif
-
-all :: bootstrap
-
-# -----------------------------------------------------------------------------
-# Installing
-
-# We want to install the stage 2 bootstrapped compiler by default, but we let
-# the user override this by saying 'make install stage=1', for example.
-ifeq "$(stage)" ""
-INSTALL_STAGE = stage=2
else
-INSTALL_STAGE =
-endif
-
-install-strip:
- $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
-
-# Same as default rule, but we pass $(INSTALL_STAGE) to $(MAKE) too
-install :: check-packages
- $(MKDIRHIER) $(DESTDIR)$(datadir)
- echo "[]" > $(DESTDIR)$(datadir)/package.conf
- @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
- for i in $(SUBDIRS); do \
- echo "------------------------------------------------------------------------"; \
- echo "== $(MAKE) $@ $(MFLAGS);"; \
- echo " in $(shell pwd)/$$i"; \
- echo "------------------------------------------------------------------------"; \
- $(MAKE) --no-print-directory -C $$i $(INSTALL_STAGE) $(MFLAGS) $@; \
- if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
- done
-
-ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-# These files need to be in the InstallShield
-# INSTALL_DATAS rather than INSTALL_DOCS is used so these files go
-# in the top-level directory of the distribution
-INSTALL_DATAS += ANNOUNCE LICENSE README
-endif
-# If installing on Windows with MinGW32, copy the gcc compiler, headers and libs
-# and the perl interpreter and dll into the GHC prefix directory.
-# Gcc and Perl source locations derived from configuration data.
-ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-ifneq "$(WhatGccIsCalled)" ""
-install ::
- -mkdir $(prefix)/gcc-lib
- -mkdir $(prefix)/include
- -mkdir $(prefix)/include/mingw
- -cp -rp $(GccDir)../include/* $(prefix)/include/mingw
- -cp -rp $(GccDir)../lib/gcc-lib/mingw32/$(GccVersion)/* $(prefix)/gcc-lib
- -cp -rp $(GccDir)../lib/gcc/mingw32/$(GccVersion)/* $(prefix)/gcc-lib
- -cp -rp $(GccDir)../libexec/gcc/mingw32/$(GccVersion)/* $(prefix)/gcc-lib
- -cp $(GccDir)../lib/*.* $(prefix)/gcc-lib
- -cp $(GccDir)gcc.exe $(prefix)
- -cp $(GccDir)as.exe $(prefix)/gcc-lib
- -cp $(GccDir)ld.exe $(prefix)/gcc-lib
- -cp $(GccDir)dllwrap.exe $(prefix)/gcc-lib
- -cp $(GccDir)dlltool.exe $(prefix)/gcc-lib
- -cp $(GhcDir)../perl.exe $(prefix)
- -cp $(GhcDir)../perl56.dll $(prefix)
-endif
-endif
-
-# Install gcc-extra-opts
-install ::
- $(INSTALL_DIR) $(DESTDIR)$(libdir)
- $(INSTALL_DATA) $(INSTALL_OPTS) extra-gcc-opts $(DESTDIR)$(libdir)
+# The problem we need to solve is as follows.
+#
+# GNU make supports included Makefiles, and it is clever enough to try
+# to update those Makefiles when they are out-of-date or missing. It
+# first reads all the Makefiles, and then tries to build each one if
+# it is out-of-date, using the rules in the Makefiles themselves.
+# When it has brought all the Makefiles up-to-date, it restarts itself
+# to read the newly-generated Makefiles.
+#
+# This works fine, unless there are dependencies *between* the
+# Makefiles. For example in the GHC build, for each package we have a
+# package-data.mk file which is generated by the ghc-cabal program,
+# and we have a .depend file. The .depend file cannot be generated
+# until package-data.mk has been generated and make has been restarted
+# to read in its contents, because it is the package-data.mk file that
+# tells us which modules are in the package. But make always makes
+# all the Makefiles before restarting - it doesn't take into account a
+# dependency between Makefiles and restart itself earlier.
-install-docs ::
- @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
- for i in $(SUBDIRS); do \
- echo "------------------------------------------------------------------------"; \
- echo "== $(MAKE) $@ $(MFLAGS);"; \
- echo " in $(shell pwd)/$$i"; \
- echo "------------------------------------------------------------------------"; \
- $(MAKE) --no-print-directory -C $$i $(INSTALL_STAGE) $(MFLAGS) $@; \
- if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ; then true; else exit 1; fi; \
- done
+# Consider the following makefile:
-# -----------------------------------------------------------------------------
-# Making a binary distribution
-#
-# `dist' `binary-dist'
-# Create a distribution tar file for this program. The tar file
-# should be set up so that the file names in the tar file start with
-# a subdirectory name which is the name of the package it is a
-# distribution for. This name can include the version number.
+# --------------------
+# all :
#
-# For example, the distribution tar file of GCC version 1.40 unpacks
-# into a subdirectory named `gcc-1.40'.
+# include inc1.mk
#
-# The easiest way to do this is to create a subdirectory
-# appropriately named, use ln or cp to install the proper files in
-# it, and then tar that subdirectory.
+# inc1.mk : Makefile
+# echo "X = C" >$@
#
-# The dist target should explicitly depend on all non-source files
-# that are in the distribution, to make sure they are up to date in
-# the distribution. See Making Releases.
-#
-# binary-dist is a GHC addition for binary distributions
+# include inc2.mk
#
+# inc2.mk : inc1.mk
+# echo "Y = $(X)" >$@
+# --------------------
-binary-dist::
- -rm -rf $(BIN_DIST_DIR)
- -$(RM) $(BIN_DIST_TAR_BZ2)
-
-ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-
-binary-dist::
- $(MAKE) prefix=$(BIN_DIST_DIR) install
- $(MAKE) prefix=$(BIN_DIST_DIR) install-docs
-
-binary-dist::
- cd $(BIN_DIST_DIR) && $(SHELL) ../distrib/prep-bin-dist-mingw
-
-binary-dist::
- $(MKDIRHIER) $(BIN_DIST_DIR)/icons
- cp distrib/hsicon.ico $(BIN_DIST_DIR)/icons
-
-# Tar up the distribution and build a manifest
-binary-dist :: tar-binary-dist
-
-.PHONY: tar-binary-dist
-tar-binary-dist:
- ( cd $(BIN_DIST_TOPDIR_ABS); $(TAR) cf - $(BIN_DIST_NAME) | bzip2 > $(FPTOOLS_TOP_ABS)/$(BIN_DIST_TAR_BZ2) )
- ( cd $(BIN_DIST_TOPDIR_ABS); bunzip2 -c $(FPTOOLS_TOP_ABS)/$(BIN_DIST_TAR_BZ2) | $(TAR) tf - | sed "s/^ghc-$(ProjectVersion)/fptools/" | sort >$(FPTOOLS_TOP_ABS)/bin-manifest-$(ProjectVersion) )
-
-else
-
-.PHONY: binary-dist
-
-BIN_DIST_VARFILE=$(BIN_DIST_PREP)/Makefile-vars.in
-
-WHERE_AM_I = $(BIN_DIST_NAME)
-
-binary-dist::
-# For the most part we will be putting filenames in $(BIN_DIST_LIST),
-# and telling tar to tar all of those files up. So to start with we
-# remove $(BIN_DIST_LIST) so that we can start with an empty slate
- $(RM) -f $(BIN_DIST_LIST)
-# Now we add a few files from mk/ to $(BIN_DIST_LIST)
- echo $(WHERE_AM_I)/mk/package.mk >> $(BIN_DIST_LIST)
- echo $(WHERE_AM_I)/mk/install.mk >> $(BIN_DIST_LIST)
- echo $(WHERE_AM_I)/mk/recurse.mk >> $(BIN_DIST_LIST)
- echo $(WHERE_AM_I)/mk/cabal.mk >> $(BIN_DIST_LIST)
- echo $(WHERE_AM_I)/mk/cabal-flags.mk >> $(BIN_DIST_LIST)
- echo $(WHERE_AM_I)/mk/fptools.css >> $(BIN_DIST_LIST)
- echo $(WHERE_AM_I)/ANNOUNCE >> $(BIN_DIST_LIST)
- echo $(WHERE_AM_I)/LICENSE >> $(BIN_DIST_LIST)
- echo $(WHERE_AM_I)/install-sh >> $(BIN_DIST_LIST)
- echo $(WHERE_AM_I)/extra-gcc-opts.in >> $(BIN_DIST_LIST)
- echo $(WHERE_AM_I)/config.guess >> $(BIN_DIST_LIST)
- echo $(WHERE_AM_I)/config.sub >> $(BIN_DIST_LIST)
-# Now we recurse into various subdirectories and tell them to add and
-# files that they want into $(BIN_DIST_LIST)
-# XXX Ug, this duplication of "-C foo WHERE_AM_I=.../foo" isn't nice.
- $(MAKE) -C gmp binary-dist WHERE_AM_I=$(WHERE_AM_I)/gmp
- $(MAKE) -C includes binary-dist WHERE_AM_I=$(WHERE_AM_I)/includes
- $(MAKE) -C compiler binary-dist WHERE_AM_I=$(WHERE_AM_I)/compiler $(INSTALL_STAGE)
- $(MAKE) -C ghc binary-dist WHERE_AM_I=$(WHERE_AM_I)/ghc $(INSTALL_STAGE)
- $(MAKE) -C rts binary-dist WHERE_AM_I=$(WHERE_AM_I)/rts
- $(MAKE) -C driver binary-dist WHERE_AM_I=$(WHERE_AM_I)/driver
- $(MAKE) -C utils binary-dist WHERE_AM_I=$(WHERE_AM_I)/utils
- $(MAKE) -C docs binary-dist WHERE_AM_I=$(WHERE_AM_I)/docs
- $(MAKE) -C libffi binary-dist WHERE_AM_I=$(WHERE_AM_I)/libffi
- $(MAKE) -C libraries binary-dist WHERE_AM_I=$(WHERE_AM_I)/libraries
- $(MAKE) -C libraries/Cabal/doc binary-dist WHERE_AM_I=$(WHERE_AM_I)/libraries/Cabal/doc
-# Now thinks get messier. Some files we need to move around, rename or
-# generate. We do this under $(BIN_DIST_PREP).
- $(RM) -rf $(BIN_DIST_PREP_DIR)
- $(MKDIRHIER) $(BIN_DIST_PREP)/mk
- echo 'include $$(TOP)/Makefile-vars' > $(BIN_DIST_PREP)/mk/boilerplate.mk
- echo 'include $$(TOP)/mk/package.mk' > $(BIN_DIST_PREP)/mk/target.mk
- echo 'include $$(TOP)/mk/install.mk' >> $(BIN_DIST_PREP)/mk/target.mk
- echo 'include $$(TOP)/mk/recurse.mk' >> $(BIN_DIST_PREP)/mk/target.mk
- touch $(BIN_DIST_PREP)/mk/bindist.mk
-ifeq "$(darwin_TARGET_OS)" "1"
- cp mk/fix_install_names.sh $(BIN_DIST_PREP)/mk
-endif
-
- cp distrib/Makefile $(BIN_DIST_PREP)
- cp distrib/INSTALL $(BIN_DIST_PREP)
- cp distrib/README $(BIN_DIST_PREP)
- cp distrib/configure-bin.ac $(BIN_DIST_PREP)/configure.ac
-# We can't just list aclocal.m4 in $(BIN_DIST_LIST), as it needs to be
-# next to configure.ac when we run autoreconf
- cp aclocal.m4 $(BIN_DIST_PREP)
- cd $(BIN_DIST_PREP) && autoreconf
-# We need to copy the pwd program that was built with stage1 to where
-# the build system expects to find it, i.e. the location the pwd built
-# with the bootstrapping compiler normally occupies
- $(MKDIRHIER) $(BIN_DIST_PREP)/utils/pwd
- cp utils/pwd/dist-install/build/pwd/pwd $(BIN_DIST_PREP)/utils/pwd
-# And likewise the installPackage program
- $(MKDIRHIER) $(BIN_DIST_PREP)/utils/installPackage/install-inplace/bin
- cp utils/installPackage/dist-install/build/installPackage/installPackage \
- $(BIN_DIST_PREP)/utils/installPackage/install-inplace/bin
-
- echo "package = ghc" >> $(BIN_DIST_VARFILE)
- echo "version = $(ProjectVersion)" >> $(BIN_DIST_VARFILE)
- echo "ProjectVersion = $(ProjectVersion)" >> $(BIN_DIST_VARFILE)
- echo "HaveLibGmp = $(HaveLibGmp)" >> $(BIN_DIST_VARFILE)
- echo "GhcLibsWithUnix = $(GhcLibsWithUnix)" >> $(BIN_DIST_VARFILE)
- echo "GhcWithInterpreter = $(GhcWithInterpreter)" >> $(BIN_DIST_VARFILE)
- echo "GhcHasEditline = $(GhcHasEditline)" >> $(BIN_DIST_VARFILE)
- echo "BootingFromHc = $(BootingFromHc)" >> $(BIN_DIST_VARFILE)
- echo "XMLDocWays = $(XMLDocWays)" >> $(BIN_DIST_VARFILE)
-# We won't actually use xsltproc, but we need to know if it's "" or not
- echo "XSLTPROC = $(XSLTPROC)" >> $(BIN_DIST_VARFILE)
- echo "TARGETPLATFORM = $(TARGETPLATFORM)" >> $(BIN_DIST_VARFILE)
- echo "HADDOCK_DOCS = $(HADDOCK_DOCS)" >> $(BIN_DIST_VARFILE)
- echo "LATEX_DOCS = $(LATEX_DOCS)" >> $(BIN_DIST_VARFILE)
- echo "INTEGER_LIBRARY = $(INTEGER_LIBRARY)" >> $(BIN_DIST_VARFILE)
- cat distrib/Makefile-bin-vars.in >> $(BIN_DIST_VARFILE)
-
-# With that done, we can now build the actual tarball
-
- $(RM) -f $(BIN_DIST_NAME)
- ln -s . $(BIN_DIST_NAME)
-# h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
-# tree then we want to include the real file, not a symlink to it
- $(TAR) hcf $(BIN_DIST_TAR) -T $(BIN_DIST_LIST)
- cd $(BIN_DIST_PREP_DIR) && $(TAR) rf ../$(BIN_DIST_TAR) $(BIN_DIST_NAME)
- bzip2 < $(BIN_DIST_TAR) > $(BIN_DIST_TAR_BZ2)
- $(TAR) tf $(BIN_DIST_TAR) | sort > bin-manifest-$(ProjectVersion)
-endif
-
-PUBLISH_FILES = $(BIN_DIST_TAR_BZ2)
-
-# Upload the distribution and documentation
-ifneq "$(ISCC)" ""
-WINDOWS_INSTALLER_BASE = ghc-$(ProjectVersion)-$(TARGETPLATFORM)
-WINDOWS_INSTALLER = $(WINDOWS_INSTALLER_BASE)$(exeext)
-
-PUBLISH_FILES += $(WINDOWS_INSTALLER)
-
-binary-dist :: generate-windows-installer
-
-.PHONY: generate-windows-installer
-generate-windows-installer ::
- $(SED) "s/@VERSION@/$(ProjectVersion)/" distrib/ghc.iss | $(ISCC) /O. /F$(WINDOWS_INSTALLER_BASE) -
-endif
-
-# Upload the distribution and documentation
-ifneq "$(PublishLocation)" ""
-publish ::
- make publish-binary-dist 'prefix=$(BIN_DIST_INST_DIR)'
-endif
-
-nTimes = set -e; for i in `seq 1 $(1)`; do echo Try "$$i: $(2)"; if $(2); then break; fi; done
-
-.PHONY: publish-binary-dist
-publish-binary-dist ::
- @for f in $(PUBLISH_FILES); \
- do $(call nTimes,10,$(PublishCp) $$f $(PublishLocation)/dist); \
- done
-
-# You need to "make binddisttest" before publishing the docs, as it
-# works by publish setting $(prefix) to inside the binddisttest
-# directory so $(docdir) points to the right place.
-
-# We assume that Windows means Cygwin, as we can't just use docdir
-# unchanged or rsync (really SSH?) thinks that c:/foo means /foo on
-# the machine c.
-
-ifeq "$(Windows)" "YES"
-PUBLISH_DOCDIR = $(shell cygpath --unix $(docdir))
-else
-PUBLISH_DOCDIR = $(docdir)
-endif
-
-publish-binary-dist ::
- $(call nTimes,10,$(PublishCp) -r "$(PUBLISH_DOCDIR)"/* $(PublishLocation)/docs)
-
-binary-dist::
- @echo "Mechanical and super-natty! Inspect the result and *if* happy; freeze, sell and get some sleep!"
-
-# -----------------------------------------------------------------------------
-# Building MacOS installer packages
-#
-# 'framework-pkg'
-# Create an installer package for /Library/Frameworks/GHC.framework
-#
-# 'framework-binary-dist'
-# Create an installer package for GHC.framework encapsulating a
-# binary-dist to make it relocatable
-# FIXME: This is only partially implemented so far
-
-ifeq "$(darwin_TARGET_OS)" "1"
-
-.PHONY: framework-pkg framework-binary-dist
-
-framework-pkg:
- $(MAKE) -C distrib/MacOS framework-pkg
-
-framework-binary-dist:
- $(MAKE) -C distrib/MacOS framework-binary-dist
-
-endif
-
-# -----------------------------------------------------------------------------
-# Building source distributions
-#
-# Do it like this:
-#
-# $ make
-# $ make dist
-#
-# WARNING: `make dist' calls `make distclean' before tarring up the tree.
-#
-
-.PHONY: dist
-
-#
-# Directory in which we're going to build the src dist
-#
-SRC_DIST_NAME=ghc-$(ProjectVersion)
-SRC_DIST_DIR=$(shell pwd)/$(SRC_DIST_NAME)
+# Now try it:
+#
+# $ make -f fail.mk
+# fail.mk:3: inc1.mk: No such file or directory
+# fail.mk:8: inc2.mk: No such file or directory
+# echo "X = C" >inc1.mk
+# echo "Y = " >inc2.mk
+# make: Nothing to be done for `all'.
+# make built both inc1.mk and inc2.mk without restarting itself
+# between the two (even though we added a dependency on inc1.mk from
+# inc2.mk).
#
-# Files to include in source distributions
-#
-SRC_DIST_DIRS += mk docs distrib bindisttest $(filter-out docs distrib libraries/Cabal/doc,$(SUBDIRS))
-SRC_DIST_FILES += \
- configure.ac config.guess config.sub configure \
- aclocal.m4 README ANNOUNCE HACKING LICENSE Makefile install-sh \
- ghc.spec.in ghc.spec extra-gcc-opts.in VERSION boot
+# The solution we adopt in the GHC build system is essentially this:
-# -----------------------------------------------------------------------------
-# Source distributions
-
-# A source dist is built from a complete build tree, because we
-# require some extra files not contained in a darcs checkout: the
-# output from Happy and Alex, for example.
+# --------------------
+# PHASE = 0
#
-# The steps performed by 'make dist' are as follows:
-# - create a complete link-tree of the current build tree in /tmp
-# - run 'make distclean' on that tree
-# - remove a bunch of other files that we know shouldn't be in the dist
-# - tar up first the extralibs package, then the main source package
-
-EXTRA_LIBS=$(patsubst %, $(SRC_DIST_NAME)/%, $(shell grep -E "extralibs|dph" packages | grep -v "^\#" | sed "s/ .*//"))
-
-SRC_DIST_TARBALL = ghc-$(ProjectVersion)-src.tar.bz2
-SRC_DIST_EXTRALIBS_TARBALL = ghc-$(ProjectVersion)-src-extralibs.tar.bz2
-
-VERSION :
- echo $(ProjectVersion) >VERSION
-
-dist :: VERSION
-
-# Use:
-# $(call copy_generated_compiler_file,cmm,CmmLex,x)
-# to copy the generated file that replaces compiler/cmm/CmmLex.x
-# XXX Should this be unconditional? Do we want to support making a src dist
-# from an unbuilt tree?
-copy_generated_compiler_file = \
- if test -f $(FPTOOLS_TOP_ABS)/compiler/dist-stage2/build/$2.hs; \
- then \
- $(CP) $(FPTOOLS_TOP_ABS)/compiler/dist-stage2/build/$2.hs compiler/$1/ ; \
- mv compiler/$1/$2.$3 compiler/$1/$2.$3.source ; \
- fi
-copy_generated_util_file = \
- if test -f $(FPTOOLS_TOP_ABS)/utils/$1/dist-install/build/$1/$1-tmp/$2.hs; \
- then \
- $(CP) $(FPTOOLS_TOP_ABS)/utils/$1/dist-install/build/$1/$1-tmp/$2.hs utils/$1/ ; \
- mv utils/$1/$2.$3 utils/$1/$2.$3.source ; \
- fi
-
-dist ::
- $(RM) -rf $(SRC_DIST_DIR)
- $(RM) $(SRC_DIST_NAME).tar.gz
- mkdir $(SRC_DIST_DIR)
- ( cd $(SRC_DIST_DIR) \
- && for i in $(SRC_DIST_DIRS); do mkdir $$i; (cd $$i && lndir $(FPTOOLS_TOP_ABS)/$$i ); done \
- && for i in $(SRC_DIST_FILES); do $(LN_S) $(FPTOOLS_TOP_ABS)/$$i .; done \
- && $(MAKE) distclean \
- && if test -f $(FPTOOLS_TOP_ABS)/libraries/haskell-src/dist/build/Language/Haskell/Parser.hs; then $(CP) $(FPTOOLS_TOP_ABS)/libraries/haskell-src/dist/build/Language/Haskell/Parser.hs libraries/haskell-src/Language/Haskell/ ; mv libraries/haskell-src/Language/Haskell/Parser.ly libraries/haskell-src/Language/Haskell/Parser.ly.source ; fi \
- && $(call copy_generated_compiler_file,cmm,CmmLex,x) \
- && $(call copy_generated_compiler_file,cmm,CmmParse,y) \
- && $(call copy_generated_compiler_file,main,ParsePkgConf,y) \
- && $(call copy_generated_compiler_file,parser,HaddockLex,x) \
- && $(call copy_generated_compiler_file,parser,HaddockParse,y) \
- && $(call copy_generated_compiler_file,parser,Lexer,x) \
- && $(call copy_generated_compiler_file,parser,Parser,y.pp) \
- && $(call copy_generated_compiler_file,parser,ParserCore,y) \
- && $(call copy_generated_util_file,hpc,HpcParser,y) \
- && $(RM) -rf compiler/stage[123] mk/build.mk \
- && $(FIND) $(SRC_DIST_DIRS) \( -name _darcs -o -name SRC -o -name "autom4te*" -o -name "*~" -o -name ".cvsignore" -o -name "\#*" -o -name ".\#*" -o -name "log" -o -name "*-SAVE" -o -name "*.orig" -o -name "*.rej" \) -print | xargs $(RM) -rf \
- )
- $(TAR) chf - $(EXTRA_LIBS) | bzip2 >$(FPTOOLS_TOP_ABS)/$(SRC_DIST_EXTRALIBS_TARBALL)
- $(RM) -rf $(EXTRA_LIBS)
- $(TAR) chf - $(SRC_DIST_NAME) 2>$src_log | bzip2 >$(FPTOOLS_TOP_ABS)/$(SRC_DIST_TARBALL)
-
-# Upload the distribution(s)
-# Retrying is to work around buggy firewalls that corrupt large file transfers
-# over SSH.
-ifneq "$(PublishLocation)" ""
-dist ::
- @for i in 0 1 2 3 4 5 6 7 8 9; do \
- echo "Try $$i: $(PublishCp) $(SRC_DIST_EXTRALIBS_TARBALL) $(PublishLocation)/dist"; \
- if $(PublishCp) $(SRC_DIST_EXTRALIBS_TARBALL) $(PublishLocation)/dist; then break; fi; \
- done
- @for i in 0 1 2 3 4 5 6 7 8 9; do \
- echo "Try $$i: $(PublishCp) $(SRC_DIST_TARBALL) $(PublishLocation)/dist"; \
- if $(PublishCp) $(SRC_DIST_TARBALL) $(PublishLocation)/dist; then break; fi; \
- done
-endif
-
-# -----------------------------------------------------------------------------
-# HC file bundles
-
-hc-file-bundle :
- $(RM) -r ghc-$(ProjectVersion)
- $(LN_S) . ghc-$(ProjectVersion)
- $(FIND) ghc-$(ProjectVersion)/compiler \
- ghc-$(ProjectVersion)/utils \
- ghc-$(ProjectVersion)/libraries -follow \
- \( -name "*.hc" -o -name "*_hsc.[ch]" -o -name "*_stub.[ch]" \) -print > hc-files-to-go
- for f in `$(FIND) ghc-$(ProjectVersion)/compiler ghc-$(ProjectVersion)/utils ghc-$(ProjectVersion)/libraries -name "*.hsc" -follow -print` ""; do \
- if test "x$$f" != "x" && test -f `echo "$$f" | sed 's/hsc$$/hs/g'`; then \
- echo `echo "$$f" | sed 's/hsc$$/hs/g' ` >> hc-files-to-go ; \
- fi; \
- done;
- for f in `$(FIND) ghc-$(ProjectVersion)/compiler ghc-$(ProjectVersion)/rts -name "*.cmm" -follow -print` ""; do \
- if test "x$$f" != "x"; then \
- echo `echo "$$f" | sed 's/cmm$$/hc/g' ` >> hc-files-to-go ; \
- fi; \
- done;
- echo ghc-$(ProjectVersion)/libraries/base/GHC/PrimopWrappers.hs >> hc-files-to-go
- echo ghc-$(ProjectVersion)/compiler/parser/Parser.hs >> hc-files-to-go
- echo ghc-$(ProjectVersion)/compiler/parser/ParserCore.hs >> hc-files-to-go
- echo ghc-$(ProjectVersion)/compiler/main/ParsePkgConf.hs >> hc-files-to-go
- echo ghc-$(ProjectVersion)/libraries/haskell-src/Language/Haskell/Parser.hs >> hc-files-to-go
- $(TAR) czf ghc-$(ProjectVersion)-$(TARGETPLATFORM)-hc.tar.gz `cat hc-files-to-go`
-
-# -----------------------------------------------------------------------------
-# Cleaning
-
-CLEAN_FILES += hc-files-to-go *-hc.tar.gz
+# ifeq "$(PHASE)" "0"
+# all :
+# $(MAKE) PHASE=1
+# else
+# all :
+# endif
+#
+# -include inc1.mk
+#
+# inc1.mk : Makefile
+# echo "X = C" >$@
+#
+# ifneq "$(PHASE)" "0"
+# include inc2.mk
+#
+# inc2.mk : inc1.mk
+# echo "Y = $(X)" >$@
+# endif
+#
+# clean :
+# rm -f inc1.mk inc2.mk
+# --------------------
-DIST_CLEAN_FILES += config.cache config.status mk/config.h mk/stamp-h \
- docs/users_guide/ug-book.xml extra-gcc-opts
+# That is, every time make is invoked, we force it to update inc1.mk
+# and then restart. In the GHC build system we need to divide the
+# build into 4 phases in fact, with a restart between each phase. See
+# ghc.mk for the details on what happens in each phase and why.
-# don't clean config.mk: it's needed when cleaning stuff later on
-LATE_DIST_CLEAN_FILES += mk/config.mk mk/are-validating.mk
+default : all
+ @:
-# VERSION is shipped in a source dist
-MAINTAINER_CLEAN_FILES += VERSION
+# No need to update makefiles for these targets:
+REALGOALS=$(filter-out clean clean_% distclean maintainer-clean show,$(MAKECMDGOALS))
-extraclean::
- $(RM) -rf autom4te.cache
+# NB. not the same as saying '%: ...', which doesn't do the right thing:
+# it does nothing if we specify a target that already exists.
+.PHONY: $(REALGOALS)
+$(REALGOALS) all:
+ @echo "===--- updating makefiles phase 0"
+ $(MAKE) -r --no-print-directory -f ghc.mk phase=0 just-makefiles
+ @echo "===--- updating makefiles phase 1"
+ $(MAKE) -r --no-print-directory -f ghc.mk phase=1 just-makefiles
+ @echo "===--- updating makefiles phase 2"
+ $(MAKE) -r --no-print-directory -f ghc.mk phase=2 just-makefiles
+ @echo "===--- updating makefiles phase 3"
+ $(MAKE) -r --no-print-directory -f ghc.mk phase=3 just-makefiles
+ @echo "===--- finished updating makefiles"
+ $(MAKE) -r --no-print-directory -f ghc.mk $@
-clean distclean ::
- $(RM) -rf inplace-datadir
+binary-dist:
+ rm -f bindist-list
+ $(MAKE) -r --no-print-directory -f ghc.mk bindist BINDIST=YES
+ $(MAKE) -r --no-print-directory -f ghc.mk binary-dist
-clean distclean ::
- $(MAKE) -C bindisttest $@
- if test -d testsuite; then $(MAKE) -C testsuite $@; fi
+clean distclean maintainer-clean:
+ $(MAKE) -r --no-print-directory -f ghc.mk $@
+ test ! -d testsuite || $(MAKE) -C testsuite $@
-# -----------------------------------------------------------------------------
+$(filter clean_%, $(MAKECMDGOALS)) : clean_% :
+ $(MAKE) -r --no-print-directory -f ghc.mk $@
-# Turn off target.mk's rules for 'all', 'boot' and 'install'.
-NO_BOOT_TARGET=YES
-NO_ALL_TARGET=YES
-NO_INSTALL_TARGET=YES
+show:
+ $(MAKE) -r --no-print-directory -f ghc.mk $@
-include $(TOP)/mk/target.mk
+# If the user says 'make A B', then we don't want to invoke two
+# instances of the rule above in parallel:
+.NOTPARALLEL:
-# -----------------------------------------------------------------------------
+endif
diff --git a/bindisttest/Makefile b/bindisttest/Makefile
index c14a08577b..8e2b911214 100644
--- a/bindisttest/Makefile
+++ b/bindisttest/Makefile
@@ -6,14 +6,14 @@ default_target: all
# Ideally we'd just include something to give us variables
# for paths and arguments to tools etc, and those set in mk/build.mk.
TOP=..
-include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/config.mk
all:
$(RM) -rf $(BIN_DIST_INST_SUBDIR)
$(RM) -rf ghc*
$(RM) HelloWorld HelloWorld.o HelloWorld.hi output
# --force-local makes tar not think that c:/foo refers to a remote file
- $(TAR) --force-local -jxf $(FPTOOLS_TOP_ABS)/$(BIN_DIST_TAR_BZ2)
+ $(TAR) --force-local -jxf $(BIN_DIST_TAR_BZ2)
ifeq "$(Windows)" "YES"
mv $(BIN_DIST_NAME) $(BIN_DIST_INST_DIR)
else
diff --git a/boot b/boot
index 18a083e02e..d586348de7 100644
--- a/boot
+++ b/boot
@@ -4,9 +4,9 @@ set -e
# Check that we have all boot packages.
for dir in `grep "^[^# ][^ ]* *[^ ][^ ]* *[^ ][^ ]*$" packages | sed "s/ .*//"`
do
- if test ! -d $dir
+ if test ! -f $dir/LICENSE
then
- echo "Looks like you're missing $dir." >&2
+ echo "Error: $dir/LICENSE doesn't exist." >&2
echo "Maybe you haven't done './darcs-all get'?" >&2
exit 1
fi
@@ -31,3 +31,19 @@ do
fi
done
+for f in libraries/*; do
+ dir=`basename $f`
+ cabals=`echo $f/*.cabal`
+ if test -f $cabals; then
+ echo "Creating $f/ghc.mk"
+ rm -f $f/ghc.mk
+ pkg=`basename ${cabals%.cabal}`
+ echo "${f}_PACKAGE = ${pkg}" >> $f/ghc.mk
+ echo "\$(eval \$(call build-package,${f},dist-install,1))" >> $f/ghc.mk
+ rm -f $f/GNUmakefile
+ echo "Creating $f/GNUmakefile"
+ echo "dir = ${f}" >> $f/GNUmakefile
+ echo "TOP = ../.." >> $f/GNUmakefile
+ echo "include \$(TOP)/mk/sub-makefile.mk" >> $f/GNUmakefile
+ fi
+done
diff --git a/compiler/LICENSE b/compiler/LICENSE
new file mode 100644
index 0000000000..b5059b71f6
--- /dev/null
+++ b/compiler/LICENSE
@@ -0,0 +1,31 @@
+The Glasgow Haskell Compiler License
+
+Copyright 2002, The University Court of the University of Glasgow.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+- Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+
+- Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
+and/or other materials provided with the distribution.
+
+- Neither name of the University nor the names of its contributors may be
+used to endorse or promote products derived from this software without
+specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF
+GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGE.
diff --git a/compiler/Makefile b/compiler/Makefile
index 18701532ca..f85e1c893c 100644
--- a/compiler/Makefile
+++ b/compiler/Makefile
@@ -1,503 +1,16 @@
-# -----------------------------------------------------------------------------
-# Main compiler Makefile
-
-# Targets:
-#
-# all builds stage1 compiler
-#
-# boot stage=N generate build dirs and dependencies for stage N.
-# NB. Must be done before 'make stageN'.
-# NB. Cannot 'make boot stage=2' until stage1 has
-# been built (similarly for stage3).
-#
-# stage1 (or stage=1) builds stage1 compiler
-# stage2 (or stage=2) builds stage2 compiler
-# stage3 (or stage=3) builds stage3 compiler
-#
-
+dir = compiler
TOP = ..
+SPEC_TARGETS = 1 2 3
+include $(TOP)/mk/sub-makefile.mk
-ifeq "$(stage)" ""
-stage=1
-endif
-
-include $(TOP)/mk/boilerplate.mk
-include $(TOP)/mk/cabal-flags.mk
-
-ifeq "$(GhcThreaded) $(GhcProfiled)" "YES YES"
-$(error Cannot make GHC both threaded and profiled)
-endif
-
-CONFIG_HS = main/Config.hs
-PRIMOP_BITS = primop-data-decl.hs-incl \
- primop-tag.hs-incl \
- primop-list.hs-incl \
- primop-has-side-effects.hs-incl \
- primop-out-of-line.hs-incl \
- primop-commutable.hs-incl \
- primop-needs-wrapper.hs-incl \
- primop-can-fail.hs-incl \
- primop-strictness.hs-incl \
- primop-primop-info.hs-incl
-
-boot:: boot.stage.$(stage)
-
-all:: build.stage.$(stage)
-
-doc:: doc.stage.$(stage)
-
-stage1 ::
- $(MAKE) stage=1
-
-stage2 ::
- $(MAKE) stage=2
-
-stage3 ::
- $(MAKE) stage=3
-
-ifeq "$(CLEAN_ALL_STAGES)" "YES"
-clean distclean maintainer-clean::
- $(RM) -f prelude/primops.txt
- $(RM) -f $(PRIMOP_BITS)
- $(RM) -f $(CONFIG_HS)
- $(RM) -f parser/Parser.y
- $(RM) -rf stage1 stage2plus
- $(RM) -f $(STAGE3_PACKAGE_CONF)
-endif
-
-ifeq "$(CLEAN_ALL_STAGES)" "YES"
-clean distclean maintainer-clean:: clean.stage.1 clean.stage.2 clean.stage.3
-else
-clean distclean maintainer-clean:: clean.stage.$(stage)
-endif
-
-ifeq "$(CLEAN_ALL_STAGES)" "YES"
-distclean maintainer-clean::
- $(RM) -f ghc.cabal
-endif
-
-clean.stage.%:
- $(RM) -f Makefile-stage$*
-# This is a bit naughty. We ought to use:
-# -$(CABAL) clean --distpref dist-stage$*
-# but that won't work if the Cabal file (a generated file) doesn't
-# exist. So we do this instead:
- $(RM) -rf dist-stage$*
-
-CONFIGURE_FLAGS_STAGE1 += --flags=stage1
-CONFIGURE_FLAGS_STAGE2 += --flags=-stage1
-
-ifeq "$(GhcWithNativeCodeGen)" "YES"
-CONFIGURE_FLAGS_STAGE1 += --flags=ncg
-CONFIGURE_FLAGS_STAGE2 += --flags=ncg
-endif
-
-ifeq "$(GhcWithInterpreter)" "YES"
-CONFIGURE_FLAGS_STAGE2 += --flags=ghci
-
-ifeq "$(BuildSharedLibs)" "YES"
-CONFIGURE_FLAGS_STAGE2 += --enable-shared
-# If we are going to use dynamic libraries instead of .o files for ghci,
-# we will need to always retain CAFs in the compiler.
-# ghci/keepCAFsForGHCi contains a GNU C __attribute__((constructor))
-# function which sets the keepCAFs flag for the RTS before any Haskell
-# code is run.
-CONFIGURE_FLAGS_STAGE2 += --flags=dynlibs
-endif
-
-ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
-# Should GHCI be building info tables in the TABLES_NEXT_TO_CODE style
-# or not?
-# XXX This should logically be a CPP option, but there doesn't seem to
-# be a flag for that
-CONFIGURE_FLAGS_STAGE2 += --ghc-option=-DGHCI_TABLES_NEXT_TO_CODE
-endif
-
-# Should the debugger commands be enabled?
-ifeq "$(GhciWithDebugger)" "YES"
-CONFIGURE_FLAGS_STAGE2 += --ghc-option=-DDEBUGGER
-endif
-
-# Enable editline if:
-# - we're building stage 2/3, and we have built the editline package
-#
-# But we don't enable editline on Windows, as Windows terminals have
-# editline-like support builtin.
-#
-ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-ifeq "$(wildcard $(FPTOOLS_TOP_ABS)/libraries/editline/unbuildable)" ""
-CONFIGURE_FLAGS_STAGE2 += --flags=editline
-endif
-endif
-endif
-
-ifeq "$(GhcWithNativeCodeGen)" "NO"
-# XXX This should logically be a CPP option, but there doesn't seem to
-# be a flag for that
-COMMON_CONFIGURE_FLAGS += --ghc-option=-DOMIT_NATIVE_CODEGEN
-endif
-
-ifeq "$(TargetOS_CPP)" "openbsd"
-COMMON_CONFIGURE_FLAGS += --ld-options=-E
-endif
-
-ifeq "$(GhcUnregisterised)" "NO"
-ifeq "$(HOSTPLATFORM)" "ia64-unknown-linux"
-# needed for generating proper relocation in large binaries: trac #856
-COMMON_CONFIGURE_FLAGS += --ld-option=-Wl,--relax
-endif
-endif
-
-# We need to turn on profiling either if we have been asked to
-# (GhcLibProfiled = YES) or if we want GHC itself to be compiled with
-# profiling enabled (GhcProfiled = YES).
-ifneq "$(GhcLibProfiled) $(GhcProfiled)" "NO NO"
-CONFIGURE_FLAGS_STAGE2 += --enable-library-profiling
-# And if we're profiling GHC then we want lots of SCCs.
-# We also don't want to waste time building the non-profiling library,
-# either normally or for ghci. Unfortunately this means that we have to
-# tell ghc-pkg --force as it gets upset when libHSghc-6.9.a doesn't
-# exist.
-ifeq "$(GhcProfiled)" "YES"
-CONFIGURE_FLAGS_STAGE2 += --ghc-option=-auto-all
-CONFIGURE_FLAGS_STAGE2 += --disable-library-vanilla
-CONFIGURE_FLAGS_STAGE2 += --disable-library-for-ghci
-CONFIGURE_FLAGS_STAGE2 += --ghc-pkg-option=--force
-endif
-endif
-
-ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
-# The #include is vital for the via-C route with older compilers, else the C
-# compiler doesn't realise that the stcall foreign imports are indeed
-# stdcall, and doesn't generate the Foo@8 name for them
-# As it's only important for older compilers we don't need to do anything
-# for stage2+.
-CONFIGURE_FLAGS_STAGE1 += --ghc-option='-\#include' \
- --ghc-option='"<windows.h>"' \
- --ghc-option='-\#include' \
- --ghc-option='"<process.h>"'
-endif
-
-# ghc_strlen percolates through so many modules that it is easier to get its
-# prototype via a global option instead of a myriad of per-file OPTIONS.
-# Again, this is only important for older compilers, so we don't do it in
-# stage 2+.
-CONFIGURE_FLAGS_STAGE1 += --ghc-options='-\#include "cutils.h"'
-
-CONFIGURE_FLAGS_STAGE3 = $(CONFIGURE_FLAGS_STAGE2)
-CONFIGURE_FLAGS_STAGE1 += $(USE_BOOT_CONFIGURE_FLAGS)
-CONFIGURE_FLAGS_STAGE2 += $(USE_STAGE1_CONFIGURE_FLAGS)
-CONFIGURE_FLAGS_STAGE3 += $(USE_STAGE2_CONFIGURE_FLAGS)
-CONFIGURE_FLAGS_STAGE3 += --package-db $(STAGE3_PACKAGE_CONF)
-
-# In a source dist we don't need to worry about Parser.y(.pp) as we have
-# the .hs file pre-generated
-ifneq "$(wildcard parser/Parser.y.pp)" ""
-PARSER_Y = parser/Parser.y
-endif
-
-boot.stage.%: $(PRIMOP_BITS) $(CONFIG_HS) $(PARSER_Y)
- test -f $(STAGE3_PACKAGE_CONF) || echo "[]" > $(STAGE3_PACKAGE_CONF)
- $(CABAL) configure --distpref dist-stage$* \
- $(CONFIGURE_FLAGS_STAGE$*) \
- $(INSTALL_DIRS_CONFIGURE_FLAGS) \
- $(COMMON_CONFIGURE_FLAGS) \
- --ghc-option=-DSTAGE=$*
- $(RM) -f Makefile-stage$*
- $(CABAL) makefile --distpref dist-stage$* -f Makefile-stage$*
-
-build.stage.%:
- $(MAKE) -f Makefile-stage$* stage=$*
- $(CABAL) register --distpref dist-stage$* --inplace
- $(MAKE) -C ../ghc stage=$*
-
-doc.stage.%:
- $(CABAL) haddock --distpref dist-stage$* \
- --html-location='../$$pkg' \
- --haddock-option=--optghc=-DSTAGE=$* \
- --haddock-option=+RTS --haddock-option=-s --haddock-option=-c --haddock-option=-RTS \
- --with-haddock=$(FPTOOLS_TOP_ABS)/utils/haddock/install-inplace/bin/haddock
-
-install:
- $(INSTALL_PACKAGE) install '$(GHC_PKG_INSTALL_PROG)' '$(DESTDIR)$(datadir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' --distpref dist-stage2
-
-# -----------------------------------------------------------------------------
-# Create compiler configuration
-#
-# The 'echo' commands simply spit the values of various make variables
-# into Config.hs, whence they can be compiled and used by GHC itself
-
-$(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk
- @$(RM) -f $(CONFIG_HS)
- @echo "Creating $(CONFIG_HS) ... "
- @echo "module Config where" >>$(CONFIG_HS)
- @echo "cProjectName :: String" >> $(CONFIG_HS)
- @echo "cProjectName = \"$(ProjectName)\"" >> $(CONFIG_HS)
- @echo "cProjectVersion :: String" >> $(CONFIG_HS)
- @echo "cProjectVersion = \"$(ProjectVersion)\"" >> $(CONFIG_HS)
- @echo "cProjectVersionInt :: String" >> $(CONFIG_HS)
- @echo "cProjectVersionInt = \"$(ProjectVersionInt)\"" >> $(CONFIG_HS)
- @echo "cProjectPatchLevel :: String" >> $(CONFIG_HS)
- @echo "cProjectPatchLevel = \"$(ProjectPatchLevel)\"" >> $(CONFIG_HS)
- @echo "cBooterVersion :: String" >> $(CONFIG_HS)
- @echo "cBooterVersion = \"$(GhcVersion)\"" >> $(CONFIG_HS)
- @echo "cStage :: String" >> $(CONFIG_HS)
- @echo "cStage = show (STAGE :: Int)" >> $(CONFIG_HS)
- @echo "cHscIfaceFileVersion :: String" >> $(CONFIG_HS)
- @echo "cHscIfaceFileVersion = \"$(HscIfaceFileVersion)\"" >> $(CONFIG_HS)
- @echo "cSplitObjs :: String" >> $(CONFIG_HS)
- @echo "cSplitObjs = \"$(SupportsSplitObjs)\"" >> $(CONFIG_HS)
- @echo "cGhcWithInterpreter :: String" >> $(CONFIG_HS)
- @echo "cGhcWithInterpreter = \"$(GhcWithInterpreter)\"" >> $(CONFIG_HS)
- @echo "cGhcWithNativeCodeGen :: String" >> $(CONFIG_HS)
- @echo "cGhcWithNativeCodeGen = \"$(GhcWithNativeCodeGen)\"" >> $(CONFIG_HS)
- @echo "cGhcWithSMP :: String" >> $(CONFIG_HS)
- @echo "cGhcWithSMP = \"$(GhcWithSMP)\"" >> $(CONFIG_HS)
- @echo "cGhcRTSWays :: String" >> $(CONFIG_HS)
- @echo "cGhcRTSWays = \"$(GhcRTSWays)\"" >> $(CONFIG_HS)
- @echo "cGhcUnregisterised :: String" >> $(CONFIG_HS)
- @echo "cGhcUnregisterised = \"$(GhcUnregisterised)\"" >> $(CONFIG_HS)
- @echo "cGhcEnableTablesNextToCode :: String" >> $(CONFIG_HS)
- @echo "cGhcEnableTablesNextToCode = \"$(GhcEnableTablesNextToCode)\"" >> $(CONFIG_HS)
- @echo "cLeadingUnderscore :: String" >> $(CONFIG_HS)
- @echo "cLeadingUnderscore = \"$(LeadingUnderscore)\"" >> $(CONFIG_HS)
- @echo "cRAWCPP_FLAGS :: String" >> $(CONFIG_HS)
- @echo "cRAWCPP_FLAGS = \"$(RAWCPP_FLAGS)\"" >> $(CONFIG_HS)
- @echo "cGCC :: String" >> $(CONFIG_HS)
- @echo "cGCC = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
- @echo "cMKDLL :: String" >> $(CONFIG_HS)
- @echo "cMKDLL = \"$(BLD_DLL)\"" >> $(CONFIG_HS)
- @echo "cLdIsGNULd :: String" >> $(CONFIG_HS)
- @echo "cLdIsGNULd = \"$(LdIsGNULd)\"" >> $(CONFIG_HS)
- @echo "cLD_X :: String" >> $(CONFIG_HS)
- @echo "cLD_X = \"$(LD_X)\"" >> $(CONFIG_HS)
- @echo "cGHC_DRIVER_DIR_REL :: String" >> $(CONFIG_HS)
- @echo "cGHC_DRIVER_DIR_REL = \"$(GHC_DRIVER_DIR_REL)\"" >> $(CONFIG_HS)
- @echo "cGHC_TOUCHY_PGM :: String" >> $(CONFIG_HS)
- @echo "cGHC_TOUCHY_PGM = \"$(GHC_TOUCHY_PGM)\"" >> $(CONFIG_HS)
- @echo "cGHC_TOUCHY_DIR_REL :: String" >> $(CONFIG_HS)
- @echo "cGHC_TOUCHY_DIR_REL = \"$(GHC_TOUCHY_DIR_REL)\"" >> $(CONFIG_HS)
- @echo "cGHC_UNLIT_PGM :: String" >> $(CONFIG_HS)
- @echo "cGHC_UNLIT_PGM = \"$(GHC_UNLIT_PGM)\"" >> $(CONFIG_HS)
- @echo "cGHC_UNLIT_DIR_REL :: String" >> $(CONFIG_HS)
- @echo "cGHC_UNLIT_DIR_REL = \"$(GHC_UNLIT_DIR_REL)\"" >> $(CONFIG_HS)
- @echo "cGHC_MANGLER_PGM :: String" >> $(CONFIG_HS)
- @echo "cGHC_MANGLER_PGM = \"$(GHC_MANGLER_PGM)\"" >> $(CONFIG_HS)
- @echo "cGHC_MANGLER_DIR_REL :: String" >> $(CONFIG_HS)
- @echo "cGHC_MANGLER_DIR_REL = \"$(GHC_MANGLER_DIR_REL)\"" >> $(CONFIG_HS)
- @echo "cGHC_SPLIT_PGM :: String" >> $(CONFIG_HS)
- @echo "cGHC_SPLIT_PGM = \"$(GHC_SPLIT_PGM)\"" >> $(CONFIG_HS)
- @echo "cGHC_SPLIT_DIR_REL :: String" >> $(CONFIG_HS)
- @echo "cGHC_SPLIT_DIR_REL = \"$(GHC_SPLIT_DIR_REL)\"" >> $(CONFIG_HS)
- @echo "cGHC_SYSMAN_PGM :: String" >> $(CONFIG_HS)
- @echo "cGHC_SYSMAN_PGM = \"$(GHC_SYSMAN)\"" >> $(CONFIG_HS)
- @echo "cGHC_SYSMAN_DIR_REL :: String" >> $(CONFIG_HS)
- @echo "cGHC_SYSMAN_DIR_REL = \"$(GHC_SYSMAN_DIR)\"" >> $(CONFIG_HS)
- @echo "cGHC_CP :: String" >> $(CONFIG_HS)
- @echo "cGHC_CP = \"$(GHC_CP)\"" >> $(CONFIG_HS)
- @echo "cGHC_PERL :: String" >> $(CONFIG_HS)
- @echo "cGHC_PERL = \"$(GHC_PERL)\"" >> $(CONFIG_HS)
- @echo "cEnableWin32DLLs :: String" >> $(CONFIG_HS)
- @echo "cEnableWin32DLLs = \"$(EnableWin32DLLs)\"" >> $(CONFIG_HS)
- @echo "cCONTEXT_DIFF :: String" >> $(CONFIG_HS)
- @echo "cCONTEXT_DIFF = \"$(CONTEXT_DIFF)\"" >> $(CONFIG_HS)
- @echo "cUSER_WAY_NAMES :: String" >> $(CONFIG_HS)
- @echo "cUSER_WAY_NAMES = \"$(USER_WAY_NAMES)\"" >> $(CONFIG_HS)
- @echo "cUSER_WAY_OPTS :: String" >> $(CONFIG_HS)
- @echo "cUSER_WAY_OPTS = \"$(USER_WAY_OPTS)\"" >> $(CONFIG_HS)
- @echo "cDEFAULT_TMPDIR :: String" >> $(CONFIG_HS)
- @echo "cDEFAULT_TMPDIR = \"$(DEFAULT_TMPDIR)\"" >> $(CONFIG_HS)
- @echo "cRelocatableBuild :: Bool" >> $(CONFIG_HS)
-ifeq "$(RelocatableBuild)" "YES"
- @echo "cRelocatableBuild = True" >> $(CONFIG_HS)
-else
- @echo "cRelocatableBuild = False" >> $(CONFIG_HS)
-endif
- @echo "cLibFFI :: Bool" >> $(CONFIG_HS)
-ifeq "$(UseLibFFIForAdjustors)" "YES"
- @echo "cLibFFI = True" >> $(CONFIG_HS)
-else
- @echo "cLibFFI = False" >> $(CONFIG_HS)
-endif
- @echo done.
-
-# -----------------------------------------------------------------------------
-# Create platform includes
-
-# Here we generate a little header file containing CPP symbols that GHC
-# uses to determine which platform it is building on/for. The platforms
-# can differ between stage1 and stage2 if we're cross-compiling, so we
-# need one of these header files per stage.
-
-PLATFORM_H = ghc_boot_platform.h
-
-stage1/$(PLATFORM_H) : $(FPTOOLS_TOP)/mk/config.mk
- $(MKDIRHIER) stage1
- @echo "Creating $@..."
- @$(RM) $@
- @echo "#ifndef __PLATFORM_H__" >$@
- @echo "#define __PLATFORM_H__" >>$@
- @echo >> $@
- @echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
- @echo "#define HostPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
- @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
- @echo >> $@
- @echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
- @echo "#define $(HostPlatform_CPP)_HOST 1" >> $@
- @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
- @echo >> $@
- @echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
- @echo "#define $(HostArch_CPP)_HOST_ARCH 1" >> $@
- @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
- @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
- @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
- @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
- @echo >> $@
- @echo "#define $(BuildOS_CPP)_BUILD_OS 1" >> $@
- @echo "#define $(HostOS_CPP)_HOST_OS 1" >> $@
- @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
- @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
- @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
- @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
-ifeq "$(HostOS_CPP)" "irix"
- @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS " >> $@
- @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
- @echo "#endif " >> $@
-endif
- @echo >> $@
- @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
- @echo "#define $(HostVendor_CPP)_HOST_VENDOR 1" >> $@
- @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
- @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
- @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
- @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
- @echo >> $@
- @echo "#endif /* __PLATFORM_H__ */" >> $@
- @echo "Done."
-
-# For stage2 and above, the BUILD platform is the HOST of stage1, and
-# the HOST platform is the TARGET of stage1. The TARGET remains the same
-# (stage1 is the cross-compiler, not stage2).
-stage2plus/$(PLATFORM_H) : $(FPTOOLS_TOP)/mk/config.mk
- $(MKDIRHIER) stage2plus
- @echo "Creating $@..."
- @$(RM) $@
- @echo "#ifndef __PLATFORM_H__" >$@
- @echo "#define __PLATFORM_H__" >>$@
- @echo >> $@
- @echo "#define BuildPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
- @echo "#define HostPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
- @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
- @echo >> $@
- @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
- @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
- @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
- @echo >> $@
- @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
- @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
- @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
- @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
- @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
- @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
- @echo >> $@
- @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
- @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
- @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
- @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
- @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
- @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
-ifeq "$(HostOS_CPP)" "irix"
- @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS " >> $@
- @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
- @echo "#endif " >> $@
-endif
- @echo >> $@
- @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
- @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
- @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
- @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
- @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
- @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
- @echo >> $@
- @echo "#endif /* __PLATFORM_H__ */" >> $@
- @echo "Done."
-
-ifeq "$(stage)" "1"
-STAGE_PLATFORM_H = stage1/$(PLATFORM_H)
-else
-STAGE_PLATFORM_H = stage2plus/$(PLATFORM_H)
-endif
-
-boot :: $(STAGE_PLATFORM_H)
-
-# ----------------------------------------------------------------------------
-# Generate supporting stuff for prelude/PrimOp.lhs
-# from prelude/primops.txt
-
-SRC_CPP_OPTS += -I$(GHC_INCLUDE_DIR)
-SRC_CPP_OPTS += ${GhcCppOpts}
-
-prelude/primops.txt parser/Parser.y: %: %.pp stage1/$(PLATFORM_H)
- $(CPP) $(RAWCPP_FLAGS) -P $(CPP_OPTS) -x c $< | grep -v '^#pragma GCC' > $@
-
-primop-data-decl.hs-incl: prelude/primops.txt
- $(GENPRIMOP) --data-decl < $< > $@
-primop-tag.hs-incl: prelude/primops.txt
- $(GENPRIMOP) --primop-tag < $< > $@
-primop-list.hs-incl: prelude/primops.txt
- $(GENPRIMOP) --primop-list < $< > $@
-primop-has-side-effects.hs-incl: prelude/primops.txt
- $(GENPRIMOP) --has-side-effects < $< > $@
-primop-out-of-line.hs-incl: prelude/primops.txt
- $(GENPRIMOP) --out-of-line < $< > $@
-primop-commutable.hs-incl: prelude/primops.txt
- $(GENPRIMOP) --commutable < $< > $@
-primop-needs-wrapper.hs-incl: prelude/primops.txt
- $(GENPRIMOP) --needs-wrapper < $< > $@
-primop-can-fail.hs-incl: prelude/primops.txt
- $(GENPRIMOP) --can-fail < $< > $@
-primop-strictness.hs-incl: prelude/primops.txt
- $(GENPRIMOP) --strictness < $< > $@
-primop-primop-info.hs-incl: prelude/primops.txt
- $(GENPRIMOP) --primop-primop-info < $< > $@
-
-# Usages aren't used any more; but the generator
-# can still generate them if we want them back
-primop-usage.hs-incl: prelude/primops.txt
- $(GENPRIMOP) --usage < $< > $@
-
-html:
- $(MAKE) doc stage=2
-
-install-docs:
- @:
-
-#-----------------------------------------------------------------------------
-# binary-dist
-#
+.PHONY: 1 2 3
-# Ideally we'd get these from the Cabal file's Install-Includes:
-BINDIST_EXTRAS += HsVersions.h
-ifeq "$(stage)" "1"
-BINDIST_EXTRAS += stage1/ghc_boot_platform.h
-else
-BINDIST_EXTRAS += stage2plus/ghc_boot_platform.h
-endif
+1:
+ +$(TOPMAKE) stage=1 all_ghc_stage1 compiler_stage1_NO_BUILD_DEPS=YES
-include $(TOP)/mk/bindist.mk
-LIB_DIST_DIR = dist-stage2
+2:
+ +$(TOPMAKE) stage=2 all_ghc_stage2 compiler_stage2_NO_BUILD_DEPS=YES
-#-----------------------------------------------------------------------------
-# etags generation
-ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
-GHCTAGS = $(TOP)/utils/ghctags/ghctags.exe
-else
-GHCTAGS = $(TOP)/utils/ghctags/ghctags-inplace
-endif
-GHCTAGS_ROOT = main/GHC.hs ghci/InteractiveUI.hs main/PprTyThing.hs
+3:
+ +$(TOPMAKE) stage=3 all_ghc_stage3 compiler_stage3_NO_BUILD_DEPS=YES
-# etags for stage2 is actually broken since it requires building
-# ghctags against an older ghc api
-etags: etags.stage.2
-etags.stage.%:
- $(GHCTAGS) --topdir $(FPTOOLS_TOP_ABS) --etags --use-cabal-config=./dist-stage$* -- -DSTAGE=$* -- $(GHCTAGS_ROOT)
diff --git a/compiler/ghc.cabal.in b/compiler/ghc.cabal.in
index b37165805a..55f235a298 100644
--- a/compiler/ghc.cabal.in
+++ b/compiler/ghc.cabal.in
@@ -1,3 +1,6 @@
+-- WARNING: ghc.cabal is automatically generated from ghc.cabal.in by
+-- ./configure. Make sure you are editing ghc.cabal.in, not ghc.cabal.
+
Name: ghc
Version: @ProjectVersion@
License: BSD3
@@ -45,6 +48,15 @@ Flag ncg
Flag stage1
Description: Is this stage 1?
+ Default: False
+
+Flag stage2
+ Description: Is this stage 2?
+ Default: False
+
+Flag stage3
+ Description: Is this stage 3?
+ Default: False
Library
Exposed: False
@@ -103,7 +115,12 @@ Library
Build-Depends: extensible-exceptions
Extensions: PatternSignatures
else
- Include-Dirs: stage2plus
+ if flag(stage2)
+ Include-Dirs: stage2
+ else
+ if flag(stage3)
+ Include-Dirs: stage2
+
Install-Includes: HsVersions.h, ghc_boot_platform.h
c-sources:
diff --git a/compiler/ghc.mk b/compiler/ghc.mk
new file mode 100644
index 0000000000..a1969e8f98
--- /dev/null
+++ b/compiler/ghc.mk
@@ -0,0 +1,432 @@
+# -----------------------------------------------------------------------------
+# For expressing extra dependencies on source files
+
+define compiler-hs-dependency # args: $1 = module, $2 = dependency
+
+$$(foreach stage,1 2 3,\
+ $$(foreach way,$$(compiler_stage$$(stage)_WAYS),\
+ compiler/stage$$(stage)/build/$1.$($(way)_osuf))) : $2
+
+endef
+
+# -----------------------------------------------------------------------------
+# Create compiler configuration
+#
+# The 'echo' commands simply spit the values of various make variables
+# into Config.hs, whence they can be compiled and used by GHC itself
+
+compiler_CONFIG_HS = compiler/main/Config.hs
+
+ifneq "$(BINDIST)" "YES"
+compiler/stage1/package-data.mk : $(compiler_CONFIG_HS)
+compiler/stage2/package-data.mk : $(compiler_CONFIG_HS)
+compiler/stage3/package-data.mk : $(compiler_CONFIG_HS)
+endif
+
+$(compiler_CONFIG_HS) : mk/config.mk
+ $(RM) -f $@
+ @echo "Creating $@ ... "
+ @echo "module Config where" >>$@
+ @echo "cProjectName :: String" >> $@
+ @echo "cProjectName = \"$(ProjectName)\"" >> $@
+ @echo "cProjectVersion :: String" >> $@
+ @echo "cProjectVersion = \"$(ProjectVersion)\"" >> $@
+ @echo "cProjectVersionInt :: String" >> $@
+ @echo "cProjectVersionInt = \"$(ProjectVersionInt)\"" >> $@
+ @echo "cProjectPatchLevel :: String" >> $@
+ @echo "cProjectPatchLevel = \"$(ProjectPatchLevel)\"" >> $@
+ @echo "cBooterVersion :: String" >> $@
+ @echo "cBooterVersion = \"$(GhcVersion)\"" >> $@
+ @echo "cStage :: String" >> $@
+ @echo "cStage = show (STAGE :: Int)" >> $@
+ @echo "cHscIfaceFileVersion :: String" >> $@
+ @echo "cHscIfaceFileVersion = \"$(HscIfaceFileVersion)\"" >> $@
+ @echo "cSplitObjs :: String" >> $@
+ @echo "cSplitObjs = \"$(SupportsSplitObjs)\"" >> $@
+ @echo "cGhcWithInterpreter :: String" >> $@
+ @echo "cGhcWithInterpreter = \"$(GhcWithInterpreter)\"" >> $@
+ @echo "cGhcWithNativeCodeGen :: String" >> $@
+ @echo "cGhcWithNativeCodeGen = \"$(GhcWithNativeCodeGen)\"" >> $@
+ @echo "cGhcWithSMP :: String" >> $@
+ @echo "cGhcWithSMP = \"$(GhcWithSMP)\"" >> $@
+ @echo "cGhcRTSWays :: String" >> $@
+ @echo "cGhcRTSWays = \"$(GhcRTSWays)\"" >> $@
+ @echo "cGhcUnregisterised :: String" >> $@
+ @echo "cGhcUnregisterised = \"$(GhcUnregisterised)\"" >> $@
+ @echo "cGhcEnableTablesNextToCode :: String" >> $@
+ @echo "cGhcEnableTablesNextToCode = \"$(GhcEnableTablesNextToCode)\"" >> $@
+ @echo "cLeadingUnderscore :: String" >> $@
+ @echo "cLeadingUnderscore = \"$(LeadingUnderscore)\"" >> $@
+ @echo "cRAWCPP_FLAGS :: String" >> $@
+ @echo "cRAWCPP_FLAGS = \"$(RAWCPP_FLAGS)\"" >> $@
+ @echo "cGCC :: String" >> $@
+ @echo "cGCC = \"$(WhatGccIsCalled)\"" >> $@
+ @echo "cMKDLL :: String" >> $@
+ @echo "cMKDLL = \"$(BLD_DLL)\"" >> $@
+ @echo "cLdIsGNULd :: String" >> $@
+ @echo "cLdIsGNULd = \"$(LdIsGNULd)\"" >> $@
+ @echo "cLD_X :: String" >> $@
+ @echo "cLD_X = \"$(LD_X)\"" >> $@
+ @echo "cGHC_DRIVER_DIR :: String" >> $@
+ @echo "cGHC_DRIVER_DIR = \"$(GHC_DRIVER_DIR)\"" >> $@
+ @echo "cGHC_TOUCHY_PGM :: String" >> $@
+ @echo "cGHC_TOUCHY_PGM = \"$(GHC_TOUCHY_PGM)\"" >> $@
+ @echo "cGHC_TOUCHY_DIR :: String" >> $@
+ @echo "cGHC_TOUCHY_DIR = \"$(GHC_TOUCHY_DIR)\"" >> $@
+ @echo "cGHC_UNLIT_PGM :: String" >> $@
+ @echo "cGHC_UNLIT_PGM = \"$(GHC_UNLIT_PGM)\"" >> $@
+ @echo "cGHC_UNLIT_DIR :: String" >> $@
+ @echo "cGHC_UNLIT_DIR = \"$(GHC_UNLIT_DIR)\"" >> $@
+ @echo "cGHC_MANGLER_PGM :: String" >> $@
+ @echo "cGHC_MANGLER_PGM = \"$(GHC_MANGLER_PGM)\"" >> $@
+ @echo "cGHC_MANGLER_DIR :: String" >> $@
+ @echo "cGHC_MANGLER_DIR = \"$(GHC_MANGLER_DIR)\"" >> $@
+ @echo "cGHC_SPLIT_PGM :: String" >> $@
+ @echo "cGHC_SPLIT_PGM = \"$(GHC_SPLIT_PGM)\"" >> $@
+ @echo "cGHC_SPLIT_DIR :: String" >> $@
+ @echo "cGHC_SPLIT_DIR = \"$(GHC_SPLIT_DIR)\"" >> $@
+ @echo "cGHC_SYSMAN_PGM :: String" >> $@
+ @echo "cGHC_SYSMAN_PGM = \"$(GHC_SYSMAN)\"" >> $@
+ @echo "cGHC_SYSMAN_DIR :: String" >> $@
+ @echo "cGHC_SYSMAN_DIR = \"$(GHC_SYSMAN_DIR)\"" >> $@
+ @echo "cGHC_CP :: String" >> $@
+ @echo "cGHC_CP = \"$(GHC_CP)\"" >> $@
+ @echo "cGHC_PERL :: String" >> $@
+ @echo "cGHC_PERL = \"$(GHC_PERL)\"" >> $@
+ @echo "cEnableWin32DLLs :: String" >> $@
+ @echo "cEnableWin32DLLs = \"$(EnableWin32DLLs)\"" >> $@
+ @echo "cCONTEXT_DIFF :: String" >> $@
+ @echo "cCONTEXT_DIFF = \"$(CONTEXT_DIFF)\"" >> $@
+ @echo "cUSER_WAY_NAMES :: String" >> $@
+ @echo "cUSER_WAY_NAMES = \"$(USER_WAY_NAMES)\"" >> $@
+ @echo "cUSER_WAY_OPTS :: String" >> $@
+ @echo "cUSER_WAY_OPTS = \"$(USER_WAY_OPTS)\"" >> $@
+ @echo "cDEFAULT_TMPDIR :: String" >> $@
+ @echo "cDEFAULT_TMPDIR = \"$(DEFAULT_TMPDIR)\"" >> $@
+ @echo "cRelocatableBuild :: Bool" >> $@
+ifeq "$(RelocatableBuild)" "YES"
+ @echo "cRelocatableBuild = True" >> $@
+else
+ @echo "cRelocatableBuild = False" >> $@
+endif
+ @echo "cLibFFI :: Bool" >> $@
+ifeq "$(UseLibFFIForAdjustors)" "YES"
+ @echo "cLibFFI = True" >> $@
+else
+ @echo "cLibFFI = False" >> $@
+endif
+ @echo done.
+
+$(eval $(call clean-target,compiler,config_hs,$(compiler_CONFIG_HS)))
+
+# -----------------------------------------------------------------------------
+# Create platform includes
+
+# Here we generate a little header file containing CPP symbols that GHC
+# uses to determine which platform it is building on/for. The platforms
+# can differ between stage1 and stage2 if we're cross-compiling, so we
+# need one of these header files per stage.
+
+PLATFORM_H = ghc_boot_platform.h
+
+compiler/stage1/$(PLATFORM_H) : mk/config.mk
+ $(MKDIRHIER) $(dir $@)
+ $(RM) $@
+ @echo "Creating $@..."
+ @echo "#ifndef __PLATFORM_H__" >$@
+ @echo "#define __PLATFORM_H__" >>$@
+ @echo >> $@
+ @echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
+ @echo "#define HostPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
+ @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
+ @echo >> $@
+ @echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
+ @echo "#define $(HostPlatform_CPP)_HOST 1" >> $@
+ @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
+ @echo >> $@
+ @echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
+ @echo "#define $(HostArch_CPP)_HOST_ARCH 1" >> $@
+ @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
+ @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
+ @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
+ @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
+ @echo >> $@
+ @echo "#define $(BuildOS_CPP)_BUILD_OS 1" >> $@
+ @echo "#define $(HostOS_CPP)_HOST_OS 1" >> $@
+ @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
+ @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
+ @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
+ @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
+ifeq "$(HostOS_CPP)" "irix"
+ @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS " >> $@
+ @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
+ @echo "#endif " >> $@
+endif
+ @echo >> $@
+ @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
+ @echo "#define $(HostVendor_CPP)_HOST_VENDOR 1" >> $@
+ @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
+ @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
+ @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
+ @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
+ @echo >> $@
+ @echo "#endif /* __PLATFORM_H__ */" >> $@
+ @echo "Done."
+
+# For stage2 and above, the BUILD platform is the HOST of stage1, and
+# the HOST platform is the TARGET of stage1. The TARGET remains the same
+# (stage1 is the cross-compiler, not stage2).
+compiler/stage2/$(PLATFORM_H) : mk/config.mk
+ $(MKDIRHIER) $(dir $@)
+ $(RM) $@
+ @echo "Creating $@..."
+ @echo "#ifndef __PLATFORM_H__" >$@
+ @echo "#define __PLATFORM_H__" >>$@
+ @echo >> $@
+ @echo "#define BuildPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
+ @echo "#define HostPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
+ @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
+ @echo >> $@
+ @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
+ @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
+ @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
+ @echo >> $@
+ @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
+ @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
+ @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
+ @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
+ @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
+ @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
+ @echo >> $@
+ @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
+ @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
+ @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
+ @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
+ @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
+ @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
+ifeq "$(HostOS_CPP)" "irix"
+ @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS " >> $@
+ @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
+ @echo "#endif " >> $@
+endif
+ @echo >> $@
+ @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
+ @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
+ @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
+ @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
+ @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
+ @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
+ @echo >> $@
+ @echo "#endif /* __PLATFORM_H__ */" >> $@
+ @echo "Done."
+
+compiler/stage3/$(PLATFORM_H) : compiler/stage2/$(PLATFORM_H)
+ $(CP) $< $@
+
+# Every Constants.o object file depends on includes/GHCConstants.h:
+$(eval $(call compiler-hs-dependency,Constants,$(includes_GHCCONSTANTS)))
+
+# ----------------------------------------------------------------------------
+# Generate supporting stuff for prelude/PrimOp.lhs
+# from prelude/primops.txt
+
+# XXX: these should go in stage1/stage2/stage3
+PRIMOP_BITS = compiler/primop-data-decl.hs-incl \
+ compiler/primop-tag.hs-incl \
+ compiler/primop-list.hs-incl \
+ compiler/primop-has-side-effects.hs-incl \
+ compiler/primop-out-of-line.hs-incl \
+ compiler/primop-commutable.hs-incl \
+ compiler/primop-needs-wrapper.hs-incl \
+ compiler/primop-can-fail.hs-incl \
+ compiler/primop-strictness.hs-incl \
+ compiler/primop-primop-info.hs-incl
+
+compiler_CPP_OPTS += -I$(GHC_INCLUDE_DIR)
+compiler_CPP_OPTS += ${GhcCppOpts}
+
+$(PRIMOPS_TXT) compiler/parser/Parser.y: %: %.pp compiler/stage1/$(PLATFORM_H)
+ $(CPP) $(RAWCPP_FLAGS) -P $(compiler_CPP_OPTS) -x c $< | grep -v '^#pragma GCC' > $@
+
+$(eval $(call clean-target,compiler,primop, $(PRIMOPS_TXT) compiler/parser/Parser.y $(PRIMOP_BITS)))
+
+compiler/primop-data-decl.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
+ $(GENPRIMOP_INPLACE) --data-decl < $< > $@
+compiler/primop-tag.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
+ $(GENPRIMOP_INPLACE) --primop-tag < $< > $@
+compiler/primop-list.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
+ $(GENPRIMOP_INPLACE) --primop-list < $< > $@
+compiler/primop-has-side-effects.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
+ $(GENPRIMOP_INPLACE) --has-side-effects < $< > $@
+compiler/primop-out-of-line.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
+ $(GENPRIMOP_INPLACE) --out-of-line < $< > $@
+compiler/primop-commutable.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
+ $(GENPRIMOP_INPLACE) --commutable < $< > $@
+compiler/primop-needs-wrapper.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
+ $(GENPRIMOP_INPLACE) --needs-wrapper < $< > $@
+compiler/primop-can-fail.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
+ $(GENPRIMOP_INPLACE) --can-fail < $< > $@
+compiler/primop-strictness.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
+ $(GENPRIMOP_INPLACE) --strictness < $< > $@
+compiler/primop-primop-info.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
+ $(GENPRIMOP_INPLACE) --primop-primop-info < $< > $@
+
+# Every PrimOp.o object file depends on $(PRIMOP_BITS):
+$(eval $(call compiler-hs-dependency,PrimOp,$(PRIMOP_BITS)))
+
+# Usages aren't used any more; but the generator
+# can still generate them if we want them back
+compiler/primop-usage.hs-incl: $(PRIMOPS_TXT)
+ $(GENPRIMOP_INPLACE) --usage < $< > $@
+
+# -----------------------------------------------------------------------------
+# Configuration
+
+compiler_stage1_CONFIGURE_OPTS += --flags=stage1
+compiler_stage2_CONFIGURE_OPTS += --flags=stage2
+compiler_stage3_CONFIGURE_OPTS += --flags=stage3
+
+ifeq "$(GhcWithNativeCodeGen)" "YES"
+compiler_stage1_CONFIGURE_OPTS += --flags=ncg
+compiler_stage2_CONFIGURE_OPTS += --flags=ncg
+endif
+
+ifeq "$(GhcWithInterpreter)" "YES"
+compiler_stage2_CONFIGURE_OPTS += --flags=ghci
+
+ifeq "$(BuildSharedLibs)" "YES"
+compiler_stage2_CONFIGURE_OPTS += --enable-shared
+# If we are going to use dynamic libraries instead of .o files for ghci,
+# we will need to always retain CAFs in the compiler.
+# ghci/keepCAFsForGHCi contains a GNU C __attribute__((constructor))
+# function which sets the keepCAFs flag for the RTS before any Haskell
+# code is run.
+compiler_stage2_CONFIGURE_OPTS += --flags=dynlibs
+endif
+
+ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
+# Should GHCI be building info tables in the TABLES_NEXT_TO_CODE style
+# or not?
+# XXX This should logically be a CPP option, but there doesn't seem to
+# be a flag for that
+compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DGHCI_TABLES_NEXT_TO_CODE
+endif
+
+# Should the debugger commands be enabled?
+ifeq "$(GhciWithDebugger)" "YES"
+compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DDEBUGGER
+endif
+
+endif
+
+ifeq "$(GhcWithNativeCodeGen)" "NO"
+# XXX This should logically be a CPP option, but there doesn't seem to
+# be a flag for that
+compiler_CONFIGURE_OPTS += --ghc-option=-DOMIT_NATIVE_CODEGEN
+endif
+
+ifeq "$(TargetOS_CPP)" "openbsd"
+compiler_CONFIGURE_OPTS += --ld-options=-E
+endif
+
+ifeq "$(GhcUnregisterised)" "NO"
+ifeq "$(HOSTPLATFORM)" "ia64-unknown-linux"
+# needed for generating proper relocation in large binaries: trac #856
+compiler_CONFIGURE_OPTS += --ld-option=-Wl,--relax
+endif
+endif
+
+# We need to turn on profiling either if we have been asked to
+# (GhcLibProfiled = YES) or if we want GHC itself to be compiled with
+# profiling enabled (GhcProfiled = YES).
+ifneq "$(GhcLibProfiled) $(GhcProfiled)" "NO NO"
+compiler_stage2_CONFIGURE_OPTS += --enable-library-profiling
+# And if we're profiling GHC then we want lots of SCCs.
+# We also don't want to waste time building the non-profiling library,
+# either normally or for ghci. Unfortunately this means that we have to
+# tell ghc-pkg --force as it gets upset when libHSghc-6.9.a doesn't
+# exist.
+ifeq "$(GhcProfiled)" "YES"
+compiler_stage2_CONFIGURE_OPTS += --ghc-option=-auto-all
+compiler_stage2_CONFIGURE_OPTS += --disable-library-vanilla
+compiler_stage2_CONFIGURE_OPTS += --disable-library-for-ghci
+compiler_stage2_CONFIGURE_OPTS += --ghc-pkg-option=--force
+endif
+endif
+
+ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
+# The #include is vital for the via-C route with older compilers, else the C
+# compiler doesn't realise that the stcall foreign imports are indeed
+# stdcall, and doesn't generate the Foo@8 name for them
+# As it's only important for older compilers we don't need to do anything
+# for stage2+.
+compiler_stage1_CONFIGURE_OPTS += --ghc-option='-\#include' \
+ --ghc-option='"<windows.h>"' \
+ --ghc-option='-\#include' \
+ --ghc-option='"<process.h>"'
+endif
+
+# ghc_strlen percolates through so many modules that it is easier to get its
+# prototype via a global option instead of a myriad of per-file OPTIONS.
+# Again, this is only important for older compilers, so we don't do it in
+# stage 2+.
+compiler_stage1_CONFIGURE_OPTS += --ghc-options='-\#include "cutils.h"'
+
+compiler_stage3_CONFIGURE_OPTS := $(compiler_stage2_CONFIGURE_OPTS)
+
+compiler_stage1_CONFIGURE_OPTS += --ghc-option=-DSTAGE=1
+compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DSTAGE=2
+compiler_stage3_CONFIGURE_OPTS += --ghc-option=-DSTAGE=3
+compiler_stage2_HADDOCK_OPTS += --haddock-option=--optghc=-DSTAGE=2
+
+compiler_stage1_CONFIGURE_OPTS += --ghc-options='$(GhcStage1HcOpts)'
+compiler_stage2_CONFIGURE_OPTS += --ghc-options='$(GhcStage2HcOpts)'
+compiler_stage3_CONFIGURE_OPTS += --ghc-options='$(GhcStage3HcOpts)'
+
+compiler/stage1/package-data.mk : compiler/ghc.mk
+compiler/stage2/package-data.mk : compiler/ghc.mk
+compiler/stage3/package-data.mk : compiler/ghc.mk
+
+# -----------------------------------------------------------------------------
+# And build the package
+
+compiler_PACKAGE = ghc
+
+# haddocking only happens for stage2
+compiler_stage1_DO_HADDOCK = NO
+compiler_stage3_DO_HADDOCK = NO
+
+# Don't do splitting for the GHC package, it takes too long and
+# there's not much benefit.
+compiler_stage1_SplitObjs = NO
+compiler_stage2_SplitObjs = NO
+compiler_stage3_SplitObjs = NO
+
+# For now, bindists always use stage 2
+ifneq "$(BINDIST)" "YES"
+# stage 1 is enabled unless $(stage) is set to something other than 1
+ifeq "$(filter-out 1,$(stage))" ""
+$(eval $(call build-package,compiler,stage1,0))
+endif
+endif
+
+# stage 2 is enabled unless $(stage) is set to something other than 2
+ifeq "$(filter-out 2,$(stage))" ""
+$(eval $(call build-package,compiler,stage2,1))
+endif
+
+ifneq "$(BINDIST)" "YES"
+# stage 3 has to be requested explicitly with stage=3
+ifeq "$(stage)" "3"
+$(eval $(call build-package,compiler,stage3,2))
+endif
+
+$(compiler_stage1_depfile) : compiler/stage1/$(PLATFORM_H)
+$(compiler_stage2_depfile) : compiler/stage2/$(PLATFORM_H)
+$(compiler_stage3_depfile) : compiler/stage3/$(PLATFORM_H)
+
+$(compiler_stage1_depfile) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS) $(PRIMOP_BITS)
+$(compiler_stage2_depfile) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS) $(PRIMOP_BITS)
+$(compiler_stage3_depfile) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS) $(PRIMOP_BITS)
+endif
+
diff --git a/compiler/main/DriverMkDepend.hs b/compiler/main/DriverMkDepend.hs
index 7451cef95e..400f8bdf0b 100644
--- a/compiler/main/DriverMkDepend.hs
+++ b/compiler/main/DriverMkDepend.hs
@@ -72,7 +72,8 @@ doMkDependHS srcs = do
-- Prcess them one by one, dumping results into makefile
-- and complaining about cycles
hsc_env <- getSession
- mapM (liftIO . processDeps dflags hsc_env excl_mods (mkd_tmp_hdl files)) sorted
+ root <- liftIO getCurrentDirectory
+ mapM (liftIO . processDeps dflags hsc_env excl_mods root (mkd_tmp_hdl files)) sorted
-- If -ddump-mod-cycles, show cycles in the module graph
liftIO $ dumpModCycles dflags mod_summaries
@@ -158,6 +159,7 @@ beginMkDependHS dflags = do
processDeps :: DynFlags
-> HscEnv
-> [ModuleName]
+ -> FilePath
-> Handle -- Write dependencies to here
-> SCC ModSummary
-> IO ()
@@ -176,11 +178,11 @@ processDeps :: DynFlags
--
-- For {-# SOURCE #-} imports the "hi" will be "hi-boot".
-processDeps _ _ _ _ (CyclicSCC nodes)
+processDeps _ _ _ _ _ (CyclicSCC nodes)
= -- There shouldn't be any cycles; report them
ghcError (ProgramError (showSDoc $ GHC.cyclicModuleErr nodes))
-processDeps dflags hsc_env excl_mods hdl (AcyclicSCC node)
+processDeps dflags hsc_env excl_mods root hdl (AcyclicSCC node)
= do { let extra_suffixes = depSuffixes dflags
include_pkg_deps = depIncludePkgDeps dflags
src_file = msHsFilePath node
@@ -194,7 +196,7 @@ processDeps dflags hsc_env excl_mods hdl (AcyclicSCC node)
Nothing -> return () ;
Just hi_file -> do
{ let hi_files = insertSuffixes hi_file extra_suffixes
- write_dep (obj,hi) = writeDependency hdl [obj] hi
+ write_dep (obj,hi) = writeDependency root hdl [obj] hi
-- Add one dependency for each suffix;
-- e.g. A.o : B.hi
@@ -204,7 +206,7 @@ processDeps dflags hsc_env excl_mods hdl (AcyclicSCC node)
-- Emit std dependency of the object(s) on the source file
-- Something like A.o : A.hs
- ; writeDependency hdl obj_files src_file
+ ; writeDependency root hdl obj_files src_file
-- Emit a dependency for each import
@@ -248,12 +250,18 @@ findDependency hsc_env srcloc pkg imp is_boot include_pkg_deps
}
-----------------------------
-writeDependency :: Handle -> [FilePath] -> FilePath -> IO ()
--- (writeDependency h [t1,t2] dep) writes to handle h the dependency
+writeDependency :: FilePath -> Handle -> [FilePath] -> FilePath -> IO ()
+-- (writeDependency r h [t1,t2] dep) writes to handle h the dependency
-- t1 t2 : dep
-writeDependency hdl targets dep
- = hPutStrLn hdl (unwords (map forOutput targets) ++ " : " ++ forOutput dep)
- where forOutput = escapeSpaces . reslash Forwards . normalise
+writeDependency root hdl targets dep
+ = do let -- We need to avoid making deps on
+ -- c:/foo/...
+ -- on cygwin as make gets confused by the :
+ -- Making relative deps avoids some instances of this.
+ dep' = makeRelative root dep
+ forOutput = escapeSpaces . reslash Forwards . normalise
+ output = unwords (map forOutput targets) ++ " : " ++ forOutput dep'
+ hPutStrLn hdl output
-----------------------------
insertSuffixes
diff --git a/compiler/main/SysTools.lhs b/compiler/main/SysTools.lhs
index 49dd4275bc..a64d73e11c 100644
--- a/compiler/main/SysTools.lhs
+++ b/compiler/main/SysTools.lhs
@@ -77,27 +77,20 @@ How GHC finds its files
[Note topdir]
GHC needs various support files (library packages, RTS etc), plus
-various auxiliary programs (cp, gcc, etc). It starts by finding topdir:
-
- for "installed" topdir is the root of GHC's support files ($libdir)
- for "in-place" topdir is the root of the build tree
+various auxiliary programs (cp, gcc, etc). It starts by finding topdir,
+the root of GHC's support files
On Unix:
- ghc always has a shell wrapper that passes a -B<dir> option
- - in an installation, <dir> is $libdir
- - in a build tree, <dir> is $TOP/inplace-datadir
- - so we detect the build-tree case and add ".." to get us back to $TOP
On Windows:
- ghc never has a shell wrapper.
- we can find the location of the ghc binary, which is
- $topdir/bin/ghc.exe in an installation, or
- $topdir/ghc/stage1-inplace/ghc.exe in a build tree.
- - we detect which one of these we have, and calculate $topdir.
-
+ $topdir/bin/<something>.exe
+ where <something> may be "ghc", "ghc-stage2", or similar
+ - we strip off the "bin/<something>.exe" to leave $topdir.
-from topdir we can find package.conf, which contains the locations of
-almost everything else, whether we're in a build tree or installed.
+from topdir we can find package.conf, ghc-asm, etc.
SysTools.initSysProgs figures out exactly where all the auxiliary programs
@@ -113,8 +106,8 @@ Config.hs contains two sorts of things
etc They do *not* include paths
- cUNLIT_DIR_REL The *path* to the directory containing unlit, split etc
- cSPLIT_DIR_REL *relative* to the root of the build tree,
+ cUNLIT_DIR The *path* to the directory containing unlit, split etc
+ cSPLIT_DIR *relative* to the root of the build tree,
for use when running *in-place* in a build tree (only)
@@ -159,46 +152,28 @@ initSysTools :: Maybe String -- Maybe TopDir path (without the '-B' prefix)
initSysTools mbMinusB dflags0
- = do { (am_installed, top_dir) <- findTopDir mbMinusB
+ = do { top_dir <- findTopDir mbMinusB
-- see [Note topdir]
-- NB: top_dir is assumed to be in standard Unix
-- format, '/' separated
- ; let installed, installed_bin :: FilePath -> FilePath
- installed_bin pgm = top_dir </> pgm
- installed file = top_dir </> file
- inplace dir pgm = top_dir </> dir </> pgm
-
- ; let pkgconfig_path
- | am_installed = installed "package.conf"
- | otherwise = inplace "inplace-datadir" "package.conf"
-
- ghc_usage_msg_path
- | am_installed = installed "ghc-usage.txt"
- | otherwise = inplace cGHC_DRIVER_DIR_REL "ghc-usage.txt"
+ ; let installed :: FilePath -> FilePath
+ installed file = top_dir </> file
+ installed_mingw_bin file = top_dir </> ".." </> "mingw" </> "bin" </> file
- ghci_usage_msg_path
- | am_installed = installed "ghci-usage.txt"
- | otherwise = inplace cGHC_DRIVER_DIR_REL "ghci-usage.txt"
+ ; let pkgconfig_path = installed "package.conf"
+ ghc_usage_msg_path = installed "ghc-usage.txt"
+ ghci_usage_msg_path = installed "ghci-usage.txt"
-- For all systems, unlit, split, mangle are GHC utilities
-- architecture-specific stuff is done when building Config.hs
- unlit_path
- | am_installed = installed_bin cGHC_UNLIT_PGM
- | otherwise = inplace cGHC_UNLIT_DIR_REL cGHC_UNLIT_PGM
+ unlit_path = installed cGHC_UNLIT_PGM
-- split and mangle are Perl scripts
- split_script
- | am_installed = installed_bin cGHC_SPLIT_PGM
- | otherwise = inplace cGHC_SPLIT_DIR_REL cGHC_SPLIT_PGM
+ split_script = installed cGHC_SPLIT_PGM
+ mangle_script = installed cGHC_MANGLER_PGM
- mangle_script
- | am_installed = installed_bin cGHC_MANGLER_PGM
- | otherwise = inplace cGHC_MANGLER_DIR_REL cGHC_MANGLER_PGM
-
- windres_path
- | am_installed = installed_bin "bin/windres"
- | otherwise = "windres"
+ windres_path = installed_mingw_bin "windres"
; tmpdir <- getTemporaryDirectory
; let dflags1 = setTmpDir tmpdir dflags0
@@ -209,43 +184,19 @@ initSysTools mbMinusB dflags0
ghcError (InstallationError
("Can't find package.conf as " ++ pkgconfig_path))
- -- On Windows, gcc and friends are distributed with GHC,
- -- so when "installed" we look in TopDir/bin
- -- When "in-place", or when not on Windows, we look wherever
- -- the build-time configure script found them
+ -- On Windows, mingw is distributed with GHC,
+ -- so we look in TopDir/../mingw/bin
; let
- -- The trailing "/" is absolutely essential; gcc seems
- -- to construct file names simply by concatenating to
- -- this -B path with no extra slash We use "/" rather
- -- than "\\" because otherwise "\\\" is mangled
- -- later on; although gcc_args are in NATIVE format,
- -- gcc can cope
- -- (see comments with declarations of global variables)
- gcc_b_arg = Option ("-B" ++ installed "gcc-lib/")
- gcc_mingw_include_arg = Option ("-I" ++ installed "include/mingw")
- (gcc_prog,gcc_args)
- | isWindowsHost && am_installed
- -- We tell gcc where its specs file + exes are (-B)
- -- and also some places to pick up include files. We need
- -- to be careful to put all necessary exes in the -B place
- -- (as, ld, cc1, etc) since if they don't get found there,
- -- gcc then tries to run unadorned "as", "ld", etc, and
- -- will pick up whatever happens to be lying around in
- -- the path, possibly including those from a cygwin
- -- install on the target, which is exactly what we're
- -- trying to avoid.
- = (installed_bin "gcc", [gcc_b_arg, gcc_mingw_include_arg])
- | otherwise = (cGCC, [])
+ gcc_prog
+ | isWindowsHost = installed_mingw_bin "gcc"
+ | otherwise = cGCC
perl_path
- | isWindowsHost && am_installed = installed_bin cGHC_PERL
- | otherwise = cGHC_PERL
+ | isWindowsHost = installed cGHC_PERL
+ | otherwise = cGHC_PERL
-- 'touch' is a GHC util for Windows
touch_path
- | isWindowsHost
- = if am_installed
- then installed_bin cGHC_TOUCHY_PGM
- else inplace cGHC_TOUCHY_DIR_REL cGHC_TOUCHY_PGM
- | otherwise = "touch"
+ | isWindowsHost = installed cGHC_TOUCHY_PGM
+ | otherwise = "touch"
-- On Win32 we don't want to rely on #!/bin/perl, so we prepend
-- a call to Perl to get the invocation of split and mangle.
-- On Unix, scripts are invoked using the '#!' method. Binary
@@ -261,23 +212,18 @@ initSysTools mbMinusB dflags0
(mkdll_prog, mkdll_args)
| not isWindowsHost
= panic "Can't build DLLs on a non-Win32 system"
- | am_installed =
- (installed "gcc-lib/" </> cMKDLL,
- [ Option "--dlltool-name",
- Option (installed "gcc-lib/" </> "dlltool"),
- Option "--driver-name",
- Option gcc_prog, gcc_b_arg, gcc_mingw_include_arg ])
- | otherwise = (cMKDLL, [])
+ | otherwise =
+ (installed_mingw_bin cMKDLL, [])
-- cpp is derived from gcc on all platforms
-- HACK, see setPgmP below. We keep 'words' here to remember to fix
-- Config.hs one day.
- ; let cpp_path = (gcc_prog, gcc_args ++
+ ; let cpp_path = (gcc_prog,
(Option "-E"):(map Option (words cRAWCPP_FLAGS)))
-- Other things being equal, as and ld are simply gcc
- ; let (as_prog,as_args) = (gcc_prog,gcc_args)
- (ld_prog,ld_args) = (gcc_prog,gcc_args)
+ ; let as_prog = gcc_prog
+ ld_prog = gcc_prog
; return dflags1{
ghcUsagePath = ghc_usage_msg_path,
@@ -287,11 +233,11 @@ initSysTools mbMinusB dflags0
pgm_L = unlit_path,
pgm_P = cpp_path,
pgm_F = "",
- pgm_c = (gcc_prog,gcc_args),
+ pgm_c = (gcc_prog,[]),
pgm_m = (mangle_prog,mangle_args),
pgm_s = (split_prog,split_args),
- pgm_a = (as_prog,as_args),
- pgm_l = (ld_prog,ld_args),
+ pgm_a = (as_prog,[]),
+ pgm_l = (ld_prog,[]),
pgm_dll = (mkdll_prog,mkdll_args),
pgm_T = touch_path,
pgm_sysman = top_dir ++ "/ghc/rts/parallel/SysMan",
@@ -303,33 +249,17 @@ initSysTools mbMinusB dflags0
\end{code}
\begin{code}
-findTopDir :: Maybe String -- Maybe TopDir path (without the '-B' prefix).
- -> IO (Bool, -- True <=> am installed, False <=> in-place
- String) -- TopDir (in Unix format '/' separated)
-
-findTopDir mbMinusB
- = do { top_dir <- get_proto
- ; exists1 <- doesFileExist (top_dir </> "package.conf")
- ; exists2 <- doesFileExist (top_dir </> "inplace")
- ; let amInplace = not exists1 -- On Windows, package.conf doesn't exist
- -- when we are inplace
- || exists2 -- On Linux, the presence of inplace signals
- -- that we are inplace
-
- ; let real_top = if exists2 then top_dir </> ".." else top_dir
-
- ; return (not amInplace, real_top)
- }
- where
- -- get_proto returns a Unix-format path (relying on getBaseDir to do so too)
- get_proto = case mbMinusB of
- Just minusb -> return (normalise minusb)
- Nothing
- -> do maybe_exec_dir <- getBaseDir -- Get directory of executable
- case maybe_exec_dir of -- (only works on Windows;
- -- returns Nothing on Unix)
- Nothing -> ghcError (InstallationError "missing -B<dir> option")
- Just dir -> return dir
+-- returns a Unix-format path (relying on getBaseDir to do so too)
+findTopDir :: Maybe String -- Maybe TopDir path (without the '-B' prefix).
+ -> IO String -- TopDir (in Unix format '/' separated)
+findTopDir (Just minusb) = return (normalise minusb)
+findTopDir Nothing
+ = do -- Get directory of executable
+ maybe_exec_dir <- getBaseDir
+ case maybe_exec_dir of
+ -- "Just" on Windows, "Nothing" on unix
+ Nothing -> ghcError (InstallationError "missing -B<dir> option")
+ Just dir -> return dir
\end{code}
@@ -473,25 +403,10 @@ runMkDLL dflags args = do
runWindres :: DynFlags -> [Option] -> IO ()
runWindres dflags args = do
- let (gcc,gcc_args) = pgm_c dflags
+ let (_gcc,gcc_args) = pgm_c dflags
windres = pgm_windres dflags
mb_env <- getGccEnv gcc_args
- runSomethingFiltered dflags id "Windres" windres
- -- we must tell windres where to find gcc: it might not be on PATH
- (Option ("--preprocessor=" ++
- unwords (map quote (gcc : map showOpt gcc_args ++
- ["-E", "-xc", "-DRC_INVOKED"])))
- -- -- use-temp-file is required for windres to interpret the
- -- quoting in the preprocessor arg above correctly. Without
- -- this, windres calls the preprocessor with popen, which gets
- -- the quoting wrong (discovered by experimentation and
- -- reading the windres sources). See #1828.
- : Option "--use-temp-file"
- : args)
- -- we must use the PATH workaround here too, since windres invokes gcc
- mb_env
- where
- quote x = '\"' : x ++ "\""
+ runSomethingFiltered dflags id "Windres" windres args mb_env
touch :: DynFlags -> String -> String -> IO ()
touch dflags purpose arg =
@@ -833,8 +748,8 @@ traceCmd dflags phase_name cmd_line action
getBaseDir :: IO (Maybe String)
#if defined(mingw32_HOST_OS)
--- Assuming we are running ghc, accessed by path $()/bin/ghc.exe,
--- return the path $(stuff). Note that we drop the "bin/" directory too.
+-- Assuming we are running ghc, accessed by path $(stuff)/bin/ghc.exe,
+-- return the path $(stuff)/lib.
getBaseDir = do let len = (2048::Int) -- plenty, PATH_MAX is 512 under Win32.
buf <- mallocArray len
ret <- getModuleFileName nullPtr buf len
@@ -844,13 +759,14 @@ getBaseDir = do let len = (2048::Int) -- plenty, PATH_MAX is 512 under Win32.
return (Just (rootDir s))
where
rootDir s = case splitFileName $ normalise s of
- (d, ghc_exe) | lower ghc_exe == "ghc.exe" ->
+ (d, ghc_exe)
+ | lower ghc_exe `elem` ["ghc.exe",
+ "ghc-stage1.exe",
+ "ghc-stage2.exe",
+ "ghc-stage3.exe"] ->
case splitFileName $ takeDirectory d of
- -- installed ghc.exe is in $topdir/bin/ghc.exe
- (d', bin) | lower bin == "bin" -> takeDirectory d'
- -- inplace ghc.exe is in $topdir/ghc/stage1-inplace/ghc.exe
- (d', x) | "-inplace" `isSuffixOf` lower x ->
- takeDirectory d' </> ".."
+ -- ghc is in $topdir/bin/ghc.exe
+ (d', bin) | lower bin == "bin" -> takeDirectory d' </> "lib"
_ -> fail
_ -> fail
where fail = panic ("can't decompose ghc.exe path: " ++ show s)
diff --git a/compiler/rename/RnNames.lhs b/compiler/rename/RnNames.lhs
index d2add1f7be..a7b84ebdef 100644
--- a/compiler/rename/RnNames.lhs
+++ b/compiler/rename/RnNames.lhs
@@ -143,8 +143,14 @@ rnImportDecl this_mod (L loc (ImportDecl loc_imp_mod_name mb_pkg want_boot
-- Issue a user warning for a redundant {- SOURCE -} import
-- NB that we arrange to read all the ordinary imports before
- -- any of the {- SOURCE -} imports
- warnIf (want_boot && not (mi_boot iface))
+ -- any of the {- SOURCE -} imports.
+ --
+ -- in --make and GHCi, the compilation manager checks for this,
+ -- and indeed we shouldn't do it here because the existence of
+ -- the non-boot module depends on the compilation order, which
+ -- is not deterministic. The hs-boot test can show this up.
+ dflags <- getDOpts
+ warnIf (want_boot && not (mi_boot iface) && isOneShot (ghcMode dflags))
(warnRedundantSourceImport imp_mod_name)
let
diff --git a/configure.ac b/configure.ac
index f7f6c09b90..e2626a2f3d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -95,10 +95,18 @@ HostPlatform=`/bin/sh $srcdir/config.sub $host` || exit 1
TargetPlatform=`/bin/sh $srcdir/config.sub $target` || exit 1
if test x"$TargetPlatform" != x"$HostPlatform" ; then
- echo "GHC configuration does not support differing host/target (i.e., cross-compiling)"
- exit 1
+ AC_MSG_ERROR([
+ GHC configuration does not support differing host/target (i.e., cross-compiling)])
fi
+case $HostPlatform in
+*-cygwin*)
+ AC_MSG_WARN([GHC does not support the Cygwin target at the moment])
+ AC_MSG_WARN([I'm assuming you wanted to build for i386-unknown-mingw32])
+ HostPlatform=i386-unknown-mingw32
+ ;;
+esac
+
exeext=''
soext='.so'
#
@@ -645,12 +653,16 @@ AC_ARG_WITH([ghc],
fi
WithGhc="$GHC"])
# GHC is passed to Cabal, so we need a native path
-if test "x$HostPlatform" = "xi386-unknown-mingw32" && \
- test "${OSTYPE}" != "msys" && \
- test "${WithGhc}" != ""
+if test "${WithGhc}" != "" && test "$HostPlatform" = "i386-unknown-mingw32"
then
- # Canonicalise to <drive>:/path/to/ghc
- WithGhc=`cygpath -m ${WithGhc}`
+ if test "${OSTYPE}" = "msys"
+ then
+ WithGhc=`echo "${WithGhc}" | sed "s#^/\([a-zA-Z]\)/#\1:/#"`
+ else
+ # Canonicalise to <drive>:/path/to/ghc
+ WithGhc=`cygpath -m ${WithGhc}`
+ fi
+ echo "Canonicalised to: ${WithGhc}"
fi
AC_SUBST([WithGhc])
@@ -663,8 +675,27 @@ AC_ARG_WITH(hc,
)
AC_SUBST(WithHc)
+AC_ARG_ENABLE(bootstrap-with-devel-snapshot,
+[AC_HELP_STRING([--enable-bootstrap-with-devel-snapshot],
+ [Allow bootstrapping using a development snapshot of GHC. This is not guaranteed to work.])],
+ EnableBootstrapWithDevelSnaphost=YES,
+ EnableBootstrapWithDevelSnaphost=NO
+)
+
if test "$WithGhc" != ""; then
FPTOOLS_GHC_VERSION([GhcVersion], [GhcMajVersion], [GhcMinVersion], [GhcPatchLevel])dnl
+
+ if test `expr $GhcMinVersion % 2` = "1"; then
+ echo $EnableBootstrapWithDevelSnaphost
+ if test "$EnableBootstrapWithDevelSnaphost" = "NO"; then
+ AC_MSG_ERROR([
+ $WithGhc is a development snapshot of GHC, version $GhcVersion.
+ Bootstrapping using this version of GHC is not supported, and may not
+ work. Use --enable-bootstrap-with-devel-snapshot to try it anyway,
+ or --with-ghc to specify a different GHC to use.])
+ fi
+ fi
+
AC_SUBST(GhcVersion)dnl
AC_SUBST(GhcMajVersion)dnl
AC_SUBST(GhcMinVersion)dnl
@@ -971,6 +1002,10 @@ dnl ** check for tar
dnl if GNU tar is named gtar, look for it first.
AC_PATH_PROGS(TarCmd,gtar tar,tar)
+dnl ** check for patch
+dnl if GNU patch is named gpatch, look for it first
+AC_PATH_PROGS(PatchCmd,gpatch patch, patch)
+
AC_PATH_PROG(HSCOLOUR,HsColour)
# HsColour is passed to Cabal, so we need a native path
if test "x$HostPlatform" = "xi386-unknown-mingw32" && \
@@ -989,15 +1024,6 @@ FP_PROG_FO_PROCESSOR
dnl ** check for ghc-pkg command
FP_PROG_GHC_PKG
-AC_ARG_WITH(greencard,
-[AC_HELP_STRING([--with-greencard=ARG],
- [Use ARG as the path to greencard [default=autodetct]])],
-[
-GreenCardCmd=$withval;
-FPTOOLS_GREENCARD(3.00)
-]
-)
-
dnl ** check for installed happy binary + version
dnl (don't do it if we're booting from .hc files though.)
if test "$BootingFromHc" = "NO"; then
@@ -1290,7 +1316,7 @@ else
fi
AC_SUBST(HavePapi)
-AC_CONFIG_FILES([mk/config.mk compiler/ghc.cabal ghc/ghc-bin.cabal utils/runghc/runghc.cabal ghc.spec extra-gcc-opts docs/users_guide/ug-book.xml])
+AC_CONFIG_FILES([mk/config.mk mk/project.mk compiler/ghc.cabal ghc/ghc-bin.cabal ghc.spec extra-gcc-opts docs/users_guide/ug-book.xml])
AC_CONFIG_COMMANDS([mk/stamp-h],[echo timestamp > mk/stamp-h])
AC_OUTPUT
@@ -1313,3 +1339,69 @@ checkMake380() {
checkMake380 make
checkMake380 gmake
+echo ["
+----------------------------------------------------------------------
+Configure completed successfully.
+
+ Building GHC version : $ProjectVersion
+
+ Build platform : $BuildPlatform
+ Host platform : $HostPlatform
+ Target platform : $TargetPlatform
+"]
+
+if test "$BootingFromHc" = "YES"; then
+echo ["\
+ Bootstrapping from HC files.
+"]
+else
+echo ["\
+ Bootstrapping using : $WithGhc
+ which is version : $GhcVersion
+"]
+fi
+
+echo ["\
+ Using GCC : $WhatGccIsCalled
+ which is version : $GccVersion
+
+ ld : $LdCmd
+ Happy : $HappyCmd
+ Alex : $AlexCmd
+ Python : $PythonCmd
+ Perl : $PerlCmd"]
+
+if test "$HSCOLOUR" = ""; then
+echo ["
+ HsColour was not found; documentation will not contain source links
+"]
+else
+echo ["\
+ HsColour : $HSCOLOUR
+"]
+fi
+
+if test "$DIR_DOCBOOK_XSL" = ""; then
+echo ["\
+ Building DocBook documentation : no"]
+else
+echo ["\
+ Building DocBook documentation : yes"]
+fi
+
+
+echo ["\
+ Building shared libraries : $BuildSharedLibs"]
+
+echo ["----------------------------------------------------------------------
+"]
+
+echo "\
+For a standard build of GHC (fully optimised with profiling), type (g)make.
+
+To make changes to the default build configuration, copy the file
+mk/build.mk.sample to mk/build.mk, and edit the settings in there.
+
+For more information on how to configure your GHC build, see
+ http://hackage.haskell.org/trac/ghc/wiki/Building
+"
diff --git a/distrib/configure-bin.ac b/distrib/configure-bin.ac
index 4f18013f06..62562b864b 100644
--- a/distrib/configure-bin.ac
+++ b/distrib/configure-bin.ac
@@ -5,7 +5,7 @@ dnl
#
# Is it there?
-AC_INIT(Makefile-vars.in)
+AC_INIT(mk/config.mk.in)
exeext=''
@@ -148,7 +148,7 @@ dnl ** Check gcc version and flags we need to pass it **
FP_GCC_EXTRA_FLAGS
#
-AC_CONFIG_FILES(Makefile-vars extra-gcc-opts)
+AC_CONFIG_FILES(extra-gcc-opts mk/config.mk)
AC_OUTPUT
echo "****************************************************"
diff --git a/docs/ext-core/Makefile b/docs/ext-core/Makefile
index c4db587289..8d97588389 100644
--- a/docs/ext-core/Makefile
+++ b/docs/ext-core/Makefile
@@ -50,9 +50,6 @@ distclean: clean
maintainer-clean: distclean
-ifeq "$(LATEX_DOCS)" "YES"
-BINDIST_EXTRAS += core.pdf
-endif
include $(TOP)/mk/bindist.mk
# dummy targets
diff --git a/docs/man/Makefile b/docs/man/Makefile
index e4e0c33f04..21e60e2df8 100644
--- a/docs/man/Makefile
+++ b/docs/man/Makefile
@@ -45,7 +45,6 @@ install-docs:: $(MAN_PAGE).$(MAN_SECTION)
endif
-BINDIST_EXTRAS += $(MAN_PAGE).$(MAN_SECTION)
include $(TOP)/mk/bindist.mk
include $(TOP)/mk/target.mk
diff --git a/docs/users_guide/ghc.mk b/docs/users_guide/ghc.mk
new file mode 100644
index 0000000000..bae39adce8
--- /dev/null
+++ b/docs/users_guide/ghc.mk
@@ -0,0 +1,7 @@
+
+docs/users_guide_DOCBOOK_SOURCES := \
+ $(wildcard docs/users_guide/*.xml) \
+ $(basename $(wildcard docs/users_guide/*.xml.in))
+
+$(eval $(call docbook,docs/users_guide,users_guide))
+
diff --git a/driver/ghc-pkg/Makefile b/driver/ghc-pkg/Makefile
deleted file mode 100644
index 2ee42d56b1..0000000000
--- a/driver/ghc-pkg/Makefile
+++ /dev/null
@@ -1,18 +0,0 @@
-TOP=../..
-include $(TOP)/mk/boilerplate.mk
-
-ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-SCRIPT_DIR = $(DESTDIR)$(bindir)
-SCRIPT_BASE = ghc-pkg
-SCRIPT_VERSIONED_BASE = $(SCRIPT_BASE)-$(ProjectVersion)
-SCRIPT = $(SCRIPT_DIR)/$(SCRIPT_BASE)
-SCRIPT_VERSIONED = $(SCRIPT_DIR)/$(SCRIPT_VERSIONED_BASE)
-
-install::
- mv $(SCRIPT) $(SCRIPT_VERSIONED)
- ln -s $(SCRIPT_VERSIONED_BASE) $(SCRIPT)
-endif
-
-include $(TOP)/mk/bindist.mk
-
-include $(TOP)/mk/target.mk
diff --git a/driver/ghc.mk b/driver/ghc.mk
new file mode 100644
index 0000000000..7739f6b2a9
--- /dev/null
+++ b/driver/ghc.mk
@@ -0,0 +1,11 @@
+
+$(eval $(call all-target,driver,$(INPLACE_LIB)/ghc-usage.txt) $(INPLACE_LIB)/ghci-usage.txt)
+
+$(INPLACE_LIB)/ghc-usage.txt: driver/ghc-usage.txt
+ cp $< $@
+
+$(INPLACE_LIB)/ghci-usage.txt: driver/ghci-usage.txt
+ cp $< $@
+
+INSTALL_LIBS += driver/ghc-usage.txt driver/ghci-usage.txt
+
diff --git a/driver/ghc/ghc.mk b/driver/ghc/ghc.mk
new file mode 100644
index 0000000000..68d35cb679
--- /dev/null
+++ b/driver/ghc/ghc.mk
@@ -0,0 +1,10 @@
+ifeq "$(Windows)" "YES"
+
+driver/ghc_dist_C_SRCS = ghc.c
+driver/ghc_dist_PROG = ghc-$(ProjectVersion)
+driver/ghc_dist_INSTALL = YES
+
+$(eval $(call build-prog,driver/ghc,dist,0))
+
+endif
+
diff --git a/driver/ghci/Makefile b/driver/ghci/Makefile
index 47f51b8c23..afb57176fb 100644
--- a/driver/ghci/Makefile
+++ b/driver/ghci/Makefile
@@ -1,63 +1,3 @@
-#-----------------------------------------------------------------------------
-# $Id: Makefile,v 1.11 2005/05/05 00:58:38 sof Exp $
-#
-
-TOP=../..
-include $(TOP)/mk/boilerplate.mk
-
-# -----------------------------------------------------------------------------
-# ghci script
-
-ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-C_PROG = ghci$(exeext)
-C_PROG_VERSIONED = ghci-$(ProjectVersion)$(exeext)
-C_OBJS += ghci.res
-
-all :: $(C_PROG_VERSIONED)
-$(C_PROG_VERSIONED) : $(C_PROG)
- cp $< $@
-else
-C_SRCS=
-endif
-
-ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-INSTALL_PROGS += $(C_PROG) $(C_PROG_VERSIONED)
-GHCII_SCRIPT=$(DESTDIR)$(bindir)/ghcii.sh
-GHCII_SCRIPT_VERSIONED = $(DESTDIR)$(bindir)/ghcii-$(ProjectVersion).sh
-install::
- $(RM) -f $(GHCII_SCRIPT)
- echo "#!$(SHELL)" >> $(GHCII_SCRIPT)
- echo 'exec "$$0"/../ghc --interactive $${1+"$$@"}' >> $(GHCII_SCRIPT)
- chmod +x $(GHCII_SCRIPT)
- cp $(GHCII_SCRIPT) $(GHCII_SCRIPT_VERSIONED)
- chmod +x $(GHCII_SCRIPT_VERSIONED)
-else
-LINK = ghci
-LINK_TARGET = $(LINK)-$(ProjectVersion)
-INSTALLED_SCRIPT=$(DESTDIR)$(bindir)/$(LINK_TARGET)
-install::
- $(RM) -f $(INSTALLED_SCRIPT)
- echo "#!$(SHELL)" >> $(INSTALLED_SCRIPT)
- echo 'exec $(bindir)/ghc-$(ProjectVersion) --interactive $${1+"$$@"}' >> $(INSTALLED_SCRIPT)
- $(EXECUTABLE_FILE) $(INSTALLED_SCRIPT)
-endif
-
-ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-INPLACE_SCRIPT = ghci
-INPLACE_GHC = $(FPTOOLS_TOP_ABS)/ghc/stage2-inplace/ghc
-CLEAN_FILES += $(INPLACE_SCRIPT)
-all::
- $(RM) -f $(INPLACE_SCRIPT)
- echo "#!$(SHELL)" >> $(INPLACE_SCRIPT)
- echo "exec $(INPLACE_GHC) --interactive $${1+"$$@"}" >> $(INPLACE_SCRIPT)
- $(EXECUTABLE_FILE) $(INPLACE_SCRIPT)
-endif
-
-ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-ghci.res : ghci.rc ghci.ico
- windres --preprocessor="$(CPP) -xc -DRC_INVOKED" -o ghci.res -i ghci.rc -O coff
-endif
-
-include $(TOP)/mk/bindist.mk
-
-include $(TOP)/mk/target.mk
+dir = driver/ghci
+TOP = ../..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/driver/ghci/ghc.mk b/driver/ghci/ghc.mk
new file mode 100644
index 0000000000..14e27123a7
--- /dev/null
+++ b/driver/ghci/ghc.mk
@@ -0,0 +1,50 @@
+ifneq "$(Windows)" "YES"
+
+install: install_driver_ghci
+
+.PHONY: install_driver_ghci
+install_driver_ghci: WRAPPER=$(DESTDIR)$(bindir)/ghci-$(ProjectVersion)
+install_driver_ghci:
+ $(MKDIRHIER) $(DESTDIR)$(bindir)
+ $(RM) -f $(WRAPPER)
+ echo '#!$(SHELL)' >> $(WRAPPER)
+ echo 'exec $(bindir)/ghc-$(ProjectVersion) --interactive ${1+"$@"}' >> $(WRAPPER)
+ $(EXECUTABLE_FILE) $(WRAPPER)
+ $(RM) -f $(DESTDIR)$(bindir)/ghci
+ $(LN_S) ghci-$(ProjectVersion) $(DESTDIR)$(bindir)/ghci
+
+else # Windows...
+
+driver/ghci_dist_C_SRCS = ghci.c
+driver/ghci_dist_PROG = ghci$(exeext)
+driver/ghci_dist_INSTALL = YES
+driver/ghci_dist_OTHER_OBJS = driver/ghci/ghci.res
+
+$(eval $(call build-prog,driver/ghci,dist,0))
+
+driver/ghci_dist_PROG_VER = ghci-$(ProjectVersion)$(exeext)
+
+INSTALL_BINS += driver/ghci/dist/build/tmp/$(driver/ghci_dist_PROG_VER)
+
+driver/ghci/ghci.res : driver/ghci/ghci.rc driver/ghci/ghci.ico
+ windres --preprocessor="$(CPP) -xc -DRC_INVOKED" -o driver/ghci/ghci.res -i driver/ghci/ghci.rc -O coff
+
+driver/ghci/dist/build/tmp/$(driver/ghci_dist_PROG_VER) : driver/ghci/dist/build/tmp/$(driver/ghci_dist_PROG)
+ $(CP) $< $@
+
+install : install_driver_ghcii
+
+.PHONY: install_driver_ghcii
+install_driver_ghcii: GHCII_SCRIPT=$(DESTDIR)$(bindir)/ghcii.sh
+install_driver_ghcii: GHCII_SCRIPT_VERSIONED = $(DESTDIR)$(bindir)/ghcii-$(ProjectVersion).sh
+install_driver_ghcii:
+ $(MKDIRHIER) $(DESTDIR)$(bindir)
+ $(RM) -f $(GHCII_SCRIPT)
+ echo "#!$(SHELL)" >> $(GHCII_SCRIPT)
+ echo 'exec "$$0"/../ghc --interactive $${1+"$$@"}' >> $(GHCII_SCRIPT)
+ $(EXECUTABLE_FILE) $(GHCII_SCRIPT)
+ cp $(GHCII_SCRIPT) $(GHCII_SCRIPT_VERSIONED)
+ $(EXECUTABLE_FILE) $(GHCII_SCRIPT_VERSIONED)
+
+endif
+
diff --git a/driver/mangler/Makefile b/driver/mangler/Makefile
index 1242d6c236..ff1a4a9ee8 100644
--- a/driver/mangler/Makefile
+++ b/driver/mangler/Makefile
@@ -1,26 +1,3 @@
-#-----------------------------------------------------------------------------
-# $Id: Makefile,v 1.3 2001/03/23 16:36:21 simonmar Exp $
-
-TOP=../..
-include $(TOP)/mk/boilerplate.mk
-
-PROG = ghc-asm
-all:: $(PROG).prl
- $(RM) -f $(PROG)
- echo '#!$(PERL)' >> $(PROG)
- echo '$$TARGETPLATFORM = "$(TARGETPLATFORM)";' >> $(PROG)
- cat $< >> $(PROG)
- $(EXECUTABLE_FILE) $(PROG)
-
-INSTALL_LIBEXEC_SCRIPTS += $(PROG)
-CLEAN_FILES += $(PROG) $(PROG).prl
-
-# needed for bootstrapping with HC files
-ifeq "$(BootingFromHc)" "YES"
-boot :: all
-endif
-
-BINDIST_EXTRAS += $(PROG)
-include $(TOP)/mk/bindist.mk
-
-include $(TOP)/mk/target.mk
+dir = driver/mangler
+TOP = ../..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/driver/mangler/ghc.mk b/driver/mangler/ghc.mk
new file mode 100644
index 0000000000..c5cb3d6b7f
--- /dev/null
+++ b/driver/mangler/ghc.mk
@@ -0,0 +1,7 @@
+driver/mangler_PERL_SRC = ghc-asm.lprl
+driver/mangler_dist_PROG = $(GHC_MANGLER_PGM)
+driver/mangler_dist_LIBEXEC = YES
+
+$(eval $(call build-perl,driver/mangler,dist))
+
+INSTALL_LIBEXEC_SCRIPTS += driver/mangler/dist/$(GHC_MANGLER_PGM)
diff --git a/driver/runhaskell/Makefile b/driver/runhaskell/Makefile
deleted file mode 100644
index 02df642571..0000000000
--- a/driver/runhaskell/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
-TOP=../..
-include $(TOP)/mk/boilerplate.mk
-
-ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-install::
- cp $(DESTDIR)$(bindir)/runghc.exe $(DESTDIR)$(bindir)/runhaskell.exe
-else
-install::
- ln -sf runghc $(DESTDIR)$(bindir)/runhaskell
-endif
-
-include $(TOP)/mk/bindist.mk
-
-include $(TOP)/mk/target.mk
diff --git a/driver/split/Makefile b/driver/split/Makefile
index 404cb97c4d..a73eeeb05b 100644
--- a/driver/split/Makefile
+++ b/driver/split/Makefile
@@ -1,21 +1,3 @@
-#-----------------------------------------------------------------------------
-# $Id: Makefile,v 1.2 2000/11/03 16:54:52 simonmar Exp $
-
-TOP=../..
-include $(TOP)/mk/boilerplate.mk
-
-PROG = ghc-split
-all:: $(PROG).prl
- $(RM) -f $(PROG)
- echo '#!$(PERL)' >> $(PROG)
- echo '$$TARGETPLATFORM = "$(TARGETPLATFORM)";' >> $(PROG)
- cat $< >> $(PROG)
- $(EXECUTABLE_FILE) $(PROG)
-
-INSTALL_LIBEXEC_SCRIPTS += $(PROG)
-CLEAN_FILES += $(PROG) $(PROG).prl
-
-BINDIST_EXTRAS += $(PROG)
-include $(TOP)/mk/bindist.mk
-
-include $(TOP)/mk/target.mk
+dir = driver/split
+TOP = ../..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/driver/split/ghc.mk b/driver/split/ghc.mk
new file mode 100644
index 0000000000..30382e090d
--- /dev/null
+++ b/driver/split/ghc.mk
@@ -0,0 +1,7 @@
+driver/split_PERL_SRC = ghc-split.lprl
+driver/split_dist_PROG = $(GHC_SPLIT_PGM)
+driver/split_dist_LIBEXEC = YES
+
+$(eval $(call build-perl,driver/split,dist))
+
+INSTALL_LIBEXEC_SCRIPTS += driver/split/dist/$(GHC_SPLIT_PGM)
diff --git a/ghc.mk b/ghc.mk
new file mode 100644
index 0000000000..329e76f0cf
--- /dev/null
+++ b/ghc.mk
@@ -0,0 +1,841 @@
+# ToDo List.
+#
+# Before we can merge the new build system into HEAD:
+#
+# * finish installation
+# * other documentation
+# * create doc index and contents
+# * Windows: should we have ghc-pkg-<version>?
+# * should we be stripping things?
+# * install libgmp.a, gmp.h
+# * finish binary distributions
+# * need to fix Cabal for new Windows layout, see
+# Distribution/Simple/GHC.configureToolchain.
+#
+# As we merge the new build system into HEAD:
+#
+# * remove old Makefiles, add new stubs for building in subdirs
+# * utils/hsc2hs/Makefile
+# * utils/haddock/Makefile
+# * mk/oldconfig.mk.in
+#
+# Once the new build system is in HEAD, and before 6.12:
+#
+# * docbook PDFs, e.g. "dblatex -T db2latex users_guide.xml"
+# * GhcProfiled
+# * optionally install stage3?
+# * why does so much stuff get rebuilt after re-configuring?
+# * shared libraries, way dyn
+# * add pointers to wiki docs from the build system source
+# * get HC bootstrapping working
+# * add Makefiles for the rest of the utils/ programs that aren't built
+# by default (need to exclude them from 'make all' too)
+#
+# Tickets we can now close, or fix and close:
+#
+# * 912 build system doesn't have enough dependencies (it does now!)
+# * 2744 check for presence of hsc2hs in ./configure
+# * 2966 make sure --with-gcc does the right thing (#2966)
+# * 3115 make ghc.cabal read-only
+# * 2107 install the docs by default
+# * 1693 make distclean
+# * 2689 make maintainer-clean
+# * 2619 bootstrapping using a newer GHC shouldn't fail
+# for bogus reasons (picking the wrong version of the ghc package)
+# * 2770 check which version of gcc we require
+# * 3173 make install with DESTDIR
+
+# Possible cleanups:
+#
+# * per-source-file dependencies instead of one .depend file?
+# * eliminate undefined variables, and use --warn-undefined-variables?
+# * perhaps we should make all the output dirs in the .depend rule, to
+# avoid all these mkdirhier calls?
+# * put outputs from different ways in different subdirs of distdir/build,
+# then we don't have to use -osuf/-hisuf. We would have to install
+# them in different places too, so we'd need ghc-pkg support for packages
+# of different ways.
+# * make PACKAGES generated by configure or sh boot?
+# * we should use a directory of package.conf files rather than a single
+# file for the inplace package database, so that we can express
+# dependencies more accurately. Otherwise it's possible to get into
+# a state where the package database is out of date, and the build
+# system doesn't know.
+
+# NOTES on how to debug:
+# make --debug=b --debug=m shows dependencies
+# make -p prints all generated makefile rules and variables
+# make show VALUE=VAR prints the value of VAR
+# $(warning stuff) prints stuff when reading the makefile
+
+# BUILD ORDER
+#
+# * With bootstrapping compiler:
+# o Build libraries/{hpc,extensible-exceptions,Cabal}
+# o Build utils/ghc-pkg
+# o Build utils/ghc-cabal
+# * With bootstrapping compiler and ghc-cabal:
+# o Build utils/hsc2hs
+# o Build libraries/hpc
+# o Build compiler (stage 1)
+# * For each package:
+# o generate package-data.mk and inplace-pkg-info
+# o register each package into inplace/lib/package.conf
+# o generate .depend for each package
+# * With stage 1:
+# o Build libraries/*
+# o Build utils/* (except haddock)
+# o Build compiler (stage 2)
+# * With stage 2:
+# o Build utils/haddock
+# o Build compiler (stage 3)
+# * With haddock:
+# o libraries/*
+# o compiler
+
+default : all
+
+# Just bring makefiles up to date:
+.PHONY: just-makefiles
+just-makefiles:
+ @:
+
+# -----------------------------------------------------------------------------
+# Misc GNU make utils
+
+nothing=
+space=$(nothing) $(nothing)
+comma=,
+
+# Cancel all suffix rules. Ideally we'd like to have 'make -r' turned on
+# by default, because that disables all the implicit rules, but there doesn't
+# seem to be a good way to do that. This turns off all the old-style suffix
+# rules, which does half the job and speeds up make quite a bit:
+.SUFFIXES:
+
+# -----------------------------------------------------------------------------
+# Makefile debugging
+# to see the effective value used for a Makefile variable, do
+# make show VALUE=MY_VALUE
+#
+
+show:
+ @echo '$(VALUE)="$($(VALUE))"'
+
+# -----------------------------------------------------------------------------
+# Include subsidiary build-system bits
+
+include mk/config.mk
+
+ifeq "$(ProjectVersion)" ""
+$(error Please run ./configure first)
+endif
+
+# (Optional) build-specific configuration
+include mk/custom-settings.mk
+
+ifeq "$(GhcLibWays)" ""
+$(error $$(GhcLibWays) is empty, it must contain at least one way)
+endif
+
+# -----------------------------------------------------------------------------
+# Macros for standard targets
+
+include rules/all-target.mk
+include rules/clean-target.mk
+
+# -----------------------------------------------------------------------------
+# The inplace tree
+
+$(eval $(call clean-target,inplace,,inplace))
+
+# -----------------------------------------------------------------------------
+# Whether to build dependencies or not
+
+# When we're just doing 'make clean' or 'make show', then we don't need
+# to build dependencies.
+
+NO_INCLUDE_DEPS = NO
+NO_INCLUDE_PKGDATA = NO
+ifneq "$(findstring clean,$(MAKECMDGOALS))" ""
+NO_INCLUDE_DEPS = YES
+NO_INCLUDE_PKGDATA = YES
+endif
+ifeq "$(findstring show,$(MAKECMDGOALS))" "show"
+NO_INCLUDE_DEPS = YES
+# We want package-data.mk for show
+endif
+
+# We don't haddock base3-compat, as it has the same package name as base
+libraries/base3-compat_dist-install_DO_HADDOCK = NO
+
+# We don't haddock the bootstrapping libraries
+libraries/hpc_dist-boot_DO_HADDOCK = NO
+libraries/Cabal_dist-boot_DO_HADDOCK = NO
+libraries/extensible-exceptions_dist-boot_DO_HADDOCK = NO
+libraries/filepath_dist-boot_DO_HADDOCK = NO
+
+# -----------------------------------------------------------------------------
+# Ways
+
+include rules/way-prelims.mk
+
+$(foreach way,$(ALL_WAYS),\
+ $(eval $(call way-prelims,$(way))))
+
+# -----------------------------------------------------------------------------
+# Compilation Flags
+
+include rules/distdir-opts.mk
+include rules/distdir-way-opts.mk
+
+# -----------------------------------------------------------------------------
+# Finding source files and object files
+
+include rules/hs-sources.mk
+include rules/c-sources.mk
+include rules/includes-sources.mk
+include rules/hs-objs.mk
+include rules/c-objs.mk
+
+# -----------------------------------------------------------------------------
+# Suffix rules
+
+include rules/hs-suffix-rules-srcdir.mk
+include rules/hs-suffix-rules.mk
+
+# -----------------------------------------------------------------------------
+# Suffix rules for .hi files
+
+include rules/hi-rule.mk
+
+$(foreach way,$(ALL_WAYS),\
+ $(eval $(call hi-rule,$(way))))
+
+#-----------------------------------------------------------------------------
+# C-related suffix rules
+
+include rules/c-suffix-rules.mk
+
+# -----------------------------------------------------------------------------
+# Building package-data.mk files from .cabal files
+
+include rules/package-config.mk
+
+# -----------------------------------------------------------------------------
+# Building dependencies
+
+include rules/build-dependencies.mk
+
+# -----------------------------------------------------------------------------
+# Build package-data.mk files
+
+include rules/build-package-data.mk
+
+# -----------------------------------------------------------------------------
+# Build and install a program
+
+include rules/build-prog.mk
+include rules/shell-wrapper.mk
+
+# -----------------------------------------------------------------------------
+# Build a perl script
+
+include rules/build-perl.mk
+
+# -----------------------------------------------------------------------------
+# Build a package
+
+include rules/build-package.mk
+include rules/build-package-way.mk
+include rules/haddock.mk
+
+# -----------------------------------------------------------------------------
+# Registering hand-written package descriptions (used in libffi and rts)
+
+include rules/manual-package-config.mk
+
+# -----------------------------------------------------------------------------
+# Docs
+
+include rules/docbook.mk
+
+# -----------------------------------------------------------------------------
+# Making bindists
+
+include rules/bindist.mk
+
+# -----------------------------------------------------------------------------
+# Building libraries
+
+# XXX generate from $(TOP)/packages
+PACKAGES = \
+ ghc-prim \
+ integer-gmp \
+ base \
+ filepath \
+ array \
+ bytestring \
+ containers
+
+ifeq "$(Windows)" "YES"
+PACKAGES += Win32
+else
+PACKAGES += unix
+endif
+
+PACKAGES += \
+ old-locale \
+ old-time \
+ directory \
+ process \
+ random \
+ extensible-exceptions \
+ haskell98 \
+ hpc \
+ packedstring \
+ pretty \
+ syb \
+ template-haskell \
+ base3-compat \
+ Cabal
+
+BOOT_PKGS = Cabal hpc extensible-exceptions
+
+# The actual .a files: needed for dependencies.
+ALL_LIBS = $(foreach lib,$(PACKAGES),$(libraries/$(lib)_dist-install_v_LIB))
+BOOT_LIBS = $(foreach lib,$(BOOT_PKGS),$(libraries/$(lib)_dist-boot_v_LIB))
+
+OTHER_LIBS = libffi/libHSffi.a libffi/HSffi.o
+ifeq "$(HaveLibGmp)" "NO"
+OTHER_LIBS += gmp/libgmp.a
+endif
+
+# We cannot run ghc-cabal to configure a package until we have
+# configured and registered all of its dependencies. So the following
+# hack forces all the configure steps to happen in exactly the order
+# given in the PACKAGES variable above. Ideally we should use the
+# correct dependencies here to allow more parallelism, but we don't
+# know the dependencies until we've generated the pacakge-data.mk
+# files.
+define fixed_pkg_dep
+libraries/$1/$2/package-data.mk : $(GHC_PKG_INPLACE) $$(if $$(fixed_pkg_prev),libraries/$$(fixed_pkg_prev)/$2/package-data.mk)
+fixed_pkg_prev:=$1
+endef
+
+ifneq "$(BINDIST)" "YES"
+fixed_pkg_prev=
+$(foreach pkg,$(PACKAGES),$(eval $(call fixed_pkg_dep,$(pkg),dist-install)))
+
+# We assume that the stage2 compiler depends on all the libraries, so
+# they all get added to the package database before we try to configure
+# it
+compiler/stage2/package-data.mk: $(foreach pkg,$(PACKAGES),libraries/$(pkg)/dist-install/package-data.mk)
+# haddock depends on ghc and some libraries, but depending on GHC's
+# package-data.mk is sufficient, as that in turn depends on all the
+# libraries
+utils/haddock/dist/package-data.mk: compiler/stage2/package-data.mk
+
+utils/hsc2hs/dist-install/package-data.mk: compiler/stage2/package-data.mk
+
+# add the final two package.conf dependencies: ghc-prim depends on RTS,
+# and RTS depends on libffi.
+libraries/ghc-prim/dist-install/package-data.mk : rts/package.conf.inplace
+rts/package.conf.inplace : libffi/package.conf.inplace
+endif
+
+# -----------------------------------------------------------------------------
+# Special magic for the ghc-prim package
+
+# We want the ghc-prim package to include the GHC.Prim module when it
+# is registered, but not when it is built, because GHC.Prim is not a
+# real source module, it is built-in to GHC. The old build system did
+# this using Setup.hs, but we can't do that here, so we have a flag to
+# enable GHC.Prim in the .cabal file (so that the ghc-prim package
+# remains compatible with the old build system for the time being).
+# GHC.Prim module in the ghc-prim package with a flag:
+#
+libraries/ghc-prim_CONFIGURE_OPTS += --flag=include-ghc-prim
+
+# And then we strip it out again before building the package:
+define libraries/ghc-prim_PACKAGE_MAGIC
+libraries/ghc-prim_dist-install_MODULES := $$(filter-out GHC.Prim,$$(libraries/ghc-prim_dist-install_MODULES))
+endef
+
+PRIMOPS_TXT = $(GHC_COMPILER_DIR)/prelude/primops.txt
+
+libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.hs : $(GENPRIMOP_INPLACE) $(PRIMOPS_TXT)
+ $(MKDIRHIER) $(dir $@)
+ $(GENPRIMOP_INPLACE) --make-haskell-wrappers <$(PRIMOPS_TXT) >$@
+
+libraries/ghc-prim/GHC/Prim.hs : $(GENPRIMOP_INPLACE) $(PRIMOPS_TXT)
+ $(GENPRIMOP_INPLACE) --make-haskell-source <$(PRIMOPS_TXT) >$@
+
+
+# -----------------------------------------------------------------------------
+# Include build instructions from all subdirs
+
+# See commentary in the top-level Makefile for why we divide the build
+# into phases.
+
+# Setting foo_dist_DISABLE=YES means "in directory foo, for build
+# "dist", just read the package-data.mk file, do not build anything".
+
+# We carefully engineer things so that we can build the
+# package-data.mk files early on: they depend only on a few tools also
+# built early. Having got the package-data.mk files built, we can
+# restart make with up-to-date information about all the packages
+# (this is phase 0). The remaining problem is the .depend files:
+#
+# - .depend files in libraries need the stage 1 compiler to build
+# - ghc/stage1/.depend needs compiler/stage1 built
+# - compiler/stage1/.depend needs the bootstrap libs built
+#
+# GHC 6.11+ can build a .depend file without having built the
+# dependencies of the package, but we can't rely on the bootstrapping
+# compiler being able to do this, which is why we have to separate the
+# three phases above.
+
+# So this is the final ordering:
+
+# Phase 0 : all package-data.mk files
+# (requires ghc-cabal, ghc-pkg, mkdirhier, dummy-ghc etc.)
+# Phase 1 : .depend files for bootstrap libs
+# (requires hsc2hs)
+# Phase 2 : compiler/stage1/.depend
+# (requires bootstrap libs and genprimopcode)
+# Phase 3 : ghc/stage1/.depend
+# (requires compiler/stage1)
+#
+# The rest : libraries/*/dist-install, compiler/stage2, ghc/stage2
+
+BUILD_DIRS =
+
+ifneq "$(BINDIST)" "YES"
+BUILD_DIRS += \
+ $(GHC_MKDEPENDC_DIR) \
+ $(GHC_MKDIRHIER_DIR)
+endif
+
+BUILD_DIRS += \
+ gmp \
+ docs/users_guide \
+ libraries/Cabal/doc \
+ $(GHC_MANGLER_DIR) \
+ $(GHC_SPLIT_DIR) \
+ $(GHC_UNLIT_DIR) \
+ $(GHC_HP2PS_DIR)
+
+ifneq "$(BINDIST)" "YES"
+BUILD_DIRS += \
+ $(GHC_GENPRIMOP_DIR)
+endif
+
+BUILD_DIRS += \
+ driver \
+ driver/ghci \
+ driver/ghc \
+ libffi \
+ includes \
+ rts
+
+ifneq "$(BINDIST)" "YES"
+BUILD_DIRS += \
+ $(GHC_CABAL_DIR) \
+ $(GHC_GENAPPLY_DIR)
+endif
+
+BUILD_DIRS += \
+ utils/haddock \
+ $(patsubst %, libraries/%, $(PACKAGES)) \
+ compiler \
+ $(GHC_HSC2HS_DIR) \
+ $(GHC_PKG_DIR) \
+ utils/hasktags \
+ utils/hpc \
+ utils/runghc \
+ ghc
+ifeq "$(Windows)" "YES"
+BUILD_DIRS += \
+ $(GHC_TOUCHY_DIR)
+endif
+
+# XXX libraries/% must come before any programs built with stage1, see
+# Note [lib-depends].
+
+ifeq "$(phase)" "0"
+$(foreach lib,$(BOOT_PKGS),$(eval \
+ libraries/$(lib)_dist-boot_DISABLE = YES))
+endif
+
+ifneq "$(findstring $(phase),0 1)" ""
+# We can build deps for compiler/stage1 in phase 2
+compiler_stage1_DISABLE = YES
+endif
+
+ifneq "$(findstring $(phase),0 1 2)" ""
+ghc_stage1_DISABLE = YES
+endif
+
+ifneq "$(findstring $(phase),0 1 2 3)" ""
+# In phases 0-3, we disable stage2-3, the full libraries and haddock
+utils/haddock_dist_DISABLE = YES
+utils/runghc_dist_DISABLE = YES
+utils/hpc_dist_DISABLE = YES
+utils/hasktags_dist_DISABLE = YES
+utils/hsc2hs_dist-install_DISABLE = YES
+utils/ghc-pkg_dist-install_DISABLE = YES
+compiler_stage2_DISABLE = YES
+compiler_stage3_DISABLE = YES
+ghc_stage2_DISABLE = YES
+ghc_stage3_DISABLE = YES
+$(foreach lib,$(PACKAGES),$(eval \
+ libraries/$(lib)_dist-install_DISABLE = YES))
+endif
+
+include $(patsubst %, %/ghc.mk, $(BUILD_DIRS))
+
+# We need -fno-warn-deprecated-flags to avoid failure with -Werror
+GhcLibHcOpts += -fno-warn-deprecated-flags
+ifeq "$(ghc_ge_609)" "YES"
+GhcBootLibHcOpts += -fno-warn-deprecated-flags
+endif
+
+# Add $(GhcLibHcOpts) to all library builds
+$(foreach pkg,$(PACKAGES),$(eval libraries/$(pkg)_dist-install_HC_OPTS += $$(GhcLibHcOpts)))
+
+# XXX we configure packages with the bootsrapping compiler (for
+# dependency reasons, see the phase ordering), which doesn't
+# necessarily support all the extensions we need, and Cabal filters
+# out the ones it thinks aren't supported.
+libraries/base3-compat_dist-install_HC_OPTS += -XPackageImports
+
+# -----------------------------------------------------------------------------
+# Bootstrapping libraries
+
+# We need to build a few libraries with the installed GHC, since GHC itself
+# and some of the tools depend on them:
+
+ifneq "$(BINDIST)" "YES"
+
+ifeq "$(wildcard $(BOOTSTRAPPING_CONF))" ""
+$(shell echo "[]" >$(BOOTSTRAPPING_CONF))
+endif
+
+$(eval $(call clean-target,$(BOOTSTRAPPING_CONF),,$(BOOTSTRAPPING_CONF)))
+
+# These three libraries do not depend on each other, so we can build
+# them straight off:
+
+$(eval $(call build-package,libraries/hpc,dist-boot,0))
+$(eval $(call build-package,libraries/extensible-exceptions,dist-boot,0))
+$(eval $(call build-package,libraries/Cabal,dist-boot,0))
+
+# register the boot packages in strict sequence, because running
+# multiple ghc-pkgs in parallel doesn't work (registrations may get
+# lost).
+fixed_pkg_prev=
+$(foreach pkg,$(BOOT_PKGS),$(eval $(call fixed_pkg_dep,$(pkg),dist-boot)))
+
+compiler/stage1/package-data.mk : \
+ libraries/Cabal/dist-boot/package-data.mk \
+ libraries/hpc/dist-boot/package-data.mk \
+ libraries/extensible-exceptions/dist-boot/package-data.mk
+
+# These are necessary because the bootstrapping compiler may not know
+# about cross-package dependencies:
+$(compiler_stage1_depfile) : $(BOOT_LIBS)
+$(ghc_stage1_depfile) : $(compiler_stage1_v_LIB)
+
+$(foreach pkg,$(BOOT_PKGS),$(eval libraries/$(pkg)_dist-boot_HC_OPTS += $$(GhcBootLibHcOpts)))
+
+endif
+
+# -----------------------------------------------------------------------------
+# Creating a local mingw copy on Windows
+
+ifeq "$(Windows)" "YES"
+
+# directories don't work well as dependencies, hence a stamp file
+$(INPLACE)/stamp-mingw : $(MKDIRHIER)
+ $(MKDIRHIER) $(INPLACE_MINGW)/bin
+ GCC=`type -p $(WhatGccIsCalled)`; \
+ GccDir=`dirname $$GCC`; \
+ $(CP) -p $$GccDir/{gcc.exe,ar.exe,as.exe,dlltool.exe,dllwrap.exe,windres.exe} $(INPLACE_MINGW)/bin; \
+ $(CP) -Rp $$GccDir/../include $(INPLACE_MINGW); \
+ $(CP) -Rp $$GccDir/../lib $(INPLACE_MINGW); \
+ $(CP) -Rp $$GccDir/../libexec $(INPLACE_MINGW); \
+ $(CP) -Rp $$GccDir/../mingw32 $(INPLACE_MINGW)
+ touch $(INPLACE)/stamp-mingw
+
+install : install_mingw
+.PHONY: install_mingw
+install_mingw : $(INPLACE_MINGW)
+ $(CP) -Rp $(INPLACE_MINGW) $(prefix)
+
+$(INPLACE_LIB)/perl.exe $(INPLACE_LIB)/perl56.dll :
+ $(CP) $(GhcDir)../{perl.exe,perl56.dll} $(INPLACE_LIB)
+
+endif # Windows
+
+libraries/ghc-prim/dist-install/doc/html/ghc-prim/ghc-prim.haddock: \
+ libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs \
+ libraries/ghc-prim/dist-install/build/autogen/GHC/PrimopWrappers.hs
+
+libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs: \
+ $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE) $(MKDIRHIER)
+ $(MKDIRHIER) $(dir $@)
+ $(GENPRIMOP_INPLACE) --make-haskell-source < $< > $@
+
+libraries/ghc-prim/dist-install/build/autogen/GHC/PrimopWrappers.hs: \
+ $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE) $(MKDIRHIER)
+ $(MKDIRHIER) $(dir $@)
+ $(GENPRIMOP_INPLACE) --make-haskell-wrappers < $< > $@
+
+# -----------------------------------------------------------------------------
+# Installation
+
+install: install_packages install_libs install_libexecs install_headers \
+ install_libexec_scripts install_bins
+
+install_bins: $(INSTALL_BINS)
+ $(INSTALL_DIR) $(DESTDIR)$(bindir)
+ for i in $(INSTALL_BINS); do \
+ $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i $(DESTDIR)$(bindir) ; \
+ if test "$(darwin_TARGET_OS)" = "1"; then \
+ sh mk/fix_install_names.sh $(libdir) $(DESTDIR)$(bindir)/$$i ; \
+ fi ; \
+ done
+
+install_libs: $(INSTALL_LIBS)
+ $(INSTALL_DIR) $(DESTDIR)$(libdir)
+ for i in $(INSTALL_LIBS); do \
+ case $$i in \
+ *.a) \
+ $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir); \
+ $(RANLIB) $(DESTDIR)$(libdir)/`basename $$i` ;; \
+ *.dll) \
+ $(INSTALL_DATA) -s $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir) ;; \
+ *.so) \
+ $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir) ;; \
+ *.dylib) \
+ $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir); \
+ install_name_tool -id $(DESTDIR)$(libdir)/`basename $$i` $(DESTDIR)$(libdir)/`basename $$i` ;; \
+ *) \
+ $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir); \
+ esac; \
+ done
+
+install_libexec_scripts: $(INSTALL_LIBEXEC_SCRIPTS)
+ $(MKDIRHIER) $(DESTDIR)$(libexecdir)
+ for i in $(INSTALL_LIBEXEC_SCRIPTS); do \
+ $(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i $(DESTDIR)$(libexecdir); \
+ done
+
+install_libexecs: $(INSTALL_LIBEXECS)
+ $(MKDIRHIER) $(DESTDIR)$(libexecdir)
+ for i in $(INSTALL_LIBEXECS); do \
+ $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i $(DESTDIR)$(libexecdir); \
+ done
+
+install_headers: $(INSTALL_HEADERS)
+ $(INSTALL_DIR) $(DESTDIR)$(headerdir)
+ for i in $(INSTALL_HEADERS); do \
+ $(INSTALL_HEADER) $(INSTALL_OPTS) $$i $(DESTDIR)$(headerdir); \
+ done
+
+INSTALLED_PACKAGE_CONF=$(DESTDIR)$(libdir)/package.conf
+
+# Install packages in the right order, so that ghc-pkg doesn't complain.
+# Also, install ghc-pkg first.
+ifeq "$(Windows)" "NO"
+INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(libexecdir)/ghc-pkg
+else
+INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(bindir)/ghc-pkg.exe
+endif
+
+install_packages: install_libexecs
+install_packages: libffi/package.conf.install rts/package.conf.install
+ $(MKDIRHIER) $(DESTDIR)$(libdir)
+ echo "[]" > $(INSTALLED_PACKAGE_CONF)
+ $(INSTALLED_GHC_PKG_REAL) --force --global-conf $(INSTALLED_PACKAGE_CONF) update libffi/package.conf.install
+ $(INSTALLED_GHC_PKG_REAL) --force --global-conf $(INSTALLED_PACKAGE_CONF) update rts/package.conf.install
+ $(foreach p, $(PACKAGES),\
+ $(GHC_CABAL_INPLACE) install \
+ $(INSTALLED_GHC_PKG_REAL) \
+ $(INSTALLED_PACKAGE_CONF) \
+ libraries/$p dist-install \
+ '$(DESTDIR)' '$(prefix)' '$(libdir)' '$(docdir)/libraries' &&) true
+ $(GHC_CABAL_INPLACE) install \
+ $(INSTALLED_GHC_PKG_REAL) \
+ $(INSTALLED_PACKAGE_CONF) \
+ compiler stage2 \
+ '$(DESTDIR)' '$(prefix)' '$(libdir)' '$(docdir)/libraries'
+
+# -----------------------------------------------------------------------------
+# Binary distributions
+
+$(eval $(call bindist,.,\
+ LICENSE \
+ configure config.sub config.guess \
+ extra-gcc-opts.in \
+ Makefile \
+ mk/config.mk.in \
+ $(INPLACE_BIN)/mkdirhier \
+ $(INPLACE_BIN)/ghc-cabal \
+ utils/pwd/pwd \
+ $(BINDIST_WRAPPERS) \
+ $(BINDIST_LIBS) \
+ $(BINDIST_HI) \
+ $(BINDIST_EXTRAS) \
+ $(INSTALL_HEADERS) \
+ $(INSTALL_LIBEXECS) \
+ $(INSTALL_LIBEXEC_SCRIPTS) \
+ $(INSTALL_BINS) \
+ $(filter-out extra-gcc-opts,$(INSTALL_LIBS)) \
+ $(filter-out %/project.mk,$(filter-out mk/config.mk,$(MAKEFILE_LIST))) \
+ mk/fix_install_names.sh \
+ mk/project.mk \
+ ))
+# mk/project.mk gets an absolute path, so we manually include it in
+# the bindist with a relative path
+
+binary-dist:
+ $(RM) -rf $(BIN_DIST_NAME)
+ mkdir $(BIN_DIST_NAME)
+ set -e; for i in LICENSE compiler ghc rts libraries utils gmp docs libffi includes driver mk rules Makefile aclocal.m4 config.sub config.guess extra-gcc-opts.in ghc.mk inplace; do ln -s ../$$i $(BIN_DIST_NAME)/; done
+ ln -s ../distrib/configure-bin.ac $(BIN_DIST_NAME)/configure.ac
+ cd $(BIN_DIST_NAME) && autoreconf
+ $(RM) -f $(BIN_DIST_TAR)
+# h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
+# tree then we want to include the real file, not a symlink to it
+ $(TAR) hcf $(BIN_DIST_TAR) -T $(BIN_DIST_LIST)
+ bzip2 < $(BIN_DIST_TAR) > $(BIN_DIST_TAR_BZ2)
+
+# -----------------------------------------------------------------------------
+# Source distributions
+
+# Do it like this:
+#
+# $ make
+# $ make sdist
+#
+
+# A source dist is built from a complete build tree, because we
+# require some extra files not contained in a darcs checkout: the
+# output from Happy and Alex, for example.
+#
+# The steps performed by 'make dist' are as follows:
+# - create a complete link-tree of the current build tree in /tmp
+# - run 'make distclean' on that tree
+# - remove a bunch of other files that we know shouldn't be in the dist
+# - tar up first the extralibs package, then the main source package
+
+#
+# Directory in which we're going to build the src dist
+#
+SRC_DIST_NAME=ghc-$(ProjectVersion)
+SRC_DIST_DIR=$(shell pwd)/$(SRC_DIST_NAME)
+
+#
+# Files to include in source distributions
+#
+SRC_DIST_DIRS = mk rules docs distrib bindisttest gmp libffi includes utils docs rts compiler ghc driver libraries
+SRC_DIST_FILES += \
+ configure.ac config.guess config.sub configure \
+ aclocal.m4 README ANNOUNCE HACKING LICENSE Makefile install-sh \
+ ghc.spec.in ghc.spec extra-gcc-opts.in VERSION boot ghc.mk
+
+EXTRA_LIBS=$(patsubst %, $(SRC_DIST_NAME)/%, $(shell grep -E "extralibs|dph" packages | grep -v "^\#" | sed "s/ .*//"))
+
+SRC_DIST_TARBALL = ghc-$(ProjectVersion)-src.tar.bz2
+SRC_DIST_EXTRALIBS_TARBALL = ghc-$(ProjectVersion)-src-extralibs.tar.bz2
+
+VERSION :
+ echo $(ProjectVersion) >VERSION
+
+sdist : VERSION
+
+# Use:
+# $(call sdist_file,compiler,stage2,cmm,CmmLex,x)
+# to copy the generated file that replaces compiler/cmm/CmmLex.x, where
+# "stage2" is the dist dir.
+sdist_file = \
+ if test -f $(TOP)/$1/$2/build/$4.hs; then \
+ $(CP) $(TOP)/$1/$2/build/$4.hs $1/$3/ ; \
+ mv $1/$3/$4.$5 $1/$3/$4.$5.source ;\
+ else \
+ echo "does not exist: $1/$2//build/$4.hs"; \
+ exit 1; \
+ fi
+
+.PHONY: sdist-prep
+sdist-prep :
+ $(RM) -rf $(SRC_DIST_DIR)
+ $(RM) $(SRC_DIST_NAME).tar.gz
+ mkdir $(SRC_DIST_DIR)
+ ( cd $(SRC_DIST_DIR) \
+ && for i in $(SRC_DIST_DIRS); do mkdir $$i; (cd $$i && lndir $(TOP)/$$i ); done \
+ && for i in $(SRC_DIST_FILES); do $(LN_S) $(TOP)/$$i .; done \
+ && $(MAKE) distclean \
+ && if test -f $(TOP)/libraries/haskell-src/dist/build/Language/Haskell/Parser.hs; then $(CP) $(TOP)/libraries/haskell-src/dist/build/Language/Haskell/Parser.hs libraries/haskell-src/Language/Haskell/ ; mv libraries/haskell-src/Language/Haskell/Parser.ly libraries/haskell-src/Language/Haskell/Parser.ly.source ; fi \
+ && $(call sdist_file,compiler,stage2,cmm,CmmLex,x) \
+ && $(call sdist_file,compiler,stage2,cmm,CmmParse,y) \
+ && $(call sdist_file,compiler,stage2,main,ParsePkgConf,y) \
+ && $(call sdist_file,compiler,stage2,parser,HaddockLex,x) \
+ && $(call sdist_file,compiler,stage2,parser,HaddockParse,y) \
+ && $(call sdist_file,compiler,stage2,parser,Lexer,x) \
+ && $(call sdist_file,compiler,stage2,parser,Parser,y.pp) \
+ && $(call sdist_file,compiler,stage2,parser,ParserCore,y) \
+ && $(call sdist_file,utils/hpc,dist,,HpcParser,y) \
+ && $(call sdist_file,utils/genprimopcode,dist,,Lexer,x) \
+ && $(call sdist_file,utils/genprimopcode,dist,,Parser,y) \
+ && $(RM) -rf compiler/stage[123] mk/build.mk \
+ && $(FIND) $(SRC_DIST_DIRS) \( -name _darcs -o -name SRC -o -name "autom4te*" -o -name "*~" -o -name ".cvsignore" -o -name "\#*" -o -name ".\#*" -o -name "log" -o -name "*-SAVE" -o -name "*.orig" -o -name "*.rej" -o -name "*-darcs-backup*" \) -print | xargs $(RM) -rf \
+ )
+
+.PHONY: sdist
+sdist : sdist-prep
+ $(TAR) chf - $(EXTRA_LIBS) | bzip2 >$(TOP)/$(SRC_DIST_EXTRALIBS_TARBALL)
+ $(RM) -rf $(EXTRA_LIBS)
+ $(TAR) chf - $(SRC_DIST_NAME) 2>$src_log | bzip2 >$(TOP)/$(SRC_DIST_TARBALL)
+
+sdist-manifest : $(SRC_DIST_TARBALL)
+ tar tjf $(SRC_DIST_TARBALL) | sed "s|^ghc-$(ProjectVersion)/||" | sort >sdist-manifest
+
+# Upload the distribution(s)
+# Retrying is to work around buggy firewalls that corrupt large file transfers
+# over SSH.
+ifneq "$(PublishLocation)" ""
+publish-sdist :
+ @for i in 0 1 2 3 4 5 6 7 8 9; do \
+ echo "Try $$i: $(PublishCp) $(SRC_DIST_EXTRALIBS_TARBALL) $(PublishLocation)/dist"; \
+ if $(PublishCp) $(SRC_DIST_EXTRALIBS_TARBALL) $(PublishLocation)/dist; then break; fi; \
+ done
+ @for i in 0 1 2 3 4 5 6 7 8 9; do \
+ echo "Try $$i: $(PublishCp) $(SRC_DIST_TARBALL) $(PublishLocation)/dist"; \
+ if $(PublishCp) $(SRC_DIST_TARBALL) $(PublishLocation)/dist; then break; fi; \
+ done
+endif
+
+# -----------------------------------------------------------------------------
+# Cleaning
+
+.PHONY: clean
+
+clean : clean_files
+.PHONY: clean_files
+clean_files :
+ $(RM) $(CLEAN_FILES)
+
+distclean : clean
+ $(RM) config.cache config.status config.log mk/config.h mk/stamp-h
+ $(RM) mk/config.mk mk/are-validating.mk
+ $(RM) extra-gcc-opts docs/users_guide/ug-book.xml
+ $(RM) compiler/ghc.cabal ghc/ghc-bin.cabal
+ $(RM) libraries/base/include/HsBaseConfig.h
+ $(RM) libraries/directory/include/HsDirectoryConfig.h
+
+maintainer-clean : distclean
+ $(RM) ghc.spec
+ $(RM) libraries/*/GNUmakefile
diff --git a/ghc.spec.in b/ghc.spec.in
index 5d3fa1f1d1..3400227c3a 100644
--- a/ghc.spec.in
+++ b/ghc.spec.in
@@ -1,3 +1,6 @@
+# WARNING: ghc.spec is automatically generated from ghc.spec.in by
+# ./configure. Make sure you are editing ghc.spec.in, not ghc.spec.
+#
# RPM spec file for GHC -*-rpm-spec-*-
#
# Copyright [1998..2007] The GHC Team
diff --git a/ghc/Main.hs b/ghc/Main.hs
index df90857fbb..bdf9e63e43 100644
--- a/ghc/Main.hs
+++ b/ghc/Main.hs
@@ -10,8 +10,6 @@
module Main (main) where
-#include "HsVersions.h"
-
-- The official GHC API
import qualified GHC
import GHC ( DynFlags(..), HscTarget(..),
diff --git a/ghc/Makefile b/ghc/Makefile
index ed7d24b643..664df24c4a 100644
--- a/ghc/Makefile
+++ b/ghc/Makefile
@@ -1,155 +1,16 @@
+dir = ghc
+TOP = ..
+SPEC_TARGETS = 1 2 3
+include $(TOP)/mk/sub-makefile.mk
-TOP=..
-include $(TOP)/mk/boilerplate.mk
-include $(TOP)/mk/cabal-flags.mk
+.PHONY: 1 2 3
-ifeq "$(stage)" ""
-stage=1
-endif
+1:
+ +$(TOPMAKE) stage=1 all_ghc_stage1 compiler_stage1_NO_BUILD_DEPS=YES
-ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
-INSTALL_FLAGS =
-else
-INSTALL_FLAGS = --enable-shell-wrappers
-endif
+2:
+ +$(TOPMAKE) stage=2 all_ghc_stage2 compiler_stage2_NO_BUILD_DEPS=YES
-# Don't strip the inplace versions, we might need to debug them
-INPLACE_INSTALL_FLAGS += --disable-executable-stripping
-
-boot:: boot.stage.$(stage)
-
-all:: build.stage.$(stage)
-
-rebuild ::
- -$(CABAL) clean --distpref dist-stage$(stage)
- $(RM) -rf stage$(stage)-inplace
- $(MAKE) boot all
-
-stage1 ::
- $(MAKE) stage=1
-
-stage2 ::
- $(MAKE) stage=2
-
-stage3 ::
- $(MAKE) stage=3
-
-
-ifeq "$(CLEAN_ALL_STAGES)" "YES"
-clean distclean maintainer-clean:: clean.stage.1 clean.stage.2 clean.stage.3
-else
-clean distclean maintainer-clean:: clean.stage.$(stage)
-endif
-
-ifeq "$(CLEAN_ALL_STAGES)" "YES"
-distclean maintainer-clean::
- $(RM) -f ghc-bin.cabal
-endif
-
-clean.stage.%:
- $(RM) -rf stage$*-inplace
-# This is a bit naughty. We ought to use:
-# -$(CABAL) clean --distpref dist-stage$*
-# but that won't work if the Cabal file (a generated file) doesn't
-# exist. So we do this instead:
- $(RM) -rf dist-stage$*
-
-CONFIGURE_FLAGS_STAGE1 += --flags=-ghci
-
-ifeq "$(GhcWithInterpreter)" "YES"
-CONFIGURE_FLAGS_STAGE2PLUS += --flags=ghci
-else
-CONFIGURE_FLAGS_STAGE2PLUS += --flags=-ghci
-endif
-
-ifeq "$(GhcProfiled)" "YES"
-CONFIGURE_FLAGS_STAGE2PLUS += --enable-executable-profiling
-endif
-ifeq "$(GhcDebugged)" "YES"
-CONFIGURE_FLAGS_STAGE2PLUS += --ghc-option=-debug
-endif
-ifeq "$(GhcThreaded)" "YES"
-# Use threaded RTS with GHCi, so threads don't get blocked at the prompt.
-CONFIGURE_FLAGS_STAGE2PLUS += --ghc-option=-threaded
-endif
-
-ifeq "$(BuildSharedLibs)" "YES"
-CONFIGURE_FLAGS_STAGE2PLUS += --ghc-option=-dynamic
-endif
-
-CONFIGURE_FLAGS_STAGE2 = $(CONFIGURE_FLAGS_STAGE2PLUS)
-CONFIGURE_FLAGS_STAGE3 = $(CONFIGURE_FLAGS_STAGE2PLUS)
-
-CONFIGURE_FLAGS_STAGE1 += $(USE_BOOT_CONFIGURE_FLAGS)
-CONFIGURE_FLAGS_STAGE2 += $(USE_STAGE1_CONFIGURE_FLAGS)
-CONFIGURE_FLAGS_STAGE3 += $(USE_STAGE2_CONFIGURE_FLAGS)
-CONFIGURE_FLAGS_STAGE3 += --package-db $(STAGE3_PACKAGE_CONF)
-
-CONFIGURE_FLAGS_STAGE1 += $(foreach flag, $(GhcStage1HcOpts), --ghc-option=$(flag))
-CONFIGURE_FLAGS_STAGE2 += $(foreach flag, $(GhcStage2HcOpts), --ghc-option=$(flag))
-CONFIGURE_FLAGS_STAGE3 += $(foreach flag, $(GhcStage3HcOpts), --ghc-option=$(flag))
-
-BUILD_FLAGS += $(patsubst %, --ghc-option=%, $(SRC_HC_OPTS))
-# Allow EXTRA_HC_OPTS to be used from the command line to add options
-# when building (e.g. -v)
-BUILD_FLAGS += $(patsubst %, --ghc-option=%, $(EXTRA_HC_OPTS))
-
-# XXX In stage2+ we should really use the inplace ghc-pkg
-# It works because installPackage doesn't actually use ghc-pkg, as there's
-# no library to register
-
-ifeq "$(stage)" "1"
-ifeq "$(ghc_ge_609)" "NO"
-# GHC 6.9+ can handle cross-package recompilation checking, but
-# we don't rely on the bootstrapping compiler being able to do this.
-TOUCH_MAIN = $(RM) dist-stage1/build/ghc/ghc-tmp/Main.o
-endif
-endif
-
-dist-stage1 dist-stage2 dist-stage3: dist-stage%: boot.stage.%
-
-boot.stage.%:
- $(CABAL) configure --distpref dist-stage$* \
- $(INSTALL_DIRS_CONFIGURE_FLAGS) \
- $(CONFIGURE_FLAGS_STAGE$*) \
- $(COMMON_CONFIGURE_FLAGS) \
- --libsubdir=. \
- --datadir='$$libdir' \
- --datasubdir=.
-
-build.stage.%: dist-stage%
- $(TOUCH_MAIN)
- $(CABAL) build --distpref dist-stage$* $(BUILD_FLAGS)
- $(INSTALL_PACKAGE) install '$(GHC_PKG_PROG)' 'XXX/package.conf' "" \
- $(FPTOOLS_TOP_ABS)/ghc/stage$*-inplace \
- $(FPTOOLS_TOP_ABS)/ghc/stage$*-inplace \
- '$$prefix' \
- '$(INPLACE_DATA_DIR)' \
- '$$prefix/libexec' \
- '$$prefix/dynlib' \
- '$(INPLACE_DATA_DIR)' \
- '$$prefix/doc' \
- '$$prefix/html' \
- '$$prefix/haddock' \
- --distpref dist-stage$* \
- $(INPLACE_INSTALL_FLAGS) \
- $(INSTALL_FLAGS)
-
-# XXX For now we always install the stage 2 compiler
-install:
- $(INSTALL_PACKAGE) install UNUSED UNUSED '$(DESTDIR)' '$(prefix)' \
- '$(prefix)' '$(bindir)' '$(libdir)' \
- '$(libexecdir)' '$(dynlibdir)' '$(datadir)' \
- '$(docdir)' '$(htmldir)' '$(haddockdir)' \
- --distpref dist-stage2 \
- $(INSTALL_FLAGS)
-
-html:
- @:
-
-install-docs:
- @:
-
-include $(TOP)/mk/bindist.mk
-EXE_DIST_DIR = dist-stage2
+3:
+ +$(TOPMAKE) stage=3 all_ghc_stage3 compiler_stage3_NO_BUILD_DEPS=YES
diff --git a/ghc/ghc-bin.cabal.in b/ghc/ghc-bin.cabal.in
index 4e6d0081b1..3374edf62d 100644
--- a/ghc/ghc-bin.cabal.in
+++ b/ghc/ghc-bin.cabal.in
@@ -1,3 +1,6 @@
+-- WARNING: ghc-bin.cabal is automatically generated from ghc-bin.cabal.in by
+-- ./configure. Make sure you are editing ghc-bin.cabal.in, not ghc-bin.cabal.
+
Name: ghc-bin
Version: @ProjectVersion@
Copyright: XXX
diff --git a/ghc/ghc.mk b/ghc/ghc.mk
new file mode 100644
index 0000000000..7f9c630771
--- /dev/null
+++ b/ghc/ghc.mk
@@ -0,0 +1,127 @@
+# ToDo
+ghc_USES_CABAL = NO
+# ghc_PACKAGE = ghc-bin
+
+ghc_stage1_HC_OPTS = $(GhcStage1HcOpts)
+ghc_stage2_HC_OPTS = $(GhcStage2HcOpts)
+ghc_stage3_HC_OPTS = $(GhcStage3HcOpts)
+
+ifeq "$(GhcWithInterpreter)" "YES"
+ghc_stage2_HC_OPTS += -DGHCI
+ghc_stage3_HC_OPTS += -DGHCI
+endif
+
+ifeq "$(GhcDebugged)" "YES"
+ghc_HC_OPTS += -debug
+endif
+
+ifeq "$(GhcThreaded)" "YES"
+# Use threaded RTS with GHCi, so threads don't get blocked at the prompt.
+ghc_HC_OPTS += -threaded
+endif
+
+ifeq "$(BuildSharedLibs)" "YES"
+ghc_HC_OPTS += -dynamic
+endif
+
+# XXX ToDp
+# ifeq "$(GhcProfiled)" "YES"
+
+ghc_stage1_MODULES = Main
+
+ghc_stage2_MODULES = $(ghc_stage1_MODULES)
+ghc_stage3_MODULES = $(ghc_stage1_MODULES)
+
+ghc_stage1_PROG = ghc-stage1$(exeext)
+ghc_stage2_PROG = ghc-stage2$(exeext)
+ghc_stage3_PROG = ghc-stage3$(exeext)
+
+# ToDo: perhaps use ghc-cabal to configure ghc-bin
+ghc_stage1_USE_BOOT_LIBS = YES
+ghc_stage1_HC_OPTS += -package $(compiler_PACKAGE)-$(compiler_stage1_VERSION)
+ghc_stage2_HC_OPTS += -package $(compiler_PACKAGE)-$(compiler_stage2_VERSION)
+ghc_stage3_HC_OPTS += -package $(compiler_PACKAGE)-$(compiler_stage3_VERSION)
+
+ghc_stage1_HC_OPTS += -XCPP -XPatternGuards
+ghc_stage2_HC_OPTS += -XCPP -XPatternGuards
+ghc_stage3_HC_OPTS += -XCPP -XPatternGuards
+
+# In stage1 we might not benefit from cross-package dependencies and
+# recompilation checking. We must force recompilation here, otherwise
+# Main.o won't necessarily be rebuilt when the ghc package has changed:
+ghc_stage1_HC_OPTS += -fforce-recomp
+
+# Further dependencies we need only in stage 1, due to no
+# cross-package dependencies or recompilation checking.
+ghc/stage1/build/Main.o : $(compiler_stage1_v_LIB)
+
+ghc_stage1_SHELL_WRAPPER = YES
+ghc_stage2_SHELL_WRAPPER = YES
+ghc_stage3_SHELL_WRAPPER = YES
+ghc_stage1_SHELL_WRAPPER_NAME = ghc/ghc.wrapper
+ghc_stage2_SHELL_WRAPPER_NAME = ghc/ghc.wrapper
+ghc_stage3_SHELL_WRAPPER_NAME = ghc/ghc.wrapper
+
+ghc_stage$(INSTALL_GHC_STAGE)_INSTALL_SHELL_WRAPPER = YES
+ghc_stage$(INSTALL_GHC_STAGE)_INSTALL_SHELL_WRAPPER_NAME = ghc-$(ProjectVersion)
+
+# stage 1 is enabled unless $(stage) is set to something other than 1
+ifeq "$(filter-out 1,$(stage))" ""
+$(eval $(call build-prog,ghc,stage1,0))
+endif
+
+# stage 2 is enabled unless $(stage) is set to something other than 2
+ifeq "$(filter-out 2,$(stage))" ""
+$(eval $(call build-prog,ghc,stage2,1))
+endif
+
+# stage 3 has to be requested explicitly with stage=3
+ifeq "$(stage)" "3"
+$(eval $(call build-prog,ghc,stage3,2))
+endif
+
+ifneq "$(BINDIST)" "YES"
+
+# ToDo: should we add these in the build-prog macro?
+ghc/stage1/build/tmp/$(ghc_stage1_PROG) : $(compiler_stage1_v_LIB)
+ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(compiler_stage2_v_LIB)
+ghc/stage3/build/tmp/$(ghc_stage3_PROG) : $(compiler_stage3_v_LIB)
+
+all_ghc_stage1 : $(GHC_STAGE1)
+all_ghc_stage2 : $(GHC_STAGE2)
+all_ghc_stage3 : $(GHC_STAGE3)
+
+$(INPLACE_LIB)/extra-gcc-opts : extra-gcc-opts
+ $(CP) $< $@
+
+# The GHC programs need to depend on all the helper programs they might call
+$(GHC_STAGE1) : $(INPLACE_LIB)/extra-gcc-opts $(MANGLER) $(SPLIT)
+$(GHC_STAGE2) : $(INPLACE_LIB)/extra-gcc-opts $(MANGLER) $(SPLIT)
+$(GHC_STAGE3) : $(INPLACE_LIB)/extra-gcc-opts $(MANGLER) $(SPLIT)
+
+ifeq "$(Windows)" "YES"
+$(GHC_STAGE1) : $(TOUCHY) $(INPLACE)/stamp-mingw $(INPLACE_LIB)/perl.exe
+$(GHC_STAGE2) : $(TOUCHY) $(INPLACE)/stamp-mingw $(INPLACE_LIB)/perl.exe
+$(GHC_STAGE3) : $(TOUCHY) $(INPLACE)/stamp-mingw $(INPLACE_LIB)/perl.exe
+endif
+
+endif
+
+INSTALL_LIBS += extra-gcc-opts
+
+ifeq "$(Windows)" "NO"
+install: install_ghc_link
+.PNONY: install_ghc_link
+install_ghc_link:
+ $(RM) -f $(DESTDIR)$(bindir)/ghc
+ $(LN_S) ghc-$(ProjectVersion) $(DESTDIR)$(bindir)/ghc
+else
+# On Windows we install the main binary as $(bindir)/ghc.exe
+# To get ghc-<version>.exe we have a little C program in driver/ghc
+install: install_ghc_post
+.PHONY: install_ghc_post
+install_ghc_post: install_bins
+ $(RM) -f $(DESTDIR)$(bindir)/ghc.exe
+ $(MV) -f $(DESTDIR)$(bindir)/ghc-stage$(INSTALL_GHC_STAGE).exe $(DESTDIR)$(bindir)/ghc.exe
+endif
+
diff --git a/ghc/ghc.wrapper b/ghc/ghc.wrapper
index 71eae84738..ce409ca488 100644
--- a/ghc/ghc.wrapper
+++ b/ghc/ghc.wrapper
@@ -1,3 +1 @@
-#!/bin/sh
-
exec $executablename -B$datadir -dynload wrapped ${1+"$@"}
diff --git a/gmp/Makefile b/gmp/Makefile
deleted file mode 100644
index 78cb5702b5..0000000000
--- a/gmp/Makefile
+++ /dev/null
@@ -1,127 +0,0 @@
-
-TOP=..
-
-include $(TOP)/mk/boilerplate.mk
-
-# -----------------------------------------------------------------------------
-# Compile GMP only if we don't have it already
-#
-# We use GMP's own configuration stuff, because it's all rather hairy
-# and not worth re-implementing in our Makefile framework.
-
-ifneq "$(HaveLibGmp)" "YES"
-ifneq "$(HaveFrameworkGMP)" "YES"
-
-PLATFORM := $(shell echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g')
-
-# 2007-09-26
-# set -o igncr
-# is not a valid command on non-Cygwin-systems.
-# Let it fail silently instead of aborting the build.
-#
-# 2007-07-05
-# We do
-# set -o igncr; export SHELLOPTS
-# here as otherwise checking the size of limbs
-# makes the build fall over on Cygwin. See the thread
-# http://www.cygwin.com/ml/cygwin/2006-12/msg00011.html
-# for more details.
-
-# 2007-07-05
-# Passing
-# as_ln_s='cp -p'
-# isn't sufficient to stop cygwin using symlinks the mingw gcc can't
-# follow, as it isn't used consistently. Instead we put an ln.bat in
-# path that always fails.
-
-# We use a tarball like gmp-4.2.1-nodoc.tar.gz, which is
-# gmp-4.2.1.tar.gz repacked without the doc/ directory contents.
-# That's because the doc/ directory contents are under the GFDL,
-# which causes problems for Debian.
-
-GMP_TARBALL := $(firstword $(wildcard gmp*.tar.gz))
-GMP_DIR := $(subst -nodoc.tar.gz,,$(GMP_TARBALL))
-
-ifeq "$(findstring dyn, $(GhcRTSWays))" "dyn"
-BUILD_SHARED=yes
-else
-BUILD_SHARED=no
-endif
-
-BINDIST_STAMPS = stamp.gmp.static
-INSTALL_HEADERS += gmp.h
-INSTALL_LIBS += libgmp.a
-
-ifeq "$(BUILD_SHARED)" "yes"
-BINDIST_STAMPS += stamp.gmp.shared
-INSTALL_LIBS += libgmp.dll.a
-INSTALL_PROGS += libgmp-3.dll
-endif
-
-install all :: $(INSTALL_HEADERS) $(INSTALL_LIBS) $(INSTALL_PROGS)
-
-stamp.gmp.static:
- $(RM) -rf $(GMP_DIR) gmpbuild
- $(TAR) -zxf $(GMP_TARBALL)
- mv $(GMP_DIR) gmpbuild
- chmod +x ln
- (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
- PATH=`pwd`:$$PATH; \
- export PATH; \
- cd gmpbuild && \
- CC=$(WhatGccIsCalled) $(SHELL) configure \
- --enable-shared=no --host=$(PLATFORM) --build=$(PLATFORM)
- touch $@
-
-stamp.gmp.shared:
- $(RM) -rf $(GMP_DIR) gmpbuild-shared
- $(TAR) -zxf $(GMP_TARBALL)
- mv $(GMP_DIR) gmpbuild-shared
- chmod +x ln
- (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
- PATH=`pwd`:$$PATH; \
- export PATH; \
- cd gmpbuild-shared && \
- CC=$(WhatGccIsCalled) $(SHELL) configure \
- --enable-shared=yes --disable-static --host=$(PLATFORM) --build=$(PLATFORM)
- touch $@
-
-gmp.h: stamp.gmp.static
- $(CP) gmpbuild/gmp.h .
-
-libgmp.a: stamp.gmp.static
- $(MAKE) -C gmpbuild MAKEFLAGS=
- $(CP) gmpbuild/.libs/libgmp.a .
- $(RANLIB) libgmp.a
-
-libgmp-3.dll: stamp.gmp.shared
- $(MAKE) -C gmpbuild-shared MAKEFLAGS=
- $(CP) gmpbuild-shared/.libs/libgmp-3.dll .
-
-libgmp.dll.a: libgmp-3.dll
- $(CP) gmpbuild-shared/.libs/libgmp.dll.a .
-endif
-endif
-
-# GMP takes a long time to build, but changes rarely. Hence we don't
-# bother cleaning it before validating, because that adds a
-# significant overhead to validation.
-ifeq "$(Validating)" "NO"
-clean distclean maintainer-clean ::
- $(RM) -f stamp.gmp.static stamp.gmp.shared
- $(RM) -rf gmpbuild
- $(RM) -rf gmpbuild-shared
-endif
-
-#-----------------------------------------------------------------------------
-#
-# binary-dist
-
-include $(TOP)/mk/target.mk
-
-BINDIST_EXTRAS += $(BINDIST_STAMPS)
-BINDIST_EXTRAS += $(INSTALL_PROGS)
-BINDIST_EXTRAS += $(INSTALL_LIBS)
-BINDIST_EXTRAS += $(INSTALL_HEADERS)
-include $(TOP)/mk/bindist.mk
-
diff --git a/gmp/ghc.mk b/gmp/ghc.mk
new file mode 100644
index 0000000000..1a71e17878
--- /dev/null
+++ b/gmp/ghc.mk
@@ -0,0 +1,124 @@
+
+# Compile GMP only if we don't have it already
+#
+# We use GMP's own configuration stuff, because it's all rather hairy
+# and not worth re-implementing in our Makefile framework.
+
+ifeq "$(findstring dyn, $(GhcRTSWays))" "dyn"
+BUILD_SHARED=yes
+else
+BUILD_SHARED=no
+endif
+
+# In a bindist, we don't want to know whether /this/ machine has gmp,
+# but whether the machine the bindist was built on had gmp.
+ifeq "$(BINDIST)" "YES"
+ifeq "$(wildcard gmp/libgmp.a)" ""
+HaveLibGmp = YES
+HaveFrameworkGMP = YES
+else
+HaveLibGmp = NO
+HaveFrameworkGMP = NO
+endif
+endif
+
+ifneq "$(HaveLibGmp)" "YES"
+ifneq "$(HaveFrameworkGMP)" "YES"
+
+INSTALL_LIBS += gmp/libgmp.a
+
+$(eval $(call all-target,gmp_dynamic,gmp/libgmp.a))
+
+ifeq "$(BUILD_SHARED)" "yes"
+$(eval $(call all-target,gmp_dynamic,gmp/libgmp.dll.a gmp/libgmp-3.dll))
+endif
+
+endif
+endif
+
+PLATFORM := $(shell echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g')
+
+# 2007-09-26
+# set -o igncr
+# is not a valid command on non-Cygwin-systems.
+# Let it fail silently instead of aborting the build.
+#
+# 2007-07-05
+# We do
+# set -o igncr; export SHELLOPTS
+# here as otherwise checking the size of limbs
+# makes the build fall over on Cygwin. See the thread
+# http://www.cygwin.com/ml/cygwin/2006-12/msg00011.html
+# for more details.
+
+# 2007-07-05
+# Passing
+# as_ln_s='cp -p'
+# isn't sufficient to stop cygwin using symlinks the mingw gcc can't
+# follow, as it isn't used consistently. Instead we put an ln.bat in
+# path that always fails.
+
+# We use a tarball like gmp-4.2.4-nodoc.tar.bz2, which is
+# gmp-4.2.4.tar.bz2 repacked without the doc/ directory contents.
+# That's because the doc/ directory contents are under the GFDL,
+# which causes problems for Debian.
+
+GMP_TARBALL := $(wildcard gmp/tarball/gmp*.tar.bz2)
+GMP_DIR := $(patsubst gmp/tarball/%-nodoc.tar.bz2,%,$(GMP_TARBALL))
+
+# XXX INSTALL_HEADERS += gmp.h
+
+gmp/libgmp.a:
+ $(RM) -rf $(GMP_DIR) gmp/gmpbuild
+ cd gmp && $(TAR) -jxf ../$(GMP_TARBALL)
+ mv gmp/$(GMP_DIR) gmp/gmpbuild
+ chmod +x gmp/ln
+ cd gmp; (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
+ PATH=`pwd`:$$PATH; \
+ export PATH; \
+ cd gmpbuild && \
+ CC=$(WhatGccIsCalled) $(SHELL) configure \
+ --enable-shared=no --host=$(PLATFORM) --build=$(PLATFORM)
+ $(MAKE) -C gmp/gmpbuild MAKEFLAGS=
+ $(CP) gmp/gmpbuild/.libs/libgmp.a gmp/
+ $(RANLIB) gmp/libgmp.a
+
+$(eval $(call clean-target,gmp,,\
+ gmp/libgmp.a gmp/gmpbuild gmp/$(GMP_DIR)))
+
+# XXX TODO:
+#stamp.gmp.shared:
+# $(RM) -rf $(GMP_DIR) gmpbuild-shared
+# $(TAR) -zxf $(GMP_TARBALL)
+# mv $(GMP_DIR) gmpbuild-shared
+# chmod +x ln
+# (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
+# PATH=`pwd`:$$PATH; \
+# export PATH; \
+# cd gmpbuild-shared && \
+# CC=$(WhatGccIsCalled) $(SHELL) configure \
+# --enable-shared=yes --disable-static --host=$(PLATFORM) --build=$(PLATFORM)
+# touch $@
+#
+#gmp.h: stamp.gmp.static
+# $(CP) gmpbuild/gmp.h .
+#
+#libgmp.a: stamp.gmp.static
+#
+#libgmp-3.dll: stamp.gmp.shared
+# $(MAKE) -C gmpbuild-shared MAKEFLAGS=
+# $(CP) gmpbuild-shared/.libs/libgmp-3.dll .
+#
+#libgmp.dll.a: libgmp-3.dll
+# $(CP) gmpbuild-shared/.libs/libgmp.dll.a .
+
+## GMP takes a long time to build, but changes rarely. Hence we don't
+## bother cleaning it before validating, because that adds a
+## significant overhead to validation.
+#ifeq "$(Validating)" "NO"
+#clean distclean maintainer-clean ::
+# $(RM) -f stamp.gmp.static stamp.gmp.shared
+# $(RM) -rf gmpbuild
+# $(RM) -rf gmpbuild-shared
+#endif
+
diff --git a/gmp/gmp-4.2.1-nodoc.tar.gz b/gmp/gmp-4.2.1-nodoc.tar.gz
deleted file mode 100644
index 71aa688458..0000000000
--- a/gmp/gmp-4.2.1-nodoc.tar.gz
+++ /dev/null
Binary files differ
diff --git a/gmp/tarball/gmp-4.2.4-nodoc.tar.bz2 b/gmp/tarball/gmp-4.2.4-nodoc.tar.bz2
new file mode 100644
index 0000000000..acd74824b9
--- /dev/null
+++ b/gmp/tarball/gmp-4.2.4-nodoc.tar.bz2
Binary files differ
diff --git a/includes/Makefile b/includes/Makefile
index a0923c3b53..bce3937dbf 100644
--- a/includes/Makefile
+++ b/includes/Makefile
@@ -1,202 +1,3 @@
-# -----------------------------------------------------------------------------
-
-TOP = ..
-include $(TOP)/mk/boilerplate.mk
-
-#
-# Header files built from the configure script's findings
-#
-H_CONFIG = ghcautoconf.h
-H_PLATFORM = ghcplatform.h
-
-#
-# All header files
-#
-H_FILES = $(filter-out $(H_CONFIG) $(H_PLATFORM),$(wildcard *.h))
-
-ifneq "$(DOING_BIN_DIST)" "YES"
-
-#
-# Options
-#
-ifeq "$(GhcUnregisterised)" "YES"
-SRC_CC_OPTS += -DNO_REGS -DUSE_MINIINTERPRETER
-endif
-
-ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
-SRC_CC_OPTS += -DTABLES_NEXT_TO_CODE
-endif
-
-SRC_CC_OPTS += -I. -I../rts -I../rts/parallel
-ifeq "$(HaveLibGmp)" "YES"
-ifneq "$(GMP_INCLUDE_DIRS)" ""
-SRC_CC_OPTS += -I$(GMP_INCLUDE_DIRS)
-endif
-else
-SRC_CC_OPTS += -I../gmp/gmpbuild
-endif
-
-ifneq "$(GhcWithSMP)" "YES"
-SRC_CC_OPTS += -DNOSMP
-endif
-
-all :: $(H_CONFIG) $(H_PLATFORM)
-
-# The fptools configure script creates the configuration header file and puts it
-# in fptools/mk/config.h. We copy it down to here (without any PACKAGE_FOO
-# definitions to avoid clashes), prepending some make variables specifying cpp
-# platform variables.
-
-ifneq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
-
-$(H_CONFIG) :
- @echo "*** Cross-compiling: please copy $(H_CONFIG) from the target system"
- @exit 1
-
-else
-
-$(H_CONFIG) : $(FPTOOLS_TOP)/mk/config.h $(FPTOOLS_TOP)/mk/config.mk
-
-$(H_CONFIG) : Makefile
- @echo "Creating $@..."
- @echo "#ifndef __GHCAUTOCONF_H__" >$@
- @echo "#define __GHCAUTOCONF_H__" >>$@
-# Turn '#define PACKAGE_FOO "blah"' into '/* #undef PACKAGE_FOO */'.
- @sed 's,^\([ ]*\)#[ ]*define[ ][ ]*\(PACKAGE_[A-Z]*\)[ ][ ]*".*".*$$,\1/* #undef \2 */,' $(FPTOOLS_TOP)/mk/config.h >> $@
- @echo "#endif /* __GHCAUTOCONF_H__ */" >> $@
- @echo "Done."
-
-endif
-
-$(H_PLATFORM) : Makefile
- @echo "Creating $@..."
- @$(RM) $@
- @echo "#ifndef __GHCPLATFORM_H__" >$@
- @echo "#define __GHCPLATFORM_H__" >>$@
- @echo >> $@
- @echo "#define BuildPlatform_TYPE $(HostPlatform_CPP)" >> $@
- @echo "#define HostPlatform_TYPE $(TargetPlatform_CPP)" >> $@
- @echo >> $@
- @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
- @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
- @echo >> $@
- @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
- @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
- @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
- @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
- @echo >> $@
- @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
- @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
- @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
- @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
-ifeq "$(HostOS_CPP)" "irix"
- @echo "#ifndef $(IRIX_MAJOR)_HOST_OS" >> $@
- @echo "#define $(IRIX_MAJOR)_HOST_OS 1" >> $@
- @echo "#endif" >> $@
-endif
- @echo >> $@
- @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
- @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
- @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
- @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
- @echo >> $@
- @echo "/* These TARGET macros are for backwards compatibily... DO NOT USE! */" >> $@
- @echo "#define TargetPlatform_TYPE $(TargetPlatform_CPP)" >> $@
- @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
- @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
- @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
- @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
- @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
- @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
- @echo >> $@
- @echo "#endif /* __GHCPLATFORM_H__ */" >> $@
- @echo "Done."
-
-# ---------------------------------------------------------------------------
-# Make DerivedConstants.h for the compiler
-
-all :: DerivedConstants.h
-
-ifneq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
-
-DerivedConstants.h :
- @echo "*** Cross-compiling: please copy DerivedConstants.h from the target system"
- @exit 1
-
-else
-
-mkDerivedConstants.c : $(H_CONFIG) $(H_PLATFORM)
-
-mkDerivedConstantsHdr : mkDerivedConstants.o
- $(CC) -o $@ $(CC_OPTS) $(LD_OPTS) mkDerivedConstants.o
-
-DerivedConstants.h : mkDerivedConstantsHdr
- ./mkDerivedConstantsHdr >$@
-
-endif
-
-CLEAN_FILES += mkDerivedConstantsHdr$(exeext) DerivedConstants.h
-
-# -----------------------------------------------------------------------------
-#
-
-all :: GHCConstants.h
-
-ifneq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
-
-GHCConstants.h :
- @echo "*** Cross-compiling: please copy DerivedConstants.h from the target system"
- @exit 1
-
-else
-
-mkGHCConstants : mkGHCConstants.o
- $(CC) -o $@ $(CC_OPTS) $(LD_OPTS) mkGHCConstants.o
-
-mkGHCConstants.o : mkDerivedConstants.c
- $(CC) -o $@ $(CC_OPTS) -c $< -DGEN_HASKELL
-
-GHCConstants.h : mkGHCConstants
- ./mkGHCConstants >$@
-
-endif
-
-CLEAN_FILES += mkGHCConstants$(exeext) GHCConstants.h
-
-endif
-
-# ---------------------------------------------------------------------------
-# boot setup:
-#
-#
-# Install all header files
-#
-# Note: we keep per-platform copies of all the include files
-# (ditto for interface files). This is not *really* needed, but
-# it gives (perhaps) a cleaner binary dist structure..might change.
-#
-INSTALL_HEADERS += $(H_FILES) $(H_CONFIG) $(H_PLATFORM)
-
-BINDIST_EXTRAS += $(INSTALL_HEADERS)
-include $(TOP)/mk/bindist.mk
-
-#
-# `make clean' settings:
-#
-CLEAN_FILES += $(H_CONFIG) $(H_PLATFORM)
-
-#
-# Finally, slurp in the standard targets.
-#
-include $(TOP)/mk/target.mk
-
-# We need DerivedConstants.h in order to make dependencies in the RTS
-# sources, so 'make boot' here should behave like 'make all'.
-#
-# However, note that we should do this only *after* 'make boot' has
-# created .depend in here; otherwise an out-of-date .depend file can
-# prevent 'make boot' from working, requiring manual removal of
-# .depend (see #1095). This is why the following target comes *after*
-# target.mk is included above (target.mk contains "boot :: depend").
-#
-boot :: all
+dir = includes
+TOP = ../..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/includes/Regs.h b/includes/Regs.h
index 29c04b302f..c219838ab8 100644
--- a/includes/Regs.h
+++ b/includes/Regs.h
@@ -397,7 +397,7 @@ GLOBAL_REG_DECL(bdescr *,HpAlloc,REG_HpAlloc)
-------------------------------------------------------------------------- */
-#define FunReg ((StgFunTable *)((void *)BaseReg - FIELD_OFFSET(struct PartCapability_, r)))
+#define FunReg ((StgFunTable *)((void *)BaseReg - STG_FIELD_OFFSET(struct PartCapability_, r)))
#define stg_EAGER_BLACKHOLE_info (FunReg->stgEagerBlackholeInfo)
#define stg_gc_enter_1 (FunReg->stgGCEnter1)
diff --git a/includes/Stg.h b/includes/Stg.h
index 394c987f07..2b2095f030 100644
--- a/includes/Stg.h
+++ b/includes/Stg.h
@@ -76,7 +76,7 @@
/* Compute offsets of struct fields
*/
-#define FIELD_OFFSET(s_type, field) ((StgWord)&(((s_type*)0)->field))
+#define STG_FIELD_OFFSET(s_type, field) ((StgWord)&(((s_type*)0)->field))
/*
* 'Portable' inlining:
diff --git a/includes/ghc.mk b/includes/ghc.mk
new file mode 100644
index 0000000000..4e9a59823f
--- /dev/null
+++ b/includes/ghc.mk
@@ -0,0 +1,179 @@
+#
+# Header files built from the configure script's findings
+#
+# XXX: these should go in includes/dist/build?
+includes_H_CONFIG = includes/ghcautoconf.h
+includes_H_PLATFORM = includes/ghcplatform.h
+
+#
+# All header files
+#
+includes_H_FILES = $(filter-out $(includes_H_CONFIG) $(includes_H_PLATFORM),$(wildcard includes/*.h))
+
+#
+# Options
+#
+ifeq "$(GhcUnregisterised)" "YES"
+includes_CC_OPTS += -DNO_REGS -DUSE_MINIINTERPRETER
+endif
+
+ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
+includes_CC_OPTS += -DTABLES_NEXT_TO_CODE
+endif
+
+includes_CC_OPTS += -Iincludes -Irts -Irts/parallel
+ifeq "$(HaveLibGmp)" "YES"
+ifneq "$(GMP_INCLUDE_DIRS)" ""
+includes_CC_OPTS += -I$(GMP_INCLUDE_DIRS)
+endif
+else
+includes_CC_OPTS += -Igmp/gmpbuild
+endif
+
+ifneq "$(GhcWithSMP)" "YES"
+includes_CC_OPTS += -DNOSMP
+endif
+
+# The fptools configure script creates the configuration header file and puts it
+# in fptools/mk/config.h. We copy it down to here (without any PACKAGE_FOO
+# definitions to avoid clashes), prepending some make variables specifying cpp
+# platform variables.
+
+ifneq "$(BINDIST)" "YES"
+
+ifneq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
+
+$(includes_H_CONFIG) :
+ @echo "*** Cross-compiling: please copy $(includes_H_CONFIG) from the target system"
+ @exit 1
+
+else
+
+$(includes_H_CONFIG) : mk/config.h mk/config.mk includes/ghc.mk
+ @echo "Creating $@..."
+ @echo "#ifndef __GHCAUTOCONF_H__" >$@
+ @echo "#define __GHCAUTOCONF_H__" >>$@
+# Turn '#define PACKAGE_FOO "blah"' into '/* #undef PACKAGE_FOO */'.
+ @sed 's,^\([ ]*\)#[ ]*define[ ][ ]*\(PACKAGE_[A-Z]*\)[ ][ ]*".*".*$$,\1/* #undef \2 */,' mk/config.h >> $@
+ @echo "#endif /* __GHCAUTOCONF_H__ */" >> $@
+ @echo "Done."
+
+endif
+
+$(includes_H_PLATFORM) : Makefile
+ $(RM) $@
+ @echo "Creating $@..."
+ @echo "#ifndef __GHCPLATFORM_H__" >$@
+ @echo "#define __GHCPLATFORM_H__" >>$@
+ @echo >> $@
+ @echo "#define BuildPlatform_TYPE $(HostPlatform_CPP)" >> $@
+ @echo "#define HostPlatform_TYPE $(TargetPlatform_CPP)" >> $@
+ @echo >> $@
+ @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
+ @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
+ @echo >> $@
+ @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
+ @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
+ @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
+ @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
+ @echo >> $@
+ @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
+ @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
+ @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
+ @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
+ifeq "$(HostOS_CPP)" "irix"
+ @echo "#ifndef $(IRIX_MAJOR)_HOST_OS" >> $@
+ @echo "#define $(IRIX_MAJOR)_HOST_OS 1" >> $@
+ @echo "#endif" >> $@
+endif
+ @echo >> $@
+ @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
+ @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
+ @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
+ @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
+ @echo >> $@
+ @echo "/* These TARGET macros are for backwards compatibily... DO NOT USE! */" >> $@
+ @echo "#define TargetPlatform_TYPE $(TargetPlatform_CPP)" >> $@
+ @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
+ @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
+ @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
+ @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
+ @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
+ @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
+ @echo >> $@
+ @echo "#endif /* __GHCPLATFORM_H__ */" >> $@
+ @echo "Done."
+
+endif
+
+# ---------------------------------------------------------------------------
+# Make DerivedConstants.h for the compiler
+
+includes_DERIVEDCONSTANTS = includes/DerivedConstants.h
+
+ifneq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
+
+DerivedConstants.h :
+ @echo "*** Cross-compiling: please copy DerivedConstants.h from the target system"
+ @exit 1
+
+else
+
+includes_dist-derivedconstants_C_SRCS = mkDerivedConstants.c
+includes_dist-derivedconstants_PROG = mkDerivedConstants$(exeext)
+
+$(eval $(call build-prog,includes,dist-derivedconstants,0))
+
+$(includes_dist-derivedconstants_depfile) : $(includes_H_CONFIG) $(includes_H_PLATFORM)
+includes/dist-derivedconstants/build/mkDerivedConstants.o : $(includes_H_CONFIG) $(includes_H_PLATFORM)
+
+ifneq "$(BINDIST)" "YES"
+$(includes_DERIVEDCONSTANTS) : $(INPLACE_BIN)/mkDerivedConstants$(exeext)
+ ./$< >$@
+endif
+
+endif
+
+# -----------------------------------------------------------------------------
+#
+
+includes_GHCCONSTANTS = includes/GHCConstants.h
+
+ifneq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
+
+$(includes_GHCCONSTANTS) :
+ @echo "*** Cross-compiling: please copy DerivedConstants.h from the target system"
+ @exit 1
+
+else
+
+includes_dist-ghcconstants_C_SRCS = mkDerivedConstants.c
+includes_dist-ghcconstants_PROG = mkGHCConstants$(exeext)
+includes_dist-ghcconstants_CC_OPTS = -DGEN_HASKELL
+
+$(eval $(call build-prog,includes,dist-ghcconstants,0))
+
+ifneq "$(BINDIST)" "YES"
+$(includes_dist-ghcconstants_depfile) : $(includes_H_CONFIG) $(includes_H_PLATFORM)
+
+includes/dist-ghcconstants/build/mkDerivedConstants.o : $(includes_H_CONFIG) $(includes_H_PLATFORM)
+
+$(includes_GHCCONSTANTS) : $(INPLACE_BIN)/mkGHCConstants$(exeext)
+ ./$< >$@
+endif
+
+endif
+
+# ---------------------------------------------------------------------------
+# Install all header files
+
+INSTALL_HEADERS += $(includes_H_FILES) $(includes_H_CONFIG) $(includes_H_PLATFORM)
+
+$(eval $(call clean-target,includes,,\
+ $(includes_H_CONFIG) $(includes_H_PLATFORM) \
+ $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS)))
+
+$(eval $(call all-target,includes,,\
+ $(includes_H_CONFIG) $(includes_H_PLATFORM) \
+ $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS)))
+
diff --git a/libffi/Makefile b/libffi/Makefile
index cee5bb95c3..3d6f949584 100644
--- a/libffi/Makefile
+++ b/libffi/Makefile
@@ -1,199 +1,3 @@
-
-TOP=..
-DONT_WANT_STD_GHCI_LIB_RULE=YES
-DONT_WANT_STD_LIBRARY=YES
-
-include $(TOP)/mk/boilerplate.mk
-# Override haddock generation for this package
-HADDOCK_DOCS=NO
-
-# We package libffi as Haskell package for two reasons:
-
-# 1) GHC uses different names for shared and static libs, so it can
-# choose the lib variant to link with on its own. With regular
-# libtool styled shared lib names, the linker would interfer and
-# link against the shared lib variant even when GHC runs in -static
-# mode.
-# 2) The first issue isn't a problem when a shared lib of libffi would
-# be installed in system locations, but we do not assume that. So,
-# when running in -dynamic mode, we must either install libffi to
-# system locations ourselves, or we must add its location to
-# respective environment variable, (DY)LD_LIBRARY_PATH etc...before
-# we call dynamically linked binaries. Especially, the latter is
-# necessary as GHC calls binary it produced before its installation
-# phase. However, both mechanism, installing to system locations or
-# modifying (DY)LD_LIBRARY_PATH, are already in place for Haskell
-# packages so with packaging libffi as Haskell package we reuse
-# them naturally.
-
-PACKAGE=ffi
-# -----------------------------------------------------------------------------
-#
-# We use libffi's own configuration stuff.
-
-PLATFORM := $(shell echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g')
-
-# 2007-09-26
-# set -o igncr
-# is not a valid command on non-Cygwin-systems.
-# Let it fail silently instead of aborting the build.
-#
-# 2007-07-05
-# We do
-# set -o igncr; export SHELLOPTS
-# here as otherwise checking the size of limbs
-# makes the build fall over on Cygwin. See the thread
-# http://www.cygwin.com/ml/cygwin/2006-12/msg00011.html
-# for more details.
-
-# 2007-07-05
-# Passing
-# as_ln_s='cp -p'
-# isn't sufficient to stop cygwin using symlinks the mingw gcc can't
-# follow, as it isn't used consistently. Instead we put an ln.bat in
-# path that always fails.
-
-LIBFFI_TARBALL := $(firstword $(wildcard libffi*.tar.gz))
-LIBFFI_DIR := $(subst .tar.gz,,$(LIBFFI_TARBALL))
-
-BINDIST_STAMPS = stamp.ffi.build stamp.ffi.configure
-
-ifeq "$(BuildSharedLibs)" "YES"
-STAMP_BUILD = stamp.ffi.build-shared
-STAMP_CONFIGURE = stamp.ffi.configure-shared
-else
-STAMP_BUILD = stamp.ffi.build
-STAMP_CONFIGURE = stamp.ffi.configure
-endif
-
-INSTALL_HEADERS += ffi.h
-STATIC_LIB = libffi.a
-INSTALL_LIBS += libHSffi.a libHSffi_p.a HSffi.o
-
-# We have to add the GHC version to the name of our dynamic libs, because
-# they will be residing in the system location along with dynamic libs from
-# other GHC installations.
-
-HS_DYN_LIB_NAME=libHSffi-ghc$(ProjectVersion)$(soext)
-
-ifeq "$(Windows)" "YES"
-DYNAMIC_PROG = $(HS_DYN_LIB_NAME).a
-DYNAMIC_LIBS = $(HS_DYN_LIB_NAME)
-else
-DYNAMIC_PROG =
-DYNAMIC_LIBS = libffi.so libffi.so.5 libffi.so.5.0.7
-endif
-
-ifeq "$(BuildSharedLibs)" "YES"
-EnableShared=yes
-else
-EnableShared=no
-endif
-
-ifeq "$(BuildSharedLibs)" "YES"
-INSTALL_LIBS += $(HS_DYN_LIB_NAME)
-ifeq "$(Windows)" "YES"
-INSTALL_PROGS += $(HS_DYN_LIB_NAME).a
-endif
-endif
-
-install all :: $(INSTALL_HEADERS) $(INSTALL_LIBS) $(INSTALL_PROGS)
-
-# We have to fake a non-working ln for configure, so that the fallback
-# option (cp -p) gets used instead. Otherwise the libffi build system
-# will use cygwin symbolic linkks which cannot be read by mingw gcc.
-# The same trick is played by the GMP build in ../gmp.
-
-$(STAMP_CONFIGURE):
- $(RM) -rf $(LIBFFI_DIR) build
- $(TAR) -zxf $(LIBFFI_TARBALL)
- mv $(LIBFFI_DIR) build
- chmod +x ln
- patch -p0 < libffi-dllize-3.0.6.patch
-
- # This patch is just the resulting delta from running automake, autoreconf, libtoolize --force --copy
- patch -p0 < libffi-autotools-update.patch
-
- (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
- PATH=`pwd`:$$PATH; \
- export PATH; \
- cd build && \
- CC=$(WhatGccIsCalled) $(SHELL) configure \
- --enable-static=yes \
- --enable-shared=$(EnableShared) \
- --host=$(PLATFORM) --build=$(PLATFORM)
-
- # libffi.so needs to be built with the correct soname.
- # NOTE: this builds libffi_convience.so with the incorrect
- # soname, but we don't need that anyway!
- $(CP) build/libtool build/libtool.orig
- sed -e s/soname_spec=.*/soname_spec="$(HS_DYN_LIB_NAME)"/ build/libtool.orig > build/libtool
-
- # We don't want libtool's cygwin hacks
- $(CP) build/libtool build/libtool.orig
- sed -e s/dlname=\'\$$tdlname\'/dlname=\'\$$dlname\'/ build/libtool.orig > build/libtool
-
- touch $@
-
-ffi.h: $(STAMP_CONFIGURE)
- $(CP) build/include/ffi.h .
-
-$(STAMP_BUILD): $(STAMP_CONFIGURE)
- $(MAKE) -C build MAKEFLAGS=
- (cd build; ./libtool --mode=install cp libffi.la $(FPTOOLS_TOP_ABS)/libffi)
- $(CP) $(STATIC_LIB) libHSffi.a
- $(CP) $(STATIC_LIB) libHSffi_p.a
- touch $@
-
-libHSffi.a libHSffi_p.a: $(STAMP_BUILD)
-
-all :: libHSffi.a libHSffi_p.a
-
-# The GHCi import lib isn't needed as compiler/ghci/Linker.lhs + rts/Linker.c
-# link the interpreted references to FFI to the compiled FFI.
-# Instead of adding libffi to the list preloaded packages (see
-# compiler/ghci/Linker.lhs:emptyPLS) we generate an empty HSffi.o
-
-HSffi.o: libHSffi.a
- touch empty.c
- $(CC) -c empty.c -o HSffi.o
-
-all :: HSffi.o
-
-ifeq "$(BuildSharedLibs)" "YES"
-ifeq "$(Windows)" "YES"
-# Windows libtool creates <soname>.dll, and as we already patched that
-# there is no need to copy from libffi.dll to libHSffi...dll.
-# However, the renaming is still required for the import library
-# libffi.dll.a.
-$(HS_DYN_LIB_NAME).a: $(STAMP_BUILD)
- $(CP) libffi.dll.a $(HS_DYN_LIB_NAME).a
-all :: $(HS_DYN_LIB_NAME).a
-
-else
-# Rename libffi.so to libHSffi...so
-$(HS_DYN_LIB_NAME): $(DYNAMIC_LIBS)
- $(CP) $(word 1,$(DYNAMIC_LIBS)) $(HS_DYN_LIB_NAME)
-
-all :: $(HS_DYN_LIB_NAME)
-endif
-endif
-
-clean distclean maintainer-clean ::
- $(RM) -f stamp.ffi.* ffi.h empty.c
- $(RM) -f libffi.a libffi.la $(DYNAMIC_PROG) $(DYNAMIC_LIBS) $(HS_DYN_LIB_NAME) $(HS_DYN_LIB_NAME).a
- $(RM) -rf build
-
-#-----------------------------------------------------------------------------
-#
-# binary-dist
-
-include $(TOP)/mk/target.mk
-
-BINDIST_EXTRAS += package.conf.in
-BINDIST_EXTRAS += $(BINDIST_STAMPS)
-BINDIST_EXTRAS += $(INSTALL_PROGS)
-BINDIST_EXTRAS += $(INSTALL_LIBS)
-BINDIST_EXTRAS += $(INSTALL_HEADERS)
-include $(TOP)/mk/bindist.mk
-
+dir = libffi
+TOP = ../..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/libffi/ghc.mk b/libffi/ghc.mk
new file mode 100644
index 0000000000..eca8dd2e11
--- /dev/null
+++ b/libffi/ghc.mk
@@ -0,0 +1,193 @@
+
+# We package libffi as Haskell package for two reasons:
+
+# 1) GHC uses different names for shared and static libs, so it can
+# choose the lib variant to link with on its own. With regular
+# libtool styled shared lib names, the linker would interfer and
+# link against the shared lib variant even when GHC runs in -static
+# mode.
+# 2) The first issue isn't a problem when a shared lib of libffi would
+# be installed in system locations, but we do not assume that. So,
+# when running in -dynamic mode, we must either install libffi to
+# system locations ourselves, or we must add its location to
+# respective environment variable, (DY)LD_LIBRARY_PATH etc...before
+# we call dynamically linked binaries. Especially, the latter is
+# necessary as GHC calls binary it produced before its installation
+# phase. However, both mechanism, installing to system locations or
+# modifying (DY)LD_LIBRARY_PATH, are already in place for Haskell
+# packages so with packaging libffi as Haskell package we reuse
+# them naturally.
+
+# -----------------------------------------------------------------------------
+#
+# We use libffi's own configuration stuff.
+
+PLATFORM := $(shell echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g')
+
+# 2007-09-26
+# set -o igncr
+# is not a valid command on non-Cygwin-systems.
+# Let it fail silently instead of aborting the build.
+#
+# 2007-07-05
+# We do
+# set -o igncr; export SHELLOPTS
+# here as otherwise checking the size of limbs
+# makes the build fall over on Cygwin. See the thread
+# http://www.cygwin.com/ml/cygwin/2006-12/msg00011.html
+# for more details.
+
+# 2007-07-05
+# Passing
+# as_ln_s='cp -p'
+# isn't sufficient to stop cygwin using symlinks the mingw gcc can't
+# follow, as it isn't used consistently. Instead we put an ln.bat in
+# path that always fails.
+
+ifeq "$(BuildSharedLibs)" "YES"
+libffi_STAMP_BUILD = libffi/stamp.ffi.build-shared
+libffi_STAMP_CONFIGURE = libffi/stamp.ffi.configure-shared
+else
+libffi_STAMP_BUILD = libffi/stamp.ffi.build
+libffi_STAMP_CONFIGURE = libffi/stamp.ffi.configure
+endif
+
+BINDIST_STAMPS = libffi/stamp.ffi.build libfii/stamp.ffi.configure
+
+INSTALL_HEADERS += libffi/ffi.h
+libffi_STATIC_LIB = libffi/libffi.a
+INSTALL_LIBS += libffi/libHSffi.a libffi/HSffi.o
+
+# We have to add the GHC version to the name of our dynamic libs, because
+# they will be residing in the system location along with dynamic libs from
+# other GHC installations.
+
+libffi_HS_DYN_LIB_NAME=libHSffi-ghc$(ProjectVersion)$(soext)
+libffi_HS_DYN_LIB_PATH=libffi/$(libffi_HS_DYN_LIB_NAME)
+
+ifeq "$(Windows)" "YES"
+libffi_DYNAMIC_PROG = $(libffi_HS_DYN_LIB_PATH).a
+libffi_DYNAMIC_LIBS = $(libffi_HS_DYN_LIB_PATH)
+else
+libffi_DYNAMIC_PROG =
+libffi_DYNAMIC_LIBS = libffi/libffi.so libffi/libffi.so.5 libffi/libffi.so.5.0.7
+endif
+
+ifeq "$(BuildSharedLibs)" "YES"
+libffi_EnableShared=yes
+else
+libffi_EnableShared=no
+endif
+
+ifeq "$(BuildSharedLibs)" "YES"
+INSTALL_LIBS += $(libffi_HS_DYN_LIB_PATH)
+ifeq "$(Windows)" "YES"
+INSTALL_PROGS += $(libffi_HS_DYN_LIB_PATH).a
+endif
+endif
+
+# We have to fake a non-working ln for configure, so that the fallback
+# option (cp -p) gets used instead. Otherwise the libffi build system
+# will use cygwin symbolic linkks which cannot be read by mingw gcc.
+# The same trick is played by the GMP build in ../gmp.
+
+ifneq "$(BINDIST)" "YES"
+$(libffi_STAMP_CONFIGURE):
+ $(RM) -rf $(LIBFFI_DIR) libffi/build
+ cd libffi && $(TAR) -zxf tarball/libffi*.tar.gz
+ mv libffi/libffi-* libffi/build
+ chmod +x libffi/ln
+ cd libffi && $(PATCH) -p0 < libffi.dllize-3.0.6.patch
+
+ # This patch is just the resulting delta from running automake, autoreconf, libtoolize --force --copy
+ cd libffi && $(PATCH) -p0 < libffi.autotools-update.patch
+
+ cd libffi && \
+ (set -o igncr 2>/dev/null) && set -o igncr; export SHELLOPTS; \
+ PATH=`pwd`:$$PATH; \
+ export PATH; \
+ cd build && \
+ CC=$(WhatGccIsCalled) $(SHELL) configure \
+ --enable-static=yes \
+ --enable-shared=$(libffi_EnableShared) \
+ --host=$(PLATFORM) --build=$(PLATFORM)
+
+ # libffi.so needs to be built with the correct soname.
+ # NOTE: this builds libffi_convience.so with the incorrect
+ # soname, but we don't need that anyway!
+ cd libffi && \
+ $(CP) build/libtool build/libtool.orig; \
+ sed -e s/soname_spec=.*/soname_spec="$(libffi_HS_DYN_LIB_NAME)"/ build/libtool.orig > build/libtool
+
+ # We don't want libtool's cygwin hacks
+ cd libffi && \
+ $(CP) build/libtool build/libtool.orig; \
+ sed -e s/dlname=\'\$$tdlname\'/dlname=\'\$$dlname\'/ build/libtool.orig > build/libtool
+
+ touch $@
+
+libffi/ffi.h: $(libffi_STAMP_CONFIGURE)
+ $(CP) libffi/build/include/ffi.h $@
+
+$(libffi_STAMP_BUILD): $(libffi_STAMP_CONFIGURE)
+ cd libffi && \
+ $(MAKE) -C build MAKEFLAGS=; \
+ (cd build; ./libtool --mode=install cp libffi.la $(TOP)/libffi)
+ $(CP) $(libffi_STATIC_LIB) libffi/libHSffi.a
+ $(CP) $(libffi_STATIC_LIB) libffi/libHSffi_p.a
+ touch $@
+
+libffi/libHSffi.a libffi/libHSffi_p.a: $(libffi_STAMP_BUILD)
+
+all_libffi : libffi/libHSffi.a libffi/libHSffi_p.a
+
+# The GHCi import lib isn't needed as compiler/ghci/Linker.lhs + rts/Linker.c
+# link the interpreted references to FFI to the compiled FFI.
+# Instead of adding libffi to the list preloaded packages (see
+# compiler/ghci/Linker.lhs:emptyPLS) we generate an empty HSffi.o
+
+libffi/HSffi.o: libffi/libHSffi.a
+ cd libffi && \
+ touch empty.c; \
+ $(CC) -c empty.c -o HSffi.o
+
+all_libffi : libffi/HSffi.o
+
+ifeq "$(BuildSharedLibs)" "YES"
+ifeq "$(Windows)" "YES"
+# Windows libtool creates <soname>.dll, and as we already patched that
+# there is no need to copy from libffi.dll to libHSffi...dll.
+# However, the renaming is still required for the import library
+# libffi.dll.a.
+$(libffi_HS_DYN_LIB_PATH).a: $(libffi_STAMP_BUILD)
+ $(CP) libffi/libffi.dll.a $(libffi_HS_DYN_LIB_PATH).a
+all_libffi : $(libffi_HS_DYN_LIB_PATH).a
+
+else
+# Rename libffi.so to libHSffi...so
+$(libffi_HS_DYN_LIB_PATH): $(libffi_DYNAMIC_LIBS)
+ $(CP) $(word 1,$(libffi_DYNAMIC_LIBS)) $(libffi_HS_DYN_LIB_PATH)
+
+all_libffi : $(libffi_HS_DYN_LIB_PATH)
+endif
+endif
+
+$(eval $(call clean-target,libffi,, \
+ libffi/build libffi/stamp.ffi.* libffi/ffi.h libffi/empty.c \
+ libffi/libffi.a libffi/libffi.la \
+ libffi/HSffi.o libffi/libHSffi.a libffi/libHSffi_p.a \
+ $(libffi_DYNAMIC_PROG) $(libffi_DYNAMIC_LIBS) \
+ $(libffi_HS_DYN_LIB_NAME) $(libffi_HS_DYN_LIB_NAME).a))
+endif
+
+#-----------------------------------------------------------------------------
+# Do the package config
+
+$(eval $(call manual-package-config,libffi))
+
+#-----------------------------------------------------------------------------
+#
+# binary-dist
+
+BINDIST_EXTRAS += libffi/package.conf.in
+
diff --git a/libffi/libffi-autotools-update.patch b/libffi/libffi.autotools-update.patch
index dd9d9c97c9..dd9d9c97c9 100644
--- a/libffi/libffi-autotools-update.patch
+++ b/libffi/libffi.autotools-update.patch
diff --git a/libffi/libffi-dllize-3.0.6.patch b/libffi/libffi.dllize-3.0.6.patch
index 6a19f1119d..6a19f1119d 100644
--- a/libffi/libffi-dllize-3.0.6.patch
+++ b/libffi/libffi.dllize-3.0.6.patch
diff --git a/libffi/package.conf.in b/libffi/package.conf.in
index afb3737f0c..eea9c401d5 100644
--- a/libffi/package.conf.in
+++ b/libffi/package.conf.in
@@ -1,4 +1,4 @@
-name: PACKAGE
+name: ffi
version: 1.0
license: BSD3
maintainer: glasgow-haskell-users@haskell.org
@@ -11,7 +11,7 @@ import-dirs:
#ifdef INSTALLING
library-dirs: LIB_DIR
#else /* !INSTALLING */
-library-dirs: FPTOOLS_TOP_ABS"/libffi"
+library-dirs: TOP"/libffi"
#endif
hs-libraries: "HSffi"
@@ -19,7 +19,7 @@ hs-libraries: "HSffi"
#ifdef INSTALLING
include-dirs: INCLUDE_DIR
#else /* !INSTALLING */
-include-dirs: FPTOOLS_TOP_ABS"/libffi/build/include"
+include-dirs: TOP"/libffi/build/include"
#endif
depends:
diff --git a/libffi/libffi-3.0.6.tar.gz b/libffi/tarball/libffi-3.0.6.tar.gz
index dd7ffc47f8..dd7ffc47f8 100644
--- a/libffi/libffi-3.0.6.tar.gz
+++ b/libffi/tarball/libffi-3.0.6.tar.gz
Binary files differ
diff --git a/libraries/Makefile b/libraries/Makefile
deleted file mode 100644
index c32c1f6152..0000000000
--- a/libraries/Makefile
+++ /dev/null
@@ -1,441 +0,0 @@
-
-# To do a fresh build:
-#
-# make clean
-# make boot
-# make
-#
-# To rebuild a particular library <package>:
-#
-# make clean.library.<package>
-# make make.library.<package>
-#
-# or the following is equivalent:
-#
-# make remake.library.<package>
-#
-# To add a new library to the tree, do
-#
-# darcs get http://darcs.haskell.org/packages/foo
-# [ -f foo/configure.ac ] && ( cd foo && autoreconf )
-# make make.library.foo
-
-.PHONY: default_target
-
-default_target: all
-
-# make doesn't give us an easy way to get the libraries built in
-# dependency order the first time, but not rebuild base (for example)
-# when we want to rebuild another library later.
-# So for now we just don't do anything in parallel in here.
-.NOTPARALLEL:
-
-# Ideally we'd just include something to give us variables
-# for paths and arguments to tools etc, and those set in mk/build.mk.
-TOP=..
-include $(TOP)/mk/boilerplate.mk
-include $(TOP)/mk/cabal-flags.mk
-
-ifeq "$(stage)" ""
-stage := 1
-endif
-
-DO_STAGE_1_LIBS := NO
-DO_STAGE_2_LIBS := NO
-ifeq "$(stage)" "1"
-DO_STAGE_1_LIBS := YES
-endif
-ifeq "$(stage)" "2"
-DO_STAGE_2_LIBS := YES
-endif
-ifneq "$(filter install clean maintainer-clean distclean binary-dist,$(MAKECMDGOALS))" ""
-DO_STAGE_1_LIBS := YES
-DO_STAGE_2_LIBS := YES
-endif
-
-# Any libraries listed here should also be in ../packages
-
-SUBDIRS :=
-
-ifeq "$(DO_STAGE_1_LIBS)" "YES"
-SUBDIRS += ghc-prim $(INTEGER_LIBRARY) base syb base3-compat array packedstring
-SUBDIRS += containers bytestring old-locale old-time filepath
-ifeq "$(GhcLibsWithUnix)" "YES"
-SUBDIRS += unix
-endif
-ifeq "$(Windows)" "YES"
-SUBDIRS += $(wildcard Win32)
-endif
-SUBDIRS += directory process pretty hpc template-haskell editline Cabal random haskell98
-
-# Set GhcBootLibs=YES from the command line to work with just the libraries
-# needed to bootstrap GHC.
-ifneq "$(GhcBootLibs)" "YES"
-SUBDIRS += $(wildcard regex-base)
-SUBDIRS += $(wildcard regex-posix)
-SUBDIRS += $(wildcard regex-compat)
-SUBDIRS += $(wildcard parsec)
-SUBDIRS += $(wildcard haskell-src)
-SUBDIRS += $(wildcard html)
-SUBDIRS += $(wildcard network)
-SUBDIRS += $(wildcard QuickCheck)
-SUBDIRS += $(wildcard HUnit)
-SUBDIRS += $(wildcard mtl)
-SUBDIRS += $(wildcard time)
-SUBDIRS += $(wildcard stm)
-SUBDIRS += $(wildcard xhtml)
-SUBDIRS += $(wildcard parallel)
-endif
-endif
-
-DPH_SUBDIRS :=
-ifneq "$(GhcBootLibs)" "YES"
-ifneq "$(wildcard dph)" ""
-DPH_SUBDIRS += dph/dph-base
-DPH_SUBDIRS += dph/dph-prim-interface
-DPH_SUBDIRS += dph/dph-prim-seq
-DPH_SUBDIRS += dph/dph-prim-par
-DPH_SUBDIRS += dph/dph-seq
-DPH_SUBDIRS += dph/dph-par
-endif
-endif
-
-# We have a separate variable for cleaning as this happens in stage=1 and
-# we want to clean the dph subdirectories, too.
-ifeq "$(DO_STAGE_2_LIBS)" "YES"
-SUBDIRS += $(DPH_SUBDIRS)
-CLEAN_SUBDIRS = $(SUBDIRS)
-else
-CLEAN_SUBDIRS = $(SUBDIRS) $(DPH_SUBDIRS)
-endif
-
-# -----------------------------------------------------------------------------
-
-empty=
-space=$(empty) $(empty)
-
-# -----------------------------------------------------------------------------
-
-ifeq "$(ghc_ge_609)" "YES"
-GhcLibHcOpts += -fno-warn-deprecated-flags
-endif
-
-IFBUILDABLE=ifBuildable/ifBuildable $(FPTOOLS_TOP_ABS)/packages
-
-ifneq "$(DOING_BIN_DIST)" "YES"
-
-CONFIGURE_OPTS =
-CONFIGURE_STAMP_EXTRAS :=
-
-ifneq "$(findstring $(space)p$(space), $(space)$(GhcLibWays)$(space))" ""
-CONFIGURE_OPTS += --enable-library-profiling
-CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-profiling
-endif
-
-ifeq "$(BuildSharedLibs)" "YES"
-CONFIGURE_OPTS += --enable-shared
-CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-shared
-endif
-
-ifeq "$(SplitObjs)" "YES"
-CONFIGURE_OPTS += --enable-split-objs
-CONFIGURE_STAMP_EXTRAS := $(CONFIGURE_STAMP_EXTRAS)-splitting
-endif
-
-.PHONY: subdirs
-
-subdirs:
- @echo $(SUBDIRS)
-
-HERE_ABS=$(FPTOOLS_TOP_ABS)/libraries
-
-CABAL_GHC_FLAGS = -Wall
-
-BOOTSTRAPPING_FLAGS = $(CABAL_GHC_FLAGS) -DCABAL_VERSION=$(CABAL_VERSION) -odir $(HERE_ABS)/bootstrapping -hidir $(HERE_ABS)/bootstrapping -i$(HERE_ABS)/Cabal -i$(HERE_ABS)/filepath -i$(HERE_ABS)/hpc
-
-.PHONY: boot
-
-boot: ifBuildable/ifBuildable cabal-bin bootstrapping.conf
-
-cabal-bin: cabal-bin.hs
- -mkdir bootstrapping
- $(GHC) $(BOOTSTRAPPING_FLAGS) --make cabal-bin -o cabal-bin
-
-bootstrapping.conf: cabal-bin
- echo "[]" > $@.tmp
- -cd extensible-exceptions && $(CABAL) clean --distpref=dist-bootstrapping
- cd extensible-exceptions && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
- cd extensible-exceptions && $(CABAL) build --distpref=dist-bootstrapping
- cd extensible-exceptions && $(CABAL) install --distpref=dist-bootstrapping --inplace
- -cd filepath && $(CABAL) clean --distpref=dist-bootstrapping
- cd filepath && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
- cd filepath && $(CABAL) build --distpref=dist-bootstrapping
- cd filepath && $(CABAL) install --distpref=dist-bootstrapping --inplace
- -cd Cabal && $(CABAL) clean --distpref=dist-bootstrapping
- cd Cabal && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
- cd Cabal && $(CABAL) build --distpref=dist-bootstrapping
- cd Cabal && $(CABAL) install --distpref=dist-bootstrapping --inplace
- -cd hpc && $(CABAL) clean --distpref=dist-bootstrapping
- cd hpc && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
- cd hpc && $(CABAL) build --distpref=dist-bootstrapping
- cd hpc && $(CABAL) install --distpref=dist-bootstrapping --inplace
- mv $@.tmp $@
-
-ifBuildable/ifBuildable: ifBuildable.hs
- -$(RM) -rf ifBuildable
- mkdir ifBuildable
- $(CP) ifBuildable.hs ifBuildable/
-ifeq "$(stage)" "2"
- cd ifBuildable && ../$(HC) -Wall --make ifBuildable -o ifBuildable
-else
- cd ifBuildable && $(GHC) -Wall --make ifBuildable -o ifBuildable
-endif
-
-.PHONY: all build configure
-
-all: build
-
-.PHONY: rebuild.library.%
-.PHONY: remake.library.%
-
-$(foreach SUBDIR,$(SUBDIRS),rebuild.library.$(SUBDIR)):\
-rebuild.library.%: clean.library.% build.library.%
-
-$(foreach SUBDIR,$(SUBDIRS),remake.library.$(SUBDIR)):\
-remake.library.%: clean.library.% make.library.%
-
-# The meta package dph is a special case
-ifeq "$(stage)" "1"
-remake.library.dph:
- @echo "*** Package dph needs to be made in stage=2"
-endif
-ifeq "$(stage)" "2"
-# NB. we're depending on make chasing dependencies from left to right here.
-# This bit goes wrong with 'make -j'.
-remake.library.dph: remake.library.dph/dph-base \
- remake.library.dph/dph-prim-interface \
- remake.library.dph/dph-prim-seq \
- remake.library.dph/dph-prim-par \
- remake.library.dph/dph-seq \
- remake.library.dph/dph-par
-endif
-
-# NB. we're depending on make chasing dependencies from left to right here.
-# This bit goes wrong with 'make -j'.
-build: $(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR))
-
-configure: $(foreach SUBDIR,$(SUBDIRS), \
- stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR))
-
-.PHONY: build.library.%
-.PHONY: make.library.%
-
-# We should depend on %/%.cabal here (and in other rules), but make
-# makes that difficult.
-
-ALL_CONFIGURE_FLAGS = \
- $(INSTALL_DIRS_CONFIGURE_FLAGS) \
- $(USE_STAGE$(stage)_CONFIGURE_FLAGS) \
- $(COMMON_CONFIGURE_FLAGS) \
- --haddock-options="--use-contents=../index.html \
- --use-index=../doc-index.html" \
- $(CONFIGURE_OPTS)
-
-stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).dph/dph-par: \
- dph/dph-par
-
-stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).dph/dph-seq: \
- dph/dph-seq
-
-dph/%:
- $(MAKE) -C dph $*
-
-$(foreach SUBDIR,$(SUBDIRS), \
- stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).$(SUBDIR)): \
-stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: cabal-bin
- -$(RM) -f stamp/configure.library.*.$* $*/unbuildable
- $(MKDIRHIER) `dirname $@`
- ( cd $* && $(CABAL) configure $(ALL_CONFIGURE_FLAGS) ) \
- && touch $@ || touch $*/unbuildable
-# We don't touch $@ if configure failed as we would prefer to try
-# configuring it next time round, rather than assuming it'll still fail.
-# This is particularly important for bootlibs, where failure means the
-# build dies!
-
-# Build the library using 'make'
-# We re-run 'setup makefile' each time, just in case any preprocessing
-# needs to be done. However, we're careful not to overwrite GNUmakefile
-# if it hasn't changed, so that dependency-generation isn't forced
-# every time.
-$(foreach SUBDIR,$(SUBDIRS),make.library.$(SUBDIR)):\
-make.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
- cabal-bin ifBuildable/ifBuildable
- if $(IFBUILDABLE) $*; then \
- cd $* && \
- cmp -s $(MAKEFILE_LOCAL) Makefile.local || cp $(MAKEFILE_LOCAL) .; \
- mv GNUmakefile GNUmakefile.tmp; \
- $(CABAL) makefile -f GNUmakefile; \
- cmp -s GNUmakefile GNUmakefile.tmp && mv GNUmakefile.tmp GNUmakefile; \
- $(MAKE) $(MFLAGS) && \
- $(CABAL) register --inplace; \
- fi
-
-# Special case for meta package dph: we can only remake it as we don't have
-# any dependency info between the sub-packages
-make.library.dph:
- @echo "*** Please use the target 'remake.library.dph' instead"
-
-MAKEFILE_LOCAL = $(FPTOOLS_TOP_ABS)/libraries/Makefile.local
-
-# Build the library using 'setup build' (not the default)
-$(foreach SUBDIR,$(SUBDIRS),build.library.$(SUBDIR)):\
-build.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
- cabal-bin ifBuildable/ifBuildable
- if $(IFBUILDABLE) $*; then \
- cd $* && \
- $(CABAL) build $(BUILD_FLAGS); \
- $(CABAL) register --inplace; \
- fi
-
-.PHONY: doc html
-
-html: doc
-
-# No docs for compat libraries for now.
-DOC_SUBDIRS = $(filter-out %-compat, $(SUBDIRS))
-
-doc: $(foreach SUBDIR,$(DOC_SUBDIRS),doc.library.$(SUBDIR))
- sh gen_contents_index --inplace
-
-# Making hyperlinked source only works if we have hscolour
-ifeq "$(HSCOLOUR_SRCS)" "YES"
-CABAL_HADDOCK_FLAGS += --hyperlink-source
-endif
-CABAL_HADDOCK_FLAGS += --with-haddock=$(FPTOOLS_TOP_ABS)/utils/haddock/install-inplace/bin/haddock
-
-$(foreach SUBDIR,$(DOC_SUBDIRS),doc.library.$(SUBDIR)):\
-doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \
- cabal-bin ifBuildable/ifBuildable
- if $(IFBUILDABLE) $*; then \
- cd $* && $(CABAL) haddock --html-location='../$$pkg' \
- $(CABAL_HADDOCK_FLAGS); \
- fi
-ifneq "$(HSCOLOUR)" ""
-# We use */src rather than $*/src due to the $(INTEGER_LIBRARY)/integer
-# mismatch
-# XXX We also need to check that the directory exists, as e.g. dph disables
-# haddock, so the directory doesn't get made. We should remove this once
-# we can always haddock everything.
- if $(IFBUILDABLE) $* && [ -d $*/dist/doc/html/*/src/ ]; then cp hscolour.css $*/dist/doc/html/*/src/; fi
-endif
-
-.PHONY: maintainer-clean distclean clean clean.library.%
-
-maintainer-clean: clean
-distclean: clean
-
-ifeq "$(DPH_SUBDIRS)" ""
-clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
-else
-clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR)) clean.library.dph
-endif
- -cd extensible-exceptions && $(CABAL) clean --distpref=dist-bootstrapping
- -cd filepath && $(CABAL) clean --distpref=dist-bootstrapping
- -cd Cabal && $(CABAL) clean --distpref=dist-bootstrapping
- -cd hpc && $(CABAL) clean --distpref=dist-bootstrapping
- $(RM) -rf bootstrapping
- $(RM) -f bootstrapping.conf bootstrapping.conf.old
- $(RM) -f bootstrapping.conf.tmp bootstrapping.conf.tmp.old
- $(RM) -f cabal-bin cabal-bin.exe
- $(RM) -rf ifBuildable
- $(RM) -f libraries.txt index.html doc-index.html doc-index*.html
- $(RM) -f haddock* *.gif
- $(RM) -rf stamp/*
-
-maintainer-clean distclean:
- $(RM) $(foreach lib, $(SUBDIRS), $(lib)/.depend $(lib)/.depend.bak)
-
-$(foreach SUBDIR,$(CLEAN_SUBDIRS),clean.library.$(SUBDIR)): \
-clean.library.%:
- $(RM) -f stamp/configure.library.*.$* $*/unbuildable
- -cd $* && $(CABAL) clean
- $(RM) -f $*/Setup $*/Setup.exe $*/Setup.hi $*/Setup.o
- $(RM) $*/GNUmakefile $*/Makefile.local
-endif
-
-# Extra target to clean all the sub-packages of dph
-clean.library.dph: clean.library.dph/dph-prim-par \
- clean.library.dph/dph-prim-seq \
- clean.library.dph/dph-prim-interface \
- clean.library.dph/dph-base
- $(MAKE) -C dph clean
-
-# -----------------------------------------------------------------------------
-
-.PHONY: install install-docs install.library.%
-
-install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
-ifeq "$(HADDOCK_DOCS)" "YES"
- $(INSTALL_DIR) $(DESTDIR)$(html_installed_root)
- $(INSTALL_DATA) index.html doc-index*.html $(DESTDIR)$(html_installed_root)
- $(INSTALL_SCRIPT) gen_contents_index $(DESTDIR)$(html_installed_root)
- $(INSTALL_DATA) prologue.txt $(DESTDIR)$(html_installed_root)
- # Hacks:
- $(INSTALL_DATA) base/dist/doc/html/*/*.css $(DESTDIR)$(html_installed_root)
- $(INSTALL_DATA) base/dist/doc/html/*/*.js $(DESTDIR)$(html_installed_root)
- $(INSTALL_DATA) base/dist/doc/html/*/*.gif $(DESTDIR)$(html_installed_root)
-endif
-
-# Cabal doesn't let us ask to install docs only, so do nothing here
-install-docs:
- @:
-
-# Ideally this would depend on a stamp/build.library.%, but if it does
-# then we can't change the libraries and then just rerun make.
-# Thus if you install without building then it will just break.
-
-# prefix and (on Windows) htmldir use $topdir when configuring, so we
-# need to tell installPackage the real path to use when installing.
-
-# We also need to pass all the other directories in, as they can be
-# overridden when installing a bindist.
-
-$(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
-install.library.%: ifBuildable/ifBuildable
- if $(IFBUILDABLE) $*; then \
- cd $* && \
- $(INSTALL_PACKAGE) install '$(GHC_PKG_INSTALL_PROG)' '$(DESTDIR)$(datadir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' ; \
- fi
-
-.PHONY: binary-dist binary-dist.library.%
-
-BIN_DIST_LIBDIR=$(BIN_DIST_DIR)/libraries
-
-binary-dist: $(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR))
-ifeq "$(WHERE_AM_I)" ""
- echo "I don't know where I am" >&2
- exit 1
-endif
- echo $(WHERE_AM_I)/Makefile >> $(BIN_DIST_LIST)
-# XXX This needs to be changed: This ifBuildable is built with the
-# bootstrapping compiler, so isn't OS X friendly. It should be made into
-# a Cabal package if we keep it. However, once we drop extralibs we can
-# probably remove it anyway.
- echo $(WHERE_AM_I)/ifBuildable/ifBuildable >> $(BIN_DIST_LIST)
- for FILE in dph/dph-prim-interface/interface/*.h dph/dph/LICENSE; do if [ -f $$FILE ]; then echo $(WHERE_AM_I)/$$FILE >> $(BIN_DIST_LIST); fi; done
-ifeq "$(HADDOCK_DOCS)" "YES"
- for FILE in gen_contents_index prologue.txt index.html doc-index*.html; do echo $(WHERE_AM_I)/$$FILE >> $(BIN_DIST_LIST); done
-endif
-
-$(foreach SUBDIR,$(SUBDIRS),binary-dist.library.$(SUBDIR)): \
-binary-dist.library.%:
- if $(IFBUILDABLE) $*; then \
- $(MAKE) -C $* -f Makefile.local binary-dist BINDIST_EXTRAS="$*.cabal LICENSE $*.buildinfo unbuildable" WHERE_AM_I=$(WHERE_AM_I)/$*; \
- fi
-
-# Ignore some doc targets that we don't support
-# The root recurses into us when these targets are made
-.PHONY: html-no-chunks chm HxS fo dvi ps pdf
-html-no-chunks chm HxS fo dvi ps pdf:
- @:
-
diff --git a/mk/bindist.mk b/mk/bindist.mk
deleted file mode 100644
index c4ef66e290..0000000000
--- a/mk/bindist.mk
+++ /dev/null
@@ -1,45 +0,0 @@
-
-LIB_DIST_DIR = dist
-EXE_DIST_DIR = dist-install
-
-# XXX This is a bit of a mess. Really we should be just asking Cabal
-# what it would install and putting those files in the bindist.
-binary-dist:
-ifeq "$(WHERE_AM_I)" ""
- echo "I don't know where I am" >&2
- exit 1
-endif
- # General bits
- -$(FIND) . -name Makefile -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- -$(FIND) . -name LICENSE -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- # Libraries
- -$(FIND) $(LIB_DIST_DIR)/setup-config -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- -$(FIND) $(LIB_DIST_DIR)/installed-pkg-config -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- -$(FIND) $(LIB_DIST_DIR)/build -name "HS*.o" -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- -$(FIND) $(LIB_DIST_DIR)/build -name "HS*.p_o" -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- -$(FIND) $(LIB_DIST_DIR)/build -name "*.a" -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- -$(FIND) $(LIB_DIST_DIR)/build -name "*.p_a" -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- -$(FIND) $(LIB_DIST_DIR)/build -name "*.hi" -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- -$(FIND) $(LIB_DIST_DIR)/build -name "*.p_hi" -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- -$(FIND) include -name "*.h" -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- # Executables
- -$(FIND) . -name "*.wrapper" -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- -$(FIND) $(EXE_DIST_DIR)/setup-config -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- # We want the executable files, which in theory would be -perm /a+x
- # ("any execute bit is set") but that doesn't work on some solaris
- # and OS X machines, so we use -perm -100 instead ("the user execute
- # bit is set"). In practice, this is extremely unlikely not to be the
- # same set of files.
- -$(FIND) $(EXE_DIST_DIR) -type f -perm -100 -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- # Docs
- # This gives us both docbook docs, and haddock docs
- $(FIND) . -name "*.haddock" -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- $(FIND) . -name "*.html" -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- $(FIND) . -name "*.css" -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- $(FIND) . -name "*.gif" -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- $(FIND) . -name "*.js" -exec echo $(WHERE_AM_I)/{} \; >> $(BIN_DIST_LIST) 2> /dev/null
- # And anything else
-ifneq "$(strip $(BINDIST_EXTRAS))" ""
- for FILE in $(BINDIST_EXTRAS); do if [ -f $$FILE ]; then echo $(WHERE_AM_I)/$$FILE >> $(BIN_DIST_LIST); fi; done
-endif
-
diff --git a/mk/boilerplate.mk b/mk/boilerplate.mk
deleted file mode 100644
index 0e7e752020..0000000000
--- a/mk/boilerplate.mk
+++ /dev/null
@@ -1,82 +0,0 @@
-#################################################################################
-#
-# mk/boilerplate.mk
-#
-# The Glorious GHC Boilerplate Makefile
-#
-# This one file should be included (directly or indirectly) by all Makefiles
-# in the GHC hierarchy.
-#
-#################################################################################
-
-# We want to disable all the built-in rules that make uses; having them
-# just slows things down, and we write all the rules ourselves.
-# Setting .SUFFIXES to empty disables them all.
-MAKEFLAGS += --no-builtin-rules
-
-# $(FPTOOLS_TOP) is the old name for $(TOP), kept for backwards compat
-FPTOOLS_TOP := $(TOP)
-
-
-# This rule makes sure that "all" is the default target, regardless of where it appears
-# THIS RULE MUST REMAIN FIRST!
-default: all
-
-#------------------------------------------------------------
-# Makefile debugging
-# to see the effective value used for a Makefile variable, do
-# make show VALUE=MY_VALUE
-#
-
-show:
- @echo '$(VALUE)="$($(VALUE))"'
-
-# -----------------------------------------------------------------------------
-# Misc bits
-
-# If $(way) is set then we define $(way_) and $(_way) from it in the
-# obvious fashion. This must be done before suffix.mk is included,
-# because the pattern rules in that file depend on these variables.
-
-ifneq "$(way)" ""
- way_ := $(way)_
- _way := _$(way)
-endif
-
-
-# When using $(patsubst ...) and friends, you can't use a literal comma
-# freely - so we use ${comma} instead. (See PACKAGE_CPP_OPTS in package.mk
-# for an example usage.)
-comma=,
-
-# -----------------------------------------------------------------------------
-# Now follow the pieces of boilerplate
-# The "-" signs tell make not to complain if they don't exist
-
-include $(TOP)/mk/config.mk
-# All configuration information
-# (generated by "configure" from config.mk.in)
-#
-
-
-include $(TOP)/mk/paths.mk
-# Variables that say where things belong (e.g install directories)
-# and where we are right now
-# Also defines variables for standard files (SRCS, LIBS etc)
-
-
-include $(TOP)/mk/opts.mk
-# Variables that control the option flags for all the
-# language processors
-
-ifeq "$(BootingFromHc)" "YES"
-include $(TOP)/mk/bootstrap.mk
-endif
-
-# (Optional) build-specific configuration
-include $(TOP)/mk/custom-settings.mk
-
-ifndef FAST
--include .depend
-endif
-# The dependencies file from the current directory
diff --git a/mk/build.mk.sample b/mk/build.mk.sample
index 911f5025ec..7368a22224 100644
--- a/mk/build.mk.sample
+++ b/mk/build.mk.sample
@@ -25,6 +25,8 @@
# Which warnings we like to use
MyWarningOpts = -W -fno-warn-unused-matches -fwarn-unused-imports
+GhcLibWays = v
+
# -------- 1. A Performance/Distribution build--------------------------------
ifeq "$(BuildFlavour)" "perf"
@@ -36,7 +38,7 @@ GhcStage1HcOpts = -O -fasm
GhcStage2HcOpts = -O2 -fasm
GhcHcOpts = -Rghc-timing
GhcLibHcOpts = -O2 -XGenerics
-GhcLibWays = p
+GhcLibWays += p
endif
@@ -48,7 +50,6 @@ SRC_HC_OPTS = -H64m -O0 -fasm
GhcStage1HcOpts = -O -fasm
GhcStage2HcOpts = -O0 -fasm
GhcLibHcOpts = -O0 -fasm
-GhcLibWays =
SplitObjs = NO
endif
@@ -61,7 +62,6 @@ SRC_HC_OPTS = -H64m -O0 -fasm
GhcStage1HcOpts = -O -fasm
GhcStage2HcOpts = -O0 -fasm
GhcLibHcOpts = -O -fasm
-GhcLibWays =
SplitObjs = NO
endif
@@ -72,7 +72,6 @@ ifeq "$(BuildFlavour)" "devel1"
SRC_HC_OPTS = -H64m -O -fasm $(MyWarningOpts)
GhcLibHcOpts = -O -dcore-lint $(MyWarningOpts)
-GhcLibWays =
GhcStage1HcOpts = -Rghc-timing -O0 -DDEBUG
GhcStage2HcOpts = -Rghc-timing -O -fasm
SplitObjs = NO
@@ -85,7 +84,6 @@ ifeq "$(BuildFlavour)" "devel2"
SRC_HC_OPTS = -H64m -O -fasm $(MyWarningOpts)
GhcLibHcOpts = -O -dcore-lint $(MyWarningOpts)
-GhcLibWays =
GhcStage1HcOpts = -Rghc-timing -O -fasm
GhcStage2HcOpts = -Rghc-timing -O0 -DDEBUG
SplitObjs = NO
diff --git a/mk/cabal-flags.mk b/mk/cabal-flags.mk
deleted file mode 100644
index 253a1e3f1f..0000000000
--- a/mk/cabal-flags.mk
+++ /dev/null
@@ -1,129 +0,0 @@
-
-nothing=
-space=$(nothing) $(nothing)
-comma=,
-
-GHC_PKG_INSTALL_PROG = $(FPTOOLS_TOP_ABS)/utils/ghc-pkg/dist-install/build/ghc-pkg/ghc-pkg
-
-LIBRARIES_ABS = $(FPTOOLS_TOP_ABS)/libraries
-UTILS_ABS = $(FPTOOLS_TOP_ABS)/utils
-CABAL = $(LIBRARIES_ABS)/cabal-bin $(GHC) $(LIBRARIES_ABS)/bootstrapping.conf $(CABAL_DOTTED_VERSION)
-INSTALL_PACKAGE = \
- $(UTILS_ABS)/installPackage/install-inplace/bin/installPackage
-STAGE3_PACKAGE_CONF = $(FPTOOLS_TOP_ABS)/stage3.package.conf
-
-# Euch, hideous hack:
-CABAL_DOTTED_VERSION = $(shell grep "^Version:" $(LIBRARIES_ABS)/Cabal/Cabal.cabal | sed "s/^Version: //")
-CABAL_VERSION = $(subst .,$(comma),$(CABAL_DOTTED_VERSION))
-CABAL_CONSTRAINT = --constraint="Cabal == $(CABAL_DOTTED_VERSION)"
-
-# We rely on all the CONFIGURE_ARGS being quoted with '...', and there
-# being no 's inside the values.
-FLAGGED_CONFIGURE_ARGS = $(subst $(space)',\
- $(space)--configure-option=',\
- $(space)$(CONFIGURE_ARGS))
-
-COMMON_CONFIGURE_FLAGS = \
- --libsubdir='$$pkgid' \
- --with-gcc=$(WhatGccIsCalled) \
- --with-ld=$(LD) \
- $(addprefix --hsc2hs-option=,$(SRC_HSC2HS_OPTS))
-
-ifeq "$(HSCOLOUR_SRCS)" "YES"
-CONFIGURE_OPTS += --with-hscolour="$(HSCOLOUR)"
-endif
-
-ifneq "$(ALEX)" ""
-COMMON_CONFIGURE_FLAGS += --with-alex="$(ALEX)"
-endif
-
-ifneq "$(HAPPY)" ""
-COMMON_CONFIGURE_FLAGS += --with-happy="$(HAPPY)"
-endif
-
-COMMON_CONFIGURE_FLAGS += $(FLAGGED_CONFIGURE_ARGS) \
- --configure-option=--with-cc="$(CC)"
-
-COMMON_CONFIGURE_FLAGS += $(shell [ -f $(HSC2HS_INPLACE) ] && \
- echo --with-hsc2hs=$(HSC2HS_INPLACE) )
-
-ifeq "$(Windows)" "YES"
-NONEXISTENT=c:/NONEXISTENT
-else
-NONEXISTENT=/NONEXISTENT
-endif
-
-# We put non-existant paths in when configuring things that we plan to
-# install, as we require that builds don't depend on these paths when
-# making bindists.
-INSTALL_DIRS_CONFIGURE_FLAGS = \
- --prefix=$(NONEXISTENT) \
- --bindir=$(NONEXISTENT) \
- --libdir=$(NONEXISTENT) \
- --libexecdir=$(NONEXISTENT) \
- --datadir=$(NONEXISTENT) \
- --docdir=$(NONEXISTENT) \
- --haddockdir=$(NONEXISTENT) \
- --htmldir=$(NONEXISTENT)
-
-INPLACE_GHC_DATADIR_CONFIGURE_FLAGS = \
- --datadir=$(FPTOOLS_TOP_ABS)/inplace-datadir \
- --datasubdir=.
-
-INPLACE_DIRS_CONFIGURE_FLAGS = \
- --prefix=`$(FPTOOLS_TOP_ABS)/utils/pwd/pwd forwardslash`/install-inplace
-
-USE_BOOT_CONFIGURE_FLAGS = \
- --with-compiler=$(GHC) \
- --with-hc-pkg=$(GHC_PKG) \
- --package-db $(FPTOOLS_TOP_ABS)/libraries/bootstrapping.conf
-
-USE_STAGE_CONFIGURE_FLAGS = \
- --with-hc-pkg=$(GHC_PKG_INPLACE) \
- $(addprefix --cc-option=,$(MACOSX_DEPLOYMENT_CC_OPTS)) \
- $(addprefix --ld-option=,$(MACOSX_DEPLOYMENT_LD_OPTS))
-
-USE_STAGE1_CONFIGURE_FLAGS = \
- --with-compiler=$(GHC_STAGE1) \
- $(USE_STAGE_CONFIGURE_FLAGS)
-
-USE_STAGE2_CONFIGURE_FLAGS = \
- --with-compiler=$(GHC_STAGE2) \
- $(USE_STAGE_CONFIGURE_FLAGS)
-
-BUILD_FLAGS = $(addprefix --ghc-option=,$(SRC_HC_OPTS))
-
-
-# We now define various i* variables, which are used for the paths
-# when installing Cabal libraries
-ifeq "$(RelocatableBuild)" "YES"
-# On Windows we want to make moveable bindists, but we need to tell
-# ghc-pkg where the haddock docs are. Therefore we completely ignore
-# where the user tells us to put the haddock documentation and put it
-# somewhere whose relative location we know. When installing we need
-# to give Cabal a real path, though.
-iprefix = $$topdir
-ibindir = $$topdir
-ilibdir = $$topdir
-ilibexecdir = $$topdir
-idynlibdir = $$topdir
-idatadir = $$topdir
-idocdir = $$topdir/doc/libraries/$$pkg
-ihaddockdir = $$topdir/doc/libraries/$$pkg
-ihtmldir = $$httptopdir/doc/libraries/$$pkg
-html_installed_root = $(prefix)/doc/libraries
-else
-# On non-Windows we can just give absolute paths all the time, and
-# thus obey the htmldir that we are given.
-iprefix = $(prefix)
-ibindir = $(bindir)
-ilibdir = $(libdir)
-ilibexecdir = $(libexecdir)
-idynlibdir = $(dynlibdir)
-idatadir = $(datadir)
-idocdir = $(docdir)/libraries/$$pkg
-ihaddockdir = $(htmldir)/libraries/$$pkg
-ihtmldir = $(htmldir)/libraries/$$pkg
-html_installed_root = $(htmldir)/libraries
-endif
-
diff --git a/mk/cabal.mk b/mk/cabal.mk
deleted file mode 100644
index 3d525d7739..0000000000
--- a/mk/cabal.mk
+++ /dev/null
@@ -1,68 +0,0 @@
-
-include $(TOP)/mk/cabal-flags.mk
-include $(TOP)/mk/bindist.mk
-
-SRC_HC_OPTS += -Wall
-
-ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
-INSTALL_FLAGS =
-else
-ifeq "$(ENABLE_SHELL_WRAPPERS)" "YES"
-INSTALL_FLAGS = --enable-shell-wrappers
-else
-INSTALL_FLAGS =
-endif
-endif
-
-# Tell stage2 to make a dynamically-linked binary, but no wrapper. We assume
-# that in an installation the shared libs will be installed somewhere that
-# the system can find them.
-ifeq "$(BuildSharedLibs)" "YES"
-DYN_FLAGS = --ghc-option=-dynamic --ghc-option=-dynload --ghc-option=deploy
-endif
-
-.PHONY: default all with-bootstrapping-compiler with-stage-2 clean distclean
-
-default all: with-bootstrapping-compiler
-
-with-bootstrapping-compiler:
- $(CABAL) configure --distpref dist-inplace \
- $(INPLACE_DIRS_CONFIGURE_FLAGS) \
- $(USE_BOOT_CONFIGURE_FLAGS) \
- $(COMMON_CONFIGURE_FLAGS) \
- $(EXTRA_INPLACE_CONFIGURE_FLAGS)
- $(CABAL) build --distpref dist-inplace $(BUILD_FLAGS)
- $(CABAL) install --distpref dist-inplace $(INSTALL_FLAGS)
-
-with-stage-2:
- $(CABAL) configure --distpref dist-install \
- $(INSTALL_DIRS_CONFIGURE_FLAGS) \
- $(USE_STAGE2_CONFIGURE_FLAGS) \
- $(COMMON_CONFIGURE_FLAGS) \
- $(EXTRA_STAGE2_CONFIGURE_FLAGS)
- $(CABAL) build --distpref dist-install $(DYN_FLAGS) $(BUILD_FLAGS)
-
-install:
- $(INSTALL_PACKAGE) install \
- '$(GHC_PKG_INSTALL_PROG)' \
- '$(DESTDIR)$(datadir)/package.conf' \
- '$(DESTDIR)' '$(prefix)' \
- '$(prefix)' '$(bindir)' '$(libdir)' \
- '$(libexecdir)' '$(dynlibdir)' '$(datadir)' \
- '$(docdir)' '$(htmldir)' '$(haddockdir)' \
- --distpref dist-install \
- $(INSTALL_FLAGS)
-
-clean:
- -$(CABAL) clean --distpref dist-inplace
- -$(CABAL) clean --distpref dist-install
- $(RM) -rf install-inplace
-ifneq "$(EXTRA_CLEAN)" ""
- $(RM) -f $(EXTRA_CLEAN)
-endif
-
-distclean: clean
-ifneq "$(EXTRA_DISTCLEAN)" ""
- $(RM) -f $(EXTRA_DISTCLEAN)
-endif
-
diff --git a/mk/config.mk.in b/mk/config.mk.in
index b83fb925dd..980e493f01 100644
--- a/mk/config.mk.in
+++ b/mk/config.mk.in
@@ -32,123 +32,11 @@ $(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)
-
-# 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
-#
-################################################################################
+# TOP: the top of the fptools hierarchy, absolute path.
+# On Windows this is a c:/foo/bar style path.
+TOP = @hardtop@
-# 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,22 +44,6 @@ 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?
BootingFromHc = @BootingFromHc@
@@ -360,14 +232,13 @@ HscIfaceFileVersion=6
# 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"
@@ -422,7 +293,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
+GhcLibHcOpts=-O2 -XGenerics
# Win32 only: Enable the RTS and libraries to be built as DLLs
DLLized=@EnableWin32DLLs@
@@ -543,19 +414,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_TOPDIR_ABS=$(TOP)
BIN_DIST_DIR=$(BIN_DIST_TOPDIR_ABS)/$(BIN_DIST_NAME)
BIN_DIST_NAME=ghc-$(ProjectVersion)
-BIN_DIST_TAR=$(BIN_DIST_NAME)-$(TARGETPLATFORM).tar
+BIN_DIST_TAR=$(TOP)/$(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_DIR=$(TOP)/bindist-prep
BIN_DIST_PREP=$(BIN_DIST_PREP_DIR)/$(BIN_DIST_NAME)
-BIN_DIST_LIST=$(FPTOOLS_TOP_ABS)/bindist-list
+BIN_DIST_LIST=$(TOP)/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
@@ -609,8 +476,8 @@ 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)
+datadir := $(prefix)/lib
+libdir := $(prefix)/lib
docdir := $(prefix)/doc
htmldir := $(docdir)
@@ -660,8 +527,6 @@ ifacedir = $(libdir)
# (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
@@ -718,10 +583,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
@@ -736,120 +597,62 @@ GC_CPP_OPTS += -P -E -x c -traditional -D__GLASGOW_HASKELL__
################################################################################
# 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)
+# so we can move things around more easily. A define $(GHC_FOO_DIR)
+# indicates a directory relative to the top of the source tree.
+
+GHC_UTILS_DIR = utils
+GHC_INCLUDE_DIR = includes
+GHC_COMPILER_DIR = compiler
+GHC_PROG_DIR = ghc
+GHC_RTS_DIR = rts
+GHC_DRIVER_DIR = driver
+GHC_COMPAT_DIR = compat
+
+GHC_MKDEPENDC_DIR = $(GHC_UTILS_DIR)/mkdependC
+GHC_LTX_DIR = $(GHC_UTILS_DIR)/ltx
+GHC_RUNTEST_DIR = $(GHC_UTILS_DIR)/runstdtest
+GHC_LNDIR_DIR = $(GHC_UTILS_DIR)/lndir
+GHC_MKDIRHIER_DIR = $(GHC_UTILS_DIR)/mkdirhier
+GHC_DOCBOOK_DIR = $(GHC_UTILS_DIR)/docbook
+GHC_UNLIT_DIR = $(GHC_UTILS_DIR)/unlit
+GHC_HP2PS_DIR = $(GHC_UTILS_DIR)/hp2ps
+GHC_HSTAGS_DIR = $(GHC_UTILS_DIR)/hasktags
+GHC_GHCTAGS_DIR = $(GHC_UTILS_DIR)/ghctags
+GHC_HSC2HS_DIR = $(GHC_UTILS_DIR)/hsc2hs
+GHC_TOUCHY_DIR = $(GHC_UTILS_DIR)/touchy
+GHC_PKG_DIR = $(GHC_UTILS_DIR)/ghc-pkg
+GHC_GENPRIMOP_DIR = $(GHC_UTILS_DIR)/genprimopcode
+GHC_GENAPPLY_DIR = $(GHC_UTILS_DIR)/genapply
+GHC_CABAL_DIR = $(GHC_UTILS_DIR)/ghc-cabal
+GHC_MANGLER_DIR = $(GHC_DRIVER_DIR)/mangler
+GHC_SPLIT_DIR = $(GHC_DRIVER_DIR)/split
+GHC_SYSMAN_DIR = $(GHC_RTS_DIR)/parallel
# -----------------------------------------------------------------------------
# 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_HSTAGS_PGM = hasktags$(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_MKDEPENDC_PGM = mkdependC
+GHC_LTX_PGM = ltx$(exeext)
+GHC_MKDIRHIER_PGM = mkdirhier
+GHC_LNDIR_PGM = lndir
+GHC_RUNTEST_PGM = runstdtest
+GHC_DUMMY_GHC_PGM = dummy-ghc$(exeext)
ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
GHC_CP = "xcopy /y"
@@ -859,23 +662,32 @@ 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)
+INPLACE = inplace
+INPLACE_BIN = $(INPLACE)/bin
+INPLACE_LIB = $(INPLACE)/lib
+INPLACE_MINGW = $(INPLACE)/mingw
+
+UNLIT = $(INPLACE_LIB)/$(GHC_UNLIT_PGM)
+TOUCHY = $(INPLACE_LIB)/$(GHC_TOUCHY_PGM)
+MKDIRHIER = $(INPLACE_BIN)/$(GHC_MKDIRHIER_PGM)
+MKDEPENDC = $(INPLACE_BIN)/$(GHC_MKDEPENDC_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
@@ -891,7 +703,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
@@ -905,63 +724,31 @@ 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@
+# Install stage 2 by default, can be changed to 3
+INSTALL_GHC_STAGE=2
-ghc_ge_607 = YES
-ghc_ge_609 = YES
+BOOTSTRAPPING_CONF = libraries/bootstrapping.conf
-else # not UseStage1 or BootingFromHc
+INPLACE_PACKAGE_CONF = $(INPLACE_LIB)/package.conf
-# Some useful GHC version predicates:
-ghc_ge_607 = @ghc_ge_607@
-ghc_ge_609 = @ghc_ge_609@
-
-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
+ghc_ge_607 = @ghc_ge_607@
+ghc_ge_609 = @ghc_ge_609@
# Canonicalised ghc version number, used for easy (integer) version
# comparisons. We must expand $(GhcMinVersion) to two digits by
@@ -988,7 +775,6 @@ ifneq "$(strip $(UseGcc))" "YES"
CC = cc
else
CC = $(WhatGccIsCalled)
- GccDir = $(dir $(WhatGccIsCalled))
endif
endif
@@ -1054,7 +840,7 @@ 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
@@ -1108,6 +894,7 @@ LdIsGNULd = @LdIsGNULd@
REAL_SHELL=$(SHELL)
SIZE = size
STRIP = strip
+PATCH = @PatchCmd@
TAR = @TarCmd@
ZIP = zip
@@ -1156,12 +943,6 @@ XSLTPROC_LABEL_OPTS = --stringparam toc.section.depth 3 \
BLD_DLL = dllwrap
#
-# .NET support software
-#
-ILX2IL = ilx2il
-ILASM = ilasm
-
-#
# ghc-pkg
#
GHC_PKG = @GhcPkgCmd@
@@ -1180,11 +961,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
@@ -1194,7 +975,7 @@ 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
# Should we build haddock docs?
HADDOCK_DOCS = YES
@@ -1229,7 +1010,7 @@ endif
#
# 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
+ALL_WAYS=v p t l s mp mg debug dyn thr thr_l debug_dyn thr_dyn thr_debug_dyn thr_p thr_debug thr_debug_l
USER_WAYS=a b c d e f g h j k l m n o A B
#
@@ -1240,9 +1021,9 @@ USER_WAYS=a b c d e f g h j k l m n o A B
#
# 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 'v':
+WAY_v_NAME=vanilla
+WAY_v_HC_OPTS=
# Way 'p':
WAY_p_NAME=profiling
@@ -1412,5 +1193,5 @@ else
BIN_DIST_INST_SUBDIR = installed
endif
-BIN_DIST_INST_DIR = $(FPTOOLS_TOP_ABS)/bindisttest/$(BIN_DIST_INST_SUBDIR)
+BIN_DIST_INST_DIR = $(TOP)/bindisttest/$(BIN_DIST_INST_SUBDIR)
diff --git a/mk/custom-settings.mk b/mk/custom-settings.mk
index 1a01873d31..75c9d8940f 100644
--- a/mk/custom-settings.mk
+++ b/mk/custom-settings.mk
@@ -1,9 +1,9 @@
--include $(TOP)/mk/are-validating.mk
+-include mk/are-validating.mk
ifeq "$(Validating)" "YES"
-include $(TOP)/mk/validate-settings.mk
--include $(TOP)/mk/validate.mk
+include mk/validate-settings.mk
+-include mk/validate.mk
else
--include $(TOP)/mk/build.mk
+-include mk/build.mk
endif
diff --git a/mk/install.mk b/mk/install.mk
deleted file mode 100644
index 1efb6958ef..0000000000
--- a/mk/install.mk
+++ /dev/null
@@ -1,307 +0,0 @@
-#
-# install* installcheck installdirs
-# install-docs*
-#
-# Some of the above targets have a version that
-# recursively invokes that target in sub-directories.
-# This relies on the importing Makefile setting SUBDIRS
-#
-# The recursive targets are marked with a * above
-#
-
-##################################################################
-# GNU Standard targets
-#
-# Every Makefile should define the following targets
-#
-# `install'
-# Compile the program and copy the executables, libraries, and so on
-# to the file names where they should reside for actual use. If
-# there is a simple test to verify that a program is properly
-# installed, this target should run that test.
-#
-# The commands should create all the directories in which files are
-# to be installed, if they don't already exist. This includes the
-# directories specified as the values of the variables prefix and
-# exec_prefix , as well as all subdirectories that are needed. One
-# way to do this is by means of an installdirs target as described
-# below.
-#
-# Use `-' before any command for installing a man page, so that make
-# will ignore any errors. This is in case there are systems that
-# don't have the Unix man page documentation system installed.
-#
-# The following targets are suggested as conventional names, for programs
-# in which they are useful.
-#
-# installcheck
-# Perform installation tests (if any). The user must build and
-# install the program before running the tests. You should not
-# assume that `$(bindir)' is in the search path.
-#
-# installdirs
-# It's useful to add a target named `installdirs' to create the
-# directories where files are installed, and their parent
-# directories. There is a script called `mkinstalldirs' which is
-# convenient for this; find it in the Texinfo package.
-# (GHC: we use a close relative of the suggested script, situated
-# in glafp-utils/mkdirhier -- SOF)
-
-
-
-# ---------------------------------------------------------------------------
-# Symbolic links
-
-# links to programs: we sometimes install a program as
-# <name>-<version> with a link from <name> to the real program.
-
-ifneq "$(LINK)" ""
-
-ifeq "$(LINK_TARGET)" ""
-ifneq "$(HS_PROG)" ""
-LINK_TARGET = $(HS_PROG)
-else
-ifneq "$(C_PROG)" ""
-LINK_TARGET = $(C_PROG)
-else
-$(error Cannot deduce LINK_TARGET)
-endif
-endif
-endif
-
-#
-# install links to script drivers.
-#
-install ::
- $(INSTALL_DIR) $(DESTDIR)$(bindir)
- if ( $(PERL) -e '$$fn="$(DESTDIR)$(bindir)/$(LINK)"; exit ((! -f $$fn || -l $$fn) ? 0 : 1);' ); then \
- echo "Creating a symbolic link from $(LINK_TARGET) to $(LINK) in $(DESTDIR)$(bindir)"; \
- $(RM) $(DESTDIR)$(bindir)/$(LINK); \
- $(LN_S) $(LINK_TARGET) $(DESTDIR)$(bindir)/$(LINK); \
- else \
- echo "Creating a symbolic link from $(LINK_TARGET) to $(LINK) in $(DESTDIR)$(bindir) failed: \`$(DESTDIR)$(bindir)/$(LINK)' already exists"; \
- echo "Perhaps remove \`$(DESTDIR)$(bindir)/$(LINK)' manually?"; \
- exit 1; \
- fi;
-
-endif # LINK
-
-
-###########################################
-#
-# Targets: install install-strip
-#
-###########################################
-
-# For each of these variables that is defined, you
-# get one install rule
-#
-# INSTALL_PROGS executable programs in $(bindir)
-# INSTALL_SCRIPTS executable scripts in $(bindir)
-# INSTALL_LIBS platform-dependent libraries in $(libdir) (ranlib'ed)
-# INSTALL_LIB_SCRIPTS platform-dependent scripts in $(libdir)
-# INSTALL_LIBEXECS platform-dependent execs in $(libdir)
-# INSTALL_DATAS platform-independent files in $(datadir)
-# INSTALL_IFACES platform-dependent interface files in $(ifacedir)
-#
-# If the installation directory variable is undefined, the install rule simply
-# emits a suitable error message.
-#
-# Remember, too, that the installation directory variables ($(bindir) and
-# friends can be overridden from their original settings in mk/config.mk.in
-# || mk/build.mk
-#
-.PHONY: install install-docs installdirs install-strip install-docs show-install
-
-show-install :
- @echo "DESTDIR = $(DESTDIR)"
- @echo "bindir = $(bindir)"
- @echo "libdir = $(libdir)"
- @echo "libexecdir = $(libexecdir) # by default, same as libdir"
- @echo "datadir = $(datadir) # unused for ghc project"
- @echo "ifacedir = $(ifacedir)"
- @echo "headerdir = $(headerdir)"
- @echo "includedir = $(includedir)"
-
-#
-# Setting user/group ownership for the installed entities
-#
-ifneq "$(INSTALL_OWNER)" ""
-SRC_INSTALL_OPTS += -o $(INSTALL_OWNER)
-endif
-ifneq "$(INSTALL_GROUP)" ""
-SRC_INSTALL_OPTS += -g $(INSTALL_GROUP)
-endif
-
-
-ifneq "$(strip $(INSTALL_PROGS))" ""
-
-#
-# Here's an interesting one - when using the win32 version
-# of install (provided via the cygwin toolkit), we have to
-# supply the .exe suffix, *if* there's no other suffix.
-#
-# The rule below does this by ferreting out the suffix of each
-# entry in the INSTALL_PROGS list. If there's no suffix, use
-# $(exeext).
-#
-INSTALL_PROGS := $(foreach p, $(INSTALL_PROGS),\
- $(if $(filter $(exeext),$(suffix $p)),\
- $p,\
- $(addsuffix $(exeext),$p)\
- )\
- )
-
-install:: $(INSTALL_PROGS)
- $(INSTALL_DIR) $(DESTDIR)$(bindir)
- for i in $(INSTALL_PROGS); do \
- $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i $(DESTDIR)$(bindir) ; \
- if test "$(darwin_TARGET_OS)" = "1"; then \
- sh $(FPTOOLS_TOP)/mk/fix_install_names.sh $(libdir) $(DESTDIR)$(bindir)/$$i ; \
- fi ; \
- done
-endif
-
-#
-# Just like INSTALL_PROGS, but prefix with install sites bin/lib/data and
-# install without stripping.
-#
-ifneq "$(strip $(INSTALL_SCRIPTS))" ""
-install:: $(INSTALL_SCRIPTS)
- $(INSTALL_DIR) $(DESTDIR)$(bindir)
- for i in $(INSTALL_SCRIPTS); do \
- $(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i $(DESTDIR)$(bindir); \
- done
-endif
-
-ifneq "$(strip $(INSTALL_LIB_SCRIPTS))" ""
-install:: $(INSTALL_LIB_SCRIPTS)
- $(INSTALL_DIR) $(DESTDIR)$(libdir)
- for i in $(INSTALL_LIB_SCRIPTS); do \
- $(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir); \
- done
-endif
-
-ifneq "$(strip $(INSTALL_LIBEXEC_SCRIPTS))" ""
-install:: $(INSTALL_LIBEXEC_SCRIPTS)
- $(INSTALL_DIR) $(DESTDIR)$(libexecdir)
- for i in $(INSTALL_LIBEXEC_SCRIPTS); do \
- $(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i $(DESTDIR)$(libexecdir); \
- done
-endif
-
-ifneq "$(strip $(INSTALL_LIBS))" ""
-install:: $(INSTALL_LIBS)
- $(INSTALL_DIR) $(DESTDIR)$(libdir)
- for i in $(INSTALL_LIBS); do \
- case $$i in \
- *.a) \
- $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir); \
- $(RANLIB) $(DESTDIR)$(libdir)/`basename $$i` ;; \
- *.dll) \
- $(INSTALL_DATA) -s $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir) ;; \
- *.so) \
- $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir) ;; \
- *.dylib) \
- $(INSTALL_SHLIB) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir); \
- install_name_tool -id $(DESTDIR)$(libdir)/`basename $$i` $(DESTDIR)$(libdir)/`basename $$i` ;; \
- *) \
- $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(libdir); \
- esac; \
- done
-endif
-
-ifneq "$(strip $(INSTALL_LIBEXECS))" ""
-#
-# See above comment next to defn of INSTALL_PROGS for what
-# the purpose of this one-liner is.
-#
-INSTALL_LIBEXECS := $(foreach p, $(INSTALL_LIBEXECS), $(addsuffix $(subst _,,$(subst __,$(exeext),_$(suffix $(p))_)), $(basename $(p))))
-
-install:: $(INSTALL_LIBEXECS)
- $(INSTALL_DIR) $(DESTDIR)$(libexecdir)
- -for i in $(INSTALL_LIBEXECS); do \
- $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i $(DESTDIR)$(libexecdir); \
- if test "$(darwin_TARGET_OS)" = "1"; then \
- sh $(FPTOOLS_TOP)/mk/fix_install_names.sh $(libdir) $(DESTDIR)$(libexecdir)/`basename $$i` ; \
- fi ; \
- done
-endif
-
-ifneq "$(strip $(INSTALL_DATAS))" ""
-install:: $(INSTALL_DATAS)
- $(INSTALL_DIR) $(DESTDIR)$(datadir)
- for i in $(INSTALL_DATAS); do \
- $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(datadir); \
- done
-endif
-
-ifneq "$(strip $(INSTALL_HEADERS))" ""
-install:: $(INSTALL_HEADERS)
- $(INSTALL_DIR) $(DESTDIR)$(headerdir)
- for i in $(INSTALL_HEADERS); do \
- $(INSTALL_HEADER) $(INSTALL_OPTS) $$i $(DESTDIR)$(headerdir); \
- done
-endif
-
-ifneq "$(strip $(INSTALL_IFACES))" ""
-install:: $(INSTALL_IFACES)
- $(INSTALL_DIR) $(DESTDIR)$(ifacedir)
- for i in $(INSTALL_IFACES); do \
- $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(ifacedir); \
- done
-endif
-
-ifneq "$(strip $(INSTALL_IFACES_WITH_DIRS))" ""
-install:: $(INSTALL_IFACES_WITH_DIRS)
- $(INSTALL_DIR) $(DESTDIR)$(ifacedir)
- for i in $(INSTALL_IFACES_WITH_DIRS); do \
- $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(ifacedir)/`dirname $$i`; \
- done
-endif
-
-ifneq "$(strip $(INSTALL_DOCS))" ""
-ifneq "$(XMLDocWays)" ""
-install-docs:: $(INSTALL_DOCS)
- $(INSTALL_DIR) $(DESTDIR)$(datadir)
- for i in $(INSTALL_DOCS); do \
- $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(DESTDIR)$(datadir); \
- done
-endif
-endif
-
-ifneq "$(strip $(INSTALL_XML_DOC))" ""
-ifeq "$(DOC_SUBDIR)" ""
-DOC_SUBDIR=docs/$(XML_DOC)
-endif
-
-ifneq "$(XMLDocWays)" ""
-# TODO: The following could be an entry for an Obfuscated Makefile Contest...
-install-docs:: $(foreach i,$(XMLDocWays),$(INSTALL_XML_DOC)$(patsubst %.html-no-chunks,%.html,$(patsubst %.html,%/index.html,.$(i))))
-
-install-docs:: $(foreach i,$(XMLDocWays),install-docs-$i)
-
-install-docs-html:
- $(INSTALL_DIR) $(DESTDIR)$(htmldir)
- $(INSTALL_DIR) $(DESTDIR)$(htmldir)/$(INSTALL_XML_DOC)
- $(CP) $(INSTALL_XML_DOC)/* $(DESTDIR)$(htmldir)/$(INSTALL_XML_DOC)
-
-install-docs-html-no-chunks:
- $(INSTALL_DIR) $(DESTDIR)$(htmldir)
- $(INSTALL_DATA) $(INSTALL_OPTS) $(INSTALL_XML_DOC).html $(DESTDIR)$(htmldir)
- $(CP) $(FPTOOLS_CSS_ABS) $(DESTDIR)$(htmldir)
-
-install-docs-%:
- $(INSTALL_DIR) $(DESTDIR)$($*dir)
- $(INSTALL_DATA) $(INSTALL_OPTS) $(INSTALL_XML_DOC).$* $(DESTDIR)$($*dir)
-endif
-endif
-
-#
-# install-strip is from the GNU Makefile standard.
-#
-ifneq "$(way)" ""
-install-strip::
- $(MAKE) EXTRA_INSTALL_OPTS='-s' install
-endif
-
diff --git a/mk/old-config.mk.in b/mk/old-config.mk.in
new file mode 100644
index 0000000000..b83fb925dd
--- /dev/null
+++ b/mk/old-config.mk.in
@@ -0,0 +1,1416 @@
+# -*-makefile-*-
+# @configure_input@
+#
+################################################################################
+#
+# config.mk.in
+#
+# This file supplies defaults for many tweakable build configuration
+# options. Some of the defaults are filled in by the autoconf-generated
+# configure script.
+#
+# 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.
+#
+# - Settings in this file may be overriden by giving replacement
+# definitions in build.mk. See build.mk.sample for a good
+# starting point for a build.mk file.
+#
+# 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)
+
+# 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
+
+################################################################################
+#
+# Global configuration options
+#
+################################################################################
+
+# 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?
+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 latex docs?
+LATEX_DOCS = NO
+
+# Mac OS X deployment target (to cross-compile for older OS versions)
+#
+MACOSX_DEPLOYMENT_VERSION = @MACOSX_DEPLOYMENT_VERSION@
+MACOSX_DEPLOYMENT_SDK = @MACOSX_DEPLOYMENT_SDK@
+
+ifneq "$(MACOSX_DEPLOYMENT_VERSION)" ""
+MACOSX_DEPLOYMENT_CC_OPTS = -mmacosx-version-min=$(MACOSX_DEPLOYMENT_VERSION) \
+ -isysroot $(MACOSX_DEPLOYMENT_SDK) \
+ --no-builtin-fprintf
+MACOSX_DEPLOYMENT_LD_OPTS = -mmacosx-version-min=$(MACOSX_DEPLOYMENT_VERSION) \
+ -Wl,-syslibroot,$(MACOSX_DEPLOYMENT_SDK)
+# We don't extend SRC_CC_OPTS and friends here directly, as (a) they may get
+# overwritten in build.mk and (b) we must not use the deployment options in
+# stage 1 or we get a linker error if the bootstrap compiler is for a more
+# recent OS version.
+#
+# We need --no-builtin-fprintf, as the use of the builtin function optimisation
+# for fprintf together with #include "PosixSource" in the RTS leads to the
+# use of fwrite$UNIX2003 (with GCC 4.0.1 on Mac OS X 10.5.2).
+endif
+
+################################################################################
+#
+# Variables that control how the compiler itself is built
+#
+################################################################################
+
+# The compiler used to build GHC is $(GHC). To change the actual compiler
+# used, re-configure with --with-ghc=<path-to-ghc>.
+
+# Extra ways in which to build the compiler (for example, you might want to
+# build a profiled compiler so you can see where it spends its time)
+GhcCompilerWays=
+
+# Extra option flags to pass to the compiler that compiles the compiler
+# (Ones that are essential are wired into compiler/Makefile)
+# Typical options to use here:
+#
+# -DDEBUG include debugging code and assertions (will make the
+# compiler slower and produce debugging output, but useful
+# for development)
+#
+# -dcore-lint check the types after every pass of the compiler;
+# a pretty strong internal check of the compiler being
+# used to compile GHC. Useful when bootstrapping.
+GhcHcOpts=-Rghc-timing
+
+# Extra options added to specific stages of the compiler bootstrap.
+# These are placed later on the command line, and may therefore
+# override options from $(GhcHcOpts).
+GhcStage1HcOpts=
+GhcStage2HcOpts=-O2
+GhcStage3HcOpts=-O2
+
+GhcProfiled=NO
+GhcDebugged=NO
+GhcLibProfiled=$(if $(filter p,$(GhcLibWays)),YES,NO)
+
+# Build shared and/or static libs?
+BuildSharedLibs=@BuildSharedLibs@
+# ToDo later:
+# BuildStaticLibs=@BuildStaticLibs@
+
+# Build a compiler that will build *unregisterised* libraries and
+# binaries by default. Unregisterised code is supposed to compile and
+# run without any support for architecture-specific assembly mangling,
+# register assignment or tail-calls, and is therefore a good way to get
+# started when porting GHC to new architectures.
+#
+# If this is set to NO, you can still use the unregisterised way
+# (way 'u') to get unregisterised code, but the default way will be
+# registerised.
+#
+# NOTE: the stage1 compiler will be a registerised binary (assuming
+# the compiler you build with is generating registerised binaries), but
+# the stage2 compiler will be an unregisterised binary.
+#
+ifneq "$(findstring $(HostArch_CPP), alpha hppa)" ""
+GhcUnregisterised=YES
+else
+GhcUnregisterised=NO
+endif
+
+# Build a compiler with a native code generator backend
+# (as well as a C backend)
+#
+# Target platforms supported:
+# i386, powerpc
+# AIX is not supported
+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.
+GhcWithNativeCodeGen=$(strip\
+ $(if $(filter YESYESNO,\
+ $(OsSupportsNCG)$(ArchSupportsNCG)$(GhcUnregisterised)),YES,NO))
+
+HaveLibDL = @HaveLibDL@
+
+# ArchSupportsSMP should be set iff there is support for that arch in
+# includes/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.
+GhcWithSMP=$(strip $(if $(filter YESNO, $(ArchSupportsSMP)$(GhcUnregisterised)),YES,NO))
+
+# 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)))
+ArchSupportsGHCi=$(strip $(patsubst $(HostArch_CPP), YES, $(findstring $(HostArch_CPP), i386 x86_64 powerpc sparc sparc64)))
+
+ifeq "$(OsSupportsGHCi)$(ArchSupportsGHCi)" "YESYES"
+GhcWithInterpreter=YES
+else
+GhcWithInterpreter=NO
+endif
+
+# GhcEnableTablesNextToCode tells us whether the target architecture
+# supports placing info tables directly before the entry code
+# (see TABLES_NEXT_TO_CODE in the RTS). Whether we actually compile for
+# TABLES_NEXT_TO_CODE depends on whether we're building unregisterised
+# code or not, which may be decided by options to the compiler later.
+ifneq "$(findstring $(TargetArch_CPP)X, ia64X powerpc64X)" ""
+GhcEnableTablesNextToCode=NO
+else
+GhcEnableTablesNextToCode=YES
+endif
+
+# On Windows we normally want to make a relocatable bindist, to we
+# ignore flags like libdir
+ifeq "$(Windows)" "YES"
+RelocatableBuild = YES
+else
+RelocatableBuild = NO
+endif
+
+# When building bindists we set this to yes so that the binaries are as
+# portable as possible.
+BeConservative = NO
+
+#
+# Building various ways?
+# (right now, empty if not).
+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
+# 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
+endif
+
+ifeq "$(BuildSharedLibs)" "YES"
+GhcLibWays += dyn
+endif
+
+# In addition, the RTS is built in some further variations. Ways that
+# make sense here:
+#
+# thr : threaded
+# thr_p : threaded profiled
+# debug : debugging (compile with -g for the C compiler, and -DDEBUG)
+# 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
+# thr_debug_l : threaded and debugging and event logging
+#
+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_debug thr_l,)
+GhcRTSWays += $(if $(findstring p, $(GhcLibWays)),$(if $(findstring NO, $(GhcUnregisterised)),thr_p,),)
+
+# We can only build GHCi threaded if we have a threaded RTS:
+GhcThreaded = $(if $(findstring thr,$(GhcRTSWays)),YES,NO)
+
+# Option flags to pass to GHC when it's compiling modules in
+# fptools/libraries. Typically these are things like -O or
+# -dcore-lint or -H32m. The ones that are *essential* are wired into
+# the build system.
+#
+# -O(2) is pretty desirable, otherwise no inlining of prelude
+# things (incl "+") happens when compiling with this compiler
+#
+# -XGenerics switches on generation of support code for
+# derivable type classes. This is now off by default,
+# 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@
+
+# Strip local symbols from libraries? This can make the libraries smaller,
+# but makes debugging somewhat more difficult. Doesn't work with all ld's.
+#
+StripLibraries=NO
+
+# These are the URL patterns that Haddock uses to generate the "Source
+# File" links on each page.
+PackageSourceURL = http://darcs.haskell.org/packages/$(PACKAGE)/%{FILE}
+
+# ----------------------------------------------------------------------------
+# Object-file splitting
+#
+# Set SplitObjs=YES or NO in your build.mk
+#
+# Don't use -split-objs in in GhcLibHcOpts, because the build
+# 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))
+
+# lazy test, so that $(GhcUnregisterised) can be set in build.mk
+SupportsSplitObjs=$(strip $(if $(filter YES,$(ArchSupportsSplitObjs)),\
+ $(if $(filter NO,$(BootingFromHc)),\
+ $(if $(filter NO,$(GhcUnregisterised)),\
+ YES,\
+ NO),\
+ NO),\
+ NO))
+
+# By default, enable SplitObjs for the libraries if this build supports it
+SplitObjs=$(SupportsSplitObjs)
+
+# Math library
+LIBM=@LIBM@
+
+# .NET interop support?
+#
+DotnetSupport=NO
+
+# Build unix package?
+#
+GhcLibsWithUnix=@GhcLibsWithUnix@
+
+# ----------------------------------------------------------------------------
+# Options for GHC's RTS
+
+# For an optimised RTS (you probably don't want to change these; we build
+# a debugging RTS by default now. Use -debug to get it).
+GhcRtsHcOpts=-optc-O2
+GhcRtsCcOpts=-fomit-frame-pointer
+
+# Include the front panel code? Needs GTK+.
+GhcRtsWithFrontPanel = NO
+
+# Include support for CPU performance counters via the PAPI library in the RTS?
+# (PAPI: http://icl.cs.utk.edu/papi/)
+GhcRtsWithPapi = NO
+PapiLibDir=
+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)
+#
+################################################################################
+
+# Directory used by GHC (and possibly other tools) for storing
+# temporary files. If your TMPDIR isn't big enough, either override
+# this in build.mk or set your environment variable "TMPDIR" to point
+# to somewhere with more space. (TMPDIR=. is a good choice).
+
+# DEFAULT_TMPDIR isn't called TMPDIR because GNU make tends to
+# override an environment variable with the value of the make variable
+# of the same name (if it exists) when executing sub-processes, so
+# setting the TMPDIR env var would have no effect in the build tree.
+
+DEFAULT_TMPDIR = /tmp
+ifeq "$(TARGETPLATFORM)" "i386-unknown-cygwin32"
+DEFAULT_TMPDIR = /C/TEMP
+endif
+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=$(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 =
+
+#
+# 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.
+
+# -----------------------------------------------------------------------------
+# Utilities programs: flags
+
+# If you want to give any standard flags to pretty much any utility
+# (see utils.mk for a complete list), by adding a line here
+#
+# SRC_P_OPTS += ...
+#
+# where P is the utility. For example, to add -O to all Haskell
+# compilations,
+#
+# SRC_HC_OPTS += -O
+
+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
+
+# Flags for CPP when running GreenCard on .pgc files
+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
+
+ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
+GHC_CP = "xcopy /y"
+GHC_PERL = perl
+else
+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)
+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)
+
+GENERATED_FILE = chmod a-w
+EXECUTABLE_FILE = chmod +x
+
+#-----------------------------------------------------------------------------
+# Haskell compilers and mkdependHS
+
+# $(GHC), $(HBC) and $(NHC) point to installed versions of the relevant
+# compilers, if available.
+#
+# $(HC) is a generic Haskell 98 compiler, set to $(GHC) by default.
+# $(MKDEPENDHS) is the Haskell dependency generator (ghc -M).
+#
+# NOTE: Don't override $(GHC) in build.mk, use configure --with-ghc instead
+# (because the version numbers have to be calculated).
+
+GHC = @WithGhc@
+GhcDir = $(dir $(GHC))
+
+# Set to YES if $(GHC) has the editline package installed
+GhcHasEditline = @GhcHasEditline@
+
+HBC = @HBC@
+NHC = @NHC@
+
+# Sometimes we want to invoke ghc from the build tree in different
+# places (eg. it's handy to have a nofib & a ghc build in the same
+# 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
+
+# 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.
+
+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_607 = YES
+ghc_ge_609 = YES
+
+else # not UseStage1 or BootingFromHc
+
+# Some useful GHC version predicates:
+ghc_ge_607 = @ghc_ge_607@
+ghc_ge_609 = @ghc_ge_609@
+
+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
+
+# Canonicalised ghc version number, used for easy (integer) version
+# comparisons. We must expand $(GhcMinVersion) to two digits by
+# adding a leading zero if necessary:
+ifneq "$(findstring $(GhcMinVersion), 0 1 2 3 4 5 6 7 8 9)" ""
+GhcCanonVersion = $(GhcMajVersion)0$(GhcMinVersion)
+else
+GhcCanonVersion = $(GhcMajVersion)$(GhcMinVersion)
+endif
+
+#-----------------------------------------------------------------------------
+# C compiler
+#
+# NB. Don't override $(WhatGccIsCalled) using build.mk, re-configure using
+# the flag --with-gcc=<blah> instead. The reason is that the configure script
+# needs to know which gcc you're using in order to perform its tests.
+
+HaveGcc = @HaveGcc@
+UseGcc = YES
+WhatGccIsCalled = @WhatGccIsCalled@
+GccVersion = @GccVersion@
+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@
+
+ifeq "$(TARGETPLATFORM)" "ia64-unknown-linux"
+SRC_CC_OPTS += -G0
+endif
+
+SRC_HSC2HS_OPTS += $(addprefix --cflag=,$(filter-out -O,$(SRC_CC_OPTS)))
+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@
+
+#-----------------------------------------------------------------------------
+# Flex (currently unused, could be moved to glafp-utils)
+
+# FLEX = @LEX@
+# Don't bother with -lfl, we define our own yywrap()s anyway.
+# FLEX_LIB =
+#WAS:FLEX_LIB = @LEXLIB@
+
+#-----------------------------------------------------------------------------
+# Other standard (ha!) Unix utilities
+
+AR = @ArCmd@
+ArSupportsInput = @ArSupportsInput@
+# Yuckage: for ghc/utils/parallel -- todo: nuke this dependency!!
+BASH = /usr/local/bin/bash
+
+CONTEXT_DIFF = @ContextDiffCmd@
+CP = cp
+CPP = @CPP@ @CPPFLAGS@
+CTAGS = $(ETAGS)
+#
+# RAWCPP_FLAGS are the flags to give to cpp (viz, gcc -E) to persuade it to
+# behave plausibly on Haskell sources.
+#
+RAWCPP_FLAGS = -undef -traditional
+FIND = @FindCmd@
+SORT = @SortCmd@
+INSTALL = @INSTALL@
+#
+# Sigh - the autoconf macro for INSTALL will subst a relative path to the fallback
+# 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))
+LATEX = latex
+HEVEA = hevea
+HACHA = hacha
+LN_S = @LN_S@
+MANMACROS = -man
+MSMACROS = -ms
+MV = mv
+NROFF = nroff
+PERL = @PerlCmd@
+PYTHON = @PythonCmd@
+PIC = pic
+PREPROCESSCMD = $(CC) -E
+RANLIB = @RANLIB@
+RM = rm -f
+SED = @SedCmd@
+SHELL = /bin/sh
+
+LD = @LdCmd@
+
+# 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 ""
+# respectively.
+LD_X = @LdXFlag@
+
+# GNU ld supports input via a linker script, which is useful to avoid
+# overflowing command-line length limits.
+LdIsGNULd = @LdIsGNULd@
+
+#
+# In emergency situations, REAL_SHELL is used to perform shell commands
+# from within the ghc driver script, by scribbling the command line to
+# a temp file and then having $(REAL_SHELL) execute it.
+#
+# The reason for having to do this is that overly long command lines
+# cause unnecessary trouble with some shells (e.g., /bin/sh on Solaris
+# 2.5.1), which is why this backdoor is provided. The situation of overly
+# long command lines is either encountered while doing `make boot' in compiler/,
+# or when linking the compiler binary (`hsc').
+#
+# We do not use SHELL to execute long commands, as `make' will more than likely
+# override whatever setting you have in your environment while executing.
+
+# By default, REAL_SHELL is set equal to SHELL, which is not really a smart move
+# as it is SHELL that will show up the bogosity in the first place, but setting
+# it to anything else isn't really portable.
+#
+# ====> If long command lines cause you trouble, invoke `ghc' (via `make' or otherwise)
+# 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
+
+HSCOLOUR = @HSCOLOUR@
+
+#
+# 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
+
+TIME = @TimeCmd@
+TROFF = troff
+UNAME = uname
+
+# GTK+
+GTK_CONFIG = @GTK_CONFIG@
+
+# Set this if you want to use Inno Setup to build a Windows installer
+# when you make a bindist
+ISCC =
+
+#-----------------------------------------------------------------------------
+# 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
+
+#-----------------------------------------------------------------------------
+# FPtools support software
+
+BLD_DLL = dllwrap
+
+#
+# .NET support software
+#
+ILX2IL = ilx2il
+ILASM = ilasm
+
+#
+# ghc-pkg
+#
+GHC_PKG = @GhcPkgCmd@
+
+#
+# GreenCard
+#
+GREENCARD = @GreenCardCmd@
+GREENCARD_VERSION = @GreenCardVersion@
+
+#
+# Happy
+#
+HAPPY = @HappyCmd@
+HAPPY_VERSION = @HappyVersion@
+#
+# Options to pass to Happy when we're going to compile the output with GHC
+#
+GHC_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
+
+#
+# Alex
+#
+ALEX = @AlexCmd@
+ALEX_VERSION = @AlexVersion@
+#
+# Options to pass to Happy when we're going to compile the output with GHC
+#
+GHC_ALEX_OPTS = -g
+
+# Should we build haddock docs?
+HADDOCK_DOCS = YES
+# And HsColour the sources?
+ifeq "$(HSCOLOUR)" ""
+HSCOLOUR_SRCS = NO
+else
+HSCOLOUR_SRCS = YES
+endif
+
+#
+# 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.
+#
+
+#
+# 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 'l':
+WAY_l_NAME=event logging
+WAY_l_HC_OPTS= -eventlog
+
+# 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 'thr_l':
+WAY_thr_l_NAME=threaded event logging
+WAY_thr_l_HC_OPTS=-optc-DTHREADED_RTS -eventlog
+
+# 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 'thr_debug_l':
+WAY_thr_debug_l_NAME=threaded debug event logging
+WAY_thr_debug_l_HC_OPTS=-optc-DTHREADED_RTS -optc-DDEBUG -eventlog
+
+# 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=
+
+################################################################################
+#
+# 31-bit-Int Core files
+#
+################################################################################
+
+#
+# It is possible to configure the compiler and prelude to support 31-bit
+# integers, suitable for a back-end and RTS using a tag bit on a 32-bit
+# architecture. Currently the only useful output from this option is external Core
+# files. The following additions to your build.mk will produce the
+# 31-bit core output. Note that this is *not* just a library "way"; the
+# compiler must be built a special way too.
+
+# GhcCppOpts +=-DWORD_SIZE_IN_BITS=31
+# GhcLibHcOpts +=-fext-core -fno-code -DWORD_SIZE_IN_BITS=31
+# GhcLibCppOpts += -DWORD_SIZE_IN_BITS=31
+# SplitObjs=NO
+
+################################################################################
+#
+# Library configure arguments
+#
+################################################################################
+
+CONFIGURE_ARGS = @CONFIGURE_ARGS@
+
+################################################################################
+#
+# Bindist testing directory
+#
+################################################################################
+
+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)
+
diff --git a/mk/opts.mk b/mk/opts.mk
deleted file mode 100644
index 08ec4b60a2..0000000000
--- a/mk/opts.mk
+++ /dev/null
@@ -1,109 +0,0 @@
-#################################################################################
-#
-# opts.mk
-#
-# This file defines Make variables for the
-# option flags for each utility program
-#
-# $Id: opts.mk,v 1.36 2004/08/26 20:08:54 panne Exp $
-#
-#################################################################################
-
-#
-# N.B. This is *NOT* the place to put extra options of ANY SORT!
-#
-
-# Exports: Define P_OPTS for the most important utility programs, P, namely
-#
-# AR AS CPP CTAGS C FLEX HC HSTAGS LD LINT
-# LIT2CHANGELOG LIT2HTML LIT2LATEX LIT2PGM
-# MKDEPENDC MKDEPENDHS MKDEPENDLIT RUNTEST
-# UNLIT
-
-
-# For each such utility program P, this file defines
-#
-# $(P) The pathname to invoke the utility
-# P_OPTS Options to pass to P
-#
-# P_OPTS is always defined like this:
-#
-# P_OPTS = SRC_P_OPTS WAY$(_way)_P_OPTS EXTRA_P_OPTS
-#
-# where the variables on the right hand side are set by the user or
-# some other Makefile. They have the following intended uses:
-#
-# SRC_P_OPTS Source-tree options for P
-# WAY$(_way)_P_OPTS Source-tree options for P specific to $(way)
-# EXTRA_P_OPTS Command-line options for P
-#
-# and for some programs
-#
-# $(HcFlavour)_P_OPTS Compiler-specific options for P
-# $($*_P_OPTS) Target specific options for P
-#
-# All these options should be set with
-# thing += extra-options
-# in case someone higher up the include hierarchy has already added some
-
-# Which class of compiler are we aiming at? (GHC, NHC or HUGS)
-ifeq "$(HcFlavour)" ""
-HcFlavour = GHC
-endif
-
-#################################################################################
-#
-# Absolutely standard glue
-#
-#################################################################################
-
-# All the standard gluing together, as in the comment right at the front
-
-
-HC_OPTS = $(BOOTSTRAPPING_PACKAGE_CONF_HC_OPTS) $(SRC_HC_OPTS) $(WAY$(_way)_HC_OPTS) $($*_HC_OPTS) $(EXTRA_HC_OPTS)
-HC_POST_OPTS = $(SRC_HC_POST_OPTS) $(WAY$(_way)_HC_POST_OPTS) $($*_HC_POST_OPTS) $(EXTRA_HC_POST_OPTS)
-HC_PRE_OPTS = $(SRC_HC_PRE_OPTS) $(WAY$(_way)_HC_PRE_OPTS) $($*_HC_PRE_OPTS) $(EXTRA_HC_PRE_OPTS)
-
-ILX2IL_OPTS = $(SRC_ILX2IL_OPTS) $(WAY$(_way)_ILX2IL_OPTS) $($*_ILX2IL_OPTS) $(EXTRA_ILX2IL_OPTS)
-ILASM_OPTS = $(SRC_ILASM_OPTS) $(WAY$(_way)_ILASM_OPTS) $($*_ILASM_OPTS) $(EXTRA_ILASM_OPTS)
-
-RUNTEST_OPTS = $(SRC_RUNTEST_OPTS) $(WAY$(_way)_RUNTEST_OPTS) \
- $($*_RUNTEST_OPTS) $(EXTRA_RUNTEST_OPTS)
-
-ALEX_OPTS = $(SRC_ALEX_OPTS) $($(HcFlavour)_ALEX_OPTS) $(WAY$(_way)_ALEX_OPTS) $($*_ALEX_OPTS) $(EXTRA_ALEX_OPTS)
-AR_OPTS = $(SRC_AR_OPTS) $(WAY$(_way)_AR_OPTS) $(EXTRA_AR_OPTS)
-AS_OPTS = $(SRC_AS_OPTS) $(WAY$(_way)_AS_OPTS) $(EXTRA_AS_OPTS)
-BLD_DLL_OPTS = $(SRC_BLD_DLL_OPTS) $(WAY$(_way)_BLD_DLL_OPTS) $($*_HC_OPTS) $(EXTRA_BLD_DLL_OPTS)
-CPP_OPTS = $(SRC_CPP_OPTS) $(WAY$(_way)_CPP_OPTS) $(EXTRA_CPP_OPTS)
-CTAGS_OPTS = $(SRC_CTAGS_OPTS) $(WAY$(_way)_CTAGS_OPTS) $(EXTRA_CTAGS_OPTS)
-CC_OPTS = $(SRC_CC_OPTS) $(WAY$(_way)_CC_OPTS) $($*_CC_OPTS) $(EXTRA_CC_OPTS)
-FLEX_OPTS = $(SRC_FLEX_OPTS) $(WAY$(_way)_FLEX_OPTS) $(EXTRA_FLEX_OPTS)
-HADDOCK_OPTS = $(SRC_HADDOCK_OPTS) $(WAY$(_way)_HADDOCK_OPTS) $($*_HADDOCK_OPTS) $(EXTRA_HADDOCK_OPTS)
-HAPPY_OPTS = $(SRC_HAPPY_OPTS) $($(HcFlavour)_HAPPY_OPTS) $(WAY$(_way)_HAPPY_OPTS) $($*_HAPPY_OPTS) $(EXTRA_HAPPY_OPTS)
-GC_OPTS = $(SRC_GC_OPTS) $(WAY$(_way)_GC_OPTS) $($*_GC_OPTS) $(EXTRA_GC_OPTS)
-HSTAGS_OPTS = $(SRC_HSTAGS_OPTS) $(WAY$(_way)_HSTAGS_OPTS) $(EXTRA_HSTAGS_OPTS)
-HSC2HS_OPTS = $(SRC_HSC2HS_OPTS) $($(HcFlavour)_HSC2HS_OPTS) $(WAY$(_way)_HSC2HS_OPTS) $(EXTRA_HSC2HS_OPTS)
-INSTALL_OPTS = $(SRC_INSTALL_OPTS) $(WAY$(_way)_INSTALL_OPTS) $(EXTRA_INSTALL_OPTS)
-INSTALL_BIN_OPTS = $(INSTALL_OPTS) $(SRC_INSTALL_BIN_OPTS)
-LD_OPTS = $(SRC_LD_OPTS) $(WAY$(_way)_LD_OPTS) $(EXTRA_LD_OPTS)
-LINT_OPTS = $(SRC_LINT_OPTS) $(WAY$(_way)_LINT_OPTS) $(EXTRA_LINT_OPTS)
-HEVEA_OPTS = $(SRC_HEVEA_OPTS) $(WAY$(_way)_HEVEA_OPTS) $(EXTRA_HEVEA_OPTS)
-HACHA_OPTS = $(SRC_HACHA_OPTS) $(WAY$(_way)_HACHA_OPTS) $(EXTRA_HACHA_OPTS)
-LIT2CHANGELOG_OPTS = $(SRC_LIT2CHANGELOG_OPTS) $(WAY$(_way)_LIT2CHANGELOG_OPTS) \
- $(EXTRA_LIT2CHANGELOG_OPTS)
-LIT2HTML_OPTS = $(SRC_LIT2HTML_OPTS) $(WAY$(_way)_LIT2HTML_OPTS) $(EXTRA_LIT2HTML_OPTS)
-LIT2LATEX_OPTS = $(SRC_LIT2LATEX_OPTS) $(WAY$(_way)_LIT2LATEX_OPTS) $(EXTRA_LIT2LATEX_OPTS)
-LIT2PGM_OPTS = $(SRC_LIT2PGM_OPTS) $(WAY$(_way)_LIT2PGM_OPTS) $(EXTRA_LIT2PGM_OPTS)
-MKDEPENDC_OPTS = $(SRC_MKDEPENDC_OPTS) $(WAY$(_way)_MKDEPENDC_OPTS) $(EXTRA_MKDEPENDC_OPTS)
-MKDEPENDHS_OPTS = $(BOOTSTRAPPING_PACKAGE_CONF_MKDEPENDHS_OPTS) \
- $(SRC_MKDEPENDHS_OPTS) $(WAY$(_way)_MKDEPENDHS_OPTS) \
- $(EXTRA_MKDEPENDHS_OPTS)
-MKDEPENDLIT_OPTS = $(SRC_MKDEPENDLIT_OPTS) $(WAY$(_way)_MKDEPENDLIT_OPTS) \
- $(EXTRA_MKDEPENDLIT_OPTS)
-XSLTPROC_OPTS = $(WAY$(_way)_XSLTPROC_OPTS) $(EXTRA_XSLTPROC_OPTS)
-FOP_OPTS = $(WAY$(_way)_FOP_OPTS) $(EXTRA_FOP_OPTS)
-UNLIT_OPTS = $(SRC_UNLIT_OPTS) $(WAY$(_way)_UNLIT_OPTS) $(EXTRA_UNLIT_OPTS)
-ZIP_OPTS = $(SRC_ZIP_OPTS) $(EXTRA_ZIP_OPTS)
-
-# Version of CC_OPTS to use when GHC is the C compiler
-GHC_CC_OPTS = $(addprefix -optc, $(CC_OPTS)) $(HC_OPTS)
diff --git a/mk/package.mk b/mk/package.mk
deleted file mode 100644
index 079e4f6a53..0000000000
--- a/mk/package.mk
+++ /dev/null
@@ -1,315 +0,0 @@
-# -----------------------------------------------------------------------------
-# $Id: package.mk,v 1.55 2005/05/13 10:05:33 krasimir Exp $
-
-ifneq "$(PACKAGE)" ""
-
-# -----------------------------------------------------------------------------
-# Directory layouts, installation etc.
-
-# Here Windows & Unix differ. On Windows, the value of $(prefix) is known
-# to the compiler, and spliced into package.conf in place of $topdir at
-# runtime.
-#
-# On Unix, we only use absolute paths in package.conf.
-#
-
-ifeq "$(Windows)" "YES"
-
-PKG_LIBDIR = $$topdir
-PKG_DATADIR = $$topdir
-
-else
-
-PKG_LIBDIR = $(libdir)
-PKG_DATADIR = $(datadir)
-
-endif # Unix
-
-IMPORT_DIR_INSTALLED = $(PKG_LIBDIR)/imports
-IMPORT_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
-
-INCLUDE_DIR_INSTALLED = $(PKG_LIBDIR)/include
-INCLUDE_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/include
-
-LIB_DIR_INSTALLED = $(PKG_LIBDIR)
-LIB_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
-
-DATA_DIR_INSTALLED = $(PKG_DATADIR)
-DATA_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)
-
-HTML_DIR_INPLACE = $(FPTOOLS_TOP_ABS)/libraries/$(PACKAGE)/html
-HTML_DIR_INSTALLED = $(PKG_DATADIR)/html/libraries/$(PACKAGE)
-
-HADDOCK_IFACE_INPLACE = $(HTML_DIR_INPLACE)/$(PACKAGE).haddock
-HADDOCK_IFACE_INSTALLED = $(HTML_DIR_INSTALLED)/$(PACKAGE).haddock
-
-# -----------------------------------------------------------------------------
-# Build the package configuration file and tell the compiler about it.
-
-# We want to build two versions of the package configuration: one for use
-# in the
-
-ifeq "$(way)" ""
-
-PACKAGE_CPP_OPTS += -I$(GHC_INCLUDE_DIR) -Iinclude
-
-PACKAGE_CPP_OPTS += -DPACKAGE=${PACKAGE}
-PACKAGE_CPP_OPTS += -DVERSION=${VERSION}
-
-PACKAGE_CPP_OPTS += -DPKG_LIBDIR='"$(PKG_LIBDIR)"'
-PACKAGE_CPP_OPTS += -DPKG_DATADIR='"$(PKG_DATADIR)"'
-
-package.conf.inplace : package.conf.in
- $(CPP) $(RAWCPP_FLAGS) -P \
- -DIMPORT_DIR='"$(IMPORT_DIR_INPLACE)"' \
- -DLIB_DIR='"$(LIB_DIR_INPLACE)"' \
- -DINCLUDE_DIR='"$(INCLUDE_DIR_INPLACE)"' \
- -DDATA_DIR='"$(DATA_DIR_INPLACE)"' \
- -DHTML_DIR='"$(HTML_DIR_INPLACE)"' \
- -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INPLACE)"' \
- -DFPTOOLS_TOP_ABS='"${FPTOOLS_TOP_ABS}"' \
- -x c $(PACKAGE_CPP_OPTS) $< | \
- grep -v '^#pragma GCC' | \
- sed -e 's/""//g' -e 's/:[ ]*,/: /g' >$@
-
-install::
- $(CPP) $(RAWCPP_FLAGS) -P -DINSTALLING \
- -DIMPORT_DIR='"$(IMPORT_DIR_INSTALLED)"' \
- -DLIB_DIR='"$(LIB_DIR_INSTALLED)"' \
- -DINCLUDE_DIR='"$(INCLUDE_DIR_INSTALLED)"' \
- -DDATA_DIR='"$(DATA_DIR_INSTALLED)"' \
- -DHTML_DIR='"$(HTML_DIR_INSTALLED)"' \
- -DHADDOCK_IFACE='"$(HADDOCK_IFACE_INSTALLED)"' \
- -I../includes \
- -x c $(PACKAGE_CPP_OPTS) package.conf.in \
- | grep -v '^#pragma GCC' \
- | sed -e 's/""//g' -e 's/:[ ]*,/: /g' \
- | $(GHC_PKG_INSTALL_PROG) --global-conf $(DESTDIR)$(datadir)/package.conf update - --force
-
-GHC_PKG_INSTALL_PROG = $(FPTOOLS_TOP_ABS)/utils/ghc-pkg/dist-install/build/ghc-pkg/ghc-pkg
-
-# we could be more accurate here and add a dependency on
-# driver/package.conf, but that doesn't work too well because of
-# make's limited accuracy with modification times: when doing 'make
-# boot' in multiple packages, make won't detect that the package
-# configuration needs updating if it was updated already in the last
-# second.
-#
-# The stamp file goes in $(GHC_DRIVER_DIR), so that if someone happens
-# to 'make clean' in ghc without cleaning in libraries too, the packages
-# will be correctly re-installed.
-#
-
-STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
-CLEAN_FILES += $(STAMP_PKG_CONF)
-
-ifneq "$(BootingFromHc)" "YES"
-boot all :: $(STAMP_PKG_CONF)
-endif
-
-$(STAMP_PKG_CONF) : package.conf.inplace
- $(GHC_PKG_INPLACE) update - --force-files <package.conf.inplace
- @touch $(STAMP_PKG_CONF)
-
-CLEAN_FILES += package.conf.inplace
-
-endif # $(way) == ""
-
-# -----------------------------------------------------------------------------
-# Building the static library libHS<pkg>.a
-
-SRC_HSC2HS_OPTS += -I.
-
-ifneq "$(NO_SET_HC)" "YES"
-HC = $(GHC_INPLACE)
-BOOTSTRAPPING_PACKAGE_CONF_HC_OPTS =
-endif
-IGNORE_PACKAGE_FLAG = -package-name $(PACKAGE)-$(VERSION)
-
-ifeq "$(NON_HS_PACKAGE)" ""
-SRC_HC_OPTS += $(IGNORE_PACKAGE_FLAG)
-SRC_HC_OPTS += $(GhcLibHcOpts)
-SRC_HC_OPTS += $(patsubst %, -package %, $(PACKAGE_DEPS))
-endif
-
-# -XGenerics switches on generation of support code for
-# derivable type classes. This is now off by default,
-# but we switch it on for the libraries so that we generate
-# the code in case someone importing wants it.
-ifeq "$(NON_HS_PACKAGE)" ""
-SRC_HC_OPTS += -XGenerics
-endif
-
-ifndef DONT_WANT_STD_LIBRARY
-ifndef LIBRARY
-ifeq "$(_way:%_dyn=YES)" "YES"
-LIBRARY = libHS$(PACKAGE)$(_way:%_dyn=%)-ghc$(ProjectVersion)$(soext)
-else
-LIBRARY = libHS$(PACKAGE)$(_way).a
-endif
-endif
-endif
-
-ifeq "$(WAYS)" ""
-WAYS = $(GhcLibWays)
-endif
-
-ifdef LIBRARY
-all :: $(LIBRARY)
-
-# POSSIBLE alternative version using --make:
-#
-# lib : $(HS_SRCS)
-# $(GHC_INPLACE) $(HC_OPTS) --make $(HS_SRCS)
-#
-# $(LIBNAME) : lib
-# $(RM) $@
-# $(AR) $(AR_OPTS) $@ $(HS_OBJS)
-# $(RANLIB) $@
-#
-# %.o : %.hs
-# $(GHC_INPLACE) $(HC_OPTS) --make $<
-# %.o : %.lhs
-# $(GHC_INPLACE) $(HC_OPTS) --make $<
-
-# -----------------------------------------------------------------------------
-# Installation; need to install .hi files as well as libraries
-
-ifeq "$(DLLized)" "YES"
-INSTALL_PROGS += $(DLL_NAME)
-INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
-endif
-endif
-
-# The interface files are put inside the $(libdir), since they
-# might (potentially) be platform specific..
-
-ifeq "$(HIERARCHICAL_LIB)" "YES"
-ifacedir = $(libdir)/imports
-else
-ifacedir = $(libdir)/hslibs-imports/$(PACKAGE)
-endif
-
-# If the lib consists of a hierachy of modules, we must retain the directory
-# structure when we install the interfaces.
-ifeq "$(HIERARCHICAL_LIB)" "YES"
-INSTALL_IFACES_WITH_DIRS += $(HS_IFACES)
-ifneq "$(ALL_DIRS)" ""
-install ::
- @for i in $(ALL_DIRS); do \
- $(INSTALL_DIR) $(ifacedir)/$$i; \
- done
-endif
-else
-INSTALL_IFACES += $(HS_IFACES)
-endif
-
-# -----------------------------------------------------------------------------
-# Dependencies
-
-MKDEPENDHS = $(GHC_INPLACE)
-
-SRC_MKDEPENDC_OPTS += $(addprefix -I,$(ALL_DIRS))
-SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
-
-endif # $(PACKAGE) != ""
-
-#--------------------------------------------------------------
-# Installation
-
-ifneq "$(NO_INSTALL_LIBRARY)" "YES"
-INSTALL_LIBS += $(LIBRARY) $(GHCI_LIBRARY)
-endif
-
-#--------------------------------------------------------------
-# Building dynamically-linkable libraries for GHCi
-#
-# Build $(GHCI_LIBRARY) whenever we build $(LIBRARY)
-#
-# Why? GHCi can only link .o files (at the moment), not .a files
-# so we have to build libFoo.o as well as libFoo.a
-#
-# Furthermore, GHCi currently never loads
-# profiling libraries (or other non-std ways)
-
-ifneq "$(LIBRARY)" ""
-
-ifeq "$(way)" ""
-ifeq "$(GhcWithInterpreter)" "YES"
-
-ifndef GHCI_LIBRARY
-GHCI_LIBRARY = $(patsubst lib%.a,%.o,$(LIBRARY))
-endif
-
-CLEAN_FILES += $(GHCI_LIBRARY)
-
-all :: $(GHCI_LIBRARY)
-
-ifneq "$(DONT_WANT_STD_GHCI_LIB_RULE)" "YES"
-# If you don't want to build GHCI_LIBRARY the 'standard' way,
-# set DONT_WANT_STD_GHCI_LIB_RULE to YES. The Prelude and
-# hslibs/Win32 uses this 'feature', which will go away soon
-# when we can use a "fixed" ld.
-#
-$(GHCI_LIBRARY) : $(LIBOBJS)
- $(LD) -r $(LD_X) -o $@ $(STUBOBJS) $(LIBOBJS)
-
-endif # DONT_WANT_STD_GHCI_LIB_RULE
-endif # GhcWithInterpreter
-endif # way
-endif # $(LIBRARY) /= ""
-
-# -----------------------------------------------------------------------------
-# Doc building with Haddock
-
-ifneq "$(PACKAGE)" ""
-ifeq "$(HADDOCK_DOCS)" "YES"
-
-HS_PPS = $(addsuffix .raw-hs, $(basename $(filter-out $(EXCLUDED_HADDOCK_SRCS), $(HS_SRCS)))) $(EXTRA_HADDOCK_SRCS)
-
-HTML_DIR = ../html-docs/$(PACKAGE)
-HTML_DOC = $(HTML_DIR)/haddock.css $(HTML_DIR)/haddock.js
-
-ifneq "$(HS_PPS)" ""
-
-CLEAN_FILES += $(HS_PPS) $(addsuffix .tmp, $(HS_SRCS))
-
-html :: $(HTML_DOC)
-
-extraclean ::
- $(RM) -rf $(HTML_DIR)
-
-$(HTML_DOC) : $(HS_PPS)
- @$(INSTALL_DIR) $(HTML_DIR)
- $(HADDOCK) $(HADDOCK_OPTS) -h -o $(HTML_DIR) $(HS_PPS) \
- --package=$(PACKAGE) \
- --dump-interface=$(PACKAGE).haddock \
- --use-index=../doc-index.html --use-contents=../index.html \
- --source-module=$(PackageSourceURL) \
- $(foreach pkg, $(PACKAGE_DEPS), \
- --read-interface=../$(pkg),../$(pkg)/$(pkg).haddock)
-
-CLEAN_FILES += $(PACKAGE).haddock
-
-%.raw-hs : %.lhs
- $(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@
-
-%.raw-hs : %.hs
- $(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@
-
-HTML_INSTALL_DIR = $(DESTDIR)$(htmldir)/libraries/html/$(PACKAGE)
-
-install-docs :: $(HTML_DOC)
- @$(INSTALL_DIR) $(HTML_INSTALL_DIR)
- for i in $(HTML_DIR)/*; do \
- echo $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
- $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(HTML_INSTALL_DIR); \
- done; \
- $(INSTALL_DATA) $(INSTALL_OPTS) $(PACKAGE).haddock $(HTML_INSTALL_DIR); \
-
-endif # HS_PPS
-endif # HADDOCK_DOCS
-endif # $(PACKAGE) /= ""
-
-# -----------------------------------------------------------------------------
-
diff --git a/mk/paths.mk b/mk/paths.mk
deleted file mode 100644
index 4cb2bbf8c8..0000000000
--- a/mk/paths.mk
+++ /dev/null
@@ -1,277 +0,0 @@
-################################################################################
-#
-# paths.mk
-#
-# This file defines Make variables for standard directories
-# and file lists
-#
-################################################################################
-
-################################################################################
-#
-# Standard variable names
-#
-################################################################################
-# The fptools mk setup defines a set of standard names which are used
-# by the standard targets provided by mk. One example of this is the
-# use of standard names for specifying what files to compile, their
-# intermediate/object code, and the name of the final
-# executable. Based on the settings of these variables, the standard
-# targets will generate/expand rules that automatically compile and
-# link your program.
-#
-# The general rules:
-#
-# SRCS - sources, might be prefixed to indicate what type of source
-# they are.
-# OBJS - object files (possibly prefixed).
-#
-# PROG - name of final executable
-#
-# We attempt to automatically devine the list of sources $(SRCS) to
-# compile by looking in the current directory (and possibly other
-# directories which may be specified by setting the $(ALL_DIRS)
-# variable). This is complicated by the fact that some files are
-# derived from other files: eg. .hsc files give rise to -hsc.c and
-# -hsc.h files, .ly files give rise to .hs files, and .hs files give
-# rise to .hc files sometimes.
-
-# So we figure out the sources in three stages: first figure out what
-# sources we can find (this is $(ALL_SRCS)). Then figure out all the
-# "derived" sources (eg. A.hsc generates A.hs and A_hsc.c), and
-# finally put all these together and remove duplicates (GNU make's
-# handy sort function does the duplicate removing).
-
-# HS_SRCS: list of Haskell modules you want to compile.
-# (also use by depend rule).
-# HS_OBJS: list of corresponding object files
-# HS_PROG: program that is ultimately linked.
-# HS_IFACES: list of interface files generated
-# (caveat: assuming no funny use of -hisuf and that
-# file name and module name match)
-
-ALL_SRCS = $(wildcard $(patsubst ./%, %, \
- $(patsubst %,%/*.hs, . $(ALL_DIRS)) \
- $(patsubst %,%/*.lhs, . $(ALL_DIRS)) \
- $(patsubst %,%/*.hs-boot, . $(ALL_DIRS)) \
- $(patsubst %,%/*.lhs-boot, . $(ALL_DIRS)) \
- $(patsubst %,%/*.y, . $(ALL_DIRS)) \
- $(patsubst %,%/*.ly, . $(ALL_DIRS)) \
- $(patsubst %,%/*.x, . $(ALL_DIRS)) \
- $(patsubst %,%/*.c, . $(ALL_DIRS)) \
- $(patsubst %,%/*.hc, . $(ALL_DIRS)) \
- $(patsubst %,%/*.S, . $(ALL_DIRS)) \
- $(patsubst %,%/*.prl, . $(ALL_DIRS)) \
- $(patsubst %,%/*.lprl, . $(ALL_DIRS)) \
- $(patsubst %,%/*.lit, . $(ALL_DIRS)) \
- $(patsubst %,%/*.verb, . $(ALL_DIRS)) \
- $(patsubst %,%/*.hsc, . $(ALL_DIRS)) \
- $(patsubst %,%/*.gc, . $(ALL_DIRS)) \
- )) $(EXTRA_SRCS)
-
-# ALL_SRCS is computed once and for all into PRE_SRCS at the top of
-# target.mk. Otherwise, we end up re-computing ALL_SRCS every time it
-# is expanded (it is used in several variables below, and these
-# variables are used in several others, etc.), which can really slow
-# down make.
-
-PRE_HS_SRCS = $(filter %.hs, $(PRE_SRCS))
-PRE_LHS_SRCS = $(filter %.lhs, $(PRE_SRCS))
-
-PRE_HS_BOOT_SRCS = $(filter %.hs-boot, $(PRE_SRCS)) \
- $(filter %.lhs-boot, $(PRE_SRCS))
-
-GC_SRCS = $(filter %.gc, $(PRE_SRCS))
-HSC_SRCS = $(filter %.hsc, $(PRE_SRCS))
-HAPPY_Y_SRCS = $(filter %.y, $(PRE_SRCS))
-HAPPY_LY_SRCS = $(filter %.ly, $(PRE_SRCS))
-HAPPY_SRCS = $(HAPPY_Y_SRCS) $(HAPPY_LY_SRCS)
-ALEX_SRCS = $(filter %.x, $(PRE_SRCS))
-
-DERIVED_GC_SRCS = $(patsubst %.gc, %.hs, $(GC_SRCS)) \
- $(patsubst %.gc, %_stub_ffi.c, $(GC_SRCS)) \
- $(patsubst %.gc, %_stub_ffi.h, $(GC_SRCS))
-
-DERIVED_HSC_SRCS = $(patsubst %.hsc, %.hs, $(HSC_SRCS)) \
- $(patsubst %.hsc, %_hsc.c, $(HSC_SRCS)) \
- $(patsubst %.hsc, %_hsc.h, $(HSC_SRCS)) \
- $(patsubst %.hsc, %.hc, $(HSC_SRCS))
-
-DERIVED_HAPPY_SRCS = $(patsubst %.y, %.hs, $(HAPPY_Y_SRCS)) \
- $(patsubst %.ly, %.hs, $(HAPPY_LY_SRCS))
-
-DERIVED_ALEX_SRCS = $(patsubst %.x, %.hs, $(ALEX_SRCS))
-
-DERIVED_HC_SRCS = $(patsubst %.hs, %.hc, $(PRE_HS_SRCS)) \
- $(patsubst %.lhs, %.hc, $(PRE_LHS_SRCS))
-
-DERIVED_SRCS = $(DERIVED_GC_SRCS) \
- $(DERIVED_HSC_SRCS) \
- $(DERIVED_HAPPY_SRCS) \
- $(DERIVED_ALEX_SRCS) \
- $(DERIVED_HC_SRCS)
-
-# EXCLUDED_SRCS can be set in the Makefile, otherwise it defaults to empty.
-EXCLUDED_GC_SRCS = $(filter %.gc, $(EXCLUDED_SRCS))
-EXCLUDED_HSC_SRCS = $(filter %.hsc, $(EXCLUDED_SRCS))
-EXCLUDED_HAPPY_Y_SRCS = $(filter %.y, $(EXCLUDED_SRCS))
-EXCLUDED_HAPPY_LY_SRCS = $(filter %.ly, $(EXCLUDED_SRCS))
-EXCLUDED_HAPPY_SRCS = $(EXCLUDED_HAPPY_Y_SRCS) $(EXCLUDED_HAPPY_LY_SRCS)
-EXCLUDED_ALEX_SRCS = $(filter %.x, $(EXCLUDED_SRCS))
-EXCLUDED_HS_SRCS = $(filter %.hs, $(EXCLUDED_SRCS))
-EXCLUDED_LHS_SRCS = $(filter %.lhs, $(EXCLUDED_SRCS))
-EXCLUDED_DERIVED_SRCS = $(patsubst %.hsc, %.hs, $(EXCLUDED_HSC_SRCS)) \
- $(patsubst %.hsc, %_hsc.h, $(EXCLUDED_HSC_SRCS)) \
- $(patsubst %.hsc, %_hsc.c, $(EXCLUDED_HSC_SRCS)) \
- $(patsubst %.hsc, %.hc, $(EXCLUDED_HSC_SRCS)) \
- $(patsubst %.gc, %_stub_ffi.c, $(EXCLUDED_GC_SRCS)) \
- $(patsubst %.gc, %_stub_ffi.h, $(EXCLUDED_GC_SRCS)) \
- $(patsubst %.y, %.hs, $(EXCLUDED_HAPPY_Y_SRCS)) \
- $(patsubst %.ly, %.hs, $(EXCLUDED_HAPPY_LY_SRCS)) \
- $(patsubst %.x, %.hs, $(EXCLUDED_ALEX_SRCS)) \
- $(patsubst %.hs, %.hc, $(EXCLUDED_HS_SRCS)) \
- $(patsubst %.lhs, %.hc, $(EXCLUDED_LHS_SRCS)) \
- $(patsubst %.hs, %_stub.c, $(EXCLUDED_HS_SRCS)) \
- $(patsubst %.lhs, %_stub.c, $(EXCLUDED_LHS_SRCS))
-
-# Exclude _hsc.c files; they get built as part of the cbits library,
-# not part of the main library
-
-CLOSED_EXCLUDED_SRCS = $(sort $(EXCLUDED_SRCS) $(EXCLUDED_DERIVED_SRCS))
-
-SRCS = $(filter-out $(CLOSED_EXCLUDED_SRCS), \
- $(sort $(PRE_SRCS) $(DERIVED_SRCS)))
-
-HS_SRCS = $(filter %.lhs %.hs, $(sort $(SRCS) $(BOOT_SRCS)))
-HS_OBJS = $(addsuffix .$(way_)o,$(basename $(HS_SRCS)))
-HS_IFACES = $(addsuffix .$(way_)hi,$(basename $(HS_SRCS)))
-
-HI_BOOTS = $(patsubst %.hs-boot, %.$(way_)hi-boot, \
- $(patsubst %.lhs-boot, %.$(way_)hi-boot, $(PRE_HS_BOOT_SRCS)))
-
-O_BOOTS = $(patsubst %.hs-boot, %.$(way_)o-boot, \
- $(patsubst %.lhs-boot, %.$(way_)o-boot, $(PRE_HS_BOOT_SRCS)))
-
-GC_C_OBJS = $(addsuffix _stub_ffi.$(way_)o,$(basename $(filter %.gc,$(SRCS))))
-HSC_C_OBJS = $(addsuffix _hsc.$(way_)o,$(basename $(filter %.hsc,$(SRCS))))
-
-ifeq "$(BootingFromHc)" "NO"
-# We don't want to build the _stub.c files ourselves, unless we're
-# bootstrapping from .hc files.
-EXCLUDED_C_SRCS = $(patsubst %.lhs, %_stub.c, $(HS_SRCS)) \
- $(patsubst %.hs, %_stub.c, $(HS_SRCS)) \
- $(patsubst %.gc, %_stub_ffi.c, $(GC_SRCS)) \
- $(patsubst %.gc, %_stub_ffi.h, $(GC_SRCS))
-endif
-
-# These are droppings from hsc2hs - ignore them if we see them.
-EXCLUDED_C_SRCS += $(patsubst %.hsc, %_hsc_make.c, $(HSC_SRCS))
-
-C_SRCS = $(filter-out $(EXCLUDED_C_SRCS),$(filter %.c %.S,$(SRCS)))
-C_OBJS = $(addsuffix .$(way_)o,$(basename $(C_SRCS)))
-
-# SCRIPT_SRCS: list of raw script files (in literate form)
-# SCRIPT_OBJS: de-litted scripts
-SCRIPT_SRCS = $(filter %.lprl,$(SRCS))
-SCRIPT_OBJS = $(addsuffix .prl,$(basename $(SCRIPT_SRCS)))
-
-OBJS = $(HS_OBJS) $(C_OBJS) $(GC_C_OBJS)
-
-# The default is for $(LIBOBJS) to be the same as $(OBJS)
-LIBOBJS = $(OBJS)
-
-#
-# Note that as long as you use the standard variables for setting
-# which C & Haskell programs you want to work on, you don't have
-# to set any of the clean variables - the default should do the Right
-# Thing.
-#
-
-#------------------------------------------------------------------
-#
-# make depend defaults
-#
-# The default set of files for the dependency generators to work on
-# is just their source equivalents.
-#
-
-ifneq "$(BootingFromHc)" "YES"
-MKDEPENDHS_SRCS=$(HS_SRCS)
-else
-MKDEPENDHS_SRCS=
-endif
-
-MKDEPENDC_SRCS=$(C_SRCS)
-
-#------------------------------------------------------------------
-#
-# make TAGS defaults
-#
-# The default set of files for the TAGS file generators to work on
-# is just their source equivalents.
-#
-TAGS_HS_SRCS=$(HS_SRCS)
-TAGS_C_SRCS=$(C_SRCS)
-
-#------------------------------------------------------------------
-# Clean file make-variables.
-#
-# The following three variables are used to control
-# what gets removed when doing `make clean'
-#
-# MOSTLYCLEAN_FILES object code etc., but not stuff
-# that is slow to recompile and/or stable
-#
-# CLEAN_FILES all files that are created by running make.
-#
-# MAINTAINER_CLEAN_FILES also clean out machine-generated files
-# that may require extra tools to create.
-#
-#
-# NOTE: $(SCRIPT_OBJS) is not in MOSTLY_CLEAN_FILES, because in some
-# places in the tree it appears that we have source files in $(SCRIPT_OBJS).
-# Specifically glafp-utils/mkdependC/mkdependC.prl and others in driver/ and
-# possibly others elsewhere in the tree. ToDo: fix this properly.
-MOSTLY_CLEAN_FILES += $(HS_OBJS) $(C_OBJS) $(HSC_C_OBJS) $(GC_C_OBJS)
-CLEAN_FILES += $(HS_PROG) $(C_PROG) $(SCRIPT_LINK) \
- $(PROG) $(LIBRARY) a.out \
- $(DERIVED_HSC_SRCS) \
- $(DERIVED_GC_SRCS) \
- $(patsubst %,%/*.$(way_)hi, . $(ALL_DIRS)) \
- $(HI_BOOTS) $(O_BOOTS)
-
-# we delete *all* the .hi files we can find, rather than just
-# $(HS_IFACES), because stale interfaces left around by modules which
-# don't exist any more can screw up the build.
-
-# Don't clean the .hc files if we're bootstrapping
-ifneq "$(BootingFromHc)" "YES"
-CLEAN_FILES += $(DERIVED_HC_SRCS)
-endif
-
-DIST_CLEAN_FILES += .depend* *.hp *.prof
-
-MAINTAINER_CLEAN_FILES += $(BOOT_SRCS) $(DERIVED_HAPPY_SRCS) $(DERIVED_ALEX_SRCS)
-
-#
-# `Standard' set of files to clean out.
-#
-MOSTLY_CLEAN_FILES += \
- *.CKP *.ln *.BAK *.bak .*.bak *.o core a.out errs ,* *.a .emacs_* \
- tags TAGS *.ind *.ilg *.idx *.idx-prev *.aux *.aux-prev *.dvi *.log \
- *.toc *.lot *.lof *.blg *.cb *_stub.c *_stub.h *.raw_s *.a.list
-
-#------------------------------------------------------------------
-
-# Directory in which DLLs are dumped so as not to get picked up by running
-# programs (e.g. ghc or hsc) that run in the build tree
-
-DLL_PEN = $(FPTOOLS_TOP)/dll
-
-#------------------------------------------------------------------
-#
-# Stylesheet for HTML generated from DocBook XML
-#
-
-FPTOOLS_CSS = fptools.css
-FPTOOLS_CSS_ABS = $(FPTOOLS_TOP)/mk/$(FPTOOLS_CSS)
diff --git a/mk/project.mk.in b/mk/project.mk.in
new file mode 100644
index 0000000000..e5f64d01cf
--- /dev/null
+++ b/mk/project.mk.in
@@ -0,0 +1,143 @@
+# WARNING: mk/project.mk is automatically generated from mk/project.mk.in by
+# ./configure. Make sure you are editing mk/project.mk.in, not mk/project.mk.
+
+################################################################################
+#
+# GHC Version
+#
+
+# ProjectVersion is treated as a *string*
+# ProjectVersionInt is treated as an *integer* (for cpp defines)
+
+# 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
+
+################################################################################
+#
+# Global configuration options
+#
+################################################################################
+
+# 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
+
diff --git a/mk/recurse.mk b/mk/recurse.mk
deleted file mode 100644
index 2bb370deeb..0000000000
--- a/mk/recurse.mk
+++ /dev/null
@@ -1,101 +0,0 @@
-
-##################################################################
-#
-# Recursive stuff
-#
-##################################################################
-
-# Here are the diabolically clever rules that
-#
-# (a) for each "recursive target" <t>
-# propagates "make <t>" to directories in SUBDIRS
-#
-# (b) when SUBDIRS is empty,
-# for each "multi-way-target" <t>
-# calls "make way=w <t>" for each w in $(WAYS)
-#
-# This has the effect of making the standard target
-# in each of the specified ways (as well as in the normal way
-
-# Controlling variables
-# WAYS = extra (beyond the normal way) ways to build things in
-# SUBDIRS = subdirectories to recurse into
-
-# No ways, so iterate over the SUBDIRS
-
-# note about recursively invoking make: we'd like make to drop all the
-# way back to the top level if it fails in any of the
-# sub(sub-...)directories. This is done by setting the -e flag to the
-# shell during the loop, which causes an immediate failure if any of
-# the shell commands fail.
-
-# One exception: if the user gave the -i or -k flag to make in the
-# first place, we'd like to reverse this behaviour. So we check for
-# these flags, and set the -e flag appropriately. NOTE: watch out for
-# the --no-print-directory flag which is passed to recursive
-# invocations of make.
-#
-ifeq "$(way)" ""
-ifneq "$(SUBDIRS)" ""
-
-# we override the 'boot', 'all' and 'install' targets in the top
-# level Makefile. Some of the sub-projects also set 'boot' to empty.
-
-ifeq "$(NO_ALL_TARGET)" "YES"
-ALL_TARGET =
-else
-ALL_TARGET = all
-endif
-
-ifeq "$(NO_BOOT_TARGET)" "YES"
-BOOT_TARGET =
-else
-BOOT_TARGET = boot
-endif
-
-ifeq "$(NO_INSTALL_TARGET)" "YES"
-INSTALL_TARGET =
-INSTALL_DOCS_TARGET =
-else
-INSTALL_TARGET = install
-INSTALL_DOCS_TARGET = install-docs
-endif
-
-$(ALL_TARGET) docs runtests $(BOOT_TARGET) TAGS clean distclean mostlyclean maintainer-clean $(INSTALL_TARGET) $(INSTALL_DOCS_TARGET) html chm HxS ps dvi txt::
- @echo "------------------------------------------------------------------------"
- @echo "== Recursively making \`$@' in $(SUBDIRS) ..."
- @echo "PWD = $(shell pwd)"
- @echo "------------------------------------------------------------------------"
-# Don't rely on -e working, instead we check exit return codes from sub-makes.
- @case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
- if [ $$x_on_err -eq 0 ]; \
- then echo "Won't exit on error due to MFLAGS: ${MFLAGS}"; \
- fi; \
- for i in $(SUBDIRS); do \
- echo "------------------------------------------------------------------------"; \
- echo "== $(MAKE) $@ $(MFLAGS);"; \
- echo " in $(shell pwd)/$$i"; \
- echo "------------------------------------------------------------------------"; \
- $(MAKE) --no-print-directory -C $$i $(MFLAGS) $@ CLEAN_ALL_STAGES=YES; \
- if [ $$? -eq 0 -o $$x_on_err -eq 0 ]; \
- then echo "Finished making $@ in $$i": $$?; \
- else echo "Failed making $@ in $$i": $$?; exit 1; \
- fi; \
- done
- @echo "------------------------------------------------------------------------"
- @echo "== Finished making \`$@' in $(SUBDIRS) ..."
- @echo "PWD = $(shell pwd)"
- @echo "------------------------------------------------------------------------"
-
-endif
-endif
-
-#
-# Selectively building subdirectories.
-#
-#
-ifneq "$(SUBDIRS)" ""
-$(SUBDIRS) ::
- $(MAKE) -C $@ $(MFLAGS)
-endif
-
diff --git a/mk/sub-makefile.mk b/mk/sub-makefile.mk
new file mode 100644
index 0000000000..1e9cf2265d
--- /dev/null
+++ b/mk/sub-makefile.mk
@@ -0,0 +1,34 @@
+# This file is included by all the "stub makefiles" in every directory
+# in the tree except the root. Its job is to invoke $(MAKE) on the
+# top-level Makefile, but modifying the target so that it applies to
+# the current directory only.
+#
+# eg.
+# make foo.o ==> make -C $(TOP) dir/foo.o
+# make all ==> make -C $(TOP) all_dir
+# make clean ==> make -C $(TOP) clean_dir
+#
+
+# Important, otherwise we get silly built-in rules:
+.SUFFIXES:
+
+TOPMAKE = $(MAKE) -C $(TOP)
+
+default :
+ +$(TOPMAKE) all_$(dir)
+
+# We must not execute multiple recursive invocations of make in parallel.
+.NOTPARALLEL:
+
+# all comes first, we want it to be the default target
+STD_TARGETS = all clean distclean maintainer_clean install
+
+# The + tells make that we're recursively invoking make, otherwise 'make -j2'
+# goes wrong.
+$(STD_TARGETS):
+ +$(TOPMAKE) $@_$(dir)
+
+OTHERTARGETS=$(filter-out $(STD_TARGETS) $(SPEC_TARGETS),$(MAKECMDGOALS))
+.PHONY: $(OTHERTARGETS)
+$(OTHERTARGETS):
+ +$(TOPMAKE) $(dir)/$@
diff --git a/mk/suffix.mk b/mk/suffix.mk
deleted file mode 100644
index 762636aea1..0000000000
--- a/mk/suffix.mk
+++ /dev/null
@@ -1,392 +0,0 @@
-#################################################################################
-#
-# suffix.mk
-#
-# Suffix rules for fptools
-#
-#################################################################################
-
-#
-# This file contain the default suffix rules for all the fptools projects.
-#
-
-
-# No need to define .SUFFIXES because we don't use any suffix rules
-# Instead we use gmake's pattern rules exlusively
-
-.SUFFIXES:
-
-# This declaration tells GNU make to delete the target if it has
-# changed and the command which created it exited with a non-zero exit
-# code.
-
-.DELETE_ON_ERROR:
-
-#-----------------------------------------------------------------------------
-# Haskell Suffix Rules
-
-# The $(odir) support is for building GHC, where we need to build three
-# different versions from the same sources. See compiler/Makefile.
-ifneq "$(odir)" ""
-odir_ = $(odir)/
-else
-odir_ =
-endif
-
-# Turn off all the Haskell suffix rules if we're booting from .hc
-# files. The file bootstrap.mk contains alternative suffix rules in
-# this case.
-ifneq "$(BootingFromHc)" "YES"
-
-$(odir_)%.$(way_)o : %.hs
- $(HC_PRE_OPTS)
- $(HC) $(HC_OPTS) -c $< -o $@ -ohi $(basename $@).$(way_)hi
- $(HC_POST_OPTS)
-
-$(odir_)%.$(way_)o : %.lhs
- $(HC_PRE_OPTS)
- $(HC) $(HC_OPTS) -c $< -o $@ -ohi $(basename $@).$(way_)hi
- $(HC_POST_OPTS)
-
-# Now the rules for hs-boot files.
-# Note that they do *not* do teh HS_PRE_OPTS / HS_POST_OPTS stuff,
-# (which concerns splitting) because they don't generate .o files
-$(odir_)%.$(way_)o-boot : %.hs-boot
- $(HC) $(HC_OPTS) -c $< -o $@ -ohi $(basename $@).$(way_)hi-boot
-
-$(odir_)%.$(way_)o-boot : %.lhs-boot
- $(HC) $(HC_OPTS) -c $< -o $@ -ohi $(basename $@).$(way_)hi-boot
-
-$(odir_)%.$(way_)hc : %.lhs
- $(RM) $@
- $(HC) $(HC_OPTS) -C $< -o $@
-
-$(odir_)%.$(way_)hc : %.hs
- $(RM) $@
- $(HC) $(HC_OPTS) -C $< -o $@
-
-$(odir_)%.$(way_)o : %.$(way_)hc
- $(HC_PRE_OPTS)
- $(HC) $(HC_OPTS) -c $< -o $@
- $(HC_POST_OPTS)
-
-$(odir_)%.$(way_)o : %.hc
- $(HC_PRE_OPTS)
- $(HC) $(HC_OPTS) -c $< -o $@
- $(HC_POST_OPTS)
-
-$(odir_)%.$(way_)s : %.$(way_)hc
- $(HC_PRE_OPTS)
- $(HC) $(HC_OPTS) -S $< -o $@
- $(HC_POST_OPTS)
-
-$(odir_)%.$(way_)hc : %.lhc
- @$(RM) $@
- $(UNLIT) $< $@
- $(GENERATED_FILE) $@
-
-
-# Here's an interesting rule!
-# The .hi file depends on the .o file,
-# so if the .hi file is dated earlier than the .o file (commonly the case,
-# when interfaces are stable) this rule just makes sure that the .o file,
-# is up to date. Then it does nothing to generate the .hi file from the
-# .o file, because the act of making sure the .o file is up to date also
-# updates the .hi file (if necessary).
-
-%.$(way_)hi : %.$(way_)o
- @if [ ! -f $@ ] ; then \
- echo Panic! $< exists, but $@ does not.; \
- exit 1; \
- else exit 0 ; \
- fi
-
-%.$(way_)hi-boot : %.$(way_)o-boot
- @if [ ! -f $@ ] ; then \
- echo Panic! $< exists, but $@ does not.; \
- exit 1; \
- else exit 0 ; \
- fi
-
-$(odir_)%.$(way_)hi : %.$(way_)hc
- @if [ ! -f $@ ] ; then \
- echo Panic! $< exists, but $@ does not.; \
- exit 1; \
- else exit 0 ; \
- fi
-
-else # BootingFromHc
-
-# -----------------------------------------------------------------------------
-# suffix rules for building a .o from a .hc file in bootstrap mode.
-
-ifeq "$(BootingFromUnregisterisedHc)" "YES"
-
-# without mangling
-
-$(odir_)%.o : %.hc
- $(CC) -x c $< -o $@ -c -O $(HC_BOOT_CC_OPTS) -I. `echo $(patsubst -monly-%-regs, -DSTOLEN_X86_REGS=%, $(filter -monly-%-regs, $($*_HC_OPTS))) | sed 's/^$$/-DSTOLEN_X86_REGS=4/'`
-
-else
-
-# with mangling
-
-$(odir_)%.raw_s : %.hc
- $(CC) -x c $< -o $@ -S -O $(HC_BOOT_CC_OPTS) -I. `echo $(patsubst -monly-%-regs, -DSTOLEN_X86_REGS=%, $(filter -monly-%-regs, $($*_HC_OPTS))) | sed 's/^$$/-DSTOLEN_X86_REGS=4/'`
-
-$(odir_)%.s : $(odir_)%.raw_s
- $(MANGLER) $< $@ $(patsubst -monly-%-regs, %, $(filter -monly-%-regs, $($*_HC_OPTS)))
-
-$(odir_)%.o : $(odir_)%.s
- $(CC) -c -o $@ $<
-
-endif # not BootingFromUnregisterisedHc
-
-endif # BootingFromHc
-
-#-----------------------------------------------------------------------------
-# Happy Suffix Rules
-#
-%.hs : %.ly
- $(HAPPY) $(HAPPY_OPTS) $<
-
-%.hs : %.y
- $(HAPPY) $(HAPPY_OPTS) $<
-
-#-----------------------------------------------------------------------------
-# Alex Suffix Rules
-#
-
-%.hs : %.x
- $(ALEX) $(ALEX_OPTS) $<
-
-#-----------------------------------------------------------------------------
-# hsc2hs Suffix Rules
-#
-ifneq "$(BootingFromHc)" "YES"
-%_hsc.c %_hsc.h %.hs : %.hsc
- $(HSC2HS_INPLACE) $(HSC2HS_OPTS) $<
- @touch $(patsubst %.hsc,%_hsc.c,$<)
-endif
-
-#-----------------------------------------------------------------------------
-# Green-card Suffix Rules
-#
-
-%.hs %_stub_ffi.c %_stub_ffi.h : %.gc
- $(GREENCARD) $(GC_OPTS) $<
-
-%.lhs : %.gc
- $(GREENCARD) $(GC_OPTS) $< -o $@
-
-%.gc : %.pgc
- $(CPP) $(GC_CPP_OPTS) $< | perl -pe 's#\\n#\n#g' > $@
-
-#-----------------------------------------------------------------------------
-# C-related suffix rules
-
-# UseGhcForCc is only relevant when not booting from HC files.
-ifeq "$(UseGhcForCc) $(BootingFromHc)" "YES NO"
-
-$(odir_)%.$(way_)o : %.c
- @$(RM) $@
- $(HC) $(GHC_CC_OPTS) -c $< -o $@
-
-$(odir_)%.$(way_)o : %.$(way_)s
- @$(RM) $@
- $(HC) $(GHC_CC_OPTS) -c $< -o $@
-
-$(odir_)%.$(way_)o : %.S
- @$(RM) $@
- $(HC) $(GHC_CC_OPTS) -c $< -o $@
-
-$(odir_)%.$(way_)s : %.c
- @$(RM) $@
- $(HC) $(GHC_CC_OPTS) -S $< -o $@
-
-else
-
-$(odir_)%.$(way_)o : %.c
- @$(RM) $@
- $(CC) $(CC_OPTS) -c $< -o $@
-
-$(odir_)%.$(way_)o : %.$(way_)s
- @$(RM) $@
- $(AS) $(AS_OPTS) -o $@ $<
-
-$(odir_)%.$(way_)o : %.S
- @$(RM) $@
- $(CC) $(CC_OPTS) -c $< -o $@
-
-$(odir_)%.$(way_)s : %.c
- @$(RM) $@
- $(CC) $(CC_OPTS) -S $< -o $@
-
-endif
-
-# stubs are automatically generated and compiled by GHC
-%_stub.$(way_)o: %.o
- @:
-
-# -----------------------------------------------------------------------------
-# Flex/lex
-
-%.c : %.flex
- @$(RM) $@
- $(FLEX) -t $(FLEX_OPTS) $< > $@
-%.c : %.lex
- @$(RM) $@
- $(FLEX) -t $(FLEX_OPTS) $< > $@
-
-#-----------------------------------------------------------------------------
-# Runtest rules for calling $(HC) on a single-file Haskell program
-
-%.runtest : %.hs
- $(TIME) $(RUNTEST) $(HC) $(RUNTEST_OPTS) $<
-
-#-----------------------------------------------------------------------------
-# DocBook XML suffix rules
-#
-
-%.html : %.xml
- $(XSLTPROC) --output $@ \
- --stringparam html.stylesheet $(FPTOOLS_CSS) \
- $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
- $(DIR_DOCBOOK_XSL)/html/docbook.xsl $<
- cp $(FPTOOLS_CSS_ABS) .
-
-%/index.html : %.xml
- $(RM) -rf $(dir $@)
- $(XSLTPROC) --stringparam base.dir $(dir $@) \
- --stringparam use.id.as.filename 1 \
- --stringparam html.stylesheet $(FPTOOLS_CSS) \
- $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
- $(DIR_DOCBOOK_XSL)/html/chunk.xsl $<
- cp $(FPTOOLS_CSS_ABS) $(dir $@)
-
-# Note: Numeric labeling seems to be uncommon for HTML Help
-%-htmlhelp/index.html : %.xml
- $(RM) -rf $(dir $@)
- $(XSLTPROC) --stringparam base.dir $(dir $@) \
- --stringparam manifest.in.base.dir 1 \
- --stringparam htmlhelp.chm "..\\"$(basename $<).chm \
- $(XSLTPROC_OPTS) \
- $(DIR_DOCBOOK_XSL)/htmlhelp/htmlhelp.xsl $<
-
-%-htmlhelp2/collection.HxC : %.xml
- $(RM) -rf $(dir $@)
- $(XSLTPROC) --stringparam base.dir $(dir $@) \
- --stringparam use.id.as.filename 1 \
- --stringparam manifest.in.base.dir 1 \
- $(XSLTPROC_OPTS) \
- $(DIR_DOCBOOK_XSL)/htmlhelp2/htmlhelp2.xsl $<
-
-# TODO: Detect hhc & Hxcomp via autoconf
-#
-# Two obstacles here:
-#
-# * The reason for the strange "if" below is that hhc returns 0 on error and 1
-# on success, the opposite of what shells and make expect.
-#
-# * There seems to be some trouble with DocBook indices, but the *.chm looks OK,
-# anyway, therefore we pacify make by "|| true". Ugly...
-#
-%.chm : %-htmlhelp/index.html
- ( cd $(dir $<) && if hhc htmlhelp.hhp ; then false ; else true ; fi ) || true
-
-%.HxS : %-htmlhelp2/collection.HxC
- ( cd $(dir $<) && if Hxcomp -p collection.HxC -o ../$@ ; then false ; else true ; fi )
-
-%.fo : %.xml
- $(XSLTPROC) --output $@ \
- --stringparam draft.mode no \
- $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
- $(DIR_DOCBOOK_XSL)/fo/docbook.xsl $<
-
-ifeq "$(FOP)" ""
-ifneq "$(PDFXMLTEX)" ""
-%.pdf : %.fo
- $(PDFXMLTEX) $<
- if grep "LaTeX Warning: Label(s) may have changed.Rerun to get cross-references right." $(basename $@).log > /dev/null ; then \
- $(PDFXMLTEX) $< ; \
- $(PDFXMLTEX) $< ; \
- fi
-endif
-else
-%.ps : %.fo
- $(FOP) $(FOP_OPTS) -fo $< -ps $@
-
-%.pdf : %.fo
- $(FOP) $(FOP_OPTS) -fo $< -pdf $@
-endif
-
-ifneq "$(XMLTEX)" ""
-%.dvi : %.fo
- $(XMLTEX) $<
- if grep "LaTeX Warning: Label(s) may have changed.Rerun to get cross-references right." $(basename $@).log > /dev/null ; then \
- $(XMLTEX) $< ; \
- $(XMLTEX) $< ; \
- fi
-endif
-
-#-----------------------------------------------------------------------------
-# Doc processing suffix rules
-#
-# ToDo: make these more robust
-#
-%.ps : %.dvi
- @$(RM) $@
- $(DVIPS) $< -o $@
-
-%.tex : %.tib
- @$(RM) $*.tex $*.verb-t.tex
- $(TIB) $*.tib
- expand $*.tib-t.tex | $(VERBATIM) > $*.tex
- @$(RM) $*.tib-t.tex
-
-%.ps : %.fig
- @$(RM) $@
- fig2dev -L ps $< $@
-
-%.tex : %.fig
- @$(RM) $@
- fig2dev -L latex $< $@
-
-#-----------------------------------------------------------------------------
-# Literate suffix rules
-
-%.prl : %.lprl
- @$(RM) $@
- $(UNLIT) $(UNLIT_OPTS) $< $@
- $(GENERATED_FILE) $@
-
-%.c : %.lc
- @$(RM) $@
- $(UNLIT) $(UNLIT_OPTS) $< $@
- $(GENERATED_FILE) $@
-
-%.h : %.lh
- @$(RM) $@
- $(UNLIT) $(UNLIT_OPTS) $< $@
- $(GENERATED_FILE) $@
-
-#-----------------------------------------------------------------------------
-# Win32 resource files
-#
-# The default is to use the GNU resource compiler.
-#
-
-%.$(way_)o : %.$(way_)rc
- @$(RM) $@
- windres --preprocessor="$(CPP) -xc -DRC_INVOKED" $< $@
-
-#-----------------------------------------------------------------------------
-# Preprocessor suffix rule
-
-# Note use of -P option to prevent #line pragmas being left in the CPP
-# output.
-
-% : %.pp
- @$(RM) $@
- $(CPP) $(RAWCPP_FLAGS) -P $(CPP_OPTS) -x c $< | \
- grep -v '^#pragma GCC' > $@
diff --git a/mk/target.mk b/mk/target.mk
deleted file mode 100644
index 37a72bcc0c..0000000000
--- a/mk/target.mk
+++ /dev/null
@@ -1,701 +0,0 @@
-#################################################################################
-#
-# target.mk
-#
-# Standard targets for GHC
-#
-#################################################################################
-
-#
-# This file contain three groups of target rules:
-#
-# 1. GHC targets
-# depend*
-# runtests*
-#
-# 2. GNU standard targets
-# all*
-# install* installcheck installdirs
-# install-docs*
-# clean* distclean* mostlyclean* maintainer-clean*
-# tags*
-# dvi ps (no info) GHC adds: pdf rtf html chm HxS
-# check
-#
-# 3. Some of the above targets have a version that
-# recursively invokes that target in sub-directories.
-# This relies on the importing Makefile setting SUBDIRS
-#
-# The recursive targets are marked with a * above
-#
-
-#
-#
-#
-
-##################################################################
-# Pre-compute the list of sources so we don't have to do this
-# multiple times. See paths.mk.
-
-PRE_SRCS := $(ALL_SRCS)
-
-##################################################################
-# Include package building machinery
-# NB. needs to be after PRE_SRCS setting above, because otherwise the
-# rule dependencies won't be set correctly.
-
-include $(TOP)/mk/package.mk
-
-###################################################################
-# Suffix rules for Haskell, C and literate
-
-include $(TOP)/mk/suffix.mk
-
-##################################################################
-# GHC standard targets
-#
-# depend:
-#
-# The depend target has to cope with a set of files that may have
-# different ways of computing their dependencies, i.e., a Haskell
-# module's dependencies are computed differently from C files.
-#
-# Note that we don't compute dependencies automatically, i.e., have the
-# .depend file be a target that is dependent on the Haskell+C sources,
-# and then have the `depend' target depend on `.depend'. The reason for
-# this is that when GNU make is processing the `include .depend' statement
-# it records .depend as being a Makefile. Before doing any other processing,
-# `make' will try to check to see if the Makefiles are up-to-date. And,
-# surprisingly enough, .depend has a rule for it, so if any of the source
-# files change, it will be invoked, *regardless* of what target you're making.
-#
-# So, for now, the dependencies has to be re-computed manually via `make depend'
-# whenever a module changes its set of imports. Doing what was outlined above
-# is only a small optimisation anyway, it would avoid the recomputation of
-# dependencies if the .depend file was newer than any of the source modules.
-#
-.PHONY: depend
-
-# Compiler produced files that are targets of the source's imports.
-MKDEPENDHS_OBJ_SUFFICES=o
-
-ifneq "$(BootingFromHc)" "YES"
-PKGCONF_DEP = $(STAMP_PKG_CONF)
-endif
-
-ifeq "$(USE_NEW_MKDEPEND_FLAGS)" "YES"
-MKDEPENDHS_FLAGS = -dep-makefile .depend $(foreach way,$(WAYS),-dep-suffix $(way))
-else
-MKDEPENDHS_FLAGS = -optdep-f -optdep.depend $(foreach way,$(WAYS),-optdep-s -optdep$(way))
-endif
-
-depend :: $(MKDEPENDHS_SRCS) $(MKDEPENDC_SRCS) $(PKGCONF_DEP)
- @$(RM) .depend
- @touch .depend
-ifneq "$(DOC_SRCS)" ""
- $(MKDEPENDLIT) -o .depend $(MKDEPENDLIT_OPTS) $(filter %.lit,$(DOC_SRCS))
-endif
-ifneq "$(MKDEPENDC_SRCS)" ""
- $(MKDEPENDC) -f .depend $(MKDEPENDC_OPTS) $(foreach way,$(WAYS),-s $(way)) -- $(CC_OPTS) -- $(MKDEPENDC_SRCS)
-endif
-ifneq "$(MKDEPENDHS_SRCS)" ""
- $(MKDEPENDHS) -M $(MKDEPENDHS_FLAGS) $(foreach obj,$(MKDEPENDHS_OBJ_SUFFICES),-osuf $(obj)) $(MKDEPENDHS_OPTS) $(filter-out -split-objs, $(HC_OPTS)) $(MKDEPENDHS_SRCS)
-endif
-
-
-##################################################################
-# boot
-#
-# The boot target, at a minimum generates dependency information
-
-.PHONY: boot
-
-ifeq "$(NO_BOOT_TARGET)" "YES"
-boot ::
-else
-boot :: depend
-endif
-
-##################################################################
-# GNU Standard targets
-#
-# Every Makefile should define the following targets
-#
-# `all'
-# Compile the entire program. This should be the default target.
-# This target need not rebuild any documentation files
-#
-# `install'
-# Compile the program and copy the executables, libraries, and so on
-# to the file names where they should reside for actual use. If
-# there is a simple test to verify that a program is properly
-# installed, this target should run that test.
-#
-# The commands should create all the directories in which files are
-# to be installed, if they don't already exist. This includes the
-# directories specified as the values of the variables prefix and
-# exec_prefix , as well as all subdirectories that are needed. One
-# way to do this is by means of an installdirs target as described
-# below.
-#
-# Use `-' before any command for installing a man page, so that make
-# will ignore any errors. This is in case there are systems that
-# don't have the Unix man page documentation system installed.
-#
-# `clean'
-#
-# Delete all files from the current directory that are normally
-# created by building the program. Don't delete the files that
-# record the configuration. Also preserve files that could be made
-# by building, but normally aren't because the distribution comes
-# with them.
-#
-# Delete `.dvi' files here if they are not part of the
-# distribution.
-#
-# `distclean'
-# Delete all files from the current directory that are created by
-# configuring or building the program. If you have unpacked the
-# source and built the program without creating any other files,
-# `make distclean' should leave only the files that were in the
-# distribution.
-#
-# `mostlyclean'
-# Like `clean', but may refrain from deleting a few files that
-# people normally don't want to recompile. For example, the
-# `mostlyclean' target for GCC does not delete `libgcc.a', because
-# recompiling it is rarely necessary and takes a lot of time.
-#
-# `maintainer-clean'
-# Delete everything from the current directory that can be
-# reconstructed with this Makefile. This typically includes
-# everything deleted by distclean , plus more: C source files
-# produced by Bison, tags tables, and so on.
-#
-# One exception, however: `make maintainer-clean' should not delete
-# `configure' even if `configure' can be remade using a rule in the
-# Makefile. More generally, `make maintainer-clean' should not delete
-# anything that needs to exist in order to run `configure' and then
-# begin to build the program.
-#
-# `TAGS'
-# Update a tags table for this program.
-#
-# `dvi' `ps' `pdf' `html' `chm' `HxS' `rtf'
-# Generate DVI/PS/PDF files for LaTeX/DocBook docs. Not everything is
-# supported everywhere, but the intention is to standardise on DocBook
-# producing all formats.
-#
-# `check'
-# Perform self-tests (if any). The user must build the program
-# before running the tests, but need not install the program; you
-# should write the self-tests so that they work when the program is
-# built but not installed.
-#
-# The following targets are suggested as conventional names, for programs
-# in which they are useful.
-#
-# installcheck
-# Perform installation tests (if any). The user must build and
-# install the program before running the tests. You should not
-# assume that `$(bindir)' is in the search path.
-#
-# installdirs
-# It's useful to add a target named `installdirs' to create the
-# directories where files are installed, and their parent
-# directories. There is a script called `mkinstalldirs' which is
-# convenient for this; find it in the Texinfo package.
-# (GHC: we use a close relative of the suggested script, situated
-# in glafp-utils/mkdirhier -- SOF)
-
-
-
-
-###########################################
-#
-# Targets: "all"
-#
-###########################################
-
-# For each of these variables that is defined
-# we generate one "all" rule and one rule for the variable itself:
-#
-# HS_PROG Haskell program
-# C_PROG C program
-# LIBRARY Library
-#
-# For details of exactly what rule is generated, see the
-# relevant section below
-
-.PHONY: all
-
-#----------------------------------------
-# Haskell programs
-
-ifneq "$(HS_PROG)" ""
-all :: $(HS_PROG)
-
-ifneq "$(BootingFromHc)" "YES"
-$(HS_PROG) :: $(OBJS)
- $(HC) -o $@ $(HC_OPTS) $(LD_OPTS) $(OBJS)
-else
-# see bootstrap.mk
-$(HS_PROG) :: $(OBJS)
- $(CC) -o $@ $(HC_BOOT_CC_OPTS) $(HC_BOOT_LD_OPTS) $(OBJS) $(HC_BOOT_LIBS)
-endif
-endif
-
-#----------------------------------------
-# C programs
-
-ifneq "$(C_PROG)" ""
-all :: $(C_PROG)
-
-$(C_PROG) :: $(C_OBJS)
- $(CC) -o $@ $(CC_OPTS) $(LD_OPTS) $(C_OBJS) $(LIBS)
-endif
-
-#----------------------------------------
-# Libraries/archives
-#
-# Build $(LIBRARY) from $(LIBOBJS)+$(STUBOBJS)
-#
-# Inputs:
-# $(LIBOBJS)
-# $(STUBOBJS)
-#
-# Outputs:
-# Rule to build $(LIBRARY)
-
-ifneq "$(LIBRARY)" ""
-all :: $(LIBRARY)
-
-ifneq "$(way)" "i"
-define BUILD_STATIC_LIB
-$(RM) $@
-$(AR) $(AR_OPTS) $@ $(STUBOBJS) $(LIBOBJS)
-$(RANLIB) $@
-endef
-else
-define BUILD_STATIC_LIB
-$(RM) $@
-al -out:$@ $(STUBOBJS) $(LIBOBJS)
-endef
-endif
-
-#
-# For Haskell object files, we might have chosen to split
-# up the object files. Test for whether the library being
-# built is consisting of Haskell files by (hackily) checking
-# whether HS_SRCS is empty or not.
-#
-
-# can't split objs in way 'u', so we disable it here
-ifeq "$(way)" "u"
-SplitObjs = NO
-endif
-
-ifneq "$(HS_SRCS)" ""
-ifeq "$(SplitObjs)" "YES"
-
-SRC_HC_OPTS += -split-objs
-
-# We generate the archive into a temporary file libfoo.a.tmp, then
-# rename it at the end. This avoids the problem that ar may sometimes
-# fail, leaving a partially built archive behind.
-ifeq "$(ArSupportsInput)" ""
-define BUILD_STATIC_LIB
-$(RM) $@ $@.tmp
-(echo $(STUBOBJS) $(C_OBJS) $(GC_C_OBJS); $(FIND) $(patsubst %.$(way_)o,%_split,$(HS_OBJS)) -name '*.$(way_)o' -print) | xargs $(AR) $@
-$(RANLIB) $@
-endef
-else
-define BUILD_STATIC_LIB
-$(RM) $@ $@.tmp
-echo $(STUBOBJS) > $@.list
-echo $(C_OBJS) >> $@.list
-echo $(GC_C_OBJS) >> $@.list
-$(FIND) $(patsubst %.$(way_)o,%_split,$(HS_OBJS)) -name '*.$(way_)o' -print >> $@.list
-$(AR) $(AR_OPTS) $@ $(ArSupportsInput) $@.list
-$(RM) $@.list
-$(RANLIB) $@
-endef
-endif
-
-# Extra stuff for compiling Haskell files with $(SplitObjs):
-
-#
-# If (Haskell) object files are split, cleaning up
-# consist of descending into the directories where
-# the myriads of object files have been put.
-#
-
-extraclean ::
- $(FIND) $(patsubst %.$(way_)o,%_split,$(HS_OBJS)) -name '*.$(way_)o' -print -o -name ld.script -print | xargs $(RM) __rm_food
- -rmdir $(patsubst %.$(way_)o,%_split,$(HS_OBJS)) > /dev/null 2>&1
-
-endif # $(SplitObjs)
-endif # $(HS_SRCS)
-
-#
-# Remove local symbols from library objects if requested.
-#
-
-ifeq "$(StripLibraries)" "YES"
-ifeq "$(SplitObjs)" "YES"
-SRC_HC_POST_OPTS += \
- for i in $(basename $@)_split/*.$(way_)o; do \
- $(LD) -r $(LD_X) -o $$i.tmp $$i; \
- $(MV) $$i.tmp $$i; \
- done
-else
-SRC_HC_POST_OPTS += \
- $(LD) -r $(LD_X) -o $@.tmp $@; $(MV) $@.tmp $@
-endif # SplitObjs
-endif # StripLibraries
-
-# Note: $(STUBOBJS) isn't depended on here, but included when building the lib.
-# (i.e., the assumption is that $(STUBOBJS) are created as a side-effect
-# of building $(LIBOBJS)).
-
-ifeq "$(LIBRARY:%.so=YES)" "YES"
-# ELF styled DSO
-$(LIBRARY): $(LIBOBJS) $(LIB_DEPS)
- $(RM) $@
- $(HC) -shared -dynamic -o $@ $(STUBOBJS) $(LIBOBJS) $(LIB_LD_OPTS)
-else
-ifeq "$(LIBRARY:%.dylib=YES)" "YES"
-$(LIBRARY): $(LIBOBJS) $(LIB_DEPS)
- $(HC) -shared -dynamic -o $@ $(STUBOBJS) $(LIBOBJS) $(LIB_LD_OPTS)
-else
-ifeq "$(LIBRARY:%.dll=YES)" "YES"
-#----------------------------------------
-# Building Win32 DLLs
-#
-$(LIBRARY): $(LIBOBJS) $(LIBRARY).o $(LIB_DEPS)
- $(HC) -shared -dynamic -o $@ $(STUBOBJS) $(LIBOBJS) $(LIBRARY).o $(LIB_LD_OPTS)
-
-DLLTOOL=dlltool
-
-$(LIBRARY).def: $(LIBOBJS)
- $(DLLTOOL) -D $(LIBRARY) --output-def $@ --export-all $(LIBOBJS)
-
-$(LIBRARY).o:
- $(DLLTOOL) -D $(LIBRARY) --output-exp $(LIBRARY).o $(LIBOBJS)
-
-# Generates library.dll.a; by MinGW conventions, this is the dll's import library
-$(LIBRARY).a: $(LIBOBJS) $(LIBRARY).def
- $(DLLTOOL) -D $(LIBRARY) --def $(LIBRARY).def --output-lib $@
-
-#
-# Version information is baked into a DLL by having the DLL include DllVersionInfo.o.
-# The version info contains two user tweakables: DLL_VERSION and DLL_VERSION_NAME.
-# (both are given sensible defaults though.)
-#
-# Note: this will not work as expected with Cygwin B20.1; you need a more recent
-# version of binutils (to pick up windres bugfixes.)
-
-ifndef DLL_VERSION
-DLL_VERSION=$(ProjectVersion)
-endif
-
-ifndef DLL_VERSION_NAME
-DLL_VERSION_NAME="http://www.haskell.org/ghc"
-endif
-
-ifndef DLL_DESCRIPTION
-DLL_DESCRIPTION="A GHC-compiled DLL"
-endif
-
-ifndef EXE_VERSION
-EXE_VERSION=$(ProjectVersion)
-endif
-
-ifndef EXE_VERSION_NAME
-EXE_VERSION_NAME="http://www.haskell.org/ghc"
-endif
-
-ifndef EXE_DESCRIPTION
-EXE_DESCRIPTION="A GHC-compiled binary"
-endif
-
-#
-# Little bit of lo-fi mangling to get at the right set of settings depending
-# on whether we're generating the VERSIONINFO for a DLL or EXE
-#
-DLL_OR_EXE=$(subst VersionInfo.$(way_)rc,,$@)
-VERSION_FT=$(subst Dll, 0x2L, $(subst Exe, 0x1L, $(DLL_OR_EXE)))
-VERSION_RES_NAME=$(subst Exe,$(EXE_VERSION_NAME), $(subst Dll, $(DLL_VERSION_NAME),$(DLL_OR_EXE)))
-VERSION_RES=$(subst Exe,$(EXE_VERSION), $(subst Dll, $(DLL_VERSION),$(DLL_OR_EXE)))
-VERSION_DESC=$(subst Exe,$(EXE_DESCRIPTION), $(subst Dll, $(DLL_DESCRIPTION),$(DLL_OR_EXE)))
-
-DllVersionInfo.$(way_)rc ExeVersionInfo.$(way_)rc:
- $(RM) DllVersionInfo.$(way_)rc
- echo "1 VERSIONINFO" > $@
- echo "FILEVERSION 1,0,0,1" >> $@
- echo "PRODUCTVERSION 1,0,0,1" >> $@
- echo "FILEFLAGSMASK 0x3fL" >> $@
- echo "FILEOS 0x4L" >> $@
- echo "FILETYPE $(VERSION_FT)" >> $@
- echo "FILESUBTYPE 0x0L" >> $@
- echo "BEGIN" >> $@
- echo " BLOCK \"StringFileInfo\"" >> $@
- echo " BEGIN" >> $@
- echo " BLOCK \"040904B0\"" >> $@
- echo " BEGIN" >> $@
- echo " VALUE \"CompanyName\", \"$(VERSION_RES_NAME)\\0\"" >> $@
- echo " VALUE \"FileVersion\", \"$(VERSION_RES)\\0\"" >> $@
- echo " VALUE \"ProductVersion\", \"$(VERSION_RES)\\0\"" >> $@
- echo " VALUE \"FileDescription\", \"$(VERSION_DESC)\\0\"" >> $@
- echo " END" >> $@
- echo " END" >> $@
- echo " BLOCK \"VarFileInfo\"" >> $@
- echo " BEGIN" >> $@
- echo " VALUE \"Translation\", 0x0409, 1200" >> $@
- echo " END" >> $@
- echo "END" >> $@
-else
-# Regular static library
-$(LIBRARY): $(LIBOBJS)
- $(BUILD_STATIC_LIB)
-endif # %.dll
-endif # %.dylib
-endif # %.so
-endif # LIBRARY = ""
-
-include $(TOP)/mk/install.mk
-
-##############################################################################
-#
-# Targets: check tags show
-#
-##############################################################################
-
-#------------------------------------------------------------
-# Check
-
-.PHONY: check
-
-check:: $(TESTS)
- @for i in $(filter-out %.lhs .hs, $(TESTS)) ''; do \
- if (test -f "$$i"); then \
- echo Running: `basename $$i` ; \
- cd test; `basename $$i` ; \
- fi; \
- done;
-
-#------------------------------------------------------------
-# Tags
-
-.PHONY: TAGS tags
-
-tags TAGS:: $(TAGS_HS_SRCS) $(TAGS_C_SRCS)
- @$(RM) TAGS
- @touch TAGS
-ifneq "$(TAGS_HS_SRCS)" ""
- $(HSTAGS) $(HSTAGS_OPTS) $(TAGS_HS_SRCS)
-endif
-ifneq "$(TAGS_C_SRCS)" ""
- etags -a $(TAGS_C_SRCS)
-endif
- @( DEREFFED=`ls -l Makefile | sed -e 's/.*-> \(.*\)/\1/g'` && $(RM) `dirname $$DEREFFED`/TAGS && $(CP) TAGS `dirname $$DEREFFED` ) 2>/dev/null || echo TAGS file generated, perhaps copy over to source tree?
-
-################################################################################
-#
-# DocBook XML Documentation
-#
-################################################################################
-
-.PHONY: html html-no-chunks chm HxS fo dvi ps pdf
-
-ifneq "$(XML_DOC)" ""
-
-all :: $(XMLDocWays)
-
-# multi-file XML document: main document name is specified in $(XML_DOC),
-# sub-documents (.xml files) listed in $(XML_SRCS).
-
-ifeq "$(XML_SRCS)" ""
-XML_SRCS = $(wildcard *.xml)
-endif
-
-XML_HTML = $(addsuffix /index.html,$(basename $(XML_DOC)))
-XML_HTML_NO_CHUNKS = $(addsuffix .html,$(XML_DOC))
-XML_CHM = $(addsuffix .chm,$(XML_DOC))
-XML_HxS = $(addsuffix .HxS,$(XML_DOC))
-XML_FO = $(addsuffix .fo,$(XML_DOC))
-XML_DVI = $(addsuffix .dvi,$(XML_DOC))
-XML_PS = $(addsuffix .ps,$(XML_DOC))
-XML_PDF = $(addsuffix .pdf,$(XML_DOC))
-
-$(XML_HTML) $(XML_NO_CHUNKS_HTML) $(XML_FO) $(XML_DVI) $(XML_PS) $(XML_PDF) :: $(XML_SRCS)
-
-html :: $(XML_HTML)
-html-no-chunks :: $(XML_HTML_NO_CHUNKS)
-chm :: $(XML_CHM)
-HxS :: $(XML_HxS)
-fo :: $(XML_FO)
-dvi :: $(XML_DVI)
-ps :: $(XML_PS)
-pdf :: $(XML_PDF)
-
-CLEAN_FILES += $(XML_HTML_NO_CHUNKS) $(XML_FO) $(XML_DVI) $(XML_PS) $(XML_PDF)
-
-extraclean ::
- $(RM) -rf $(XML_DOC).out $(FPTOOLS_CSS) $(basename $(XML_DOC)) $(basename $(XML_DOC))-htmlhelp
-
-validate ::
- $(XMLLINT) --valid --noout $(XMLLINT_OPTS) $(XML_DOC).xml
-endif
-
-##############################################################################
-#
-# Targets: clean
-#
-##############################################################################
-
-# we have to be careful about recursion here; since all the clean
-# targets are recursive, we don't want to make eg. distclean depend on
-# clean because that would result in far too many recursive calls.
-
-.PHONY: mostlyclean clean distclean maintainer-clean
-
-mostlyclean::
- rm -f $(MOSTLY_CLEAN_FILES)
-
-# extraclean is used for adding actions to the clean target.
-extraclean::
-
-clean:: extraclean
- rm -f $(MOSTLY_CLEAN_FILES) $(CLEAN_FILES)
-
-distclean:: extraclean
- rm -f $(MOSTLY_CLEAN_FILES) $(CLEAN_FILES) $(DIST_CLEAN_FILES)
-
-maintainer-clean:: extraclean
- @echo 'This command is intended for maintainers to use; it'
- @echo 'deletes files that may need special tools to rebuild.'
- rm -f $(MOSTLY_CLEAN_FILES) $(CLEAN_FILES) $(DIST_CLEAN_FILES) $(MAINTAINER_CLEAN_FILES)
-
-################################################################################
-#
-# Way management
-#
-################################################################################
-
-# Here is the ingenious jiggery pokery that allows you to build multiple versions
-# of a program in a single build tree.
-#
-# The ways setup requires the following variables to be set:
-#
-# Expects: $(WAYS) the possible "way" strings to one of
-# which $(way) will be set
-
-ifneq "$(way)" ""
-ifeq "$(findstring $(way), $(WAYS))" ""
-$(error Unknown way $(way) of $(WAYS))
-endif
-endif
-
-# So how does $(way) ever get set to anything? Answer, we recursively
-# invoke make, setting $(way) on the command line.
-# When do we do this recursion? Answer: whenever the programmer
-# asks make to make a target that involves a way suffix.
-# We must remember *not* to recurse again; but that's easy: we
-# just see if $(way) is set:
-
-ifeq "$(way)" ""
-
-# If $(WAYS) = p mc, then WAY_TARGETS expands to
-# %.p_lhs %.p_hs %.p_o ... %.mc_lhs %.p_hs ...
-# and OTHER_WAY_TARGETS to
-# %_p.a %_p %_mc.a %_mc
-# where the suffixes are from $(SUFFIXES)
-#
-# We have to treat libraries and "other" targets differently,
-# because their names are of the form
-# libHS_p.a and Foo_p
-# whereas everything else has names of the form
-# Foo.p_o
-
-FPTOOLS_SUFFIXES := o hi hc
-
-WAY_TARGETS = $(foreach way,$(WAYS),$(foreach suffix, $(FPTOOLS_SUFFIXES), %.$(way)_$(suffix)))
-LIB_WAY_TARGETS = $(foreach way,$(filter-out %dyn,$(WAYS)), %_$(way).a)
-LIB_WAY_TARGETS_DYN = $(foreach way,$(filter %dyn,$(WAYS)), %$(subst dyn,-ghc$(ProjectVersion),$(subst _dyn,dyn,$(way)))$(soext))
-
-# $@ will be something like Foo.p_o
-# $(suffix $@) returns .p_o
-# $(subst .,.p_o) returns p_o
-# $(subst _,.,p_o) returns p.o (clever)
-# $(basename p.o) returns p
-#
-$(WAY_TARGETS) :
- $(MAKE) way=$(basename $(subst _,.,$(subst .,,$(suffix $@)))) $@
-
-# $(@F) will be something like libHS_p.a, or Foo_p
-# $(basename $(@F)) will be libHS_p, or Foo_p
-# The sed script extracts the "p" part.
-
-$(LIB_WAY_TARGETS) :
- $(MAKE) $(MFLAGS) $@ way=$(subst .,,$(suffix $(subst _,.,$(basename $@))))
-
-$(LIB_WAY_TARGETS_DYN) :
- $(MAKE) $(MFLAGS) $@ way=$(patsubst _dyn,dyn,$(subst .,,$(suffix $(subst _,.,$(basename $(subst -ghc$(ProjectVersion),,$@)))))_dyn)
-
-endif # if way
-
-# -------------------------------------------------------------------------
-# Object and interface files have suffixes tagged with their ways
-
-ifneq "$(way)" ""
-SRC_HC_OPTS += -hisuf $(way_)hi -hcsuf $(way_)hc -osuf $(way_)o
-endif
-
-# -------------------------------------------------------------------------
-# Rules to invoke the current target recursively for each way
-
-ifneq "$(strip $(WAYS))" ""
-ifeq "$(way)" ""
-
-# NB: the targets exclude
-# boot runtests
-# since these are way-independent
-all docs TAGS clean distclean mostlyclean maintainer-clean install ::
- @echo "------------------------------------------------------------------------"
- @echo "== Recursively making \`$@' for ways: $(WAYS) ..."
- @echo "PWD = $(shell pwd)"
- @echo "------------------------------------------------------------------------"
-# Don't rely on -e working, instead we check exit return codes from sub-makes.
- case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
- for i in $(WAYS) ; do \
- echo "------------------------------------------------------------------------"; \
- echo "== $(MAKE) way=$$i $@;"; \
- echo "PWD = $(shell pwd)"; \
- echo "------------------------------------------------------------------------"; \
- $(MAKE) way=$$i --no-print-directory $(MFLAGS) $@ ; \
- if [ $$? -eq 0 ] ; then true; else exit $$x_on_err; fi; \
- done
- @echo "------------------------------------------------------------------------"
- @echo "== Finished recursively making \`$@' for ways: $(WAYS) ..."
- @echo "PWD = $(shell pwd)"
- @echo "------------------------------------------------------------------------"
-
-endif
-endif
-
-include $(TOP)/mk/recurse.mk
-
-# -----------------------------------------------------------------------------
-# Further cleaning
-
-# Sometimes we want to clean things only after the recursve cleaning
-# has heppened (eg. if the files we're about to remove would affect
-# the recursive traversal).
-
-distclean::
- rm -f $(LATE_DIST_CLEAN_FILES)
-
-maintainer-clean::
- rm -f $(LATE_DIST_CLEAN_FILES)
-
diff --git a/mk/validate-settings.mk b/mk/validate-settings.mk
index 7d647edfcc..53f635b3f8 100644
--- a/mk/validate-settings.mk
+++ b/mk/validate-settings.mk
@@ -14,14 +14,14 @@ GhcStage2HcOpts = -O -fasm
# running of the tests, and faster building of the utils to be installed
GhcLibHcOpts = -O -fasm -dcore-lint
-GhcLibWays =
+GhcLibWays = v
SplitObjs = NO
NoFibWays =
STRIP = :
GhcBootLibs = YES
ifeq "$(ValidateHpc)" "YES"
-GhcStage2HcOpts += -fhpc -hpcdir $(FPTOOLS_TOP_ABS)/testsuite/hpc_output/
+GhcStage2HcOpts += -fhpc -hpcdir $(TOP)/testsuite/hpc_output/
endif
ifeq "$(ValidateSlow)" "YES"
GhcStage2HcOpts += -XGenerics -DDEBUG
diff --git a/rts/Capability.h b/rts/Capability.h
index 0f61fad913..d2fcc5ed7b 100644
--- a/rts/Capability.h
+++ b/rts/Capability.h
@@ -148,7 +148,7 @@ struct Capability_ {
INLINE_HEADER Capability *
regTableToCapability (StgRegTable *reg)
{
- return (Capability *)((void *)((unsigned char*)reg - FIELD_OFFSET(Capability,r)));
+ return (Capability *)((void *)((unsigned char*)reg - STG_FIELD_OFFSET(Capability,r)));
}
// Initialise the available capabilities.
diff --git a/rts/Interpreter.c b/rts/Interpreter.c
index 1a6e9273e0..3a99d42139 100644
--- a/rts/Interpreter.c
+++ b/rts/Interpreter.c
@@ -1425,7 +1425,7 @@ run_BCO:
ffi_call(cif, fn, ret, argptrs);
// And restart the thread again, popping the RET_DYN frame.
- cap = (Capability *)((void *)((unsigned char*)resumeThread(tok) - FIELD_OFFSET(Capability,r)));
+ cap = (Capability *)((void *)((unsigned char*)resumeThread(tok) - STG_FIELD_OFFSET(Capability,r)));
LOAD_STACK_POINTERS;
// Re-load the pointer to the BCO from the RET_DYN frame,
diff --git a/rts/Makefile b/rts/Makefile
index bda4bc7afe..0497a74442 100644
--- a/rts/Makefile
+++ b/rts/Makefile
@@ -1,497 +1,4 @@
-#-----------------------------------------------------------------------------
-#
-# This is the Makefile for the runtime-system stuff.
-# This stuff is written in C (and cannot be written in Haskell).
-#
-# .c files are vanilla C,
-# .hc files are "Haskellized-C", compiled using the C compiler and
-# (possibly) the assembly-mangler. The GHC driver script
-# knows how to compile this stuff.
-
-#-----------------------------------------------------------------------------
-# Preamble
-
-TOP=..
-
-# Set UseGhcForCc: this causes the fptools build system to use a different
-# set of suffix rules for compiling C code, using $(HC) rather than $(CC)
-# and prepending "-optc" to $(CC_OPTS). NB. must be done before including
-# boilerplate.mk below.
-UseGhcForCc = YES
-
-include $(TOP)/mk/boilerplate.mk
-
-PACKAGE = rts
-
-HC=$(GHC_INPLACE)
-
-
-# Setting _way here is a nasty hack to make sure we get libHSrts*.a etc
-# rather than just libHSrts.a when we are installing bindists.
-ifeq "$(DOING_BIN_DIST)" "YES"
-_way = *
-endif
-
-# -----------------------------------------------------------------------------
-# RTS ways
-
-WAYS=$(strip $(GhcLibWays) $(GhcRTSWays))
-
-ifneq "$(findstring debug, $(way))" ""
-GhcRtsHcOpts=
-GhcRtsCcOpts=-g -O0
-endif
-
-ifeq "$(BeConservative)" "YES"
-GhcRtsCcOpts += -DBE_CONSERVATIVE
-endif
-
-# -----------------------------------------------------------------------------
-
-# There's nothing for Haddock here...
-override HADDOCK_DOCS = NO
-
-# -----------------------------------------------------------------------------
-
-# Tells the build system not to add various Haskellish options to $(SRC_HC_OPTS)
-NON_HS_PACKAGE = YES
-
-# grab sources from these subdirectories
-ALL_DIRS = hooks parallel sm eventlog
-
-ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
-ALL_DIRS += win32
-else
-ALL_DIRS += posix
-endif
-
-ifneq "$(findstring dyn, $(way))" ""
-DYNAMIC_RTS=YES
-else
-DYNAMIC_RTS=NO
-endif
-
-ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
-EXCLUDED_SRCS += Main.c
-# It's not included in the DLL, but we need to compile it up separately.
-
-all :: Main.$(way_)o
-INSTALL_LIBS += Main.$(way_)o
-else
-EXCLUDED_SRCS += RtsDllMain.c
-endif
-
-# This file ends up being empty unless we're building for a powerpc
-# or darwin system, and it is reported that Solaris ld chokes on it when
-# building HSrts.o.
-ifeq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
-ifeq "$(findstring $(TargetOS_CPP), darwin)" ""
-EXCLUDED_SRCS += AdjustorAsm.S
-endif
-endif
-
-EXCLUDED_SRCS += parallel/SysMan.c
-
-EXCLUDED_SRCS += dyn-wrapper.c
-
-# compile generic patchable dyn-wrapper
-
-DYNWRAPPER_SRC = dyn-wrapper.c
-DYNWRAPPER_PROG = dyn-wrapper$(exeext)
-$(DYNWRAPPER_PROG): $(DYNWRAPPER_SRC)
- $(HC) -cpp -optc-include -optcdyn-wrapper-patchable-behaviour.h $(INPLACE_EXTRA_FLAGS) $< -o $@
-
-# The build system doesn't give us these
-CMM_SRCS = $(filter-out AutoApply%.cmm, $(wildcard *.cmm)) $(EXTRA_CMM_SRCS)
-CMM_OBJS = $(patsubst %.cmm,%.$(way_)o, $(CMM_SRCS))
-
-CLEAN_FILES += $(CMM_OBJS)
-
-# Override the default $(LIBOBJS) (defaults to $(HS_OBJS))
-LIBOBJS = $(C_OBJS) $(CMM_OBJS)
-
-SplitObjs=NO
-
-H_FILES = $(wildcard ../includes/*.h) $(wildcard *.h)
-
-#-----------------------------------------------------------------------------
-# Flags for compiling RTS .c and .hc files
-
-# gcc provides lots of useful warnings if you ask it.
-# This is a pretty good list to start with - use a # to comment out
-# any you don't like.
-WARNING_OPTS += -Wall
-WARNING_OPTS += -W
-WARNING_OPTS += -Wstrict-prototypes
-WARNING_OPTS += -Wmissing-prototypes
-WARNING_OPTS += -Wmissing-declarations
-WARNING_OPTS += -Winline
-WARNING_OPTS += -Waggregate-return
-#WARNING_OPTS += -Wpointer-arith
-#WARNING_OPTS += -Wbad-function-cast
-#WARNING_OPTS += -Wcast-align
-#WARNING_OPTS += -Wnested-externs
-#WARNING_OPTS += -Wshadow
-#WARNING_OPTS += -Wcast-qual
-#WARNING_OPTS += -Wno-unused
-#WARNING_OPTS += -Wredundant-decls
-#WARNING_OPTS += -Wconversion
-
-STANDARD_OPTS += -I../includes -I. -Iparallel -Ism -Ieventlog
-
-# COMPILING_RTS is only used when building Win32 DLL support.
-STANDARD_OPTS += -DCOMPILING_RTS
-
-# HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
-# only included in .c compilations. HC_OPTS included the WAY_* opts, which
-# must be included in both types of compilations.
-
-SRC_CC_OPTS += $(WARNING_OPTS)
-SRC_CC_OPTS += $(STANDARD_OPTS)
-
-SRC_CC_OPTS += $(GhcRtsCcOpts)
-SRC_HC_OPTS += $(GhcRtsHcOpts) $(STANDARD_OPTS) -package-name rts
-
-ifneq "$(GhcWithSMP)" "YES"
-SRC_CC_OPTS += -DNOSMP
-SRC_HC_OPTS += -optc-DNOSMP
-endif
-
-ifeq "$(UseLibFFIForAdjustors)" "YES"
-SRC_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
-endif
-
-ifeq "$(Windows)" "YES"
-# SDM: when compiled with -fasm the RTS currently has bogus references to
-# __imp_base_ things, so working around for now:
-SRC_HC_OPTS = -fvia-C
-endif
-
-ifneq "$(DYNAMIC_RTS)" "YES"
-SRC_HC_OPTS += -static
-else
-LIB_LD_OPTS += -ignore-package base -ignore-package rts
-ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
-LIB_DEPS=buildbase
-.PHONY: buildbase
-
-BASE_DIST_LIB=$(TOP)/libraries/base/dist/build
-
-# The following must be a one liner otherwise its evaluation won't be delayed until base/rts packages are properly registered
-LIB_LD_OPTS = $(foreach lib,$(shell $(GHC_PKG_INPLACE) field base hs-libraries | sed -e 's/hs-libraries: //'),"-l$(lib)-ghc$(ProjectVersion)$(soext)") $(foreach lib,$(shell $(GHC_PKG_INPLACE) field rts extra-libraries | sed -e s/extra-libraries://),"-l$(lib)") $(foreach libdir,$(shell $(GHC_PKG_INPLACE) field base library-dirs | sed -e 's/library-dirs: //' | sed -e s,\\\\,/,g) $(shell $(GHC_PKG_INPLACE) field rts library-dirs | sed -e s/library-dirs:// | sed -e s/\\\\/\\\\\\\\/g),"-L$(libdir)")
-endif
-endif
-
-# Mac OS X: make sure we compile for the right OS version
-SRC_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
-SRC_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
-LIB_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
-
-# XXX DQ is now the same on all platforms, so get rid of it
-DQ = \"
-
-# If Main.c is built with optimisation then the SEH exception stuff on
-# Windows gets confused.
-# This has to be in HC rather than CC opts, as otherwise there's a
-# -optc-O2 that comes after it.
-Main_HC_OPTS += -optc-O0
-
-RtsMessages_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
-RtsUtils_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
-RtsUtils_CC_OPTS += -DRtsWay=$(DQ)rts$(_way)$(DQ)
-#
-RtsUtils_CC_OPTS += -DHostPlatform=$(DQ)$(HOSTPLATFORM)$(DQ)
-RtsUtils_CC_OPTS += -DHostArch=$(DQ)$(HostArch_CPP)$(DQ)
-RtsUtils_CC_OPTS += -DHostOS=$(DQ)$(HostOS_CPP)$(DQ)
-RtsUtils_CC_OPTS += -DHostVendor=$(DQ)$(HostVendor_CPP)$(DQ)
-#
-RtsUtils_CC_OPTS += -DBuildPlatform=$(DQ)$(BUILDPLATFORM)$(DQ)
-RtsUtils_CC_OPTS += -DBuildArch=$(DQ)$(BuildArch_CPP)$(DQ)
-RtsUtils_CC_OPTS += -DBuildOS=$(DQ)$(BuildOS_CPP)$(DQ)
-RtsUtils_CC_OPTS += -DBuildVendor=$(DQ)$(BuildVendor_CPP)$(DQ)
-#
-RtsUtils_CC_OPTS += -DTargetPlatform=$(DQ)$(TARGETPLATFORM)$(DQ)
-RtsUtils_CC_OPTS += -DTargetArch=$(DQ)$(TargetArch_CPP)$(DQ)
-RtsUtils_CC_OPTS += -DTargetOS=$(DQ)$(TargetOS_CPP)$(DQ)
-RtsUtils_CC_OPTS += -DTargetVendor=$(DQ)$(TargetVendor_CPP)$(DQ)
-#
-RtsUtils_CC_OPTS += -DGhcUnregisterised=$(DQ)$(GhcUnregisterised)$(DQ)
-RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=$(DQ)$(GhcEnableTablesNextToCode)$(DQ)
-
-# ffi.h triggers prototype warnings, so disable them here:
-Interpreter_CC_OPTS += -Wno-strict-prototypes
-Adjustor_CC_OPTS += -Wno-strict-prototypes
-sm/Storage_CC_OPTS += -Wno-strict-prototypes
-
-StgCRun_CC_OPTS += -w
-Typeable_CC_OPTS += -w
-RetainerProfile_CC_OPTS += -w
-sm/Compact_CC_OPTS += -w
-# On Windows:
-win32/ConsoleHandler_CC_OPTS += -w
-win32/ThrIOManager_CC_OPTS += -w
-win32/Ticker_CC_OPTS += -w
-# The above warning supression flags are a temporary kludge.
-# While working on this module you are encouraged to remove it and fix
-# any warnings in the module. See
-# http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
-# for details
-
-ifeq "$(way)" "mp"
-SRC_HC_OPTS += -I$$PVM_ROOT/include
-endif
-
-# If -DDEBUG is in effect, adjust package conf accordingly..
-ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
-PACKAGE_CPP_OPTS += -DDEBUG
-endif
-
-ifeq "$(HaveLibMingwEx)" "YES"
-PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
-endif
-
-ifeq "$(GhciWithDebugger)" "YES"
-STANDARD_OPTS += -DDEBUGGER
-endif
-
-ifeq "$(DotnetSupport)" "YES"
-
-#
-# Would like to just use SUBDIRS here, but need to
-# descend into dotnet/ earlier than that.
-#
-all ::
- $(MAKE) -C dotnet all
-
-# But use SUBDIRS for other recursive targets.
-SUBDIRS += dotnet
-
-LIBOBJS += dotnet/Invoke.o
-endif
-
-# Suppress uninitialized variable warnings for GC.c
-GC_CC_OPTS += -Wno-uninitialized
-
-#-----------------------------------------------------------------------------
-# Include the Front panel code?
-
-# we need GTK+ for the front panel
-ifneq "$(GTK_CONFIG)" ""
-ifeq "$(GhcRtsWithFrontPanel)" "YES"
-SRC_HC_OPTS += `$(GTK_CONFIG) --cflags` -optc-DRTS_GTK_FRONTPANEL
-VisCallbacks_CC_OPTS += -Wno-unused
-SRC_MKDEPENDC_OPTS += `$(GTK_CONFIG) --cflags`
-else # GhcRtsWithFrontPanel
-EXCLUDED_SRCS += $(wildcard Vis*.c)
-endif
-else # GTK_CONFIG
-EXCLUDED_SRCS += $(wildcard Vis*.c)
-endif
-
-#-----------------------------------------------------------------------------
-# Add PAPI library if needed
-
-ifeq "$(GhcRtsWithPapi)" "YES"
-
-SRC_CC_OPTS += -DUSE_PAPI
-PACKAGE_CPP_OPTS += -DUSE_PAPI
-
-PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=$(PapiIncludeDir)
-PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=$(PapiLibDir)
-
-ifneq "$(PapiIncludeDir)" ""
-SRC_HC_OPTS += -I$(PapiIncludeDir)
-SRC_CC_OPTS += -I$(PapiIncludeDir)
-SRC_HSC2HS_OPTS += -I$(PapiIncludeDir)
-endif
-ifneq "$(PapiLibDirs)" ""
-SRC_LD_OPTS += -L$(PapiLibDirs)
-endif
-
-else # GhcRtsWithPapi==YES
-
-PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=""
-PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=""
-
-endif
-
-#-----------------------------------------------------------------------------
-# make depend setup
-
-SRC_MKDEPENDC_OPTS += -I. -I../includes
-
-# Hack: we define every way-related option here, so that we get (hopefully)
-# a superset of the dependencies. To do this properly, we should generate
-# a different set of dependencies for each way. Further hack: PROFILING and
-# TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
-SRC_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG -DEVENTLOG
-
-# -----------------------------------------------------------------------------
-# The auto-generated apply code
-
-# We want a slightly different version for the unregisterised way, so we make
-# AutoApply on a per-way basis (eg. AutoApply_p.cmm).
-
-ifneq "$(DOING_BIN_DIST)" "YES"
-
-AUTO_APPLY_CMM = AutoApply$(_way).cmm
-
-ifneq "$(BootingFromHc)" "YES"
-$(AUTO_APPLY_CMM): $(GHC_GENAPPLY)
- @$(RM) $@
- $(GENAPPLY) $(if $(filter $(way), u debug_u), -u) >$@
-endif
-
-EXTRA_CMM_SRCS += $(AUTO_APPLY_CMM)
-
-CLEAN_FILES += $(AUTO_APPLY_CMM)
-
-endif
-
-# -----------------------------------------------------------------------------
-
-# Need to get the GMP vars in through CPP to package.conf.in, and put
-# quotes around each element.
-
-empty =
-space = $(empty) $(empty)
-comma = ,
-PACKAGE_CPP_OPTS += -DGMP_INCLUDE_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_INCLUDE_DIRS))))'
-PACKAGE_CPP_OPTS += -DGMP_LIB_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_LIB_DIRS))))'
-
-ifneq "$(GMP_INCLUDE_DIRS)" ""
-SRC_HC_OPTS += -I$(GMP_INCLUDE_DIRS)
-SRC_CC_OPTS += -I$(GMP_INCLUDE_DIRS)
-SRC_HSC2HS_OPTS += -I$(GMP_INCLUDE_DIRS)
-endif
-ifneq "$(GMP_LIB_DIRS)" ""
-SRC_LD_OPTS += -L$(GMP_LIB_DIRS)
-endif
-
-SRC_CC_OPTS += -I../gmp/gmpbuild
-SRC_HC_OPTS += -I../gmp/gmpbuild
-SRC_HSC2HS_OPTS += -I../gmp/gmpbuild
-SRC_LD_OPTS += -L../gmp/gmpbuild
-
-#-----------------------------------------------------------------------------
-# libffi stuff
-
-SRC_CC_OPTS += -I../libffi/build/include
-SRC_HC_OPTS += -I../libffi/build/include
-SRC_HSC2HS_OPTS += -I../libffi/build/include
-SRC_LD_OPTS += -L../libffi/build/include
-
-#-----------------------------------------------------------------------------
-#
-# Building the GUM SysMan
-#
-
-ifeq "$(way)" "mp"
-all :: parallel/SysMan
-
-ifdef solaris2_TARGET_OS
-__socket_libs = -lsocket -lnsl
-else
-__socket_libs =
-endif
-
-parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
- $(RM) $@
- gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
-
-CLEAN_FILES += parallel/SysMan.mp_o parallel/SysMan
-INSTALL_LIBEXECS += parallel/SysMan
-endif
-
-#-----------------------------------------------------------------------------
-# Compiling the cmm files
-
-# ToDo: should we really include Rts.h here? Required for GNU_ATTRIBUTE().
-SRC_HC_OPTS += -I.
-
-# Otherwise the stack-smash handler gets triggered.
-ifeq "$(TargetOS_CPP)" "openbsd"
-SRC_HC_OPTS += -optc-fno-stack-protector
-endif
-
-# -O3 helps unroll some loops (especially in copy() with a constant argument).
-sm/Evac_HC_OPTS += -optc-funroll-loops
-
-ifneq "$(findstring thr, $(way))" ""
-EXTRA_SRCS += sm/Evac_thr.c sm/Scav_thr.c
-CLEAN_FILES += sm/Evac_thr.c sm/Scav_thr.c
-
-sm/Evac_thr.c : sm/Evac.c
- cp $< $@
-sm/Scav_thr.c : sm/Scav.c
- cp $< $@
-
-sm/Evac_thr_HC_OPTS += -optc-DPARALLEL_GC
-sm/Scav_thr_HC_OPTS += -optc-DPARALLEL_GC
-
-sm/Evac_thr_HC_OPTS += -optc-funroll-loops
-else
-EXCLUDED_SRCS += sm/Evac_thr.c sm/Scav_thr.c
-endif
-
-# Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
-sm/Compact_HC_OPTS += -optc-finline-limit=2500
-
-# -fno-strict-aliasing is required for the runtime, because we often
-# use a variety of types to represent closure pointers (StgPtr,
-# StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
-# allowed to assume that these pointers do not alias. eg. without
-# this flag we get problems in sm/Evac.c:copy() with gcc 3.4.3, the
-# upd_evacee() assigments get moved before the object copy.
-SRC_CC_OPTS += -fno-strict-aliasing
-
-# We *want* type-checking of hand-written cmm.
-SRC_HC_OPTS += -dcmm-lint
-
-ifneq "$(BootingFromHc)" "YES"
-# .cmm files depend on all the .h files, to a first approximation.
-%.$(way_)o : %.cmm $(H_FILES)
- $(HC_PRE_OPTS)
- $(HC) $(HC_OPTS) -c $< -o $@
- $(HC_POST_OPTS)
-
-%.$(way_)hc : %.cmm $(H_FILES)
- $(HC) $(HC_OPTS) -C $< -o $@
-
-%.$(way_)s : %.cmm $(H_FILES)
- $(HC) $(HC_OPTS) -S $< -o $@
-endif
-
-#-----------------------------------------------------------------------------
-#
-# Files to install
-#
-# Just libHSrts is installed uniformly across ways
-#
-
-include $(TOP)/mk/target.mk
-
-ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
-# $(LIBRARY).a is not the static library libHSrts.a but
-# libHSrts.dll.a, the import library for dynamic linking required for
-# linking the dynamic version of base
-buildbase: $(LIBRARY).a
- $(MAKE) way="" -C ../libraries/ make.library.ghc-prim
- $(MAKE) way="" -C ../libraries/ make.library.integer-gmp
- $(MAKE) way="" -C ../libraries/ make.library.base
-endif
-
-#-----------------------------------------------------------------------------
-#
-# binary-dist
-
-BINDIST_EXTRAS += package.conf.in
-BINDIST_EXTRAS += $(INSTALL_LIBS)
-BINDIST_EXTRAS += $(INSTALL_LIBEXECS)
-
-# Setting _way here is a nasty hack to make sure we get libHSrts*.a etc
-# rather than just libHSrts.a when we are making bindists.
-binary-dist: _way=*
-
-include $(TOP)/mk/bindist.mk
+dir = rts
+TOP = ..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/rts/ghc.mk b/rts/ghc.mk
new file mode 100644
index 0000000000..e684f62c28
--- /dev/null
+++ b/rts/ghc.mk
@@ -0,0 +1,393 @@
+# -----------------------------------------------------------------------------
+# Building the RTS
+
+# We build the RTS with stage 1
+rts_dist_HC = $(GHC_STAGE1)
+
+rts_WAYS = $(strip $(GhcLibWays) $(GhcRTSWays))
+
+ALL_RTS_LIBS = $(foreach way,$(rts_WAYS),rts/dist/build/libHSrts$($(way)__way).a)
+all_rts : $(ALL_RTS_LIBS)
+
+# The per-dir options
+$(eval $(call distdir-opts,rts,dist))
+
+# -----------------------------------------------------------------------------
+# Defining the sources
+
+ALL_DIRS = hooks parallel sm
+
+ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
+ALL_DIRS += win32
+else
+ALL_DIRS += posix
+endif
+
+EXCLUDED_SRCS += rts/parallel/SysMan.c
+EXCLUDED_SRCS += rts/dyn-wrapper.c
+EXCLUDED_SRCS += $(wildcard rts/Vis*.c)
+
+rts_C_SRCS = $(filter-out $(EXCLUDED_SRCS),$(wildcard rts/*.c $(foreach dir,$(ALL_DIRS),rts/$(dir)/*.c)))
+rts_CMM_SRCS = $(wildcard rts/*.cmm)
+
+ifneq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
+rts_S_SRCS += rts/AdjustorAsm.S
+else
+ifneq "$(findstring $(TargetOS_CPP), darwin)" ""
+rts_S_SRCS += rts/AdjustorAsm.S
+endif
+endif
+
+ifeq "$(GhcUnregisterised)" "YES"
+GENAPPLY_OPTS = -u
+endif
+
+rts_AUTO_APPLY_CMM = rts/dist/build/AutoApply.cmm
+
+$(rts_AUTO_APPLY_CMM): $(GENAPPLY_INPLACE)
+ $(RM) $@
+ $(GENAPPLY_INPLACE) >$@
+
+rts/dist/build/sm/Evac_thr.c : rts/sm/Evac.c
+ $(MKDIRHIER) $(dir $@)
+ cp $< $@
+rts/dist/build/sm/Scav_thr.c : rts/sm/Scav.c
+ $(MKDIRHIER) $(dir $@)
+ cp $< $@
+
+rts_H_FILES = $(wildcard $(GHC_INCLUDE_DIR)/*.h) $(wildcard rts/*.h)
+
+#-----------------------------------------------------------------------------
+# Building one way
+
+define cmm-suffix-rules
+# $1 = dir
+# $2 = distdir
+# $3 = way
+
+# .cmm files depend on all the .h files, to a first approximation.
+
+$1/$2/build/%.$$($3_way_)o : $1/%.cmm $$(rts_H_FILES) $$($1_$2_HC)
+ $$($1_$2_HC) $$($1_$2_$3_MOST_HC_OPTS) -c $$< -o $$@
+
+$1/$2/build/%.$$($3_way_)o : $1/$2/build/%.cmm $$(rts_H_FILES) $$($1_$2_HC)
+ $$($1_$2_HC) $$($1_$2_$3_MOST_HC_OPTS) -c $$< -o $$@
+
+$1/$2/build/%.$$($3_way_)hc : $1/%.cmm $$(rts_H_FILES) $$($1_$2_HC)
+ $$($1_$2_HC) $$($1_$2_$3_MOST_HC_OPTS) -c $$< -o $$@
+
+$1/$2/build/%.$$($3_way_)hc : $1/$2/build/%.cmm $$(rts_H_FILES) $$($1_$2_HC)
+ $$($1_$2_HC) $$($1_$2_$3_MOST_HC_OPTS) -c $$< -o $$@
+
+$1/$2/build/%.$$($3_way_)s : $1/%.cmm $$(rts_H_FILES) $$($1_$2_HC)
+ $$($1_$2_HC) $$($1_$2_$3_MOST_HC_OPTS) -c $$< -o $$@
+
+$1/$2/build/%.$$($3_way_)s : $1/$2/build/%.cmm $$(rts_H_FILES) $$($1_$2_HC)
+ $$($1_$2_HC) $$($1_$2_$3_MOST_HC_OPTS) -c $$< -o $$@
+
+endef
+
+
+define build-rts-way # args: $1 = way
+
+# The per-way CC_OPTS
+ifneq "$$(findstring debug, $1)" ""
+rts_dist_$1_HC_OPTS =
+rts_dist_$1_CC_OPTS = -g -O0
+else
+rts_dist_$1_HC_OPTS = $(GhcRtsHcOpts)
+rts_dist_$1_CC_OPTS = $(GhcRtsCcOpts)
+endif
+
+ifneq "$$(findstring thr, $1)" ""
+rts_$1_EXTRA_C_SRCS = rts/dist/build/sm/Evac_thr.c rts/dist/build/sm/Scav_thr.c
+endif
+
+$(call distdir-way-opts,rts,dist,$1)
+$(call c-suffix-rules,rts,dist,$1,YES)
+$(call cmm-suffix-rules,rts,dist,$1)
+
+rts_$1_LIB = rts/dist/build/libHSrts$$($1__way).a
+
+rts_$1_C_OBJS = $$(patsubst rts/%.c,rts/dist/build/%.$$($1_osuf),$$(rts_C_SRCS)) $$(patsubst %.c,%.$$($1_osuf),$$(rts_$1_EXTRA_C_SRCS))
+rts_$1_S_OBJS = $$(patsubst rts/%.S,rts/dist/build/%.$$($1_osuf),$$(rts_S_SRCS))
+rts_$1_CMM_OBJS = $$(patsubst rts/%.cmm,rts/dist/build/%.$$($1_osuf),$$(rts_CMM_SRCS)) $$(patsubst %.cmm,%.$$($1_osuf),$(rts_AUTO_APPLY_CMM))
+
+rts_$1_OBJS = $$(rts_$1_C_OBJS) $$(rts_$1_S_OBJS) $$(rts_$1_CMM_OBJS)
+
+$$(rts_$1_LIB) : $$(rts_$1_OBJS)
+ $$(RM) $$@
+ echo $$(rts_$1_OBJS) | xargs $$(AR) $$(EXTRA_AR_ARGS) $$@
+
+endef
+
+# And expand the above for each way:
+$(foreach way,$(rts_WAYS),$(eval $(call build-rts-way,$(way))))
+
+#-----------------------------------------------------------------------------
+# Flags for compiling every file
+
+# gcc provides lots of useful warnings if you ask it.
+# This is a pretty good list to start with - use a # to comment out
+# any you don't like.
+WARNING_OPTS += -Wall
+WARNING_OPTS += -W
+WARNING_OPTS += -Wstrict-prototypes
+WARNING_OPTS += -Wmissing-prototypes
+WARNING_OPTS += -Wmissing-declarations
+WARNING_OPTS += -Winline
+WARNING_OPTS += -Waggregate-return
+#WARNING_OPTS += -Wpointer-arith
+#WARNING_OPTS += -Wbad-function-cast
+#WARNING_OPTS += -Wcast-align
+#WARNING_OPTS += -Wnested-externs
+#WARNING_OPTS += -Wshadow
+#WARNING_OPTS += -Wcast-qual
+#WARNING_OPTS += -Wno-unused
+#WARNING_OPTS += -Wredundant-decls
+#WARNING_OPTS += -Wconversion
+
+STANDARD_OPTS += -I$(GHC_INCLUDE_DIR) -I$(GHC_RTS_DIR) -Irts/parallel -Irts/sm -Irts/eventlog
+# COMPILING_RTS is only used when building Win32 DLL support.
+STANDARD_OPTS += -DCOMPILING_RTS
+
+# HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
+# only included in .c compilations. HC_OPTS included the WAY_* opts, which
+# must be included in both types of compilations.
+
+rts_CC_OPTS += $(WARNING_OPTS)
+rts_CC_OPTS += $(STANDARD_OPTS)
+
+rts_HC_OPTS += $(STANDARD_OPTS) -package-name rts
+
+ifneq "$(GhcWithSMP)" "YES"
+rts_CC_OPTS += -DNOSMP
+rts_HC_OPTS += -optc-DNOSMP
+endif
+
+ifeq "$(UseLibFFIForAdjustors)" "YES"
+rts_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
+endif
+
+ifeq "$(Windows)" "YES"
+# SDM: when compiled with -fasm the RTS currently has bogus references to
+# __imp_base_ things, so working around for now:
+rts_HC_OPTS += -fvia-C
+endif
+
+ifneq "$(DYNAMIC_RTS)" "YES"
+rts_HC_OPTS += -static
+else
+$(error ToDo: DYNAMIC_RTS)
+endif
+
+# Mac OS X: make sure we compile for the right OS version
+rts_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
+rts_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
+rts_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
+
+# Otherwise the stack-smash handler gets triggered.
+ifeq "$(TargetOS_CPP)" "openbsd"
+rts_HC_OPTS += -optc-fno-stack-protector
+endif
+
+# We *want* type-checking of hand-written cmm.
+rts_HC_OPTS += -dcmm-lint
+
+# -fno-strict-aliasing is required for the runtime, because we often
+# use a variety of types to represent closure pointers (StgPtr,
+# StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
+# allowed to assume that these pointers do not alias. eg. without
+# this flag we get problems in sm/Evac.c:copy() with gcc 3.4.3, the
+# upd_evacee() assigments get moved before the object copy.
+rts_CC_OPTS += -fno-strict-aliasing
+
+ifeq "$(BeConservative)" "YES"
+rts_CC_OPTS += -DBE_CONSERVATIVE
+endif
+
+#-----------------------------------------------------------------------------
+# Flags for compiling specific files
+
+# XXX DQ is now the same on all platforms, so get rid of it
+DQ = \"
+
+# If Main.c is built with optimisation then the SEH exception stuff on
+# Windows gets confused.
+# This has to be in HC rather than CC opts, as otherwise there's a
+# -optc-O2 that comes after it.
+Main_HC_OPTS += -optc-O0
+
+RtsMessages_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
+RtsUtils_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
+RtsUtils_CC_OPTS += -DRtsWay=$(DQ)rts$(_way)$(DQ)
+#
+RtsUtils_CC_OPTS += -DHostPlatform=$(DQ)$(HOSTPLATFORM)$(DQ)
+RtsUtils_CC_OPTS += -DHostArch=$(DQ)$(HostArch_CPP)$(DQ)
+RtsUtils_CC_OPTS += -DHostOS=$(DQ)$(HostOS_CPP)$(DQ)
+RtsUtils_CC_OPTS += -DHostVendor=$(DQ)$(HostVendor_CPP)$(DQ)
+#
+RtsUtils_CC_OPTS += -DBuildPlatform=$(DQ)$(BUILDPLATFORM)$(DQ)
+RtsUtils_CC_OPTS += -DBuildArch=$(DQ)$(BuildArch_CPP)$(DQ)
+RtsUtils_CC_OPTS += -DBuildOS=$(DQ)$(BuildOS_CPP)$(DQ)
+RtsUtils_CC_OPTS += -DBuildVendor=$(DQ)$(BuildVendor_CPP)$(DQ)
+#
+RtsUtils_CC_OPTS += -DTargetPlatform=$(DQ)$(TARGETPLATFORM)$(DQ)
+RtsUtils_CC_OPTS += -DTargetArch=$(DQ)$(TargetArch_CPP)$(DQ)
+RtsUtils_CC_OPTS += -DTargetOS=$(DQ)$(TargetOS_CPP)$(DQ)
+RtsUtils_CC_OPTS += -DTargetVendor=$(DQ)$(TargetVendor_CPP)$(DQ)
+#
+RtsUtils_CC_OPTS += -DGhcUnregisterised=$(DQ)$(GhcUnregisterised)$(DQ)
+RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=$(DQ)$(GhcEnableTablesNextToCode)$(DQ)
+
+# ffi.h triggers prototype warnings, so disable them here:
+Interpreter_CC_OPTS += -Wno-strict-prototypes
+Adjustor_CC_OPTS += -Wno-strict-prototypes
+sm/Storage_CC_OPTS += -Wno-strict-prototypes
+
+StgCRun_CC_OPTS += -w
+Typeable_CC_OPTS += -w
+RetainerProfile_CC_OPTS += -w
+sm/Compact_CC_OPTS += -w
+# On Windows:
+win32/ConsoleHandler_CC_OPTS += -w
+win32/ThrIOManager_CC_OPTS += -w
+win32/Ticker_CC_OPTS += -w
+# The above warning supression flags are a temporary kludge.
+# While working on this module you are encouraged to remove it and fix
+# any warnings in the module. See
+# http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
+# for details
+
+# Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
+sm/Compact_CC_OPTS += -finline-limit=2500
+
+# -O3 helps unroll some loops (especially in copy() with a constant argument).
+sm/Evac_CC_OPTS += -funroll-loops
+sm/Evac_thr_HC_OPTS += -optc-funroll-loops
+
+# These files are just copies of sm/Evac.c and sm/Scav.c respectively,
+# but compiled with -DPARALLEL_GC.
+sm/Evac_thr_HC_OPTS += -optc-DPARALLEL_GC
+sm/Scav_thr_HC_OPTS += -optc-DPARALLEL_GC
+
+#-----------------------------------------------------------------------------
+# Add PAPI library if needed
+
+ifeq "$(GhcRtsWithPapi)" "YES"
+
+rts_CC_OPTS += -DUSE_PAPI
+
+rts_PACKAGE_CPP_OPTS += -DUSE_PAPI
+rts_PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=$(PapiIncludeDir)
+rts_PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=$(PapiLibDir)
+
+ifneq "$(PapiIncludeDir)" ""
+rts_HC_OPTS += -I$(PapiIncludeDir)
+rts_CC_OPTS += -I$(PapiIncludeDir)
+rts_HSC2HS_OPTS += -I$(PapiIncludeDir)
+endif
+ifneq "$(PapiLibDirs)" ""
+rts_LD_OPTS += -L$(PapiLibDirs)
+endif
+
+else # GhcRtsWithPapi==YES
+
+rts_PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=""
+rts_PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=""
+
+endif
+
+# -----------------------------------------------------------------------------
+# dependencies
+
+# Hack: we define every way-related option here, so that we get (hopefully)
+# a superset of the dependencies. To do this properly, we should generate
+# a different set of dependencies for each way. Further hack: PROFILING and
+# TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
+rts_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
+
+rts_WAYS_DASHED = $(subst $(space),,$(patsubst %,-%,$(strip $(rts_WAYS))))
+rts_dist_depfile = rts/dist/build/.depend$(rts_WAYS_DASHED)
+
+rts_dist_C_SRCS = $(rts_C_SRCS)
+rts_dist_S_SRCS = $(rts_S_SRCS)
+rts_dist_C_FILES = $(rts_C_SRCS) $(rts_S_SRCS)
+
+$(eval $(call build-dependencies,rts,dist))
+
+$(rts_dist_depfile) : libffi/ffi.h
+
+# -----------------------------------------------------------------------------
+
+# Need to get the GMP vars in through CPP to package.conf.in, and put
+# quotes around each element.
+
+rts_PACKAGE_CPP_OPTS += -DGMP_INCLUDE_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_INCLUDE_DIRS))))'
+rts_PACKAGE_CPP_OPTS += -DGMP_LIB_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_LIB_DIRS))))'
+
+ifneq "$(GMP_INCLUDE_DIRS)" ""
+rts_HC_OPTS += -I$(GMP_INCLUDE_DIRS)
+rts_CC_OPTS += -I$(GMP_INCLUDE_DIRS)
+rts_HSC2HS_OPTS += -I$(GMP_INCLUDE_DIRS)
+endif
+ifneq "$(GMP_LIB_DIRS)" ""
+rts_LD_OPTS += -L$(GMP_LIB_DIRS)
+endif
+
+rts_CC_OPTS += -Igmp/gmpbuild
+rts_HC_OPTS += -Igmp/gmpbuild
+rts_HSC2HS_OPTS += -Igmp/gmpbuild
+rts_LD_OPTS += -Lgmp/gmpbuild
+
+#-----------------------------------------------------------------------------
+# libffi stuff
+
+rts_CC_OPTS += -Ilibffi/build/include
+rts_HC_OPTS += -Ilibffi/build/include
+rts_HSC2HS_OPTS += -Ilibffi/build/include
+rts_LD_OPTS += -Llibffi/build/include
+
+# -----------------------------------------------------------------------------
+# compile generic patchable dyn-wrapper
+
+DYNWRAPPER_SRC = rts/dyn-wrapper.c
+DYNWRAPPER_PROG = rts/dyn-wrapper$(exeext)
+$(DYNWRAPPER_PROG): $(DYNWRAPPER_SRC)
+ $(HC) -cpp -optc-include -optcdyn-wrapper-patchable-behaviour.h $(INPLACE_EXTRA_FLAGS) $< -o $@
+
+# -----------------------------------------------------------------------------
+# The RTS package config
+
+# If -DDEBUG is in effect, adjust package conf accordingly..
+ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
+rts_PACKAGE_CPP_OPTS += -DDEBUG
+endif
+
+ifeq "$(HaveLibMingwEx)" "YES"
+rts_PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
+endif
+
+$(eval $(call manual-package-config,rts))
+
+rts/package.conf.inplace : $(includes_H_CONFIG) $(includes_H_PLATFORM)
+
+# -----------------------------------------------------------------------------
+# installing
+
+install : install_rts
+
+.PHONY: install_rts
+install_rts:
+ $(MKDIRHIER) $(DESTDIR)$(libdir)
+ $(MKDIRHIER) $(DESTDIR)$(libdir)/include
+ $(CP) $(ALL_RTS_LIBS) $(DESTDIR)$(libdir)
+
+# -----------------------------------------------------------------------------
+# cleaning
+
+$(eval $(call clean-target,rts,dist,rts/dist))
+
+BINDIST_EXTRAS += rts/package.conf.in
+BINDIST_EXTRAS += $(ALL_RTS_LIBS)
+
diff --git a/rts/package.conf.in b/rts/package.conf.in
index 490222fdb9..54f3b27543 100644
--- a/rts/package.conf.in
+++ b/rts/package.conf.in
@@ -3,7 +3,7 @@
#include "ghcconfig.h"
#include "RtsConfig.h"
-name: PACKAGE
+name: rts
version: 1.0
license: BSD3
maintainer: glasgow-haskell-users@haskell.org
@@ -21,9 +21,9 @@ library-dirs: LIB_DIR GMP_LIB_DIRS PAPI_LIB_DIR
/* force the dist-provided gcc-lib/ into scope. */
# endif
#else /* !INSTALLING */
-library-dirs: FPTOOLS_TOP_ABS"/rts" GMP_LIB_DIRS PAPI_LIB_DIR
+library-dirs: TOP"/rts/dist/build" GMP_LIB_DIRS PAPI_LIB_DIR
# if !defined(HAVE_LIB_GMP) && !defined(HAVE_FRAMEWORK_GMP)
- , FPTOOLS_TOP_ABS"/gmp"
+ , TOP"/gmp"
# endif
#endif
@@ -60,9 +60,9 @@ extra-libraries: "m" /* for ldexp() */
#ifdef INSTALLING
include-dirs: INCLUDE_DIR GMP_INCLUDE_DIRS PAPI_INCLUDE_DIR
#else /* !INSTALLING */
-include-dirs: FPTOOLS_TOP_ABS"/includes"
+include-dirs: TOP"/includes"
# if !defined(HAVE_LIB_GMP) && !defined(HAVE_FRAMEWORK_GMP)
- FPTOOLS_TOP_ABS"/gmp/gmpbuild"
+ TOP"/gmp/gmpbuild"
# endif
GMP_INCLUDE_DIRS
#endif
diff --git a/rules/all-target.mk b/rules/all-target.mk
new file mode 100644
index 0000000000..976ff1debe
--- /dev/null
+++ b/rules/all-target.mk
@@ -0,0 +1,7 @@
+
+define all-target # args: $1 = dir, $2 = deps
+all : all_$1
+.PHONY: all_$1
+all_$1 : $2
+endef
+
diff --git a/rules/bindist.mk b/rules/bindist.mk
new file mode 100644
index 0000000000..b9e093c56e
--- /dev/null
+++ b/rules/bindist.mk
@@ -0,0 +1,16 @@
+
+# Add files to the bindist. Invoke like this:
+#
+# $(eval $(call bindist,utils/genapply,ghc.mk))
+
+define bindist
+# $1 = dir
+# $2 = files
+
+.PHONY: bindist_$1
+bindist: bindist_$1
+
+bindist_$1:
+ for f in $$(addprefix $1/,$2); do echo $(BIN_DIST_NAME)/$$$$f >> $(BIN_DIST_LIST); done
+endef
+
diff --git a/rules/build-dependencies.mk b/rules/build-dependencies.mk
new file mode 100644
index 0000000000..860a2f6ff3
--- /dev/null
+++ b/rules/build-dependencies.mk
@@ -0,0 +1,48 @@
+
+define build-dependencies # args: $1 = dir, $2 = distdir
+
+ifeq "$$($1_$2_ghc_ge_609)" "YES"
+$1_$2_MKDEPENDHS_FLAGS = -include-pkg-deps -dep-makefile $$($1_$2_depfile) $$(foreach way,$$(filter-out v,$$($1_$2_WAYS)),-dep-suffix $$(way))
+else
+$1_$2_MKDEPENDHS_FLAGS = -optdep--include-pkg-deps -optdep-f -optdep$$($1_$2_depfile) $$(foreach way,$$(filter-out v,$$($1_$2_WAYS)),-optdep-s -optdep$$(way))
+endif
+
+ifneq "$$($1_$2_NO_BUILD_DEPS)" "YES"
+
+$$($1_$2_depfile) : $$(MKDIRHIER) $$(MKDEPENDC) $$($1_$2_HS_SRCS) $$($1_$2_HS_BOOT_SRCS) $$($1_$2_HC_MK_DEPEND_DEP) $$($1_$2_C_FILES) $$($1_$2_S_FILES)
+ $$(MKDIRHIER) $1/$2/build
+ $(RM) $$@ $$@.tmp
+ touch $$@.tmp
+ifneq "$$($1_$2_C_SRCS)$$($1_$2_S_SRCS)" ""
+ $$(MKDEPENDC) -f $$($1_$2_depfile).tmp $$($1_MKDEPENDC_OPTS) $$(foreach way,$$($1_WAYS),-s $$(way)) -- $$($1_$2_v_ALL_CC_OPTS) -- $$($1_$2_C_FILES) $$($1_$2_S_FILES) || ( $$(RM) $$@; exit 1 )
+ sed -e "s|$1/\([^ :]*o[ :]\)|$1/$2/build/\1|g" -e "s|$(TOP)/||" <$$($1_$2_depfile).tmp >$$($1_$2_depfile)
+endif
+ifneq "$$($1_$2_HS_SRCS)" ""
+ $$($1_$2_HC_MK_DEPEND) -M $$($1_$2_MKDEPENDHS_FLAGS) \
+ $$(filter-out -split-objs, $$($1_$2_v_ALL_HC_OPTS)) \
+ $$($1_$2_HS_SRCS) || ( $$(RM) $$@; exit 1 )
+endif
+ echo "$1_$2_depfile_EXISTS = YES" >> $$@
+ifneq "$$($1_$2_SLASH_MODS)" ""
+ for dir in $$(sort $$(foreach mod,$$($1_$2_SLASH_MODS),$1/$2/build/$$(dir $$(mod)))); do \
+ if test ! -d $$$$dir; then mkdir -p $$$$dir; fi \
+ done
+endif
+
+endif # $1_$2_NO_BUILD_DEPS
+
+# Note sed magic above: mkdependC can't do -odir stuff, so we have to
+# munge the dependencies it generates to refer to the correct targets.
+
+# Seems as good a place as any to attach the unlit dependency
+$$($1_$2_depfile) : $$(UNLIT)
+
+ifneq "$$(NO_INCLUDE_DEPS)" "YES"
+include $$($1_$2_depfile)
+else
+ifeq "$$(DEBUG)" "YES"
+$$(warning not building dependencies in $1)
+endif
+endif
+
+endef
diff --git a/rules/build-package-data.mk b/rules/build-package-data.mk
new file mode 100644
index 0000000000..206a6591f9
--- /dev/null
+++ b/rules/build-package-data.mk
@@ -0,0 +1,16 @@
+define build-package-data # args: $1 = dir, $2 = distdir
+
+ifeq "$(HSCOLOUR_SRCS)" "YES"
+$1_$2_CONFIGURE_FLAGS += --with-hscolour="$$(HSCOLOUR)"
+endif
+
+# This rule configures the package, generates the package-data.mk file
+# for our build system, and registers the package for use in-place in
+# the build tree.
+$1/$2/package-data.mk $1/$2/inplace-pkg-config $1/$2/build/autogen/cabal_macros.h : $$(GHC_CABAL_INPLACE) $$($1_$2_GHC_PKG_DEP) $1/$$($1_PACKAGE).cabal $$(wildcard $1/configure) $$($1_$2_HC_CONFIG_DEP)
+ $$(GHC_CABAL_INPLACE) configure --with-ghc=$$($1_$2_HC_CONFIG) --with-ghc-pkg=$$($1_$2_GHC_PKG) --with-gcc=$$(WhatGccIsCalled) --configure-option=--with-cc=$$(WhatGccIsCalled) $$($1_$2_CONFIGURE_FLAGS) $$($1_CONFIGURE_OPTS) $$($1_$2_CONFIGURE_OPTS) -- $2 $1
+ if [ "$$($1_$2_PROG)" = "" ]; then \
+ $$($1_$2_GHC_PKG) update --force $$($1_$2_GHC_PKG_OPTS) $1/$2/inplace-pkg-config; \
+ fi
+
+endef
diff --git a/rules/build-package-way.mk b/rules/build-package-way.mk
new file mode 100644
index 0000000000..086c231b43
--- /dev/null
+++ b/rules/build-package-way.mk
@@ -0,0 +1,52 @@
+
+define build-package-way # $1 = dir, $2 = distdir, $3 = way, $4 = stage
+
+$(call distdir-way-opts,$1,$2,$3)
+$(call hs-suffix-rules,$1,$2,$3)
+$$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
+ $$(eval $$(call hs-suffix-rules-srcdir,$1,$2,$3,$$(dir))))
+
+$(call hs-objs,$1,$2,$3)
+
+$1_$2_$3_LIB = $1/$2/build/libHS$$($1_PACKAGE)-$$($1_$2_VERSION)$$($3__way).a
+
+$1_$2_$3_MKSTUBOBJS = find $1/$2/build -name "*_stub.$$($3_osuf)" -print
+# HACK ^^^ we tried to use $(wildcard), but apparently it fails due to
+# make using cached directory contents, or something.
+
+# Build the ordinary .a library
+ifeq "$$($1_$2_SplitObjs)" "YES"
+$$($1_$2_$3_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_C_OBJS) $$($1_$2_S_OBJS)
+ $$(RM) $$@
+ (echo $$($1_$2_C_OBJS) $$($1_$2_S_OBJS) `$$($1_$2_$3_MKSTUBOBJS)`; find $$(patsubst %.$$($3_osuf),%_split,$$($1_$2_$3_HS_OBJS)) -name '*.$$($3_osuf)' -print) | xargs $$(AR) $$(EXTRA_AR_ARGS) $$@
+else
+$$($1_$2_$3_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_C_OBJS) $$($1_$2_S_OBJS)
+ $$(RM) $$@
+ echo $$($1_$2_C_OBJS) $$($1_$2_S_OBJS) $$($1_$2_$3_HS_OBJS) `$$($1_$2_$3_MKSTUBOBJS)` | xargs $$(AR) $$(EXTRA_AR_ARGS) $$@
+endif
+
+$(call all-target,$1_$2,all_$1_$2_$3)
+$(call all-target,$1_$2_$3,$$($1_$2_$3_LIB))
+
+# Don't put bootstrapping packages in the bindist
+ifneq "$4" "0"
+BINDIST_HI += $$($1_$2_$3_HI)
+BINDIST_LIBS += $$($1_$2_$3_LIB)
+endif
+
+# Build the GHCi library
+ifeq "$3" "v"
+$1_$2_GHCI_LIB = $1/$2/build/HS$$($1_PACKAGE)-$$($1_$2_VERSION).$$($3_osuf)
+# Don't put bootstrapping packages in the bindist
+ifneq "$4" "0"
+BINDIST_LIBS += $$($1_$2_GHCI_LIB)
+endif
+$$($1_$2_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_C_OBJS) $$($1_$2_S_OBJS)
+ $$(RM) $$@
+ $$(LD) -r -o $$@ $$(EXTRA_LD_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_C_OBJS) $$($1_$2_S_OBJS) `$$($1_$2_$3_MKSTUBOBJS)`
+
+$(call all-target,$1_$2,$$($1_$2_GHCI_LIB))
+endif
+
+endef
+
diff --git a/rules/build-package.mk b/rules/build-package.mk
new file mode 100644
index 0000000000..4ca3c6e66f
--- /dev/null
+++ b/rules/build-package.mk
@@ -0,0 +1,135 @@
+
+# Build a package with the stage-1 compiler, multiple ways. A typical
+# libraries/foo/ghc.mk will look like this:
+#
+# $(eval $(call build-package,libraries/base,dist-install))
+#
+# The package metadata is generated from the .cabal file and placed in
+# package-data.mk. It will look something like this:
+#
+# libraries/base_dist_MODULES = GHC.Base Data.Tuple ...
+# libraries/base_dist_PACKAGE = base
+# libraries/base_dist_VERSION = 4.0.0.0
+# libraries/base_dist_HC_OPTS = -package ghc-prim-0.1.0.0 -XRank2Types ...
+# libraries/base_dist_C_SRCS = cbits/PrelIOUtils.c ...
+# libraries/base_dist_S_SRCS = cbits/foo.S ...
+# libraries/base_dist_CC_OPTS = -Iinclude ...
+# libraries/base_dist_LD_OPTS = -package ghc-prim-0.1.0.0
+
+# TODO: soext
+
+define build-package
+# $1 = dir
+# $2 = distdir
+# $3 = GHC stage to use (0 == bootstrapping compiler)
+
+ifeq "$$(findstring $3,0 1 2)" ""
+$$(error $1/$2: stage argument to build-package should be 0, 1, or 2)
+endif
+
+# We don't install things compiled by stage 0, so no need to put them
+# in the bindist.
+ifneq "$(BINDIST) $3" "YES 0"
+
+$(call all-target,$1,all_$1_$2)
+
+$(call clean-target,$1,$2,$1/$2)
+
+distclean : clean_$1_$2_config
+
+.PHONY: clean_$1_$2_config
+clean_$1_$2_config:
+ $(RM) $1/config.log $1/config.status $1/include/Hs*Config.h
+ $(RM) -r $1/autom4te.cache
+
+# --- CONFIGURATION
+
+$1_$2_USE_BOOT_LIBS = YES
+$(call package-config,$1,$2,$3)
+
+ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
+include $1/$2/package-data.mk
+endif
+
+ifeq "$$($1_$2_DISABLE)" "YES"
+
+ifeq "$$(DEBUG)" "YES"
+$$(warning $1/$2 disabled)
+endif
+
+# A package is disabled when we want to bring its package-data.mk file
+# up-to-date first, or due to other build dependencies.
+
+$(call all-target,$1_$2,$1/$2/package-data.mk)
+
+ifneq "$(BINDIST)" "YES"
+# We have a rule for package-data.mk only when the package is
+# disabled, because we want the build to fail if we haven't run phase 0.
+$(call build-package-data,$1,$2)
+endif
+
+else
+
+ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
+ifeq "$$($1_$2_VERSION)" ""
+$$(error phase ordering error: $1/$2 is enabled, but $1/$2/package-data.mk does not exist)
+endif
+endif
+
+# Sometimes we need to modify the automatically-generated package-data.mk
+# bindings in a special way for the GHC build system, so allow that here:
+$($1_PACKAGE_MAGIC)
+
+# Bootstrapping libs are only built one way
+ifeq "$3" "0"
+$1_$2_WAYS = v
+else
+$1_$2_WAYS = $$(GhcLibWays)
+endif
+
+$(call hs-sources,$1,$2)
+$(call c-sources,$1,$2)
+$(call includes-sources,$1,$2)
+
+# --- DEPENDENCIES
+
+# We must use a different dependency file if $(GhcLibWays) changes, so
+# encode the ways into the name of the file.
+$1_$2_WAYS_DASHED = $$(subst $$(space),,$$(patsubst %,-%,$$(strip $$($1_$2_WAYS))))
+$1_$2_depfile = $1/$2/build/.depend$$($1_$2_WAYS_DASHED)
+
+$(call build-dependencies,$1,$2)
+
+# --- BUILDING
+
+# We don't bother splitting the bootstrap packages (built with stage 0)
+ifeq "$$($1_$2_SplitObjs)" ""
+ifeq "$$(SplitObjs) $3" "YES 1"
+$1_$2_SplitObjs = YES
+else
+$1_$2_SplitObjs = NO
+endif
+endif
+
+# C and S files are built only once, not once per way
+$(call c-objs,$1,$2)
+$(call distdir-opts,$1,$2,$3)
+$(call c-suffix-rules,$1,$2,v,YES)
+
+# Now generate all the build rules for each way in this directory:
+$$(foreach way,$$($1_$2_WAYS),$$(eval $$(call build-package-way,$1,$2,$$(way),$3)))
+
+$(call haddock,$1,$2)
+
+endif # package-data.mk exists
+
+# Don't put bootstrapping packages in the bindist
+ifeq "$3" "1"
+BINDIST_EXTRAS += $1/*.cabal $1/$2/setup-config $1/LICENSE
+BINDIST_EXTRAS += $$($1_$2_INSTALL_INCLUDES_SRCS)
+endif
+
+endif
+
+endef
+
diff --git a/rules/build-perl.mk b/rules/build-perl.mk
new file mode 100644
index 0000000000..48694e460e
--- /dev/null
+++ b/rules/build-perl.mk
@@ -0,0 +1,45 @@
+
+# Build a perl script. Invoke like this:
+#
+# driver/mangler_PERL_SRC = ghc-asm.lprl
+# driver/mangler_dist_PROG = ghc-asm
+#
+# $(eval $(call build-perl,driver/mangler,dist))
+
+define build-perl
+# $1 = dir
+# $2 = distdir
+
+ifeq "$$($1_$2_LIBEXEC)" "YES"
+$1_$2_INPLACE = $(INPLACE_LIB)/$$($1_$2_PROG)
+else
+$1_$2_INPLACE = $(INPLACE_BIN)/$$($1_$2_PROG)
+endif
+
+$(call all-target,$$($1_$2_INPLACE))
+
+$(call clean-target,$1,$2,$1/$2 $$($1_$2_INPLACE))
+.PHONY: clean_$1
+clean_$1 : clean_$1_$2
+
+ifneq "$$(BINDIST)" "YES"
+$1/$2/$$($1_$2_PROG).prl: $1/$$($1_PERL_SRC) $$(UNLIT)
+ $$(MKDIRHIER) $1/$2
+ $$(RM) -f $$@
+ $$(UNLIT) $$(UNLIT_OPTS) $$< $$@
+
+$1/$2/$$($1_$2_PROG): $1/$2/$$($1_$2_PROG).prl
+ $$(RM) -f $$@
+ echo '#!$$(PERL)' >> $$@
+ echo '$$$$TARGETPLATFORM = "$$(TARGETPLATFORM)";' >> $$@
+ cat $$< >> $$@
+ $$(EXECUTABLE_FILE) $$@
+
+$$($1_$2_INPLACE): $1/$2/$$($1_$2_PROG)
+ $$(MKDIRHIER) $$(dir $$@)
+ $$(RM) -f $$@
+ $$(CP) $$< $$@
+ $$(EXECUTABLE_FILE) $$@
+endif
+
+endef
diff --git a/rules/build-prog.mk b/rules/build-prog.mk
new file mode 100644
index 0000000000..46dd5af273
--- /dev/null
+++ b/rules/build-prog.mk
@@ -0,0 +1,139 @@
+
+# Build a program with the stage-1 compiler. Invoke like this:
+#
+# utils/genapply_MODULES = Main
+# utils/genapply_HC_OPTS = -package Cabal
+# utils/genapply_dist_PROG = genapply
+#
+# $(eval $(call build-prog,utils/genapply,dist-install))
+
+define build-prog
+# $1 = dir
+# $2 = distdir
+# $3 = GHC stage to use (0 == bootstrapping compiler)
+
+ifeq "$$($1_$2_PROG)" ""
+$$(error $1_$2_PROG is not set)
+endif
+
+ifeq "$$(findstring $3,0 1 2)" ""
+$$(error $1/$2: stage argument to build-prog should be 0, 1, or 2)
+endif
+
+$(call all-target,$1,all_$1_$2)
+
+$(call clean-target,$1,$2,$1/$2)
+
+$(call package-config,$1,$2,$3)
+
+ifeq "$$($1_USES_CABAL)" "YES"
+ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
+include $1/$2/package-data.mk
+endif
+endif
+
+ifeq "$$($1_USES_CABAL)$$($1_$2_VERSION)" "YES"
+$1_$2_DISABLE = YES
+endif
+
+ifeq "$$($1_$2_DISABLE)" "YES"
+
+ifeq "$$(DEBUG)" "YES"
+$$(warning $1/$2 disabled)
+endif
+
+# The following code to build the package all depends on settings
+# obtained from package-data.mk. If we don't have package-data.mk
+# yet, then don't try to do anything else with this package. Make will
+# try to build package-data.mk, then restart itself and we'll be in business.
+
+$(call all-target,$1_$2,$1/$2/package-data.mk)
+
+# We have a rule for package-data.mk only when the package is
+# disabled, because we want the build to fail if we haven't run phase 0.
+ifneq "$(BINDIST)" "YES"
+$(call build-package-data,$1,$2)
+endif
+
+else
+
+ifneq "$(BINDIST)" "YES"
+$(call hs-sources,$1,$2)
+$(call c-sources,$1,$2)
+
+# --- DEPENDENCIES
+
+$1_$2_depfile = $1/$2/build/.depend
+
+$(call build-dependencies,$1,$2)
+
+# --- IMPLICIT RULES
+
+$(call distdir-opts,$1,$2,$3)
+
+# Just the 'v' way for programs
+$(call distdir-way-opts,$1,$2,v)
+
+$(call c-suffix-rules,$1,$2,v,YES)
+
+$(call hs-suffix-rules,$1,$2,v)
+$$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
+ $$(eval $$(call hs-suffix-rules-srcdir,$1,$2,v,$$(dir))))
+
+$(call c-objs,$1,$2)
+$(call hs-objs,$1,$2,v)
+
+$1/$2/build/tmp/$$($1_$2_PROG) : $$($1_$2_v_HS_OBJS) $$($1_$2_C_OBJS) $$($1_$2_S_OBJS) $$($1_$2_OTHER_OBJS)
+ $$(MKDIRHIER) $$(dir $$@)
+ $$($1_$2_HC) -o $$@ $$($1_$2_v_ALL_HC_OPTS) $$(LD_OPTS) $$($1_$2_v_HS_OBJS) $$($1_$2_C_OBJS) $$($1_$2_S_OBJS) $$($1_$2_OTHER_OBJS)
+
+# Note [lib-depends] if this program is built with stage1 or greater, we
+# need to depend on the libraries too. NB. since $(ALL_LIBS) and
+# $(ALL_RTS_LIBS) are not defined until after libraries/*/ghc.mk have
+# been included, this introduces an ordering dependency.
+ifneq "$3" "0"
+ifeq "$$(ALL_LIBS)" ""
+$$(error ordering failure in $1: $$(ALL_LIBS) is empty)
+endif
+$1/$2/build/tmp/$($1_$2_PROG) : $$(ALL_LIBS) $$(ALL_RTS_LIBS) $$(OTHER_LIBS)
+endif
+endif
+
+ifeq "$$($1_$2_INSTALL_INPLACE)" "NO"
+$(call all-target,$1_$2,$1/$2/build/tmp/$$($1_$2_PROG))
+else
+# Where do we install the inplace version?
+ifeq "$$($1_$2_SHELL_WRAPPER) $$(Windows)" "YES NO"
+$1_$2_INPLACE = $$(INPLACE_LIB)/$$($1_$2_PROG)
+else
+ifeq "$$($1_$2_LIBEXEC)" "YES"
+$1_$2_INPLACE = $$(INPLACE_LIB)/$$($1_$2_PROG)
+else
+$1_$2_INPLACE = $$(INPLACE_BIN)/$$($1_$2_PROG)
+endif
+endif
+
+$(call all-target,$1_$2,$$($1_$2_INPLACE))
+$(call clean-target,$1,$2_inplace,$$($1_$2_INPLACE))
+
+$$($1_$2_INPLACE) : $1/$2/build/tmp/$$($1_$2_PROG) $$(MKDIRHIER)
+ $$(MKDIRHIER) $$(dir $$@)
+ $$(CP) -p $$< $$@
+ touch $$@
+
+# touch is necessary; cp doesn't update the file time.
+endif
+
+$(call shell-wrapper,$1,$2)
+
+ifeq "$$($1_$2_INSTALL)" "YES"
+ifeq "$$($1_$2_LIBEXEC)" "YES"
+INSTALL_LIBEXECS += $1/$2/build/tmp/$$($1_$2_PROG)
+else
+INSTALL_BINS += $1/$2/build/tmp/$$($1_$2_PROG)
+endif
+endif
+
+endif # package-data.mk exists
+
+endef
diff --git a/rules/c-objs.mk b/rules/c-objs.mk
new file mode 100644
index 0000000000..b8514b6d60
--- /dev/null
+++ b/rules/c-objs.mk
@@ -0,0 +1,5 @@
+define c-objs # args: $1 = dir, $2 = distdir
+# C and S files are built only once, not once per way
+$1_$2_C_OBJS = $$(patsubst %.c,$1/$2/build/%.$$(v_osuf),$$($1_$2_C_SRCS))
+$1_$2_S_OBJS = $$(patsubst %.S,$1/$2/build/%.$$(v_osuf),$$($1_$2_S_SRCS))
+endef
diff --git a/rules/c-sources.mk b/rules/c-sources.mk
new file mode 100644
index 0000000000..8e90c702aa
--- /dev/null
+++ b/rules/c-sources.mk
@@ -0,0 +1,4 @@
+define c-sources # args: $1 = dir, $2 = distdir
+$1_$2_C_FILES = $$(patsubst %,$1/%,$$($1_$2_C_SRCS))
+$1_$2_S_FILES = $$(patsubst %,$1/%,$$($1_$2_S_SRCS))
+endef
diff --git a/rules/c-suffix-rules.mk b/rules/c-suffix-rules.mk
new file mode 100644
index 0000000000..6dfed87680
--- /dev/null
+++ b/rules/c-suffix-rules.mk
@@ -0,0 +1,60 @@
+
+define c-suffix-rules
+# $1 = dir
+# $2 = distdir
+# $3 = way
+# $4 = use GHC (YES/NO)
+
+# UseGhcForCc is only relevant when not booting from HC files.
+ifeq "$4" "YES"
+
+$1/$2/build/%.$$($3_osuf) : $1/%.c $$(MKDIRHIER) $$($1_$2_HC_DEP)
+ $$(RM) $$@
+ $$(MKDIRHIER) $$(dir $$@)
+ $$($1_$2_HC) $$($1_$2_$3_GHC_CC_OPTS) -c $$< -o $$@
+
+$1/$2/build/%.$$($3_osuf) : $1/$2/build/%.c $$($1_$2_HC_DEP)
+ $$(RM) $$@
+ $$($1_$2_HC) $$($1_$2_$3_GHC_CC_OPTS) -c $$< -o $$@
+
+$1/$2/build/%.$$($3_osuf) : $1/$2/build/%.$$($3_way_)s $$($1_$2_HC_DEP)
+ $$(RM) $$@
+ $$($1_$2_HC) $$($1_$2_$3_GHC_CC_OPTS) -c $$< -o $$@
+
+$1/$2/build/%.$$($3_osuf) : $1/%.S $$(MKDIRHIER) $$($1_$2_HC_DEP)
+ $$(RM) $$@
+ $$(MKDIRHIER) $$(dir $$@)
+ $$($1_$2_HC) $$($1_$2_$3_GHC_CC_OPTS) -c $$< -o $$@
+
+$1/$2/build/%.$$($3_way_)s : $1/$2/build/%.c $$($1_$2_HC_DEP)
+ $$(RM) $$@
+ $$($1_$2_HC) $$($1_$2_$3_GHC_CC_OPTS) -S $$< -o $$@
+
+else
+
+$1/$2/build/%.$$($3_osuf) : $1/%.c $$(MKDIRHIER)
+ $$(RM) $$@
+ $$(MKDIRHIER) $$(dir $$@)
+ $$(CC) $$($1_$2_$3_ALL_CC_OPTS) -c $$< -o $$@
+
+$1/$2/build/%.$$($3_osuf) : $1/$2/build/%.c
+ $$(RM) $$@
+ $$(CC) $$($1_$2_$3_ALL_CC_OPTS) -c $$< -o $$@
+
+$1/$2/build/%.$$($3_osuf) : $1/$2/build/%.$$($3_way_)s
+ $$(RM) $$@
+ $$(AS) $$($1_$2_$3_ALL_AS_OPTS) -o $$@ $$<
+
+$1/$2/build/%.$$($3_osuf) : $1/%.S $$(MKDIRHIER)
+ $$(RM) $$@
+ $$(MKDIRHIER) $$(dir $$@)
+ $$(CC) $$($1_$2_$3_ALL_CC_OPTS) -c $$< -o $$@
+
+$1/$2/build/%.$$($3_way_)s : $1/$2/build/%.c
+ $$(RM) $$@
+ $$(CC) $$($1_$2_$3_ALL_CC_OPTS) -S $$< -o $$@
+
+endif
+
+endef
+
diff --git a/rules/clean-target.mk b/rules/clean-target.mk
new file mode 100644
index 0000000000..12c7528573
--- /dev/null
+++ b/rules/clean-target.mk
@@ -0,0 +1,9 @@
+
+define clean-target # args: $1 = dir, $2 = key, $3 = files/dirs to clean
+clean : clean_$1
+.PHONY: clean_$1
+clean_$1 : clean_$1_$2
+.PHONY: clean_$1_$2
+clean_$1_$2:
+ $(RM) -rf $3
+endef
diff --git a/rules/distdir-opts.mk b/rules/distdir-opts.mk
new file mode 100644
index 0000000000..5394adfc78
--- /dev/null
+++ b/rules/distdir-opts.mk
@@ -0,0 +1,60 @@
+
+# Set compilation flags that depend on a particular directory/distdir
+
+define distdir-opts # args: $1 = dir, $2 = distdir
+# $3 = GHC stage to use (0 == bootstrapping compiler)
+
+ifeq "$3" "0"
+# This is a bit of a hack.
+# If we are compiling something with the bootstrapping compiler on
+# cygwin, and it uses an include file from the rts (say), then we
+# need to stop mkdependC from generating a dependincy on
+# c:/ghc/rts/include/Rts.h
+# as that confuses make. So we use -isystem instead of -I, which stops
+# these dependencies from being generated. Technically this is wrong if
+# we depend on a library that is built inside the build tree, and we
+# use headers from that library, but currently I don't think that's the
+# case.
+$1_$2_DEP_INCLUDE_DIRS_FLAG = -isystem
+else
+$1_$2_DEP_INCLUDE_DIRS_FLAG = -I
+endif
+
+$1_$2_BUILD_CC_OPTS = \
+ $$(SRC_CC_OPTS) \
+ $$($1_CC_OPTS) \
+ $$(foreach dir,$$($1_$2_INCLUDE_DIRS),-I$1/$$(dir)) \
+ $$($1_$2_CC_OPTS) \
+ $$($1_$2_CPP_OPTS) \
+ $$(foreach dir,$$($1_$2_DEP_INCLUDE_DIRS),$$($1_$2_DEP_INCLUDE_DIRS_FLAG)$$(dir)) \
+ $$($1_$2_DEP_CC_OPTS)
+
+$1_$2_BUILD_LD_OPTS = \
+ $$(SRC_LD_OPTS) \
+ $$($1_LD_OPTS) \
+ $$($1_$2_LD_OPTS) \
+ $$(foreach opt,$$($1_$2_DEP_LIB_DIRS),-L$$(opt)) \
+ $$(foreach opt,$$($1_$2_DEP_EXTRA_LIBS),-l$$(opt)) \
+ $$($1_$2_DEP_LD_OPTS)
+
+# c.f. Cabal's Distribution.Simple.GHC.ghcOptions
+$1_$2_BUILD_HC_OPTS = \
+ $$(SRC_HC_OPTS) \
+ $$($1_HC_OPTS) \
+ $$($1_$2_HC_PKGCONF) \
+ $$(if $$($1_$2_PROG),, \
+ $$(if $$($1_PACKAGE),-package-name $$($1_PACKAGE)-$$($1_$2_VERSION))) \
+ $$(if $$($1_PACKAGE),-hide-all-packages) \
+ -i $$(if $$($1_$2_HS_SRC_DIRS),$$(foreach dir,$$($1_$2_HS_SRC_DIRS),-i$1/$$(dir)),-i$1) \
+ -i$1/$2/build -i$1/$2/build/autogen \
+ -I$1/$2/build -I$1/$2/build/autogen \
+ $$(foreach dir,$$($1_$2_INCLUDE_DIRS),-I$1/$$(dir)) \
+ $$(foreach inc,$$($1_$2_INCLUDE),-\#include "$$(inc)") \
+ $$(foreach opt,$$($1_$2_CPP_OPTS),-optP$$(opt)) \
+ $$(if $$($1_PACKAGE),-optP-include -optP$1/$2/build/autogen/cabal_macros.h) \
+ $$(foreach pkg,$$($1_$2_DEPS),-package $$(pkg)) \
+ $$(if $$(findstring YES,$$($1_$2_SplitObjs)),-split-objs,) \
+ $$($1_$2_HC_OPTS)
+
+endef
+
diff --git a/rules/distdir-way-opts.mk b/rules/distdir-way-opts.mk
new file mode 100644
index 0000000000..2248e2986f
--- /dev/null
+++ b/rules/distdir-way-opts.mk
@@ -0,0 +1,78 @@
+
+# Set compilation flags that additionally depend on a particular way
+
+define distdir-way-opts # args: $1 = dir, $2 = distdir, $3 = way
+
+# Options for a Haskell compilation:
+# - SRC_HC_OPTS source-tree-wide options
+# - WAY_v_HC_OPTS options for this way
+# - libraries/base_BUILD_HC_OPTS options from the build system for this dir
+# - -Idir1 -Idir2 ... include-dirs from this package
+# - -odir/-hidir/-stubdir put the output files under $3/build
+# - -osuf/-hisuf/-hcsuf suffixes for the output files in this way
+# - EXTRA_HC_OPTS options from the command-line
+
+$1_$2_$3_MOST_HC_OPTS = \
+ $$(WAY_$3_HC_OPTS) \
+ $$($1_$2_BUILD_HC_OPTS) \
+ $$($1_$2_$3_HC_OPTS) \
+ $$($$*_HC_OPTS) \
+ $$(EXTRA_HC_OPTS)
+
+# For real Haskell compilations we add -hidir etc.
+$1_$2_$3_ALL_HC_OPTS = \
+ $$($1_$2_$3_MOST_HC_OPTS) \
+ -odir $1/$2/build -hidir $1/$2/build -stubdir $1/$2/build \
+ -hisuf $$($3_hisuf) -osuf $$($3_osuf) -hcsuf $$($3_hcsuf)
+
+# c.f. Cabal's Distribution.Simple.PreProcess.ppHsc2hs
+# We use '' around cflags and lflags to handle paths with backslashes in
+# on Windows
+$1_$2_$3_ALL_HSC2HS_OPTS = \
+ --cc=$$(WhatGccIsCalled) \
+ --ld=$$(WhatGccIsCalled) \
+ $$(SRC_HSC2HS_OPTS) \
+ $$(WAY_$3_HSC2HS_OPTS) \
+ --cflag=-D__GLASGOW_HASKELL__=$$(ProjectVersionInt) \
+ $$(foreach opt,$$($1_$2_BUILD_CC_OPTS),'--cflag=$$(opt)') \
+ $$(foreach opt,$$($1_$2_BUILD_LD_OPTS),'--lflag=$$(opt)') \
+ $$($$*_HSC2HS_OPTS) \
+ $$(EXTRA_HSC2HS_OPTS)
+
+$1_$2_$3_ALL_CC_OPTS = \
+ $$(WAY_$3_CC_OPTS) \
+ $$($1_$2_BUILD_CC_OPTS) \
+ $$($1_$2_$3_CC_OPTS) \
+ $$($$*_CC_OPTS) \
+ $$(EXTRA_CC_OPTS)
+
+$1_$2_$3_GHC_CC_OPTS = \
+ $$(addprefix -optc, $$($1_$2_$3_ALL_CC_OPTS)) \
+ $$($1_$2_$3_MOST_HC_OPTS)
+
+$1_$2_$3_ALL_AS_OPTS = \
+ $$(SRC_AS_OPTS)
+ $$(WAY_$3_AS_OPTS) \
+ $$($1_AS_OPTS) \
+ $$($1_$2_AS_OPTS) \
+ $$($1_$2_$3_AS_OPTS) \
+ $$(EXTRA_AS_OPTS)
+
+$1_$2_$3_ALL_ALEX_OPTS = \
+ $$(SRC_ALEX_OPTS)
+ $$(WAY_$3_ALEX_OPTS) \
+ $$($1_ALEX_OPTS) \
+ $$($1_$2_ALEX_OPTS) \
+ $$($1_$2_$3_ALEX_OPTS) \
+ $$(EXTRA_ALEX_OPTS)
+
+$1_$2_$3_ALL_HAPPY_OPTS = \
+ $$(SRC_HAPPY_OPTS) \
+ $$(WAY_$3_HAPPY_OPTS) \
+ $$($1_HAPPY_OPTS) \
+ $$($1_$2_HAPPY_OPTS) \
+ $$($1_$2_$3_HAPPY_OPTS) \
+ $$(EXTRA_HAPPY_OPTS)
+
+endef
+
diff --git a/rules/docbook.mk b/rules/docbook.mk
new file mode 100644
index 0000000000..2f86363d4c
--- /dev/null
+++ b/rules/docbook.mk
@@ -0,0 +1,24 @@
+
+# Build docbook docs
+
+define docbook
+# $1 = dir
+# $2 = docname
+
+$(call clean-target,$1,docbook,$1/$2)
+
+ifneq "$$(XSLTPROC)" ""
+$(call all-target,$1,$1/$2/index.html)
+
+$1/$2/index.html: $$($1_DOCBOOK_SOURCES)
+ $$(RM) -r $$(dir $$@)
+ $$(XSLTPROC) --stringparam base.dir $$(dir $$@) \
+ --stringparam use.id.as.filename 1 \
+ --stringparam html.stylesheet fptools.css \
+ $$(XSLTPROC_LABEL_OPTS) $$(XSLTPROC_OPTS) \
+ $$(DIR_DOCBOOK_XSL)/html/chunk.xsl $1/$2.xml
+ cp mk/fptools.css $$(dir $$@)
+endif
+
+endef
+
diff --git a/rules/haddock.mk b/rules/haddock.mk
new file mode 100644
index 0000000000..74cb20713f
--- /dev/null
+++ b/rules/haddock.mk
@@ -0,0 +1,27 @@
+
+define haddock # args: $1 = dir, $2 = distdir, $3 = way
+
+ifneq "$$($1_$2_DO_HADDOCK)" "NO"
+
+ifeq "$$($$($1_PACKAGE)_HADDOCK_FILE)" ""
+$$($1_PACKAGE)_HADDOCK_FILE = $1/$2/doc/html/$$($1_PACKAGE)/$$($1_PACKAGE).haddock
+else
+$$(error Already got a haddock file for $$($1_PACKAGE))
+endif
+
+$(call all-target,$1_$2_haddock,$$($$($1_PACKAGE)_HADDOCK_FILE))
+
+$$($1_PACKAGE)_HADDOCK_DEPS = $$(foreach n,$$($1_$2_DEP_NAMES),$$($$n_HADDOCK_FILE))
+
+ifeq "$$(HSCOLOUR_SRCS)" "YES"
+$1_$2_HADDOCK_FLAGS += --hyperlink-source
+endif
+
+$$($$($1_PACKAGE)_HADDOCK_FILE) : $$(MKDIRHIER) $(INPLACE_BIN)/haddock$(exeext) $$(GHC_CABAL_INPLACE) $$($1_$2_HS_SRCS) $$($$($1_PACKAGE)_HADDOCK_DEPS)
+ $$(MKDIRHIER) $$(dir $$@)
+ $$(GHC_CABAL_INPLACE) haddock $2 $1 --with-haddock=$$(TOP)/$(INPLACE_BIN)/haddock --with-ghc=$$(TOP)/$(INPLACE_BIN)/ghc-stage2 $$($1_$2_HADDOCK_FLAGS) $$($1_$2_HADDOCK_OPTS)
+
+endif
+
+endef
+
diff --git a/rules/hi-rule.mk b/rules/hi-rule.mk
new file mode 100644
index 0000000000..07b65ed8e1
--- /dev/null
+++ b/rules/hi-rule.mk
@@ -0,0 +1,25 @@
+
+# Here's an interesting rule!
+# The .hi file depends on the .o file,
+# so if the .hi file is dated earlier than the .o file (commonly the case,
+# when interfaces are stable) this rule just makes sure that the .o file,
+# is up to date. Then it does nothing to generate the .hi file from the
+# .o file, because the act of making sure the .o file is up to date also
+# updates the .hi file (if necessary).
+
+define hi-rule # $1 = way
+%.$$($1_hisuf) : %.$$($1_osuf)
+ @if [ ! -f $$@ ] ; then \
+ echo Panic! $$< exists, but $$@ does not.; \
+ exit 1; \
+ else exit 0 ; \
+ fi
+
+%.$$($1_way_)hi-boot : %.$$($1_way_)o-boot
+ @if [ ! -f $$@ ] ; then \
+ echo Panic! $$< exists, but $$@ does not.; \
+ exit 1; \
+ else exit 0 ; \
+ fi
+endef
+
diff --git a/rules/hs-objs.mk b/rules/hs-objs.mk
new file mode 100644
index 0000000000..dac0bc540c
--- /dev/null
+++ b/rules/hs-objs.mk
@@ -0,0 +1,5 @@
+
+define hs-objs # args: $1 = dir, $2 = distdir, $3 = way
+$1_$2_$3_HS_OBJS = $$(patsubst %,$1/$2/build/%.$$($3_osuf),$$($1_$2_SLASH_MODS))
+$1_$2_$3_HI = $$(patsubst %,$1/$2/build/%.$$($3_hisuf),$$($1_$2_SLASH_MODS))
+endef
diff --git a/rules/hs-sources.mk b/rules/hs-sources.mk
new file mode 100644
index 0000000000..d8e6b4224a
--- /dev/null
+++ b/rules/hs-sources.mk
@@ -0,0 +1,46 @@
+
+define hs-sources # args: $1 = dir, $2 = distdir
+
+ifeq "$$($1_$2_HS_SRC_DIRS)" ""
+$1_$2_HS_SRC_DIRS = .
+endif
+
+# Here we collect all the .hs/.lhs source files that we can find. If
+# we can't find a Haskell source file for a given module, then presumably
+# it can be generated by preprocessing something (.hsc, .y, .x etc.), so
+# we depend on dist/build/Foo.hs in anticipation that the implicit rules
+# will put the preprocessed source file there.
+#
+# NB. use :=, we only want this thing evaluated once.
+#
+$1_$2_HS_SRCS := $$(foreach file,$$($1_$2_SLASH_MODS),\
+ $$(firstword \
+ $$(wildcard \
+ $$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
+ $1/$$(dir)/$$(file).hs $1/$$(dir)/$$(file).lhs)) \
+ $1/$2/build/$$(file).hs))
+
+# .hs-boot files must be in the same place as the .hs file they go
+# with (GHC assumes this). When we preprocess a source file, and
+# that module has a .hs-boot or .lhs-boot file, we must arrange to
+# copy the file into the distdir so that it ends up alongside the
+# preprocessed .hs file. This complicated macro figures out for which
+# files we need to do this, so we can add them as dependencies of the
+# .depend file rule.
+#
+# for each .hs file in the build dir,
+# if there is a .hs-boot or .lhs-boot file for it in a source dir,
+# we want that file in the build dir.
+#
+# NB. use :=, we only want this thing evaluated once.
+#
+$1_$2_HS_BOOT_SRCS := $$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
+ $$(subst $1/$$(dir),$1/$2/build,\
+ $$(wildcard \
+ $$(subst $1/$2/build,$1/$$(dir),\
+ $$(foreach file,\
+ $$(filter $1/$2/build%,$$($1_$2_HS_SRCS)),\
+ $$(patsubst %.hs,%.hs-boot,$$(file)) \
+ $$(patsubst %.hs,%.lhs-boot,$$(file)))))))
+
+endef
diff --git a/rules/hs-suffix-rules-srcdir.mk b/rules/hs-suffix-rules-srcdir.mk
new file mode 100644
index 0000000000..276d28b264
--- /dev/null
+++ b/rules/hs-suffix-rules-srcdir.mk
@@ -0,0 +1,70 @@
+
+define hs-suffix-rules-srcdir
+# args: $1 = dir, $2 = distdir, $3 = way, $4 = srcdir
+
+# Preprocessing Haskell source
+
+$1/$2/build/%.hs : $1/$4/%.ly $$(MKDIRHIER)
+ $$(MKDIRHIER) $$(dir $$@)
+ $$(HAPPY) $$($1_$2_$3_ALL_HAPPY_OPTS) $$< -o $$@
+
+$1/$2/build/%.hs : $1/$4/%.y $$(MKDIRHIER)
+ $$(MKDIRHIER) $$(dir $$@)
+ $$(HAPPY) $$($1_$2_$3_ALL_HAPPY_OPTS) $$< -o $$@
+
+$1/$2/build/%.hs : $1/$4/%.x $$(MKDIRHIER)
+ $$(MKDIRHIER) $$(dir $$@)
+ $$(ALEX) $$($1_$2_$3_ALL_ALEX_OPTS) $$< -o $$@
+
+$1/$2/build/%_hsc.c $1/$2/build/%_hsc.h $1/$2/build/%.hs : $1/$4/%.hsc $$(HSC2HS_INPLACE)
+ $$(MKDIRHIER) $$(dir $$@)
+ $$(HSC2HS_INPLACE) $$($1_$2_$3_ALL_HSC2HS_OPTS) $$< -o $$@
+ touch $$(patsubst %.hsc,%_hsc.c,$$<)
+
+# Compiling Haskell source
+
+$1/$2/build/%.$$($3_osuf) : $1/$4/%.hs $$($1_$2_HC_DEP)
+ $$($1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -c $$< -o $$@
+
+$1/$2/build/%.$$($3_osuf) : $1/$4/%.lhs $$($1_$2_HC_DEP)
+ $$($1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -c $$< -o $$@
+
+$1/$2/build/%.$$($3_hcsuf) : $1/$4/%.hs $$($1_$2_HC_DEP)
+ $$($1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -C $$< -o $$@
+
+$1/$2/build/%.$$($3_hcsuf) : $1/$4/%.lhs $$($1_$2_HC_DEP)
+ $$($1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -C $$< -o $$@
+
+# XXX: for some reason these get used in preference to the direct
+# .hs->.o rule, I don't know why --SDM
+
+# $1/$2/build/%.$$($3_osuf) : $1/$2/build/%.$$($3_way_)hc
+# $$($1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -c $$< -o $$@
+#
+# $1/$2/build/%.$$($3_osuf) : $1/$2/build/%.hc
+# $$($1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -c $$< -o $$@
+#
+# $1/$2/build/%.$$($3_way_)s : $1/$2/build/%.$$($3_way_)hc
+# $$($1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -S $$< -o $$@
+
+# Now the rules for hs-boot files.
+
+$1/$2/build/%.hs-boot : $1/$4/%.hs-boot
+ $$(CP) $$< $$@
+
+$1/$2/build/%.lhs-boot : $1/$4/%.lhs-boot
+ $$(CP) $$< $$@
+
+$1/$2/build/%.$$($3_way_)o-boot : $1/$4/%.hs-boot $$($1_$2_HC_DEP)
+ $$($1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -c $$< -o $$@
+
+$1/$2/build/%.$$($3_way_)o-boot : $1/$4/%.lhs-boot $$($1_$2_HC_DEP)
+ $$($1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -c $$< -o $$@
+
+# stubs are automatically generated and compiled by GHC
+
+$1/$2/build/%_stub.$$($3_osuf): $1/$2/build/%.$$($3_osuf)
+ @:
+
+endef
+
diff --git a/rules/hs-suffix-rules.mk b/rules/hs-suffix-rules.mk
new file mode 100644
index 0000000000..62022bcec4
--- /dev/null
+++ b/rules/hs-suffix-rules.mk
@@ -0,0 +1,17 @@
+
+define hs-suffix-rules # args: $1 = dir, $2 = distdir, $3 = way
+
+$1/$2/build/%.$$($3_hcsuf) : $1/$2/build/%.hs $$($1_$2_HC_DEP)
+ $$($1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -C $$< -o $$@
+
+$1/$2/build/%.$$($3_osuf) : $1/$2/build/%.hs $$($1_$2_HC_DEP)
+ $$($1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -c $$< -o $$@
+
+$1/$2/build/%.$$($3_hcsuf) : $1/$2/build/autogen/%.hs $$($1_$2_HC_DEP)
+ $$($1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -C $$< -o $$@
+
+$1/$2/build/%.$$($3_osuf) : $1/$2/build/autogen/%.hs $$($1_$2_HC_DEP)
+ $$($1_$2_HC) $$($1_$2_$3_ALL_HC_OPTS) -c $$< -o $$@
+
+endef # hs-suffix-rules
+
diff --git a/rules/includes-sources.mk b/rules/includes-sources.mk
new file mode 100644
index 0000000000..de66b39305
--- /dev/null
+++ b/rules/includes-sources.mk
@@ -0,0 +1,14 @@
+
+define includes-sources # args: $1 = dir, $2 = distdir
+
+ifeq "$$($1_$2_INCLUDE_DIRS)" ""
+$1_$2_INCLUDE_DIRS = .
+endif
+
+$1_$2_INSTALL_INCLUDES_SRCS :=\
+ $$(foreach file,$$($1_$2_INSTALL_INCLUDES),\
+ $$(firstword \
+ $$(wildcard \
+ $$(foreach dir,$$($1_$2_INCLUDE_DIRS),\
+ $1/$$(dir)/$$(file)))))
+endef
diff --git a/rules/manual-package-config.mk b/rules/manual-package-config.mk
new file mode 100644
index 0000000000..2eb33b787a
--- /dev/null
+++ b/rules/manual-package-config.mk
@@ -0,0 +1,33 @@
+
+define manual-package-config # args: $1 = dir
+
+$1/package.conf.inplace : $1/package.conf.in $(GHC_PKG_INPLACE)
+ $(CPP) $(RAWCPP_FLAGS) -P \
+ -DTOP='"$$(TOP)"' \
+ $$($1_PACKAGE_CPP_OPTS) \
+ -x c -I$$(GHC_INCLUDE_DIR) $$< | \
+ grep -v '^#pragma GCC' | \
+ sed -e 's/""//g' -e 's/:[ ]*,/: /g' >$$@
+
+ $(GHC_PKG_INPLACE) update --force $$@
+
+# This is actually a real file, but we need to recreate it on every
+# "make install", so we declare it as phony
+.PHONY: $1/package.conf.install
+$1/package.conf.install:
+ $(CPP) $(RAWCPP_FLAGS) -P \
+ -DINSTALLING \
+ -DLIB_DIR='"$$(libdir)"' \
+ -DINCLUDE_DIR='"$$(libdir)/include"' \
+ $$($1_PACKAGE_CPP_OPTS) \
+ -x c -I$$(GHC_INCLUDE_DIR) $1/package.conf.in | \
+ grep -v '^#pragma GCC' | \
+ sed -e 's/""//g' -e 's/:[ ]*,/: /g' >$$@
+
+clean : clean_$1
+.PHONY: clean_$1
+clean_$1 : clean_$1_package.conf
+.PHONY: clean_$1_package.conf
+clean_$1_package.conf :
+ $(RM) $1/package.conf.install $1/package.conf.inplace
+endef
diff --git a/rules/package-config.mk b/rules/package-config.mk
new file mode 100644
index 0000000000..111386e115
--- /dev/null
+++ b/rules/package-config.mk
@@ -0,0 +1,41 @@
+
+define package-config # args: $1 = dir, $2 = distdir, $3 = GHC stage
+
+$1_$2_HC = $$(GHC_STAGE$3)
+
+# configuration stuff that depends on which GHC we're building with
+ifeq "$3" "0"
+$1_$2_ghc_ge_609 = $(ghc_ge_609)
+$1_$2_HC_CONFIG = $$(GHC_STAGE0)
+$1_$2_HC_CONFIG_DEP =
+$1_$2_GHC_PKG = $$(GHC_PKG)
+$1_$2_GHC_PKG_DEP =
+$1_$2_HC_MK_DEPEND = $$($1_$2_HC)
+# We can't make rules depend on the bootstrapping compiler, as then
+# on cygwin we get a dep on c:/ghc/..., and make gets confused by the :
+$1_$2_HC_MK_DEPEND_DEP =
+$1_$2_HC_DEP =
+ifeq "$$($1_$2_USE_BOOT_LIBS)" "YES"
+$1_$2_HC_PKGCONF = -package-conf $(BOOTSTRAPPING_CONF)
+$1_$2_GHC_PKG_OPTS = --package-conf=$$(BOOTSTRAPPING_CONF)
+$1_$2_CONFIGURE_OPTS += --package-db=$$(TOP)/$$(BOOTSTRAPPING_CONF)
+endif
+else
+$1_$2_ghc_ge_609 = YES
+$1_$2_HC_PKGCONF =
+$1_$2_HC_CONFIG = $$(TOP)/$$(DUMMY_GHC_INPLACE)
+$1_$2_HC_CONFIG_DEP = $$(DUMMY_GHC_INPLACE)
+$1_$2_GHC_PKG = $$(TOP)/$$(GHC_PKG_INPLACE)
+$1_$2_GHC_PKG_DEP = $$(GHC_PKG_INPLACE)
+$1_$2_GHC_PKG_OPTS =
+# If stage is not 0 then we always use stage1 for making .depend, as later
+# stages aren't available early enough
+$1_$2_HC_MK_DEPEND = $$(GHC_STAGE1)
+$1_$2_HC_MK_DEPEND_DEP = $$($1_$2_HC_MK_DEPEND)
+$1_$2_HC_DEP = $$($1_$2_HC)
+$1_$2_HC_OPTS += -no-user-package-conf
+endif
+
+# Useful later
+$1_$2_SLASH_MODS = $$(subst .,/,$$($1_$2_MODULES))
+endef
diff --git a/rules/shell-wrapper.mk b/rules/shell-wrapper.mk
new file mode 100644
index 0000000000..a2aca45e36
--- /dev/null
+++ b/rules/shell-wrapper.mk
@@ -0,0 +1,63 @@
+define shell-wrapper
+# $1 = dir
+# $2 = distdir
+
+ifeq "$$($1_$2_SHELL_WRAPPER)" "YES"
+
+ifeq "$(Windows)" "YES"
+
+ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER)" "YES"
+# Just install the binary on Windows
+$1_$2_INSTALL = YES
+endif
+
+else
+
+ifeq "$$($1_$2_SHELL_WRAPPER_NAME)" ""
+$1_$2_SHELL_WRAPPER_NAME = $1/$$($1_$2_PROG).wrapper
+endif
+
+ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
+all_$1_$2 : $$(INPLACE_BIN)/$$($1_$2_PROG)
+
+$$(INPLACE_BIN)/$$($1_$2_PROG): $$($1_$2_INPLACE)
+ $$(RM) -f $$@
+ echo '#!$$(SHELL)' >> $$@
+ echo 'executablename=$$(TOP)/$$<' >> $$@
+ echo 'datadir=$$(TOP)/$$(INPLACE_LIB)' >> $$@
+ echo 'bindir=$$(TOP)/$$(INPLACE_BIN)' >> $$@
+ cat $$($1_$2_SHELL_WRAPPER_NAME) >> $$@
+ $$(EXECUTABLE_FILE) $$@
+endif
+
+ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER)" "YES"
+
+ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)" ""
+$1_$2_INSTALL_SHELL_WRAPPER_NAME = $$($1_$2_PROG)
+endif
+
+# Install the binary in $(libexecdir), and install a shell wrapper in $(bindir)
+INSTALL_LIBEXECS += $1/$2/build/tmp/$$($1_$2_PROG)
+BINDIST_WRAPPERS += $$($1_$2_SHELL_WRAPPER_NAME)
+
+install: install_$1_$2_wrapper
+
+.PHONY: install_$1_$2_wrapper
+install_$1_$2_wrapper: WRAPPER=$$(DESTDIR)$$(bindir)/$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)
+install_$1_$2_wrapper:
+ $$(MKDIRHIER) $$(DESTDIR)$$(bindir)
+ $$(RM) -f $$(WRAPPER)
+ echo '#!$$(SHELL)' >> $$(WRAPPER)
+ echo 'executablename=$$(libexecdir)/$$($1_$2_PROG)' >> $$(WRAPPER)
+ echo 'datadir=$$(datadir)' >> $$(WRAPPER)
+ echo 'bindir=$$(bindir)' >> $$(WRAPPER)
+ cat $$($1_$2_SHELL_WRAPPER_NAME) >> $$(WRAPPER)
+ $$(EXECUTABLE_FILE) $$(WRAPPER)
+
+endif # $1_$2_INSTALL_SHELL_WRAPPER
+
+endif
+
+endif # $1_$2_SHELL_WRAPPER
+
+endef
diff --git a/rules/way-prelims.mk b/rules/way-prelims.mk
new file mode 100644
index 0000000000..9df9a5bc69
--- /dev/null
+++ b/rules/way-prelims.mk
@@ -0,0 +1,13 @@
+
+define way-prelims # $1 = way
+ifeq "$1" "v"
+$1__way =
+$1_way_ =
+else
+$1__way = _$1
+$1_way_ = $1_
+endif
+$1_osuf = $$($1_way_)o
+$1_hisuf = $$($1_way_)hi
+$1_hcsuf = $$($1_way_)hc
+endef
diff --git a/utils/genapply/Makefile b/utils/genapply/Makefile
index 186eb0e034..06c44cf2a8 100644
--- a/utils/genapply/Makefile
+++ b/utils/genapply/Makefile
@@ -1,29 +1,3 @@
-TOP=../..
-include $(TOP)/mk/boilerplate.mk
-
-HS_PROG = $(GHC_GENAPPLY_PGM)
-
-# genapply is needed to boot in rts/...
-ifneq "$(BootingFromHc)" "YES"
-boot :: all
-endif
-
-ifeq "$(GhcUnregisterised)" "YES"
-SRC_HC_OPTS += -DNO_REGS
-endif
-
-ifeq "$(ghc_ge_607)" "YES"
-SRC_HC_OPTS += -package pretty
-endif
-
-# Try to get dependencies right...
-SRC_HC_OPTS += -fforce-recomp
-
-GenApply.o : $(GHC_INCLUDE_DIR)/ghcconfig.h
-GenApply.o : $(GHC_INCLUDE_DIR)/MachRegs.h
-GenApply.o : $(GHC_INCLUDE_DIR)/Constants.h
-
-binary-dist:
- @:
-
-include $(TOP)/mk/target.mk
+dir = utils/genapply
+TOP = ../..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/utils/genapply/ghc.mk b/utils/genapply/ghc.mk
new file mode 100644
index 0000000000..94fb45639c
--- /dev/null
+++ b/utils/genapply/ghc.mk
@@ -0,0 +1,16 @@
+utils/genapply_dist_MODULES = GenApply
+utils/genapply_dist_PROG = $(GHC_GENAPPLY_PGM)
+
+ifeq "$(ghc_ge_607)" "YES"
+utils/genapply_HC_OPTS += -package pretty
+endif
+
+ifeq "$(GhcUnregisterised)" "YES"
+utils/genapply_HC_OPTS += -DNO_REGS
+endif
+
+utils/genapply/GenApply.hs : $(GHC_INCLUDE_DIR)/ghcconfig.h
+utils/genapply/GenApply.hs : $(GHC_INCLUDE_DIR)/MachRegs.h
+utils/genapply/GenApply.hs : $(GHC_INCLUDE_DIR)/Constants.h
+
+$(eval $(call build-prog,utils/genapply,dist,0))
diff --git a/utils/genprimopcode/Makefile b/utils/genprimopcode/Makefile
index ed011eb0c2..8849708790 100644
--- a/utils/genprimopcode/Makefile
+++ b/utils/genprimopcode/Makefile
@@ -1,10 +1,3 @@
-TOP=../..
-include $(TOP)/mk/boilerplate.mk
-
-HS_PROG = genprimopcode
-
-binary-dist:
- @:
-
-include $(TOP)/mk/target.mk
-
+dir = utils/genprimopcode
+TOP = ../..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/utils/genprimopcode/ghc.mk b/utils/genprimopcode/ghc.mk
new file mode 100644
index 0000000000..74ac4232e6
--- /dev/null
+++ b/utils/genprimopcode/ghc.mk
@@ -0,0 +1,4 @@
+utils/genprimopcode_dist_MODULES = Lexer Main ParserM Parser Syntax
+utils/genprimopcode_dist_PROG = $(GHC_GENPRIMOP_PGM)
+
+$(eval $(call build-prog,utils/genprimopcode,dist,0))
diff --git a/utils/ghc-cabal/ghc-cabal.hs b/utils/ghc-cabal/ghc-cabal.hs
new file mode 100644
index 0000000000..c806d3cf16
--- /dev/null
+++ b/utils/ghc-cabal/ghc-cabal.hs
@@ -0,0 +1,246 @@
+
+module Main (main) where
+
+import qualified Distribution.ModuleName as ModuleName
+import Distribution.PackageDescription
+import Distribution.PackageDescription.Configuration
+import Distribution.PackageDescription.Parse
+import Distribution.Simple
+import Distribution.Simple.Configure
+import Distribution.Simple.LocalBuildInfo
+import Distribution.Simple.Program
+import Distribution.Simple.Utils (defaultPackageDesc)
+import Distribution.Simple.Build (writeAutogenFiles)
+import Distribution.Simple.Register (writeInstalledConfig)
+import Distribution.Text
+import Distribution.Verbosity
+import qualified Distribution.InstalledPackageInfo as Installed
+ ( InstalledPackageInfo_(..) )
+import qualified Distribution.Simple.PackageIndex as PackageIndex
+ ( topologicalOrder, lookupPackageName, insert )
+
+import Control.Monad
+import Data.Maybe
+import System.IO
+import System.Directory
+import System.Environment
+import System.Exit
+import System.FilePath
+
+main :: IO ()
+main = do args <- getArgs
+ case args of
+ "haddock" : distDir : dir : args' ->
+ runHaddock distDir dir args'
+ "install" : ghcpkg : ghcpkgconfig : directory : distDir
+ : myDestDir : myPrefix : myLibdir : myDocdir : args' ->
+ doInstall ghcpkg ghcpkgconfig directory distDir
+ myDestDir myPrefix myLibdir myDocdir args'
+ "configure" : args' -> case break (== "--") args' of
+ (config_args, "--" : distdir : directories) ->
+ mapM_ (generate config_args distdir) directories
+ _ -> die syntax_error
+ _ -> die syntax_error
+
+syntax_error :: [String]
+syntax_error =
+ ["syntax: ghc-cabal configure <configure-args> -- <distdir> <directory>...",
+ " ghc-cabal install <ghc-pkg> <directory> <distdir> <destdir> <prefix> <args>...",
+ " ghc-cabal haddock <distdir> <directory> <args>..."]
+
+die :: [String] -> IO ()
+die errs = do mapM_ (hPutStrLn stderr) errs
+ exitWith (ExitFailure 1)
+
+-- XXX Should use bracket
+withCurrentDirectory :: FilePath -> IO a -> IO a
+withCurrentDirectory directory io
+ = do curDirectory <- getCurrentDirectory
+ setCurrentDirectory directory
+ r <- io
+ setCurrentDirectory curDirectory
+ return r
+
+-- We need to use the autoconfUserHooks, as the packages that use
+-- configure can create a .buildinfo file, and we need any info that
+-- ends up in it.
+userHooks :: UserHooks
+userHooks = autoconfUserHooks
+
+runHaddock :: FilePath -> FilePath -> [String] -> IO ()
+runHaddock distdir directory args
+ = withCurrentDirectory directory
+ $ defaultMainWithHooksArgs hooks ("haddock" : "--builddir" : distdir : args)
+ where
+ hooks = userHooks {
+ haddockHook = modHook (haddockHook userHooks)
+ }
+ modHook f pd lbi us flags
+ | packageName pd == PackageName "ghc-prim"
+ = let pd' = case library pd of
+ Just lib ->
+ let ghcPrim = fromJust (simpleParse "GHC.Prim")
+ ems = filter (ghcPrim /=)
+ (exposedModules lib)
+ lib' = lib { exposedModules = ems }
+ in pd { library = Just lib' }
+ Nothing ->
+ error "Expected a library, but none found"
+ pc = withPrograms lbi
+ pc' = userSpecifyArgs "haddock"
+ ["dist-install/build/autogen/GHC/Prim.hs"] pc
+ lbi' = lbi { withPrograms = pc' }
+ in f pd' lbi' us flags
+ | otherwise
+ = f pd lbi us flags
+
+doInstall :: FilePath -> FilePath -> FilePath -> FilePath -> FilePath
+ -> FilePath -> FilePath -> FilePath -> [String] -> IO ()
+doInstall ghcpkg ghcpkgconf directory distDir myDestDir myPrefix myLibdir myDocdir args
+ = withCurrentDirectory directory $ do
+ defaultMainWithHooksArgs hooks (["copy", "--builddir", distDir]
+ ++ (if null myDestDir then []
+ else ["--destdir", myDestDir])
+ ++ args)
+ defaultMainWithHooksArgs hooks ("register" : "--builddir" : distDir : args)
+ where
+ hooks = userHooks {
+ copyHook = modHook (copyHook userHooks),
+ regHook = modHook (regHook userHooks)
+ }
+
+ modHook f pd lbi us flags
+ = let
+ pd'
+ | packageName pd == PackageName "ghc-prim" =
+ case library pd of
+ Just lib ->
+ let ghcPrim = fromJust (simpleParse "GHC.Prim")
+ ems = filter (ghcPrim /=) (exposedModules lib)
+ lib' = lib { exposedModules = ems }
+ in pd { library = Just lib' }
+ Nothing ->
+ error "Expected a library, but none found"
+ | otherwise = pd
+ idts = installDirTemplates lbi
+ idts' = idts { prefix = toPathTemplate myPrefix,
+ libdir = toPathTemplate myLibdir,
+ libsubdir = toPathTemplate "$pkgid",
+ docdir = toPathTemplate (myDocdir </> "$pkgid"),
+ htmldir = toPathTemplate "$docdir" }
+ progs = withPrograms lbi
+ prog = ConfiguredProgram {
+ programId = programName ghcPkgProgram,
+ programVersion = Nothing,
+ programArgs = ["--global-conf", ghcpkgconf]
+ ++ if not (null myDestDir)
+ then ["--force"]
+ else [],
+ programLocation = UserSpecified ghcpkg
+ }
+ progs' = updateProgram prog progs
+ lbi' = lbi {
+ installDirTemplates = idts',
+ withPrograms = progs'
+ }
+ in f pd' lbi' us flags
+
+generate :: [String] -> FilePath -> FilePath -> IO ()
+generate config_args distdir directory
+ = withCurrentDirectory directory
+ $ do let verbosity = verbose
+ gpdFile <- defaultPackageDesc verbosity
+ gpd <- readPackageDescription verbosity gpdFile
+
+ -- XXX We shouldn't just configure with the default flags
+ -- XXX And this, and thus the "getPersistBuildConfig distdir" below,
+ -- aren't going to work when the deps aren't built yet
+ withArgs (["configure", "--distdir", distdir] ++ config_args)
+ (case buildType (flattenPackageDescription gpd) of
+ Just Configure -> defaultMainWithHooks autoconfUserHooks
+ _other -> defaultMain)
+ -- not quite right, but good enough for us
+
+ lbi <- getPersistBuildConfig distdir
+ let pd0 = localPkgDescr lbi
+
+ hooked_bi <-
+ if (buildType pd0 == Just Configure)
+ then do
+ maybe_infoFile <- defaultHookedPackageDesc
+ case maybe_infoFile of
+ Nothing -> return emptyHookedBuildInfo
+ Just infoFile -> readHookedBuildInfo verbosity infoFile
+ else
+ return emptyHookedBuildInfo
+
+ let pd = updatePackageDescription hooked_bi pd0
+
+ -- generate Paths_<pkg>.hs and cabal-macros.h
+ writeAutogenFiles verbosity pd lbi
+
+ -- generate inplace-pkg-config
+ when (isJust $ library pd) $
+ writeInstalledConfig distdir pd lbi True Nothing
+
+ let
+ libBiModules lib = (libBuildInfo lib, libModules pd)
+ exeBiModules exe = (buildInfo exe, ModuleName.main : exeModules pd)
+ biModuless = (maybeToList $ fmap libBiModules $ library pd)
+ ++ (map exeBiModules $ executables pd)
+ buildableBiModuless = filter isBuildable biModuless
+ where isBuildable (bi', _) = buildable bi'
+ (bi, modules) = case buildableBiModuless of
+ [] -> error "No buildable component found"
+ [biModules] -> biModules
+ _ -> error ("XXX ghc-cabal can't handle " ++
+ "more than one buildinfo yet")
+ -- XXX Another Just...
+ Just ghcProg = lookupProgram ghcProgram (withPrograms lbi)
+
+ dep_pkgs = PackageIndex.topologicalOrder (packageHacks (installedPkgs lbi))
+ forDeps f = concatMap f dep_pkgs
+
+ -- copied from Distribution.Simple.PreProcess.ppHsc2Hs
+ packageHacks = case compilerFlavor (compiler lbi) of
+ GHC -> hackRtsPackage
+ _ -> id
+ -- We don't link in the actual Haskell libraries of our
+ -- dependencies, so the -u flags in the ldOptions of the rts
+ -- package mean linking fails on OS X (it's ld is a tad
+ -- stricter than gnu ld). Thus we remove the ldOptions for
+ -- GHC's rts package:
+ hackRtsPackage index =
+ case PackageIndex.lookupPackageName index (PackageName "rts") of
+ [rts] -> PackageIndex.insert rts { Installed.ldOptions = [] } index
+ _ -> error "No (or multiple) ghc rts package is registered!!"
+
+ let variablePrefix = directory ++ '_':distdir
+ let xs = [variablePrefix ++ "_VERSION = " ++ display (pkgVersion (package pd)),
+ variablePrefix ++ "_MODULES = " ++ unwords (map display modules),
+ variablePrefix ++ "_HS_SRC_DIRS = " ++ unwords (hsSourceDirs bi),
+ variablePrefix ++ "_DEPS = " ++ unwords (map display (packageDeps lbi)),
+ variablePrefix ++ "_DEP_NAMES = " ++ unwords (map (display . packageName) (packageDeps lbi)),
+ variablePrefix ++ "_INCLUDE_DIRS = " ++ unwords (includeDirs bi),
+ variablePrefix ++ "_INCLUDES = " ++ unwords (includes bi),
+ variablePrefix ++ "_INSTALL_INCLUDES = " ++ unwords (installIncludes bi),
+ variablePrefix ++ "_EXTRA_LIBRARIES = " ++ unwords (extraLibs bi),
+ variablePrefix ++ "_EXTRA_LIBDIRS = " ++ unwords (extraLibDirs bi),
+ variablePrefix ++ "_C_SRCS = " ++ unwords (cSources bi),
+ -- XXX This includes things it shouldn't, like:
+ -- -odir dist-bootstrapping/build
+ variablePrefix ++ "_HC_OPTS = " ++ escape (unwords
+ (programArgs ghcProg
+ ++ hcOptions GHC bi
+ ++ extensionsToFlags (compiler lbi) (extensions bi))),
+ variablePrefix ++ "_CC_OPTS = " ++ unwords (ccOptions bi),
+ variablePrefix ++ "_CPP_OPTS = " ++ unwords (cppOptions bi),
+ variablePrefix ++ "_LD_OPTS = " ++ unwords (ldOptions bi),
+ variablePrefix ++ "_DEP_INCLUDE_DIRS = " ++ unwords (forDeps Installed.includeDirs),
+ variablePrefix ++ "_DEP_CC_OPTS = " ++ unwords (forDeps Installed.ccOptions),
+ variablePrefix ++ "_DEP_LIB_DIRS = " ++ unwords (forDeps Installed.libraryDirs),
+ variablePrefix ++ "_DEP_EXTRA_LIBS = " ++ unwords (forDeps Installed.extraLibraries),
+ variablePrefix ++ "_DEP_LD_OPTS = " ++ unwords (forDeps Installed.ldOptions)]
+ writeFile (distdir ++ "/package-data.mk") $ unlines xs
+ where
+ escape = foldr (\c xs -> if c == '#' then '\\':'#':xs else c:xs) []
diff --git a/utils/ghc-cabal/ghc.mk b/utils/ghc-cabal/ghc.mk
new file mode 100644
index 0000000000..c0fd0f336d
--- /dev/null
+++ b/utils/ghc-cabal/ghc.mk
@@ -0,0 +1,54 @@
+# -----------------------------------------------------------------------------
+# Bootstrapping ghc-cabal
+
+# Euch, hideous hack:
+# XXX This should be in a different Makefile
+CABAL_DOTTED_VERSION := $(shell grep "^Version:" libraries/Cabal/Cabal.cabal | sed "s/^Version: //")
+CABAL_VERSION := $(subst .,$(comma),$(CABAL_DOTTED_VERSION))
+CABAL_CONSTRAINT := --constraint="Cabal == $(CABAL_DOTTED_VERSION)"
+
+$(GHC_CABAL_INPLACE) : $(GHC_CABAL_DIR)/dist/build/tmp/ghc-cabal$(exeext)
+ $(MKDIRHIER) $(dir $@)
+ $(CP) $< $@
+
+$(GHC_CABAL_DIR)/dist/build/tmp/ghc-cabal$(exeext): $(GHC_CABAL_DIR)/ghc-cabal.hs $(MKDIRHIER)
+ $(MKDIRHIER) bootstrapping
+ $(MKDIRHIER) $(dir $@)
+ $(GHC) --make $(GHC_CABAL_DIR)/ghc-cabal.hs -o $@ \
+ -Wall $(WERROR) \
+ -DCABAL_VERSION=$(CABAL_VERSION) \
+ -odir bootstrapping \
+ -hidir bootstrapping \
+ -ilibraries/Cabal \
+ -ilibraries/filepath \
+ -ilibraries/hpc
+ touch $@
+
+# touch is required, because otherwise if mkdirhier is newer, we
+# repeatedly rebuild ghc-cabal.
+
+$(eval $(call clean-target,$(GHC_CABAL_DIR),dist,\
+ $(GHC_CABAL_DIR)/dist bootstrapping))
+
+$(eval $(call all-target,$(GHC_CABAL_DIR),$(GHC_CABAL_INPLACE)))
+
+# -----------------------------------------------------------------------------
+# dummy-ghc
+
+# This is a tiny program to fool Cabal's configure that we have a
+# stage1 GHC, which lets us configure all the packages before we've
+# build stage1.
+
+$(GHC_CABAL_DIR)_dist-dummy-ghc_MODULES = dummy-ghc
+$(GHC_CABAL_DIR)_dist-dummy-ghc_PROG = dummy-ghc$(exeext)
+
+$(GHC_CABAL_DIR)/dist-dummy-ghc/build/dummy-ghc.hs : $(GHC_CABAL_DIR)/ghc.mk $(MKDIRHIER)
+ $(MKDIRHIER) $(dir $@)
+ echo "import System.Environment; import System.Cmd; import System.Exit" >$@
+ echo "main = do args <- getArgs; if args == [\"--numeric-version\"] then putStrLn \"$(ProjectVersion)\" else do e <- rawSystem \"$(GHC_STAGE0)\" args; exitWith e" >>$@
+
+# We don't build dummy-ghc with Cabal, so we need to pass -package
+# flags manually
+utils/ghc-cabal_dist-dummy-ghc_HC_OPTS = -package process
+$(eval $(call build-prog,utils/ghc-cabal,dist-dummy-ghc,0))
+
diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs
index 3d1c8059c7..b1aaaba7b0 100644
--- a/utils/ghc-pkg/Main.hs
+++ b/utils/ghc-pkg/Main.hs
@@ -378,19 +378,14 @@ getPkgDatabases modify my_flags = do
let err_msg = "missing --global-conf option, location of global package.conf unknown\n"
global_conf <-
case [ f | FlagGlobalConfig f <- my_flags ] of
- [] -> do mb_dir <- getExecDir "/bin/ghc-pkg.exe"
+ [] -> do mb_dir <- getLibDir
case mb_dir of
Nothing -> die err_msg
Just dir ->
- do let path1 = dir </> "package.conf"
- path2 = dir </> ".." </> ".." </> ".."
- </> "inplace-datadir"
- </> "package.conf"
- exists1 <- doesFileExist path1
- exists2 <- doesFileExist path2
- if exists1 then return path1
- else if exists2 then return path2
- else die "Can't find package.conf"
+ do let path = dir </> "package.conf"
+ exists <- doesFileExist path
+ unless exists $ die "Can't find package.conf"
+ return path
fs -> return (last fs)
let global_conf_dir = global_conf ++ ".d"
@@ -1053,7 +1048,7 @@ checkGHCiLib dirs batch_lib_dir batch_lib_file lib auto_build
| auto_build = autoBuildGHCiLib batch_lib_dir batch_lib_file ghci_lib_file
| otherwise = do
m <- doesFileExistOnPath ghci_lib_file dirs
- when (isNothing m) $
+ when (isNothing m && ghci_lib_file /= "HSrts.o") $
hPutStrLn stderr ("warning: can't find GHCi lib " ++ ghci_lib_file)
where
ghci_lib_file = lib <.> "o"
@@ -1069,7 +1064,7 @@ autoBuildGHCiLib dir batch_file ghci_file = do
#if defined(darwin_HOST_OS)
r <- rawSystem "ld" ["-r","-x","-o",ghci_lib_file,"-all_load",batch_lib_file]
#elif defined(mingw32_HOST_OS)
- execDir <- getExecDir "/bin/ghc-pkg.exe"
+ execDir <- getLibDir
r <- rawSystem (maybe "" (++"/gcc-lib/") execDir++"ld") ["-r","-x","-o",ghci_lib_file,"--whole-archive",batch_lib_file]
#else
r <- rawSystem "ld" ["-r","-x","-o",ghci_lib_file,"--whole-archive",batch_lib_file]
@@ -1184,26 +1179,34 @@ subst a b ls = map (\ x -> if x == a then b else x) ls
unDosifyPath :: FilePath -> FilePath
unDosifyPath xs = subst '\\' '/' xs
-getExecDir :: String -> IO (Maybe String)
+getLibDir :: IO (Maybe String)
+getLibDir = fmap (fmap (</> "lib")) $ getExecDir "/bin/ghc-pkg.exe"
+
-- (getExecDir cmd) returns the directory in which the current
-- executable, which should be called 'cmd', is running
-- So if the full path is /a/b/c/d/e, and you pass "d/e" as cmd,
-- you'll get "/a/b/c" back as the result
-getExecDir cmd
- = allocaArray len $ \buf -> do
- ret <- getModuleFileName nullPtr buf len
- if ret == 0 then return Nothing
- else do s <- peekCString buf
- return (Just (reverse (drop (length cmd)
- (reverse (unDosifyPath s)))))
- where
- len = 2048::Int -- Plenty, PATH_MAX is 512 under Win32.
+getExecDir :: String -> IO (Maybe String)
+getExecDir cmd =
+ getExecPath >>= maybe (return Nothing) removeCmdSuffix
+ where unDosifyPath = subst '\\' '/'
+ initN n = reverse . drop n . reverse
+ removeCmdSuffix = return . Just . initN (length cmd) . unDosifyPath
+
+getExecPath :: IO (Maybe String)
+getExecPath =
+ allocaArray len $ \buf -> do
+ ret <- getModuleFileName nullPtr buf len
+ if ret == 0 then return Nothing
+ else liftM Just $ peekCString buf
+ where len = 2048 -- Plenty, PATH_MAX is 512 under Win32.
+
+foreign import stdcall unsafe "GetModuleFileNameA"
+ getModuleFileName :: Ptr () -> CString -> Int -> IO Int32
-foreign import stdcall unsafe "GetModuleFileNameA"
- getModuleFileName :: Ptr () -> CString -> Int -> IO Int32
#else
-getExecDir :: String -> IO (Maybe String)
-getExecDir _ = return Nothing
+getLibDir :: IO (Maybe String)
+getLibDir = return Nothing
#endif
-----------------------------------------
diff --git a/utils/ghc-pkg/Makefile b/utils/ghc-pkg/Makefile
index 632e02c1d5..c45176561c 100644
--- a/utils/ghc-pkg/Makefile
+++ b/utils/ghc-pkg/Makefile
@@ -1,21 +1,3 @@
-
-TOP=../..
-ENABLE_SHELL_WRAPPERS = YES
-EXTRA_CLEAN = Version.hs
-EXTRA_INPLACE_CONFIGURE_FLAGS = $(INPLACE_GHC_DATADIR_CONFIGURE_FLAGS)
-EXTRA_STAGE2_CONFIGURE_FLAGS = --datasubdir=.
-
-include $(TOP)/mk/boilerplate.mk
-include $(TOP)/mk/cabal.mk
-
-with-bootstrapping-compiler: Version.hs
-with-stage-2: Version.hs
-
-Version.hs: Makefile $(TOP)/mk/config.mk
- $(RM) -f Version.hs
- echo "module Version where" >> Version.hs
- echo "version, targetOS, targetARCH :: String" >> Version.hs
- echo "version = \"$(ProjectVersion)\"" >> Version.hs
- echo "targetOS = \"$(TargetOS_CPP)\"" >> Version.hs
- echo "targetARCH = \"$(TargetArch_CPP)\"" >> Version.hs
-
+dir = utils/ghc-pkg
+TOP = ../..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/utils/ghc-pkg/ghc.mk b/utils/ghc-pkg/ghc.mk
new file mode 100644
index 0000000000..388af0d5b9
--- /dev/null
+++ b/utils/ghc-pkg/ghc.mk
@@ -0,0 +1,69 @@
+# -----------------------------------------------------------------------------
+# Bootstrapping ghc-pkg
+
+utils/ghc-pkg_dist_PROG = ghc-pkg
+
+$(GHC_PKG_INPLACE) : utils/ghc-pkg/dist/build/$(utils/ghc-pkg_dist_PROG)$(exeext) $(MKDIRHIER)
+ $(MKDIRHIER) $(dir $(INPLACE_PACKAGE_CONF))
+ echo "[]" > $(INPLACE_PACKAGE_CONF)
+ifeq "$(Windows)" "YES"
+ cp $< $@
+else
+ $(RM) $@
+ echo "#!/bin/sh" >>$@
+ echo "PKGCONF=$(TOP)/$(INPLACE_PACKAGE_CONF)" >>$@
+ echo '$(TOP)/utils/ghc-pkg/dist/build/$(utils/ghc-pkg_dist_PROG) --global-conf $$PKGCONF $${1+"$$@"}' >> $@
+ chmod +x $@
+endif
+
+# depend on ghc-cabal, otherwise we build Cabal twice when building in parallel
+utils/ghc-pkg/dist/build/$(utils/ghc-pkg_dist_PROG)$(exeext): utils/ghc-pkg/Main.hs utils/ghc-pkg/Version.hs $(GHC_CABAL_INPLACE) $(MKDIRHIER)
+ $(MKDIRHIER) bootstrapping
+ $(MKDIRHIER) utils/ghc-pkg/dist/build
+ $(GHC) --make utils/ghc-pkg/Main.hs -o $@ \
+ -Wall \
+ -DCABAL_VERSION=$(CABAL_VERSION) \
+ -odir bootstrapping \
+ -hidir bootstrapping \
+ -iutils/ghc-pkg \
+ -XCPP -XExistentialQuantification -XDeriveDataTypeable \
+ -ilibraries/Cabal \
+ -ilibraries/filepath \
+ -ilibraries/extensible-exceptions \
+ -ilibraries/hpc
+
+utils/ghc-pkg/Version.hs: mk/config.mk
+ $(RM) -f $@
+ echo "module Version where" >> $@
+ echo "version, targetOS, targetARCH :: String" >> $@
+ echo "version = \"$(ProjectVersion)\"" >> $@
+ echo "targetOS = \"$(TargetOS_CPP)\"" >> $@
+ echo "targetARCH = \"$(TargetArch_CPP)\"" >> $@
+
+$(eval $(call clean-target,utils/ghc-pkg,dist,\
+ utils/ghc-pkg/dist \
+ utils/ghc-pkg/Version.hs))
+
+# -----------------------------------------------------------------------------
+# Building ghc-pkg with stage 1
+
+utils/ghc-pkg_dist-install_PROG = ghc-pkg
+utils/ghc-pkg_dist-install_MODULES = Main Version
+utils/ghc-pkg_dist-install_DEPS = Cabal
+utils/ghc-pkg_dist-install_SHELL_WRAPPER = YES
+utils/ghc-pkg_dist-install_INSTALL_SHELL_WRAPPER = YES
+utils/ghc-pkg_dist-install_INSTALL_SHELL_WRAPPER_NAME = ghc-pkg-$(ProjectVersion)
+utils/ghc-pkg_dist-install_INSTALL_INPLACE = NO
+
+$(eval $(call build-prog,utils/ghc-pkg,dist-install,1))
+
+ifeq "$(Windows)" "NO"
+install: install_utils/ghc-pkg_link
+
+.PNONY: install_utils/ghc-pkg_link
+install_utils/ghc-pkg_link:
+ $(MKDIRHIER) $(DESTDIR)$(bindir)
+ $(RM) -f $(DESTDIR)$(bindir)/ghc-pkg
+ $(LN_S) ghc-pkg-$(ProjectVersion) $(DESTDIR)$(bindir)/ghc-pkg
+endif
+
diff --git a/utils/hasktags/Makefile b/utils/hasktags/Makefile
index 0f34de9174..64905b050a 100644
--- a/utils/hasktags/Makefile
+++ b/utils/hasktags/Makefile
@@ -1,5 +1,3 @@
-
-TOP=../..
-include $(TOP)/mk/boilerplate.mk
-include $(TOP)/mk/cabal.mk
-
+dir = utils/hasktags
+TOP = ../..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/utils/hasktags/ghc.mk b/utils/hasktags/ghc.mk
new file mode 100644
index 0000000000..38ed434228
--- /dev/null
+++ b/utils/hasktags/ghc.mk
@@ -0,0 +1,10 @@
+utils/hasktags_dist_MODULES = Main
+utils/hasktags_dist_PROG = hasktags$(exeext)
+utils/hasktags_dist_INSTALL = YES
+
+utils/hasktags/dist/build/Main.hs : utils/hasktags/HaskTags.hs $(MKDIRHIER)
+ $(MKDIRHIER) $(dir $@)
+ $(CP) $< $@
+
+$(eval $(call build-prog,utils/hasktags,dist,1))
+
diff --git a/utils/hp2ps/Main.h b/utils/hp2ps/Main.h
index 81c62dc891..0d0d75f847 100644
--- a/utils/hp2ps/Main.h
+++ b/utils/hp2ps/Main.h
@@ -1,7 +1,7 @@
#ifndef MAIN_H
#define MAIN_H
-#include "../includes/ghcconfig.h"
+#include "ghcconfig.h"
#include <stdio.h>
#ifdef __STDC__
diff --git a/utils/hp2ps/Makefile b/utils/hp2ps/Makefile
index 93aa856ffc..ed3dff8b21 100644
--- a/utils/hp2ps/Makefile
+++ b/utils/hp2ps/Makefile
@@ -1,20 +1,3 @@
-TOP=../..
-include $(TOP)/mk/boilerplate.mk
-
-SRC_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
-SRC_LD_OPTS += $(MACOSX_DEPLOYMENT_LD_OPTS)
-
-C_PROG = hp2ps
-
-SRC_CC_OPTS += -I$(GHC_INCLUDE_DIR) -Wall
-
-INSTALL_PROGS += $(C_PROG)
-
-LIBS = $(LIBM)
-
-CLEAN_FILES += $(C_OBJS) $(C_PROG)
-
-BINDIST_EXTRAS += $(C_PROG)
-include $(TOP)/mk/bindist.mk
-
-include $(TOP)/mk/target.mk
+dir = utils/hp2ps
+TOP = ../..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/utils/hp2ps/ghc.mk b/utils/hp2ps/ghc.mk
new file mode 100644
index 0000000000..75964e1e39
--- /dev/null
+++ b/utils/hp2ps/ghc.mk
@@ -0,0 +1,10 @@
+utils/hp2ps_dist_C_SRCS = AreaBelow.c Curves.c Error.c Main.c \
+ Reorder.c TopTwenty.c AuxFile.c Deviation.c \
+ HpFile.c Marks.c Scale.c TraceElement.c \
+ Axes.c Dimensions.c Key.c PsFile.c Shade.c \
+ Utilities.c
+utils/hp2ps_dist_PROG = hp2ps$(exeext)
+utils/hp2ps_dist_INSTALL = YES
+
+$(eval $(call build-prog,utils/hp2ps,dist,0))
+
diff --git a/utils/hpc/Hpc.hs b/utils/hpc/Main.hs
index da859d0345..da859d0345 100644
--- a/utils/hpc/Hpc.hs
+++ b/utils/hpc/Main.hs
diff --git a/utils/hpc/Makefile b/utils/hpc/Makefile
index 0f34de9174..a8458d2ee6 100644
--- a/utils/hpc/Makefile
+++ b/utils/hpc/Makefile
@@ -1,5 +1,3 @@
-
-TOP=../..
-include $(TOP)/mk/boilerplate.mk
-include $(TOP)/mk/cabal.mk
-
+dir = utils/hpc
+TOP = ../..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/utils/hpc/ghc.mk b/utils/hpc/ghc.mk
new file mode 100644
index 0000000000..0e0f91cd94
--- /dev/null
+++ b/utils/hpc/ghc.mk
@@ -0,0 +1,7 @@
+utils/hpc_dist_MODULES = Main HpcCombine HpcDraft HpcFlags HpcLexer HpcMap \
+ HpcMarkup HpcOverlay HpcParser HpcReport HpcSet \
+ HpcShowTix HpcUtils
+utils/hpc_dist_HC_OPTS = -cpp -package hpc
+utils/hpc_dist_INSTALL = YES
+utils/hpc_dist_PROG = hpc$(exeext)
+$(eval $(call build-prog,utils/hpc,dist,1))
diff --git a/utils/installPackage/Makefile b/utils/installPackage/Makefile
deleted file mode 100644
index 758442dc85..0000000000
--- a/utils/installPackage/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
-
-TOP=../..
-include $(TOP)/mk/boilerplate.mk
-include $(TOP)/mk/cabal.mk
-
-# If the bootstrapping compiler already has a newer version of Cabal
-# than the in-tree Cabal, then we need to forcibly use the in-tree one.
-# Otherwise we use one Cabal for some things and the other Cabal for
-# other things, and Cabal (rightly) complains about the version
-# mismatch.
-EXTRA_INPLACE_CONFIGURE_FLAGS += $(CABAL_CONSTRAINT)
-EXTRA_STAGE2_CONFIGURE_FLAGS += $(CABAL_CONSTRAINT)
-
diff --git a/utils/installPackage/installPackage.cabal b/utils/installPackage/installPackage.cabal
deleted file mode 100644
index ab078200d5..0000000000
--- a/utils/installPackage/installPackage.cabal
+++ /dev/null
@@ -1,28 +0,0 @@
-Name: installPackage
--- XXX
-Version: 1.0
-Copyright: XXX
-License: BSD3
--- XXX License-File: LICENSE
-Author: XXX
-Maintainer: XXX
-Synopsis: XXX
-Description:
- XXX
-Category: XXX
-build-type: Simple
-cabal-version: >=1.2
-
---Flag base3
--- Description: Choose the new smaller, split-up base package.
-
-Executable installPackage
- Main-Is: installPackage.hs
- Build-Depends: base, Cabal
--- if flag(base3)
--- Build-Depends: base >= 3 && < 4,
--- directory >= 1 && < 1.1,
--- process >= 1 && < 1.1
--- else
--- Build-Depends: base < 3
-
diff --git a/utils/installPackage/installPackage.hs b/utils/installPackage/installPackage.hs
deleted file mode 100644
index 9ec7282592..0000000000
--- a/utils/installPackage/installPackage.hs
+++ /dev/null
@@ -1,154 +0,0 @@
-
-import Control.Monad
-import Data.Maybe
-import Distribution.PackageDescription
-import Distribution.PackageDescription.Parse
-import Distribution.ReadE
-import Distribution.Simple
-import Distribution.Simple.Configure
-import Distribution.Simple.LocalBuildInfo
-import Distribution.Simple.Program
-import Distribution.Simple.Setup
-import Distribution.Simple.Utils
-import Distribution.Text
-import Distribution.Verbosity
-import System.Environment
-
-main :: IO ()
-main
- = do args <- getArgs
- case args of
- "install" : ghcpkg : ghcpkgconf : destdir : topdir :
- iprefix : ibindir : ilibdir : ilibexecdir : idynlibdir :
- idatadir : idocdir : ihtmldir : ihaddockdir :
- args' ->
- case parseArgs args' of
- (verbosity, distPref, enableShellWrappers, strip) ->
- doInstall verbosity distPref enableShellWrappers strip
- ghcpkg ghcpkgconf destdir topdir
- iprefix ibindir ilibdir ilibexecdir
- idynlibdir idatadir idocdir ihtmldir
- ihaddockdir
- _ ->
- error ("Bad arguments: " ++ show args)
-
--- XXX We should really make Cabal do the hardwork here
-parseArgs :: [String]
- -> (Verbosity, -- verbosity
- FilePath, -- dist prefix
- Bool, -- enable shell wrappers?
- Bool) -- strip exe?
-parseArgs = f normal defaultDistPref False True
- where f _ dp esw strip (('-':'v':val):args)
- = f (readEOrFail flagToVerbosity val) dp esw strip args
- f v _ esw strip ("--distpref":dp:args) = f v dp esw strip args
- f v dp _ strip ("--enable-shell-wrappers":args) = f v dp True strip args
- f v dp esw _ ("--disable-executable-stripping":args) = f v dp esw False args
- f v dp esw strip [] = (v, dp, esw, strip)
- f _ _ _ _ args = error ("Bad arguments: " ++ show args)
-
-doInstall :: Verbosity -> FilePath -> Bool -> Bool
- -> FilePath -> FilePath -> FilePath -> FilePath
- -> FilePath -> FilePath -> FilePath -> FilePath -> FilePath
- -> FilePath -> FilePath -> FilePath -> FilePath
- -> IO ()
-doInstall verbosity distPref enableShellWrappers strip
- ghcpkg ghcpkgconf destdir topdir
- iprefix ibindir ilibdir ilibexecdir idynlibdir idatadir
- idocdir ihtmldir ihaddockdir =
- do let userHooks = simpleUserHooks
- copyto = if null destdir then NoCopyDest else CopyTo destdir
- copyFlags = defaultCopyFlags {
- copyDistPref = toFlag distPref,
- copyUseWrapper = toFlag enableShellWrappers,
- copyDest = toFlag copyto,
- copyVerbosity = toFlag verbosity
- }
- registerFlags = defaultRegisterFlags {
- regDistPref = toFlag distPref,
- regPackageDB = toFlag GlobalPackageDB,
- regVerbosity = toFlag verbosity,
- regGenScript = toFlag $ False,
- regInPlace = toFlag $ False
- }
- lbi <- getConfig verbosity distPref
- let pd = localPkgDescr lbi
- i = installDirTemplates lbi
- -- This is an almighty hack. We need to register
- -- ghc-prim:GHC.Prim, but it doesn't exist, get built, get
- -- haddocked, get copied, etc.
- pd_reg = if packageName pd == PackageName "ghc-prim"
- then case library pd of
- Just lib ->
- let ems = fromJust (simpleParse "GHC.Prim")
- : exposedModules lib
- lib' = lib { exposedModules = ems }
- in pd { library = Just lib' }
- Nothing ->
- error "Expected a library, but none found"
- else pd
- -- When coying, we need to actually give a concrete
- -- directory to copy to rather than "$topdir"
- toPathTemplate' = toPathTemplate . replaceTopdir topdir
- i_copy = i { prefix = toPathTemplate' iprefix,
- bindir = toPathTemplate' ibindir,
- libdir = toPathTemplate' ilibdir,
- dynlibdir = toPathTemplate' idynlibdir,
- libexecdir = toPathTemplate' ilibexecdir,
- datadir = toPathTemplate' idatadir,
- docdir = toPathTemplate' idocdir,
- htmldir = toPathTemplate' ihtmldir,
- haddockdir = toPathTemplate' ihaddockdir
- }
- lbi_copy = lbi { installDirTemplates = i_copy,
- stripExes = strip }
- -- When we run GHC we give it a $topdir that includes the
- -- $compiler/lib/ part of libsubdir, so we only want the
- -- $pkgid part in the package.conf file. This is a bit of
- -- a hack, really.
- progs = withPrograms lbi
- prog = ConfiguredProgram {
- programId = programName ghcPkgProgram,
- programVersion = Nothing,
- programArgs = ["--force", "--global-conf", ghcpkgconf],
- programLocation = UserSpecified ghcpkg
- }
- progs' = updateProgram prog progs
- i_reg = i { prefix = toPathTemplate iprefix,
- bindir = toPathTemplate ibindir,
- libdir = toPathTemplate ilibdir,
- dynlibdir = toPathTemplate idynlibdir,
- libexecdir = toPathTemplate ilibexecdir,
- datadir = toPathTemplate idatadir,
- docdir = toPathTemplate idocdir,
- htmldir = toPathTemplate ihtmldir,
- haddockdir = toPathTemplate ihaddockdir
- }
- lbi_reg = lbi { installDirTemplates = i_reg,
- withPrograms = progs' }
- (copyHook simpleUserHooks) pd lbi_copy userHooks copyFlags
- -- Cabal prints a scary "Package contains no library to register"
- -- message if we call register but this is an executable package.
- -- We therefore don't call it if we don't have a library for it.
- when (isJust (library pd_reg)) $
- (regHook simpleUserHooks) pd_reg lbi_reg userHooks registerFlags
- return ()
-
-replaceTopdir :: FilePath -> FilePath -> FilePath
-replaceTopdir topdir ('$':'t':'o':'p':'d':'i':'r':p) = topdir ++ p
-replaceTopdir topdir ('$':'h':'t':'t':'p':'t':'o':'p':'d':'i':'r':p)
- = topdir ++ p
-replaceTopdir _ p = p
-
--- Get the build info, merging the setup-config and buildinfo files.
-getConfig :: Verbosity -> FilePath -> IO LocalBuildInfo
-getConfig verbosity distPref = do
- lbi <- getPersistBuildConfig distPref
- maybe_infoFile <- defaultHookedPackageDesc
- case maybe_infoFile of
- Nothing -> return lbi
- Just infoFile -> do
- hbi <- readHookedBuildInfo verbosity infoFile
- return lbi { localPkgDescr = updatePackageDescription hbi (localPkgDescr lbi)}
-
-
diff --git a/utils/mkdependC/Makefile b/utils/mkdependC/Makefile
index 432c8981e4..0a67928259 100644
--- a/utils/mkdependC/Makefile
+++ b/utils/mkdependC/Makefile
@@ -1,24 +1,3 @@
-#
-# Boilerplate Makefile for building perl script that
-# needs some configured constants prepended to it.
-#
-TOP=../..
-include $(TOP)/mk/boilerplate.mk
-
-boot :: all
-
-PROG=mkdependC
-CLEAN_FILES += $(PROG)
-all::
- $(RM) -f $(PROG)
- echo '#!$(PERL)' >> $(PROG)
- echo '$$DEFAULT_TMPDIR = "$(DEFAULT_TMPDIR)";' >> $(PROG)
- echo '$$CPP = "$(CPP)";' >> $(PROG)
- echo '$$BUILDPLATFORM = "$(BUILDPLATFORM)";' >> $(PROG)
- cat $(PROG).prl >> $(PROG)
- $(EXECUTABLE_FILE) $(PROG)
-
-binary-dist:
- @:
-
-include $(TOP)/mk/target.mk
+dir = utils/mkdependC
+TOP = ../..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/utils/mkdependC/ghc.mk b/utils/mkdependC/ghc.mk
new file mode 100644
index 0000000000..4f43cc72dc
--- /dev/null
+++ b/utils/mkdependC/ghc.mk
@@ -0,0 +1,12 @@
+$(MKDEPENDC) : utils/mkdependC/mkdependC.prl $(MKDIRHIER)
+ $(MKDIRHIER) $(dir $@)
+ $(RM) -f $@
+ echo '#!$(PERL)' >> $@
+ echo '$$DEFAULT_TMPDIR = "$(DEFAULT_TMPDIR)";' >> $@
+ echo '$$CPP = "$(CPP)";' >> $@
+ echo '$$BUILDPLATFORM = "$(BUILDPLATFORM)";' >> $@
+ cat utils/mkdependC/mkdependC.prl >> $@
+ $(EXECUTABLE_FILE) $@
+
+$(eval $(call all-target,utils/mkdependC,$(MKDEPENDC)))
+$(eval $(call clean-target,utils/mkdependC,,$(MKDEPENDC)))
diff --git a/utils/mkdependC/mkdependC.prl b/utils/mkdependC/mkdependC.prl
index f7af53ac3c..166c3f16a7 100644
--- a/utils/mkdependC/mkdependC.prl
+++ b/utils/mkdependC/mkdependC.prl
@@ -122,6 +122,8 @@ sub mangle_command_line_args {
push(@Defines, $2);
} elsif ( /^(-optc)?(-I.*)/ ) {
$Include_dirs .= " $2";
+ } elsif ( /^(-optc)?(-isystem.*)/ ) {
+ $Include_dirs .= " $2";
} elsif ($Dashdashes_seen != 1) { # not between -- ... --
if ( /^-v$/ ) {
diff --git a/utils/mkdirhier/Makefile b/utils/mkdirhier/Makefile
index 0e32bbbde4..879e170be5 100644
--- a/utils/mkdirhier/Makefile
+++ b/utils/mkdirhier/Makefile
@@ -1,17 +1,3 @@
-TOP=../..
-include $(TOP)/mk/boilerplate.mk
-
-boot :: all
-
-PROG=mkdirhier
-CLEAN_FILES += $(PROG)
-all::
- $(RM) -f $(PROG)
- echo '#!$(SHELL)' >> $(PROG)
- cat $(PROG).sh >> $(PROG)
- $(EXECUTABLE_FILE) $(PROG)
-
-BINDIST_EXTRAS += $(PROG)
-include $(TOP)/mk/bindist.mk
-
-include $(TOP)/mk/target.mk
+dir = utils/mkdirhier
+TOP = ../..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/utils/mkdirhier/ghc.mk b/utils/mkdirhier/ghc.mk
new file mode 100644
index 0000000000..59ad53fe69
--- /dev/null
+++ b/utils/mkdirhier/ghc.mk
@@ -0,0 +1,11 @@
+$(MKDIRHIER) : utils/mkdirhier/mkdirhier.sh
+ -mkdir $(INPLACE)
+ -mkdir $(INPLACE_BIN)
+ -mkdir $(INPLACE_LIB)
+ $(RM) -f $@
+ echo '#!$(SHELL)' >> $@
+ cat utils/mkdirhier/mkdirhier.sh >> $@
+ $(EXECUTABLE_FILE) $@
+
+$(eval $(call all-target,utils/mkdirhier,$(MKDIRHIER)))
+$(eval $(call clean-target,utils/mkdirhier,,$(MKDIRHIER)))
diff --git a/utils/parallel/Makefile b/utils/parallel/Makefile
index 50909c68e1..8b68d777b9 100644
--- a/utils/parallel/Makefile
+++ b/utils/parallel/Makefile
@@ -48,8 +48,6 @@ $(BASH_INSTALLERS): install.bash.%:
cat $*.bash >> $(bindir)/$*
$(EXECUTABLE_FILE) $(bindir)/$*
-BINDIST_EXTRAS += $(addsuffix .pl,$(PERL_PROGS))
-BINDIST_EXTRAS += $(addsuffix .bash,$(BASH_PROGS))
include $(TOP)/mk/bindist.mk
include $(TOP)/mk/target.mk
diff --git a/utils/runghc/Makefile b/utils/runghc/Makefile
index 1415921b04..fb5c1c1c55 100644
--- a/utils/runghc/Makefile
+++ b/utils/runghc/Makefile
@@ -1,12 +1,3 @@
-
-TOP=../..
-ENABLE_SHELL_WRAPPERS = YES
-
-include $(TOP)/mk/boilerplate.mk
-include $(TOP)/mk/cabal.mk
-
-distclean maintainer-clean:
- $(RM) -f runghc.cabal
-
-# XXX Need to make runhaskell somehow
-
+dir = utils/runghc
+TOP = ../..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/utils/runghc/ghc.mk b/utils/runghc/ghc.mk
new file mode 100644
index 0000000000..1eb2d87c47
--- /dev/null
+++ b/utils/runghc/ghc.mk
@@ -0,0 +1,29 @@
+utils/runghc_dist_MODULES = Main
+utils/runghc_dist_HC_OPTS = -cpp -DVERSION="\"$(ProjectVersion)\""
+utils/runghc_dist_PROG = runghc$(exeext)
+utils/runghc_dist_SHELL_WRAPPER = YES
+utils/runghc_dist_INSTALL_SHELL_WRAPPER = YES
+
+ifneq "$(BINDIST)" "YES"
+
+# hack: the build system has trouble with Main modules not called Main.hs
+utils/runghc/dist/build/Main.hs : utils/runghc/runghc.hs $(MKDIRHIER)
+ $(MKDIRHIER) $(dir $@)
+ $(CP) $< $@
+
+$(eval $(call build-prog,utils/runghc,dist,1))
+
+endif
+
+install: install_runhaskell
+
+.PHONY: install_runhaskell
+ifeq "$(Windows)" "YES"
+install_runhaskell: install_bins
+ $(CP) $(DESTDIR)$(bindir)/runghc$(exeext) $(DESTDIR)$(bindir)/runhaskell$(exeext)
+else
+install_runhaskell:
+ $(RM) $(DESTDIR)$(bindir)/runhaskell
+ $(LN_S) runghc $(DESTDIR)$(bindir)/runhaskell
+endif
+
diff --git a/utils/runghc/runghc.hs b/utils/runghc/runghc.hs
index 47615def3a..aadafd9a71 100644
--- a/utils/runghc/runghc.hs
+++ b/utils/runghc/runghc.hs
@@ -22,8 +22,6 @@
module Main (main) where
-import Paths_runghc
-
import Control.Exception
import Data.Char
import Data.List
@@ -85,7 +83,7 @@ parseRunGhcFlags = f mempty
printVersion :: IO ()
printVersion = do
- putStrLn ("runghc " ++ showVersion version)
+ putStrLn ("runghc " ++ VERSION)
printUsage :: IO ()
printUsage = do
diff --git a/utils/touchy/ghc.mk b/utils/touchy/ghc.mk
new file mode 100644
index 0000000000..022783fd3e
--- /dev/null
+++ b/utils/touchy/ghc.mk
@@ -0,0 +1,5 @@
+utils/touchy_dist_C_SRCS = touchy.c
+utils/touchy_dist_PROG = $(GHC_TOUCHY_PGM)
+utils/touchy_dist_LIBEXEC = YES
+utils/touchy_dist_INSTALL = YES
+$(eval $(call build-prog,utils/touchy,dist,0))
diff --git a/utils/touchy/touchy.c b/utils/touchy/touchy.c
index 90fb31e93e..dc4dc8d83f 100644
--- a/utils/touchy/touchy.c
+++ b/utils/touchy/touchy.c
@@ -11,6 +11,7 @@
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
+#include <utime.h>
int
main(int argc, char** argv)
diff --git a/utils/unlit/Makefile b/utils/unlit/Makefile
index 1723a08e26..b5ecc2dd47 100644
--- a/utils/unlit/Makefile
+++ b/utils/unlit/Makefile
@@ -1,25 +1,3 @@
-TOP=../..
-include $(TOP)/mk/boilerplate.mk
-
-# Exclude for booting
-ifeq "$(stage)" "2"
-SRC_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
-SRC_LD_OPTS += $(MACOSX_DEPLOYMENT_LD_OPTS)
-endif
-
-C_SRCS=unlit.c
-C_PROG=unlit
-SRC_CC_OPTS += -O
-
-# Get it over with!
-boot :: all
-
-#
-# Install unlit in lib/
-#
-INSTALL_LIBEXECS += $(C_PROG)
-
-BINDIST_EXTRAS += $(C_PROG)
-include $(TOP)/mk/bindist.mk
-
-include $(TOP)/mk/target.mk
+dir = utils/unlit
+TOP = ../..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/utils/unlit/ghc.mk b/utils/unlit/ghc.mk
new file mode 100644
index 0000000000..458092543d
--- /dev/null
+++ b/utils/unlit/ghc.mk
@@ -0,0 +1,9 @@
+utils/unlit_dist_C_SRCS = unlit.c
+utils/unlit_dist_PROG = $(GHC_UNLIT_PGM)
+utils/unlit_dist_LIBEXEC = YES
+utils/unlit_dist_INSTALL = YES
+
+ifneq "$(BINDIST)" "YES"
+$(eval $(call build-prog,utils/unlit,dist,0))
+endif
+
diff --git a/utils/unlit/unlit.c b/utils/unlit/unlit.c
index c5beeb1cbf..1269b81463 100644
--- a/utils/unlit/unlit.c
+++ b/utils/unlit/unlit.c
@@ -90,10 +90,8 @@ static char *ofilename = NULL;
* if noisy is not set.
*/
-complain(file, lin, what)
-char *file;
-char *what;
-int lin; {
+void complain(char *file, int lin, char *what)
+{
if (noisy) {
if (file)
fprintf(stderr, "%s ", file);
@@ -102,7 +100,7 @@ int lin; {
}
}
-writeerror()
+void writeerror(void)
{
if (!strcmp(ofilename,"-")) {
fprintf(stderr, CANNOTWRITESTDOUT);
@@ -112,9 +110,8 @@ writeerror()
exit(1);
}
-myputc(c, ostream)
-char c;
-FILE *ostream; {
+void myputc(char c, FILE *ostream)
+{
if (putc(c,ostream) == EOF) {
writeerror();
}
@@ -247,10 +244,8 @@ FILE *istream, *ostream; {
* - there should be at least one DEFN line in a script.
*/
-unlit(file, istream, ostream)
-char *file;
-FILE *istream;
-FILE *ostream; {
+void unlit(char *file, FILE *istream, FILE *ostream)
+{
line last, this=START;
int linesread=0;
int defnsread=0;
@@ -317,9 +312,8 @@ FILE *ostream; {
* position to specify the standard input or the standard output respectively.
*/
-main(argc,argv)
-int argc;
-char **argv; {
+int main(int argc,char **argv)
+{
FILE *istream, *ostream;
char *file;
diff --git a/validate b/validate
index d57a0955e6..6229763636 100644
--- a/validate
+++ b/validate
@@ -58,6 +58,11 @@ if [ $no_clean -eq 0 ]; then
make distclean
fi
+ INSTDIR=`pwd`/inst
+ if [ "$OSTYPE" = "cygwin" ]
+ then
+ INSTDIR=`cygpath -m "$INSTDIR"`
+ fi
case $OSTYPE in
cygwin|msys) config_args=--build=i386-unknown-mingw32
if [ -f c:/mingw/bin/gcc.exe ]
@@ -72,7 +77,7 @@ if [ $no_clean -eq 0 ]; then
esac
sh boot
- ./configure "--prefix=`pwd`/inst" $config_args
+ ./configure --prefix="$INSTDIR" $config_args
fi
thisdir=`utils/pwd/pwd forwardslash`