Clean-up the build system.
authorKim Nguyễn <kn@lri.fr>
Thu, 7 Feb 2013 22:12:04 +0000 (23:12 +0100)
committerKim Nguyễn <kn@lri.fr>
Thu, 7 Feb 2013 22:12:04 +0000 (23:12 +0100)
- Add a portable build script (only requires ocaml)
- Regroup all build option in the _tags file
- Write a generic myocamlbuild.ml file

Makefile [deleted file]
_tags
build [new file with mode: 0755]
myocamlbuild.ml

diff --git a/Makefile b/Makefile
deleted file mode 100644 (file)
index 09c08ab..0000000
--- a/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
-SOURCE_DIR=src,src/xpath,src/utils,src/tree,src/auto
-TARGET=main.otarget
-OCAMLFINDPKG=unix,ulex,expat,camlp4,camlp4.lib,camlp4.macro
-all:
-       @echo [BUILD]
-       ocamlbuild -pkgs $(OCAMLFINDPKG) -use-ocamlfind -Is $(SOURCE_DIR) $(TARGET)
-
-clean:
-       @echo [Clean]
-       @ocamlbuild -clean
diff --git a/_tags b/_tags
index 8baa48a..571d289 100644 (file)
--- a/_tags
+++ b/_tags
@@ -1,5 +1,30 @@
+#camlp4 packages and syntax tags
+
+true:    package(ulex),          \
+         package(unix),          \
+         package(expat),         \
+         package(camlp4.macro),  \
+         syntax(camlp4o),        \
+         macro_include(include)
+
+#compilation options
+
+true:    inline(100), unsafe(true)
+
+
+#project source tree
 <src/xpath/*.cmx>:  for-pack(Xpath)
+<src/xpath>:        include
+
 <src/utils/*.cmx>:  for-pack(Utils)
+<src/utils>: include
+
 <src/tree/*.cmx>:   for-pack(Tree)
+<src/tree>: include
+
 <src/auto/*.cmx>:   for-pack(Auto)
-<**/*.ml>:          syntax(camlp4o), macro_include(include)
\ No newline at end of file
+<src/auto>: include
+
+<src>: include
+
+
diff --git a/build b/build
new file mode 100755 (executable)
index 0000000..ed3876a
--- /dev/null
+++ b/build
@@ -0,0 +1,24 @@
+#!/usr/bin/env ocaml
+
+let target = ref "main.otarget"
+let debug = ref false
+let profile = ref false
+let verbose = ref false
+
+let () =
+  for i = 1 to Array.length Sys.argv - 1 do
+    match Sys.argv.(i) with
+    | "-d" -> debug := true
+    | "-p" -> profile := true
+    | "-v" -> verbose := true
+    | x -> target := x
+  done
+
+let oprofile = if !profile then " -tag profile " else ""
+let odebug = if !profile then " -tag debug " else ""
+let otarget = if !target = "clean" then " -clean " else !target
+let overbose = if !verbose then " -classic-display " else ""
+
+let cmd = "ocamlbuild -use-ocamlfind " ^ overbose ^ oprofile ^ odebug ^ otarget
+let _ = Sys.command cmd
+
index a1fe8e9..41730a6 100644 (file)
@@ -1,15 +1,23 @@
 open Ocamlbuild_plugin
 open Command
 
-let includes = Hashtbl.create 17
+let includes = ref StringSet.empty
+
 let register_include dir =
-  if not (Hashtbl.mem includes dir) then begin
-    Hashtbl.add includes dir ();
+  if not (StringSet.mem dir !includes) then begin
+    includes := StringSet.add dir !includes;
     dep [ "extension:ml" ]
       (List.map (fun s -> dir ^ "/" ^ s )
          (Array.to_list (Pathname.readdir dir)))
   end
 
+let set_flags tag_list action_list =
+  List.iter (fun s ->
+    List.iter (fun (fl, fu) ->
+      pflag s fl fu)
+      action_list
+  ) tag_list
+
 let macro_flags = [
   "macro_include",
   (fun s -> register_include s; S [A"-ppopt"; A "-I"; A"-ppopt"; A s]);
@@ -19,12 +27,14 @@ let macro_flags = [
 let () = dispatch begin
   function
     | Before_rules ->
-        List.iter (fun s ->
-          List.iter (fun (fl, fu) ->
-            pflag s fl fu) macro_flags
-        )
-          [["ocaml";"compile"];
-           ["ocaml";"ocamldep"] ]
-;
+        set_flags [["ocaml";"compile"]; ["ocaml";"ocamldep"] ] macro_flags;
+        flag [ "ocaml"; "compile"; "debug" ] (S[ A"-g"; A"-ppopt"; A"-DDEBUG"]);
+        flag [ "ocaml"; "link"; "debug" ] (A"-g");
+        flag [ "ocaml"; "compile"; "profile"] (S[A"-ppopt"; A"-DPROFILE"]);
+        flag [ "ocaml"; "compile"; "profile"; "native"] (A"-p");
+        flag [ "ocaml"; "link"; "profile"; "native"] (A"-p");
+        pflag [ "ocaml"; "compile"; "native" ] "inline" (fun i -> (S[ A"-inline"; A i ]));
+        pflag [ "ocaml"; "compile" ] "unsafe" (fun s -> (if s = "true" then S[A"-ppopt";A "-unsafe"] else N));
+
     | _ -> ()
 end