Skip to content

Commit

Permalink
Reorganize dune files for better C flags configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
thvnx committed Sep 8, 2024
1 parent 1448189 commit a2f059e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,4 @@ jobs:
opam exec -- dune build @runtest --profile dev --verbose
opam exec -- dune build @doc
opam exec -- dune install
# LD_LIBRARY_PATH is not exported by dune for executables
# FIXME find a way to export LD_LIBRARY_PATH with dune
LD_LIBRARY_PATH=/usr/local/lib opam exec -- dune exec examples/example.exe
opam exec -- dune exec examples/example.exe
11 changes: 6 additions & 5 deletions src/config/discover.ml → config/discover.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ let cflags = [ "-O2"; "-Wall"; "-Wextra"; "-fPIC" ]
let () =
C.main ~name:"discover-mpfr" (fun c ->
let default : C.Pkg_config.package_conf =
{ libs = [ "-lmpfr" ]; cflags }
{ libs = [ "-lmpfr"; "-lgmp" ]; cflags }
in
let conf =
let conf p =
match C.Pkg_config.get c with
| None -> default
| Some pc -> (
match C.Pkg_config.query pc ~package:"mpfr" with
match C.Pkg_config.query pc ~package:p with
| None -> default
| Some deps -> deps)
in

C.Flags.write_sexp "c_flags.sexp" (List.concat [ cflags; conf.cflags ]);
C.Flags.write_sexp "c_library_flags.sexp" conf.libs)
C.Flags.write_sexp "c_flags.sexp" (List.concat [ cflags; (conf "mpfr").cflags; (conf "gmp").cflags ]);
C.Flags.write_sexp "c_library_flags.sexp" (List.concat [ (conf "mpfr").libs; (conf "gmp").libs ])
)
File renamed without changes.
15 changes: 12 additions & 3 deletions dune
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
(env
(dev
(flags
(:standard -w +42 -ccopt -L/usr/local/lib))
(:standard -ccopt))
(c_flags
(:standard -O2 -Wall -Wextra -g -L/usr/local/lib))
(:standard -O2 -Wall -Wextra -g)
(:include c_flags.sexp)
(:include c_library_flags.sexp))
(env-vars
(LD_LIBRARY_PATH /usr/local/lib)))
(release
(flags
(:standard -warn-error))
(c_flags
(:standard -O2 -Werror))))
(:standard -O2 -Werror)
(:include c_flags.sexp)
(:include c_library_flags.sexp))))

(rule
(targets c_flags.sexp c_library_flags.sexp)
(action
(run ./config/discover.exe)))
2 changes: 1 addition & 1 deletion src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
(rule
(targets c_flags.sexp c_library_flags.sexp)
(action
(run ./config/discover.exe)))
(run ../config/discover.exe)))
16 changes: 8 additions & 8 deletions testsuite/dune
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
(target basicarithmeticfunctions.ref)
(deps basicarithmeticfunctions.c)
(action
(run %{cc} -o %{target} %{deps} -lmpfr)))
(run %{cc} -o %{target} %{deps})))

(rule
(target basicarithmeticfunctions.expected)
Expand All @@ -42,7 +42,7 @@
(target comparisonfunctions.ref)
(deps comparisonfunctions.c)
(action
(run %{cc} -o %{target} %{deps} -lmpfr)))
(run %{cc} -o %{target} %{deps})))

(rule
(target comparisonfunctions.expected)
Expand All @@ -58,7 +58,7 @@
(target exceptionrelatedfunctions.ref)
(deps exceptionrelatedfunctions.c)
(action
(run %{cc} -o %{target} %{deps} -lmpfr)))
(run %{cc} -o %{target} %{deps})))

(rule
(target exceptionrelatedfunctions.expected)
Expand All @@ -74,7 +74,7 @@
(target initializationfunctions.ref)
(deps initializationfunctions.c)
(action
(run %{cc} -o %{target} %{deps} -lmpfr)))
(run %{cc} -o %{target} %{deps})))

(rule
(target initializationfunctions.expected)
Expand All @@ -90,7 +90,7 @@
(target integerandremainderrelatedfunctions.ref)
(deps integerandremainderrelatedfunctions.c)
(action
(run %{cc} -o %{target} %{deps} -lmpfr)))
(run %{cc} -o %{target} %{deps})))

(rule
(target integerandremainderrelatedfunctions.expected)
Expand All @@ -106,7 +106,7 @@
(target miscellaneousfunctions.ref)
(deps miscellaneousfunctions.c)
(action
(run %{cc} -o %{target} %{deps} -lmpfr)))
(run %{cc} -o %{target} %{deps})))

(rule
(target miscellaneousfunctions.expected)
Expand All @@ -122,7 +122,7 @@
(target roundingrelatedfunctions.ref)
(deps roundingrelatedfunctions.c)
(action
(run %{cc} -o %{target} %{deps} -lmpfr)))
(run %{cc} -o %{target} %{deps})))

(rule
(target roundingrelatedfunctions.expected)
Expand All @@ -138,7 +138,7 @@
(target specialfunctions.ref)
(deps specialfunctions.c)
(action
(run %{cc} -o %{target} %{deps} -lmpfr)))
(run %{cc} -o %{target} %{deps})))

(rule
(target specialfunctions.expected)
Expand Down

0 comments on commit a2f059e

Please sign in to comment.