On 09-07-2009, Dario Teixeira <darioteixeira@...> wrote:
>
> Hi,
>
> Is there a syntax extension that allows a string to be assigned the content=
> s
> of a file? So instead of doing
>
> let str =3D "very long string"
>
> one would just
>
> let str =3D #include "file.txt" (* or something like this *)
>
> where file.txt would contain a "very long string". I've looked in the
> Hump,
> but there doesn't seem to be anything that matches this description. Also,
> I know the same functionality can be implemented via the C-interface by
> linking in a binary object, but that's overkill for my purposes.
>
There is a small utility call ocamlify:
https://forge.ocamlcore.org/projects/ocamlify/
http://darcs.ocamlcore.org/repos/ocamlify/ocamlify/ (darcs repository)
You should look at ocaml-autobuild that use it extensively to include
files in the exec:
http://darcs.ocamlcore.org/repos/ocaml-autobuild/ocaml-autobuild/src/base/BaseDa\
ta.mlify
with the following rules in ocamlbuild:
let ocamlify = A"ocamlify";;
rule "ocamlify: %.mlify -> %.mlify.depends"
~prod:"%.mlify.depends"
~dep:"%.mlify"
begin
fun env _ ->
Cmd(S[ocamlify;
T(tags_of_pathname (env "%.mlify")++"ocamlify"++"depends");
A"--depends";
A"--output"; P(env "%.mlify.depends");
P(env "%.mlify");])
end
;;
rule "ocamlify: %.mlify & %.mlify.depends -> %.ml"
~prod:"%.ml"
~deps:["%.mlify"; "%.mlify.depends"]
begin
fun env build ->
depends_from_file
env
build
(env "%.mlify.depends");
Cmd(S[ocamlify; A"--output"; P(env "%.ml"); P(env "%.mlify")])
end
;;
This allow to create a .ml file containing the various file you want to
include as string or string list.
There is no release for now, as the project is tightly coupled with
ocaml-autobuild which is not yet released.
Regards,
Sylvain Le Gall