1{ stdenv
2, lib
3, fetchurl
4, perl
5, gmp
6, gf2x ? null
7# I asked the ntl maintainer weather or not to include gf2x by default:
8# > If I remember correctly, gf2x is now thread safe, so there's no reason not to use it.
9, withGf2x ? true
10, tune ? false # tune for current system; non reproducible and time consuming
11}:
12
13assert withGf2x -> gf2x != null;
14
15stdenv.mkDerivation rec {
16 pname = "ntl";
17 version = "11.5.1";
18
19 src = fetchurl {
20 url = "http://www.shoup.net/ntl/ntl-${version}.tar.gz";
21 sha256 = "sha256-IQ0GwxMGy8bq9oFEU8Vsd22djo3zbXTrMG9qUj0caoo=";
22 };
23
24 buildInputs = [
25 gmp
26 ];
27
28 nativeBuildInputs = [
29 perl # needed for ./configure
30 ];
31
32 sourceRoot = "${pname}-${version}/src";
33
34 enableParallelBuilding = true;
35
36 dontAddPrefix = true; # DEF_PREFIX instead
37
38 # Written in perl, does not support autoconf-style
39 # --build=/--host= options:
40 # Error: unrecognized option: --build=x86_64-unknown-linux-gnu
41 configurePlatforms = [ ];
42
43 # reference: http://shoup.net/ntl/doc/tour-unix.html
44 configureFlags = [
45 "DEF_PREFIX=$(out)"
46 "SHARED=on" # genereate a shared library (as well as static)
47 "NATIVE=off" # don't target code to current hardware (reproducibility, portability)
48 "TUNE=${
49 if tune then
50 "auto"
51 else if stdenv.hostPlatform.isx86 then
52 "x86" # "chooses options that should be well suited for most x86 platforms"
53 else
54 "generic" # "chooses options that should be OK for most platforms"
55 }"
56 "CXX=${stdenv.cc.targetPrefix}c++"
57 ] ++ lib.optionals withGf2x [
58 "NTL_GF2X_LIB=on"
59 "GF2X_PREFIX=${gf2x}"
60 ];
61
62 doCheck = true; # takes some time
63
64 meta = with lib; {
65 description = "A Library for doing Number Theory";
66 longDescription = ''
67 NTL is a high-performance, portable C++ library providing data
68 structures and algorithms for manipulating signed, arbitrary
69 length integers, and for vectors, matrices, and polynomials over
70 the integers and over finite fields.
71 '';
72 # Upstream contact: maintainer is victorshoup on GitHub. Alternatively the
73 # email listed on the homepage.
74 homepage = "http://www.shoup.net/ntl/";
75 # also locally at "${src}/doc/tour-changes.html";
76 changelog = "https://www.shoup.net/ntl/doc/tour-changes.html";
77 maintainers = teams.sage.members;
78 license = licenses.gpl2Plus;
79 platforms = platforms.all;
80 };
81}