From 08dfb9567320a64a082408fc157e62a09ae2df14 Mon Sep 17 00:00:00 2001
From: Matthew Pickering <matthewtpickering@gmail.com>
Date: Fri, 8 Dec 2017 23:35:22 +0000
Subject: [PATCH 1/2] ber_metaocaml: (re)init at 104

---
 .../compilers/ocaml/ber-metaocaml-104.nix     | 84 +++++++++++++++++++
 pkgs/top-level/all-packages.nix               |  2 +
 2 files changed, 86 insertions(+)
 create mode 100644 pkgs/development/compilers/ocaml/ber-metaocaml-104.nix

diff --git a/pkgs/development/compilers/ocaml/ber-metaocaml-104.nix b/pkgs/development/compilers/ocaml/ber-metaocaml-104.nix
new file mode 100644
index 00000000000..81c8cd53402
--- /dev/null
+++ b/pkgs/development/compilers/ocaml/ber-metaocaml-104.nix
@@ -0,0 +1,84 @@
+{ stdenv, fetchurl, ncurses, libX11, xproto, buildEnv }:
+
+let
+   useX11 = stdenv.isi686 || stdenv.isx86_64;
+   useNativeCompilers = stdenv.isi686 || stdenv.isx86_64 || stdenv.isMips;
+   inherit (stdenv.lib) optionals optionalString;
+in
+
+stdenv.mkDerivation rec {
+
+  name = "ber-metaocaml-${version}";
+  version = "104";
+
+  src = fetchurl {
+    url = "http://caml.inria.fr/pub/distrib/ocaml-4.04/ocaml-4.04.0.tar.gz";
+    sha256 = "1pi2hdm9lxhn45qvfqfss1hpa4jijm14qgmrgajsadxqdiplhqyb";
+  };
+
+  metaocaml = fetchurl {
+    url = "http://okmij.org/ftp/ML/ber-metaocaml-104.tar.gz";
+    sha256 = "1gmwlxairxqcmqa2r6kbf8b4dxc7pfhfbh48g1s14d3z20rj8nib";
+  };
+
+  # Needed to avoid a SIGBUS on the final executable on mips
+  NIX_CFLAGS_COMPILE = if stdenv.isMips then "-fPIC" else "";
+
+  x11env = buildEnv { name = "x11env"; paths = [libX11 xproto];};
+  x11lib = x11env + "/lib";
+  x11inc = x11env + "/include";
+
+  prefixKey = "-prefix ";
+  configureFlags = optionals useX11 [ "-x11lib" x11lib
+                                      "-x11include" x11inc ];
+
+  dontStrip = true;
+  buildInputs = [ncurses] ++ optionals useX11 [ libX11 xproto ];
+  installFlags = "-i";
+  installTargets = "install"; # + optionalString useNativeCompilers " installopt";
+
+  postConfigure = ''
+    tar -xvzf $metaocaml
+    cd ${name}
+    make patch
+    cd ..
+  '';
+  buildPhase = ''
+    make world
+    make -i install
+
+    make bootstrap
+    make opt.opt
+    make installopt
+    mkdir -p $out/include
+    ln -sv $out/lib/ocaml/caml $out/include/caml
+    cd ${name}
+    make all
+    make install
+    make install.opt
+    cd ..
+ '';
+  installPhase = "";
+  postBuild = ''
+  '';
+  checkPhase = ''
+    cd ${name}
+    make test
+    make test-compile
+    make test-native
+    cd ..
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = "http://okmij.org/ftp/ML/index.html#ber-metaocaml";
+    license = with licenses; [
+      qpl /* compiler */
+      lgpl2 /* library */
+    ];
+    description = "Conservative extension of OCaml";
+    longDescription = ''
+      A conservative extension of OCaml with the primitive type of code values,
+      and three basic multi-stage expression forms: Brackets, Escape, and Run
+    '';
+  };
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 301bcfd193d..f0c4b6e7c57 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -6260,6 +6260,8 @@ with pkgs;
 
   ber_metaocaml_003 = callPackage ../development/compilers/ocaml/ber-metaocaml-003.nix { };
 
+  ber_metaocaml = callPackage ../development/compilers/ocaml/ber-metaocaml-104.nix { };
+
   ocaml_make = callPackage ../development/ocaml-modules/ocamlmake { };
 
   ocaml-top = callPackage ../development/tools/ocaml/ocaml-top { };

