jsx/priv/jsx

68 lines
1.8 KiB
Text
Raw Normal View History

2010-06-07 17:21:04 -07:00
#!/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)
; ["install"|Opts] -> install(Opts)
; ["uninstall"|Opts] -> uninstall(Opts)
2010-06-07 17:21:04 -07:00
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") ].
install([]) ->
os:cmd("mkdir -p " ++ appdir()),
os:cmd("cp -r " ++ "ebin " ++ appdir()).
uninstall([]) ->
os:cmd("rm -rf " ++ appdir()).
appdir() ->
{ok, [{application, jsx, AppInfo}]} = file:consult("ebin/jsx.app"),
code:lib_dir() ++ "/jsx-" ++ proplists:get_value(vsn, AppInfo).
2010-06-07 17:21:04 -07:00