<commit_before>{ stdenv, fetchurl, gmp, bison, perl, autoconf, ncurses, readline, coreutils, pkgconfig
, autoreconfHook
, flint
, ntl
, cddlib
, enableFactory ? true
, enableGfanlib ? true
}:

stdenv.mkDerivation rec {
  name = "singular-${version}${patchVersion}";
  version = "4.1.1";
  patchVersion = "p1";

  urlVersion = builtins.replaceStrings [ "." ] [ "-" ] version;
  src = fetchurl {
    url = "http://www.mathematik.uni-kl.de/ftp/pub/Math/Singular/SOURCES/${urlVersion}/singular-${version}${patchVersion}.tar.gz";
    sha256 = "0wvgz7l1b7zkpmim0r3mvv4fp8xnhlbz4c7hc90rn30snlansnf1";
  };

  configureFlags = stdenv.lib.optionals enableFactory [
    "--enable-factory"
  ] ++ stdenv.lib.optionals enableGfanlib [
    "--enable-gfanlib"
  ];

  postUnpack = ''
    patchShebangs .
  '';

  # For reference (last checked on commit 75f460d):
  # https://github.com/Singular/Sources/blob/spielwiese/doc/Building-Singular-from-source.md
  # https://github.com/Singular/Sources/blob/spielwiese/doc/external-packages-dynamic-modules.md
  buildInputs = [
    # necessary
    gmp
    # by upstream recommended but optional
    ncurses
    readline
    ntl
    flint
  ] ++ stdenv.lib.optionals enableGfanlib [
    cddlib
  ];
  nativeBuildInputs = [ autoconf bison perl pkgconfig autoreconfHook ];

  preConfigure = ''
    find . -type f -exec sed -e 's@/bin/rm@${coreutils}&@g' -i '{}' ';'
    find . -type f -exec sed -e 's@/bin/uname@${coreutils}&@g' -i '{}' ';'
  '';

  hardeningDisable = stdenv.lib.optional stdenv.isi686 "stackprotector";

  # The Makefile actually defaults to `make install` anyway
  buildPhase = "true;";

  installPhase = ''
    mkdir -p "$out"
    cp -r Singular/LIB "$out/lib"
    make install<commit_msg>singular: Fix ntl dependency<commit_after>{ stdenv, fetchurl, gmp, bison, perl, autoconf, ncurses, readline, coreutils, pkgconfig
, autoreconfHook
, file
, flint
, ntl
, cddlib
, enableFactory ? true
, enableGfanlib ? true
}:

stdenv.mkDerivation rec {
  name = "singular-${version}${patchVersion}";
  version = "4.1.1";
  patchVersion = "p1";

  urlVersion = builtins.replaceStrings [ "." ] [ "-" ] version;
  src = fetchurl {
    url = "http://www.mathematik.uni-kl.de/ftp/pub/Math/Singular/SOURCES/${urlVersion}/singular-${version}${patchVersion}.tar.gz";
    sha256 = "0wvgz7l1b7zkpmim0r3mvv4fp8xnhlbz4c7hc90rn30snlansnf1";
  };

  configureFlags = [
    "--with-ntl=${ntl}"
  ] ++stdenv.lib.optionals enableFactory [
    "--enable-factory"
  ] ++ stdenv.lib.optionals enableGfanlib [
    "--enable-gfanlib"
  ];

  postUnpack = ''
    patchShebangs .
  '';

  # For reference (last checked on commit 75f460d):
  # https://github.com/Singular/Sources/blob/spielwiese/doc/Building-Singular-from-source.md
  # https://github.com/Singular/Sources/blob/spielwiese/doc/external-packages-dynamic-modules.md
  buildInputs = [
    # necessary
    gmp
    # by upstream recommended but optional
    ncurses
    readline
    ntl
    flint
  ] ++ stdenv.lib.optionals enableGfanlib [
    cddlib
  ];
  nativeBuildInputs = [
    bison
    perl
    pkgconfig
    autoreconfHook
  ];

  preAutoreconf = ''
    find . -type f -readable -writable -exec sed \
      -e 's@/bin/rm@${coreutils}&@g' \
      -e 's@/bin/uname@${coreutils}&@g' \
      -e 's@/usr/bin/file@${file}/bin/file@g' \
      -i '{}' ';'
  '';

  hardeningDisable = stdenv.lib.optional stdenv.isi686 "stackprotector";

  # The Makefile actually defaults to `make install` anyway
  buildPhase = "true;";

  installPhase = ''
    mkdir -p "$out"
    cp -r Singular/LIB "$out/lib"
    make install
{'fraction_non_alphanumeric': 0.1495118549511855, 'fraction_numerical': 0.016736401673640166, 'mean_word_length': 3.2589073634204277, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5557884', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1330, 'n_words': 233}