From 9a072a466cd7f4aaba91c1302a2c895425cb8491 Mon Sep 17 00:00:00 2001
From: Matthew Pickering <matthewtpickering@gmail.com>
Date: Fri, 8 Dec 2017 23:39:51 +0000
Subject: [PATCH 2/2] Remove broken ber-metaocaml-003 attribute

---
 .../compilers/ocaml/ber-metaocaml-003.nix     | 72 -------------------
 pkgs/top-level/all-packages.nix               |  2 -
 2 files changed, 74 deletions(-)
 delete mode 100644 pkgs/development/compilers/ocaml/ber-metaocaml-003.nix

diff --git a/pkgs/development/compilers/ocaml/ber-metaocaml-003.nix b/pkgs/development/compilers/ocaml/ber-metaocaml-003.nix
deleted file mode 100644
index c95d29326a4..00000000000
--- a/pkgs/development/compilers/ocaml/ber-metaocaml-003.nix
+++ /dev/null
@@ -1,72 +0,0 @@
-{ stdenv, fetchurl, ncurses, xlibsWrapper }:
-
-let
-   useX11 = stdenv.isi686 || stdenv.isx86_64;
-   useNativeCompilers = stdenv.isi686 || stdenv.isx86_64 || stdenv.isMips;
-   inherit (stdenv.lib) optionals optionalString;
-in
-
-stdenv.mkDerivation rec {
-  
-  name = "ber-metaocaml-${version}";
-  version = "003";
-  
-  src = fetchurl {
-    url = "http://caml.inria.fr/pub/distrib/ocaml-3.11/ocaml-3.11.2.tar.bz2";
-    sha256 = "0hw1yp1mmfyn1pmda232d0ry69m7ln1z0fn5lgi8nz3y1mx3iww6";
-  };
-
-  metaocaml = fetchurl {
-    url = "http://okmij.org/ftp/ML/ber-metaocaml.tar.gz";
-    sha256 = "1kq1if25c1wvcdiy4g46xk05dkc1am2gc4qvmg4x19wvvaz09gzf";
-  };
-
-  # Needed to avoid a SIGBUS on the final executable on mips
-  NIX_CFLAGS_COMPILE = if stdenv.isMips then "-fPIC" else "";
-
-  patches = optionals stdenv.isDarwin [ ./gnused-on-osx-fix.patch ];
-
-  prefixKey = "-prefix ";
-  configureFlags = ["-no-tk"] ++ optionals useX11 [ "-x11lib" xlibsWrapper ];
-  buildFlags = "core coreboot all"; # "world" + optionalString useNativeCompilers " bootstrap world.opt";
-  buildInputs = [ncurses] ++ optionals useX11 [ xlibsWrapper ];
-  installFlags = "-i";
-  installTargets = "install"; # + optionalString useNativeCompilers " installopt";
-  prePatch = ''
-    CAT=$(type -tp cat)
-    sed -e "s@/bin/cat@$CAT@" -i config/auto-aux/sharpbang
-    patch -p0 < ${./mips64.patch}
-  '';
-  postConfigure = ''
-    tar -xvzf $metaocaml
-    cd ${name}
-    make patch
-    cd ..
-  '';
-  postBuild = ''
-    mkdir -p $out/include
-    ln -sv $out/lib/ocaml/caml $out/include/caml
-  '';
-  postInstall = ''
-    cd ${name}
-    make all
-    make install
-    make test
-    make test-compile
-    cd ..
-  '';
-
-  meta = with stdenv.lib; {
-    homepage = "http://okmij.org/ftp/ML/index.html#ber-metaocaml";
-    license = with licenses; [
-      qpl /* compiler */
-      lgpl2 /* library */
-    ];
-    description = "Conservative extension of OCaml";
-    longDescription = ''
-      A conservative extension of OCaml with the primitive type of code values,
-      and three basic multi-stage expression forms: Brackets, Escape, and Run
-    '';
-    broken = true;
-  };
-}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index f0c4b6e7c57..5c198eaa8f2 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -6258,8 +6258,6 @@ with pkgs;
 
   metaocaml_3_09 = callPackage ../development/compilers/ocaml/metaocaml-3.09.nix { };
 
-  ber_metaocaml_003 = callPackage ../development/compilers/ocaml/ber-metaocaml-003.nix { };
-
   ber_metaocaml = callPackage ../development/compilers/ocaml/ber-metaocaml-104.nix { };
 
   ocaml_make = callPackage ../development/ocaml-modules/ocamlmake { };