(* OASIS_START *)
(* OASIS_STOP *)

let dispatch = function
  | After_rules ->
    let env = BaseEnvLight.load () in
    let system = BaseEnvLight.var_get "system" env in
    let is_darwin = String.is_prefix "macos" system in
    let arch_sixtyfour = BaseEnvLight.var_get "arch_sixtyfour" env = "true" in

    let cpp = "gcc -E -xc -undef -w" in
    let cpp = if arch_sixtyfour then cpp ^ " -DARCH_SIXTYFOUR" else cpp in

    let cpp = S [A "-pp"; P cpp] in

    dep ["ocaml"; "ocamldep"; "mlh"] ["lib/int_codes.mlh"];

    flag ["ocamldep"; "ocaml"; "use_pa_bin_prot"]
      (S [A "-ppopt"; P "syntax/pa_bin_prot.cma"]);

    flag ["compile"; "ocaml"; "use_pa_bin_prot"]
      (S [A "-ppopt"; P "syntax/pa_bin_prot.cma"]);

    flag ["ocamldep"; "ocaml"; "cpp"] cpp;

    flag ["compile"; "ocaml"; "cpp"] cpp;

    flag ["doc"; "ocaml"; "cpp"] cpp;

    if is_darwin then
      flag ["compile"; "c"] (S [A "-ccopt"; A "-DOS_DARWIN"]);
  | _ ->
    ()

let () = Ocamlbuild_plugin.dispatch (fun hook -> dispatch hook; dispatch_default hook)

(* OASIS_START *)
(* OASIS_STOP *)

let dispatch = function
  | After_rules ->
    let env = BaseEnvLight.load () in
    let system = BaseEnvLight.var_get "system" env in
    let cc = BaseEnvLight.var_get "ccomp_type" env in
    let is_darwin = String.is_prefix "macos" system in
    let arch_sixtyfour = BaseEnvLight.var_get "arch_sixtyfour" env = "true" in

    let cpp = cc ^ " -E -xc -undef -w" in
    let cpp = if arch_sixtyfour then cpp ^ " -DARCH_SIXTYFOUR" else cpp in

    let cpp = S [A "-pp"; P cpp] in

    dep ["ocaml"; "ocamldep"; "mlh"] ["lib/int_codes.mlh"];

    flag ["ocamldep"; "ocaml"; "use_pa_bin_prot"]
      (S [A "-ppopt"; P "syntax/pa_bin_prot.cma"]);

    flag ["compile"; "ocaml"; "use_pa_bin_prot"]
      (S [A "-ppopt"; P "syntax/pa_bin_prot.cma"]);

    flag ["ocamldep"; "ocaml"; "cpp"] cpp;

    flag ["compile"; "ocaml"; "cpp"] cpp;

    flag ["doc"; "ocaml"; "cpp"] cpp;

    if is_darwin then
      flag ["compile"; "c"] (S [A "-ccopt"; A "-DOS_DARWIN"]);
  | _ ->
    ()

let () = Ocamlbuild_plugin.dispatch (fun hook -> dispatch hook; dispatch_default hook)

Use ccomp_type to determine C compiler
build: Use ccomp_type to determine C compiler

This library did not build properly on FreeBSD because of the hard-coded
C compiler in myocamlbuild.ml. The file now checks ccomp_type to
determine the C compiler to use, which should make the library more
portable.

Tested on FreeBSD 10.0.

Closes #6
