Build with the PIC version of libasmrun. Fix the mlgmpidl interface.
This commit is contained in:
parent
4135bf0b9f
commit
a4b8f7c376
153
ocaml-tplib-mlgmpidl.patch
Normal file
153
ocaml-tplib-mlgmpidl.patch
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
--- src/numeric_plugins/mlgmp_plugin.ml.orig 2013-02-14 04:08:25.000000000 -0700
|
||||||
|
+++ src/numeric_plugins/mlgmp_plugin.ml 2017-12-03 14:00:36.471566987 -0700
|
||||||
|
@@ -19,48 +19,69 @@
|
||||||
|
|
||||||
|
*)
|
||||||
|
|
||||||
|
-open Gmp
|
||||||
|
-
|
||||||
|
-let bits_of_string s =
|
||||||
|
- let s' = String.sub s 2 ((String.length s)-2) in (* remove prefix "0b" *)
|
||||||
|
- Z.from_string_base ~base:2 s'
|
||||||
|
+let randobj = Gmp_random.init_default ();
|
||||||
|
|
||||||
|
module Mlgmp_int =
|
||||||
|
struct
|
||||||
|
- type t = Z.t
|
||||||
|
+ type t = Mpz.t
|
||||||
|
|
||||||
|
- let zero = Z.of_int 0
|
||||||
|
- let max x y = if Z.cmp x y >= 0 then x else y
|
||||||
|
- let min x y = if Z.cmp x y >= 0 then y else x
|
||||||
|
- let add = Z.add
|
||||||
|
- let neg = Z.neg
|
||||||
|
- let mul = Z.mul
|
||||||
|
- let div = Z.cdiv_q
|
||||||
|
- let pow = Z.pow_ui
|
||||||
|
- let compare = Z.cmp
|
||||||
|
+ let zero = Mpz.of_int 0
|
||||||
|
+ let max x y = if Mpz.cmp x y >= 0 then x else y
|
||||||
|
+ let min x y = if Mpz.cmp x y >= 0 then y else x
|
||||||
|
+ let add x y =
|
||||||
|
+ let res = Mpz.init () in
|
||||||
|
+ Mpz.add res x y;
|
||||||
|
+ res
|
||||||
|
+ let neg x =
|
||||||
|
+ let res = Mpz.init () in
|
||||||
|
+ Mpz.neg res x;
|
||||||
|
+ res
|
||||||
|
+ let mul x y =
|
||||||
|
+ let res = Mpz.init () in
|
||||||
|
+ Mpz.mul res x y;
|
||||||
|
+ res
|
||||||
|
+ let div x y =
|
||||||
|
+ let res = Mpz.init () in
|
||||||
|
+ Mpz.cdiv_q res x y;
|
||||||
|
+ res
|
||||||
|
+ let pow x y =
|
||||||
|
+ let res = Mpz.init () in
|
||||||
|
+ Mpz.pow_ui res x y;
|
||||||
|
+ res
|
||||||
|
+ let compare = Mpz.cmp
|
||||||
|
let random n =
|
||||||
|
- bits_of_string (Random_generator.to_string n)
|
||||||
|
- let of_int = Z.from_int
|
||||||
|
- let of_string x =
|
||||||
|
- try
|
||||||
|
- Z.from_string_base ~base:10 x
|
||||||
|
- with Invalid_argument _ ->
|
||||||
|
- raise (Failure ("Mpzf.of_string: "^x^" is not well-formatted"))
|
||||||
|
- let to_string = Z.to_string_base ~base:10
|
||||||
|
+ let res = Mpz.init () in
|
||||||
|
+ Gmp_random.Mpz.urandomb res randobj n;
|
||||||
|
+ res
|
||||||
|
+ let of_int = Mpz.of_int
|
||||||
|
+ let of_string = Mpz.of_string
|
||||||
|
+ let to_string = Mpz.get_str ~base:10
|
||||||
|
end
|
||||||
|
|
||||||
|
module Mlgmp_rat =
|
||||||
|
struct
|
||||||
|
- type t = Q.t
|
||||||
|
+ type t = Mpq.t
|
||||||
|
|
||||||
|
- let zero = Q.from_int 0
|
||||||
|
- let one = Q.from_int 1
|
||||||
|
- let max x y = if Q.cmp x y >= 0 then x else y
|
||||||
|
- let min x y = if Q.cmp x y >= 0 then y else x
|
||||||
|
- let add = Q.add
|
||||||
|
- let neg = Q.neg
|
||||||
|
- let mul = Q.mul
|
||||||
|
- let div = Q.div
|
||||||
|
+ let zero = Mpq.of_int 0
|
||||||
|
+ let one = Mpq.of_int 1
|
||||||
|
+ let max x y = if Mpq.cmp x y >= 0 then x else y
|
||||||
|
+ let min x y = if Mpq.cmp x y >= 0 then y else x
|
||||||
|
+ let add x y =
|
||||||
|
+ let res = Mpq.init () in
|
||||||
|
+ Mpq.add res x y;
|
||||||
|
+ res
|
||||||
|
+ let neg x =
|
||||||
|
+ let res = Mpq.init () in
|
||||||
|
+ Mpq.neg res x;
|
||||||
|
+ res
|
||||||
|
+ let mul x y =
|
||||||
|
+ let res = Mpq.init () in
|
||||||
|
+ Mpq.mul res x y;
|
||||||
|
+ res
|
||||||
|
+ let div x y =
|
||||||
|
+ let res = Mpq.init () in
|
||||||
|
+ Mpq.div res x y;
|
||||||
|
+ res
|
||||||
|
|
||||||
|
let pow x n =
|
||||||
|
let rec pow_aux x n =
|
||||||
|
@@ -68,31 +89,29 @@ struct
|
||||||
|
if n = 0 then one
|
||||||
|
else
|
||||||
|
let y = pow_aux x (n/2) in
|
||||||
|
- let z = mul y y in
|
||||||
|
- if n mod 2 = 0 then
|
||||||
|
- z
|
||||||
|
- else
|
||||||
|
- mul x z
|
||||||
|
+ let z = Mpq.init () in
|
||||||
|
+ Mpq.mul z y y;
|
||||||
|
+ if n mod 2 != 0 then
|
||||||
|
+ Mpq.mul z x z;
|
||||||
|
+ z
|
||||||
|
in
|
||||||
|
if n >= 0 then
|
||||||
|
pow_aux x n
|
||||||
|
else
|
||||||
|
- pow_aux (Q.inv x) (-n)
|
||||||
|
+ pow_aux (Mpq.inv x x; x) (-n)
|
||||||
|
|
||||||
|
- let compare = Q.cmp
|
||||||
|
+ let compare = Mpq.cmp
|
||||||
|
let random n =
|
||||||
|
- let num = bits_of_string (Random_generator.to_string n) in
|
||||||
|
- let den = bits_of_string (Random_generator.to_string n) in
|
||||||
|
- Q.div (Q.from_z num) (Q.add Q.one (Q.from_z den))
|
||||||
|
- let of_int = Q.from_int
|
||||||
|
- let of_string x =
|
||||||
|
- try
|
||||||
|
- let i = String.index x '/' in
|
||||||
|
- let num = Z.from_string_base ~base:10 (String.sub x 0 i) in
|
||||||
|
- let den = Z.from_string_base ~base:10 (String.sub x (i+1) ((String.length x)-(i+1))) in
|
||||||
|
- Q.div (Q.from_z num) (Q.from_z den)
|
||||||
|
- with Not_found -> Q.from_z (Z.from_string_base ~base:10 x)
|
||||||
|
- let to_string = Q.to_string
|
||||||
|
+ let num = Mpz.init () in
|
||||||
|
+ let den = Mpz.init () in
|
||||||
|
+ Gmp_random.Mpz.urandomb num randobj n;
|
||||||
|
+ Gmp_random.Mpz.urandomb den randobj n;
|
||||||
|
+ let res = Mpq.init () in
|
||||||
|
+ Mpq.div res (Mpq.init_set_z num) (Mpq.add res one (Mpq.init_set_z den); res);
|
||||||
|
+ res
|
||||||
|
+ let of_int = Mpq.of_int
|
||||||
|
+ let of_string = Mpq.of_string
|
||||||
|
+ let to_string = Mpq.to_string
|
||||||
|
end
|
||||||
|
|
||||||
|
let _ =
|
@ -1,5 +1,3 @@
|
|||||||
%global opt %(test -x %{_bindir}/ocamlopt && echo 1 || echo 0)
|
|
||||||
|
|
||||||
Name: ocaml-tplib
|
Name: ocaml-tplib
|
||||||
Version: 1.3
|
Version: 1.3
|
||||||
Release: 30%{?dist}
|
Release: 30%{?dist}
|
||||||
@ -20,11 +18,15 @@ Source6: compute_tropical_complex.1
|
|||||||
# Upstream patch to adapt to new ocamlbuild behavior. See
|
# Upstream patch to adapt to new ocamlbuild behavior. See
|
||||||
# https://github.com/ocaml/opam-repository/blob/master/packages/tplib/tplib.1.3/files/fix-makefile.diff
|
# https://github.com/ocaml/opam-repository/blob/master/packages/tplib/tplib.1.3/files/fix-makefile.diff
|
||||||
Patch0: %{name}-ocamlbuild.patch
|
Patch0: %{name}-ocamlbuild.patch
|
||||||
|
# Adapt to current versions of mlgmpidl
|
||||||
|
Patch1: %{name}-mlgmpidl.patch
|
||||||
|
|
||||||
|
BuildRequires: mpfr-devel
|
||||||
BuildRequires: ocaml
|
BuildRequires: ocaml
|
||||||
BuildRequires: ocaml-ocamlbuild
|
BuildRequires: ocaml-ocamlbuild-devel
|
||||||
BuildRequires: ocaml-camlidl-devel
|
BuildRequires: ocaml-camlidl-devel
|
||||||
BuildRequires: ocaml-findlib-devel
|
BuildRequires: ocaml-findlib-devel
|
||||||
|
BuildRequires: ocaml-mlgmpidl-devel
|
||||||
BuildRequires: ocaml-num-devel
|
BuildRequires: ocaml-num-devel
|
||||||
BuildRequires: ocaml-ocamldoc
|
BuildRequires: ocaml-ocamldoc
|
||||||
BuildRequires: ocaml-zarith-devel
|
BuildRequires: ocaml-zarith-devel
|
||||||
@ -60,10 +62,18 @@ Tools that use TPLib.
|
|||||||
%prep
|
%prep
|
||||||
%setup -q -n tplib-%{version}
|
%setup -q -n tplib-%{version}
|
||||||
%patch0
|
%patch0
|
||||||
|
%patch1
|
||||||
|
|
||||||
# Enable debuginfo generation
|
# Enable debuginfo generation
|
||||||
sed -i 's/@OCAMLBUILD@/& -cflag -g -lflag -g/' Makefile.in
|
sed -i 's/@OCAMLBUILD@/& -cflag -g -lflag -g/' Makefile.in
|
||||||
|
|
||||||
|
# Use the PIC version of libasmrun
|
||||||
|
sed -i 's/-lasmrun/&_pic/g' Makefile.in configure
|
||||||
|
sed -i 's/libasmrun\.a/libasmrun_pic.a/' Makefile.in
|
||||||
|
|
||||||
|
# Build the bindings with -fPIC
|
||||||
|
sed -i 's,CFLAGS += -I\$(OCAML_HOME_DIR),& -fPIC,' Makefile.in
|
||||||
|
|
||||||
%build
|
%build
|
||||||
%configure
|
%configure
|
||||||
# Don't use %%{?_smp_mflags}; it leads to build failures
|
# Don't use %%{?_smp_mflags}; it leads to build failures
|
||||||
|
Loading…
Reference in New Issue
Block a user