Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion antic/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(library
(name antic)
(public_name antic)
(c_library_flags -lantic)
(c_library_flags
(:include ../configure/flint_libs.sexp)
(:include ../configure/antic_libs.sexp))
(libraries zarith flint threads)
(flags -w -9-27))
18 changes: 12 additions & 6 deletions arb/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
(name arb)
(public_name arb)
(c_library_flags
-lflint
(:include ../configure/arb_cflag.sexp))
(:include ../configure/common_libs.sexp)
(:include ../configure/flint_libs.sexp)
(:include ../configure/arb_libs.sexp))
(foreign_stubs
(language c)
(names ocaml_acb_utils)
(flags
(:include ../configure/c_flags.sexp)
(:include ../configure/common_cflags.sexp)
(:include ../configure/flint_cflags.sexp)
(:include ../configure/arb_cflags.sexp)
:standard))
(libraries zarith flint threads)
(flags -w -9-27)
Expand All @@ -18,11 +21,14 @@
(vendored
(c_flags
"-Werror=implicit-function-declaration"
(:include ../configure/c_flags.sexp)
(:include ../configure/common_cflags.sexp)
(:include ../configure/flint_cflags.sexp)
(:include ../configure/arb_cflags.sexp)
:standard)
(c_library_flags
(:include ../configure/libs.sexp)
"-lgmp -lmpfr")))
(:include ../configure/common_libs.sexp)
(:include ../configure/flint_libs.sexp)
(:include ../configure/arb_libs.sexp))))
(headers
(include "acb.h" "string.h"))
(type_description
Expand Down
35 changes: 21 additions & 14 deletions calcium/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
(name calcium)
(public_name calcium)
(c_library_flags
-lflint
(:include ../configure/arb_cflag.sexp)
-lantic
-lcalcium)
(:include ../configure/common_libs.sexp)
(:include ../configure/flint_libs.sexp)
(:include ../configure/arb_libs.sexp)
(:include ../configure/antic_libs.sexp)
(:include ../configure/calcium_libs.sexp))
(foreign_stubs
(language c)
(names ocaml_calcium_utils)
(flags
(:include ../configure/c_flags.sexp)
(:include ../configure/common_cflags.sexp)
(:include ../configure/flint_cflags.sexp)
(:include ../configure/arb_cflags.sexp)
(:include ../configure/antic_cflags.sexp)
(:include ../configure/calcium_cflags.sexp)
:standard))
(libraries zarith flint arb antic threads)
(flags -w -9-27)
Expand All @@ -19,19 +24,21 @@
(build_flags_resolver
(vendored
(c_flags
"-Iflint"
"-Iantic"
"-Icalcium"
"-Werror=implicit-function-declaration"
(:include ../configure/c_flags.sexp)
(:include ../configure/common_cflags.sexp)
(:include ../configure/flint_cflags.sexp)
(:include ../configure/arb_cflags.sexp)
(:include ../configure/antic_cflags.sexp)
(:include ../configure/calcium_cflags.sexp)
:standard)
(c_library_flags
(:include ../configure/libs.sexp)
"-lgmp -lmpfr -lflint"
(:include ../configure/arb_cflag.sexp)
"-lantic -lcalcium")))
(:include ../configure/common_libs.sexp)
(:include ../configure/flint_libs.sexp)
(:include ../configure/arb_libs.sexp)
(:include ../configure/antic_libs.sexp)
(:include ../configure/calcium_libs.sexp))))
(headers
(include "calcium/ca.h" "string.h"))
(include "ca.h" "string.h"))
(type_description
(instance Type)
(functor Type_description))
Expand Down
2 changes: 1 addition & 1 deletion calcium/ocaml_calcium_utils.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "calcium/ca.h"
#include "ca.h"
#include "ctypes_cstubs_internals.h"
#include <stdio.h>

Expand Down
24 changes: 20 additions & 4 deletions configure/dune
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
(executables
(names discover find_arb)
(names find_common find_flint find_arb find_antic find_calcium)
(modules find_common find_flint find_arb find_antic find_calcium util)
(libraries dune-configurator))

(rule
(targets c_flags.sexp libs.sexp)
(targets common_cflags.sexp common_libs.sexp)
(action
(run ./discover.exe)))
(run ./find_common.exe)))

