@@ -1,4 +1,6 @@
1−{ stdenv, fetchurl, gmp, bison, perl, autoconf, ncurses, readline, coreutils }:
1+{ stdenv, fetchurl, gmp, bison, perl, autoconf, ncurses, readline, coreutils, pkgconfig
2+, asLibsingular ? false
3+}:
24
35stdenv.mkDerivation rec {
46 name = "singular-${version}";
@@ -9,23 +11,33 @@ stdenv.mkDerivation rec {
911 sha256 = "1j4mcpnwzdp3h4qspk6ww0m67rmx4s11cy17pvzbpf70lm0jzzh2";
1012 };
1113
12− buildInputs = [ gmp bison perl autoconf ncurses readline coreutils ];
14+ buildInputs = [ gmp perl ncurses readline ];
15+ nativeBuildInputs = [ autoconf bison pkgconfig ];
1316
1417 preConfigure = ''
1518 find . -exec sed -e 's@/bin/rm@${coreutils}&@g' -i '{}' ';'
1619 find . -exec sed -e 's@/bin/uname@${coreutils}&@g' -i '{}' ';'
20+ ${stdenv.lib.optionalString asLibsingular ''NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -DLIBSINGULAR"''}
1721 '';
1822
1923 hardeningDisable = stdenv.lib.optional stdenv.isi686 "stackprotector";
2024
21− postInstall = ''
22− rm -rf "$out/LIB"
23− cp -Tr Singular/LIB "$out/lib"
24− ln -s "$out"/*/include "$out"
25+ # The Makefile actually defaults to `make install` anyway
26+ buildPhase = "true;";
27+
28+ installPhase = ''
29+ 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"
2535 mkdir -p "$out/bin"
26− ln -s "$out/"*/Singular "$out/bin"
36+ ln -s $binaries "$out/bin"
2737 '';
2838
39+ enableParallelBuild = true;
40+
2941 meta = with stdenv.lib; {
3042 description = "A CAS for polynomial computations";
3143 maintainers = with maintainers;