(* -*- tuareg -*- *)

open StdLabels
open Jbuild_plugin.V1

let subdir, link_flags =
  match List.assoc "os_type" ocamlc_config with
  | "Win32" -> "win32", "-lkernel32 -lgdi32 -luser32"
| _ -> "unix", "-lX11"

let c_names =
  Sys.readdir subdir
  |> Array.to_list
  |> List.filter ~f:(fun fn ->
      Filename.check_suffix fn ".c")
  |> List.map ~f:Filename.chop_extension
  |> List.sort ~cmp:String.compare

let () =
  Printf.ksprintf send {|
(library
 (public_name graphics)
 (wrapped false)
 (c_names %s)
 (c_library_flags %s))

(copy_files# %s/*)
|}
    (String.concat c_names ~sep:" ")
    link_flags
    subdir