(rule
(targets arb_cflag.sexp)
(targets flint_cflags.sexp flint_libs.sexp)
(action
(run ./find_flint.exe)))

(rule
(targets arb_cflags.sexp arb_libs.sexp)
(action
(run ./find_arb.exe)))

(rule
(targets antic_cflags.sexp antic_libs.sexp)
(action
(run ./find_antic.exe)))

(rule
(targets calcium_cflags.sexp calcium_libs.sexp)
(action
(run ./find_calcium.exe)))
40 changes: 40 additions & 0 deletions configure/find_antic.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module C = Configurator.V1

(* Starting with version 3, `flint` integrates
`arb`, `antic`, and `calcium`. However, given
that it a recent release, not all distribution
will have it. Therefore we need to try and handle
both version 3 and version > 3 of `flint`, and
handle things differently depending on which version
is installed.

Also, as of now, neither debian nor archlinux packages
include pkg-config files, so we have to find other ways
to determine libs and cflags.

These are the different situations:
- on version <2 (and distros such as Debian):
+ antic headers are in `/usr/include/antic`
+ antic lib file is libantic.so
- on version 3 (and distros such as archlinux):
+ antic headers are in `/usr/include/flint`
+ antic library file does not exist (included in flint.so)
*)

(* Test the location of the `qfb.h` header to determine the
current situation *)
let version c =
if Util.is_header_available c "antic/qfb.h" then `Antic2
else if Util.is_header_available c "flint/qfb.h" then `Flint3
else C.die "Could not find the `antic` library"

let () =
C.main ~name:"find_antic" (fun c ->
let libs, cflags =
match version c with
| `Antic2 -> ([ "-lantic" ], [ "-I/usr/include/antic" ])
| `Flint3 -> ([], [ "-I/usr/include/flint" ])
in
C.Flags.write_sexp "antic_cflags.sexp" cflags;
C.Flags.write_sexp "antic_libs.sexp" libs;
())
61 changes: 33 additions & 28 deletions configure/find_arb.ml
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@

module C = Configurator.V1

(* Unfortunately, at least on archlinux, the `arb`,
`flint`, 'antic` and `calcium` library do not
install the files required for pkg-config to work.
Additionally, the name of the c installed c library
for `arb` is different on archlinux (where it is
`-larb` instead of `lflint-arb`).
(* Starting with version 3, `flint` integrates
`arb`, `antic`, and `calcium`. However, given
that it a recent release, not all distribution
will have it. Therefore we need to try and handle
both version 3 and version > 3 of `flint`, and
handle things differently depending on which version
is installed.

Also, as of now, neither debian nor archlinux packages
include pkg-config files, so we have to find other ways
to determine libs and cflags.

Therefore, this is a small hack to determine which
flag to use for `arb`. *)
let find_working_cflag ~name ~c flags =
let dummy_c_main = {|int main() { return 0; }|} in
let rec aux = function
| [] ->
C.die "Could not find an available c libname for %s" name
| cflag :: r ->
if C.c_test c ~c_flags:[cflag] dummy_c_main
then cflag
else aux r
in
aux flags
These are the different situations:
- on version <2 (and distros such as Debian):
+ arb headers are directly in `/usr/include`
+ arb lib file is libflint-arb.so
- on version 3 (and distros such as archlinux):
+ arb headers are in `/usr/include/flint`
+ arb library file does not exist (included in flint.so)
*)

(* Test the location of the `arb.h` header to determine the
current situation *)
let version c =
if Util.is_header_available c "arb.h" then `Arb2
else if Util.is_header_available c "flint/arb.h" then `Flint3
else C.die "Could not find the `arb` library"

let () =
C.main ~name:"find_arb" (fun c ->
let arb_cflag =
find_working_cflag ~name:"arb" ~c [
"-lflint-arb"; (* on most system *)
"-larb"; (* on archlinux *)
]
let libs, cflags =
match version c with
| `Arb2 -> ([ "-lflint-arb" ], [])
| `Flint3 -> ([], [ "-I/usr/include/flint" ])
in

C.Flags.write_sexp "arb_cflag.sexp" [arb_cflag]
)
C.Flags.write_sexp "arb_cflags.sexp" cflags;
C.Flags.write_sexp "arb_libs.sexp" libs;
())
40 changes: 40 additions & 0 deletions configure/find_calcium.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module C = Configurator.V1

