Commits

Sebastien Mondet  committed 4ab8efa

build: add documentation generation

  • Participants
  • Parent commits 767b4db

Comments (0)

Files changed (1)

  • +31 -11
    mk
 
 let args = Array.to_list Sys.argv
 
-let build () =
+let in_build_directory f =
   cmdf "mkdir -p _build/";
   Sys.chdir "_build/";
-  chain [
-    "pwd";
-    "cp ../pvem.ml .";
-    "ocamlc -c pvem.ml -annot -o _build/pvem.cmo";
-    "ocamlopt -c pvem.ml -annot -o _build/pvem.cmx";
-  ];
+  begin try
+    f ();
+  with
+    e ->
+    Sys.chdir "../";
+    raise e
+  end;
+  Sys.chdir "../";
   ()
 
+
+let build () =
+  in_build_directory (fun () ->
+      chain [
+        "pwd";
+        "cp ../pvem.ml .";
+        "ocamlc -c pvem.ml -annot -o _build/pvem.cmo";
+        "ocamlopt -c pvem.ml -annot -o _build/pvem.cmx";
+      ])
+
 let () =
   match args with
   | exec :: "build" :: [] ->
     say "Building.";
     build ();
     say "Testing.";
-    chain [
-      "cp ../test_pvem.ml .";
-      "ocaml pvem.cmo test_pvem.ml;"
-    ];
+    in_build_directory (fun () ->
+        chain [
+          "cp ../test_pvem.ml .";
+          "ocaml pvem.cmo test_pvem.ml;"
+        ];
+      );
     say "Done."
+  | exec :: "doc" :: [] ->
+    say "Building the documentation.";
+    in_build_directory (fun () ->
+        chain [
+          "ocamldoc -charset UTF-8 -colorize-code -html pvem.ml";
+        ])
   | exec :: "clean" :: []
   | exec :: "C" :: [] ->
     cmdf "rm -fr _build"