(* -*- tuareg -*- *)
open StdLabels
open Jbuild_plugin.V1

let git_version =
  let placeholder = "6.4.0" in
  match run_and_read_lines "git describe --always --dirty" with
  | exception _ -> ""
  | version :: _ ->
    if "%%" ^ "VERSION" ^ "%%" = placeholder
    then version
    else placeholder
  | [] -> ""

let dyn =
  Printf.sprintf
    {|
(rule
  (target GIT-VERSION)
  (action (with-stdout-to %%{target} (echo "%s"))))
|}
    git_version

let () = send dyn
