;
; Shims for running coq binaries with minimal dependencies
;

; coqtop

(alias
 (name coqtop-prelude)
 (deps
  %{bin:coqtop}
   ; XXX: bug, we are missing the dep on the _install meta file...
  %{project_root}/theories/Init/Prelude.vo))

(rule
 (targets coqtop)
 (deps (alias coqtop-prelude))
 (action
  (with-stdout-to %{targets}
   (progn
    (echo "#!/usr/bin/env bash\n")
    (bash "echo '\"$(dirname \"$0\")\"/%{bin:coqtop} -I \"$(dirname \"$0\")/%{project_root}/../install/default/lib\" -coqlib \"$(dirname \"$0\")/%{project_root}\" \"$@\"'")
    (run chmod +x %{targets})))))

; coqc

(alias
 (name coqc-prelude)
 (deps
  %{bin:coqc}
  %{bin:coqworker.opt}
  %{project_root}/theories/Init/Prelude.vo))

(rule
 (targets coqc)
 (deps (alias coqc-prelude))
 (action
  (with-stdout-to %{targets}
   (progn
    (echo "#!/usr/bin/env bash\n")
    (bash "echo '\"$(dirname \"$0\")\"/%{bin:coqc} -I \"$(dirname \"$0\")/%{project_root}/../install/default/lib\" -coqlib \"$(dirname \"$0\")\"/%{project_root} -nI \"$(dirname \"$0\")\"/%{project_root}/kernel/.kernel.objs/byte \"$@\"'")
    (run chmod +x %{targets})))))

; coqtop.byte

(alias
 (name coqtop.byte-prelude)
 (deps
  %{project_root}/theories/Init/Prelude.vo
  %{bin:coqtop.byte}
  %{lib:coq-core.config:config.cma}
  %{lib:coq-core.clib:clib.cma}
  %{lib:coq-core.lib:lib.cma}
  %{lib:coq-core.kernel:kernel.cma}
  %{lib:coq-core.vm:coqrun.cma}
  %{lib:coq-core.vm:../../stublibs/dllcoqrun_stubs.so}
  %{lib:coq-core.library:library.cma}
  %{lib:coq-core.engine:engine.cma}
  %{lib:coq-core.pretyping:pretyping.cma}
  %{lib:coq-core.gramlib:gramlib.cma}
  %{lib:coq-core.interp:interp.cma}
  %{lib:coq-core.proofs:proofs.cma}
  %{lib:coq-core.parsing:parsing.cma}
  %{lib:coq-core.printing:printing.cma}
  %{lib:coq-core.tactics:tactics.cma}
  %{lib:coq-core.vernac:vernac.cma}
  %{lib:coq-core.stm:stm.cma}
  %{lib:coq-core.sysinit:sysinit.cma}
  %{lib:coq-core.toplevel:toplevel.cma}
  %{lib:coq-core.plugins.number_string_notation:number_string_notation_plugin.cma}
  %{lib:coq-core.plugins.tauto:tauto_plugin.cma}
  %{lib:coq-core.plugins.cc:cc_plugin.cma}
  %{lib:coq-core.plugins.firstorder:firstorder_plugin.cma}
  %{lib:coq-core.plugins.ltac:ltac_plugin.cma}
  (alias %{project_root}/dev/ml_toplevel_files)))

(rule
 (targets coqtop.byte)
 (deps (alias coqtop.byte-prelude))
 (action
  (with-stdout-to %{targets}
   (progn
    (echo "#!/usr/bin/env bash\n")
    (bash "echo '\"$(dirname \"$0\")\"/%{bin:coqtop.byte} -I \"$(dirname \"$0\")/%{project_root}/../install/default/lib\" -coqlib \"$(dirname \"$0\")\"/%{project_root} \"$@\"'")
    (run chmod +x %{targets})))))

; coqide

(alias
 (name coqide-prelude)
 (deps
  ; without this if the gtk libs are not available dune can try to use
  ; coqide from PATH instead of giving a nice error
  ; there is no problem with the other shims since they don't depend on optional build products
  %{project_root}/ide/coqide/coqide_main.exe
  %{bin:coqworker.opt}
  %{project_root}/theories/Init/Prelude.vo
  %{project_root}/coqide-server.install
  %{project_root}/coqide.install))

(rule
 (targets coqide)
 (deps (alias coqide-prelude))
 (action
  (with-stdout-to %{targets}
   (progn
    (echo "#!/usr/bin/env bash\n")
    (bash "echo '\"$(dirname \"$0\")\"/%{bin:coqide} -I \"$(dirname \"$0\")/%{project_root}/../install/default/lib\" -coqlib \"$(dirname \"$0\")\"/%{project_root} \"$@\"'")
    (run chmod +x %{targets})))))
