Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 lib,
3 stdenv,
4 fetchurl,
5 m4,
6 cxx ? !stdenv.hostPlatform.useAndroidPrebuilt && !stdenv.hostPlatform.isWasm,
7 buildPackages,
8 withStatic ? stdenv.hostPlatform.isStatic,
9}:
10
11# Note: this package is used for bootstrapping fetchurl, and thus
12# cannot use fetchpatch! All mutable patches (generated by GitHub or
13# cgit) that are needed here should be included directly in Nixpkgs as
14# files.
15
16let
17 inherit (lib) optional;
18in
19
20let
21 self = stdenv.mkDerivation rec {
22 pname = "gmp${lib.optionalString cxx "-with-cxx"}";
23 version = "6.3.0";
24
25 src = fetchurl {
26 # we need to use bz2, others aren't in bootstrapping stdenv
27 urls = [
28 "mirror://gnu/gmp/gmp-${version}.tar.bz2"
29 "ftp://ftp.gmplib.org/pub/gmp-${version}/gmp-${version}.tar.bz2"
30 ];
31 hash = "sha256-rCghGnz7YJuuLiyNYFjWbI/pZDT3QM9v4uR7AA0cIMs=";
32 };
33
34 #outputs TODO: split $cxx due to libstdc++ dependency
35 # maybe let ghc use a version with *.so shared with rest of nixpkgs and *.a added
36 # - see #5855 for related discussion
37 outputs = [
38 "out"
39 "dev"
40 "info"
41 ];
42 passthru.static = self.out;
43
44 strictDeps = true;
45 depsBuildBuild = [ buildPackages.stdenv.cc ];
46 nativeBuildInputs = [ m4 ];
47
48 configureFlags = [
49 "--with-pic"
50 # gcc-15 have c23 standard by default, where "void foo()" now means "void foo(void)".
51 #
52 # The "configure" script relies on c17 and below semantics for "long long
53 # reliability test 1" (defined in aclocal.m4)
54 "CFLAGS=-std=c99"
55
56 (lib.enableFeature cxx "cxx")
57 # Build a "fat binary", with routines for several sub-architectures
58 # (x86), except on Solaris where some tests crash with "Memory fault".
59 # See <https://hydra.nixos.org/build/2760931>, for instance.
60 #
61 # no darwin because gmp uses ASM that clang doesn't like
62 (lib.enableFeature (!stdenv.hostPlatform.isSunOS && stdenv.hostPlatform.isx86) "fat")
63 # The config.guess in GMP tries to runtime-detect various
64 # ARM optimization flags via /proc/cpuinfo (and is also
65 # broken on multicore CPUs). Avoid this impurity.
66 "--build=${stdenv.buildPlatform.config}"
67 ]
68 ++ optional (cxx && stdenv.hostPlatform.isDarwin) "CPPFLAGS=-fexceptions"
69 ++ optional (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.is64bit) "ABI=64"
70 # to build a .dll on windows, we need --disable-static + --enable-shared
71 # see https://gmplib.org/manual/Notes-for-Particular-Systems.html
72 ++ optional (!withStatic && stdenv.hostPlatform.isWindows) "--disable-static --enable-shared"
73 ++ optional (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) "--disable-assembly";
74
75 doCheck = true; # not cross;
76
77 dontDisableStatic = withStatic;
78
79 enableParallelBuilding = true;
80
81 meta = with lib; {
82 homepage = "https://gmplib.org/";
83 description = "GNU multiple precision arithmetic library";
84 license = with licenses; [
85 lgpl3Only
86 gpl2Only
87 ];
88
89 longDescription = ''
90 GMP is a free library for arbitrary precision arithmetic, operating
91 on signed integers, rational numbers, and floating point numbers.
92 There is no practical limit to the precision except the ones implied
93 by the available memory in the machine GMP runs on. GMP has a rich
94 set of functions, and the functions have a regular interface.
95
96 The main target applications for GMP are cryptography applications
97 and research, Internet security applications, algebra systems,
98 computational algebra research, etc.
99
100 GMP is carefully designed to be as fast as possible, both for small
101 operands and for huge operands. The speed is achieved by using
102 fullwords as the basic arithmetic type, by using fast algorithms,
103 with highly optimised assembly code for the most common inner loops
104 for a lot of CPUs, and by a general emphasis on speed.
105
106 GMP is faster than any other bignum library. The advantage for GMP
107 increases with the operand sizes for many operations, since GMP uses
108 asymptotically faster algorithms.
109 '';
110
111 platforms = platforms.all;
112 maintainers = [ ];
113 };
114 };
115in
116self