--- /dev/null
+#!/usr/bin/env bash
+set -e
+declare canon_name="canon-name/src/canon-name"
+declare archive="work/archive"
+
+if [[ ! -x "$canon_name" ]]; then
+ gmake -f mk/canon-name.mk
+fi
+readonly platform=$("$canon_name")
+
+echo "This is build-hc-pkg, running on \"$platform\"."
+
+if [[ "$1" = "clean" ]]; then
+ echo "Cleaning..."
+ rm -rf work
+ exit
+fi
+
+declare srcpath=""
+if [[ -e "$archive" ]]; then
+ srcpath=$(cat "$archive")
+fi
+
+if [[ -z "$srcpath" || ! -e "$srcpath" ]]; then
+ mkdir -p work
+ read -e -p "Enter the file path to ghc-x.y.z-src.tar.bz2: " srcpath
+ if [[ -e "$srcpath" ]]; then
+ mkdir -p work
+ echo "$srcpath" > "$archive"
+ else
+ echo "$srcpath not found." >&2
+ exit 1
+ fi
+fi
+
+gmake -f mk/main.mk SRCPATH="$srcpath" PLATFORM="$platform" SHELL="$SHELL"
+
+echo "If you are done, run \"$0 clean\" to cleanup the working directory."
--- /dev/null
+PORTING_HOST = YES
+GhcUnregisterised = YES
+GhcLibHcOpts = -O -fvia-C -keep-hc-files
+GhcRtsHcOpts = -keep-hc-files
+GhcLibWays = v
+GhcRTSWays =
+SplitObjs = NO
+GhcWithNativeCodeGen = NO
+GhcWithInterpreter = NO
+GhcStage1HcOpts = -O
+GhcStage2HcOpts = -O -fvia-C -keep-hc-files
+SRC_HC_OPTS += -H32m
+GhcWithSMP = NO
+utils/ghc-pkg_dist-install_v_HC_OPTS += -keep-hc-files
+
+INTEGER_LIBRARY = integer-simple
+libraries/terminfo_CONFIGURE_OPTS += \
+ --configure-option=--with-curses-includes=/usr/pkg/include \
+ --configure-option=--with-curses-libraries=/usr/pkg/lib
--- /dev/null
+#!/bin/sh
+set -x
+rm -f list mkfiles boot.tar
+find . -name "*.hi" >> list
+find . -name "*.hc" >> list
+find . -name "*_stub.c" >> list
+find . -name "*_stub.h" >> list
+find . -name package-data.mk >> list
+find . -name package.conf.d >> list
+find . -name package.conf.inplace >> list
+ls compiler/stage?/build/Config.hs >> list
+echo compiler/prelude/primops.txt >> list
+ls compiler/primop-*.hs-incl >> list
+find . -name .depend | sed -e 's/^/mkdir -p `dirname /' -e 's/$/`/' >> mkfiles
+find . -name .depend | sed "s/^/touch /" >> mkfiles
+echo mkfiles >> list
+tar -cf boot.tar -T list
--- /dev/null
+DIRNAME := $(patsubst %-src.tar.bz2,%,$(notdir $(SRCPATH)))
+GNUTAR ?= gnutar
+HC_TARNAME ?= $(DIRNAME)-boot-$(PLATFORM).tar.bz2
+
+all: work/pack-hc-pkg.stamp
+
+work/extract-src.stamp:
+ $(GNUTAR) -jxf $(SRCPATH) -C work
+ touch $@
+
+work/patch-src.stamp: work/extract-src.stamp
+ @echo "Executing an inner shell."
+ @echo "Apply some patch to the source tree, then exit."
+ @echo "(pwd: `pwd`/$(DIRNAME))"
+ @cd "work/$(DIRNAME)" && "$(SHELL)"
+ touch $@
+
+work/duplicate-target.stamp: work/patch-src.stamp
+ cp -rp "work/$(DIRNAME)" "work/$(DIRNAME)-target"
+ touch $@
+
+work/rename-host.stamp: work/duplicate-target.stamp
+ mv "work/$(DIRNAME)" "work/$(DIRNAME)-host"
+ touch $@
+
+work/$(DIRNAME)-target/Makefile: work/rename-host.stamp
+ cd "work/$(DIRNAME)-target" && \
+ ./configure -C --enable-hc-boot
+ touch $@
+
+work/$(DIRNAME)-target/mk/build.mk: files/target-build.mk work/$(DIRNAME)-target/Makefile
+ cp -f $< $@
+
+work/build-boot-files.stamp: work/$(DIRNAME)-target/mk/build.mk
+ $(MAKE) -C "work/$(DIRNAME)-target" bootstrapping-files
+ touch $@
+
+work/$(DIRNAME)-host/Makefile: work/build-boot-files.stamp
+ cd "work/$(DIRNAME)-host" && \
+ ./configure \
+ --with-iconv-includes=/usr/pkg/include \
+ --with-iconv-libraries=/usr/pkg/lib
+ touch $@
+
+work/$(DIRNAME)-host/mk/build.mk: files/host-build.mk work/$(DIRNAME)-host/Makefile
+ cp -f $< $@
+
+work/copy-boot-files.stamp: work/$(DIRNAME)-host/mk/build.mk
+ for i in dist-ghcconstants dist-derivedconstants ghcautoconf.h; do \
+ rm -rf "work/$(DIRNAME)-host/includes/$$i" && \
+ cp -pr \
+ "work/$(DIRNAME)-target/includes/$$i" \
+ "work/$(DIRNAME)-host/includes"; \
+ done
+ touch $@
+
+work/build-hc.stamp: work/copy-boot-files.stamp
+ $(MAKE) -C "work/$(DIRNAME)-host"
+ touch $@
+
+work/build-boot-tarball.stamp: work/build-hc.stamp
+ cd "work/$(DIRNAME)-host" && ../../files/mkboot
+ touch $@
+
+work/extract-boot-tarball.stamp: work/build-boot-tarball.stamp
+ mkdir -p "work/$(DIRNAME)"
+ $(GNUTAR) -xf "work/$(DIRNAME)-host/boot.tar" -C "work/$(DIRNAME)"
+ touch $@
+
+work/replace-paths.stamp: work/extract-boot-tarball.stamp
+ cd "work/$(DIRNAME)" && \
+ gsed -i \
+ -e 's#/usr/pkg#[[PREFIX]]#g' \
+ -e 's#'`pwd`'-host#[[GHC_SOURCE_PATH]]#g' \
+ inplace/lib/package.conf.d/*.conf \
+ */package.conf.inplace \
+ */*/package-data.mk \
+ */*/*/package-data.mk \
+ */*/*/*/package-data.mk
+ touch $@
+
+work/pack-hc-pkg.stamp: work/replace-paths.stamp
+ $(GNUTAR) -jcf "work/$(HC_TARNAME)" -C "work" $(DIRNAME)
+ touch $@
+ @echo "Done. Upload \"work/$(HC_TARNAME)\" to somewhere."