(env
 (release
  (ocamlopt_flags
   (:standard -O2)))
 (dev
  (flags
   (:standard -w -9))))

(include_subdirs unqualified)

(generate_sites_module
 (module sites)
 (sites liquidsoap-lang))

(menhir
 (modules parser json_parser)
 (flags
  --unused-token
  DOTVAR
  --unused-token
  PP_ELSE
  --unused-token
  PP_ENDIF
  --unused-token
  PP_ENDL
  --unused-token
  PP_IFDEF
  --unused-token
  PP_IFENCODER
  --unused-token
  PP_IFNDEF
  --unused-token
  PP_IFNENCODER
  --unused-token
  PP_IFVERSION
  --unused-token
  PP_INT_DOT_LCUR
  --unused-token
  PP_REGEXP
  --unused-token
  PP_STRING
  --unused-token
  REPLACES
  --unused-token
  SLASH))

(rule
 (target build_config.ml)
 (action
  (with-stdout-to
   %{target}
   (progn
    (echo "let is_snapshot = %{env:IS_SNAPSHOT=true}\n")
    (echo "let version = \"%{version:liquidsoap-lang}\"\n")
    (echo "let version_len = String.length version\n")
    (echo "let parsed_sha = String.trim \"")
    (with-accepted-exit-codes
     (or 0 128)
     (run git rev-parse --short HEAD))
    (echo "\"\n")
    (echo "let parsed_sha_len = String.length parsed_sha\n")
    (echo "let dune_sha_len = 7\n")
    (echo "let git_sha = match is_snapshot, parsed_sha with \n")
    (echo "  | false, _ | _, \"\" -> None\n")
    (echo
     "  | _, _ when dune_sha_len <= version_len && dune_sha_len <= parsed_sha_len && String.sub parsed_sha 0 dune_sha_len = String.sub version (version_len - dune_sha_len) dune_sha_len -> None\n")
    (echo "  |  _, s -> Some s\n")
    (echo
     "let git_sha = match Sys.getenv_opt \"LIQ_GIT_SHA\" with None -> git_sha | Some v -> Some v \n")
    (echo
     "let version = version ^ (if not is_snapshot then \"\" else (match git_sha with None -> \"+dev\" | Some sha -> \"+git@\" ^ sha))\n")
    (echo
     "let version = match Sys.getenv_opt \"LIQ_VERSION\" with None -> version | Some v -> v \n")
    (echo "let ext_exe = \"%{ocaml-config:ext_exe}\"\n")
    (echo "let architecture = \"%{ocaml-config:architecture}\"\n")
    (echo "let host = \"%{ocaml-config:host}\"\n")
    (echo "let target = \"%{ocaml-config:target}\"\n")
    (echo "let system = \"%{ocaml-config:system}\"\n")
    (echo "let ocamlopt_cflags = \"%{ocaml-config:ocamlopt_cflags}\"\n")
    (echo "let native_c_compiler = \"%{ocaml-config:native_c_compiler}\"\n")
    (echo
     "let native_c_libraries = \"%{ocaml-config:native_c_libraries}\"\n")))))

(library
 (name liquidsoap_lang)
 (public_name liquidsoap-lang)
 (preprocess
  (pps sedlex.ppx ppx_string ppx_hash))
 (libraries
  liquidsoap-lang.console
  dune-site
  re
  str
  unix
  menhirLib
  xml-light
  (select
   liqmemtrace.ml
   from
   (memtrace -> liqmemtrace.memtrace.ml)
   (-> liqmemtrace.disabled.ml)))
 (modules
  build_config
  builtins_bool
  builtins_eval
  builtins_getter
  builtins_json
  builtins_lang
  builtins_list
  builtins_math
  builtins_null
  builtins_profiler
  builtins_regexp
  builtins_string
  builtins_yaml
  builtins_xml
  builtins_ref
  cache
  doc
  environment
  error
  evaluation
  extralib
  flags
  hooks
  json_base
  json_lexer
  json_parser
  json
  lang
  lang_core
  lang_error
  lang_eval
  lang_regexp
  lang_string
  lexer
  liqmemtrace
  methods
  modules
  parsed_term
  parser
  parser_helper
  pos
  plug
  preprocessor
  profiler
  repr
  ref_type
  runtime
  runtime_error
  runtime_term
  sites
  startup
  term
  term_base
  term_cache
  term_custom
  term_hash
  term_preprocessor
  term_reducer
  term_stdlib
  term_trim
  type
  type_base
  type_constraints
  type_custom
  typechecking
  typing
  unifier
  utils
  value))
