openOcamlbuild_plugin;;(**********************)(* these functions are not really officially exported *)letrun_and_read=Ocamlbuild_pack.My_unix.run_and_readletblank_sep_strings=Ocamlbuild_pack.Lexers.blank_sep_stringsletsplitsch=letx=ref[]inletrecgos=letpos=String.indexschinx:=(String.beforespos)::!x;go(String.afters(pos+1))intrygoswithNot_found->!xletsplit_nls=splits'\n'letbefore_spaces=tryString.befores(String.indexs' ')withNot_found->s(* this lists all supported packages *)letfind_packages()=List.mapbefore_space(split_nl&run_and_read"ocamlfind list")(* this is supposed to list available syntaxes, but I don't know how to do it. *)letfind_syntaxes()=["camlp4o";"camlp4r"](* ocamlfind command *)letocamlfindx=S[A"ocamlfind";x];;letdisp_ocamlfind=beginfunction|Before_options->(* by using Before_options one let command line options have an higher priority *)(* on the contrary using After_options will guarantee to have the higher priority *)(* override default commands by ocamlfind ones *)(* Options.ocamlc := ocamlfind & A"ocamlc";*)Options.ocamlc:=ocamlfind&S[A"ocamlc";A"-verbose"];Options.ocamlopt:=ocamlfind&A"ocamlopt";Options.ocamldep:=ocamlfind&A"ocamldep"(* S[A"ocamldep"; A"-verbose"] *);Options.ocamldoc:=ocamlfind&A"ocamldoc";Options.ocamlmktop:=ocamlfind&A"ocamlmktop"|After_rules->(* When one link an OCaml library/binary/package, one should use -linkpkg *)flag["ocaml";"link"]&A"-linkpkg";(* For each ocamlfind package one inject the -package option when * compiling, computing dependencies, generating documentation and * linking. *)List.iterbeginfunpkg->flag["ocaml";"compile";"pkg_"^pkg]&S[A"-package";Apkg];flag["ocaml";"ocamldep";"pkg_"^pkg]&S[A"-package";Apkg];flag["ocaml";"doc";"pkg_"^pkg]&S[A"-package";Apkg];flag["ocaml";"link";"pkg_"^pkg]&S[A"-package";Apkg];flag["ocaml";"infer_interface";"pkg_"^pkg]&S[A"-package";Apkg];end(find_packages());(* Like -package but for extensions syntax. Morover -syntax is useless * when linking. *)List.iterbeginfunsyntax->flag["ocaml";"compile";"syntax_"^syntax]&S[A"-syntax";Asyntax];flag["ocaml";"ocamldep";"syntax_"^syntax]&S[A"-syntax";Asyntax];flag["ocaml";"doc";"syntax_"^syntax]&S[A"-syntax";Asyntax];flag["ocaml";"infer_interface";"syntax_"^syntax]&S[A"-syntax";Asyntax];end(find_syntaxes());(* The default "thread" tag is not compatible with ocamlfind. Indeed, the default rules add the "threads.cma" or "threads.cmxa" options when using this tag. When using the "-linkpkg" option with ocamlfind, this module will then be added twice on the command line. To solve this, one approach is to add the "-thread" option when using the "threads" package using the previous plugin. *)flag["ocaml";"pkg_threads";"compile"](S[A"-thread"]);flag["ocaml";"pkg_threads";"link"](S[A"-thread"]);flag["ocaml";"pkg_threads";"infer_interface"](S[A"-thread"])|_->()end(**********************)(*List.iter begin fun class_name -> flag ["ocaml"; "pp"; "classes"^class_name] (S[A"-classes"; A class_name])end ["Show"; "Typeable"];;*)letlibdir=!Ocamlbuild_pack.Ocamlbuild_where.libdir;;(*Printf.printf "%!\n\n\nlibdir: %S\n\n\n%!" !Ocamlbuild_pack.Ocamlbuild_where.libdir !libdir !Ocamlbuild_where.libdir !Myocamlbuild_config.libdir !Ocamlbuild_Myocamlbuild_config.libdir*)letstdlib_dir=Ocamlbuild_pack.Ocaml_utils.stdlib_dir;;letstr_replace_charstrcfromcto=letstr=String.copystrinlet()=fori=0toString.lengthstr-1do(ifstr.[i]=cfromthenstr.[i]<-ctoelse())doneinstr;;letdisp_deriving=(function|After_rules->letstdlib_dir=Lazy.forcestdlib_dirinletsyn_dir=stdlib_dir/"deriving"/"syntax"in(* let syn_dir = if Sys.os_type = "Win32" then str_replace_char syn_dir '/' '\\' else syn_dir in*)(flag["ocaml";"pp";"deriving"](S[A"-I";P(syn_dir);S(List.map(funm->A(m^".cmo"))["utils";"type";"base";"id";"extend";"show_class"])]);flag["ocaml";"compile";"deriving"](S[A"-I";P("+deriving"/"lib")]);flag["ocaml";"link";"deriving";"byte"](S[A"-I";P("+deriving"/"lib");A"deriving.cma"]);flag["ocaml";"link";"deriving";"native"](S[A"-I";P("+deriving"/"lib");A"deriving.cmxa"]))|_->());;dispatch(funx->(disp_ocamlfindx;disp_derivingx));;