Subject: [alpine-aports] [PATCH 0/5] new ghc aport patch series

From: Mitch Tishmack <[email-masked]>
Date: Thu, 14 Jul 2016 21:53:18 -0500

This patch series supercedes any prior patch series for ghc from myself.

I've updated the series to include a port of llvm 3.7.1 as discussed on
irc. This adds a new port, llvm3.7, that lets one install llvm 3.7.1 alongside
the system llvm. It works well enough to build ghc, but might be able to
build/be built against by julia. Note however I haven't tested this. It
should also provide an llvm that other tools that are sensitive to llvm
versions could use. All binaries are suffixed with -3.7 and all other
libraries/include directories are similarly suffixed.

The dockerfiles for the bootstrap both now check sha1 sums of the tools
they download to build the bootstrap compilers.

To use this port however ghc needs to be bootstrapped through two docker
images that install a debian 8.0 container and build bootstrap compilers
for armhf and x86_64 via existing tools. Note this can take a long time
and only needs to be done successfully once per ghc release. The scp 
command in the snapshot function is and should be considered suspect. 
I took some liberty with where I imagined the bootstrap compilers should
go, the patch applier should adjust that as necessary. Once both bootstrap
compilers are built ghc-bootstrap's APKBUILD file will need to have its
source variable updated and the checksums recalculated. The bootstrap 
compiler tarballs that are produced aren't deterministic/repeatable.

But once bootstrap tarballs are built and uploaded and llvm3.7 is built
the rest of this series should work fine. The order is important however
as all of the ports depend on one another as follows:
llvm3.7 -> ghc-bootstrap -> ghc -> cabal -> stack

This attempts to mimic the go apk as much as possible in style. Included in
this series as well is the cabal build tool, as well as the alternative stack 
build tool. Both are similar to pip/gem/cargo/cpan. With all this in place
it should be possible to start porting other ghc programs or libraries.

Mitch Tishmack (5):
  testing/llvm3.7 new aport
  testing/ghc-bootstrap: new aport
  testing/ghc: new aport
  testing/cabal: new aport
  testing/stack: new aport

 testing/cabal/APKBUILD                             |  53 +++++++
 testing/cabal/cabal-0001-force-ld.gold.patch       |  10 ++
 testing/ghc-bootstrap/APKBUILD                     |  50 ++++++
 testing/ghc-bootstrap/bootstrap/armhf/Dockerfile   | 154 ++++++++++++++++++
 .../ghc-bootstrap/bootstrap/armhf/bootstrap.patch  | 112 ++++++++++++++
 testing/ghc-bootstrap/bootstrap/armhf/settings     |  32 ++++
 testing/ghc-bootstrap/bootstrap/gmpurl.patch       |  22 +++
 testing/ghc-bootstrap/bootstrap/llvm-3.7.1.sh      |  88 +++++++++++
 testing/ghc-bootstrap/bootstrap/x86_64/Dockerfile  | 143 +++++++++++++++++
 .../ghc-bootstrap/bootstrap/x86_64/bootstrap.patch | 112 ++++++++++++++
 testing/ghc-bootstrap/bootstrap/x86_64/settings    |  32 ++++
 testing/ghc/APKBUILD                               | 105 +++++++++++++
 testing/llvm3.7/APKBUILD                           | 172 +++++++++++++++++++++
 ...Add-Musl-MuslEABI-and-Musl-EABIHF-triples.patch | 112 ++++++++++++++
 .../llvm-0002-Fix-build-with-musl-libc.patch       |  35 +++++
 testing/llvm3.7/llvm-0002-musl-triple.patch        |  90 +++++++++++
 ...ix-DynamicLibrary-to-build-with-musl-libc.patch |  33 ++++
 testing/llvm3.7/llvm-0003-musl-hacks.patch         | 114 ++++++++++++++
 testing/llvm3.7/llvm-nm-workaround.patch           |  27 ++++
 testing/stack/APKBUILD                             |  39 +++++
 20 files changed, 1535 insertions(+)
 create mode 100644 testing/cabal/APKBUILD
 create mode 100644 testing/cabal/cabal-0001-force-ld.gold.patch
 create mode 100755 testing/ghc-bootstrap/APKBUILD
 create mode 100644 testing/ghc-bootstrap/bootstrap/armhf/Dockerfile
 create mode 100644 testing/ghc-bootstrap/bootstrap/armhf/bootstrap.patch
 create mode 100644 testing/ghc-bootstrap/bootstrap/armhf/settings
 create mode 100644 testing/ghc-bootstrap/bootstrap/gmpurl.patch
 create mode 100755 testing/ghc-bootstrap/bootstrap/llvm-3.7.1.sh
 create mode 100644 testing/ghc-bootstrap/bootstrap/x86_64/Dockerfile
 create mode 100644 testing/ghc-bootstrap/bootstrap/x86_64/bootstrap.patch
 create mode 100644 testing/ghc-bootstrap/bootstrap/x86_64/settings
 create mode 100755 testing/ghc/APKBUILD
 create mode 100755 testing/llvm3.7/APKBUILD
 create mode 100644 testing/llvm3.7/llvm-0001-Add-Musl-MuslEABI-and-Musl-EABIHF-triples.patch
 create mode 100644 testing/llvm3.7/llvm-0002-Fix-build-with-musl-libc.patch
 create mode 100644 testing/llvm3.7/llvm-0002-musl-triple.patch
 create mode 100644 testing/llvm3.7/llvm-0003-Fix-DynamicLibrary-to-build-with-musl-libc.patch
 create mode 100644 testing/llvm3.7/llvm-0003-musl-hacks.patch
 create mode 100644 testing/llvm3.7/llvm-nm-workaround.patch
 create mode 100755 testing/stack/APKBUILD

-- 
2.8.0

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---

---

From: Mitch Tishmack <[email-masked]>
Date: Thu, 14 Jul 2016 21:53:20 -0500

---
 testing/ghc-bootstrap/APKBUILD                     |  50 +++++++
 testing/ghc-bootstrap/bootstrap/armhf/Dockerfile   | 154 +++++++++++++++++++++
 .../ghc-bootstrap/bootstrap/armhf/bootstrap.patch  | 112 +++++++++++++++
 testing/ghc-bootstrap/bootstrap/armhf/settings     |  32 +++++
 testing/ghc-bootstrap/bootstrap/gmpurl.patch       |  22 +++
 testing/ghc-bootstrap/bootstrap/llvm-3.7.1.sh      |  88 ++++++++++++
 testing/ghc-bootstrap/bootstrap/x86_64/Dockerfile  | 143 +++++++++++++++++++
 .../ghc-bootstrap/bootstrap/x86_64/bootstrap.patch | 112 +++++++++++++++
 testing/ghc-bootstrap/bootstrap/x86_64/settings    |  32 +++++
 9 files changed, 745 insertions(+)
 create mode 100755 testing/ghc-bootstrap/APKBUILD
 create mode 100644 testing/ghc-bootstrap/bootstrap/armhf/Dockerfile
 create mode 100644 testing/ghc-bootstrap/bootstrap/armhf/bootstrap.patch
 create mode 100644 testing/ghc-bootstrap/bootstrap/armhf/settings
 create mode 100644 testing/ghc-bootstrap/bootstrap/gmpurl.patch
 create mode 100755 testing/ghc-bootstrap/bootstrap/llvm-3.7.1.sh
 create mode 100644 testing/ghc-bootstrap/bootstrap/x86_64/Dockerfile
 create mode 100644 testing/ghc-bootstrap/bootstrap/x86_64/bootstrap.patch
 create mode 100644 testing/ghc-bootstrap/bootstrap/x86_64/settings

