1{ stdenv, fetchgit, bash, coreutils, ocaml, zlib, pcre, neko, camlp4 }:
2
3let
4 generic = { version, sha256, prePatch }:
5 stdenv.mkDerivation rec {
6 name = "haxe-${version}";
7
8 buildInputs = [ocaml zlib pcre neko camlp4];
9
10 src = fetchgit {
11 url = https://github.com/HaxeFoundation/haxe.git;
12 inherit sha256;
13 fetchSubmodules = true;
14 rev = "refs/tags/${version}";
15 };
16
17 inherit prePatch;
18
19 buildFlags = [ "all" "tools" ];
20
21 installPhase = ''
22 install -vd "$out/bin" "$out/lib/haxe/std"
23 cp -vr haxe haxelib std "$out/lib/haxe"
24
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
29
30 if [[ "\$HAXELIB_PATH" =~ : ]]; then
31 NEW_HAXELIB_PATH="\$(${coreutils}/bin/mktemp -d)"
32
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 '';
51
52 setupHook = ./setup-hook.sh;
53
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 };
64in {
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.6";
76 sha256 = "1myc4b8fwp0f9vky17wv45n34a583f5sjvajsc93f5gm1wanp4if";
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 '';
81 };
82}