Passage à dune

This commit is contained in:
Matthieu Dubuget 2018-07-12 17:08:54 +02:00
parent 760c0b26e4
commit 3448741682
17 changed files with 100 additions and 98 deletions

3
dune-project Normal file
View File

@ -0,0 +1,3 @@
(lang dune 1.0)
(name libusb)
(version 2018-07-12-1)

32
lib/dune Normal file
View File

@ -0,0 +1,32 @@
(library
(name libusb)
(public_name libusb)
(flags -w "-9")
(libraries ctypes)
(c_names cstub_libusb)
(c_flags (:include libusb_cflags_and_no_discarded_qualifiers))
(c_library_flags -lusb-1.0)
)
(rule
(targets libusb_cflags_and_no_discarded_qualifiers)
(deps generator/stubs/libusb_cflags)
(action
(with-stdout-to %{targets}
(progn (echo "(")
(cat %{deps})
(echo " -Wno-discarded-qualifiers")
(echo ")")
)
)
)
)
(copy_files generator/g.ml)
(copy_files generator/stubs/{t,my_types}.ml)
(rule
(targets cstub_libusb.c bindings.ml)
(deps generator/generator.exe)
(action (run %{deps}))
)

7
lib/generator/dune Normal file
View File

@ -0,0 +1,7 @@
(executable
(name generator)
(libraries ctypes.stubs)
(flags -w "-9")
)
(copy_files stubs/{t,my_types}.ml)

View File

@ -1,6 +0,0 @@
(executable(
(name generator)
(libraries (ctypes.stubs))
))
(copy_files stubs/{t,my_types}.ml)

View File

@ -0,0 +1,9 @@
(executable
(name c_types_generator)
(libraries ctypes.stubs)
)
(rule
(targets t.ml)
(action (copy ../t.ml t.ml))
)

View File

@ -1,9 +0,0 @@
(executable(
(name c_types_generator)
(libraries (ctypes.stubs))
))
(rule(
(targets (t.ml))
(action (copy ../t.ml t.ml))
))

View File

@ -0,0 +1,4 @@
(executable
(name ctypes_cflags_generator)
(libraries findlib)
)

View File

@ -1,4 +0,0 @@
(executable(
(name ctypes_cflags_generator)
(libraries (findlib))
))

36
lib/generator/stubs/dune Normal file
View File

@ -0,0 +1,36 @@
(rule
(targets my_types.ml)
(deps my_types_generator.exe)
(action (with-stdout-to %{targets} (run %{deps})))
)
(rule
(targets my_types_generator.exe)
(deps my_types_generator.c)
(action (run %{cc}
-o %{targets}
%{read:libusb_cflags}
%{read:ctypes_cflags}
-I%{ocaml-config:standard_library}
%{deps}))
)
(rule
(targets my_types_generator.c)
(action (with-stdout-to %{targets}
(run c_types_generator/c_types_generator.exe)))
)
(rule
(targets ctypes_cflags)
(action
(with-stdout-to %{targets}
(run ctypes_cflags_generator/ctypes_cflags_generator.exe)))
)
(rule
(targets libusb_cflags)
(action
(with-stdout-to %{targets}
(run libusb_cflags_generator/libusb_cflags_generator.exe)))
)

View File

@ -1,36 +0,0 @@
(rule(
(targets (my_types.ml))
(deps (my_types_generator.exe))
(action (with-stdout-to ${@} (run ${<})))
))
(rule(
(targets (my_types_generator.exe))
(deps (my_types_generator.c))
(action (run ${CC}
-o ${@}
${read:libusb_cflags}
${read:ctypes_cflags}
-I${ocaml-config:standard_library}
${<}))
))
(rule(
(targets (my_types_generator.c))
(action
(with-stdout-to ${@}
(run c_types_generator/c_types_generator.exe)
))
))
(rule(
(targets (ctypes_cflags))
(action (with-stdout-to ${@}
(run ctypes_cflags_generator/ctypes_cflags_generator.exe)))
))
(rule(
(targets (libusb_cflags))
(action (with-stdout-to ${@}
(run libusb_cflags_generator/libusb_cflags_generator.exe)))
))

