(rule
 (targets module1.cmo module1.cmi)
 (action
  (run ocamlc -g -c %{dep:module1.ml})))

(rule
 (targets module2.cmo module2.cmi)
 (deps module1.cmi lib1_mod1.cmi)
 (action
  (run ocamlc -g -c %{dep:module2.ml})))

(rule
 (targets lib1.cma)
 (action
  (run ocamlc -g -a %{dep:lib1_mod1.cmo} %{dep:lib1_mod2.cmo} -o lib1.cma)))

(rule
 (targets lib1_mod1.cmo lib1_mod1.cmi)
 (action
  (run ocamlc -g -c %{dep:lib1_mod1.ml})))

(rule
 (targets lib1_mod2.cmo lib1_mod2.cmi)
 (action
  (run ocamlc -g -c %{dep:lib1_mod2.ml})))

(rule
 (targets lib1.cma.js)
 (action
  (run
   %{bin:js_of_ocaml}
   --load-shape
   %{dep:stdlib.cma.js}
   --pretty
   --source-map
   %{dep:lib1.cma}
   -o
   %{targets})))

(rule
 (targets module1.js)
 (action
  (run
   %{bin:js_of_ocaml}
   --load-shape
   %{dep:stdlib.cma.js}
   --pretty
   --source-map
   %{dep:module1.cmo}
   -o
   %{targets})))

(rule
 (targets module2.js)
 (action
  (run
   %{bin:js_of_ocaml}
   --load-shape
   %{dep:stdlib.cma.js}
   --load-shape
   %{dep:lib1.cma.js}
   --load-shape
   %{dep:module1.js}
   --pretty
   --source-map
   %{dep:module2.cmo}
   -o
   %{targets})))

(rule
 (targets stdlib.cma.js)
 (action
  (run
   %{bin:js_of_ocaml}
   --pretty
   --source-map
   %{lib:stdlib:stdlib.cma}
   -o
   %{targets})))

(rule
 (targets std_exit.js)
 (action
  (run
   %{bin:js_of_ocaml}
   --load-shape
   %{dep:stdlib.cma.js}
   --pretty
   --source-map
   %{lib:stdlib:std_exit.cmo}
   -o
   %{targets})))

(rule
 (targets myruntime.js)
 (action
  (run %{bin:js_of_ocaml} build-runtime --pretty --source-map -o %{targets})))

(rule
 (targets bin.js)
 (action
  (run
   %{bin:js_of_ocaml}
   link
   --pretty
   %{dep:myruntime.js}
   %{dep:stdlib.cma.js}
   %{dep:lib1.cma.js}
   %{dep:module1.js}
   %{dep:module2.js}
   %{dep:std_exit.js}
   -o
   %{targets})))

(rule
 (target bin.actual)
 (deps bin.js)
 (action
  (with-stdout-to
   %{target}
   (run node ./bin.js))))

(rule
 (alias runtest-js)
 (action
  (diff bin.expected bin.actual)))

(alias
 (name default)
 (deps
  myruntime.js
  stdlib.cma.js
  std_exit.js
  module2.js
  module1.js
  bin.js
  index.html))
