(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_COMMENT
  --unused-token
  PP_DEF
  --unused-token
  PP_DEFINE
  --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_INCLUDE_EXTRA
  --unused-token
  PP_INCLUDE
  --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 version = version ^ (if not is_snapshot then \"\" else (match git_sha with None -> \"+dev\" | Some sha -> \"+git@\" ^ sha))\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))
 (libraries liquidsoap-lang.console dune-site str unix menhirLib)
 (modules
  active_value
  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_ref
  doc
  environment
  error
  evaluation
  extralib
  ground_type
  hooks
  json_base
  json_lexer
  json_parser
  json
  lang
  lang_core
  lang_error
  lang_regexp
  lang_string
  lexer
  methods
  modules
  parser
  parser_helper
  pos
  plug
  preprocessor
  profiler
  repr
  ref_type
  regexp
  runtime
  runtime_error
  sites
  startup
  term
  type
  type_base
  typechecking
  typing
  unifier
  utils
  value))
