@@ -0,0 +1,150 @@
1+{ stdenv
2+, coreutils
3+, patchelf
4+, requireFile
5+, callPackage
6+, alsaLib
7+, dbus
8+, fontconfig
9+, freetype
10+, gcc
11+, glib
12+, ncurses
13+, opencv
14+, openssl
15+, unixODBC
16+, xkeyboard_config
17+, xorg
18+, zlib
19+, libxml2
20+, libuuid
21+, lang ? "en"
22+, libGL
23+, libGLU
24+}:
25+
26+let
27+ l10n =
28+ import ./l10ns.nix {
29+ lib = stdenv.lib;
30+ inherit requireFile lang;
31+ majorVersion = "11";
32+ };
33+in
34+stdenv.mkDerivation rec {
35+ inherit (l10n) version name src;
36+
37+ buildInputs = [
38+ coreutils
39+ patchelf
40+ alsaLib
41+ coreutils
42+ dbus
43+ fontconfig
44+ freetype
45+ gcc.cc
46+ gcc.libc
47+ glib
48+ ncurses
49+ opencv
50+ openssl
51+ unixODBC
52+ xkeyboard_config
53+ libxml2
54+ libuuid
55+ zlib
56+ libGL
57+ libGLU
58+ ] ++ (with xorg; [
59+ libX11
60+ libXext
61+ libXtst
62+ libXi
63+ libXmu
64+ libXrender
65+ libxcb
66+ libXcursor
67+ libXfixes
68+ libXrandr
69+ libICE
70+ libSM
71+ ]);
72+
73+ ldpath = stdenv.lib.makeLibraryPath buildInputs
74+ + stdenv.lib.optionalString (stdenv.hostPlatform.system == "x86_64-linux")
75+ (":" + stdenv.lib.makeSearchPathOutput "lib" "lib64" buildInputs);
76+
77+ phases = "unpackPhase installPhase fixupPhase";
78+
79+ unpackPhase = ''
80+ echo "=== Extracting makeself archive ==="
81+ # find offset from file
82+ offset=$(${stdenv.shell} -c "$(grep -axm1 -e 'offset=.*' $src); echo \$offset" $src)
83+ dd if="$src" ibs=$offset skip=1 | tar -xf -
84+ cd Unix
85+ '';
86+
87+ installPhase = ''
88+ cd Installer
89+ # don't restrict PATH, that has already been done
90+ sed -i -e 's/^PATH=/# PATH=/' MathInstaller
91+ sed -i -e 's/\/bin\/bash/\/bin\/sh/' MathInstaller
92+
93+ echo "=== Running MathInstaller ==="
94+ ./MathInstaller -auto -createdir=y -execdir=$out/bin -targetdir=$out/libexec/Mathematica -silent
95+
96+ # Fix library paths
97+ cd $out/libexec/Mathematica/Executables
98+ for path in mathematica MathKernel Mathematica WolframKernel wolfram math; do
99+ sed -i -e 's#export LD_LIBRARY_PATH$#export LD_LIBRARY_PATH=${zlib}/lib:\''${LD_LIBRARY_PATH}#' $path
100+ done
101+
102+ # Fix xkeyboard config path for Qt
103+ for path in mathematica Mathematica; do
104+ line=$(grep -n QT_PLUGIN_PATH $path | sed 's/:.*//')
105+ sed -i -e "$line iexport QT_XKB_CONFIG_ROOT=\"${xkeyboard_config}/share/X11/xkb\"" $path
106+ done
107+ '';
108+
109+ preFixup = ''
110+ echo "=== PatchElfing away ==="
111+ # This code should be a bit forgiving of errors, unfortunately
112+ set +e
113+ find $out/libexec/Mathematica/SystemFiles -type f -perm -0100 | while read f; do
114+ type=$(readelf -h "$f" 2>/dev/null | grep 'Type:' | sed -e 's/ *Type: *\([A-Z]*\) (.*/\1/')
115+ if [ -z "$type" ]; then
116+ :
117+ elif [ "$type" == "EXEC" ]; then
118+ echo "patching $f executable <<"
119+ patchelf --shrink-rpath "$f"
120+ patchelf \
121+ --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
122+ --set-rpath "$(patchelf --print-rpath "$f"):${ldpath}" \
123+ "$f" \
124+ && patchelf --shrink-rpath "$f" \
125+ || echo unable to patch ... ignoring 1>&2
126+ elif [ "$type" == "DYN" ]; then
127+ echo "patching $f library <<"
128+ patchelf \
129+ --set-rpath "$(patchelf --print-rpath "$f"):${ldpath}" \
130+ "$f" \
131+ && patchelf --shrink-rpath "$f" \
132+ || echo unable to patch ... ignoring 1>&2
133+ else
134+ echo "not patching $f <<: unknown elf type"
135+ fi
136+ done
137+ '';
138+
139+ # all binaries are already stripped
140+ dontStrip = true;
141+
142+ # we did this in prefixup already
143+ dontPatchELF = true;
144+
145+ meta = {
146+ description = "Wolfram Mathematica computational software system";
147+ homepage = http://www.wolfram.com/mathematica/;
148+ license = stdenv.lib.licenses.unfree;
149+ };
150+}