aboutsummaryrefslogtreecommitdiffstats
path: root/community
diff options
context:
space:
mode:
Diffstat (limited to 'community')
-rw-r--r--community/ghc/0000-alpine.patch11
-rw-r--r--community/ghc/0000-bootstrap.patch16
-rw-r--r--community/ghc/0001-rm-ghc-pwd.patch184
-rw-r--r--community/ghc/0002-Correct-issue-with-libffi-and-glibc.patch28
-rw-r--r--community/ghc/0003-do-not-use-SHELL.patch71
-rw-r--r--community/ghc/0004-reproducible-tmp-names.patch43
-rw-r--r--community/ghc/0005-buildpath-abi-stability.patch25
-rw-r--r--community/ghc/0006-fix-madvise.patch63
-rw-r--r--community/ghc/0007-build-hp2ps-twice.patch25
-rw-r--r--community/ghc/0008-build-unlit-twice.patch58
-rw-r--r--community/ghc/APKBUILD201
-rw-r--r--community/ghc/ghc.post-install5
12 files changed, 730 insertions, 0 deletions
diff --git a/community/ghc/0000-alpine.patch b/community/ghc/0000-alpine.patch
new file mode 100644
index 0000000000..0487096862
--- /dev/null
+++ b/community/ghc/0000-alpine.patch
@@ -0,0 +1,11 @@
+--- ghc-8.0.2/aclocal.m4.orig 2017-02-17 12:00:45.179765870 +0000
++++ ghc-8.0.2/aclocal.m4 2017-02-17 12:00:56.033299769 +0000
+@@ -227,7 +227,7 @@
+
+ checkVendor() {
+ case [$]1 in
+- dec|unknown|hp|apple|next|sun|sgi|ibm|montavista|portbld)
++ dec|unknown|hp|apple|next|sun|sgi|ibm|montavista|portbld|alpine)
+ ;;
+ *)
+ echo "Unknown vendor [$]1"
diff --git a/community/ghc/0000-bootstrap.patch b/community/ghc/0000-bootstrap.patch
new file mode 100644
index 0000000000..95a3f5de4f
--- /dev/null
+++ b/community/ghc/0000-bootstrap.patch
@@ -0,0 +1,16 @@
+diff --git a/ghc.mk b/ghc.mk
+index 5e4ecc6..a07ff73 100644
+--- a/ghc.mk
++++ b/ghc.mk
+@@ -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/community/ghc/0001-rm-ghc-pwd.patch b/community/ghc/0001-rm-ghc-pwd.patch
new file mode 100644
index 0000000000..cf4417547b
--- /dev/null
+++ b/community/ghc/0001-rm-ghc-pwd.patch
@@ -0,0 +1,184 @@
+commit 4c56ad36ee0d1f8b6f1b2bc0d8fff1c9acd1a389
+Author: Thomas Miedema <thomasmiedema@gmail.com>
+Date: Mon Jan 4 18:29:49 2016 +0100
+
+ Build system: delete ghc-pwd
+
+ On Windows, with msys2, `pwd` works (as can be seen by the use of `pwd`
+ that slipped into the validate script), so there is really no need for
+ `ghc-pwd` anymore.
+
+ Test Plan: try it
+
+ Reviewers: austin, bgamari, Phyx
+
+ Reviewed By: Phyx
+
+ Subscribers: Phyx, erikd
+
+ Differential Revision: https://phabricator.haskell.org/D1731
+
+diff --git a/aclocal.m4 b/aclocal.m4
+index 8e97726..0c93de4 100644
+--- a/aclocal.m4
++++ b/aclocal.m4
+@@ -1737,33 +1737,9 @@ AC_DEFUN([FP_CURSES],
+ # Calculate absolute path to build tree
+ # --------------------------------------------------------------
+
+-AC_DEFUN([FP_INTREE_GHC_PWD],[
+-AC_MSG_NOTICE(Building in-tree ghc-pwd)
+- dnl This would be
+- dnl make -C utils/ghc-pwd clean && make -C utils/ghc-pwd
+- dnl except we don't want to have to know what make is called. Sigh.
+- rm -rf utils/ghc-pwd/dist-boot
+- mkdir utils/ghc-pwd/dist-boot
+- dnl If special linker flags are needed to build things, then allow
+- dnl the user to pass them in via LDFLAGS.
+- changequote(, )dnl
+- GHC_LDFLAGS=`perl -e 'foreach (@ARGV) { print "-optl$_ " }' -- $LDFLAGS`
+- changequote([, ])dnl
+- if ! "$WithGhc" $GHC_LDFLAGS -v0 -no-user-$GHC_PACKAGE_DB_FLAG -hidir utils/ghc-pwd/dist-boot -odir utils/ghc-pwd/dist-boot -stubdir utils/ghc-pwd/dist-boot --make utils/ghc-pwd/Main.hs -o utils/ghc-pwd/dist-boot/ghc-pwd
+- then
+- AC_MSG_ERROR([Building ghc-pwd failed])
+- fi
+-
+- GHC_PWD=utils/ghc-pwd/dist-boot/ghc-pwd
+-])
+-
+-AC_DEFUN([FP_BINDIST_GHC_PWD],[
+- GHC_PWD=utils/ghc-pwd/dist-install/build/tmp/ghc-pwd-bindist
+-])
+-
+ AC_DEFUN([FP_FIND_ROOT],[
+ AC_MSG_CHECKING(for path to top of build tree)
+- hardtop=`$GHC_PWD`
++ hardtop=`pwd`
+
+ dnl Remove common automounter nonsense
+ hardtop=`echo $hardtop | sed 's|^/tmp_mnt.*\(/local/.*\)$|\1|' | sed 's|^/tmp_mnt/|/|'`
+diff --git a/configure.ac b/configure.ac
+index 042b417..ab82bb0 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -26,6 +26,8 @@ AC_INIT([The Glorious Glasgow Haskell Compilation System], [8.1], [glasgow-haske
+ # checkout), then we ship a file 'VERSION' containing the full version
+ # when the source distribution was created.
+
++FP_FIND_ROOT
++
+ if test ! -f mk/config.h.in; then
+ echo "mk/config.h.in doesn't exist: perhaps you haven't run 'perl boot'?"
+ exit 1
+@@ -258,10 +260,6 @@ AC_ARG_WITH(hc,
+ )
+ AC_SUBST(WithHc)
+
+-# This uses GHC, so put it after the "GHC is required" check above:
+-FP_INTREE_GHC_PWD
+-FP_FIND_ROOT
+-
+ fail() {
+ echo >&2
+ echo "$1" >&2
+diff --git a/distrib/configure.ac.in b/distrib/configure.ac.in
+index 0f68a52..4d57cd8 100644
+--- a/distrib/configure.ac.in
++++ b/distrib/configure.ac.in
+@@ -6,7 +6,6 @@ dnl
+
+ AC_INIT([The Glorious Glasgow Haskell Compilation System], [@ProjectVersion@], [glasgow-haskell-bugs@haskell.org], [ghc])
+
+-FP_BINDIST_GHC_PWD
+ FP_FIND_ROOT
+
+ dnl--------------------------------------------------------------------
+diff --git a/ghc.mk b/ghc.mk
+index ba708a1..3ccc496 100644
+--- a/ghc.mk
++++ b/ghc.mk
+@@ -516,7 +516,6 @@ $(foreach pkg,$(PACKAGES_STAGE1),$(eval $(call fixed_pkg_dep,$(pkg),dist-install
+ # 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)
+@@ -660,7 +659,6 @@ BUILD_DIRS += utils/testremove
+ BUILD_DIRS += utils/ghctags
+ BUILD_DIRS += utils/check-api-annotations
+ BUILD_DIRS += utils/dll-split
+-BUILD_DIRS += utils/ghc-pwd
+ BUILD_DIRS += utils/ghc-cabal
+ BUILD_DIRS += utils/hpc
+ BUILD_DIRS += utils/runghc
+@@ -1020,7 +1018,6 @@ $(eval $(call bindist-list,.,\
+ mk/config.mk.in \
+ $(INPLACE_BIN)/mkdirhier \
+ utils/ghc-cabal/dist-install/build/tmp/ghc-cabal \
+- utils/ghc-pwd/dist-install/build/tmp/ghc-pwd \
+ $(BINDIST_WRAPPERS) \
+ $(BINDIST_PERL_SOURCES) \
+ $(BINDIST_LIBS) \
+@@ -1366,9 +1363,6 @@ distclean : clean
+ # Internal files generated by ./configure for itself.
+ $(call removeFiles,config.cache config.status config.log)
+
+-# ./configure build ghc-pwd in utils/ghc-pwd/dist-boot, so clean it up.
+- $(call removeTrees,utils/ghc-pwd/dist-boot)
+-
+ # The root Makefile makes .old versions of some files that configure
+ # generates, so we clean those too.
+ $(call removeFiles,mk/config.mk.old)
+diff --git a/utils/ghc-pwd/Main.hs b/utils/ghc-pwd/Main.hs
+deleted file mode 100644
+index 91a5606..0000000
+--- a/utils/ghc-pwd/Main.hs
++++ /dev/null
+@@ -1,22 +0,0 @@
+-
+-module Main where
+-
+-import System.Directory
+-import System.Environment
+-import System.Exit
+-import System.IO
+-
+-main :: IO ()
+-main = do
+- args <- getArgs
+- case args of
+- [] -> do d <- getCurrentDirectory
+- putStr $ map forwardifySlashes d
+- _ -> do hPutStrLn stderr ("Bad args: " ++ show args)
+- hPutStrLn stderr "Usage: ghc-pwd"
+- exitFailure
+-
+-forwardifySlashes :: Char -> Char
+-forwardifySlashes '\\' = '/'
+-forwardifySlashes c = c
+-
+diff --git a/utils/ghc-pwd/Setup.hs b/utils/ghc-pwd/Setup.hs
+deleted file mode 100644
+index 9a994af..0000000
+--- a/utils/ghc-pwd/Setup.hs
++++ /dev/null
+@@ -1,2 +0,0 @@
+-import Distribution.Simple
+-main = defaultMain
+diff --git a/utils/ghc-pwd/ghc.mk b/utils/ghc-pwd/ghc.mk
+deleted file mode 100644
+index ac6bc76..0000000
+--- a/utils/ghc-pwd/ghc.mk
++++ /dev/null
+@@ -1,9 +0,0 @@
+-
+-utils/ghc-pwd_USES_CABAL = YES
+-utils/ghc-pwd_PACKAGE = ghc-pwd
+-utils/ghc-pwd_dist-install_INSTALL_INPLACE = YES
+-utils/ghc-pwd_dist-install_WANT_BINDIST_WRAPPER = YES
+-utils/ghc-pwd_dist-install_PROGNAME = ghc-pwd
+-
+-$(eval $(call build-prog,utils/ghc-pwd,dist-install,1))
+-
diff --git a/community/ghc/0002-Correct-issue-with-libffi-and-glibc.patch b/community/ghc/0002-Correct-issue-with-libffi-and-glibc.patch
new file mode 100644
index 0000000000..87420f9928
--- /dev/null
+++ b/community/ghc/0002-Correct-issue-with-libffi-and-glibc.patch
@@ -0,0 +1,28 @@
+From 843bd68ea83ba011d593ad7162d1df89c230004b Mon Sep 17 00:00:00 2001
+From: Mitch Tishmack <mitch.tishmack@gmail.com>
+Date: Sat, 15 Oct 2016 21:53:13 -0500
+Subject: [PATCH 1/1] Correct issue with libffi and glibc
+
+Ref: https://github.com/mitchty/alpine-linux-ghc-bootstrap/issues/16
+
+Shamelessly learnt from here
+https://github.com/nilcons/ghc-musl/blob/master/ghc-musl/Dockerfile#L24
+---
+ libffi/ghc.mk | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/libffi/ghc.mk b/libffi/ghc.mk
+index 404cce9..2034873 100644
+--- a/libffi/ghc.mk
++++ b/libffi/ghc.mk
+@@ -61,6 +61,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.
++ sed -i s/__gnu_linux__/1/ libffi/build/src/closures.c
+ chmod +x libffi/ln
+
+ # We need to use -MMD rather than -MD, as otherwise we get paths
+--
+2.9.0
+
diff --git a/community/ghc/0003-do-not-use-SHELL.patch b/community/ghc/0003-do-not-use-SHELL.patch
new file mode 100644
index 0000000000..540efa92b1
--- /dev/null
+++ b/community/ghc/0003-do-not-use-SHELL.patch
@@ -0,0 +1,71 @@
+Description: Do not use $SHELL
+ as $SHELL is the user's preferred interactive shell. We do not want this to
+ leak into the wrapper scripts.
+Author: Joachim Breitner <nomeata@debian.org>
+
+Index: ghc/driver/ghci/ghc.mk
+===================================================================
+--- ghc.orig/driver/ghci/ghc.mk 2016-07-07 12:40:40.690866042 +0200
++++ ghc/driver/ghci/ghc.mk 2016-07-07 12:40:40.686863966 +0200
+@@ -21,7 +21,7 @@
+ $(INSTALL_DIR) "$(DESTDIR)$(bindir)"
+ $(call removeFiles, "$(WRAPPER)")
+ $(CREATE_SCRIPT) "$(WRAPPER)"
+- echo '#!$(SHELL)' >> "$(WRAPPER)"
++ echo '#!/bin/sh' >> "$(WRAPPER)"
+ echo 'exec "$(bindir)/ghc-$(ProjectVersion)" --interactive "$$@"' >> "$(WRAPPER)"
+ $(EXECUTABLE_FILE) "$(WRAPPER)"
+ $(call removeFiles,"$(DESTDIR)$(bindir)/ghci")
+@@ -56,7 +56,7 @@
+ install_driver_ghcii:
+ $(INSTALL_DIR) "$(DESTDIR)$(bindir)"
+ $(call removeFiles,"$(GHCII_SCRIPT)")
+- echo "#!$(SHELL)" >> $(GHCII_SCRIPT)
++ echo "#!/bin/sh" >> $(GHCII_SCRIPT)
+ echo 'exec "$$(dirname "$$0")"/ghc --interactive "$$@"' >> $(GHCII_SCRIPT)
+ $(EXECUTABLE_FILE) $(GHCII_SCRIPT)
+ cp $(GHCII_SCRIPT) $(GHCII_SCRIPT_VERSIONED)
+Index: ghc/rules/shell-wrapper.mk
+===================================================================
+--- ghc.orig/rules/shell-wrapper.mk 2016-07-07 12:40:40.690866042 +0200
++++ ghc/rules/shell-wrapper.mk 2016-07-07 12:40:40.686863966 +0200
+@@ -41,7 +41,7 @@
+ endif
+ $$($1_$2_INPLACE_WRAPPER): $$($1_$2_INPLACE)
+ $$(call removeFiles, $$@)
+- echo '#!$$(SHELL)' >> $$@
++ echo '#!/bin/sh' >> $$@
+ echo 'executablename="$$(TOP)/$$<"' >> $$@
+ echo 'datadir="$$(TOP)/$$(INPLACE_LIB)"' >> $$@
+ echo 'bindir="$$(TOP)/$$(INPLACE_BIN)"' >> $$@
+@@ -80,7 +80,7 @@
+ $$(INSTALL_DIR) "$$(DESTDIR)$$(bindir)"
+ $$(call removeFiles, "$$(WRAPPER)")
+ $$(CREATE_SCRIPT) "$$(WRAPPER)"
+- echo '#!$$(SHELL)' >> "$$(WRAPPER)"
++ echo '#!/bin/sh' >> "$$(WRAPPER)"
+ echo 'exedir="$$(ghclibexecdir)/bin"' >> "$$(WRAPPER)"
+ echo 'exeprog="$$($1_$2_PROG)"' >> "$$(WRAPPER)"
+ echo 'executablename="$$$$exedir/$$$$exeprog"' >> "$$(WRAPPER)"
+@@ -106,7 +106,7 @@
+
+ $$($1_$2_BINDIST_WRAPPER): $1/$2/build/tmp/$$($1_$2_PROG)
+ $$(call removeFiles, $$@)
+- echo '#!$$(SHELL)' >> $$@
++ echo '#!/bin/sh' >> $$@
+ ifeq "$$(DYNAMIC_GHC_PROGRAMS)" "YES"
+ echo '$$(call prependLibraryPath,$$($1_$2_DEP_LIB_REL_DIRS_SEARCHPATH))' >> $$@
+ endif
+Index: ghc/utils/mkdirhier/ghc.mk
+===================================================================
+--- ghc.orig/utils/mkdirhier/ghc.mk 2016-07-07 12:40:40.690866042 +0200
++++ ghc/utils/mkdirhier/ghc.mk 2016-07-07 12:40:40.686863966 +0200
+@@ -14,7 +14,7 @@
+ mkdir -p $(INPLACE_BIN)
+ mkdir -p $(INPLACE_LIB)
+ $(call removeFiles,$@)
+- echo '#!$(SHELL)' >> $@
++ echo '#!/bin/sh' >> $@
+ cat utils/mkdirhier/mkdirhier.sh >> $@
+ $(EXECUTABLE_FILE) $@
+
diff --git a/community/ghc/0004-reproducible-tmp-names.patch b/community/ghc/0004-reproducible-tmp-names.patch
new file mode 100644
index 0000000000..a0417f145d
--- /dev/null
+++ b/community/ghc/0004-reproducible-tmp-names.patch
@@ -0,0 +1,43 @@
+This is an attempt to make GHC build reproducible. The name of .c files may end
+up in the resulting binary (in the debug section), but not the directory.
+
+Instead of using the process id, create a hash from the command line arguments,
+and assume that is going to be unique.
+
+Index: ghc/compiler/main/SysTools.hs
+===================================================================
+--- ghc.orig/compiler/main/SysTools.hs 2016-04-23 17:57:12.812255430 +0200
++++ ghc/compiler/main/SysTools.hs 2016-04-23 17:57:12.808255337 +0200
+@@ -65,6 +65,7 @@
+ import Util
+ import DynFlags
+ import Exception
++import Fingerprint
+
+ import LlvmCodeGen.Base (llvmVersionStr, supportedLlvmVersion)
+
+@@ -1158,8 +1159,8 @@
+ mapping <- readIORef dir_ref
+ case Map.lookup tmp_dir mapping of
+ Nothing -> do
+- pid <- getProcessID
+- let prefix = tmp_dir </> "ghc" ++ show pid ++ "_"
++ pid <- getStableProcessID
++ let prefix = tmp_dir </> "ghc" ++ pid ++ "_"
+ mask_ $ mkTempDir prefix
+ Just dir -> return dir
+ where
+@@ -1575,6 +1576,13 @@
+ getProcessID = System.Posix.Internals.c_getpid >>= return . fromIntegral
+ #endif
+
++-- Debian-specific hack to get reproducible output, by not using the "random"
++-- pid, but rather something determinisic
++getStableProcessID :: IO String
++getStableProcessID = do
++ args <- getArgs
++ return $ take 4 $ show $ fingerprintString $ unwords args
++
+ -- Divvy up text stream into lines, taking platform dependent
+ -- line termination into account.
+ linesPlatform :: String -> [String]
diff --git a/community/ghc/0005-buildpath-abi-stability.patch b/community/ghc/0005-buildpath-abi-stability.patch
new file mode 100644
index 0000000000..8add0fcd1c
--- /dev/null
+++ b/community/ghc/0005-buildpath-abi-stability.patch
@@ -0,0 +1,25 @@
+Forwarded to https://ghc.haskell.org/trac/ghc/ticket/10424
+
+Index: ghc/compiler/iface/MkIface.hs
+===================================================================
+--- ghc.orig/compiler/iface/MkIface.hs 2016-04-19 09:26:40.075170754 +0200
++++ ghc/compiler/iface/MkIface.hs 2016-04-19 09:26:40.071170684 +0200
+@@ -556,7 +556,7 @@
+ iface_hash <- computeFingerprint putNameLiterally
+ (mod_hash,
+ ann_fn (mkVarOcc "module"), -- See mkIfaceAnnCache
+- mi_usages iface0,
++ usages,
+ sorted_deps,
+ mi_hpc iface0)
+
+@@ -589,6 +589,9 @@
+ (non_orph_fis, orph_fis) = mkOrphMap ifFamInstOrph (mi_fam_insts iface0)
+ fix_fn = mi_fix_fn iface0
+ ann_fn = mkIfaceAnnCache (mi_anns iface0)
++ -- Do not allow filenames to affect the interface
++ usages = [ case u of UsageFile _ fp -> UsageFile "" fp; _ -> u | u <- mi_usages iface0 ]
++
+
+ getOrphanHashes :: HscEnv -> [Module] -> IO [Fingerprint]
+ getOrphanHashes hsc_env mods = do
diff --git a/community/ghc/0006-fix-madvise.patch b/community/ghc/0006-fix-madvise.patch
new file mode 100644
index 0000000000..0672001722
--- /dev/null
+++ b/community/ghc/0006-fix-madvise.patch
@@ -0,0 +1,63 @@
+From 6576bf83cdf4eac05eb88a24aa934a736c91e3da Mon Sep 17 00:00:00 2001
+From: Ben Gamari <bgamari.foss@gmail.com>
+Date: Thu, 1 Dec 2016 12:55:23 -0500
+Subject: [PATCH] rts: Ensure we always give MADV_DONTNEED a chance in
+ osDecommitMemory
+
+As described in #12865, newer Linux kernels support both MADV_FREE and
+MADV_DONTNEED. Previously a runtime would fail to try MADV_DONTNEED if
+MADV_FREE failed (e.g. since the kernel which the image is running on
+doesn't support the latter). Now we try MADV_DONTNEED if MADV_FREE
+failed to ensure that binaries compiled on a kernel supporting MADV_FREE
+don't fail on decommit.
+
+Test Plan: Validate
+
+Reviewers: austin, erikd, simonmar
+
+Reviewed By: simonmar
+
+Subscribers: thomie
+
+Differential Revision: https://phabricator.haskell.org/D2780
+
+GHC Trac Issues: #12865
+---
+ rts/posix/OSMem.c | 19 ++++++++++++++++---
+ 1 file changed, 16 insertions(+), 3 deletions(-)
+
+diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c
+index 5291745..beffeda 100644
+--- a/rts/posix/OSMem.c
++++ b/rts/posix/OSMem.c
+@@ -541,11 +541,24 @@ void osDecommitMemory(void *at, W_ size)
+
+ #ifdef MADV_FREE
+ // Try MADV_FREE first, FreeBSD has both and MADV_DONTNEED
+- // just swaps memory out
++ // just swaps memory out. Linux >= 4.5 has both DONTNEED and FREE; either
++ // will work as they both allow the system to free anonymous pages.
++ // It is important that we try both methods as the kernel which we were
++ // built on may differ from the kernel we are now running on.
+ r = madvise(at, size, MADV_FREE);
+-#else
+- r = madvise(at, size, MADV_DONTNEED);
++ if(r < 0) {
++ if (errno == EINVAL) {
++ // Perhaps the system doesn't support MADV_FREE; fall-through and
++ // try MADV_DONTNEED.
++ } else {
++ sysErrorBelch("unable to decommit memory");
++ }
++ } else {
++ return;
++ }
+ #endif
++
++ r = madvise(at, size, MADV_DONTNEED);
+ if(r < 0)
+ sysErrorBelch("unable to decommit memory");
+ }
+--
+1.9.1
+
diff --git a/community/ghc/0007-build-hp2ps-twice.patch b/community/ghc/0007-build-hp2ps-twice.patch
new file mode 100644
index 0000000000..47e8a8f266
--- /dev/null
+++ b/community/ghc/0007-build-hp2ps-twice.patch
@@ -0,0 +1,25 @@
+--- a/utils/hp2ps/ghc.mk 2017-02-25 22:37:12.000000000 -0600
++++ b/utils/hp2ps/ghc.mk 2017-02-25 23:21:33.000000000 -0600
+@@ -17,10 +17,21 @@
+ Utilities.c
+ utils/hp2ps_dist_EXTRA_LIBRARIES = m
+ utils/hp2ps_dist_PROGNAME = $(CrossCompilePrefix)hp2ps
+-utils/hp2ps_dist_INSTALL = YES
++utils/hp2ps_dist_INSTALL = NO
+ utils/hp2ps_dist_INSTALL_INPLACE = YES
+
+ utils/hp2ps_CC_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
+
+ $(eval $(call build-prog,utils/hp2ps,dist,0))
+
++utils/hp2ps_dist-install_C_SRCS = AreaBelow.c Curves.c Error.c Main.c \
++ Reorder.c TopTwenty.c AuxFile.c Deviation.c \
++ HpFile.c Marks.c Scale.c TraceElement.c \
++ Axes.c Dimensions.c Key.c PsFile.c Shade.c \
++ Utilities.c
++utils/hp2ps_dist-install_PROGNAME = hp2ps
++utils/hp2ps_dist-install_TOPDIR = YES
++utils/hp2ps_dist-install_INSTALL = YES
++utils/hp2ps_dist-install_INSTALL_INPLACE = NO
++
++$(eval $(call build-prog,utils/hp2ps,dist-install,1))
diff --git a/community/ghc/0008-build-unlit-twice.patch b/community/ghc/0008-build-unlit-twice.patch
new file mode 100644
index 0000000000..91380a5c26
--- /dev/null
+++ b/community/ghc/0008-build-unlit-twice.patch
@@ -0,0 +1,58 @@
+From eba93774c3ce2f151e7c72f6d068b753f24dbcfa Mon Sep 17 00:00:00 2001
+From: Thomas Miedema <thomasmiedema@gmail.com>
+Date: Wed, 15 Jun 2016 14:56:46 +0200
+Subject: [PATCH] Build system: build unlit twice
+
+See Note [Why build certain utils twice?] in utils/ghc-pkg/ghc.mk
+---
+ utils/ghc-pkg/ghc.mk | 7 ++++++-
+ utils/unlit/ghc.mk | 10 +++++++++-
+ 2 files changed, 15 insertions(+), 2 deletions(-)
+
+diff --git a/utils/ghc-pkg/ghc.mk b/utils/ghc-pkg/ghc.mk
+index f7d97de..410de72 100644
+--- a/utils/ghc-pkg/ghc.mk
++++ b/utils/ghc-pkg/ghc.mk
+@@ -27,7 +27,7 @@ utils/ghc-pkg_PACKAGE = ghc-pkg
+ # Note [Why build certain utils twice?]
+ #
+ # We build certain utils twice: once with stage0, and once with stage1.
+-# Examples are ghc-pkg and hsc2hs.
++# Examples are ghc-pkg, hsc2hs and unlit.
+ #
+ # These tools are needed during the bootstrapping process, so we have to use
+ # stage0 to build them at first (stage1 doesn't exist yet). (side note: they're
+@@ -38,6 +38,11 @@ utils/ghc-pkg_PACKAGE = ghc-pkg
+ # dynamically linked. But the stage0 copies are either statically linked, or
+ # linked against libraries on the build machine.
+ #
++# Another reason why we can't install the stage0 copies is that they are
++# built to run on the build(=host) platform, but when installing a
++# "cross-compiled stage2 compiler" we need copies that run on the target
++# platform.
++#
+ # Therefore we build fresh copies, using the stage1 compiler, and install them
+ # when you run 'make install'. They are not used for any other purpose.
+
+diff --git a/utils/unlit/ghc.mk b/utils/unlit/ghc.mk
+index e947989..6805c4e 100644
+--- a/utils/unlit/ghc.mk
++++ b/utils/unlit/ghc.mk
+@@ -13,8 +13,16 @@
+ utils/unlit_dist_C_SRCS = unlit.c
+ utils/unlit_dist_PROGNAME = unlit
+ utils/unlit_dist_TOPDIR = YES
+-utils/unlit_dist_INSTALL = YES
++utils/unlit_dist_INSTALL = NO
+ utils/unlit_dist_INSTALL_INPLACE = YES
+
+ $(eval $(call build-prog,utils/unlit,dist,0))
+
++utils/unlit_dist-install_C_SRCS = unlit.c
++utils/unlit_dist-install_PROGNAME = unlit
++utils/unlit_dist-install_TOPDIR = YES
++utils/unlit_dist-install_INSTALL = YES
++utils/unlit_dist-install_INSTALL_INPLACE = NO
++
++# See Note [Why build certain utils twice?].
++$(eval $(call build-prog,utils/unlit,dist-install,1))
diff --git a/community/ghc/APKBUILD b/community/ghc/APKBUILD
new file mode 100644
index 0000000000..9b922eb4ae
--- /dev/null
+++ b/community/ghc/APKBUILD
@@ -0,0 +1,201 @@
+# Maintainer: Mitch Tishmack <mitch.tishmack@gmail.com>
+pkgname=ghc
+pkgver=8.0.2
+pkgrel=6
+pkgdesc="The Glasgow Haskell Compiler"
+url="http://haskell.org"
+arch="x86_64 armhf"
+# Note ghc's license is basically BSD-3. If you'd like to know more visit:
+# * https://www.haskell.org/ghc/license
+# * https://ghc.haskell.org/trac/ghc/wiki/Licensing
+license="custom:BSD-3"
+# Note 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
+depends="gmp-dev perl gcc>=6.2.1 llvm3.7 libffi-dev"
+makedepends_build="$pkgname autoconf cpio binutils-gold paxmark libffi-dev ncurses-dev"
+makedepends_host="linux-headers musl-dev zlib-dev gmp-dev binutils-dev libffi-dev ncurses-dev"
+makedepends="$makedepends_build $makedepends_host"
+checkdepends="python2"
+provides="
+ haskell-cabal=1.24.2.0
+ haskell-bytestring=0.10.8.1
+ haskell-containers=0.5.7.1
+ haskell-deepseq=1.4.2.0
+ haskell-directory=1.3.0.0
+ haskell-filepath=1.4.1.1
+ haskell-ghc=8.0.2
+ haskell-ghc-boot=8.0.2
+ haskell-ghc-boot-th=8.0.2
+ haskell-ghc-prim=0.5.0.0
+ haskell-ghci=8.0.2
+ haskell-haskeline=0.7.3.0
+ haskell-hoopl=3.10.2.1
+ haskell-hpc=0.6.0.3
+ haskell-integer-gmp=1.0.0.1
+ haskell-pretty=1.1.3.3
+ haskell-process=1.4.3.0
+ haskell-rts=1.0
+ haskell-template-haskell=2.11.1.0
+ haskell-terminfo=0.4.0.2
+ haskell-time=1.6.0.1
+ haskell-transformers=0.5.2.0
+ haskell-unix=2.7.2.1
+ haskell-xhtml=3000.2.1
+ "
+subpackages="$pkgname-doc $pkgname-dev"
+install="$pkgname.post-install"
+options="!strip" # we strip it manually in build()
+source="http://downloads.haskell.org/~ghc/$pkgver/ghc-$pkgver-src.tar.xz
+ http://downloads.haskell.org/~ghc/$pkgver/ghc-$pkgver-testsuite.tar.xz
+ 0000-alpine.patch
+ 0000-bootstrap.patch
+ 0001-rm-ghc-pwd.patch
+ 0002-Correct-issue-with-libffi-and-glibc.patch
+ 0003-do-not-use-SHELL.patch
+ 0004-reproducible-tmp-names.patch
+ 0005-buildpath-abi-stability.patch
+ 0006-fix-madvise.patch
+ 0007-build-hp2ps-twice.patch
+ 0008-build-unlit-twice.patch
+ "
+builddir="$srcdir/$pkgname-$pkgver"
+
+prepare() {
+ default_prepare
+
+ cp mk/build.mk.sample mk/build.mk
+
+ cat >> mk/build.mk <<-EOF
+ BuildFlavour = perf-llvm
+ INTEGER_LIBRARY = integer-gmp
+ BeConservative = YES
+ V = 0
+ GhcStage3HcOpts += -O3
+ SplitSections = YES
+ EOF
+
+ if [ "$CBUILD" != "$CTARGET" ]; then
+ # cross-build
+ cat >> mk/build.mk <<-EOF
+ HADDOCK_DOCS = NO
+ BUILD_SPHINX_HTML = NO
+ BUILD_SPHINX_PS = NO
+ BUILD_SPHINX_PDF = NO
+ EOF
+ fi
+
+ # Due to patches to the configure script
+ autoreconf
+}
+
+build() {
+ cd "$builddir"
+
+ local ffi_inc=$(pkg-config libffi --cflags-only-I); ffi_inc="${ffi_inc%% }"
+ local ffi_lib=$(pkg-config libffi --libs-only-L); ffi_lib="${ffi_lib%% }"
+
+ # NOTE: ghc build system requires host == build, and it ends up
+ # compiling the cross-compiler (stage1) and cross-compiling with
+ # that the native compiler (stage2)
+ ./configure \
+ --build=$CBUILD \
+ --host=$CBUILD \
+ --target=$CTARGET \
+ --prefix=/usr \
+ --with-system-libffi \
+ ${ffi_inc:+--with-ffi-includes="${ffi_inc#-I}"} \
+ ${ffi_lib:+--with-ffi-libraries="${ffi_lib#-L}"} \
+ --with-ar=${CROSS_COMPILE}ar \
+ --with-nm=${CROSS_COMPILE}nm \
+ --with-ranlib=${CROSS_COMPILE}ranlib \
+ --with-objdump=${CROSS_COMPILE}objdump \
+ --with-ld=${CROSS_COMPILE}ld.gold \
+ --with-ld.gold=${CROSS_COMPILE}ld.gold
+ make
+}
+
+check() {
+ cd "$builddir/testsuite"
+ make fast THREADS=$JOBS
+}
+
+doc() {
+ default_doc
+ install -Dm644 "$builddir/LICENSE" \
+ "$subpkgdir/usr/share/licenses/$subpkgname/LICENSE"
+}
+
+package() {
+ local ghclib="usr/lib/ghc-$pkgver"
+ local newpath path target
+
+ cd "$builddir"
+ make -j1 DESTDIR="$pkgdir" install
+
+ cd "$pkgdir"
+
+ # Fixup install tree if needed.
+ if [ -d usr/lib/$CTARGET-ghc-$pkgver ]; then
+ # different location
+ ghclib="usr/lib/$CTARGET-ghc-$pkgver"
+
+ # Rename binaries and fix links.
+ local path; for path in usr/bin/"$CTARGET"-*; do
+ newpath="${path//$CTARGET-/}"
+
+ if [ -h "$path" ]; then
+ target="$(readlink $path)"
+ ln -sf "${target//$CTARGET-/}" "$newpath"
+ rm "$path"
+ else
+ mv "$path" "$newpath"
+ fi
+ done
+
+ # Remove triplet prefix from settings -- the intention is
+ # that the native compiler will use native gcc/ld on the target.
+ sed -i "s|$CTARGET-||g" usr/lib/$CTARGET-ghc-$pkgver/settings
+ fi
+
+ # Can't do a full strip on archives.
+ find . -type f \( -name "*.so" -o -name "*.a" \) \
+ -exec ${CROSS_COMPILE}strip --strip-unneeded {} \;
+ find $ghclib/bin -type f -exec ${CROSS_COMPILE}strip {} \;
+
+ paxmark -m \
+ $ghclib/bin/ghc \
+ $ghclib/bin/ghc-iserv \
+ $ghclib/bin/ghc-iserv-dyn \
+ $ghclib/bin/ghc-iserv-prof
+}
+
+# Like debian, we split apart the profiled archives/etc...
+# This drastically reduces the install size of the ghc pkg.
+dev() {
+ pkgdesc="$pkgdesc (development files)"
+ depends="$pkgname=$pkgver-r$pkgrel"
+
+ cd "$pkgdir"
+
+ install -dm755 "$subpkgdir"
+
+ local pfiles=$(find . \( -type f -o -type l \) \( -name "*.p_*" -o -name "lib*_p.a" \))
+ echo "$pfiles" | cpio -pamVd "$subpkgdir"
+ echo "$pfiles" | xargs rm -fr
+}
+
+sha512sums="58ea3853cd93b556ecdc4abd0be079b2621171b8491f59004ea4e036a4cba4470aaafe6591b942e0a50a64bdc47540e01fe6900212a1ef7087850112d9bfc5ef ghc-8.0.2-src.tar.xz
+1b35fc6a5f482dc1e33f21ddf4c4fe17591990f16a4105c787225980a5f4dbaa42205204faf547f8e1b53f6356aefde9d3ff50cc416c9bf1a9ac08feadd74a99 ghc-8.0.2-testsuite.tar.xz
+23a52467fe83322e7b1d5f3e17a9defd08969666acb5a40e40ad93aa4f3feec028389448d4620edbe3ee8b246b3b6e338b267dce09cb14bdd0949b98e75d7562 0000-alpine.patch
+82cecce9e42c12cc3c8d484331b76ac5c6d2529887cd73181d4798f95057883be47489919379e6ebf7daba95b7c25b5d9d689b30ed8d01b13dda20a3b921ce3d 0000-bootstrap.patch
+128eece1b103f286b915a1563a628b638f03509d18cdb2e6510957d26eb56a4ae66e33c946c0e6c2aac2f947b9646dc88c1f390c69ea21f9dc64e0bef4de4e97 0001-rm-ghc-pwd.patch
+6f90b0de1e34c286e54ef14514ffabe17f9012fbc5448b4aacb3687aac065942e0a3a2c1c57b6338121140369a8870b4ce2a6b355c83c43344d4de8909a253a4 0002-Correct-issue-with-libffi-and-glibc.patch
+59194e6994c8344c579ec16c3adf3e0cdc7c356b524b12f8b10ec940191463d686782e525537c94ffa8e1bf9efcc36a2b3da3004183586ab0e354ab0a7036e0a 0003-do-not-use-SHELL.patch
+b5a5e73a2f01c0cabc96a49776d0d0f3d1d7a10759bb0b2982e7c7f6dc525d0559c0183ee779feb77ec6f2cec3bac17c1a5ba4c3bc0c6f780dfc1ed3dcf6c80e 0004-reproducible-tmp-names.patch
+e1c2cef06d307eda4b35521204e95eb54ace5dbcd22de659e95356f884b4424d6304365e4ab45c5116192cba4c095e2e91114bc7cb73d7c7173a7035287d0854 0005-buildpath-abi-stability.patch
+478f9c9990ee01b70e88daf97138f853816d862731a02e9286ad787845dcb40c1443a30520598d805d0ff7cea8c3d604ed5d9033dbe8e572e8a85911ee739ff7 0006-fix-madvise.patch
+a1032b800515908eae1602454c03bd80c92e39faa4004b52dba698d84166abea1bb4ce4afc2b69aad4a25a4e9acb2d12704453e512ab2b2ceae02c6df180bd76 0007-build-hp2ps-twice.patch
+0a53264a2066869379cbcb3a6175b93d4461d9a9fe6d2594bf0c9438daa176fbccf033832fa61bd482a23335c4528d8087301e3bdc08d08160acb789befbe005 0008-build-unlit-twice.patch"
diff --git a/community/ghc/ghc.post-install b/community/ghc/ghc.post-install
new file mode 100644
index 0000000000..43a1034bf6
--- /dev/null
+++ b/community/ghc/ghc.post-install
@@ -0,0 +1,5 @@
+#!/bin/sh
+# Force ghc-pkg to recache the base installed packages. Necessary as we
+# did make install DESTDIR=... so the cache has invalid locations.
+
+ghc-pkg recache