(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_alpha.o
            tezos_protocol_alpha.cmx
            tezos_protocol_alpha.cmi
            tezos_protocol_alpha_dummy.ml))
  (deps ((glob_files src/*.ml)
         (glob_files src/*.mli)
         src/TEZOS_PROTOCOL))
  (action (with-stdout-to ${path-no-dep:tezos_protocol_alpha_dummy.ml}
           (chdir ${ROOT}
                  (run ${bin:tezos-protocol-compiler} -static ${path-no-dep:tezos_protocol_alpha} ${path-no-dep:src}))))))

(library
 ((name tezos_protocol_alpha)
  (public_name tezos-protocol-alpha)
  (library_flags (:standard -linkall
                            lib_embedded_protocol_alpha/tezos_protocol_alpha.cmx))
  (wrapped false)
  (modes (native))
  (modules (Tezos_protocol_alpha_dummy))))

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

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