(env
 (dev
  (flags
   (:standard -w -3))))

(generate_sites_module
 (module sites)
 (sites camomile))

(include_subdirs unqualified)

(rule
 (target configImpl.ml)
 (action
  (copy configImpl.%{env:CAMOMILE_CONFIG=dune}.ml %{target})))

(rule
 (target configImpl.env.ml)
 (deps configImpl.env.ml.in)
 (action
  (with-stdout-to
   %{target}
   (progn
    (echo "let prefix = \"%{env:CAMOMILE_PREFIX=/usr}/share/camomile\"\n")
    (cat configImpl.env.ml.in)))))

(rule
 (target script_type.ml)
 (deps tools/gen_unidata.exe unidata/Scripts.txt)
 (action
  (with-stdout-to
   %{target}
   (run tools/gen_unidata.exe --gen-script-type unidata/Scripts.txt))))

(rule
 (target version_type.ml)
 (deps tools/gen_unidata.exe unidata/DerivedAge.txt)
 (action
  (with-stdout-to
   %{target}
   (run tools/gen_unidata.exe --gen-version-type unidata/DerivedAge.txt))))

; -b 0 emits one string literal per file instead of 4096-byte chunks: read
; returns the literal itself and the data stays demand-paged from the
; executable, rather than being faulted in wholesale by the GC's root scan.

(rule
 (target camomile_embedded_data.ml)
 (deps
  (glob_files database/*.mar)
  (glob_files charmaps/*.mar)
  (glob_files locales/*.mar)
  (glob_files mappings/*.mar))
 (action
  (run %{bin:ocaml-crunch} -m plain -b 0 -e mar -o %{target} .)))

(rule
 (target camomile_embedded_charmaps_data.ml)
 (deps
  (glob_files charmaps/*.mar))
 (action
  (run %{bin:ocaml-crunch} -m plain -b 0 -e mar -o %{target} charmaps)))

(rule
 (target camomile_embedded_unimaps_data.ml)
 (deps
  (glob_files mappings/*.mar))
 (action
  (run %{bin:ocaml-crunch} -m plain -b 0 -e mar -o %{target} mappings)))

(library
 (name camomileLib)
 (public_name camomile.lib)
 (libraries bigarray camlp-streams)
 (modules
  :standard
  \
  camomile
  camomile_embedded_data
  camomile_embedded_charmaps_data
  camomile_embedded_unimaps_data
  configImpl
  sites))

(library
 (name camomile)
 (public_name camomile)
 (libraries camomileLib dune-site)
 (modules camomile configImpl sites))
