@@ -1,23 +1,52 @@
11{ stdenv, fetchurl, gmp, bison, perl, autoconf, ncurses, readline, coreutils, pkgconfig
2−, asLibsingular ? false
2+, autoreconfHook
3+, flint
4+, ntl
5+, cddlib
6+, enableFactory ? true
7+, enableGfanlib ? true
38}:
49
510stdenv.mkDerivation rec {
6− name = "singular-${version}";
7− version="3-1-7";
11+ name = "singular-${version}${patchVersion}";
12+ version = "4.1.1";
13+ patchVersion = "p1";
814
15+ urlVersion = builtins.replaceStrings [ "." ] [ "-" ] version;
916 src = fetchurl {
10− url = "http://www.mathematik.uni-kl.de/ftp/pub/Math/Singular/SOURCES/${version}/Singular-${version}.tar.gz";
11− sha256 = "1j4mcpnwzdp3h4qspk6ww0m67rmx4s11cy17pvzbpf70lm0jzzh2";
17+ url = "http://www.mathematik.uni-kl.de/ftp/pub/Math/Singular/SOURCES/${urlVersion}/singular-${version}${patchVersion}.tar.gz";
18+ sha256 = "0wvgz7l1b7zkpmim0r3mvv4fp8xnhlbz4c7hc90rn30snlansnf1";
1219 };
1320
14− buildInputs = [ gmp perl ncurses readline ];
15− nativeBuildInputs = [ autoconf bison pkgconfig ];
21+ configureFlags = stdenv.lib.optionals enableFactory [
22+ "--enable-factory"
23+ ] ++ stdenv.lib.optionals enableGfanlib [
24+ "--enable-gfanlib"
25+ ];
26+
27+ postUnpack = ''
28+ patchShebangs .
29+ '';
30+
31+ # For reference (last checked on commit 75f460d):
32+ # https://github.com/Singular/Sources/blob/spielwiese/doc/Building-Singular-from-source.md
33+ # https://github.com/Singular/Sources/blob/spielwiese/doc/external-packages-dynamic-modules.md
34+ buildInputs = [
35+ # necessary
36+ gmp
37+ # by upstream recommended but optional
38+ ncurses
39+ readline
40+ ntl
41+ flint
42+ ] ++ stdenv.lib.optionals enableGfanlib [
43+ cddlib
44+ ];
45+ nativeBuildInputs = [ autoconf bison perl pkgconfig autoreconfHook ];
1646
1747 preConfigure = ''
1848 find . -type f -exec sed -e 's@/bin/rm@${coreutils}&@g' -i '{}' ';'
1949 find . -type f -exec sed -e 's@/bin/uname@${coreutils}&@g' -i '{}' ';'
20− ${stdenv.lib.optionalString asLibsingular ''NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -DLIBSINGULAR"''}
2150 '';
2251
2352 hardeningDisable = stdenv.lib.optional stdenv.isi686 "stackprotector";
@@ -27,17 +56,21 @@ stdenv.mkDerivation rec {
2756
2857 installPhase = ''
2958 mkdir -p "$out"
30− cp -r Singular/LIB "$out/LIB"
31− make install${stdenv.lib.optionalString asLibsingular "-libsingular"}
32−
33− binaries="$(find "$out"/* \( -type f -o -type l \) -perm -111 \! -name '*.so' -maxdepth 1)"
34− ln -s "$out"/*/{include,lib} "$out"
35− mkdir -p "$out/bin"
36− for b in $binaries; do
37− bbn="$(basename "$b")"
38− echo -e '#! ${stdenv.shell}\n"'"$b"'" "$@"' > "$out/bin/$bbn"
39− chmod a+x "$out/bin/$bbn"
40− done
59+ cp -r Singular/LIB "$out/lib"
60+ make install
61+
62+ # Make sure patchelf picks up the right libraries
63+ rm -rf libpolys factory resources omalloc Singular
64+ '';
65+
66+ # simple test to make sure singular starts and finds its libraries
67+ doInstallCheck = true;
68+ installCheckPhase = ''
69+ $out/bin/Singular -c 'LIB "freegb.lib"; exit;'
70+ if [ $? -ne 0 ]; then
71+ echo >&2 "Error loading the freegb library in Singular."
72+ exit 1
73+ fi
4174 '';
4275
4376 enableParallelBuilding = true;
@@ -47,7 +80,7 @@ stdenv.mkDerivation rec {
4780 maintainers = with maintainers; [ raskin ];
4881 platforms = subtractLists platforms.i686 platforms.linux;
4982 license = licenses.gpl3; # Or GPLv2 at your option - but not GPLv4
50− homepage = http://www.singular.uni-kl.de/index.php;
83+ homepage = http://www.singular.uni-kl.de;
5184 downloadPage = "http://www.mathematik.uni-kl.de/ftp/pub/Math/Singular/SOURCES/";
5285 };
5386}