diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index adfa7d3..c57c0c0 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -7,26 +7,30 @@ jobs: runs-on: ubuntu-latest steps: - name: Install packages - run: sudo apt-get install ocaml-nox libgmp-dev + run: sudo apt-get install ocaml-nox libgmp-dev opam - name: Checkout uses: actions/checkout@v2 - - name: configure tree - run: ./configure + - name: init opam + run: opam init + - name: install deps + run: opam install . --deps-only --with-test --yes - name: Build - run: make + run: opam exec -- dune build - name: Run the testsuite - run: make -C tests test + run: opam exec -- dune runtest MacOS: runs-on: macos-latest steps: - name: Install packages - run: brew install ocaml ocaml-findlib gmp + run: brew install ocaml ocaml-findlib gmp opam - name: Checkout uses: actions/checkout@v2 - - name: configure tree - run: ./configure + - name: init opam + run: opam init + - name: install deps + run: opam install . --deps-only --with-test --yes - name: Build - run: make + run: opam exec -- dune build - name: Run the testsuite - run: make -C tests test + run: opam exec -- dune runtest diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 425a3b9..e89d995 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,14 +35,14 @@ jobs: - run: opam install . --with-test --deps-only - - name: configure tree - run: opam exec -- sh ./configure + - name: install deps + run: opam install . --deps-only --with-test --yes - name: Build - run: opam exec -- make + run: opam exec -- dune build - name: Run the testsuite - run: opam exec -- make -C tests test + run: opam exec -- dune runtest - run: opam install . --with-test diff --git a/.gitignore b/.gitignore index 9b60f89..15b506d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,7 @@ Makefile.config depend zarith_version.ml +_build +.merlin +c-flags.sexp +library-flags.sexp \ No newline at end of file diff --git a/DUNE.md b/DUNE.md new file mode 100644 index 0000000..23e5b2a --- /dev/null +++ b/DUNE.md @@ -0,0 +1,4 @@ +- why use -linkall for zarith.cmxs ? +- do we need -failsafe when calling OCAMLMKLIB +- do we need -O3 -Wall -Wextra +- we not longer test bytecode \ No newline at end of file diff --git a/META b/META deleted file mode 100644 index 72bd4ca..0000000 --- a/META +++ /dev/null @@ -1,18 +0,0 @@ -description = "Arbitrary precision integers" -requires = "" -version = "1.14" -archive(byte) = "zarith.cma" -archive(native) = "zarith.cmxa" -plugin(byte) = "zarith.cma" -plugin(native) = "zarith.cmxs" - -package "top" ( - version = "1.13" - description = "ZArith toplevel support" - requires = "zarith" - archive(byte) = "zarith_top.cma" - archive(native) = "zarith_top.cmxa" - plugin(byte) = "zarith_top.cma" - plugin(native) = "zarith_top.cmxs" - exists_if = "zarith_top.cma" -) diff --git a/Makefile b/Makefile deleted file mode 100644 index d795e60..0000000 --- a/Makefile +++ /dev/null @@ -1,143 +0,0 @@ -# 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). - -include Makefile.config - -# project files -############### - -CSRC = caml_z.c -MLSRC = zarith_version.ml z.ml q.ml big_int_Z.ml -MLISRC = z.mli q.mli big_int_Z.mli - -AUTOGEN = zarith_version.ml - -CMIOBJ = $(MLISRC:%.mli=%.cmi) -CMXOBJ = $(MLSRC:%.ml=%.cmx) -CMIDOC = $(MLISRC:%.mli=%.cmti) - -TOBUILD = zarith.cma libzarith.$(LIBSUFFIX) $(CMIOBJ) zarith_top.cma z.mli - -TOINSTALL = $(TOBUILD) zarith.h q.mli big_int_Z.mli - -ifeq ($(HASOCAMLOPT),yes) -TOBUILD += zarith.cmxa $(CMXOBJ) -TOINSTALL += zarith.$(LIBSUFFIX) -endif -DEBUG = -g -OCAMLFLAGS += $(DEBUG) -I +compiler-libs -OCAMLOPTFLAGS += $(DEBUG) -I +compiler-libs - -ifeq ($(HASDYNLINK),yes) -TOBUILD += zarith.cmxs -endif - -ifeq ($(HASBINANNOT),yes) -TOINSTALL += $(CMIDOC) -OCAMLFLAGS += -bin-annot -endif - -# build targets -############### - -all: $(TOBUILD) - -tests: - make -C tests test - -zarith.cma: $(MLSRC:%.ml=%.cmo) - $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) $(LDFLAGS) - -zarith.cmxa: $(MLSRC:%.ml=%.cmx) - $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) $(LDFLAGS) - -zarith.cmxs: zarith.cmxa libzarith.$(LIBSUFFIX) - $(OCAMLOPT) -shared -o $@ -I . zarith.cmxa -linkall - -libzarith.$(LIBSUFFIX): $(CSRC:%.c=%.$(OBJSUFFIX)) - $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) $(LDFLAGS) - -zarith_top.cma: zarith_top.cmo - $(OCAMLC) $(DEBUG) -o $@ -a $< - -doc: $(MLISRC) -ifneq ($(OCAMLDOC),) - mkdir -p html - $(OCAMLDOC) -html -d html -charset utf8 $+ -else - $(error ocamldoc is required to build the documentation) -endif - -zarith_version.ml: META - (echo "let"; grep "version" META | head -1) > zarith_version.ml - -# install targets -################# - -ifeq ($(INSTMETH),install) -install: - install -d $(INSTALLDIR) $(INSTALLDIR)/zarith $(INSTALLDIR)/stublibs - for i in $(TOINSTALL); do \ - if test -f $$i; then $(INSTALL) -m 0644 $$i $(INSTALLDIR)/zarith/$$i; fi; \ - done - if test -f dllzarith.$(DLLSUFFIX); then $(INSTALL) -m 0755 dllzarith.$(DLLSUFFIX) $(INSTALLDIR)/stublibs/dllzarith.$(DLLSUFFIX); fi - -uninstall: - for i in $(TOINSTALL); do \ - rm -f $(INSTALLDIR)/zarith/$$i; \ - done - if test -f $(INSTALLDIR)/stublibs/dllzarith.$(DLLSUFFIX); then rm -f $(INSTALLDIR)/stublibs/dllzarith.$(DLLSUFFIX); fi -endif - -ifeq ($(INSTMETH),findlib) -install: - $(OCAMLFIND) install -destdir "$(INSTALLDIR)" zarith META $(TOINSTALL) -optional dllzarith.$(DLLSUFFIX) - -uninstall: - $(OCAMLFIND) remove -destdir "$(INSTALLDIR)" zarith -endif - - -# rules -####### - -%.cmi: %.mli - $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< - -%.cmo: %.ml %.cmi - $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< - -%.cmx: %.ml %.cmi - $(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAMLINC) -c $< - -%.cmo: %.ml - $(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $< - -%.cmx: %.ml - $(OCAMLOPT) $(OCAMLOPTFLAGS) $(OCAMLINC) -c $< - -%.$(OBJSUFFIX): %.c - $(OCAMLC) -ccopt "$(CFLAGS)" -c $< - -clean: - /bin/rm -rf *.o *.obj *.lib *.a *.cmi *.cmo *.cmx *.cmxa *.cmxs *.cma *.cmt *.cmti *~ \#* depend test $(AUTOGEN) tmp.c depend - make -C tests clean - -depend: $(AUTOGEN) - $(OCAMLDEP) $(OCAMLINC) $(MLSRC) $(MLISRC) > depend - -include depend - -$(CSRC:%.c=%.$(OBJSUFFIX)): zarith.h - -.PHONY: clean -.PHONY: tests diff --git a/README.md b/README.md index d552663..17c78af 100644 --- a/README.md +++ b/README.md @@ -35,35 +35,20 @@ provided by [Zarith_stubs_js](https://github.com/janestreet/zarith_stubs_js). * OCaml, version 4.04.0 or later. * Either the GMP library or the MPIR library, including development files. * GCC or Clang or a gcc-compatible C compiler and assembler (other compilers may work). -* The Findlib package manager (optional, recommended). +* dune, version 2.7 or later ## INSTALLATION -1) First, run the "configure" script by typing: +1) First, build with ``` - ./configure + dune build ``` -The `configure` script has a few options. Use the `-help` option to get a -list and short description of each option. - -2) It creates a Makefile, which can be invoked by: -``` - make -``` -This builds native and bytecode versions of the library. 3) The libraries are installed by typing: ``` - make install -``` -or, if you install to a system location but are not an administrator -``` - sudo make install + dune install ``` -If Findlib is detected, it is used to install files. -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`. @@ -73,13 +58,13 @@ option to `ocamlc` / `ocamlopt`, or the `-package zarith` option to `ocamlfind`. 4) (optional, recommended) Test programs are built and run by the additional command ``` - make tests + dune runtest ``` (but these are not installed). -5) (optional) HTML API documentation is built (using `ocamldoc`) by the additional command +5) (optional) HTML API documentation is built (using `odoc`) by the additional command ``` - make doc + dune build @doc ``` ## ONLINE DOCUMENTATION @@ -115,15 +100,13 @@ INRIA Rocquencourt (Institut national de recherche en informatique, France). ## CONTENTS -Source files | Description ---------------------|----------------------------------------- - configure | configuration script - z.ml[i] | Z module and implementation for small integers - caml_z.c | C implementation - big_int_z.ml[i] | wrapper to provide a Big_int compatible API to Z - q.ml[i] | rational library, pure OCaml on top of Z - zarith_top.ml | toplevel module to provide pretty-printing - projet.mak | builds Z, Q and the tests - zarith.opam | package description for opam - z_mlgmpidl.ml[i] | conversion between Zarith and MLGMPIDL - tests/ | simple regression tests and benchmarks +Source files | Description +----- ------------------|----------------------------------------- + src/z.ml[i] | Z module and implementation for small integers + src/caml_z.c | C implementation + src/big_int_z.ml[i] | wrapper to provide a Big_int compatible API to Z + src/q.ml[i] | rational library, pure OCaml on top of Z + src/top/zarith_top.ml | toplevel module to provide pretty-printing + zarith.opam | package description for opam + z_mlgmpidl/* | conversion between Zarith and MLGMPIDL + tests/ | simple regression tests and benchmarks diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..9f76d37 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.13 \ No newline at end of file diff --git a/config/discover.ml b/config/discover.ml new file mode 100644 index 0000000..a522f46 --- /dev/null +++ b/config/discover.ml @@ -0,0 +1,88 @@ +module C = Configurator.V1 + +module Version = struct + type t = { major : int; minor : int } + + let num = function '0' .. '9' -> true | _ -> false + + let of_string_exn s : t = + try Scanf.sscanf s "%d.%d" (fun major minor -> { major; minor }) + with _ -> failwith (Printf.sprintf "unable to parse ocaml version %S" s) + + let compare a b = + match compare a.major b.major with 0 -> compare a.minor b.minor | n -> n +end + +type libmode = [ `Auto | `Gmp | `Mpir ] + +let lib : libmode ref = ref `Auto +let perf = ref false + +let lookup_with_pkg_config c ~lib = + match C.Pkg_config.get c with + | None -> None + | Some pc -> ( + match C.Pkg_config.query pc ~package:lib with + | Some deps -> Some deps + | None -> None) + +let lookup_manually c ~lib ~include_h = + let libflag = Printf.sprintf "-l%s" lib in + let c_code = + Printf.sprintf {| +#include <%s>" +int main() { return 1; } +|} include_h + in + if C.c_test c ~link_flags:[ libflag ] c_code then + Some { C.Pkg_config.libs = [ libflag ]; cflags = [] } + else None + +let () = + C.main + ~args: + [ + ( "-gmp", + Unit (fun () -> lib := `Gmp), + "use GMP library (default if found)" ); + ( "-mpir", + Unit (fun () -> lib := `Mpir), + "use MPIR library instead of GMP" ); + ("-perf", Set perf, "enable performance statistics"); + ] + ~name:"zarith" + (fun c -> + let version = + Version.of_string_exn (C.ocaml_config_var_exn c "version") + in + let use_legacy = + Version.compare version { Version.major = 4; minor = 8 } < 0 + in + let find_one ~lib ~include_h = + match lookup_with_pkg_config c ~lib with + | Some x -> x + | None -> match lookup_manually c ~lib ~include_h with + | Some x -> x + | None -> failwith (Printf.sprintf "Unable to find the %s c library" lib) + in + + let backend, conf = + let rec find = function + | `Auto -> ( + try find `Gmp with e -> ( try find `Mpir with _ -> raise e)) + | `Gmp -> (`Gmp, find_one ~lib:"gmp" ~include_h:"gmp.h") + | `Mpir -> (`Mpir, find_one ~lib:"mpir" ~include_h:"mpir.h") + in + find !lib + in + let defs = + match backend with `Gmp -> [ "-DHAS_GMP" ] | `Mpir -> [ "-DHAS_MPIR" ] + in + let defs = if !perf then "-DZ_PERF_COUNTER" :: defs else defs in + let defs = + if use_legacy then "DZ_OCAML_LEGACY_CUSTOM_OPERATIONS" :: defs else defs + in + + C.Flags.write_sexp "c-flags.sexp" + (conf.cflags @ defs (* @ [ "-O3"; "-Wall"; "-Wextra" ] *)); + C.Flags.write_sexp "c-library-flags.sexp" conf.libs) diff --git a/config/dune b/config/dune new file mode 100644 index 0000000..187bd5e --- /dev/null +++ b/config/dune @@ -0,0 +1,3 @@ +(executable + (name discover) + (libraries dune-configurator)) diff --git a/configure b/configure deleted file mode 100755 index d8dbb51..0000000 --- a/configure +++ /dev/null @@ -1,415 +0,0 @@ -#! /bin/sh - -# configuration script - -# 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). - - -# options -installdir='auto' -ocamllibdir='auto' -gmp='auto' -perf='no' - -ocaml='ocaml' -ocamlc='ocamlc' -ocamlopt='ocamlopt' -ocamlmklib='ocamlmklib' -ocamldep='ocamldep' -ocamldoc='ocamldoc' -ccinc="$CPPFLAGS" -ldflags="$LDFLAGS" -cclib='' -ccdef='' -mlflags="$OCAMLFLAGS" -mloptflags="$OCAMLOPTFLAGS" -mlinc="$OCAMLINC" -ocamlfind="auto" - -# sanitize -LC_ALL=C -export LC_ALL -unset IFS - - -# help -help() -{ - cat <" > tmp.c - echo "int main() { return 1; }" >> tmp.c - r=1 - $ocamlc -ccopt "$ccopt $ccinc" -c tmp.c -o tmp.o >/dev/null 2>/dev/null || r=0 - if test ! -f tmp.o; then r=0; fi - rm -f tmp.c tmp.o - if test $r -eq 0; then echo "not found"; else echo "found"; fi - return $r -} - -checklib() -{ - echo_n "library $1: " - rm -f tmp.ml tmp.out - echo "" > tmp.ml - r=1 - $ocamlc -custom -ccopt "$ldflags $cclib" tmp.ml -cclib -l$1 -o tmp.out >/dev/null 2>/dev/null || r=0 - if test ! -x tmp.out; then r=0; fi - rm -f tmp.out tmp.ml tmp.cmi tmp.cmo - if test $r -eq 0; then echo "not found"; else echo "found"; fi - return $r -} - -checkcc() -{ - echo_n "checking compilation with $ocamlc $ccopt: " - rm -f tmp.c tmp.out - echo "int main() { return 1; }" >> tmp.c - echo "" > tmpml.ml - r=1 - $ocamlc -ccopt "$ccopt" tmp.c tmpml.ml -o tmp.out >/dev/null 2>/dev/null || r=0 - if test ! -x tmp.out; then r=0; fi - rm -f tmp.c tmp.o tmp.out tmpml.ml tmpml.cm* - if test $r -eq 0; then echo "not working"; else echo "working"; fi - return $r -} - -checkcmxalib() -{ - echo_n "library $1: " - $ocamlopt $mloptflags $1 -o tmp.out >/dev/null 2>/dev/null || r=0 - if test ! -x tmp.out; then r=0; fi - rm -f tmp.out - if test $r -eq 0; then echo "not found"; else echo "found"; fi - return $r -} - - -# check required programs - -searchbinreq $ocaml -searchbinreq $ocamlc -searchbinreq $ocamldep -searchbinreq $ocamlmklib -if searchbin $ocamldoc; then - ocamldoc='' -fi - -if test -n "$CC"; then - searchbinreq "$CC" - ccopt="$CFLAGS" -else - ccopt="-O3 -Wall -Wextra $CFLAGS" -fi - -case "$("$ocamlc" -config | tr -d '\r' | sed -ne '/^system:/s/.*: //p')" in - win32|win64) - # MSVC - objsuffix='obj' - libsuffix='lib' - dllsuffix='dll' - exe='.exe' - ;; - mingw|mingw64) - # mingw-w64 - objsuffix='o' - libsuffix='a' - dllsuffix='dll' - exe='.exe' - ;; - *) - # Unix - objsuffix='o' - libsuffix='a' - dllsuffix='so' - exe='' - ;; -esac - -# optional native-code generation - -hasocamlopt='no' - -searchbin $ocamlopt -if test $? -eq 1; then hasocamlopt='yes'; fi - - -# check C compiler - -checkcc -if test $? -eq 0; then - # try again with (almost) no options - ccopt='-O' - checkcc - if test $? -eq 0; then echo "cannot compile and link program"; exit 2; fi -fi - - -# directories - -if test "$ocamllibdir" = "auto" -then ocamllibdir="$(ocamlc -where | tr -d '\r')" -fi - -if test ! -f "$ocamllibdir/caml/mlvalues.h" -then echo "cannot find OCaml libraries in $ocamllibdir"; exit 2; fi -ccinc="-I$ocamllibdir $ccinc" -checkinc "caml/mlvalues.h" -if test $? -eq 0; then echo "cannot include caml/mlvalues.h"; exit 2; fi - - -# optional dynamic linking - -hasdynlink='no' - -if test $hasocamlopt = yes -then - checkcmxalib dynlink.cmxa - if test $? -eq 1; then hasdynlink='yes'; fi -fi - - -# installation method - -searchbin ocamlfind -if test $? -eq 1 && test $ocamlfind != "no"; then - instmeth='findlib' - if test "$installdir" = "auto" - then installdir="$(ocamlfind printconf destdir | tr -d '\r')"; fi -else - searchbin install - if test $? -eq 1; then instmeth='install' - else echo "no installation method found"; exit 2; fi - if test "$installdir" = "auto"; then installdir="$ocamllibdir"; fi -fi - - -# detect OCaml's word-size - -echo "print_int (Sys.word_size);;" > tmp.ml -wordsize="$(ocaml tmp.ml)" -echo "OCaml's word size is $wordsize" -rm -f tmp.ml - - -# check GMP, MPIR - -if test "$gmp" = 'gmp' || test "$gmp" = 'auto'; then - if pkg-config gmp 2>/dev/null; then - echo 'package gmp: found' - gmp='OK' - cclib="$cclib $(pkg-config --libs gmp)" - ccinc="$ccinc $(pkg-config --cflags gmp)" - ccdef="-DHAS_GMP $ccdef" - else - checkinc gmp.h - if test $? -eq 1; then - checklib gmp - if test $? -eq 1; then - gmp='OK' - cclib="$cclib -lgmp" - ccdef="-DHAS_GMP $ccdef" - fi - fi - fi -fi -if test "$gmp" = 'mpir' || test "$gmp" = 'auto'; then - checkinc mpir.h - if test $? -eq 1; then - checklib mpir - if test $? -eq 1; then - gmp='OK' - cclib="$cclib -lmpir" - ccdef="-DHAS_MPIR $ccdef" - fi - fi -fi -if test "$gmp" != 'OK'; then echo "cannot find GMP nor MPIR"; exit 2; fi - - -# OCaml version - -ocamlver="$(ocamlc -version)" - -# OCaml version 4.04 or later is required - -case "$ocamlver" in - [123].* | 4.0[0123].*) - echo "OCaml version $ocamlver is no longer supported." - echo "OCaml version 4.04.0 or later is required." - exit 2 - ;; -esac - -# -bin-annot available since 4.00.0 -echo "OCaml supports -bin-annot to produce documentation" -hasbinannot='yes' - -# Changes to C API (the custom_operation struct) since 4.08.0 -case "$ocamlver" in - [123].* | 4.0[01234567].* ) - echo "Using OCaml legacy C API custom operations" - ccdef="-DZ_OCAML_LEGACY_CUSTOM_OPERATIONS $ccdef" - ;; - *) - ;; -esac - -# dump Makefile - -cat > Makefile.config <") +(homepage "https://github.com/ocaml/Zarith") +(bug_reports "https://github.com/ocaml/Zarith/issues") +(source + (uri "git+https://github.com/ocaml/Zarith.git")) +(license "LGPL-2.0-only WITH OCaml-LGPL-linking-exception") + +(package + (name zarith) + (synopsis "Implements arithmetic and logical operations over arbitrary-precision integers") + (description + "The Zarith library implements arithmetic and logical operations over +arbitrary-precision integers. It uses GMP to efficiently implement +arithmetic over big integers. Small integers are represented as Caml +unboxed integers, for speed and space economy.") + (depends + (ocaml (>= 4.04)) + (num :with-test) + (dune (< 3.9)) + dune-configurator + conf-gmp)) diff --git a/big_int_Z.ml b/src/big_int_Z.ml similarity index 100% rename from big_int_Z.ml rename to src/big_int_Z.ml diff --git a/big_int_Z.mli b/src/big_int_Z.mli similarity index 100% rename from big_int_Z.mli rename to src/big_int_Z.mli diff --git a/caml_z.c b/src/caml_z.c similarity index 100% rename from caml_z.c rename to src/caml_z.c diff --git a/src/dune b/src/dune new file mode 100644 index 0000000..9991c75 --- /dev/null +++ b/src/dune @@ -0,0 +1,26 @@ +(library + (name zarith) + (wrapped false) + (flags -w -6) + (public_name zarith) + (c_library_flags + (:include c-library-flags.sexp)) + (synopsis "Arbitrary precision integers") + (foreign_stubs + (language c) + (names caml_z) + (flags + :standard + (:include c-flags.sexp)))) + +(rule + (target zarith_version.ml) + (action + (with-stdout-to + %{target} + (run ./gen/gen_version.exe %{dep:../VERSION})))) + +(rule + (targets c-flags.sexp c-library-flags.sexp) + (action + (run ../config/discover.exe))) diff --git a/src/gen/dune b/src/gen/dune new file mode 100644 index 0000000..82af462 --- /dev/null +++ b/src/gen/dune @@ -0,0 +1,2 @@ +(executable + (name gen_version)) diff --git a/src/gen/gen_version.ml b/src/gen/gen_version.ml new file mode 100644 index 0000000..ad19f5a --- /dev/null +++ b/src/gen/gen_version.ml @@ -0,0 +1,6 @@ +let () = + let ic = open_in Sys.argv.(1) in + let version = input_line ic in + Printf.printf "(* generated by gen_version.ml *)\n"; + Printf.printf "let version = %S\n" version; + close_in ic diff --git a/q.ml b/src/q.ml similarity index 100% rename from q.ml rename to src/q.ml diff --git a/q.mli b/src/q.mli similarity index 100% rename from q.mli rename to src/q.mli diff --git a/src/top/dune b/src/top/dune new file mode 100644 index 0000000..9d9e5a9 --- /dev/null +++ b/src/top/dune @@ -0,0 +1,6 @@ +(library + (name zarith_top) + (public_name zarith.top) + (synopsis "ZArith toplevel support") + (library_flags (:standard -linkall)) + (libraries compiler-libs.toplevel zarith)) diff --git a/zarith_top.ml b/src/top/zarith_top.ml similarity index 100% rename from zarith_top.ml rename to src/top/zarith_top.ml diff --git a/src/top/zarith_top.mli b/src/top/zarith_top.mli new file mode 100644 index 0000000..73fead3 --- /dev/null +++ b/src/top/zarith_top.mli @@ -0,0 +1,8 @@ +(* + 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. +*) + +(* This interface is deliberately empty *) diff --git a/z.ml b/src/z.ml similarity index 100% rename from z.ml rename to src/z.ml diff --git a/z.mli b/src/z.mli similarity index 100% rename from z.mli rename to src/z.mli diff --git a/zarith.h b/src/zarith.h similarity index 100% rename from zarith.h rename to src/zarith.h diff --git a/tests/dune b/tests/dune new file mode 100644 index 0000000..7d8f90d --- /dev/null +++ b/tests/dune @@ -0,0 +1,97 @@ +(executables + (names ofstring pi zq timings chi2 tst_extract) + (modules ofstring pi zq timings chi2 tst_extract) + (modes + (best exe) + (byte exe)) + (flags -w -27) + (libraries zarith)) + +(executables + (names bi) + (modules bi) + (flags -w -35) + (libraries num zarith)) + +(executable + (name tofloat) + (modules tofloat) + (flags -w -35) + (foreign_stubs + (language c) + (names setround)) + (libraries zarith)) + +(rule + (target zq.output32.corrected) + (enabled_if + (= %{ocaml-config:word_size} 32)) + (action + (with-stdout-to + %{target} + (run ./zq.exe)))) + +(rule + (alias runtest) + (enabled_if + (= %{ocaml-config:word_size} 32)) + (action + (diff zq.output32 zq.output32.corrected))) + +(rule + (target zq.output64.corrected) + (enabled_if + (= %{ocaml-config:word_size} 64)) + (action + (with-stdout-to + %{target} + (run ./zq.exe)))) + +(rule + (alias runtest) + (enabled_if + (= %{ocaml-config:word_size} 64)) + (action + (diff zq.output64 zq.output64.corrected))) + +(rule + (alias runtest) + (action + (diff pi.output pi.output.corrected))) + +(rule + (alias runtest) + (action + (run ./bi.exe))) + +(rule + (target pi.output.corrected) + (action + (with-stdout-to + %{target} + (run ./pi.exe 500)))) + +(rule + (alias runtest) + (action + (diff pi.output pi.output.corrected))) + +(rule + (alias runtest) + (action + (run ./tofloat.exe))) + +(rule + (alias runtest) + (action + (run ./ofstring.exe))) + +(rule + (alias runtest) + (action + (run ./chi2.exe))) + +(rule + (alias runtest) + (action + (run ./tst_extract.exe))) diff --git a/z_mlgmpidl.ml b/z_mlgmpidl/z_mlgmpidl.ml similarity index 100% rename from z_mlgmpidl.ml rename to z_mlgmpidl/z_mlgmpidl.ml diff --git a/z_mlgmpidl.mli b/z_mlgmpidl/z_mlgmpidl.mli similarity index 100% rename from z_mlgmpidl.mli rename to z_mlgmpidl/z_mlgmpidl.mli diff --git a/zarith.opam b/zarith.opam index 995af2f..e438420 100644 --- a/zarith.opam +++ b/zarith.opam @@ -1,29 +1,5 @@ +# This file is generated by dune, edit dune-project instead opam-version: "2.0" -name: "zarith" -version: "1.14" -maintainer: "Xavier Leroy " -authors: [ - "Antoine Miné" - "Xavier Leroy" - "Pascal Cuoq" -] -homepage: "https://github.com/ocaml/Zarith" -bug-reports: "https://github.com/ocaml/Zarith/issues" -dev-repo: "git+https://github.com/ocaml/Zarith.git" -license: "LGPL-2.0-only WITH OCaml-LGPL-linking-exception" -build: [ - ["./configure"] - [make] -] -install: [ - [make "install"] -] -depends: [ - "ocaml" {>= "4.07.0"} - "ocamlfind" - "conf-pkg-config" - "conf-gmp" -] synopsis: "Implements arithmetic and logical operations over arbitrary-precision integers" description: """ @@ -31,3 +7,31 @@ The Zarith library implements arithmetic and logical operations over arbitrary-precision integers. It uses GMP to efficiently implement arithmetic over big integers. Small integers are represented as Caml unboxed integers, for speed and space economy.""" +maintainer: ["Xavier Leroy "] +authors: ["Antoine Miné" "Xavier Leroy" "Pascal Cuoq"] +license: "LGPL-2.0-only WITH OCaml-LGPL-linking-exception" +homepage: "https://github.com/ocaml/Zarith" +bug-reports: "https://github.com/ocaml/Zarith/issues" +depends: [ + "ocaml" {>= "4.04"} + "num" {with-test} + "dune" {>= "2.7" & < "3.9"} + "dune-configurator" + "conf-gmp" + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/ocaml/Zarith.git"