diff --git a/testing/ghc-bootstrap/APKBUILD b/testing/ghc-bootstrap/APKBUILD
new file mode 100755
index 0000000..85af90f
--- /dev/null
+++ b/testing/ghc-bootstrap/APKBUILD
@@ -0,0 +1,50 @@
+#-*-mode: Shell-script; coding: utf-8;-*-
+# Maintainer: Mitch Tishmack <[email-masked]>
+#
+# Build/bootstrap ghc similarly to the go package.
+# Caveat: bootstrapping isn't a commonly tested piece of ghc.
+pkgname=ghc-bootstrap
+pkgdesc="The Glasgow haskell compiler (bootstrapped)"
+apkgver=8.0
+pkgrel=0
+pkgver=$(echo ${apkgver} | tr -d '[a-z]')
+url="http://haskell.org"
+subpackages=""
+arch="x86_64 armhf"
+source="
+	https://mitchty.net/ghc/8.0.1/ghc-8.0.1-x86_64-unknown-linux-musl.tar.xz
+	https://mitchty.net/ghc/8.0.1/ghc-8.0.1-arm-unknown-linux-musleabihf.tar.xz
+"
+license="custom:bsd3"
+depends="bash libffi musl zlib gcc binutils-gold llvm3.7"
+install=""
+subpackages=""
+makedepends=""
+
+package() {
+	cd "$srcdir/$CARCH"
+	install -d "$pkgdir" || return 1
+	mv usr "$pkgdir" || return 1
+	settings=$(find "$pkgdir" -name settings -type f)
+}
+
+# The bootstrap process uses docker to build ghc from a debian glibc host
+# then upload the bootstrap compiler to where that source url is.
+#
+# Ensure that docker is running prior to calling this.
+#
+# Note, these docker images are large, ~10G the dockerfiles weren't built
+# to be small. Once built the containers should likely be removed.
+snapshot() {
+        docker build -t ghc-bootstrap:x86_64 -f bootstrap/x86_64/Dockerfile .
+        docker run -a stdout "ghc-bootstrap:x86_64" /bin/cat "/tmp/ghc-${apkgver}-x86_64-pc-linux-musl.tar.xz" > ghc-${apkgver}-x86_64-unknown-linux-musl.tar.xz
+        docker build -t ghc-bootstrap:armhf -f bootstrap/armhf/Dockerfile .
+        docker run -a stdout "ghc-bootstrap:armhf" /bin/cat "/tmp/ghc-${apkgver}-arm-unknown-linux-musleabihf.tar.xz" > ghc-${apkgver}-arm-unknown-linux-musleabihf.tar.xz
+	scp "ghc-$pkgver-*-unknown-linux-musl*.tar.xz" dev.alpinelinux.org:/archive/ghc-bootstrap/ || return 1
+}
+md5sums="866b70400314dca48fcd9325a4f196aa  ghc-8.0.1-x86_64-unknown-linux-musl.tar.xz
+ade64136d1603333fdc3cb269c2335b2  ghc-8.0.1-arm-unknown-linux-musleabihf.tar.xz"
+sha256sums="11b3975a2bb7422d3c0d359597da8ea613b4ab6bd580c19b7afc0b513d547c4b  ghc-8.0.1-x86_64-unknown-linux-musl.tar.xz
+93d023aab2547480c22d5952652388a523ca98581176bc2f65c0d9a394b57a6d  ghc-8.0.1-arm-unknown-linux-musleabihf.tar.xz"
+sha512sums="b51fd2badc2ec1f8ad438476824c56e0b5417b87989bdf6813cb629c0c977aad7618a0bc6cdec8a27735afff8ec89e0a463936e6d225420b924fc0ec19aa412a  ghc-8.0.1-x86_64-unknown-linux-musl.tar.xz
+53e5caec5d218e75798a72b30201e8c0a6ba1a333406d217c7153f7f9b0585105e1862b1bb50617673a5d4ea86252c2f803989b642a46c1a853098f334f22470  ghc-8.0.1-arm-unknown-linux-musleabihf.tar.xz"
diff --git a/testing/ghc-bootstrap/bootstrap/armhf/Dockerfile b/testing/ghc-bootstrap/bootstrap/armhf/Dockerfile
new file mode 100644
index 0000000..2ef2572
--- /dev/null
+++ b/testing/ghc-bootstrap/bootstrap/armhf/Dockerfile
@@ -0,0 +1,154 @@
+# Mostly self contained setup to build a stage2 ghc for musl
+from debian:8.0
+
+# Install stock bindist for cross compile
+env ghc 7.10.3
+env arch x86_64
+env llvm 3.7.1
+env cabal 1.22.9.0
+
+# all needed packages for compiling
+run apt-get clean && \
+    apt-get update && \
+    apt-get install -y \
+      binutils-gold \
+      musl-tools \
+      build-essential \
+      wget \
+      curl \
+      libncurses-dev \
+      autoconf \
+      elfutils \
+      libgmp-dev \
+      zlib1g-dev \
+      git \
+      libtool \
+      pkg-config \
+      libffi-dev \
+      cmake \
+      g++ \
+      python \
+      pixz \
+      openssl \
+      bison \
+      flex \
+      git
+
+add http://llvm.org/releases/$llvm/llvm-$llvm.src.tar.xz /tmp/
+add http://llvm.org/releases/$llvm/polly-$llvm.src.tar.xz /tmp/
+
+# Install a non ancient version of llvm on debian, I'm purposefully ignoring
+# debian repos in favor of compiling to not have to deal with
+# "what debian upstream has a current version of llvm" nonsense, takes more
+# time to do that than just build the right llvm from source.
+workdir /tmp
+copy bootstrap/llvm-$llvm.sh /tmp/llvm.sh
+run openssl sha1 llvm-$llvm.src.tar.xz | grep "SHA1(llvm-3.7.1.src.tar.xz)= 5dbdcafac105273dcbff94c68837a66c6dd78cef" && \
+    openssl sha1 polly-$llvm.src.tar.xz | grep "SHA1(polly-3.7.1.src.tar.xz)= 0e3a461907cde7505fbdb44bf61ff318aa9254f7" && \
+    tar xJpf /tmp/llvm-$llvm.src.tar.xz && \
+    tar xJpf /tmp/polly-$llvm.src.tar.xz && \
+    /tmp/llvm.sh && \
+    rm -fr /tmp/llvm-$llvm.src
+
+add https://downloads.haskell.org/~ghc/$ghc/ghc-$ghc-$arch-deb8-linux.tar.xz /tmp/
+
+# Install debian ghc binary from upstream.
+workdir /tmp
+run openssl sha1 ghc-$ghc-$arch-deb8-linux.tar.xz | grep "SHA1(ghc-7.10.3-x86_64-deb8-linux.tar.xz)= bab16f95ef4fe6b7cc2fb6b36a02dceeeb53faa4" && \
+    tar xJpf /tmp/ghc-$ghc-$arch-deb8-linux.tar.xz
+workdir /tmp/ghc-$ghc
+run ./configure --prefix=/usr && \
+    make -j1 install && \
+    rm -fr /tmp/ghc-$ghc
+
+add https://www.haskell.org/cabal/release/cabal-install-$cabal/cabal-install-$cabal.tar.gz /tmp/
+
+# Install cabal so we can install alex/happy to pull off of git
+# bootstrap cabal and install alex/happy the same way apks are built
+# only globally
+workdir /tmp
+run openssl sha1 cabal-install-$cabal.tar.gz | grep "SHA1(cabal-install-1.22.9.0.tar.gz)= f1375c928794f45f253b8ec92c2af4732fec597b" && \
+    tar xzpf /tmp/cabal-install-$cabal.tar.gz
+workdir /tmp/cabal-install-$cabal
+run ./bootstrap.sh --global --no-doc && \
+    cabal update && \
+    cabal install --global alex happy && \
+    rm -fr /tmp/cabal-install-$cabal
+
+# First up, install/compile the cross compiler with musl libc
+# armv7 hard float cross compiler, we basically rebuild ghc again here with
+# the cross compiler, and the llvm we built for x86_64 as well
+workdir /tmp
+run git clone --depth 1 https://github.com/GregorR/musl-cross.git musl-cross
+workdir /tmp/musl-cross
+run echo GCC_BUILTIN_PREREQS=yes >> config.sh && \
+    echo ARCH=arm >> config.sh && \
+    echo TRIPLE=arm-linux-musleabihf >> config.sh && \
+    echo GCC_BOOTSTRAP_CONFFLAGS=\"--with-arch=armv6 --with-float=hard --with-fpu=vfp\" >> config.sh && \
+    echo GCC_CONFFLAGS=\"--with-arch=armv6 --with-float=hard --with-fpu=vfp\" >> config.sh && \
+    echo GCC_STAGE1_NOOPT=1 >> config.sh && \
+    echo CC_BASE_PREFIX=/usr >> config.sh && \
+    echo MAKEFLAGS=-j$(grep -c processor /proc/cpuinfo) >> config.sh && \
+    echo "BINUTILS_CONFFLAGS='CXXFLAGS=-fpermissive --enable-gold --enable-plugins --disable-werror'" >> config.sh && \
+    echo "CFLAGS='-g -O2 -fPIC -DPIC'" >> config.sh && \
+    echo "CPPFLAGS='-fPIC -DPIC'" >> config.sh && \
+    echo "LDFLAGS='-fPIC -DPIC'" >> config.sh
+copy bootstrap/gmpurl.patch gmpurl.patch
+run patch -p1 < gmpurl.patch && \
+    ./build.sh && \
+    rm -fr /tmp/musl-cross
+
+add http://downloads.haskell.org/~ghc/8.0.1/ghc-8.0.1-src.tar.xz /tmp/
+
+env tardir /tmp/root
+env destdir /tmp/root/armhf
+env crosscc arm-linux-musleabihf-gcc
+env target arm-linux-musleabihf
+env triple arm-unknown-linux-musleabihf
+env ghc 8.0.1  
+
+# add cross toolchain to PATH
+env PATH /usr/$target/bin:$PATH
+
+workdir /tmp
+run openssl sha1 ghc-$ghc-src.tar.xz | grep "SHA1(ghc-8.0.1-src.tar.xz)= 585a2d34a17ce2452273147f2e3cef1a2efe1aa5" && \
+    tar xJpf /tmp/ghc-$ghc-src.tar.xz
+workdir /tmp/ghc-$ghc
+env PATH $PATH:/usr/$triple/bin  
+copy bootstrap/$arch/bootstrap.patch bootstrap.patch  
+run patch -p1 < bootstrap.patch  
+run cp mk/build.mk.sample mk/build.mk && \  
+    ./boot && \  
+    echo "BuildFlavour         = quick-llvm" >> mk/build.mk && \  
+    echo "INTEGER_LIBRARY      = integer-simple" >> mk/build.mk && \  
+    echo "HADDOCK_DOCS         = NO" >> mk/build.mk && \  
+    echo "BUILD_SPHINX_HTML    = NO" >> mk/build.mk && \  
+    echo "BUILD_SPHINX_PS      = NO" >> mk/build.mk && \  
+    echo "BUILD_SPHINX_PDF     = NO" >> mk/build.mk && \  
+    ./configure \  
+  --target=$target \  
+  --prefix=/usr  
+run make -j$(grep -c processor /proc/cpuinfo) || make -j1  
+run make -j1 install STRIP_CMD=$target-strip DESTDIR=$destdir
+  
+# unlit and hp2ps both build using the stage0, not having luck
+# getting the build patched right so for now lets just
+# remove and rebuild these c helper programs
+run rm $(find $destdir -name "*-hp2ps")
+
+# remove target prefix from stage2 binaries
+# HACK, just build unlit with the cross compiler and move it to /usr/bin in the install dir
+workdir /tmp/ghc-$ghc/utils/unlit
+run $crosscc unlit.c -o $(find $destdir -name unlit)
+
+# remove target prefix from stage2 binaries
+workdir $destdir/usr/bin
+run (for i in $triple-* ; do ln -s $i ${i#$triple-} || /bin/true ; done )
+copy bootstrap/armhf/settings /tmp/settings
+run mv /tmp/settings $(find $destdir -name settings -type f)
+run rm -fr $destdir/usr/share/doc
+
+workdir $tardir
+# Compress to xz via pixz because xz is normally too
+# old for -TN multithreads
+run tar -I'pixz -9' -cf /tmp/ghc-$ghc-$triple.tar.xz .
diff --git a/testing/ghc-bootstrap/bootstrap/armhf/bootstrap.patch b/testing/ghc-bootstrap/bootstrap/armhf/bootstrap.patch
new file mode 100644
index 0000000..7e5fc95
--- /dev/null
+++ b/testing/ghc-bootstrap/bootstrap/armhf/bootstrap.patch
@@ -0,0 +1,112 @@
+diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
+index fa1141e..6ff2ac4 100644
+--- a/compiler/main/DynFlags.hs
++++ b/compiler/main/DynFlags.hs
+@@ -2448,8 +2448,7 @@ dynamic_flags_deps = [
+   , make_ord_flag defGhcFlag "dynload"            (hasArg parseDynLibLoaderMode)
+   , make_ord_flag defGhcFlag "dylib-install-name" (hasArg setDylibInstallName)
+     -- -dll-split is an internal flag, used only during the GHC build
+-  , make_ord_flag defHiddenFlag "dll-split"
+-      (hasArg (\f d -> d { dllSplitFile = Just f, dllSplit = Nothing }))
++  , make_ord_flag defHiddenFlag "dll-split"       (NoArg (addWarn "ignoring -dll-split"))
+ 
+         ------- Libraries ---------------------------------------------------
+   , make_ord_flag defFlag "L"   (Prefix addLibraryPath)
+diff --git a/ghc.mk b/ghc.mk
+index 5e4ecc6..a07ff73 100644
+--- a/ghc.mk
++++ b/ghc.mk
+@@ -433,7 +433,7 @@ else # CLEANING
+ PACKAGES_STAGE0 = binary Cabal/Cabal hpc ghc-boot hoopl transformers template-haskell
+ ifeq "$(Windows_Host)" "NO"
+ ifneq "$(HostOS_CPP)" "ios"
+-PACKAGES_STAGE0 += terminfo
++PACKAGES_STAGE0 +=
+ endif
+ endif
+ 
+@@ -471,7 +471,7 @@ endif
+ 
+ ifeq "$(Windows_Target)" "NO"
+ ifneq "$(TargetOS_CPP)" "ios"
+-PACKAGES_STAGE1 += terminfo
++PACKAGES_STAGE1 +=
+ endif
+ endif
+ PACKAGES_STAGE1 += haskeline
+@@ -968,8 +968,8 @@ INSTALLED_PACKAGE_CONF=$(DESTDIR)$(topdir)/package.conf.d
+ # Install packages in the right order, so that ghc-pkg doesn't complain.
+ # Also, install ghc-pkg first.
+ ifeq "$(Windows_Host)" "NO"
+-INSTALLED_GHC_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc
+-INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc-pkg
++INSTALLED_GHC_REAL=$(CURDIR)/inplace/bin/ghc-stage1
++INSTALLED_GHC_PKG_REAL=$(CURDIR)/utils/ghc-pkg/dist/build/tmp/ghc-pkg
+ else
+ INSTALLED_GHC_REAL=$(DESTDIR)$(bindir)/ghc.exe
+ INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(bindir)/ghc-pkg.exe
+diff --git a/rules/build-package-way.mk b/rules/build-package-way.mk
+index 905b7f0..3e23b1f 100644
+--- a/rules/build-package-way.mk
++++ b/rules/build-package-way.mk
+@@ -62,17 +62,6 @@ $1_$2_$3_ALL_OBJS = $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_NON_HS_OBJS)
+ 
+ ifeq "$3" "dyn"
+ 
+-ifneq "$$($1_$2_dll0_MODULES)" ""
+-$$($1_$2_$3_LIB)  : $1/$2/dll-split.stamp
+-ifneq "$$($1_$2_$3_LIB0)" ""
+-$$($1_$2_$3_LIB0) : $1/$2/dll-split.stamp
+-endif
+-endif
+-
+-$1/$2/dll-split.stamp: $$($1_$2_depfile_haskell) $$$$(dll-split_INPLACE)
+-	$$(dll-split_INPLACE) $$< "$$($1_$2_dll0_START_MODULE)" "$$($1_$2_dll0_MODULES)"
+-	touch $$@
+-
+ # Link a dynamic library
+ # On windows we have to supply the extra libs this one links to when building it.
+ ifeq "$$(HostOS_CPP)" "mingw32"
+diff --git a/rules/distdir-way-opts.mk b/rules/distdir-way-opts.mk
+index f099d4e..6dcf911 100644
+--- a/rules/distdir-way-opts.mk
++++ b/rules/distdir-way-opts.mk
+@@ -160,13 +160,6 @@ $1_$2_$3_ALL_HC_OPTS = \
+  $$(if $$(findstring YES,$$($1_$2_SplitSections)),$$(if $$(findstring dyn,$3),,-split-sections),) \
+  $$(if $$(findstring YES,$$($1_$2_DYNAMIC_TOO)),$$(if $$(findstring v,$3),-dynamic-too))
+ 
+-ifeq "$3" "dyn"
+-ifeq "$$(HostOS_CPP)" "mingw32"
+-ifneq "$$($1_$2_dll0_MODULES)" ""
+-$1_$2_$3_ALL_HC_OPTS += -dll-split $1/$2/dll-split
+-endif
+-endif
+-endif
+ 
+ $1_$2_$3_ALL_CC_OPTS = \
+  $$(WAY_$3_CC_OPTS) \
+diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs
+index af3032d..1c38e8e 100644
+--- a/utils/ghc-pkg/Main.hs
++++ b/utils/ghc-pkg/Main.hs
+@@ -1,5 +1,6 @@
+ {-# LANGUAGE CPP, TypeSynonymInstances, FlexibleInstances #-}
+ {-# OPTIONS_GHC -fno-warn-orphans #-}
++#define BOOTSTRAPPING
+ -----------------------------------------------------------------------------
+ --
+ -- (c) The University of Glasgow 2004-2009.
+diff --git a/utils/ghc-pkg/ghc-pkg.cabal b/utils/ghc-pkg/ghc-pkg.cabal
+index 5f76e1b..2f9b558 100644
+--- a/utils/ghc-pkg/ghc-pkg.cabal
++++ b/utils/ghc-pkg/ghc-pkg.cabal
+@@ -31,7 +31,7 @@ Executable ghc-pkg
+                    ghc-boot,
+                    bytestring
+     if !os(windows)
+-        Build-Depends: unix,
+-                       terminfo
++        Build-Depends: unix
++
+     if os(windows)
+         c-sources: CRT_noglob.c
diff --git a/testing/ghc-bootstrap/bootstrap/armhf/settings b/testing/ghc-bootstrap/bootstrap/armhf/settings
new file mode 100644
index 0000000..549d03d
--- /dev/null
+++ b/testing/ghc-bootstrap/bootstrap/armhf/settings
@@ -0,0 +1,32 @@
+[("GCC extra via C opts", " -fwrapv -fno-builtin"),
+ ("C compiler command", "gcc"),
+ ("C compiler flags", " -marm -fno-stack-protector"),
+ ("C compiler link flags", " --no-pie -fuse-ld=gold -Wl,-z,noexecstack"),
+ ("Haskell CPP command","gcc"),
+ ("Haskell CPP flags","-E -undef -traditional"),
+ ("ld command", "ld.gold"),
+ ("ld flags", " -z noexecstack"),
+ ("ld supports compact unwind", "YES"),
+ ("ld supports build-id", "YES"),
+ ("ld supports filelist", "NO"),
+ ("ld is GNU ld", "YES"),
+ ("ar command", "ar"),
+ ("ar flags", "q"),
+ ("ar supports at file", "YES"),
+ ("touch command", "touch"),
+ ("dllwrap command", "/bin/false"),
+ ("windres command", "/bin/false"),
+ ("libtool command", "libtool"),
+ ("perl command", "/usr/bin/perl"),
+ ("cross compiling", "YES"),
+ ("target os", "OSLinux"),
+ ("target arch", "ArchARM {armISA = ARMv6, armISAExt = [VFPv2], armABI = HARD}"),
+ ("target word size", "4"),
+ ("target has GNU nonexec stack", "False"),
+ ("target has .ident directive", "True"),
+ ("target has subsections via symbols", "False"),
+ ("Unregisterised", "NO"),
+ ("LLVM llc command", "llc-3.7"),
+ ("LLVM opt command", "opt-3.7")
+ ]
+
diff --git a/testing/ghc-bootstrap/bootstrap/gmpurl.patch b/testing/ghc-bootstrap/bootstrap/gmpurl.patch
new file mode 100644
index 0000000..c919fa3
--- /dev/null
+++ b/testing/ghc-bootstrap/bootstrap/gmpurl.patch
@@ -0,0 +1,22 @@
+diff -r d72695b410e3 defs.sh
+--- a/defs.sh   Sun Jul 26 15:38:58 2015 -0400
++++ b/defs.sh   Sun Jan 31 23:18:18 2016 +0000
+@@ -221,7 +221,7 @@
+ gccprereqs() {
+     if [ ! -e gcc-$GCC_VERSION/gmp ]
+     then
+-        fetchextract http://gmplib.org/download/gmp/ gmp-$GMP_VERSION .tar.bz2
++        fetchextract http://gmplib.org/download/gmp/archive/ gmp-$GMP_VERSION .tar.bz2
+         mv gmp-$GMP_VERSION gcc-$GCC_VERSION/gmp
+     fi
+
+--- a/extra/build-gcc-deps.sh   Sun Jul 26 15:38:58 2015 -0400
++++ b/extra/build-gcc-deps.sh   Sun Jan 31 23:18:18 2016 +0000
+@@ -28,7 +28,7 @@
+ PREFIX="$CC_PREFIX/$TRIPLE"
+
+ # GMP
+-fetchextract ftp://ftp.gmplib.org/pub/gmp-$GMP_VERSION/ gmp-$GMP_VERSION .tar.bz2
++fetchextract ftp://ftp.gmplib.org/pub/archive/gmp-$GMP_VERSION/ gmp-$GMP_VERSION .tar.bz2
+ cp -f "$MUSL_CC_BASE/extra/config.sub" gmp-$GMP_VERSION/configfsf.sub
+ buildinstall '' gmp-$GMP_VERSION --host="$TRIPLE" --enable-static --disable-shared
diff --git a/testing/ghc-bootstrap/bootstrap/llvm-3.7.1.sh b/testing/ghc-bootstrap/bootstrap/llvm-3.7.1.sh
new file mode 100755
index 0000000..49e44df
--- /dev/null
+++ b/testing/ghc-bootstrap/bootstrap/llvm-3.7.1.sh
@@ -0,0 +1,88 @@
+#!/usr/bin/env sh
+#-*-mode: Shell-script; coding: utf-8;-*-
+export script=$(basename "$0")
+export dir=$(cd "$(dirname "$0")"; pwd)
+export iam=${dir}/${script}
+llvm_major=3.7
+llvm_version=${llvm_major}.1
+llvm_srcdir="/tmp/llvm-${llvm_version}.src"
+suffix="-${llvm_major}"
+llvm_builddir=/tmp/build
+polly_orig_srcdir="/tmp/polly-$llvm_version.src"
+
+cd "$llvm_srcdir"
+
+_cmake_flags="\
+	-DCMAKE_BUILD_TYPE=Release \
+	-DCMAKE_VERBOSE_MAKEFILE=NO \
+	-DLLVM_BINUTILS_INCDIR=/usr/include \
+	-DLLVM_ENABLE_ASSERTIONS=NO \
+	-DLLVM_ENABLE_LIBCXX=NO \
+	-DLLVM_ENABLE_PIC=YES \
+	-DLLVM_ENABLE_ZLIB=YES \
+	-DLLVM_ENABLE_RTTI=YES \
+	-DLLVM_BUILD_EXAMPLES=NO \
+	-DLLVM_INCLUDE_EXAMPLES=NO \
+	-DLIBXML2_INCLUDE_DIR=/usr/include/libxml2 \
+	-DCMAKE_INSTALL_PREFIX=/usr \
+	-DLLVM_TARGETS_TO_BUILD='all' \
+	-DLLVM_BUILD_EXTERNAL_COMPILER_RT=NO \
+	-DBUILD_SHARED_LIBS=NO \
+	-DLLVM_BUILD_DOCS=NO \
+	-DLLVM_BUILD_TESTS=NO \
+	-DLLVM_ENABLE_CXX1Y=NO \
+	-DLLVM_ENABLE_FFI=YES \
+	-DLLVM_ENABLE_SPHINX=NO \
+	-DLLVM_ENABLE_TERMINFO=NO \
+	-DLLVM_ENABLE_CURSES=NO \
+	-DWITH_POLLY=YES \
+	-DLLVM_INCLUDE_EXAMPLES=NO \
+	-DLLVM_INCLUDE_TESTS=NO \
+	"
+srcdir_polly="$llvm_srcdir"/tools/polly
+mv /tmp/polly-$llvm_version.src "$srcdir_polly" || return 1
+
+(
+	OCFLAGS="${CFLAGS}"
+	OCXXFLAGS="${CXXFLAGS}"
+	unset CFLAGS
+	unset CXXFLAGS
+
+	test -z "${OCFLAGS}" && OCFLAGS="-O3"
+	test -z "${OCXXFLAGS}" && OCXXFLAGS="-O3"
+
+	cflags="${OCFLAGS} -DNDEBUG -I$srcdir/tmp/include"
+	cxxflags="${OCXXFLAGS} -DNDEBUG -fno-devirtualize"
+
+	export CC=gcc
+	export CXX=g++
+
+	ffi_include_dir="$(pkg-config --cflags-only-I libffi | sed 's|^-I||g')"
+
+	cflags="${OCFLAGS} -DNDEBUG"
+	cxxflags="${OCXXFLAGS} -DNDEBUG"
+
+	mkdir -p "${llvm_builddir}"
+	cd "${llvm_builddir}"
+	cmake -G "Unix Makefiles" -Wno-dev ${_cmake_final_flags} \
+			  -DCMAKE_C_COMPILER="${CC}" \
+			  -DCMAKE_CXX_COMPILER="${CXX}" \
+			  -DCMAKE_C_FLAGS_RELEASE="${cflags}" \
+			  -DCMAKE_CXX_FLAGS_RELEASE="${cxxflags}" \
+			  -DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS} -L$srcdir/tmp/lib" \
+			  -DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}" \
+			  -DFFI_INCLUDE_DIR="$ffi_include_dir" \
+			  -DCMAKE_PREFIX_PATH="$srcdir/tmp" \
+			  "${llvm_srcdir}" || return 1
+
+	(
+		export LD_LIBRARY_PATH="$srcdir/tmp/lib:$LD_LIBRARY_PATH"
+		make -j$(grep -c processor /proc/cpuinfo) llvm-tblgen || return 1
+		make -j$(grep -c processor /proc/cpuinfo) || return 1
+	) || return 1
+	export CFLAGS="${OCFLAGS}"
+	export CXXFLAGS="${OCXXFLAGS}"
+
+	# install portion
+	make -j1 install || return 1
+) || return 1
diff --git a/testing/ghc-bootstrap/bootstrap/x86_64/Dockerfile b/testing/ghc-bootstrap/bootstrap/x86_64/Dockerfile
new file mode 100644
index 0000000..9ca75c6
--- /dev/null
+++ b/testing/ghc-bootstrap/bootstrap/x86_64/Dockerfile
@@ -0,0 +1,143 @@
+# Mostly self contained setup to build a stage2 ghc for musl
+from debian:8.0
+
+# Install stock bindist for cross compile
+env ghc 7.10.3
+env arch x86_64
+env llvm 3.7.1
+env cabal 1.22.9.0
+
+# all needed packages for compiling
+run apt-get clean && \
+    apt-get update && \
+    apt-get install -y \
+      binutils-gold \
+      musl-tools \
+      build-essential \
+      wget \
+      curl \
+      libncurses-dev \
+      autoconf \
+      elfutils \
+      libgmp-dev \
+      zlib1g-dev \
+      git \
+      libtool \
+      pkg-config \
+      libffi-dev \
+      cmake \
+      g++ \
+      python \
+      pixz \
+      openssl \
+      git \
+      bison \
+      flex
+
+add http://llvm.org/releases/$llvm/llvm-$llvm.src.tar.xz /tmp/
+add http://llvm.org/releases/$llvm/polly-$llvm.src.tar.xz /tmp/
+
+# Install a non ancient version of llvm on debian, I'm purposefully ignoring
+# debian repos in favor of compiling to not have to deal with
+# "what debian upstream has a current version of llvm" nonsense, takes more
+# time to do that than just build the right llvm from source.
+workdir /tmp
+copy bootstrap/llvm-$llvm.sh /tmp/llvm.sh
+run openssl sha1 llvm-$llvm.src.tar.xz | grep "SHA1(llvm-3.7.1.src.tar.xz)= 5dbdcafac105273dcbff94c68837a66c6dd78cef" && \
+    openssl sha1 polly-$llvm.src.tar.xz | grep "SHA1(polly-3.7.1.src.tar.xz)= 0e3a461907cde7505fbdb44bf61ff318aa9254f7" && \
+    tar xJpf /tmp/llvm-$llvm.src.tar.xz && \
+    tar xJpf /tmp/polly-$llvm.src.tar.xz && \
+    /tmp/llvm.sh && \
+    rm -fr /tmp/llvm-$llvm.src /tmp/build
+
+add https://downloads.haskell.org/~ghc/$ghc/ghc-$ghc-$arch-deb8-linux.tar.xz /tmp/
+
+# Install debian ghc binary from upstream.
+workdir /tmp
+run openssl sha1 ghc-$ghc-$arch-deb8-linux.tar.xz | grep "SHA1(ghc-7.10.3-x86_64-deb8-linux.tar.xz)= bab16f95ef4fe6b7cc2fb6b36a02dceeeb53faa4" && \
+    tar xJpf /tmp/ghc-$ghc-$arch-deb8-linux.tar.xz
+workdir /tmp/ghc-$ghc
+run ./configure --prefix=/usr && \
+    make -j1 install && \
+    rm -fr /tmp/ghc-$ghc
+
+add https://www.haskell.org/cabal/release/cabal-install-$cabal/cabal-install-$cabal.tar.gz /tmp/
+
+# Install cabal so we can install alex/happy to pull off of git
+# bootstrap cabal and install alex/happy the same way apks are built
+# only globally
+workdir /tmp
+run openssl sha1 cabal-install-$cabal.tar.gz | grep "SHA1(cabal-install-1.22.9.0.tar.gz)= f1375c928794f45f253b8ec92c2af4732fec597b" && \
+    tar xzpf /tmp/cabal-install-$cabal.tar.gz
+workdir /tmp/cabal-install-$cabal
+run ./bootstrap.sh --global --no-doc && \
+    cabal update && \
+    cabal install --global alex happy && \
+    rm -fr /tmp/cabal-install-$cabal
+
+# Build our cross compiler with musl libc from the sabotage linux stuff
+workdir /tmp
+run git clone --depth 1 https://github.com/GregorR/musl-cross.git musl-cross
+workdir /tmp/musl-cross
+run echo GCC_BUILTIN_PREREQS=yes >> config.sh && \
+    echo ARCH=x86_64 >> config.sh && \
+    echo TRIPLE=x86_64-pc-linux-musl >> config.sh && \
+    echo GCC_STAGE1_NOOPT=1 >> config.sh && \
+    echo CC_BASE_PREFIX=/usr >> config.sh && \
+    echo MAKEFLAGS=-j$(grep -c processor /proc/cpuinfo) >> config.sh && \
+    echo "BINUTILS_CONFFLAGS='CXXFLAGS=-fpermissive --enable-gold --enable-plugins --disable-werror'" >> config.sh && \
+    echo "CFLAGS='-g -O2 -fPIC -DPIC'" >> config.sh && \
+    echo "CPPFLAGS='-fPIC -DPIC'" >> config.sh && \
+    echo "LDFLAGS='-fPIC -DPIC'" >> config.sh
+copy bootstrap/gmpurl.patch gmpurl.patch
+run patch -p1 < gmpurl.patch && \
+    ./build.sh && \
+    rm -fr /tmp/musl-cross
+
+add http://downloads.haskell.org/~ghc/8.0.1/ghc-8.0.1-src.tar.xz /tmp/
+
+env tardir /tmp/root
+env destdir /tmp/root/x86_64
+env triple x86_64-pc-linux-musl
+env crosscc $triple-gcc
+env ghc 8.0.1
+
+workdir /tmp
+run openssl sha1 ghc-$ghc-src.tar.xz | grep "SHA1(ghc-8.0.1-src.tar.xz)= 585a2d34a17ce2452273147f2e3cef1a2efe1aa5" && \
+    tar xJpf /tmp/ghc-$ghc-src.tar.xz
+workdir /tmp/ghc-$ghc
+env PATH $PATH:/usr/$triple/bin
+copy bootstrap/$arch/bootstrap.patch bootstrap.patch
+run patch -p1 < bootstrap.patch
+run cp mk/build.mk.sample mk/build.mk && \
+    ./boot && \
+    echo "BuildFlavour         = quick-llvm" >> mk/build.mk && \
+    echo "INTEGER_LIBRARY      = integer-simple" >> mk/build.mk && \
+    echo "HADDOCK_DOCS         = NO" >> mk/build.mk && \
+    echo "BUILD_SPHINX_HTML    = NO" >> mk/build.mk && \
+    echo "BUILD_SPHINX_PS      = NO" >> mk/build.mk && \
+    echo "BUILD_SPHINX_PDF     = NO" >> mk/build.mk && \
+    ./configure \
+  --target=$triple \
+  --prefix=/usr
+run make -j$(grep -c processor /proc/cpuinfo) || make -j1
+run make -j1 install DESTDIR=$destdir
+
+run rm $(find $destdir -name "*-hp2ps")
+
+# remove target prefix from stage2 binaries
+# HACK, just build unlit with the cross compiler and move it to /usr/bin in the install dir
+workdir /tmp/ghc-$ghc/utils/unlit
+run $crosscc unlit.c -o $(find $destdir -name unlit)
+
+# remove target prefix from stage2 binaries
+workdir $destdir/usr/bin
+run (for i in $triple-* ; do ln -s $i ${i#$triple-} ; done )
+copy bootstrap/$arch/settings /tmp/settings
+run mv /tmp/settings $(find $destdir -name settings -type f)
+run rm -fr $destdir/usr/share/doc
+
+workdir $tardir
+# Compress to xz via pixz because xz is normally too
+# old for -TN multithreads
+run tar -I'pixz -9' -cf /tmp/ghc-$ghc-$triple.tar.xz .
diff --git a/testing/ghc-bootstrap/bootstrap/x86_64/bootstrap.patch b/testing/ghc-bootstrap/bootstrap/x86_64/bootstrap.patch
new file mode 100644
index 0000000..7e5fc95
--- /dev/null
+++ b/testing/ghc-bootstrap/bootstrap/x86_64/bootstrap.patch
@@ -0,0 +1,112 @@
+diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
+index fa1141e..6ff2ac4 100644
+--- a/compiler/main/DynFlags.hs
++++ b/compiler/main/DynFlags.hs
+@@ -2448,8 +2448,7 @@ dynamic_flags_deps = [
+   , make_ord_flag defGhcFlag "dynload"            (hasArg parseDynLibLoaderMode)
+   , make_ord_flag defGhcFlag "dylib-install-name" (hasArg setDylibInstallName)
+     -- -dll-split is an internal flag, used only during the GHC build
+-  , make_ord_flag defHiddenFlag "dll-split"
+-      (hasArg (\f d -> d { dllSplitFile = Just f, dllSplit = Nothing }))
++  , make_ord_flag defHiddenFlag "dll-split"       (NoArg (addWarn "ignoring -dll-split"))
+ 
+         ------- Libraries ---------------------------------------------------
+   , make_ord_flag defFlag "L"   (Prefix addLibraryPath)
+diff --git a/ghc.mk b/ghc.mk
+index 5e4ecc6..a07ff73 100644
+--- a/ghc.mk
++++ b/ghc.mk
+@@ -433,7 +433,7 @@ else # CLEANING
+ PACKAGES_STAGE0 = binary Cabal/Cabal hpc ghc-boot hoopl transformers template-haskell
+ ifeq "$(Windows_Host)" "NO"
+ ifneq "$(HostOS_CPP)" "ios"
+-PACKAGES_STAGE0 += terminfo
++PACKAGES_STAGE0 +=
+ endif
+ endif
+ 
+@@ -471,7 +471,7 @@ endif
+ 
+ ifeq "$(Windows_Target)" "NO"
+ ifneq "$(TargetOS_CPP)" "ios"
+-PACKAGES_STAGE1 += terminfo
++PACKAGES_STAGE1 +=
+ endif
+ endif
+ PACKAGES_STAGE1 += haskeline
+@@ -968,8 +968,8 @@ INSTALLED_PACKAGE_CONF=$(DESTDIR)$(topdir)/package.conf.d
+ # Install packages in the right order, so that ghc-pkg doesn't complain.
+ # Also, install ghc-pkg first.
+ ifeq "$(Windows_Host)" "NO"
+-INSTALLED_GHC_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc
+-INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc-pkg
++INSTALLED_GHC_REAL=$(CURDIR)/inplace/bin/ghc-stage1
++INSTALLED_GHC_PKG_REAL=$(CURDIR)/utils/ghc-pkg/dist/build/tmp/ghc-pkg
+ else
+ INSTALLED_GHC_REAL=$(DESTDIR)$(bindir)/ghc.exe
+ INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(bindir)/ghc-pkg.exe
+diff --git a/rules/build-package-way.mk b/rules/build-package-way.mk
+index 905b7f0..3e23b1f 100644
+--- a/rules/build-package-way.mk
++++ b/rules/build-package-way.mk
+@@ -62,17 +62,6 @@ $1_$2_$3_ALL_OBJS = $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_NON_HS_OBJS)
+ 
+ ifeq "$3" "dyn"
+ 
+-ifneq "$$($1_$2_dll0_MODULES)" ""
+-$$($1_$2_$3_LIB)  : $1/$2/dll-split.stamp
+-ifneq "$$($1_$2_$3_LIB0)" ""
+-$$($1_$2_$3_LIB0) : $1/$2/dll-split.stamp
+-endif
+-endif
+-
+-$1/$2/dll-split.stamp: $$($1_$2_depfile_haskell) $$$$(dll-split_INPLACE)
+-	$$(dll-split_INPLACE) $$< "$$($1_$2_dll0_START_MODULE)" "$$($1_$2_dll0_MODULES)"
+-	touch $$@
+-
+ # Link a dynamic library
+ # On windows we have to supply the extra libs this one links to when building it.
+ ifeq "$$(HostOS_CPP)" "mingw32"
+diff --git a/rules/distdir-way-opts.mk b/rules/distdir-way-opts.mk
+index f099d4e..6dcf911 100644
+--- a/rules/distdir-way-opts.mk
++++ b/rules/distdir-way-opts.mk
+@@ -160,13 +160,6 @@ $1_$2_$3_ALL_HC_OPTS = \
+  $$(if $$(findstring YES,$$($1_$2_SplitSections)),$$(if $$(findstring dyn,$3),,-split-sections),) \
+  $$(if $$(findstring YES,$$($1_$2_DYNAMIC_TOO)),$$(if $$(findstring v,$3),-dynamic-too))
+ 
+-ifeq "$3" "dyn"
+-ifeq "$$(HostOS_CPP)" "mingw32"
+-ifneq "$$($1_$2_dll0_MODULES)" ""
+-$1_$2_$3_ALL_HC_OPTS += -dll-split $1/$2/dll-split
+-endif
+-endif
+-endif
+ 
+ $1_$2_$3_ALL_CC_OPTS = \
+  $$(WAY_$3_CC_OPTS) \
+diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs
+index af3032d..1c38e8e 100644
+--- a/utils/ghc-pkg/Main.hs
++++ b/utils/ghc-pkg/Main.hs
+@@ -1,5 +1,6 @@
+ {-# LANGUAGE CPP, TypeSynonymInstances, FlexibleInstances #-}
+ {-# OPTIONS_GHC -fno-warn-orphans #-}
++#define BOOTSTRAPPING
+ -----------------------------------------------------------------------------
+ --
+ -- (c) The University of Glasgow 2004-2009.
+diff --git a/utils/ghc-pkg/ghc-pkg.cabal b/utils/ghc-pkg/ghc-pkg.cabal
+index 5f76e1b..2f9b558 100644
+--- a/utils/ghc-pkg/ghc-pkg.cabal
++++ b/utils/ghc-pkg/ghc-pkg.cabal
+@@ -31,7 +31,7 @@ Executable ghc-pkg
+                    ghc-boot,
+                    bytestring
+     if !os(windows)
+-        Build-Depends: unix,
+-                       terminfo
++        Build-Depends: unix
++
+     if os(windows)
+         c-sources: CRT_noglob.c
diff --git a/testing/ghc-bootstrap/bootstrap/x86_64/settings b/testing/ghc-bootstrap/bootstrap/x86_64/settings
new file mode 100644
index 0000000..bd33b80
--- /dev/null
+++ b/testing/ghc-bootstrap/bootstrap/x86_64/settings
@@ -0,0 +1,32 @@
+[("GCC extra via C opts", " -fwrapv -fno-builtin"),
+ ("C compiler command", "gcc"),
+ ("C compiler flags", " -fno-stack-protector"),
+ ("C compiler link flags", "--no-pie"),
+ ("Haskell CPP command","gcc"),
+ ("Haskell CPP flags","-E -undef -traditional "),
+ ("ld command", "ld.gold"),
+ ("ld flags", ""),
+ ("ld supports compact unwind", "YES"),
+ ("ld supports build-id", "YES"),
+ ("ld supports filelist", "NO"),
+ ("ld is GNU ld", "YES"),
+ ("ar command", "ar"),
+ ("ar flags", "q"),
+ ("ar supports at file", "YES"),
+ ("touch command", "touch"),
+ ("dllwrap command", "/bin/false"),
+ ("windres command", "/bin/false"),
+ ("libtool command", "libtool"),
+ ("readelf command", "readelf"),
+ ("perl command", "perl"),
+ ("cross compiling", "YES"),
+ ("target os", "OSLinux"),
+ ("target arch", "ArchX86_64"),
+ ("target word size", "8"),
+ ("target has GNU nonexec stack", "True"),
+ ("target has .ident directive", "True"),
+ ("target has subsections via symbols", "False"),
+ ("Unregisterised", "NO"),
+ ("LLVM llc command", "llc-3.7"),
+ ("LLVM opt command", "opt-3.7")
+ ]
-- 
2.8.0

---

---

From: Mitch Tishmack <[email-masked]>
Date: Thu, 14 Jul 2016 21:53:19 -0500

---
 7 files changed, 583 insertions(+)

diff --git a/testing/llvm3.7/APKBUILD b/testing/llvm3.7/APKBUILD
new file mode 100755
index 0000000..c46fb4a
--- /dev/null
+++ b/testing/llvm3.7/APKBUILD
@@ -0,0 +1,172 @@
+# Contributor Travis Tilley <[email-masked]>
+# Contributor Mitch Tishmack <[email-masked]>
+# Maintainer: Travis Tilley <[email-masked]>
+pkgname=llvm3.7
+pkgname_short=llvm
+pkgver=3.7.1
+pkgrel=0
+pkgdesc="low level virtual machine compiler system"
+arch="all"
+url="http://llvm.org/"
+license="UOI-NCSA"
+depends=""
+makedepends="$depends_dev
+	binutils-dev
+	bison
+	chrpath
+	cmake
+	flex
+	groff
+	isl-dev
+	libffi-dev
+	make
+	file
+	paxmark
+	py-sphinx
+	python
+	python-dev
+	zlib-dev
+	"
+install=
+subpackages="$pkgname-static $pkgname-libs"
+source="
+	llvm-0001-Add-Musl-MuslEABI-and-Musl-EABIHF-triples.patch
+	llvm-0002-Fix-build-with-musl-libc.patch
+	llvm-0003-Fix-DynamicLibrary-to-build-with-musl-libc.patch
+	llvm-nm-workaround.patch
+
+	http://llvm.org/releases/$pkgver/llvm-$pkgver.src.tar.xz
+	"
+
+_builddir="$srcdir"/build
+
+_cmake_common_flags="\
+"
+
+
+_srcdir="$srcdir"/"$pkgname_short-$pkgver.src"
+
+prepare() {
+	msg "Patching LLVM core..."
+	cd "$_srcdir" || return 1
+	update_config_sub || return 1
+	sed -i -e '/case "\${UNAME_MACHINE}:\${UNAME_SYSTEM}:\${UNAME_RELEASE}:\${UNAME_VERSION}" in/i \' \
+	       -e 'if [ x != "x$CBUILD" ]; then echo "$CBUILD"; exit; fi' \
+		./autoconf/config.guess || return 1
+	for i in $source; do
+		case $i in
+		llvm-*.patch)
+			msg "Applying $i..."
+			patch --ignore-whitespace -s -p1 -N -i "$srcdir"/$i || return 1
+			;;
+		esac
+	done
+	# remove some tests that fails
+	rm test/tools/llvm-objdump/macho-compact-unwind-x86_64.test \
+		test/tools/llvm-objdump/macho-compact-unwind-i386.test \
+		test/Transforms/GlobalOpt/alias-used.ll \
+		|| return 1
+}
+
+build() {
+	mkdir -p "$_builddir"
+	cd "$_builddir"
+
+	# auto-detect it by guessing either.
+	_ffi_include_dir="$(pkg-config --cflags-only-I libffi | sed 's|^-I||g')"
+
+	cmake -G "Unix Makefiles" -Wno-dev \
+		-DCMAKE_BUILD_TYPE=Release \
+		-DCMAKE_INSTALL_PREFIX=/usr \
+		-DCMAKE_VERBOSE_MAKEFILE=NO \
+		\
+		-DFFI_INCLUDE_DIR="$_ffi_include_dir" \
+		-DLLVM_BINUTILS_INCDIR=/usr/include/llvm-3.7 \
+		-DLLVM_BUILD_DOCS=YES \
+		-DLLVM_BUILD_EXAMPLES=NO \
+		-DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON \
+		-DLLVM_BUILD_LLVM_DYLIB=ON \
+		-DLLVM_BUILD_TESTS=YES \
+		-DLLVM_DEFAULT_TARGET_TRIPLE=$CBUILD \
+		-DLLVM_DYLIB_EXPORT_ALL=ON \
+		-DLLVM_ENABLE_ASSERTIONS=NO \
+		-DLLVM_ENABLE_CXX1Y=YES \
+		-DLLVM_ENABLE_FFI=YES \
+		-DLLVM_ENABLE_LIBCXX=NO \
+		-DLLVM_ENABLE_PIC=YES \
+		-DLLVM_ENABLE_RTTI=YES \
+		-DLLVM_ENABLE_SPHINX=NO \
+		-DLLVM_ENABLE_TERMINFO=YES \
+		-DLLVM_ENABLE_ZLIB=YES \
+		-DLLVM_HOST_TRIPLE=$CHOST \
+		-DLLVM_INCLUDE_EXAMPLES=NO \
+		-DLLVM_LINK_LLVM_DYLIB=ON \
+		-DLLVM_TARGETS_TO_BUILD=all \
+		\
+		-DSPHINX_WARNINGS_AS_ERRORS=NO \
+		"${_srcdir}" || return 1
+
+	make llvm-tblgen || return 1
+	make || return 1
+
+	paxmark m bin/llvm-rtdyld
+	paxmark m bin/lli
+	paxmark m bin/lli-child-target
+
+	paxmark m unittests/ExecutionEngine/MCJIT/MCJITTests
+	paxmark m unittests/Support/SupportTests
+
+
+	case "$CARCH" in
+	arm*)
+		# ARM has few failures in test suite
+		# that we don't care about currently
+		;;
+	*)
+		make check-llvm		|| return 1
+		;;
+	esac
+}
+
+package() {
+	cd "$_builddir"
+	make DESTDIR="$pkgdir" install
+	file "$pkgdir"/usr/lib/*.so | awk -F: '$2~/ELF/{print $1}' | xargs -r chrpath -d
+	file "$pkgdir"/usr/bin/* | awk -F: '$2~/ELF/{print $1}' | xargs -r chrpath -d
+	for f in $(ls -d "$pkgdir"/usr/bin/*); do
+		mv ${f} ${f}-3.7
+	done
+	mv "$pkgdir"/usr/lib/LLVMgold.so "$pkgdir"/usr/lib/LLVMgold.so.3.7
+	mv "$pkgdir"/usr/lib/libLTO.so "$pkgdir"/usr/lib/libLTO.so.3.7
+	mv "$pkgdir"/usr/lib/BugpointPasses.so "$pkgdir"/usr/lib/BugpointPasses.so.3.7
+	rm "$pkgdir"/usr/lib/libLLVM.so 
+}
+
+static() {
+	pkgdesc="LLVM static libraries"
+	mkdir -p "$subpkgdir"/usr/lib
+	mv "$pkgdir"/usr/lib/*.a "$subpkgdir"/usr/lib/
+}
+
+libs() {
+	pkgdesc="LLVM runtiem libraries"
+	mkdir -p "$subpkgdir"/usr/lib
+	mv "$pkgdir"/usr/lib/libLLVM.so.[0-9]* "$subpkgdir"/usr/lib/
+}
+
+
+md5sums="b370ea6589931c560a92699b890dd888  llvm-0001-Add-Musl-MuslEABI-and-Musl-EABIHF-triples.patch
+b0cd098117223159b76e96c3f884536b  llvm-0002-Fix-build-with-musl-libc.patch
+9cc5050619f764ca9dc842a5ab122290  llvm-0003-Fix-DynamicLibrary-to-build-with-musl-libc.patch
+785147afd8ab80fa95955a5637b6582f  llvm-nm-workaround.patch
+bf8b3a2c79e61212c5409041dfdbd319  llvm-3.7.1.src.tar.xz"
+sha256sums="6018671b549f3043ab4d7100956f0e05092d83de72b88edea199c91d5755d819  llvm-0001-Add-Musl-MuslEABI-and-Musl-EABIHF-triples.patch
+e1b0fd5f6918d8c8404f3ec4b8d3ab8fbe8dadc2d6011792349b56e5e8ee51e2  llvm-0002-Fix-build-with-musl-libc.patch
+fc28356bf0d5fcfe9b99e28f4abbc2f49f50d263b44e428e30f33bf5472747b4  llvm-0003-Fix-DynamicLibrary-to-build-with-musl-libc.patch
+1870f910a6f5f2ba6144bd079ec55ed879fe8fd8b1b1b384935f36da43e5f114  llvm-nm-workaround.patch
+be7794ed0cec42d6c682ca8e3517535b54555a3defabec83554dbc74db545ad5  llvm-3.7.1.src.tar.xz"
+sha512sums="64388ca3100fd36dfcfa7ba8ec8eb8dd40a7388d4363952ec9b4012e5b82494bd445a1b46506b479283121ec2f74fe3dc07b154f5c76db27b6f5b1af50c265aa  llvm-0001-Add-Musl-MuslEABI-and-Musl-EABIHF-triples.patch
+4cb3fabbb627b596ce398ed717c66ad20bbea7092ba30751520cc5a63d38e1ac53d23e98a6ad82121ddcf2434383ba5cadbc2990f99a4528e99c6e2160c2f725  llvm-0002-Fix-build-with-musl-libc.patch
+19bfb9282455d39d07dbb2b1293b03a45c57d522fbb9c5e58dac034200669628b97e7a90cd4ff5d52d9bb79acfccbef653d8a1140a7f0589ecd6f9b7c4ba0eb6  llvm-0003-Fix-DynamicLibrary-to-build-with-musl-libc.patch
+11db6f3c5d697bc536c7d053530f7a5572756185e16399c32c31306861b58046ca9bc14b8d8097758c00a8c1a7026cbfb75636c0e697e59c53dda5848f93b006  llvm-nm-workaround.patch
+ac521debc02f6deba96ef975d6a546b0c5c77299c1dbf5e1b87a7974ff5e7fd715bd7e384b92d9adf572ce47130bdbf6d3c648eb0d7f72f16f976292e4909e90  llvm-3.7.1.src.tar.xz"
diff --git a/testing/llvm3.7/llvm-0001-Add-Musl-MuslEABI-and-Musl-EABIHF-triples.patch b/testing/llvm3.7/llvm-0001-Add-Musl-MuslEABI-and-Musl-EABIHF-triples.patch
new file mode 100644
index 0000000..15f255a
--- /dev/null
+++ b/testing/llvm3.7/llvm-0001-Add-Musl-MuslEABI-and-Musl-EABIHF-triples.patch
@@ -0,0 +1,112 @@
+From 1cec99f6d53d442d8a8c9d2ed9f4a58f8fdc6412 Mon Sep 17 00:00:00 2001
+From: Natanael Copa <[email-masked]>
+Date: Thu, 18 Feb 2016 08:30:07 +0100
+Subject: [PATCH 1/3] Add Musl, MuslEABI and Musl EABIHF triples
+
+---
+ include/llvm/ADT/Triple.h           | 11 +++++++++++
+ lib/Support/Triple.cpp              |  7 +++++++
+ lib/Target/ARM/ARMSubtarget.h       |  3 +++
+ lib/Target/ARM/ARMTargetMachine.cpp |  2 ++
+ 4 files changed, 23 insertions(+)
+
+diff --git a/include/llvm/ADT/Triple.h b/include/llvm/ADT/Triple.h
+index e01db0a..2fc4fc1 100644
+--- a/include/llvm/ADT/Triple.h
++++ b/include/llvm/ADT/Triple.h
+@@ -174,6 +174,10 @@ public:
+     EABIHF,
+     Android,
+ 
++    Musl,
++    MuslEABI,
++    MuslEABIHF,
++
+     MSVC,
+     Itanium,
+     Cygnus,
+@@ -544,6 +548,13 @@ public:
+   /// Tests whether the target is Android
+   bool isAndroid() const { return getEnvironment() == Triple::Android; }
+ 
++  /// Tests whether the target is musl libc
++  bool isMusl() const {
++    return getEnvironment() == Triple::Musl ||
++           getEnvironment() == Triple::MuslEABI ||
++           getEnvironment() == Triple::MuslEABIHF;
++  }
++
+   /// @}
+   /// @name Mutators
+   /// @{
+diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp
+index 11afcf7..d90a06a 100644
+--- a/lib/Support/Triple.cpp
++++ b/lib/Support/Triple.cpp
+@@ -199,6 +199,9 @@ const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) {
+   case CODE16: return "code16";
+   case EABI: return "eabi";
+   case EABIHF: return "eabihf";
++  case Musl: return "musl";
++  case MuslEABIHF: return "muslgnueabihf";
++  case MuslEABI: return "muslgnueabi";
+   case Android: return "android";
+   case MSVC: return "msvc";
+   case Itanium: return "itanium";
+@@ -454,6 +457,9 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
+     .StartsWith("code16", Triple::CODE16)
+     .StartsWith("gnu", Triple::GNU)
+     .StartsWith("android", Triple::Android)
++    .StartsWith("muslgnueabihf", Triple::MuslEABIHF)
++    .StartsWith("muslgnueabi", Triple::MuslEABI)
++    .StartsWith("musl", Triple::Musl)
+     .StartsWith("msvc", Triple::MSVC)
+     .StartsWith("itanium", Triple::Itanium)
+     .StartsWith("cygnus", Triple::Cygnus)
+@@ -1431,6 +1437,7 @@ StringRef Triple::getARMCPUForArch(StringRef MArch) const {
+     switch (getEnvironment()) {
+     case llvm::Triple::EABIHF:
+     case llvm::Triple::GNUEABIHF:
++    case llvm::Triple::MuslEABIHF:
+       return "arm1176jzf-s";
+     default:
+       return "arm7tdmi";
+diff --git a/lib/Target/ARM/ARMSubtarget.h b/lib/Target/ARM/ARMSubtarget.h
+index 4d54e57..7ed7ab7 100644
+--- a/lib/Target/ARM/ARMSubtarget.h
++++ b/lib/Target/ARM/ARMSubtarget.h
+@@ -405,8 +405,10 @@ public:
+   bool isTargetEHABICompatible() const {
+     return (TargetTriple.getEnvironment() == Triple::EABI ||
+             TargetTriple.getEnvironment() == Triple::GNUEABI ||
++             TargetTriple.getEnvironment() == Triple::MuslEABI ||
+             TargetTriple.getEnvironment() == Triple::EABIHF ||
+             TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
++             TargetTriple.getEnvironment() == Triple::MuslEABIHF ||
+             TargetTriple.getEnvironment() == Triple::Android) && 
+            !isTargetDarwin() && !isTargetWindows();
+   }
+@@ -415,6 +417,7 @@ public:
+     // FIXME: this is invalid for WindowsCE
+     return TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
+            TargetTriple.getEnvironment() == Triple::EABIHF ||
++            TargetTriple.getEnvironment() == Triple::MuslEABIHF ||
+            isTargetWindows();
+   }
+   bool isTargetAndroid() const {
+diff --git a/lib/Target/ARM/ARMTargetMachine.cpp b/lib/Target/ARM/ARMTargetMachine.cpp
+index fca1901..25f5cf9 100644
+--- a/lib/Target/ARM/ARMTargetMachine.cpp
++++ b/lib/Target/ARM/ARMTargetMachine.cpp
+@@ -101,6 +101,8 @@ computeTargetABI(const Triple &TT, StringRef CPU,
+     case llvm::Triple::GNUEABIHF:
+     case llvm::Triple::EABIHF:
+     case llvm::Triple::EABI:
++    case llvm::Triple::MuslEABI:
++    case llvm::Triple::MuslEABIHF:
+       TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
+       break;
+     case llvm::Triple::GNU:
+-- 
+2.7.3
+
diff --git a/testing/llvm3.7/llvm-0002-Fix-build-with-musl-libc.patch b/testing/llvm3.7/llvm-0002-Fix-build-with-musl-libc.patch
new file mode 100644
index 0000000..1a69080
--- /dev/null
+++ b/testing/llvm3.7/llvm-0002-Fix-build-with-musl-libc.patch
@@ -0,0 +1,35 @@
+From 5c571082fdaf61f6df19d9b7137dc26d71334058 Mon Sep 17 00:00:00 2001
+From: Natanael Copa <[email-masked]>
+Date: Thu, 18 Feb 2016 10:33:04 +0100
+Subject: [PATCH 2/3] Fix build with musl libc
+
+On musl libc the fopen64 and fopen are the same thing, but for
+compatibility they have a `#define fopen64 fopen`. Same applies for
+fseek64, fstat64, fstatvfs64, ftello64, lstat64, stat64 and tmpfile64.
+---
+ include/llvm/Analysis/TargetLibraryInfo.h | 9 +++++++++
+ 1 file changed, 9 insertions(+)
+
+diff --git a/include/llvm/Analysis/TargetLibraryInfo.h b/include/llvm/Analysis/TargetLibraryInfo.h
+index 7becdf0..7f14427 100644
+--- a/include/llvm/Analysis/TargetLibraryInfo.h
++++ b/include/llvm/Analysis/TargetLibraryInfo.h
+@@ -18,6 +18,15 @@
+ #include "llvm/IR/Module.h"
+ #include "llvm/Pass.h"
+ 
++#undef fopen64
++#undef fseeko64
++#undef fstat64
++#undef fstatvfs64
++#undef ftello64
++#undef lstat64
++#undef stat64
++#undef tmpfile64
++
+ namespace llvm {
+ /// VecDesc - Describes a possible vectorization of a function.
+ /// Function 'VectorFnName' is equivalent to 'ScalarFnName' vectorized
+-- 
+2.7.3
+
diff --git a/testing/llvm3.7/llvm-0002-musl-triple.patch b/testing/llvm3.7/llvm-0002-musl-triple.patch
new file mode 100644
index 0000000..2f6fd59
--- /dev/null
+++ b/testing/llvm3.7/llvm-0002-musl-triple.patch
@@ -0,0 +1,90 @@
+From 58be6f7fb164dbf42fdd28ce6474dbe4bc5ca401 Mon Sep 17 00:00:00 2001
+From: Andrea Brancaleoni <[email-masked]>
+Date: Tue, 8 Sep 2015 21:53:42 +0200
+Subject: [PATCH 2/3] musl triple
+
+---
+ include/llvm/ADT/Triple.h           | 4 ++++
+ lib/Support/Triple.cpp              | 6 ++++++
+ lib/Target/ARM/ARMSubtarget.h       | 3 +++
+ lib/Target/ARM/ARMTargetMachine.cpp | 2 ++
+ 4 files changed, 15 insertions(+)
+
+diff --git a/include/llvm/ADT/Triple.h b/include/llvm/ADT/Triple.h
+index 947812d..d2a6bbe 100644
+--- a/include/llvm/ADT/Triple.h
++++ b/include/llvm/ADT/Triple.h
+@@ -167,6 +167,10 @@ public:
+     EABIHF,
+     Android,
+ 
++    Musl,
++    MuslEABI,
++    MuslEABIHF,
++
+     MSVC,
+     Itanium,
+     Cygnus,
+diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp
+index c6646fb..8d47ad9 100644
+--- a/lib/Support/Triple.cpp
++++ b/lib/Support/Triple.cpp
+@@ -192,6 +192,9 @@ const char *Triple::getEnvironmentTypeName(EnvironmentType Kind) {
+   case CODE16: return "code16";
+   case EABI: return "eabi";
+   case EABIHF: return "eabihf";
++  case Musl: return "musl";
++  case MuslEABIHF: return "musleabihf";
++  case MuslEABI: return "musleabi";
+   case Android: return "android";
+   case MSVC: return "msvc";
+   case Itanium: return "itanium";
+@@ -427,6 +430,9 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
+     .StartsWith("code16", Triple::CODE16)
+     .StartsWith("gnu", Triple::GNU)
+     .StartsWith("android", Triple::Android)
++    .StartsWith("musleabihf", Triple::MuslEABIHF)
++    .StartsWith("musleabi", Triple::MuslEABI)
++    .StartsWith("musl", Triple::Musl)
+     .StartsWith("msvc", Triple::MSVC)
+     .StartsWith("itanium", Triple::Itanium)
+     .StartsWith("cygnus", Triple::Cygnus)
+diff --git a/lib/Target/ARM/ARMSubtarget.h b/lib/Target/ARM/ARMSubtarget.h
+index dd101df..c5bdcca 100644
+--- a/lib/Target/ARM/ARMSubtarget.h
++++ b/lib/Target/ARM/ARMSubtarget.h
+@@ -381,8 +381,10 @@ public:
+   bool isTargetEHABICompatible() const {
+     return (TargetTriple.getEnvironment() == Triple::EABI ||
+             TargetTriple.getEnvironment() == Triple::GNUEABI ||
++            TargetTriple.getEnvironment() == Triple::MuslEABI ||
+             TargetTriple.getEnvironment() == Triple::EABIHF ||
+             TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
++            TargetTriple.getEnvironment() == Triple::MuslEABIHF ||
+             TargetTriple.getEnvironment() == Triple::Android) &&
+            !isTargetDarwin() && !isTargetWindows();
+   }
+@@ -391,6 +393,7 @@ public:
+     // FIXME: this is invalid for WindowsCE
+     return TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
+            TargetTriple.getEnvironment() == Triple::EABIHF ||
++           TargetTriple.getEnvironment() == Triple::MuslEABIHF ||
+            isTargetWindows();
+   }
+   bool isTargetAndroid() const {
+diff --git a/lib/Target/ARM/ARMTargetMachine.cpp b/lib/Target/ARM/ARMTargetMachine.cpp
+index 93495d6..56e6b7f 100644
+--- a/lib/Target/ARM/ARMTargetMachine.cpp
++++ b/lib/Target/ARM/ARMTargetMachine.cpp
+@@ -97,6 +97,8 @@ computeTargetABI(const Triple &TT, StringRef CPU,
+     case llvm::Triple::GNUEABIHF:
+     case llvm::Triple::EABIHF:
+     case llvm::Triple::EABI:
++    case llvm::Triple::MuslEABI:
++    case llvm::Triple::MuslEABIHF:
+       TargetABI = ARMBaseTargetMachine::ARM_ABI_AAPCS;
+       break;
+     case llvm::Triple::GNU:
+-- 
+2.5.1
+
diff --git a/testing/llvm3.7/llvm-0003-Fix-DynamicLibrary-to-build-with-musl-libc.patch b/testing/llvm3.7/llvm-0003-Fix-DynamicLibrary-to-build-with-musl-libc.patch
new file mode 100644
index 0000000..d5d7f07
--- /dev/null
+++ b/testing/llvm3.7/llvm-0003-Fix-DynamicLibrary-to-build-with-musl-libc.patch
@@ -0,0 +1,33 @@
+From d12ecb83d01dcb580dd94f4d57828f33d3eb4c35 Mon Sep 17 00:00:00 2001
+From: Natanael Copa <[email-masked]>
+Date: Thu, 18 Feb 2016 15:33:21 +0100
+Subject: [PATCH 3/3] Fix DynamicLibrary to build with musl libc
+
+stdin/out/err is part of the libc and not the kernel so we check for the
+specific libc that does the unexpected instead of linux.
+
+This is needed for making it build with musl libc.
+---
+ lib/Support/DynamicLibrary.cpp | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/lib/Support/DynamicLibrary.cpp b/lib/Support/DynamicLibrary.cpp
+index 9a7aeb5..0c1c8f8 100644
+--- a/lib/Support/DynamicLibrary.cpp
++++ b/lib/Support/DynamicLibrary.cpp
+@@ -140,10 +140,10 @@ void* DynamicLibrary::SearchForAddressOfSymbol(const char *symbolName) {
+ #define EXPLICIT_SYMBOL(SYM) \
+    if (!strcmp(symbolName, #SYM)) return &SYM
+ 
+-// On linux we have a weird situation. The stderr/out/in symbols are both
++// On GNU libc we have a weird situation. The stderr/out/in symbols are both
+ // macros and global variables because of standards requirements. So, we
+ // boldly use the EXPLICIT_SYMBOL macro without checking for a #define first.
+-#if defined(__linux__) and !defined(__ANDROID__)
++#if defined(__GLIBC__)
+   {
+     EXPLICIT_SYMBOL(stderr);
+     EXPLICIT_SYMBOL(stdout);
+-- 
+2.7.3
+
diff --git a/testing/llvm3.7/llvm-0003-musl-hacks.patch b/testing/llvm3.7/llvm-0003-musl-hacks.patch
new file mode 100644
index 0000000..d88b5fc
--- /dev/null
+++ b/testing/llvm3.7/llvm-0003-musl-hacks.patch
@@ -0,0 +1,114 @@
+From faca3fbd15d0c3108493c3c54cd93138e049ac43 Mon Sep 17 00:00:00 2001
+From: Andrea Brancaleoni <[email-masked]>
+Date: Tue, 8 Sep 2015 22:03:02 +0200
+Subject: [PATCH 3/3] musl
+
+---
+ include/llvm/Analysis/TargetLibraryInfo.h | 9 +++++++++
+ lib/Analysis/TargetLibraryInfo.cpp        | 5 +++--
+ lib/Support/DynamicLibrary.cpp            | 2 +-
+ lib/Support/Unix/Signals.inc              | 6 +++---
+ utils/unittest/googletest/src/gtest.cc    | 1 +
+ 5 files changed, 17 insertions(+), 6 deletions(-)
+
+diff --git a/include/llvm/Analysis/TargetLibraryInfo.h b/include/llvm/Analysis/TargetLibraryInfo.h
+index e0a1ee3..465b65a 100644
+--- a/include/llvm/Analysis/TargetLibraryInfo.h
++++ b/include/llvm/Analysis/TargetLibraryInfo.h
+@@ -18,6 +18,15 @@
+ #include "llvm/IR/Module.h"
+ #include "llvm/Pass.h"
+ 
++#undef fopen64
++#undef fseeko64
++#undef fstat64
++#undef fstatvfs64
++#undef ftello64
++#undef lstat64
++#undef stat64
++#undef tmpfile64
++
+ namespace llvm {
+ /// VecDesc - Describes a possible vectorization of a function.
+ /// Function 'VectorFnName' is equivalent to 'ScalarFnName' vectorized
+diff --git a/lib/Analysis/TargetLibraryInfo.cpp b/lib/Analysis/TargetLibraryInfo.cpp
+index 635c50c..863f4a0 100644
+--- a/lib/Analysis/TargetLibraryInfo.cpp
++++ b/lib/Analysis/TargetLibraryInfo.cpp
+@@ -336,14 +336,15 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
+   }
+ 
+   // The following functions are available on at least Linux:
+-  if (!T.isOSLinux()) {
++  if (!T.isOSLinux())
++    TLI.setUnavailable(LibFunc::memalign);
++  if (1 /*!T.isGlibc()*/) {
+     TLI.setUnavailable(LibFunc::dunder_strdup);
+     TLI.setUnavailable(LibFunc::dunder_strtok_r);
+     TLI.setUnavailable(LibFunc::dunder_isoc99_scanf);
+     TLI.setUnavailable(LibFunc::dunder_isoc99_sscanf);
+     TLI.setUnavailable(LibFunc::under_IO_getc);
+     TLI.setUnavailable(LibFunc::under_IO_putc);
+-    TLI.setUnavailable(LibFunc::memalign);
+     TLI.setUnavailable(LibFunc::fopen64);
+     TLI.setUnavailable(LibFunc::fseeko64);
+     TLI.setUnavailable(LibFunc::fstat64);
+diff --git a/lib/Support/DynamicLibrary.cpp b/lib/Support/DynamicLibrary.cpp
+index 9a7aeb5..e21750d 100644
+--- a/lib/Support/DynamicLibrary.cpp
++++ b/lib/Support/DynamicLibrary.cpp
+@@ -138,7 +138,7 @@ void* DynamicLibrary::SearchForAddressOfSymbol(const char *symbolName) {
+ 
+ // This macro returns the address of a well-known, explicit symbol
+ #define EXPLICIT_SYMBOL(SYM) \
+-   if (!strcmp(symbolName, #SYM)) return &SYM
++   if (!strcmp(symbolName, #SYM)) return (void *) &SYM
+ 
+ // On linux we have a weird situation. The stderr/out/in symbols are both
+ // macros and global variables because of standards requirements. So, we
+diff --git a/lib/Support/Unix/Signals.inc b/lib/Support/Unix/Signals.inc
+index bfe2a3a..e8372d9 100644
+--- a/lib/Support/Unix/Signals.inc
++++ b/lib/Support/Unix/Signals.inc
+@@ -117,7 +117,7 @@ static void RegisterHandlers() {
+   // during handling an actual signal because you can't safely call new in a
+   // signal handler.
+   *SignalsMutex;
+-  
++
+   // If the handlers are already registered, we're done.
+   if (NumRegisteredSignals != 0) return;
+ 
+@@ -164,7 +164,7 @@ static void RemoveFilesToRemove() {
+     // super-user permissions.
+     if (!S_ISREG(buf.st_mode))
+       continue;
+-  
++
+     // Otherwise, remove the file. We ignore any errors here as there is nothing
+     // else we can do.
+     unlink(path);
+@@ -430,7 +430,7 @@ static bool printSymbolizedStackTrace(void **StackTrace, int Depth,
+ // On glibc systems we have the 'backtrace' function, which works nicely, but
+ // doesn't demangle symbols.
+ void llvm::sys::PrintStackTrace(raw_ostream &OS) {
+-#if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES)
++#if defined(__GLIBC__) && defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES)
+   static void* StackTrace[256];
+   // Use backtrace() to output a backtrace on Linux systems with glibc.
+   int depth = backtrace(StackTrace,
+diff --git a/utils/unittest/googletest/src/gtest.cc b/utils/unittest/googletest/src/gtest.cc
+index 5780764..1d548c1 100644
+--- a/utils/unittest/googletest/src/gtest.cc
++++ b/utils/unittest/googletest/src/gtest.cc
+@@ -120,6 +120,7 @@
+ 
+ #if GTEST_CAN_STREAM_RESULTS_
+ # include <arpa/inet.h>  // NOLINT
++# include <sys/socket.h>  // NOLINT
+ # include <netdb.h>  // NOLINT
+ #endif
+ 
+-- 
+2.5.1
+
diff --git a/testing/llvm3.7/llvm-nm-workaround.patch b/testing/llvm3.7/llvm-nm-workaround.patch
new file mode 100644
index 0000000..5755e57
--- /dev/null
+++ b/testing/llvm3.7/llvm-nm-workaround.patch
@@ -0,0 +1,27 @@
+From https://llvm.org/bugs/show_bug.cgi?id=24115
+
+diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp
+index e7ee312..b9e4779 100644
+--- a/tools/llvm-nm/llvm-nm.cpp
++++ b/tools/llvm-nm/llvm-nm.cpp
+@@ -486,7 +486,7 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
+                                    std::string ArchiveName,
+                                    std::string ArchitectureName) {
+   if (!NoSort) {
+-    std::function<bool(const NMSymbol &, const NMSymbol &)> Cmp;
++    bool (*Cmp)(const NMSymbol &, const NMSymbol &);
+     if (NumericSort)
+       Cmp = compareSymbolAddress;
+     else if (SizeSort)
+@@ -495,8 +495,9 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
+       Cmp = compareSymbolName;
+ 
+     if (ReverseSort)
+-      Cmp = [=](const NMSymbol &A, const NMSymbol &B) { return Cmp(B, A); };
+-    std::sort(SymbolList.begin(), SymbolList.end(), Cmp);
++      std::sort(SymbolList.begin(), SymbolList.end(), [=](const NMSymbol &A, const NMSymbol &B) { return Cmp(B, A); });
++    else
++      std::sort(SymbolList.begin(), SymbolList.end(), Cmp);
+   }
+ 
+   if (!PrintFileName) {
-- 
2.8.0

---

---

From: Mitch Tishmack <[email-masked]>
Date: Thu, 14 Jul 2016 21:53:22 -0500

---
 testing/cabal/APKBUILD                       | 53 ++++++++++++++++++++++++++++
 testing/cabal/cabal-0001-force-ld.gold.patch | 10 ++++++
 2 files changed, 63 insertions(+)
 create mode 100644 testing/cabal/APKBUILD
 create mode 100644 testing/cabal/cabal-0001-force-ld.gold.patch

diff --git a/testing/cabal/APKBUILD b/testing/cabal/APKBUILD
new file mode 100644
index 0000000..524f849
--- /dev/null
+++ b/testing/cabal/APKBUILD
@@ -0,0 +1,53 @@
+# Maintainer: Mitch Tishmack <[email-masked]>
+pkgname=cabal
+pkgver=1.24.0.0
+pkgrel=0
+pkgdesc="The Haskell Cabal"
+url="http://haskell.org"
+arch="x86_64 armhf"
+license="bsd3"
+depends="musl zlib gmp"
+makedepends="ghc ghc-dev binutils-gold chrpath"
+install=""
+subpackages=""
+source="
+	https://www.haskell.org/$pkgname/release/$pkgname-install-$pkgver/$pkgname-install-$pkgver.tar.gz
+	cabal-0001-force-ld.gold.patch
+"
+_builddir="$srcdir/$pkgname-install-$pkgver"
+
+prepare() {                         
+        cd "$_builddir" || return 1
+        for i in $source; do         
+                case $i in        
+                cabal-*.patch)
+                        msg "Applying $i..."         
+                        patch -s -p0 -N -i "$srcdir"/$i || return 1
+                        ;;
+                esac                                           
+        done                                                    
+}    
+
+build() {
+	cd "$_builddir"
+	(
+		export HOME="$_builddir"
+		export NO_DOCUMENTATION=1
+		export EXTRA_BUILD_OPTS="--ghc-option=-fPIC --ghc-option=-fllvm"
+		./bootstrap.sh || return 1
+	) || return 1
+}
+
+package() {
+	cd "$_builddir"
+	install -d "$pkgdir/usr/bin" || return 1
+	install -m755 "$_builddir/dist/build/cabal/cabal" "$pkgdir/usr/bin/cabal" || return 1
+	chrpath -d "$pkgdir/usr/bin/cabal" || return 1
+	install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" || return 1
+}
+md5sums="beb998cdc385523935620381abe393f4  cabal-install-1.24.0.0.tar.gz
+e64c6868b8696f8d49945900af80b30c  cabal-0001-force-ld.gold.patch"
+sha256sums="d840ecfd0a95a96e956b57fb2f3e9c81d9fc160e1fd0ea350b0d37d169d9e87e  cabal-install-1.24.0.0.tar.gz
+74a2516bbcb5c7a5a9c8d7633630ce5b3397e160bd0e0c06fd10f104ac08002f  cabal-0001-force-ld.gold.patch"
+sha512sums="0bbd217259e6cd953731179e89dd0b9c972e8634c78d1270c9141daf8be4c53f4817812c93bec86c3cbaf5cc3467497137a4d30c0c594cc27204f0e9aebe6830  cabal-install-1.24.0.0.tar.gz
+35a9127f9aa5689047fbb3ad8757c3c0a3834c15f90d764edcb9ca24652f271c180458715c447d550f5329c0e2368207502318e4ae31292e593c667eeb79d386  cabal-0001-force-ld.gold.patch"
diff --git a/testing/cabal/cabal-0001-force-ld.gold.patch b/testing/cabal/cabal-0001-force-ld.gold.patch
new file mode 100644
index 0000000..86ed3a3
--- /dev/null
+++ b/testing/cabal/cabal-0001-force-ld.gold.patch
@@ -0,0 +1,10 @@
+--- bootstrap.sh.original	2016-02-10 06:45:52.000000000 -0600
++++ bootstrap.sh	2016-03-18 23:28:06.000000000 -0500
+@@ -74,6 +74,7 @@
+ 
+ # Fall back to "ld"... might work.
+ [ -$LINK- = -""- ] && LINK=ld
++LINK="ld.gold"
+ 
+ # And finally, see if we can compile and link something.
+   echo 'int main(){}' | $CC -xc - -o /dev/null ||
-- 
2.8.0

---

---

From: Mitch Tishmack <[email-masked]>
Date: Thu, 14 Jul 2016 21:53:21 -0500

---
 testing/ghc/APKBUILD | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 105 insertions(+)
 create mode 100755 testing/ghc/APKBUILD

diff --git a/testing/ghc/APKBUILD b/testing/ghc/APKBUILD
new file mode 100755
index 0000000..4b405a1
--- /dev/null
+++ b/testing/ghc/APKBUILD
@@ -0,0 +1,105 @@
+#-*-mode: Shell-script; coding: utf-8;-*-
+# Contributor: Mitch Tishmack <[email-masked]>
+# Maintainer: Mitch Tishmack <[email-masked]>
+pkgname=ghc
+pkgdesc="The Glasgow haskell compiler 8.0.1"
+url="http://haskell.org"
+subpackages="$pkgname-doc $pkgname-dev"
+arch="x86_64 armhf"
+apkgver=8.0.1
+pkgver=$(echo ${apkgver} | tr -d '[a-z]')
+# setting _date to YYYmmDD will activate build from git behavior
+_date=
+if [ ${_date} != "" ]; then
+  pkgrel=${_date}
+  _builddir="$srcdir/$pkgname-${apkgver}.${_date}"
+  source="
+	https://s3-us-west-2.amazonaws.com/alpine-ghc/next/ghc-${apkver}.${_date}-src.tar.xz
+	"
+else
+  pkgrel=0
+  _builddir="$srcdir/$pkgname-$apkgver"
+  source="
+	http://downloads.haskell.org/~ghc/${apkgver}/ghc-${apkgver}-src.tar.xz
+	"
+fi
+inst_prefix=/usr
+# Note ghc's license is basically bsd3. If you'd like to know more visit:
+# https://www.haskell.org/ghc/license
+# https://ghc.haskell.org/trac/ghc/wiki/Licensing
+#
+# Note also that ghc is sensitive to the version of llvm used, hence the
+# llvm3.7 package.
+#
+# Ref: https://ghc.haskell.org/trac/ghc/wiki/Status/GHC-8.0.1
+#      https://ghc.haskell.org/trac/ghc/wiki/ImprovedLLVMBackend
+license="custom:bsd3"
+depends="bash gmp-dev libffi musl zlib ncurses perl gcc llvm3.7"
+install=""
+dev_depends="
+	$depends
+	linux-headers
+	musl-dev
+	ncurses-dev
+	gmp-dev
+	libffi-dev
+	zlib-dev
+	binutils-dev
+	"
+# ghc build dependencies
+makedepends="
+	$dev_depends
+	ghc-bootstrap
+	"
+
+_ghc_build_tmp="$_builddir/tmp"
+
+# Allow for multiple installs, intentionally not default.
+if [ ! -z $MULTI ]; then
+	inst_prefix="/opt/ghc/${pkgver}"
+	pkgname="ghc-${pkgver}"
+	depends="${depends}-37"
+fi
+
+build() {
+	cd "$_builddir"
+	cp mk/build.mk.sample mk/build.mk || return 1
+	echo "BuildFlavour         = perf-llvm" >> mk/build.mk || return 1
+	echo "SRC_HC_OPTS         += -fPIC" >> mk/build.mk || return 1
+	echo "SRC_HC_OPTS         += -fllvm" >> mk/build.mk || return 1
+	echo "SRC_CC_OPTS         += -fPIC" >> mk/build.mk || return 1
+	echo "GhcLibHcOpts        += -fPIC" >> mk/build.mk || return 1
+	echo "GhcRtsCcOpts        += -fPIC" >> mk/build.mk || return 1
+	echo "INTEGER_LIBRARY      = integer-gmp" >> mk/build.mk || return 1
+	echo "BeConservative       = YES" >> mk/build.mk || return 1
+	echo "GhcLibWays           = v" >> mk/build.mk || return 1
+	echo "GhcLibWays          += dyn" >> mk/build.mk || return 1
+	echo "GhcLibWays          += p"  >> mk/build.mk || return 1
+	echo "BUILD_SPHINX_HTML    = NO" >> mk/build.mk  || return 1
+	echo "BUILD_SPHINX_PS      = NO" >> mk/build.mk || return 1
+	echo "BUILD_SPHINX_PDF     = NO" >> mk/build.mk || return 1
+	echo "HADDOCK_DOCS         = NO" >> mk/build.mk || return 1
+	./configure \
+		--prefix="${inst_prefix}" \
+		--with-ld=ld.gold || return 1
+	make || return 1
+}
+
+dev() {
+	depends="$dev_depends"
+	cd "$_builddir"
+	pkgdesc="Packages necessary for general ghc development"
+	install -Dm644 LICENSE "$subpkgdir/usr/share/licenses/$subpkgname/LICENSE" || return 1
+}
+
+# Note, -nopie due to this bug, and must remain until fixed.
+# https://ghc.haskell.org/trac/ghc/ticket/9007
+package() {
+	cd "$_builddir"
+	make -j1 DESTDIR="$pkgdir" install || return 1
+	install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" || return 1
+	perl -pi -e 's/.*C compiler link flags.*/ \(\"C compiler link flags\"\, \"-nopie\"\)\,/' "$(find $pkgdir -name settings -type f)"
+}
+md5sums="c185b8a1f3e67e43533ec590b751c2ff  ghc-8.0.1-src.tar.xz"
+sha256sums="90fb20cd8712e3c0fbeb2eac8dab6894404c21569746655b9b12ca9684c7d1d2  ghc-8.0.1-src.tar.xz"
+sha512sums="5fa69fd0f7a639a10221a35e16c30b00e801644fcb8581903d3e215ecc0b3bd67960fc07a23d84d083b25e17024c69824fc21925cf82c26d8b36ee6c1fc9d28d  ghc-8.0.1-src.tar.xz"
-- 
2.8.0

---

---

From: Mitch Tishmack <[email-masked]>
Date: Thu, 14 Jul 2016 21:53:23 -0500

---
 testing/stack/APKBUILD | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100755 testing/stack/APKBUILD

diff --git a/testing/stack/APKBUILD b/testing/stack/APKBUILD
new file mode 100755
index 0000000..33afe5e
--- /dev/null
+++ b/testing/stack/APKBUILD
@@ -0,0 +1,39 @@
+# Contributor: Mitch Tishmack <[email-masked]>
+# Maintainer: Mitch Tishmack <[email-masked]>
+pkgname=stack
+pkgver=1.1.2
+pkgrel=0
+pkgdesc="The Haskell Tool Stack"
+url="https://github.com/commercialhaskell/stack"
+arch="x86_64 armhf"
+license="bsd3"
+depends="ca-certificates"
+makedepends="bash ghc ghc-dev cabal pcre-dev"
+install=""
+subpackages="$pkgname-doc"
+source="$pkgname-$pkgver.tar.gz::https://github.com/commercialhaskell/stack/archive/v$pkgver.tar.gz"
+_builddir="$srcdir/$pkgname-$pkgver"
+
+# Where we have cabal store our sandbox
+buildtmp="$_builddir/tmp"
+build() {
+	cd "$_builddir"
+	install -d "$buildtmp"
+	(
+		export PATH="${PATH}:$buildtmp/.cabal/bin"
+		export HOME="$buildtmp"
+		cabal update || return 1
+		cabal install -fstatic --ghc-option=-fllvm --constraint 'http-client < 0.5' || return 1
+	)
+}
+
+package() {
+	cd "$_builddir"
+	install -d "$pkgdir/usr/bin" || return 1
+	pkg_stack="$buildtmp/.cabal/bin/$pkgname"
+	install -m755 "$pkg_stack" "$pkgdir/usr/bin" || return 1
+	install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" || return 1
+}
+md5sums="7150fa22bfdb23e07457335fd6853cd9  stack-1.1.2.tar.gz"
+sha256sums="8f43d69a00a8861b156705a634e55179524cefbd98e6c29182e7bdcb57d8b3be  stack-1.1.2.tar.gz"
+sha512sums="e206ada405ba7fb0fd05a5cce6391b83b858b789323ccb0547c90bcfad4bd9d33d82c5dcc25ad7174c0de4eb7643e5d1f2bf657079efaa8883a060f73c6a57ab  stack-1.1.2.tar.gz"
-- 
2.8.0

---