summaryrefslogtreecommitdiff
path: root/dev-lang/mlton
diff options
context:
space:
mode:
Diffstat (limited to 'dev-lang/mlton')
-rw-r--r--dev-lang/mlton/Manifest13
-rw-r--r--dev-lang/mlton/files/mlton-20070826-no-execmem.patch29
-rw-r--r--dev-lang/mlton/files/mlton-20130715-no-PIE.patch66
-rw-r--r--dev-lang/mlton/files/mlton-20130715-split-make-for-pax-mark.patch11
-rw-r--r--dev-lang/mlton/files/mlton-20180207-bootstrap.patch27
-rw-r--r--dev-lang/mlton/files/mlton-20180207-paxmark.patch18
-rw-r--r--dev-lang/mlton/metadata.xml21
-rw-r--r--dev-lang/mlton/mlton-20130715.ebuild119
-rw-r--r--dev-lang/mlton/mlton-20180207.ebuild264
9 files changed, 568 insertions, 0 deletions
diff --git a/dev-lang/mlton/Manifest b/dev-lang/mlton/Manifest
new file mode 100644
index 000000000000..44c2ae357c1f
--- /dev/null
+++ b/dev-lang/mlton/Manifest
@@ -0,0 +1,13 @@
+AUX mlton-20070826-no-execmem.patch 1236 BLAKE2B 1d708bba547f8ea3076bdd494a5e45f8352430b9a852c45296258b6371fd2bee07a7d2d9cb224bc426e8c364b07d8d37b92d98d6fc186b0217b0650ac961e128 SHA512 d6f323bc181656fbdfdf25e0472e7e13e93b565f3ba64ea9cc81fbcb6c935580c1811f783035a5b1c45be082a38f157610666276aad9fb36d3fdb009fe7ce1c9
+AUX mlton-20130715-no-PIE.patch 2399 BLAKE2B a0af01c4eea65a38d788744f593303d8732a754de19230ce13ce14ce6368058840e9076934311385bed7951d94f1daed878847a57e70ac9330f4af575f35c1bf SHA512 ef0d675acfcbe05c1f810da2b9d684b4412a0f283e6025930c13d80912036ffc650972664f5a4fdd955e4c78c3564c751c1ba9bf279f738eca96801eeb57f0b2
+AUX mlton-20130715-split-make-for-pax-mark.patch 556 BLAKE2B a98f9a6b01edfc19723ef20eaeb0e9046162e179f3c63c69f59d07a39e0b723c4b429c3f10adb6099f912340431e8ea7b06a63d397cb8feff46d3d7d256a0e22 SHA512 9d334c930abe38f222bdd16c7dbdb0b1e0a70955aa8832fd441c9443c53f9d66c3ec49c06f59de501c014a66c6265a6df64269e0534c0ffdae0115718febb694
+AUX mlton-20180207-bootstrap.patch 980 BLAKE2B 4128d0d3aae1e30c6b234e9cc3e0d91ee6de7338e2f8d4e8da7bb5b63ea62138db3148f8ec9ab16966983587dac7c9040a52aea80d21409d5d8fdbb020d13f7f SHA512 7657185d7f4c4e9bff4fd44f3991cd3d115ea0e1e4f6c3b702ecba74a3b2fcb7c1c0c47a814dc26bd3af7a523a92aac50df4d4ddb873eba938c2689ac6b5cf0b
+AUX mlton-20180207-paxmark.patch 728 BLAKE2B 05bb27260dc8007a815ce74276a537a48127b4c336472afca571c39b0e29368be5be79ae03c21940dde6bd37f79613817adc8f22d986d570fab4cb184051b141 SHA512 78526ab383f481663cc892938f74ad1783aa7a2b1fcfd7032a67c4489daa5d141877806fb16232b8f0843e7b4e001d3f76a9a171a8da6413cd921688f493f7f9
+DIST mlton-20130715-1.amd64-linux.tgz 19512324 BLAKE2B 972688dcf6fc6ec17146e2597e6f5dab3b5df4e894697a98c68de61cf4728bf7e2e3ef1cee96befae90f9b555bed0b09cef846912225f8b770d20782fa833212 SHA512 ac41cf8b2afbba80ed25908b1842348eac1507b2aada103648171db1482358c4176b01d9266dfee053b20fc224653ec58ee9d3265672c02fa3774b7562a319bf
+DIST mlton-20130715-1.x86-linux.tgz 18065793 BLAKE2B d05ca4f46fb35b0b819e2678f282943fc9cd8f701bdf2a20da68b285db4618401b4138a227352e8aacef9f604528c7fafc0973631115954cfd91e01e9dd01a9d SHA512 13a996952df27420f05f8290920055231156c8982c1cf3c31259d73e0c534258e2aad91596e51809719ffb0b74652aa052d296000f2ab99462714d4ef9a41859
+DIST mlton-20130715.src.tgz 25606142 BLAKE2B 3fa3e8cf4991faef98e23ae4cbe9e0db5cae2e46ce27be57b784a81b576eeed17a179018e8b70d1264cb9595a3467900f034a2b4a7c114d1bac74025450741e1 SHA512 db273de47dc0059e830332b559918567f5153a0518e067ba71927e3705157f1984d6f6202201cef25aaef29d1a71a637e9a1cb30951e94dbfae4ab1a5e5d40d1
+DIST mlton-20180207-1.amd64-linux.tgz 18772644 BLAKE2B 7fe2d9db7edfb2d3e301be88e90b7dffe1441ff315ddac1464ef42fb436be1a9dc4e2c03fdb93880779360aed04cb7662a1a5a733f2d4158082d228f718d8b93 SHA512 74ab847ff567cde365a113f8819bae69cc18df20c441a6c6666b600980d2687faf143311f42be21a261b2493dc5c45fbecb4737c599cf767c3680afec06c2e0c
+DIST mlton-20180207.src.tgz 25003695 BLAKE2B 8cddfe83c76e05fda446917ddc85035b3d74534fe4bc597a839cd13cb59a15538f40a3f68bb8f7136f9cf8cb27a582e88ca0d14b8f7a4582a202b3bd075f3c9a SHA512 3599159950e857d257abce92abf5c548dd9c0b0cdc4ba0d7cdf9badb5d997f73386cd1ff79f563221b394dd831cb344e287927f90683b0715678edb3ca0ae15a
+EBUILD mlton-20130715.ebuild 3998 BLAKE2B 8fce5cb495bf3c314e2aa280f756efc08d6ca316837875c66be2085fdab016987345758a44efcaa3e1a8975e813c93e25f20ff93a185e4bea3f4fdf10acb3a83 SHA512 1c25e4e15b227356f2ecc29ab83e4256cdffbc82229d45a268f4e3c1105a8e6bdf80282ce556069701678a162672fcec8fbba2c07e226858ffae59c8a114f9cd
+EBUILD mlton-20180207.ebuild 7024 BLAKE2B 2d0c9379e5c62c4037cf1e5af55ca9da9d4948418567fbf24d15f52804143e310a31d6f80c8a75e4a06f839b9dbef40df16cb602f2cc1ad2d84d709b8261e88e SHA512 cfa3415c31a527b9274376c6cd0bcb6317a93007b0766a98ccc574696badbe2dbf2a9da31113310a532777dafba69fca232a52a9c9bd297c03befb09ebb90491
+MISC metadata.xml 752 BLAKE2B 5a01dd9703df49651fee5d19e003b99315981907eaedc9f2a4c2247f4a6b6dfdbe52f7bd2d3f557ab768b2635d74202bfa4466907643a08fc605cb2d671ea8be SHA512 7fe1b98c03aba81adea9f9a6a9b8a77130ca95d4086204a3387c84eb33da4825d0ab97e7e9ca946e650436966bcb5a861010f067dc0ec39319ba539bee48ee08
diff --git a/dev-lang/mlton/files/mlton-20070826-no-execmem.patch b/dev-lang/mlton/files/mlton-20070826-no-execmem.patch
new file mode 100644
index 000000000000..f4d4bdf540bf
--- /dev/null
+++ b/dev-lang/mlton/files/mlton-20070826-no-execmem.patch
@@ -0,0 +1,29 @@
+From 544930de3b1c754fa8803169902a63bce7cc02ba Mon Sep 17 00:00:00 2001
+From: Adam Goode <adam@spicenitz.org>
+Date: Wed, 6 Feb 2008 20:17:51 -0500
+Subject: [PATCH] Remove PROT_EXEC from mprotect
+
+It looks like mprotect is used here as part of signal handling.
+There doesn't seems to be a reason to have the area of memory
+marked as executable. In fact, on Fedora 9, this causes MLton
+compiled binaries (including MLton itself) to fail.
+---
+ runtime/platform/mmap-protect.c | 2 +-
+ 1 files changed, 1 insertions(+), 1 deletions(-)
+
+diff --git a/runtime/platform/mmap-protect.c b/runtime/platform/mmap-protect.c
+index f0dea49..df42215 100644
+--- a/runtime/platform/mmap-protect.c
++++ b/runtime/platform/mmap-protect.c
+@@ -7,7 +7,7 @@ void *GC_mmapAnon_safe_protect (void *start, size_t length,
+ if (mprotect (low, dead_low, PROT_NONE))
+ diee ("mprotect failed");
+ result = (void*)((pointer)low + dead_low);
+- if (mprotect (result, length, PROT_READ | PROT_WRITE | PROT_EXEC))
++ if (mprotect (result, length, PROT_READ | PROT_WRITE))
+ diee ("mprotect failed");
+ high = (void*)((pointer)result + length);
+ if (mprotect (high, dead_high, PROT_NONE))
+--
+1.5.4
+
diff --git a/dev-lang/mlton/files/mlton-20130715-no-PIE.patch b/dev-lang/mlton/files/mlton-20130715-no-PIE.patch
new file mode 100644
index 000000000000..a059b1598bec
--- /dev/null
+++ b/dev-lang/mlton/files/mlton-20130715-no-PIE.patch
@@ -0,0 +1,66 @@
+--- mlton-20130715-orig/bin/upgrade-basis 2013-07-16 05:59:09.000000000 +1000
++++ mlton-20130715/bin/upgrade-basis 2013-12-17 18:17:24.165889500 +1100
+@@ -28,7 +28,7 @@
+ tmp="$$.sml"
+
+ echo "val () = print \"I work\"" >"$tmp"
+-if ! mlton "$tmp" 1>&2; then
++if ! mlton -link-opt -fno-PIE "$tmp" 1>&2; then
+ die "Error: cannot upgrade basis because the compiler doesn't work"
+ fi
+
+--- mlton-20130715-orig/mlton/Makefile 2013-07-16 05:59:09.000000000 +1000
++++ mlton-20130715/mlton/Makefile 2013-12-17 23:35:06.137421195 +1100
+@@ -106,7 +106,7 @@
+ rm -f control/version.sml
+ $(MAKE) control/version.sml
+ @echo 'Compiling mlton (takes a while)'
+- mlton $(FLAGS) $(FILE)
++ mlton $(FLAGS) -link-opt -fno-PIE $(FILE)
+
+ .PHONY: def-use
+ def-use: mlton.def-use
+--- mlton-20130715-orig/mllex/Makefile 2013-07-16 05:59:09.000000000 +1000
++++ mlton-20130715/mllex/Makefile 2013-12-18 07:03:29.592171611 +1100
+@@ -21,7 +21,7 @@
+
+ $(NAME): $(NAME).mlb $(shell PATH="$(BIN):$$PATH" && "$(MLTON)" -stop f $(NAME).mlb)
+ @echo 'Compiling $(NAME)'
+- "$(MLTON)" $(FLAGS) $(NAME).mlb
++ "$(MLTON)" $(FLAGS) -link-opt -fno-PIE $(NAME).mlb
+
+ html/index.html: $(TEX_FILES)
+ mkdir -p html
+--- mlton-20130715-orig/mlnlffigen/Makefile 2013-07-16 05:59:09.000000000 +1000
++++ mlton-20130715/mlnlffigen/Makefile 2013-12-18 11:55:33.590660407 +1100
+@@ -22,7 +22,7 @@
+
+ $(NAME): $(NAME).mlb $(shell PATH="$(BIN):$$PATH" && "$(MLTON)" -stop f $(NAME).mlb)
+ @echo 'Compiling $(NAME)'
+- $(MLTON) $(FLAGS) $(NAME).mlb
++ $(MLTON) $(FLAGS) -link-opt -fno-PIE $(NAME).mlb
+
+ .PHONY: clean
+ clean:
+--- mlton-20130715-orig/mlprof/Makefile 2013-07-16 05:59:09.000000000 +1000
++++ mlton-20130715/mlprof/Makefile 2013-12-20 14:02:50.292677796 +1100
+@@ -21,7 +21,7 @@
+
+ $(NAME): $(NAME).mlb $(shell PATH="$(BIN):$$PATH" && "$(MLTON)" -stop f $(NAME).mlb)
+ @echo 'Compiling $(NAME)'
+- $(MLTON) $(FLAGS) $(NAME).mlb
++ $(MLTON) $(FLAGS) -link-opt -fno-PIE $(NAME).mlb
+
+ .PHONY: clean
+ clean:
+--- mlton-20130715-orig/mlyacc/Makefile 2013-07-16 05:59:09.000000000 +1000
++++ mlton-20130715/mlyacc/Makefile 2013-12-20 15:01:26.567775876 +1100
+@@ -41,7 +41,7 @@
+
+ $(NAME): $(NAME).mlb $(shell PATH="$(BIN):$$PATH" && "$(MLTON)" -stop f $(NAME).mlb)
+ @echo 'Compiling $(NAME)'
+- "$(MLTON)" $(FLAGS) $(NAME).mlb
++ "$(MLTON)" $(FLAGS) -link-opt -fno-PIE $(NAME).mlb
+
+ src/yacc.lex.sml: src/yacc.lex
+ rm -f src/yacc.lex.sml && \
diff --git a/dev-lang/mlton/files/mlton-20130715-split-make-for-pax-mark.patch b/dev-lang/mlton/files/mlton-20130715-split-make-for-pax-mark.patch
new file mode 100644
index 000000000000..3286d44e3522
--- /dev/null
+++ b/dev-lang/mlton/files/mlton-20130715-split-make-for-pax-mark.patch
@@ -0,0 +1,11 @@
+--- mlton-20130715-orig/Makefile 2013-07-16 05:59:09.000000000 +1000
++++ mlton-20130715/Makefile 2013-12-27 13:29:35.259563131 +1100
+@@ -58,7 +58,7 @@
+
+ .PHONY: all-no-docs
+ all-no-docs:
+- $(MAKE) dirs runtime compiler basis-no-check script mlbpathmap constants libraries tools
++ $(MAKE) basis-no-check script mlbpathmap constants libraries tools
+ # Remove $(AOUT) so that the $(MAKE) compiler below will remake MLton.
+ # We also want to re-run the just-built tools (mllex and mlyacc)
+ # because they may be better than those that were used for the first
diff --git a/dev-lang/mlton/files/mlton-20180207-bootstrap.patch b/dev-lang/mlton/files/mlton-20180207-bootstrap.patch
new file mode 100644
index 000000000000..5287a809f5aa
--- /dev/null
+++ b/dev-lang/mlton/files/mlton-20180207-bootstrap.patch
@@ -0,0 +1,27 @@
+--- mlton-20180207-orig/Makefile 2018-02-07 21:22:55.000000000 +1100
++++ mlton-20180207/Makefile 2018-02-28 11:28:00.639642560 +1100
+@@ -137,18 +137,22 @@
+ .PHONY: bootstrap-smlnj
+ bootstrap-smlnj:
+ $(MAKE) smlnj-mlton
+- $(RM) "$(BIN)/mlton"
++ $(MV) "$(BIN)/mlton" "$(BIN)/mlton.mlton"
++ $(CP) "$(BIN)/mlton.smlnj" "$(BIN)/mlton"
+ $(MAKE) BOOTSTRAP_MLTON=mlton.smlnj all
+ smlnj_heap_suffix=`echo 'TextIO.output (TextIO.stdErr, SMLofNJ.SysInfo.getHeapSuffix ());' | sml 2>&1 1> /dev/null` && $(RM) "$(LIB)/mlton/mlton-smlnj.$$smlnj_heap_suffix"
+ $(RM) "$(BIN)/mlton.smlnj"
++ $(MV) "$(BIN)/mlton.mlton" "$(BIN)/mlton"
+
+ .PHONY: bootstrap-polyml
+ bootstrap-polyml:
+ $(MAKE) polyml-mlton
+- $(RM) "$(BIN)/mlton"
++ $(MV) "$(BIN)/mlton" "$(BIN)/mlton.mlton"
++ $(CP) "$(BIN)/mlton.polyml" "$(BIN)/mlton"
+ $(MAKE) BOOTSTRAP_MLTON=mlton.polyml all
+ $(RM) "$(LIB)/mlton-polyml$(EXE)"
+ $(RM) "$(BIN)/mlton.polyml"
++ $(MV) "$(BIN)/mlton.mlton" "$(BIN)/mlton"
+
+ .PHONY: clean
+ clean:
diff --git a/dev-lang/mlton/files/mlton-20180207-paxmark.patch b/dev-lang/mlton/files/mlton-20180207-paxmark.patch
new file mode 100644
index 000000000000..00f4b84c7dc9
--- /dev/null
+++ b/dev-lang/mlton/files/mlton-20180207-paxmark.patch
@@ -0,0 +1,18 @@
+--- mlton-20180207-orig/Makefile 2018-02-07 21:22:55.000000000 +1100
++++ mlton-20180207/Makefile 2018-02-28 11:27:30.448517470 +1100
+@@ -51,6 +51,7 @@
+ SED := sed
+ TAR := tar
+ XARGS := xargs
++PAXMARK := true
+
+ ######################################################################
+ ######################################################################
+@@ -97,6 +98,7 @@
+ all:
+ $(MAKE) dirs runtime
+ $(MAKE) compiler CHECK_FIXPOINT=false # tools0 + mlton0 -> mlton1
++ $(PAXMARK) -m lib/mlton/mlton-compile bin/mllex bin/mlyacc
+ $(MAKE) script basis-no-check constants basis-check libraries
+ $(MAKE) tools CHECK_FIXPOINT=false # tools0 + mlton1 -> tools1
+ ifeq (true, $(findstring true,$(BOOTSTRAP) $(CHECK_FIXPOINT)))
diff --git a/dev-lang/mlton/metadata.xml b/dev-lang/mlton/metadata.xml
new file mode 100644
index 000000000000..e00a5b040ec4
--- /dev/null
+++ b/dev-lang/mlton/metadata.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <maintainer type="project">
+ <email>ml@gentoo.org</email>
+ <name>Gentoo ML Project</name>
+ </maintainer>
+ <use>
+ <flag name="binary">install a binary version</flag>
+ <flag name="bootstrap-smlnj">Boostrap mlton with dev-lang/smlnj
+ (takes a long time)</flag>
+ <flag name="stage3">After bootstrap building mlton with
+ dev-lang/smlnj, rebuild mlton with the second stage build of
+ mlton (recommended).</flag>
+ <flag name="pax_kernel">Enable if the user plans to run the
+ package under a pax enabled hardened kernel</flag>
+ </use>
+ <upstream>
+ <remote-id type="sourceforge">mlton</remote-id>
+ </upstream>
+</pkgmetadata>
diff --git a/dev-lang/mlton/mlton-20130715.ebuild b/dev-lang/mlton/mlton-20130715.ebuild
new file mode 100644
index 000000000000..a306bfabb1c3
--- /dev/null
+++ b/dev-lang/mlton/mlton-20130715.ebuild
@@ -0,0 +1,119 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+inherit check-reqs eutils pax-utils
+
+DESCRIPTION="Standard ML optimizing compiler and libraries"
+BASE_URI="mirror://sourceforge/${PN}"
+SRC_URI="!binary? ( ${BASE_URI}/${P}.src.tgz )
+ binary? ( amd64? ( ${BASE_URI}/${P}-1.amd64-linux.tgz )
+ x86? ( ${BASE_URI}/${P}-1.x86-linux.tgz ) )"
+
+HOMEPAGE="http://www.mlton.org"
+
+LICENSE="HPND MIT"
+SLOT="0/${PV}"
+# there is support for ppc64 and ia64, but no
+# binaries are provided and there is no native
+# code generation for these platforms
+KEYWORDS="-* ~amd64 ~x86"
+IUSE="binary doc"
+
+DEPEND="dev-libs/gmp:*
+ doc? ( virtual/latex-base )"
+RDEPEND="dev-libs/gmp:*"
+
+QA_PRESTRIPPED="binary? (
+ usr/bin/mlnlffigen
+ usr/bin/mllex
+ usr/bin/mlprof
+ usr/bin/mlyacc
+ usr/lib/mlton/mlton-compile
+)"
+
+# The resident set size of mlton-compile is 10GB on amd64
+CHECKREQS_MEMORY="4G"
+
+pkg_pretend() {
+ if use !binary; then
+ check-reqs_pkg_pretend
+ fi
+}
+
+src_unpack() {
+ if use !binary; then
+ unpack ${A}
+ else
+ mkdir -p "${S}" || die "Could not create ${S} directory"
+ pushd "${S}" || die "Could not cd to ${S}"
+ unpack ${A}
+ popd
+ fi
+}
+
+src_prepare() {
+ if use !binary; then
+ # The patch removing executable permissions from mmap'd memory regions is not upstreamed:
+ # http://pkgs.fedoraproject.org/cgit/mlton.git/tree/mlton-20070826-no-execmem.patch
+ epatch "${FILESDIR}/${PN}-20070826-no-execmem.patch"
+ # PIE in hardened requires executables to be linked with -fPIC. mlton by default tries
+ # to link executables against the non PIC objects in libmlton.a. We may be bootstrapping
+ # with an old mlton install, if we tried to patch it (to link with libmlton-pic.a) we would
+ # need a patched binary.
+ # http://mlton.org/MLtonWorld says Executables that save and load worlds are incompatible
+ # with address space layout randomization (ASLR) of the executable.
+ epatch "${FILESDIR}/${PN}-20130715-no-PIE.patch"
+ # Remove dirs runtime compiler from all-no-docs to avoid repeating these steps.
+ # As we need to pax-mark the mlton-compiler executable.
+ epatch "${FILESDIR}/${PN}-20130715-split-make-for-pax-mark.patch"
+ fi
+}
+
+src_compile() {
+ if use !binary; then
+ has_version dev-lang/mlton || die "emerge with binary use flag first"
+
+ # Fix location in which to install man pages
+ sed -i 's@^MAN_PREFIX_EXTRA :=.*@MAN_PREFIX_EXTRA := /share@' \
+ Makefile || die 'sed Makefile failed'
+
+ emake -j1 dirs runtime compiler CFLAGS="${CFLAGS}" || die
+ pax-mark m "${S}/mlton/mlton-compile"
+ pax-mark m "${S}/build/lib/mlton-compile"
+
+ # Does not support parallel make
+ emake -j1 all-no-docs CFLAGS="${CFLAGS}" || die
+ if use doc; then
+ export VARTEXFONTS="${T}/fonts"
+ emake docs || die "failed to create documentation"
+ fi
+ fi
+}
+
+src_install() {
+ if use binary; then
+ # Fix location in which to install man pages
+ mv "${S}/usr/man" "${S}/usr/share" || die "mv man failed"
+ pax-mark m "${S}/usr/lib/mlton/mlton-compile"
+ pax-mark m "${S}/usr/bin/mllex"
+ pax-mark m "${S}/usr/bin/mlyacc"
+ mv "${S}/usr" "${D}" || die "mv failed"
+ else
+ emake DESTDIR="${D}" install-no-docs || die
+ if use doc; then emake DESTDIR="${D}" TDOC="${D}"/usr/share/doc/${P} install-docs || die; fi
+ fi
+}
+
+pkg_postinst() {
+ # There are PIC objects in libmlton-pic.a. -link-opt -lmlton-pic does not help as mlton
+ # specifies -lmlton before -lmlton-pic. It appears that it would be necessary to patch mlton
+ # to convince mlton to use the lib*-pic.a libraries when linking an executable.
+ ewarn 'PIE in Gentoo hardened requires executables to be linked with -fPIC. mlton by default links'
+ ewarn 'executables against the non PIC objects in libmlton.a. http://mlton.org/MLtonWorld notes:'
+ ewarn 'Executables that save and load worlds are incompatible with address space layout'
+ ewarn 'randomization (ASLR) of the executable.'
+ ewarn 'To suppress the generation of position-independent executables.'
+ ewarn '-link-opt -fno-PIE'
+}
diff --git a/dev-lang/mlton/mlton-20180207.ebuild b/dev-lang/mlton/mlton-20180207.ebuild
new file mode 100644
index 000000000000..b8df540a09ff
--- /dev/null
+++ b/dev-lang/mlton/mlton-20180207.ebuild
@@ -0,0 +1,264 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+
+inherit check-reqs eutils multibuild pax-utils
+
+DESCRIPTION="Standard ML optimizing compiler and libraries"
+BASE_URI="mirror://sourceforge/${PN}"
+SRC_URI="!binary? ( ${BASE_URI}/${P}.src.tgz )
+ !bootstrap-smlnj? ( amd64? ( ${BASE_URI}/${P}-1.amd64-linux.tgz ) )"
+HOMEPAGE="http://www.mlton.org"
+
+LICENSE="HPND MIT"
+SLOT="0/${PV}"
+KEYWORDS="~amd64 ~x86"
+IUSE="binary bootstrap-smlnj stage3 doc pax_kernel"
+
+DEPEND="dev-libs/gmp:*
+ bootstrap-smlnj? ( dev-lang/smlnj )
+ !bootstrap-smlnj? (
+ !amd64? ( dev-lang/smlnj )
+ )
+ pax_kernel? ( sys-apps/elfix )
+ doc? ( virtual/latex-base )"
+RDEPEND="dev-libs/gmp:*"
+
+QA_PRESTRIPPED="binary? (
+ usr/lib64/${PN}/bin/mlnlffigen
+ usr/lib64/${PN}/bin/mllex
+ usr/lib64/${PN}/bin/mlprof
+ usr/lib64/${PN}/bin/mlyacc
+ usr/lib64/${PN}/lib/mlton-compile
+ usr/lib/${PN}/bin/mlnlffigen
+ usr/lib/${PN}/bin/mllex
+ usr/lib/${PN}/bin/mlprof
+ usr/lib/${PN}/bin/mlyacc
+ usr/lib/${PN}/lib/mlton-compile
+)"
+
+B="${P}-1.${ARCH}-${KERNEL}"
+R="${WORKDIR}/${B}"
+
+mlton_subdir() {
+ echo $(get_libdir)/${PN}
+}
+
+mlton_dir() {
+ echo "${EPREFIX%/}"/usr/$(mlton_subdir)
+}
+
+mlton_memory_requirement() {
+ # The resident set size of compiling mlton with mlton is almost 14GB on amd64.
+ # http://mlton.org/SelfCompiling
+ # Compiling MLton requires at least 1GB of RAM for 32-bit platforms (2GB is
+ # preferable) and at least 2GB RAM for 64-bit platforms (4GB is preferable).
+ # If your machine has less RAM, self-compilation will likely fail, or at least
+ # take a very long time due to paging. Even if you have enough memory, there
+ # simply may not be enough available, due to memory consumed by other
+ # processes. In this case, you may see an Out of memory message, or
+ # self-compilation may become extremely slow. The only fix is to make sure
+ # that enough memory is available.
+ [[ ${ARCH} == "x86" ]] && echo "2G" || echo "4G"
+}
+
+pkg_pretend() {
+ if use !binary; then
+ local CHECKREQS_MEMORY=$(mlton_memory_requirement)
+ check-reqs_pkg_pretend
+ fi
+}
+
+pkg_setup() {
+ if use !binary; then
+ local CHECKREQS_MEMORY=$(mlton_memory_requirement)
+ check-reqs_pkg_setup
+ fi
+}
+
+mlton_bootstrap_variant() {
+ local b=""
+ if use bootstrap-smlnj || ! use amd64; then
+ b="bootstrap-smlnj"
+ else
+ b="bootstrap"
+ fi
+ echo "${b}"
+}
+
+mlton_bootstrap_build_dir() {
+ echo $(basename ${S})"-"$(mlton_bootstrap_variant)
+}
+
+mlton_bootstrap_bin_dir() {
+ local b=$(mlton_bootstrap_build_dir)
+ if use bootstrap-smlnj || ! use amd64; then
+ b+="/build/bin"
+ else
+ b+="/bin"
+ fi
+ echo "${b}"
+}
+
+# Return the array of multilib build variants
+mlton_multibuild_variants() {
+ local MULTIBUILD_VARIANTS=()
+ if ! use binary; then
+ if use bootstrap-smlnj || ! use amd64; then
+ MULTIBUILD_VARIANTS+=( $(mlton_bootstrap_variant) )
+ use stage3 && MULTIBUILD_VARIANTS+=( build-with-mlton )
+ else
+ MULTIBUILD_VARIANTS+=( build-with-mlton )
+ fi
+ fi
+ echo ${MULTIBUILD_VARIANTS[*]}
+}
+
+# Return the last multibuild variant
+mlton_last_multibuild_variant() {
+ local vs=( $(mlton_multibuild_variants) )
+ echo ${vs[${#vs[@]}-1]}
+}
+
+src_unpack() {
+ default
+ if use binary; then
+ mkdir -p "${S}" || die
+ fi
+}
+
+BIN_STUBS=( mllex mlnlffigen mlprof mlton mlyacc )
+
+mlton_create_bin_stubs() {
+ local SUBDIR=$(mlton_subdir)
+ mkdir "${S}"/bin_stubs || die
+ pushd "${S}"/bin_stubs || die
+ for i in ${BIN_STUBS[*]}; do
+ cat <<- EOF >> ${i}
+ #!/bin/bash
+ exec ${EPREFIX%/}/usr/${SUBDIR}/bin/${i} \$*
+ EOF
+ chmod a+x ${i} || die
+ done
+ popd || die
+}
+
+src_prepare() {
+ if ! use binary; then
+ # For Gentoo hardened: paxmark the mlton-compiler, mllex and mlyacc executables
+ epatch "${FILESDIR}/${PN}-20180207-paxmark.patch"
+ # Fix the bootstrap-smlnj and bootstrap-polyml Makefile targets
+ epatch "${FILESDIR}/${PN}-20180207-bootstrap.patch"
+ fi
+ default
+ $(mlton_create_bin_stubs)
+ if use binary; then
+ pax-mark m "${R}/lib/${PN}/mlton-compile"
+ pax-mark m "${R}/bin/mllex"
+ pax-mark m "${R}/bin/mlyacc"
+ ln -s ${R} ../$(mlton_bootstrap_build_dir) || die
+ gunzip ${R}/share/man/man1/*.gz || die
+ else
+ local MULTIBUILD_VARIANTS=( $(mlton_multibuild_variants) )
+ multibuild_copy_sources
+ if ! use bootstrap-smlnj && [[ ${ARCH} == "amd64" ]]; then
+ ln -s ${B} ../$(mlton_bootstrap_build_dir) || die
+ fi
+ fi
+}
+
+mlton_src_compile() {
+ if [[ ${MULTIBUILD_VARIANT} == $(mlton_bootstrap_variant) ]]; then
+ emake -j1 \
+ "bootstrap-smlnj" \
+ PAXMARK=$(usex pax_kernel "paxmark.sh" "true") \
+ CFLAGS="${CFLAGS}" \
+ WITH_GMP_INC_DIR="${EPREFIX}"/usr/include \
+ WITH_GMP_LIB_DIR="${EPREFIX}"/$(get_libdir)
+ else
+ export PATH="${WORKDIR}/"$(mlton_bootstrap_bin_dir)":${PATH}"
+ einfo "${MULTIBUILD_VARIANT}: Building mlton with mlton in PATH=$PATH"
+ emake -j1 \
+ CFLAGS="${CFLAGS}" \
+ WITH_GMP_INC_DIR="${EPREFIX}"/usr/include \
+ WITH_GMP_LIB_DIR="${EPREFIX}"/$(get_libdir)
+ fi
+ if [[ ${MULTIBUILD_VARIANT} == $(mlton_last_multibuild_variant) ]]; then
+ if use doc; then
+ export VARTEXFONTS="${T}/fonts"
+ emake docs
+ fi
+ fi
+}
+
+src_compile() {
+ if ! use binary; then
+ local MULTIBUILD_VARIANTS=( $(mlton_multibuild_variants) )
+ multibuild_foreach_variant run_in_build_dir mlton_src_compile
+ fi
+}
+
+mlton_src_test() {
+ emake check
+}
+
+src_test() {
+ if ! use binary; then
+ local MULTIBUILD_VARIANTS=( $(mlton_last_multibuild_variant) )
+ multibuild_foreach_variant run_in_build_dir mlton_src_test
+ fi
+}
+
+mlton_src_install() {
+ local DIR=$(mlton_dir)
+ emake \
+ install-no-strip install-strip \
+ DESTDIR="${D}" \
+ PREFIX="${DIR}"
+ if use doc; then
+ emake TDOC="${D}"/usr/share/doc/${PF} install-docs \
+ DESTDIR="${D}" \
+ PREFIX="${DIR}"
+ fi
+}
+
+mlton_install_bin_stubs() {
+ exeinto /usr/bin
+ for i in ${BIN_STUBS[*]}; do
+ doexe "${S}"/bin_stubs/${i}
+ done
+}
+
+src_install() {
+ $(mlton_install_bin_stubs)
+ if use binary; then
+ local DIR=$(mlton_dir)
+ exeinto "${DIR}"/bin
+ doexe "${R}"/bin/*
+ insinto "${DIR}"/lib
+ doins -r "${R}"/lib/${PN}
+ exeinto "${DIR}"/lib/${PN}
+ doexe "${R}"/lib/${PN}/mlton-compile
+ doman "${R}"/share/man/man1/*
+ if use doc; then
+ local DOCS=( "${R}"/share/doc/${PN}/. )
+ einstalldocs
+ fi
+ else
+ local MULTIBUILD_VARIANTS=( $(mlton_last_multibuild_variant) )
+ multibuild_foreach_variant run_in_build_dir mlton_src_install
+ fi
+}
+
+pkg_postinst() {
+ # There are PIC objects in libmlton-pic.a. -link-opt -lmlton-pic does not help as mlton
+ # specifies -lmlton before -lmlton-pic. It appears that it would be necessary to patch mlton
+ # to convince mlton to use the lib*-pic.a libraries when linking an executable.
+ ewarn 'PIE in Gentoo hardened requires executables to be linked with -fPIC. mlton by default links'
+ ewarn 'executables against the non PIC objects in libmlton.a. http://mlton.org/MLtonWorld notes:'
+ ewarn 'Executables that save and load worlds are incompatible with address space layout'
+ ewarn 'randomization (ASLR) of the executable.'
+ ewarn 'To suppress the generation of position-independent executables.'
+ ewarn '-link-opt -fno-PIE'
+}