Subject: [alpine-aports] [PATCH 1/3] testing/ghc-llvm35 new aport

From: Mitch Tishmack <[email-masked]>
Date: Tue, 1 Mar 2016 19:28:54 -0600

From: Mitch Tishmack <[email-masked]>

---
 testing/ghc-llvm35/APKBUILD                        | 175 +++++++++++++++++++++
 .../ghc-llvm35/llvm-0001-fix-shared-build.patch    |  48 ++++++
 testing/ghc-llvm35/llvm-0002-musl-triple.patch     |  74 +++++++++
 testing/ghc-llvm35/llvm-0003-musl-hacks.patch      |  82 ++++++++++
 4 files changed, 379 insertions(+)
 create mode 100755 testing/ghc-llvm35/APKBUILD
 create mode 100644 testing/ghc-llvm35/llvm-0001-fix-shared-build.patch
 create mode 100644 testing/ghc-llvm35/llvm-0002-musl-triple.patch
 create mode 100644 testing/ghc-llvm35/llvm-0003-musl-hacks.patch

diff --git a/testing/ghc-llvm35/APKBUILD b/testing/ghc-llvm35/APKBUILD
new file mode 100755
index 0000000..e85b324
--- /dev/null
+++ b/testing/ghc-llvm35/APKBUILD
@@ -0,0 +1,175 @@
+# Contributor: Mitch Tishmack <[email-masked]>
+# Maintainer: Mitch Tishmack <[email-masked]>
+#
+# Note, this ONLY compiles llvm for opt/llc and moves the
+# suffixed binaries to /usr/lib/ghc
+#
+# This allows the ghc/ghc-bootstrap portx to use the correct llvm.
+_pkgname=llvm
+llvm_major=3.5
+llvm_version=${llvm_major}.2
+suffix="-${llvm_major}"
+opt=opt${suffix}
+llc=llc${suffix}
+pkgname=ghc-${_pkgname}-${llvm_major}
+pkgver=$llvm_version
+pkgrel=0
+pkgdesc="ghc required llvm binaries"
+url="n/a"
+arch="x86_64 armhf"
+license="UIO-NCSA"
+depends=""
+install=""
+subpackages=""
+# llvm build dependencies
+makedepends="
+	$depends
+	$makedepends
+	perl
+	cmake
+	make
+	flex
+	bison
+	groff
+	musl-dev
+	binutils-dev
+	libffi-dev
+	zlib-dev
+	ncurses-dev
+	python
+	python-dev
+	gmp-dev
+	git
+	libtool
+	autoconf
+	automake
+"
+_builddir="$srcdir/$pkgname-$pkgver"
+
+# musl patches for 3.5.2
+source="
+	llvm-0001-fix-shared-build.patch
+	llvm-0002-musl-triple.patch
+	llvm-0003-musl-hacks.patch
+"
+
+# llvm/polly
+source="
+	$source
+	http://llvm.org/releases/$pkgver/llvm-$pkgver.src.tar.xz
+	http://llvm.org/releases/$pkgver/polly-$pkgver.src.tar.xz
+"
+_builddir="$srcdir"/build
+llvm_srcdir="$srcdir/llvm-$llvm_version.src"
+llvm_builddir="$srcdir/build"
+srcdir_polly="$srcdir"/polly-$llvm_version.src
+
+_cmake_flags="\
+	-DCMAKE_BUILD_TYPE=Release \
+	-DCMAKE_VERBOSE_MAKEFILE=NO \
+	-DLLVM_DEFAULT_TARGET_TRIPLE=$CBUILD \
+	-DLLVM_HOST_TRIPLE=$CHOST \
+	-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 \
+	-DWITH_POLLY=YES \
+	-DLLVM_BUILD_DOCS=NO \
+	-DLLVM_BUILD_TESTS=NO \
+	-DLLVM_ENABLE_CXX1Y=NO \
+	-DLLVM_ENABLE_FFI=YES \
+	-DLLVM_ENABLE_SPHINX=NO \
+	-DLLVM_INCLUDE_EXAMPLES=NO \
+	-DLLVM_INCLUDE_TESTS=NO \
+	-DLLVM_ENABLE_CURSES=NO \
+	-DLLVM_ENABLE_TERMINFO=NO \
+"
+
+prepare() {
+	msg "Patching LLVM core..."
+	cd "$llvm_srcdir" || return 1
+	for i in $source; do
+		case $i in
+			llvm-*.patch)
+				msg "Applying $i..."
+				patch -s -p1 -N -i "$srcdir"/$i || return 1
+			;;
+		esac
+	done
+}
+
+build() {
+	msg "building isl"
+	# Note, isl is now too new for 3.5.2 in alpine linux.
+	# compile the right version into $srcdir so we can use polly
+	tmp="$srcdir/tmp"
+	install -d ${tmp} || return 1
+	isl_srcdir="$tmp/isl"
+	cloog_srcdir="$tmp/cloog"
+	cd "$srcdir_polly/utils"
+	./checkout_cloog.sh ${tmp} || return 1
+	cd "$isl_srcdir"
+	./configure --build=$CBUILD \
+		--host=$CHOST \
+		--prefix=$tmp || return 1
+	make || return 1
+	make -j1 INSTALL="install -D"		 install || return 1
+	mv "$srcdir"/polly-$llvm_version.src ""$llvm_srcdir"/tools/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 CBUILD
+
+		ffi_include_dir="$(pkg-config --cflags-only-I libffi | sed 's|^-I||g')"
+
+		cflags="${OCFLAGS} -DNDEBUG"
+		cxxflags="${OCXXFLAGS} -DNDEBUG"
+		CC="gcc"
+		CXX="g++"
+
+		msg "Compiling llvm"
+		install -d "${llvm_builddir}"
+		cd "${llvm_builddir}"
+		cmake -G "Unix Makefiles" -Wno-dev ${_cmake_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 -static" \
+			-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 llvm-tblgen opt llc || return 1
+		) || return 1
+	) || return 1
+}
+
+package() {
+	cd "$_builddir"
+	install -d "$pkgdir/usr/lib/ghc"
+	for x in opt llc; do
+		install -Dm755 "$srcdir/build/bin/${x}" "$pkgdir/usr/lib/ghc/${x}${suffix}" || return 1
+	done
+}
diff --git a/testing/ghc-llvm35/llvm-0001-fix-shared-build.patch b/testing/ghc-llvm35/llvm-0001-fix-shared-build.patch
new file mode 100644
index 0000000..492c439
--- /dev/null
+++ b/testing/ghc-llvm35/llvm-0001-fix-shared-build.patch
@@ -0,0 +1,48 @@
+From 0d03d2ea17b66d8cb0f6ca5f2181237228535845 Mon Sep 17 00:00:00 2001
+From: Sanjoy Das <sanjoy at azulsystems.com>
+Date:   Thu Jun 19 15:38:02 2014 -0700
+Subject: Fix the --enable-shared build.
+
+Currently a build configured with ./configure --enable-shared breaks
+with an undefined "llvm::cl::parser<llvm::PassInfo
+const*>::getOption(unsigned int) const" symbol when linking opt.  This
+body for this symbol gets emitted into Pass.o (along with the destructor
+for PassNameParser), but gets linked into libLLVM-3.5svn.so with local
+visibility, causing the link error.
+
+This fix uses the existing EXTERN_TEMPLATE machinery to force a globally
+visible definition for the functions in parser<const PassInfo *> into
+Pass.o.
+---
+ include/llvm/IR/LegacyPassNameParser.h | 2 ++
+ lib/IR/Pass.cpp                        | 2 ++
+ 2 files changed, 4 insertions(+)
+
+diff --git a/include/llvm/IR/LegacyPassNameParser.h b/include/llvm/IR/LegacyPassNameParser.h
+index e2e4912..a07e3fd 100644
+--- a/include/llvm/IR/LegacyPassNameParser.h
++++ b/include/llvm/IR/LegacyPassNameParser.h
+@@ -95,6 +95,8 @@ private:
+   }
+ };
+
++EXTERN_TEMPLATE_INSTANTIATION(class cl::parser<const PassInfo *>);
++
+ ///===----------------------------------------------------------------------===//
+ /// FilteredPassNameParser class - Make use of the pass registration
+ /// mechanism to automatically add a command line argument to opt for
+diff --git a/lib/IR/Pass.cpp b/lib/IR/Pass.cpp
+index 91d86ae..00ce223 100644
+--- a/lib/IR/Pass.cpp
++++ b/lib/IR/Pass.cpp
+@@ -234,6 +234,8 @@ PassNameParser::~PassNameParser() {
+   // attempting to remove the registration listener is an error.
+ }
+
++TEMPLATE_INSTANTIATION(class cl::parser<const PassInfo *>);
++
+ //===----------------------------------------------------------------------===//
+ //   AnalysisUsage Class Implementation
+ //
+--
+2.1.4
diff --git a/testing/ghc-llvm35/llvm-0002-musl-triple.patch b/testing/ghc-llvm35/llvm-0002-musl-triple.patch
new file mode 100644
index 0000000..7ef97be
--- /dev/null
+++ b/testing/ghc-llvm35/llvm-0002-musl-triple.patch
@@ -0,0 +1,74 @@
+diff --git a/include/llvm/ADT/Triple.h b/include/llvm/ADT/Triple.h
+index 8a68599..072623c 100644
+--- a/include/llvm/ADT/Triple.h
++++ b/include/llvm/ADT/Triple.h
+@@ -154,6 +154,10 @@ public:
+     EABIHF,
+     Android,
+
++    Musl,
++    MuslEABI,
++    MuslEABIHF,
++
+     MSVC,
+     Itanium,
+     Cygnus,
+diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp
+index 0838e90..4be78e5 100644
+--- a/lib/Support/Triple.cpp
++++ b/lib/Support/Triple.cpp
+@@ -175,6 +175,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";
+@@ -375,6 +378,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)
+--- llvm-3.6.1.src.orig/lib/Support/Triple.cpp
++++ llvm-3.6.1.src/lib/Support/Triple.cpp
+@@ -1094,6 +1094,7 @@
+     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 dbacd4d..b330be5 100644
+--- a/lib/Target/ARM/ARMSubtarget.h
++++ b/lib/Target/ARM/ARMSubtarget.h
+@@ -369,8 +369,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();
+   }
+@@ -379,6 +381,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 {
+--
+2.1.4
diff --git a/testing/ghc-llvm35/llvm-0003-musl-hacks.patch b/testing/ghc-llvm35/llvm-0003-musl-hacks.patch
new file mode 100644
index 0000000..7d3e0a6
--- /dev/null
+++ b/testing/ghc-llvm35/llvm-0003-musl-hacks.patch
@@ -0,0 +1,82 @@
+diff --git a/include/llvm/Target/TargetLibraryInfo.h b/include/llvm/Target/TargetLibraryInfo.h
+index 46f87b9..41ac5fd 100644
+--- a/include/llvm/Target/TargetLibraryInfo.h
++++ b/include/llvm/Target/TargetLibraryInfo.h
+@@ -13,6 +13,15 @@
+ #include "llvm/ADT/DenseMap.h"
+ #include "llvm/Pass.h"
+
++#undef fopen64
++#undef fseeko64
++#undef fstat64
++#undef fstatvfs64
++#undef ftello64
++#undef lstat64
++#undef stat64
++#undef tmpfile64
++
+ namespace llvm {
+   class Triple;
+
+diff --git a/lib/Support/DynamicLibrary.cpp b/lib/Support/DynamicLibrary.cpp
+index d2b551e..4634a13 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 e8f4643..8a320ef 100644
+--- a/lib/Support/Unix/Signals.inc
++++ b/lib/Support/Unix/Signals.inc
+@@ -416,7 +416,7 @@ static bool printSymbolizedStackTrace(void **StackTrace, int Depth, FILE *FD) {
+ // On glibc systems we have the 'backtrace' function, which works nicely, but
+ // doesn't demangle symbols.
+ void llvm::sys::PrintStackTrace(FILE *FD) {
+-#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/lib/Target/TargetLibraryInfo.cpp b/lib/Target/TargetLibraryInfo.cpp
+index c0abdbd..ed908f8 100644
+--- a/lib/Target/TargetLibraryInfo.cpp
++++ b/lib/Target/TargetLibraryInfo.cpp
+@@ -664,14 +664,15 @@ static void initialize(TargetLibraryInfo &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/utils/unittest/googletest/src/gtest.cc b/utils/unittest/googletest/src/gtest.cc
+index bf850c6..9e9088c 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.1.4
-- 
2.7.0

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

---

From: Mitch Tishmack <[email-masked]>
Date: Tue, 1 Mar 2016 19:28:55 -0600

---
 testing/ghc-bootstrap/APKBUILD                     |  38 ++
 testing/ghc-bootstrap/Makefile                     |  50 +++
 testing/ghc-bootstrap/bootstrap/gmpurl.patch       |  22 ++
 testing/ghc-bootstrap/bootstrap/llvm-3.5.2.sh      | 122 +++++++
 testing/ghc-bootstrap/bootstrap/x86_64/Dockerfile  |  96 +++++
 .../ghc-bootstrap/bootstrap/x86_64/bootstrap.patch | 397 +++++++++++++++++++++
 testing/ghc-bootstrap/bootstrap/x86_64/settings    |  32 ++
 7 files changed, 757 insertions(+)
 create mode 100755 testing/ghc-bootstrap/APKBUILD
 create mode 100644 testing/ghc-bootstrap/Makefile
 create mode 100644 testing/ghc-bootstrap/bootstrap/gmpurl.patch
 create mode 100755 testing/ghc-bootstrap/bootstrap/llvm-3.5.2.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..d396589
--- /dev/null
+++ b/testing/ghc-bootstrap/APKBUILD
@@ -0,0 +1,38 @@
+#-*-mode: Shell-script; coding: utf-8;-*-
+# Contributor: Mitch Tishmack <[email-masked]>
+# Maintainer: Mitch Tishmack <[email-masked]>
+#
+# Mostly here for porting, beyond that the native ghc
+# should be preferred. Cross compiling insn't a commonly
+# tested piece of ghc.
+pkgname=ghc-bootstrap
+pkgdesc="The Glasgow haskell compiler (bootstrapped)"
+apkgver=7.10.3b
+pkgrel=0
+pkgver=$(echo ${apkgver} | tr -d '[a-z]')
+url="http://haskell.org"
+subpackages=""
+arch="x86_64"
+source="https://dev.alpinelinux.org/archive/ghc-bootstrap/ghc-$apkgver-x86_64-unknown-linux-musl.tar.xz"
+license="custom:bsd3"
+depends="bash libffi musl zlib gcc binutils-gold ghc-llvm-3.5"
+install=""
+subpackages=""
+makedepends="perl"
+
+package() {
+	cd "$srcdir"
+	install -d "$pkgdir" || return 1
+	mv usr "$pkgdir" || return 1
+	settings=$(find "$pkgdir" -name settings -type f)
+	perl -pi -e 's/.*C compiler link flags.*/ \(\"C compiler link flags\"\, \"-nopie\"\)\,/' "$settings" || return 1
+}
+
+# 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.
+snapshot () {
+	make x86_64
+	scp "ghc-$pkgver-$bs_arch-unknown-linux-musl.tar.xz" dev.alpinelinux.org:/archive/ghc-bootstrap/ || return 1
+}
diff --git a/testing/ghc-bootstrap/Makefile b/testing/ghc-bootstrap/Makefile
new file mode 100644
index 0000000..94214b3
--- /dev/null
+++ b/testing/ghc-bootstrap/Makefile
@@ -0,0 +1,50 @@
+CABAL_VERSION:=1.22.7.0
+GHC_VERSION:=7.10.3
+LLVM_VERSION:=3.5.2
+ARCH:=x86_64
+GHC_BS:=ghc-$(GHC_VERSION)-$(ARCH)-deb8-linux.tar.xz
+GHC_SRC:=ghc-$(GHC_VERSION)-src.tar.xz
+CABAL_BS:=cabal-install-$(CABAL_VERSION).tar.gz
+LLVM_BS:=llvm-$(LLVM_VERSION).src.tar.xz
+POLLY_BS:=polly-$(LLVM_VERSION).src.tar.xz
+SRCS:= $(GHC_BS) $(GHC_SRC) $(CABAL_BS) $(LLVM_BS) $(POLLY_BS)
+
+DOCKER_NAME:=alpine-ghc-bootstrap
+TARGET:=ghc-$(GHC_VERSION)-$(ARCH)-unknown-linux-musl.tar.xz
+
+.PHONY: clean distclean cleandocker x86_64
+
+all: x86_64
+
+dl: $(SRCS)
+
+x86_64:
+	TARGET=ghc-$(GHC_VERSION)[email-masked]
+	docker build -t $(DOCKER_NAME):$@ -f bootstrap/$@/Dockerfile . | tee make-$@-$(shell date +%s).log
+	docker run -a stdout "$(DOCKER_NAME):$@" /bin/cat "/tmp/ghc-$(GHC_VERSION)-$(ARCH)-pc-linux-musl.tar.xz" > $(TARGET)
+
+$(GHC_BS):
+	curl -LO https://downloads.haskell.org/~ghc/$(GHC_VERSION)/$@
+
+$(GHC_SRC):
+	curl -LO https://www.haskell.org/ghc/dist/$(GHC_VERSION)/$@
+
+$(CABAL_BS):
+	curl -LO https://www.haskell.org/cabal/release/cabal-install-$(CABAL_VERSION)/$@
+
+$(LLVM_BS):
+	curl -LO http://llvm.org/releases/$(LLVM_VERSION)/$@
+
+$(POLLY_BS):
+	curl -LO http://llvm.org/releases/$(LLVM_VERSION)/$@
+
+clean:
+	-rm $(SRCS) $(TARGET)
+
+cleanlogs:
+	-rm make-*.log
+
+cleandocker:
+	docker rmi $(DOCKER_NAME)
+
+distclean: clean cleanlogs
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.5.2.sh b/testing/ghc-bootstrap/bootstrap/llvm-3.5.2.sh
new file mode 100755
index 0000000..f130872
--- /dev/null
+++ b/testing/ghc-bootstrap/bootstrap/llvm-3.5.2.sh
@@ -0,0 +1,122 @@
+#!/usr/bin/env sh
+#-*-mode: Shell-script; coding: utf-8;-*-
+# File: llvm.sh
+# Copyright: 2016 Mitchell Tishmack
+# Description: bootstrap llvm for ghc bootstrapping
+# largely a copypasta of what is in APKBUILD
+export script=$(basename "$0")
+export dir=$(cd "$(dirname "$0")"; pwd)
+export iam=${dir}/${script}
+llvm_major=3.5
+llvm_version=${llvm_major}.2
+llvm_srcdir="/tmp/llvm-${llvm_version}.src"
+#mdir="/tmp/llvm-mirror-llvm-7892e56"
+#if [ -e ${mdir} ]; then
+#  mv ${mdir} ${llvm_srcdir}
+#fi
+suffix="-${llvm_major}"
+llvm_builddir=/tmp/build
+polly_orig_srcdir="/tmp/polly-$llvm_version.src"
+
+cd "$llvm_srcdir"
+# for i in /tmp/llvm*.patch; do
+# 	patch -s -p1 -N -i $i || return 1
+# done
+
+_cmake_flags="\
+	-DCMAKE_BUILD_TYPE=Release \
+	-DCMAKE_VERBOSE_MAKEFILE=NO \
+	-DLLVM_DEFAULT_TARGET_TRIPLE=$CBUILD \
+	-DLLVM_HOST_TRIPLE=$CHOST \
+	-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_EXTERNAL_POLLY_BUILD=NO \
+	-DLINK_POLLY_INTO_TOOLS=NO \
+	-DLLVM_BUILD_DOCS=NO \
+	-DLLVM_BUILD_TESTS=NO \
+	-DLLVM_ENABLE_CXX1Y=NO \
+	-DLLVM_ENABLE_FFI=YES \
+	-DLLVM_ENABLE_SPHINX=NO \
+	-DLLVM_ENABLE_TERMINFO=YES \
+	-DWITH_POLLY=YES \
+	-DLLVM_INCLUDE_EXAMPLES=NO \
+	-DLLVM_INCLUDE_TESTS=NO \
+	-DPOLLY_ENABLE_GPGPU_CODEGEN=NO \
+	"
+srcdir_polly="$llvm_srcdir"/tools/polly
+mv /tmp/polly-$llvm_version.src "$srcdir_polly" || return 1
+
+build_isl() {
+	srcdir=/tmp
+	tmp="$srcdir/tmp"
+	install -d ${tmp} || return 1
+	isl_srcdir="$tmp/isl"
+	cloog_srcdir="$tmp/cloog"
+	cd "$srcdir_polly/utils"
+	./checkout_cloog.sh ${tmp} || return 1
+#	./checkout_isl.sh ${isl_srcdir} || return 1
+	cd "$isl_srcdir"
+	./configure --build=$CBUILD \
+		--host=$CHOST \
+		--prefix=$tmp || return 1
+	make -j$(grep -c processor /proc/cpuinfo)|| return 1
+	make -j1 INSTALL="install -D"	 install || return 1
+}
+
+build_isl "$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 CBUILD
+	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..00b1bfc
--- /dev/null
+++ b/testing/ghc-bootstrap/bootstrap/x86_64/Dockerfile
@@ -0,0 +1,96 @@
+from debian:8.0
+
+# all needed packages for compiling
+run 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
+
+# Install stock bindist for cross compile
+env ghc 7.10.3
+env arch x86_64
+copy ghc-$ghc-$arch-deb8-linux.tar.xz /tmp/ghc.txz
+workdir /tmp
+run tar xJpf /tmp/ghc.txz
+workdir /tmp/ghc-$ghc
+run ./configure --prefix=/usr && \
+make -j1 install && \
+rm -fr /tmp/ghc-$ghc
+
+env llvm 3.5.2
+workdir /tmp
+copy llvm-$llvm.src.tar.xz /tmp/llvm.txz
+copy polly-$llvm.src.tar.xz /tmp/polly.txz
+copy bootstrap/llvm-3.5.2.sh /tmp/llvm.sh
+run tar xJpf /tmp/llvm.txz && \
+    tar xJpf /tmp/polly.txz && \
+    /tmp/llvm.sh && \
+    rm -fr /tmp/llvm-$llvm.src
+
+env tardir /tmp/root
+env crosscc musl-gcc
+
+workdir /tmp
+copy ghc-$ghc-src.tar.xz /tmp/ghc-src.txz
+run tar xJpf /tmp/ghc-src.txz
+workdir /tmp/ghc-$ghc
+copy bootstrap/$arch/bootstrap.patch bootstrap.patch
+run patch -p1 < bootstrap.patch
+run cp mk/build.mk.sample mk/build.mk
+run echo "BuildFlavour         = quick-llvm" >> mk/build.mk && \
+    echo "INTEGER_LIBRARY      = integer-simple" >> mk/build.mk && \
+    echo "HADDOCK_DOCS         = NO" >> mk/build.mk && \
+    echo "BUILD_DOCBOOK_HTML   = NO" >> mk/build.mk && \
+    echo "BUILD_DOCBOOK_PS     = NO" >> mk/build.mk && \
+    echo "BUILD_DOCBOOK_PDF    = NO" >> mk/build.mk
+run ./configure \
+  --target=$arch-pc-linux-musl \
+  --with-gcc=$crosscc \
+  --with-ld=ld.gold \
+  --with-nm=nm \
+  --with-ar=ar \
+  --with-ranlib=ranlib \
+  --with-readelf=eu-readelf \
+  --prefix=/usr
+run make -j$(grep -c processor /proc/cpuinfo) || make -j1
+run make -j1 install DESTDIR=$tardir
+
+env triple pc-linux-musl
+# 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 $tardir/usr/bin/$arch-$triple-hp2ps $tardir/usr/lib/$arch-$triple-ghc-$ghc/unlit
+
+# 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 $tardir/usr/lib/$arch-$triple-ghc-$ghc/unlit
+run $crosscc unlit.c -o $tardir/usr/bin/unlit
+
+# remove target prefix from stage2 binaries
+workdir $tardir/usr/bin
+run (for i in $arch-$triple-* ; do ln -s $i ${i#$arch-$triple-} ; done )
+copy bootstrap/$arch/settings /tmp/settings
+run mv /tmp/settings $(find $tardir -name settings -type f)
+run rm -fr $tardir/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-$arch-$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..b2ef497
--- /dev/null
+++ b/testing/ghc-bootstrap/bootstrap/x86_64/bootstrap.patch
@@ -0,0 +1,397 @@
+diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
+index 42ac14e..75a7471 100644
+--- a/compiler/main/DynFlags.hs
++++ b/compiler/main/DynFlags.hs
+@@ -2353,8 +2353,7 @@ dynamic_flags = [
+   , defGhcFlag "dynload"            (hasArg parseDynLibLoaderMode)
+   , defGhcFlag "dylib-install-name" (hasArg setDylibInstallName)
+     -- -dll-split is an internal flag, used only during the GHC build
+-  , defHiddenFlag "dll-split"
+-      (hasArg (\f d -> d{ dllSplitFile = Just f, dllSplit = Nothing }))
++  , defHiddenFlag "dll-split"       (NoArg (addWarn "ignoring -dll-split"))
+ 
+         ------- Libraries ---------------------------------------------------
+   , defFlag "L"   (Prefix addLibraryPath)
+diff --git a/ghc.mk b/ghc.mk
+index 9aa0dc3..97464b8 100644
+--- a/ghc.mk
++++ b/ghc.mk
+@@ -386,7 +386,7 @@ else
+ PACKAGES_STAGE0 = binary Cabal/Cabal hpc bin-package-db hoopl transformers
+ ifeq "$(Windows_Host)" "NO"
+ ifneq "$(HostOS_CPP)" "ios"
+-PACKAGES_STAGE0 += terminfo
++PACKAGES_STAGE0 +=
+ endif
+ endif
+ 
+@@ -424,7 +424,7 @@ endif
+ 
+ ifeq "$(Windows_Target)" "NO"
+ ifneq "$(TargetOS_CPP)" "ios"
+-PACKAGES_STAGE1 += terminfo
++PACKAGES_STAGE1 +=
+ endif
+ endif
+ PACKAGES_STAGE1 += haskeline
+@@ -444,7 +444,9 @@ REGULAR_INSTALL_DYNLIBS += $(addprefix libraries/,$(PACKAGES_STAGE2))
+ REGULAR_INSTALL_DYNLIBS := $(filter-out $(REGULAR_INSTALL_PACKAGES),\
+                                         $(REGULAR_INSTALL_DYNLIBS))
+ 
+-ifneq "$(CrossCompiling)" "YES"
++# See Note [No stage2 packages when CrossCompiling or Stage1Only].
++# See Note [Stage1Only vs stage=1] in mk/config.mk.in.
++ifeq "$(CrossCompiling) $(Stage1Only)" "NO NO"
+ define addExtraPackage
+ ifeq "$2" "-"
+ # Do nothing; this package is already handled above
+@@ -486,7 +488,7 @@ endif
+ endif
+ 
+ # -------------------------------------------
+-# Dependencies between package-data.mk files
++# Note [Dependencies between package-data.mk files].
+ 
+ # We cannot run ghc-cabal to configure a package until we have
+ # configured and registered all of its dependencies.  So the following
+@@ -506,29 +508,34 @@ ifneq "$(BINDIST)" "YES"
+ fixed_pkg_prev=
+ $(foreach pkg,$(PACKAGES_STAGE1),$(eval $(call fixed_pkg_dep,$(pkg),dist-install)))
+ 
++# Intermezzo: utils that we build with the stage1 compiler. They depend on
++# the stage1 packages, so we have to make sure those packages get configured
++# and registered before we can start with these. Note that they don't depend on
++# eachother, so we can configure them in parallel.
++utils/ghc-pwd/dist-install/package-data.mk: $(fixed_pkg_prev)
++utils/ghc-cabal/dist-install/package-data.mk: $(fixed_pkg_prev)
++utils/hpc/dist-install/package-data.mk: $(fixed_pkg_prev)
++utils/ghc-pkg/dist-install/package-data.mk: $(fixed_pkg_prev)
++utils/hsc2hs/dist-install/package-data.mk: $(fixed_pkg_prev)
++utils/compare_sizes/dist-install/package-data.mk: $(fixed_pkg_prev)
++utils/runghc/dist-install/package-data.mk: $(fixed_pkg_prev)
++
+ # the GHC package doesn't live in libraries/, so we add its dependency manually:
+ compiler/stage2/package-data.mk: $(fixed_pkg_prev)
+-fixed_pkg_prev:=compiler/stage2/package-data.mk
+ 
+ # and continue with PACKAGES_STAGE2, which depend on GHC:
++fixed_pkg_prev:=compiler/stage2/package-data.mk
+ $(foreach pkg,$(PACKAGES_STAGE2),$(eval $(call fixed_pkg_dep,$(pkg),dist-install)))
+ 
+ ghc/stage1/package-data.mk: compiler/stage1/package-data.mk
+ ghc/stage2/package-data.mk: compiler/stage2/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/ghc-pwd/dist-install/package-data.mk: compiler/stage2/package-data.mk
+-utils/ghc-cabal/dist-install/package-data.mk: compiler/stage2/package-data.mk
+ 
++# Utils that we build with the stage2 compiler.
++# They depend on the ghc library and some other libraries, but depending on
++# the ghc library's package-data.mk is sufficient, as that in turn depends on
++# all the other libraries' package-data.mk files.
++utils/haddock/dist/package-data.mk: compiler/stage2/package-data.mk
+ utils/ghctags/dist-install/package-data.mk: compiler/stage2/package-data.mk
+-utils/dll-split/dist-install/package-data.mk: compiler/stage2/package-data.mk
+-utils/hpc/dist-install/package-data.mk: compiler/stage2/package-data.mk
+-utils/ghc-pkg/dist-install/package-data.mk: compiler/stage2/package-data.mk
+-utils/hsc2hs/dist-install/package-data.mk: compiler/stage2/package-data.mk
+-utils/compare_sizes/dist-install/package-data.mk: compiler/stage2/package-data.mk
+-utils/runghc/dist-install/package-data.mk: compiler/stage2/package-data.mk
+ utils/mkUserGuidePart/dist/package-data.mk: compiler/stage2/package-data.mk
+ 
+ # add the final package.conf dependency: ghc-prim depends on RTS
+@@ -598,26 +605,12 @@ endif
+ 
+ # -----------------------------------------------------------------------------
+ # Include build instructions from all subdirs
+-
+-ifneq "$(BINDIST)" "YES"
+ BUILD_DIRS += utils/mkdirhier
+-endif
+-
+-ifeq "$(Windows_Host)" "YES"
+ BUILD_DIRS += utils/touchy
+-endif
+-
+ BUILD_DIRS += utils/unlit
+ BUILD_DIRS += utils/hp2ps
+-
+-ifneq "$(GhcUnregisterised)" "YES"
+ BUILD_DIRS += driver/split
+-endif
+-
+-ifneq "$(BINDIST)" "YES"
+ BUILD_DIRS += utils/genprimopcode
+-endif
+-
+ BUILD_DIRS += driver
+ BUILD_DIRS += driver/ghci
+ BUILD_DIRS += driver/ghc
+@@ -626,11 +619,8 @@ BUILD_DIRS += libffi
+ BUILD_DIRS += utils/deriveConstants
+ BUILD_DIRS += includes
+ BUILD_DIRS += rts
+-
+-ifneq "$(BINDIST)" "YES"
+ BUILD_DIRS += bindisttest
+ BUILD_DIRS += utils/genapply
+-endif
+ 
+ ifneq "$(CLEANING)" "YES"
+ # These are deliberately in reverse order, so as to ensure that
+@@ -647,52 +637,76 @@ endif
+ endif
+ 
+ 
+-ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
+ BUILD_DIRS += libraries/integer-gmp/gmp
+ BUILD_DIRS += libraries/integer-gmp/mkGmpDerivedConstants
+-else ifneq "$(findstring clean,$(MAKECMDGOALS))" ""
+-BUILD_DIRS += libraries/integer-gmp/gmp
+-BUILD_DIRS += libraries/integer-gmp/mkGmpDerivedConstants
+-endif
+-
+-ifeq "$(INTEGER_LIBRARY)" "integer-gmp2"
+-BUILD_DIRS += libraries/integer-gmp2/gmp
+-else ifneq "$(findstring clean,$(MAKECMDGOALS))" ""
+ BUILD_DIRS += libraries/integer-gmp2/gmp
+-endif
+-
+-ifeq "$(HADDOCK_DOCS)" "YES"
+ BUILD_DIRS += utils/haddock
+ BUILD_DIRS += utils/haddock/doc
+-endif
+-
+ BUILD_DIRS += compiler
+ BUILD_DIRS += utils/hsc2hs
+ BUILD_DIRS += utils/ghc-pkg
+ BUILD_DIRS += utils/testremove
+-ifneq "$(Stage1Only)" "YES"
+ BUILD_DIRS += utils/ghctags
+-endif
+-BUILD_DIRS += utils/dll-split
+ BUILD_DIRS += utils/ghc-pwd
+ BUILD_DIRS += utils/ghc-cabal
+ BUILD_DIRS += utils/hpc
+ BUILD_DIRS += utils/runghc
+ BUILD_DIRS += ghc
+-
+-ifneq "$(BINDIST)" "YES"
+-ifneq "$(CrossCompiling)-$(phase)" "YES-final"
+ BUILD_DIRS += utils/mkUserGuidePart
+-endif
+-endif
+-
+ BUILD_DIRS += docs/users_guide
+ BUILD_DIRS += docs/man
+ BUILD_DIRS += utils/count_lines
+ BUILD_DIRS += utils/compare_sizes
+ 
+ # ----------------------------------------------
+-# Actually include all the sub-ghc.mk's
++# Actually include the sub-ghc.mk's
++
++ifeq "$(CLEANING)" "YES"
++# Don't exclude any BUILD_DIRS when cleaning. When you for example build
++# haddock once, but later set HADDOCK_DOCS back to NO, then 'make clean'
++# should still clean the haddock directory.
++else # CLEANING
++ifeq "$(BINDIST)" "YES"
++BUILD_DIRS := $(filter-out utils/mkdirhier,$(BUILD_DIRS))
++BUILD_DIRS := $(filter-out utils/genprimopcode,$(BUILD_DIRS))
++BUILD_DIRS := $(filter-out bindisttest,$(BUILD_DIRS))
++BUILD_DIRS := $(filter-out utils/genapply,$(BUILD_DIRS))
++BUILD_DIRS := $(filter-out utils/mkUserGuidePart,$(BUILD_DIRS))
++endif
++ifeq "$(HADDOCK_DOCS)" "NO"
++BUILD_DIRS := $(filter-out utils/haddock,$(BUILD_DIRS))
++BUILD_DIRS := $(filter-out utils/haddock/doc,$(BUILD_DIRS))
++endif
++ifeq "$(BUILD_DOCBOOK_HTML) $(BUILD_DOCBOOK_PS) $(BUILD_DOCBOOK_PDF)" "NO NO NO"
++# Don't to build this little utility if we're not building the User's Guide.
++BUILD_DIRS := $(filter-out utils/mkUserGuidePart,$(BUILD_DIRS))
++endif
++ifeq "$(Windows_Host)" "NO"
++BUILD_DIRS := $(filter-out utils/touchy,$(BUILD_DIRS))
++endif
++ifeq "$(GhcUnregisterised)" "YES"
++BUILD_DIRS := $(filter-out driver/split,$(BUILD_DIRS))
++endif
++ifeq "$(GhcWithInterpreter)" "NO"
++# runghc is just GHCi in disguise
++BUILD_DIRS := $(filter-out utils/runghc,$(BUILD_DIRS))
++endif
++ifneq "$(INTEGER_LIBRARY)" "integer-gmp"
++BUILD_DIRS := $(filter-out libraries/integer-gmp/gmp,$(BUILD_DIRS))
++BUILD_DIRS := $(filter-out libraries/integer-gmp/mkGmpDerivedConstants,$(BUILD_DIRS))
++endif
++ifneq "$(INTEGER_LIBRARY)" "integer-gmp2"
++BUILD_DIRS := $(filter-out libraries/integer-gmp2/gmp,$(BUILD_DIRS))
++endif
++ifneq "$(CrossCompiling) $(Stage1Only)" "NO NO"
++# See Note [No stage2 packages when CrossCompiling or Stage1Only].
++# See Note [Stage1Only vs stage=1] in mk/config.mk.in.
++BUILD_DIRS := $(filter-out utils/haddock,$(BUILD_DIRS))
++BUILD_DIRS := $(filter-out utils/haddock/doc,$(BUILD_DIRS))
++BUILD_DIRS := $(filter-out utils/ghctags,$(BUILD_DIRS))
++BUILD_DIRS := $(filter-out utils/mkUserGuidePart,$(BUILD_DIRS))
++endif
++endif # CLEANING
+ 
+ include $(patsubst %, %/ghc.mk, $(BUILD_DIRS))
+ 
+@@ -737,6 +751,11 @@ $(eval $(call clean-target,root,bootstrapping_conf,$(BOOTSTRAPPING_CONF)))
+ # lost).
+ fixed_pkg_prev=
+ $(foreach pkg,$(PACKAGES_STAGE0),$(eval $(call fixed_pkg_dep,$(pkg),dist-boot)))
++# ghc-pkg, unlike other utils that we build with the stage0 compiler (TODO: is
++# this really true?), depends on several boot packages (e.g. Cabal and
++# bin-package-db). They need to be configured before ghc-pkg, so we add a
++# dependency between their package-data.mk files. See also Note
++# [Dependencies between package-data.mk files].
+ utils/ghc-pkg/dist/package-data.mk: $(fixed_pkg_prev)
+ compiler/stage1/package-data.mk:    $(fixed_pkg_prev)
+ endif
+@@ -900,8 +919,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
+@@ -1398,6 +1417,50 @@ endif
+ 	cd libraries/xhtml && ./Setup clean   --builddir=dist-bindist
+ 	cd libraries/xhtml && rm -f Setup Setup.exe Setup.hi Setup.o
+ 
++# Note [No stage2 packages when CrossCompiling or Stage1Only]
++#
++# (first read Note [CrossCompiling vs Stage1Only] and
++#  Note [Stage1Only vs stage=1] in mk/config.mk.in)
++#
++# When either CrossCompiling=YES or Stage1Only=YES, we have to exclude the
++# following packages from the build:
++#   * packages that we build with ghc-stage2 [1]
++#   * packages that depend on the ghc library [2]
++#
++# Here's why:
++#  - first of all, ghc-stage1 can't use stage0's ghc library (it's too old)
++#  - neither do we register the ghc library (compiler/stage1) that we build
++#    with stage0. TODO Why not? We do build it...
++#  - as a result, we need to a) use ghc-stage2 to build packages that depend on
++#    the ghc library (e.g. ghctags [4] and mkUserGuidePart) and b) exclude
++#    those packages when ghc-stage2 is not available.
++#  - when Stage1Only=YES, it's clear that ghc-stage2 is not available (we just
++#    said we didn't want it), so we have to exclude the stage2 packages from
++#    the build. This includes the case where Stage1Only=YES is combined with
++#    CrossCompiling=YES (Building GHC as a cross-compiler [3]).
++#  - when CrossCompiling=YES, but Stage1Only=NO (Cross-compiling GHC itself
++#    [3]), we can not use ghc-stage2 either. The reason is that stage2 doesn't
++#    run on the host platform at all; it is built to run on $(TARGETPLATFORM)"
++#    [5]. Therefore in this case we also have to exclude the stage2 packages
++#    from the build.
++#
++#  [1] find utils -name ghc.mk | xargs grep -l 'build-prog.*,2'
++#
++#  [2]
++#  find utils -name package-data.mk | xargs grep -l 'DEP_NAMES =.* ghc\($\| \)'
++#
++#  [3] https://ghc.haskell.org/trac/ghc/wiki/Building/CrossCompiling
++#
++#  [4] 5fb72555f7b7ab67a33583f33ad9160761ca434f
++#      "ghctags needs the stage2 compiler, since it uses the GHC API."
++#
++#  [5] * bc31dbe8ee22819054df60f5ef219fed393a1c54
++#      "Disable any packages built with stage 2 when cross-compiling
++#       Since we can't run stage 2 on the host."
++#
++#      * 72995160b0b190577b5c0cb8d7bd0426cc455b05
++#      "We cannot use the stage 2 compiler, it runs on $(TARGETPLATFORM)"
++
+ # -----------------------------------------------------------------------------
+ # Numbered phase targets
+ 
+diff --git a/libffi/ghc.mk b/libffi/ghc.mk
+index 59e089d..7e743f6 100644
+--- a/libffi/ghc.mk
++++ b/libffi/ghc.mk
+@@ -65,6 +65,7 @@ $(libffi_STAMP_CONFIGURE): $(TOUCH_DEP)
+ # 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 links which cannot be read by mingw gcc.
++	cp /usr/share/misc/config.sub libffi/build/config.sub
+ 	chmod +x libffi/ln
+ 
+ 	# don't report nonselinux systems as selinux
+diff --git a/rules/build-package-way.mk b/rules/build-package-way.mk
+index 27da099..10d8863 100644
+--- a/rules/build-package-way.mk
++++ b/rules/build-package-way.mk
+@@ -58,17 +58,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 99f7ce9..cb4709b 100644
+--- a/rules/distdir-way-opts.mk
++++ b/rules/distdir-way-opts.mk
+@@ -139,14 +139,6 @@ $1_$2_$3_ALL_HC_OPTS = \
+  $$(if $$(findstring YES,$$($1_$2_SplitObjs)),$$(if $$(findstring dyn,$3),,-split-objs),) \
+  $$(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) \
+  $$($1_$2_DIST_GCC_CC_OPTS) \
+diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs
+index decdb38..f852114 100644
+--- a/utils/ghc-pkg/Main.hs
++++ b/utils/ghc-pkg/Main.hs
+@@ -1,6 +1,7 @@
+ {-# LANGUAGE CPP, TypeSynonymInstances, FlexibleInstances, RecordWildCards,
+              GeneralizedNewtypeDeriving, StandaloneDeriving #-}
+ {-# 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 317aab7..72b244a 100644
+--- a/utils/ghc-pkg/ghc-pkg.cabal
++++ b/utils/ghc-pkg/ghc-pkg.cabal
+@@ -28,7 +28,7 @@ Executable ghc-pkg
+                    bin-package-db,
+                    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..59e12d7
--- /dev/null
+++ b/testing/ghc-bootstrap/bootstrap/x86_64/settings
@@ -0,0 +1,32 @@
+[("GCC extra via C opts", " -fwrapv"),
+ ("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", "/usr/lib/ghc/llc-3.5"),
+ ("LLVM opt command", "/usr/lib/ghc/opt-3.5")
+ ]
-- 
2.7.0

---

---

From: Mitch Tishmack <[email-masked]>
Date: Tue, 1 Mar 2016 19:28:56 -0600

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

diff --git a/testing/ghc/APKBUILD b/testing/ghc/APKBUILD
new file mode 100755
index 0000000..284ed52
--- /dev/null
+++ b/testing/ghc/APKBUILD
@@ -0,0 +1,87 @@
+#-*-mode: Shell-script; coding: utf-8;-*-
+# Contributor: Mitch Tishmack <[email-masked]>
+# Maintainer: Mitch Tishmack <[email-masked]>
+pkgname=ghc
+pkgdesc="The Glasgow haskell compiler"
+apkgver=7.10.3b
+pkgver=$(echo ${apkgver} | tr -d '[a-z]')
+pkgrel=1
+url="http://haskell.org"
+subpackages="$pkgname-doc $pkgname-dev"
+arch="x86_64"
+# 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
+# ghc-llvm-X.Y 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 ghc-llvm-3.5"
+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
+	"
+
+_builddir="$srcdir/$pkgname-$pkgver"
+
+# ghc source
+source="
+	https://www.haskell.org/ghc/dist/$pkgver/ghc-$apkgver-src.tar.bz2
+	"
+
+_ghc_build_tmp="$_builddir/tmp"
+
+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_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-gmp2" >> mk/build.mk || return 1
+	echo "BeConservative       = YES" >> mk/build.mk || return 1
+	echo "GhcLibWays           = v p dyn" >> mk/build.mk || return 1
+	echo "BUILD_DOCBOOK_HTML   = NO" >> mk/build.mk  || return 1
+	echo "BUILD_DOCBOOK_PS     = NO" >> mk/build.mk || return 1
+	echo "BUILD_DOCBOOK_PDF    = NO" >> mk/build.mk || return 1
+	./configure \
+		--prefix=/usr \
+		--sysconfdir=/etc \
+		--mandir=/usr/share/man \
+		--infodir=/usr/share/info \
+		--localstatedir=/var \
+		--with-ld=ld.gold \
+		--with-llc=/usr/lib/ghc/llc-3.5 \
+		--with-opt=/usr/lib/ghc/opt-3.5 || 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
+}
+
+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)"
+}
-- 
2.7.0

---