(* -*- tuareg -*- *)

(**********************************************************************)
(*                                                                    *)
(*                            OCamlFormat                             *)
(*                                                                    *)
(*  Copyright (c) 2017-present, Facebook, Inc.  All rights reserved.  *)
(*                                                                    *)
(*  This source code is licensed under the MIT license found in the   *)
(*  LICENSE file in the root directory of this source tree.           *)
(*                                                                    *)
(**********************************************************************)

let ocamlc_flags =
  match Jbuild_plugin.V1.context with
  | "dbg" -> "-g -opaque"
  | _ -> "-noassert"

let ocamlopt_flags =
  match Jbuild_plugin.V1.context with
  | "dbg" -> ocamlc_flags ^ " -w -a"
  | _ -> ocamlc_flags ^ " -O3"

;; Jbuild_plugin.V1.send @@ Format.sprintf "
(rule
 ((targets (Version.ml))
  (action (run ../tools/gen_version.sh Version.ml))
  (fallback)
  (deps
   (${SCOPE_ROOT}/../../.git/index
    ${SCOPE_ROOT}/../../.git/HEAD
    (files_recursively_in ${SCOPE_ROOT}/../../.git/refs/heads)
    (files_recursively_in ${SCOPE_ROOT}/../../.git/refs/tags)))))

(executables
 ((names (ocamlformat ocamlformat_reason))
  (flags
   (-w +a-4-6-9-40-41-42-44-45-48@50
    -strict-formats -strict-sequence -principal
    -short-paths -bin-annot -keep-docs -unboxed-types
    -open Import))
  (ocamlc_flags (%s))
  (ocamlopt_flags (%s))
  (libraries (cmdliner ocamlformat_support import ocaml-migrate-parsetree unix))))

(install
 ((section bin)
  (files ((ocamlformat.exe as ocamlformat)))
  (package ocamlformat)))

(install
 ((section bin)
  (files ((ocamlformat_reason.exe as ocamlformat_reason)))
  (package ocamlformat_reason)))
"
ocamlc_flags ocamlopt_flags
