(include_subdirs unqualified)

(executable
 (name ocamlmerlin_server)
 (package merlin)
 (public_name ocamlmerlin-server)
 (flags
  :standard
  -open Ocaml_utils
  -open Ocaml_parsing
  -open Ocaml_typing
  -open Merlin_kernel
  -open Merlin_utils
  -open Merlin_analysis
  -open Merlin_kernel
  -open Merlin_commands)
 (libraries merlin-lib.config yojson merlin-lib.analysis merlin-lib.kernel
            merlin-lib.utils merlin-lib.os_ipc merlin-lib.ocaml_parsing
            merlin-lib.query_protocol merlin-lib.query_commands
            merlin-lib.ocaml_typing merlin-lib.ocaml_utils
            merlin-lib.commands
            unix str))

; Write one flag per line in the output file

(rule
 (enabled_if (= %{ocaml-config:ccomp_type} "cc"))
 (action
  (progn
   (write-file ldlibs "")
   (write-file outputexe "-o"))))

(rule
 (enabled_if (= %{ocaml-config:ccomp_type} "msvc"))
 (action
  (progn
   (write-file ldlibs "advapi32.lib")
   (write-file outputexe "-Fe"))))

(rule
 (enabled_if
  (and
   (= %{ocaml-config:ccomp_type} "cc")
   (= %{profile} "dev")))
 (action
  (write-file cflags "-Wextra\n-Werror")))

(rule
 (enabled_if
  (and
   (= %{ocaml-config:ccomp_type} "msvc")
   (= %{profile} "dev")))
 (action
  (write-file cflags "-WX")))

(rule
 (enabled_if
  (<> %{profile} "dev"))
 (action
  (write-file cflags "")))

(rule
 (target ocamlmerlin.exe)
 (deps   (:c ocamlmerlin.c))
 (action (run %{cc} %{read-strings:cflags} %{read:outputexe}%{target} %{c} %{read-strings:ldlibs})))

(install
 (package merlin)
 (section bin)
 (files   (ocamlmerlin.exe as ocamlmerlin)))
