diff --git a/makefile b/makefile new file mode 100644 index 0000000..d01d450 --- /dev/null +++ b/makefile @@ -0,0 +1,13 @@ +compile: + ./priv/jsx compile + +test: force + ./priv/jsx test + +examples: force + ./priv/jsx examples + +clean: + ./priv/jsx clean + +force: \ No newline at end of file diff --git a/priv/.DS_Store b/priv/.DS_Store new file mode 100644 index 0000000..6a25882 Binary files /dev/null and b/priv/.DS_Store differ diff --git a/priv/jsx b/priv/jsx new file mode 100755 index 0000000..b1b2136 --- /dev/null +++ b/priv/jsx @@ -0,0 +1,55 @@ +#!/usr/bin/env escript + +main(Args) -> + case Args of + ["compile"|Opts] -> compile(Opts) + ; ["examples"|Opts] -> examples(Opts) + ; ["test"|Opts] -> test(Opts) + ; ["clean"|Opts] -> clean(Opts) + end. + +compile([]) -> + Mods = ["src/jsx"], + compile_files(Mods, [{outdir, "ebin"}]), + compile_backend(). + +compile_files([], _) -> + ok; +compile_files([FileName|Rest], Opts) -> + case compile:file(FileName, Opts) of + {ok, _} -> ok + ; {ok, Name, Bin} -> file:write_file("ebin/" ++ atom_to_list(Name) ++ ".beam", Bin), ok + end, + compile_files(Rest, Opts). + +compile_backend() -> + [ compile_files(["src/jsx_decoder"], [binary, {d, Backend}, {d, name, to_modname(Backend)}]) + || Backend <- [utf8, utf16, utf16le, utf32, utf32le] + ]. + +to_modname(Atom) -> + list_to_atom("jsx_" ++ atom_to_list(Atom)). + + +examples([]) -> + Mods = ["examples/jsx_prettify", + "examples/jsx_parser", + "examples/jsx_stream_parser", + "examples/jsx_verify" + ], + compile_files(Mods, [{outdir, "ebin"}]). + +test(Path) -> + Mods = ["test/jsx_test"], + compile_files(Mods, [{outdir, "ebin"}]), + true = code:add_path("ebin"), + case Path of + [] -> jsx_test:test("test/cases") + ; Path -> jsx_test:test(Path) + end. + +clean([]) -> + [ file:delete(Filename) || Filename <- filelib:wildcard("ebin/*.beam") ]. + + + \ No newline at end of file