From 0336e221bf2ff068b1b16e27d24f7e9f87869b3e Mon Sep 17 00:00:00 2001 From: Marcello Seri Date: Tue, 28 Mar 2023 10:18:21 +0200 Subject: [PATCH 1/2] configurator: use linking flags and compile flags where needed Signed-off-by: Marcello Seri --- arb/dune | 9 +++++++-- calcium/dune | 7 ++++++- configure/discover.ml | 19 ++++++++++--------- configure/dune | 5 +++-- flint/dune | 7 ++++++- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/arb/dune b/arb/dune index 68925d4..bfabc03 100644 --- a/arb/dune +++ b/arb/dune @@ -5,7 +5,10 @@ (foreign_archives arb) (foreign_stubs (language c) - (names ocaml_acb_utils)) + (names ocaml_acb_utils) + (flags + (:include ../configure/c_flags.sexp) + :standard)) (libraries zarith flint threads) (flags -w -9-27) (ctypes @@ -18,7 +21,9 @@ "-Werror=implicit-function-declaration" (:include ../configure/c_flags.sexp) :standard) - (c_library_flags "-lgmp -lmpfr"))) + (c_library_flags + (:include ../configure/libs.sexp) + "-lgmp -lmpfr"))) (deps arb.h acb.h) (headers (include "acb.h" "string.h")) diff --git a/calcium/dune b/calcium/dune index cc84cbb..b4ce260 100644 --- a/calcium/dune +++ b/calcium/dune @@ -6,6 +6,9 @@ (foreign_stubs (language c) (names ocaml_calcium_utils) + (flags + (:include ../configure/c_flags.sexp) + :standard) (include_dirs lib (lib flint) @@ -25,7 +28,9 @@ "-Werror=implicit-function-declaration" (:include ../configure/c_flags.sexp) :standard) - (c_library_flags "-lgmp -lmpfr"))) + (c_library_flags + (:include ../configure/libs.sexp) + "-lgmp -lmpfr"))) (deps lib/ca.h) (headers (include "lib/ca.h" "string.h")) diff --git a/configure/discover.ml b/configure/discover.ml index ef7b777..10be03f 100644 --- a/configure/discover.ml +++ b/configure/discover.ml @@ -2,19 +2,20 @@ module C = Configurator.V1 let () = C.main ~name:"discover" (fun c -> - let conf = + let cflags, libs = match C.Pkg_config.get c with - | None -> [] + | None -> ([], []) | Some pc -> - let cflags ~package = + let flags ~package = match C.Pkg_config.query pc ~package with - | None -> [] - | Some info -> info.cflags + | None -> ([], []) + | Some info -> (info.cflags, info.libs) in - let gmp = cflags ~package:"gmp" in - let mpfr = cflags ~package:"mpfr" in + let gmp = flags ~package:"gmp" in + let mpfr = flags ~package:"mpfr" in - gmp @ mpfr + (fst gmp @ fst mpfr, snd gmp @ snd mpfr) in - C.Flags.write_sexp "c_flags.sexp" conf) + C.Flags.write_sexp "c_flags.sexp" cflags; + C.Flags.write_sexp "libs.sexp" libs) diff --git a/configure/dune b/configure/dune index 617bc69..cafd06b 100644 --- a/configure/dune +++ b/configure/dune @@ -3,5 +3,6 @@ (libraries dune-configurator)) (rule - (targets c_flags.sexp) - (action (run ./discover.exe))) + (targets c_flags.sexp libs.sexp) + (action + (run ./discover.exe))) diff --git a/flint/dune b/flint/dune index 06a7e04..3d671dc 100644 --- a/flint/dune +++ b/flint/dune @@ -6,6 +6,9 @@ (foreign_stubs (language c) (names ocaml_flint_utils) + (flags + (:include ../configure/c_flags.sexp) + :standard) (include_dirs flint (lib zarith))) @@ -21,7 +24,9 @@ "-Werror=implicit-function-declaration" (:include ../configure/c_flags.sexp) :standard) - (c_library_flags "-lgmp -lmpfr"))) + (c_library_flags + (:include ../configure/libs.sexp) + "-lgmp -lmpfr"))) (deps flint/flint.h flint/fmpz.h) (headers (include "flint/fmpz.h" "flint/fmpq.h" "string.h")) From 24ee67cb3939b936777d5f9899d558de3773816d Mon Sep 17 00:00:00 2001 From: Marcello Seri Date: Tue, 28 Mar 2023 10:18:40 +0200 Subject: [PATCH 2/2] dune build @fmt Signed-off-by: Marcello Seri --- antic/antic/dune | 4 ++-- arb/dune | 4 ++-- calcium/lib/dune | 4 ++-- calcium/tests/dune | 3 +-- flint/flint/dune | 4 ++-- flint/tests/dune | 6 +++--- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/antic/antic/dune b/antic/antic/dune index 6d6da22..a0f710f 100644 --- a/antic/antic/dune +++ b/antic/antic/dune @@ -32,8 +32,8 @@ CFLAGS=-fPIC) (run make library -j) (run make install) - (system "if [ -f ../prefix/lib/libantic.dylib ]; then mv ../prefix/lib/libantic.dylib ../prefix/lib/libantic.so; fi") - )) + (system + "if [ -f ../prefix/lib/libantic.dylib ]; then mv ../prefix/lib/libantic.dylib ../prefix/lib/libantic.so; fi"))) (copy prefix/lib/libantic%{ext_dll} dllantic%{ext_dll}) (copy prefix/lib/libantic%{ext_lib} libantic%{ext_lib}) (copy prefix/include/antic/nf_elem.h nf_elem.h) diff --git a/arb/dune b/arb/dune index bfabc03..131ab0a 100644 --- a/arb/dune +++ b/arb/dune @@ -106,8 +106,8 @@ CFLAGS=-fPIC) (run make library -j) (run make install) - (system "if [ -f ../prefix/lib/libarb.dylib ]; then mv ../prefix/lib/libarb.dylib ../prefix/lib/libarb.so; fi") - )) + (system + "if [ -f ../prefix/lib/libarb.dylib ]; then mv ../prefix/lib/libarb.dylib ../prefix/lib/libarb.so; fi"))) (copy prefix/lib/libarb%{ext_dll} dllarb%{ext_dll}) (copy prefix/lib/libarb%{ext_lib} libarb%{ext_lib}) (copy prefix/include/dirichlet.h dirichlet.h) diff --git a/calcium/lib/dune b/calcium/lib/dune index e0a156d..aebbdc6 100644 --- a/calcium/lib/dune +++ b/calcium/lib/dune @@ -66,8 +66,8 @@ CFLAGS=-fPIC) (run make library -j) (run make install) - (system "if [ -f ../prefix/lib/libcalcium.dylib ]; then mv ../prefix/lib/libcalcium.dylib ../prefix/lib/libcalcium.so; fi") - )) + (system + "if [ -f ../prefix/lib/libcalcium.dylib ]; then mv ../prefix/lib/libcalcium.dylib ../prefix/lib/libcalcium.so; fi"))) (copy prefix/lib/libcalcium%{ext_dll} dllcalcium%{ext_dll}) (copy prefix/lib/libcalcium%{ext_lib} libcalcium%{ext_lib}) (copy prefix/include/calcium/qqbar.h qqbar.h) diff --git a/calcium/tests/dune b/calcium/tests/dune index 620a987..86113c7 100644 --- a/calcium/tests/dune +++ b/calcium/tests/dune @@ -2,8 +2,7 @@ (names units) (modules units) (libraries calcium) - (package calcium) -) + (package calcium)) ;; Need dune whole mode for foreign library diff --git a/flint/flint/dune b/flint/flint/dune index 7918f21..4c3c67e 100644 --- a/flint/flint/dune +++ b/flint/flint/dune @@ -140,8 +140,8 @@ (run ./configure --prefix=../prefix CFLAGS=-fPIC --with-pkg-config) (run make library -j) (run make install) - (system "if [ -f ../prefix/lib/libflint.dylib ]; then mv ../prefix/lib/libflint.dylib ../prefix/lib/libflint.so; fi") - )) + (system + "if [ -f ../prefix/lib/libflint.dylib ]; then mv ../prefix/lib/libflint.dylib ../prefix/lib/libflint.so; fi"))) (copy prefix/lib/libflint%{ext_lib} libflint%{ext_lib}) (copy prefix/lib/libflint%{ext_dll} dllflint%{ext_dll}) (copy prefix/include/flint/aprcl.h aprcl.h) diff --git a/flint/tests/dune b/flint/tests/dune index a5eaccd..e06e193 100644 --- a/flint/tests/dune +++ b/flint/tests/dune @@ -9,6 +9,6 @@ (names dynamic) (modules dynamic) (libraries dune-site.plugins zarith threads) - (deps (package flint)) - (package flint) -) + (deps + (package flint)) + (package flint))