(* -*- tuareg -*- *)

let library_entry name suffix =
  Printf.sprintf
"(library
  (name %s)
  (wrapped false)
  (modules)
  (libraries %s_%s))" name name suffix

let fb_entry name =
  library_entry name "fb"

let stubs_entry name =
  library_entry name "stubs"

let entry is_fb name =
  if is_fb then
    fb_entry name
  else
    stubs_entry name

let () =
  (* test presence of fb subfolder *)
  let current_dir = Sys.getcwd () in
  (* we are in src/hack_forked/utils/logging/common, locate src/facebook *)
  let src_dir = Filename.(dirname @@ dirname @@ dirname @@ dirname current_dir) in
  let fb_dir = Filename.concat src_dir "facebook" in
  (* locate src/facebook/dune *)
  let fb_dune = Filename.concat fb_dir "dune" in
  let is_fb = Sys.file_exists fb_dune in
  let logging_common = entry is_fb "logging_common" in
  Jbuild_plugin.V1.send logging_common
