(jbuild_version 1)

;; Build a functorized version of the protocol with the `tezos-protocol-compiler`
;; This is bit hackish...
;;
;; AFAIK the current version of jbuilder (1.0+beta16) does not allow to compile
;; with a custom `rule` the `(modules)` of a library.
;;
;; A trick is to provide the `.cmx` through the `(library_flags)` and to generate
;; a empty `.ml` to correctly handle the dependencies...

(rule
 ((targets (tezos_protocol_demo.o
            tezos_protocol_demo.cmx
            tezos_protocol_demo.cmi
            tezos_protocol_demo_dummy.ml))
  (deps ((glob_files src/*.ml)
         (glob_files src/*.mli)
         src/TEZOS_PROTOCOL))
  (action (with-stdout-to ${path-no-dep:tezos_protocol_demo_dummy.ml}
           (chdir ${ROOT}
                  (run ${bin:tezos-protocol-compiler} -static ${path-no-dep:tezos_protocol_demo} ${path-no-dep:src}))))))

(library
 ((name tezos_protocol_demo)
  (public_name tezos-protocol-demo)
  (library_flags (:standard -linkall
                            lib_embedded_protocol_demo/tezos_protocol_demo.cmx))
  (wrapped false)
  (modes (native))
  (modules (Tezos_protocol_demo_dummy))))

(alias
 ((name runtest_sandbox)
  (deps (tezos_protocol_demo.cmx))))

(alias
 ((name runtest_indent)
  (deps ((glob_files src/*.ml) (glob_files src/*.mli)))
  (action (run bash ${libexec:tezos-stdlib:test-ocp-indent.sh} ${<}))))