@@ -1,40 +1,82 @@
1−{ stdenv, fetchgit, ocaml, zlib, pcre, neko, camlp4 }:
1+{ stdenv, fetchgit, bash, coreutils, ocaml, zlib, pcre, neko, camlp4 }:
22
3−stdenv.mkDerivation {
4− name = "haxe-3.4.2";
3+let
4+ generic = { version, sha256, prePatch }:
5+ stdenv.mkDerivation rec {
6+ name = "haxe-${version}";
57
6− buildInputs = [ocaml zlib pcre neko camlp4];
8+ buildInputs = [ocaml zlib pcre neko camlp4];
79
8− src = fetchgit {
9− url = "https://github.com/HaxeFoundation/haxe.git";
10− sha256 = "1m5fp183agqv8h3ynhxw4kndkpq2d6arysmirv3zl3vz5crmpwqd";
11− fetchSubmodules = true;
10+ src = fetchgit {
11+ url = https://github.com/HaxeFoundation/haxe.git;
12+ inherit sha256;
13+ fetchSubmodules = true;
14+ rev = "refs/tags/${version}";
15+ };
1216
13− # Tag 3.4.2
14− rev = "890f8c70cf23ce6f9fe0fdd0ee514a9699433ca7";
15− };
17+ inherit prePatch;
18+
19+ buildFlags = [ "all" "tools" ];
1620
17− prePatch = ''
18− sed -i -e 's|"/usr/lib/haxe/std/";|"'"$out/lib/haxe/std/"'";\n&|g' src/main.ml
19− '';
21+ installPhase = ''
22+ install -vd "$out/bin" "$out/lib/haxe/std"
23+ cp -vr haxe haxelib std "$out/lib/haxe"
2024
21− buildFlags = [ "all" "tools" ];
25+ # make wrappers which provide a temporary HAXELIB_PATH with symlinks to multiple repositories HAXELIB_PATH may point to
26+ for name in haxe haxelib; do
27+ cat > $out/bin/$name <<EOF
28+ #!{bash}/bin/bash
2229
23− installPhase = ''
24− install -vd "$out/bin" "$out/lib/haxe/std"
25− install -vt "$out/bin" haxe haxelib
26− cp -vr std "$out/lib/haxe"
27− '';
30+ if [[ "\$HAXELIB_PATH" =~ : ]]; then
31+ NEW_HAXELIB_PATH="\$(${coreutils}/bin/mktemp -d)"
2832
29− setupHook = ./setup-hook.sh;
33+ IFS=':' read -ra libs <<< "\$HAXELIB_PATH"
34+ for libdir in "\''${libs[@]}"; do
35+ for lib in "\$libdir"/*; do
36+ if [ ! -e "\$NEW_HAXELIB_PATH/\$(${coreutils}/bin/basename "\$lib")" ]; then
37+ ${coreutils}/bin/ln -s "--target-directory=\$NEW_HAXELIB_PATH" "\$lib"
38+ fi
39+ done
40+ done
41+ export HAXELIB_PATH="\$NEW_HAXELIB_PATH"
42+ $out/lib/haxe/$name "\$@"
43+ rm -rf "\$NEW_HAXELIB_PATH"
44+ else
45+ exec $out/lib/haxe/$name "\$@"
46+ fi
47+ EOF
48+ chmod +x $out/bin/$name
49+ done
50+ '';
3051
31− dontStrip = true;
52+ setupHook = ./setup-hook.sh;
3253
33− meta = with stdenv.lib; {
34− description = "Programming language targeting JavaScript, Flash, NekoVM, PHP, C++";
35− homepage = https://haxe.org;
36− license = with licenses; [ gpl2 bsd2 /*?*/ ]; # -> docs/license.txt
37− maintainers = [ maintainers.marcweber ];
38− platforms = platforms.linux ++ platforms.darwin;
54+ dontStrip = true;
55+
56+ meta = with stdenv.lib; {
57+ description = "Programming language targeting JavaScript, Flash, NekoVM, PHP, C++";
58+ homepage = https://haxe.org;
59+ license = with licenses; [ gpl2 bsd2 /*?*/ ]; # -> docs/license.txt
60+ maintainers = [ maintainers.marcweber ];
61+ platforms = platforms.linux ++ platforms.darwin;
62+ };
63+ };
64+in {
65+ # this old version is required to compile some libraries
66+ haxe_3_2 = generic {
67+ version = "3.2.1";
68+ sha256 = "1x9ay5a2llq46fww3k07jxx8h1vfpyxb522snc6702a050ki5vz3";
69+ prePatch = ''
70+ sed -i -e 's|"/usr/lib/haxe/std/";|"'"$out/lib/haxe/std/"'";\n&|g' main.ml
71+ sed -i -e 's|"neko"|"${neko}/bin/neko"|g' extra/haxelib_src/src/tools/haxelib/Main.hx
72+ '';
73+ };
74+ haxe_3_4 = generic {
75+ version = "3.4.2";
76+ sha256 = "1m5fp183agqv8h3ynhxw4kndkpq2d6arysmirv3zl3vz5crmpwqd";
77+ prePatch = ''
78+ sed -i -e 's|"/usr/lib/haxe/std/";|"'"$out/lib/haxe/std/"'";\n&|g' src/main.ml
79+ sed -i -e 's|"neko"|"${neko}/bin/neko"|g' extra/haxelib_src/src/haxelib/client/Main.hx
80+ '';
3981 };
4082}