View File

@ -0,0 +1,4 @@
(executable
(name libusb_cflags_generator)
(libraries dune.configurator)
)

View File

@ -1,4 +0,0 @@
(executable(
(name libusb_cflags_generator)
(libraries (configurator))
))

View File

@ -1,11 +1,11 @@
let (>>|) a f = match a with None -> None | Some a -> f a let (>>|) a f = match a with None -> None | Some a -> f a
let libusb_c_flags = let libusb_c_flags =
let open Configurator in let open Configurator.V1 in
create "c" create "c"
|> Pkg_config.get |> Pkg_config.get
>>| Pkg_config.query ~package:"libusb-1.0" >>| Pkg_config.query ~package:"libusb-1.0"
>>| (fun Pkg_config.{cflags} -> >>| (fun Pkg_config.{cflags;_} ->
Some (String.concat " " cflags)) Some (String.concat " " cflags))
|> (function |> (function
| None -> "libusb flag not found" | None -> "libusb flag not found"

View File

@ -1,30 +0,0 @@
(library(
(name libusb)
(public_name libusb)
(libraries (ctypes))
(c_names (cstub_libusb))
(c_flags (:include libusb_cflags_and_no_discarded_qualifiers))
(c_library_flags (-lusb-1.0))
))
(rule(
(targets (libusb_cflags_and_no_discarded_qualifiers))
(deps (generator/stubs/libusb_cflags))
(action (with-stdout-to ${@}
(progn
(echo "(")
(cat ${<})
(echo " -Wno-discarded-qualifiers")
(echo ")")
)
))
))
(copy_files generator/g.ml)
(copy_files generator/stubs/{t,my_types}.ml)
(rule(
(targets (cstub_libusb.c bindings.ml))
(deps (generator/generator.exe))
(action (run ${<}))
))

View File

@ -8,8 +8,6 @@
- in order to experiment more in depth with {{:https://github.com/ocamllabs/ocaml-ctypes} Ctypes}; - in order to experiment more in depth with {{:https://github.com/ocamllabs/ocaml-ctypes} Ctypes};
- and because I needed something more portable than {{:https://github.com/letoh/ocaml-usb} ocaml-usb}: this one is working on Windows. *) - and because I needed something more portable than {{:https://github.com/letoh/ocaml-usb} ocaml-usb}: this one is working on Windows. *)
open Ctypes
include module type of T include module type of T

View File

@ -1,5 +1,5 @@
opam-version: "1.2" opam-version: "1.2"
version: "2018-06-24-1" version: "2018-07-12-1"
maintainer: "Matthieu Dubuget <matthieu.dubuget@gmail.com>" maintainer: "Matthieu Dubuget <matthieu.dubuget@gmail.com>"
authors: "Matthieu Dubuget <matthieu.dubuget@gmail.com>" authors: "Matthieu Dubuget <matthieu.dubuget@gmail.com>"
@ -7,15 +7,13 @@ homepage: "none"
bug-reports: "Matthieu Dubuget <matthieu.dubuget@gmail.com>" bug-reports: "Matthieu Dubuget <matthieu.dubuget@gmail.com>"
build: [ build: [
["jbuilder" "subst" "-n" name] {pinned} [ "dune" "build" "-p" name "-j" jobs ]
[ "jbuilder" "build" "-p" name "-j" jobs ]
] ]
license: "Not yet decided" license: "Not yet decided"
depends: [ depends: [
"jbuilder" {build & >= "1.0+beta13"} "dune" {build}
"ctypes" {build} "ctypes" {build}
"configurator" {build}
"ocamlfind" {build} "ocamlfind" {build}
] ]