(* Starting with version 3, `flint` integrates
`arb`, `antic`, and `calcium`. However, given
that it a recent release, not all distribution
will have it. Therefore we need to try and handle
both version 3 and version > 3 of `flint`, and
handle things differently depending on which version
is installed.

Also, as of now, neither debian nor archlinux packages
include pkg-config files, so we have to find other ways
to determine libs and cflags.

These are the different situations:
- on version <2 (and distros such as Debian):
+ antic headers are in `/usr/include/antic`
+ antic lib file is libantic.so
- on version 3 (and distros such as archlinux):
+ calcium headers are in `/usr/include/flint`
+ calcium library file does not exist (included in flint.so)
*)

(* Test the location of the `qfb.h` header to determine the
current situation *)
let version c =
if Util.is_header_available c "calcium/calcium.h" then `Calcium2
else if Util.is_header_available c "flint/calcium.h" then `Flint3
else C.die "Could not find the `calcium` library"

let () =
C.main ~name:"find_calcium" (fun c ->
let libs, cflags =
match version c with
| `Calcium2 -> ([ "-lcalcium" ], [ "-I/usr/include/calcium" ])
| `Flint3 -> ([], [ "-I/usr/include/flint" ])
in
C.Flags.write_sexp "calcium_cflags.sexp" cflags;
C.Flags.write_sexp "calcium_libs.sexp" libs;
())
9 changes: 5 additions & 4 deletions configure/discover.ml → configure/find_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ let () =
C.main ~name:"discover" (fun c ->
let cflags, libs =
match C.Pkg_config.get c with
| None -> ([], [])
| None ->
(* sane defaults in the absence of pkg-config *)
([ "-lgmp"; "-lmpfr" ], [])
| Some pc ->
let flags ~package =
match C.Pkg_config.query pc ~package with
Expand All @@ -13,9 +15,8 @@ let () =
in
let gmp = flags ~package:"gmp" in
let mpfr = flags ~package:"mpfr" in

(fst gmp @ fst mpfr, snd gmp @ snd mpfr)
in

C.Flags.write_sexp "c_flags.sexp" cflags;
C.Flags.write_sexp "libs.sexp" libs)
C.Flags.write_sexp "common_cflags.sexp" cflags;
C.Flags.write_sexp "common_libs.sexp" libs)
31 changes: 31 additions & 0 deletions configure/find_flint.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module C = Configurator.V1

(* Starting with version 3, `flint` integrates
`arb`, `antic`, and `calcium`. However, given
that it a recent release, not all distribution
will have it. Therefore we need to try and handle
both version 3 and version > 3 of `flint`, and
handle things differently depending on which version
is installed.

Also, as of now, neither debian nor archlinux packages
include pkg-config files, so we have to find other ways
to determine libs and cflags.

These are the different situations:
- on version <2 (and distros such as Debian):
+ flint headers are in `/usr/include/flint`
+ flint lib file is libflint.so
- on version 3 (and distros such as archlinux):
+ flint headers are in `/usr/include/flint`
+ flint lib file is libflint.so
*)

(* Test the location of the `arb.h` header to determine the
current situation *)
let () =
C.main ~name:"find_flint" (fun _c ->
let libs, cflags = ([ "-lflint" ], [ "-I/usr/include/flint" ]) in
C.Flags.write_sexp "flint_cflags.sexp" cflags;
C.Flags.write_sexp "flint_libs.sexp" libs;
())
15 changes: 15 additions & 0 deletions configure/util.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module C = Configurator.V1

let is_header_available c ?(c_flags = []) h =
let c_main = Format.asprintf {|#include "%s"|} h in
let c_flags = "-c" :: c_flags in
C.c_test c ~c_flags c_main

let find_working_cflag ~name ~c flags =
let dummy_c_main = {|int main() { return 0; }|} in
let rec aux = function
| [] -> C.die "Could not find an available c libname for %s" name
| cflag :: r ->
if C.c_test c ~c_flags:[ cflag ] dummy_c_main then cflag else aux r
in
aux flags
Loading