From d89f59cf6220e605bfbb67fd3cb83f9165fde5a5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kim=20Nguy=E1=BB=85n?= Date: Thu, 7 Feb 2013 23:12:04 +0100 Subject: [PATCH] Clean-up the build system. - Add a portable build script (only requires ocaml) - Regroup all build option in the _tags file - Write a generic myocamlbuild.ml file --- Makefile | 10 ---------- _tags | 27 ++++++++++++++++++++++++++- build | 24 ++++++++++++++++++++++++ myocamlbuild.ml | 30 ++++++++++++++++++++---------- 4 files changed, 70 insertions(+), 21 deletions(-) delete mode 100644 Makefile create mode 100755 build diff --git a/Makefile b/Makefile deleted file mode 100644 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 --- 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 : for-pack(Xpath) +: include + : for-pack(Utils) +: include + : for-pack(Tree) +: include + : for-pack(Auto) -<**/*.ml>: syntax(camlp4o), macro_include(include) \ No newline at end of file +: include + +: include + + diff --git a/build b/build new file mode 100755 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 + diff --git a/myocamlbuild.ml b/myocamlbuild.ml index a1fe8e9..41730a6 100644 --- a/myocamlbuild.ml +++ b/myocamlbuild.ml @@ -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 -- 2.17.1