Skip to content

Commit

Permalink
- bumped META to version 1.1
Browse files Browse the repository at this point in the history
- installs in `ocamlc -where`/zarith instead of `ocamlc -where` when no ocamlfind found
- adde Z.version: the library version in string form
- added zarith.h: conversion between GMP and Zarith for C libraries
  • Loading branch information
antoinemine committed Apr 30, 2012
1 parent 1fe08e3 commit b757af4
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 8 deletions.
2 changes: 1 addition & 1 deletion META
@@ -1,5 +1,5 @@
description = "Arbitrary precision integers"
requires = ""
version = "0.1"
version = "1.1"
archive(byte) = "zarith.cma"
archive(native) = "zarith.cmxa"
7 changes: 5 additions & 2 deletions README
Expand Up @@ -60,9 +60,12 @@ or, if you install to a system location but are not an administrator
sudo make install

If Findlib is detected, it is used to install files.
Otherwise, the files are simply copied to the location given by `ocamlc -where`.
Otherwise, the files are copied to a zarith subdirectory of the directory
given by `ocamlc -where`.
The libraries are named "zarith.cmxa" and "zarith.cma", and the Findlib module
is named "zarith".
is named "zarith".
Compiling and linking with the library requires passing the "-I +zarith"
option to ocamlc / ocamlopt.
The "configure" script has a few options. Use the "-help" option to get a
list and short description of each option.

Expand Down
6 changes: 5 additions & 1 deletion configure
Expand Up @@ -45,6 +45,7 @@ mlflags="$OCAMLFLAGS"
mloptflags="$OCAMLOPTFLAGS"
mlinc="$OCAMLINC"
objsuffix="o"
ocamlfind="auto"

# sanitize
LC_ALL=C
Expand Down Expand Up @@ -90,6 +91,9 @@ while : ; do
-ocamllibdir|---ocamllibdir)
ocamllibdir="$2"
shift;;
-no-ocamlfind)
ocamlfind="no"
shift;;
-host|--host)
host="$2"
shift;;
Expand Down Expand Up @@ -251,7 +255,7 @@ fi
# installation method

searchbin ocamlfind
if test $? -eq 1; then
if test $? -eq 1 -a $ocamlfind != "no"; then
instmeth='findlib'
if test "$installdir" = "auto"
then installdir=`ocamlfind printconf destdir`; fi
Expand Down
10 changes: 6 additions & 4 deletions project.mak
Expand Up @@ -22,7 +22,7 @@ MLISRC = z.mli q.mli big_int_Z.mli
AUTOGEN = z.ml z.mli

CMIOBJ = $(MLISRC:%.mli=%.cmi)
TOINSTALL := zarith.cma libzarith.a $(MLISRC) $(CMIOBJ)
TOINSTALL := zarith.cma libzarith.a zarith.h $(MLISRC) $(CMIOBJ)
TESTS := test.b

ifeq ($(HASOCAMLOPT),yes)
Expand Down Expand Up @@ -78,16 +78,18 @@ doc: $(MLISRC)
ifeq ($(INSTMETH),install)
install:
install -d $(INSTALLDIR)
install -d $(INSTALLDIR)/zarith
for i in $(TOINSTALL); do \
if test -f $$i; then $(INSTALL) -m 0644 $$i $(INSTALLDIR); fi; \
if test -f $$i; then $(INSTALL) -m 0644 $$i $(INSTALLDIR)/zarith; fi; \
done
if test -f dllzarith.so; then $(INSTALL) -m 0755 dllzarith.so $(INSTALLDIR)/stublibs; fi
if test -f dllzarith.so; then install -d $(INSTALLDIR)/stublibs; $(INSTALL) -m 0755 dllzarith.so $(INSTALLDIR)/stublibs; fi

uninstall:
for i in $(TOINSTALL); do \
rm -f $(INSTALLDIR)/$$i; \
done
if test -f $(INSTALLDIR)/stublibs/dllzarith.so; then rm -f $(INSTALLDIR)/stublibs/dllzarith.so; fi
rm -rf $(INSTALLDIR)/zarith
rm -f $(INSTALLDIR)/stublibs/dllzarith.so
endif

ifeq ($(INSTMETH),findlib)
Expand Down
5 changes: 5 additions & 0 deletions z.mlip
Expand Up @@ -549,3 +549,8 @@ external (~$): int -> t = "%identity"

external ( ** ): t -> int -> t = "ml_z_pow"
(** Power [pow]. *)

(** {1 Miscellaneous} *)

val version: string
(** Library version (this file refers to version [@VERSION]). *)
1 change: 1 addition & 0 deletions z.mlp
Expand Up @@ -161,3 +161,4 @@ external (asr): t -> int -> t = shift_right@ASM
external (~$): int -> t = "%identity"
external ( ** ): t -> int -> t = "ml_z_pow"

let version = @VERSION
7 changes: 7 additions & 0 deletions z_pp.pl
Expand Up @@ -18,6 +18,12 @@

die "Usage: './z_pp.pl architecture'" unless $#ARGV==0;

# version, from META file

$v = `grep version META`;
($ver) = $v =~ /version\s*=\s*(\S+)/;


# scan assembly

$ASM = "caml_z_${ARGV[0]}.S";
Expand Down Expand Up @@ -55,6 +61,7 @@ sub doml {
}
$l =~ s/$f\@ASM/$r/g;
}
$l =~ s/\@VERSION/$ver/;
print O "$l";
}
close F;
Expand Down
42 changes: 42 additions & 0 deletions zarith.h
@@ -0,0 +1,42 @@
/**
Public C interface for Zarith.
This is intended for C libraries that wish to convert between mpz_t and
Z.t objects.
This file is part of the Zarith library
http://forge.ocamlcore.org/projects/zarith .
It is distributed under LGPL 2 licensing, with static linking exception.
See the LICENSE file included in the distribution.
Copyright (c) 2010-2011 Antoine Miné, Abstraction project.
Abstraction is part of the LIENS (Laboratoire d'Informatique de l'ENS),
a joint laboratory by:
CNRS (Centre national de la recherche scientifique, France),
ENS (École normale supérieure, Paris, France),
INRIA Rocquencourt (Institut national de recherche en informatique, France).
*/


/* gmp.h or mpir.h must be included manually before zarith.h */

#ifdef __cplusplus
extern "C" {
#endif

#include <caml/mlvalues.h>

/* sets rop to the value in op (limbs are copied) */
void ml_z_mpz_set_z(mpz_t rop, value op);

/* inits and sets rop to the value in op (limbs are copied) */
void ml_z_mpz_init_set_z(mpz_t rop, value op);

/* returns a new z objects equal to op (limbs are copied) */
value ml_z_from_mpz(mpz_t op);

#ifdef __cplusplus
}
#endif

0 comments on commit b757af4

Please sign in to comment.