2012-10-14 13:08:15 -04:00
|
|
|
#!/usr/bin/env escript
|
|
|
|
-export([main/1]).
|
|
|
|
|
|
|
|
main([FileName]) ->
|
2014-03-05 13:44:43 -05:00
|
|
|
LibDirs = (["ebin", "include", "src", "test"] ++
|
2014-03-05 13:20:29 -05:00
|
|
|
filelib:wildcard("{apps,deps,lib}/*/{ebin,include}")),
|
2013-04-18 11:07:15 -04:00
|
|
|
compile(FileName, LibDirs);
|
2013-08-06 11:25:29 -04:00
|
|
|
|
2014-03-05 11:36:36 -05:00
|
|
|
main([FileName, "-rebar", Path, LibDirs]) ->
|
2013-08-06 11:25:29 -04:00
|
|
|
{ok, L} = file:consult(Path),
|
|
|
|
P = dict:from_list(L),
|
|
|
|
Root = filename:dirname(Path),
|
|
|
|
|
|
|
|
Lib1 = case dict:find(lib_dirs, P) of
|
|
|
|
{ok, X} -> lists:map(fun(Sub) -> Root ++ "/" ++ Sub end, X);
|
|
|
|
_ -> []
|
|
|
|
end,
|
|
|
|
|
|
|
|
Lib2 = case dict:find(sub_dirs, P) of
|
|
|
|
{ok, Y} -> lists:foldl(
|
|
|
|
fun(Sub,Sofar) ->
|
|
|
|
Sofar ++ [
|
|
|
|
Root ++ "/" ++ Sub,
|
|
|
|
Root ++ "/" ++ Sub ++ "/include",
|
|
|
|
Root ++ "/" ++ Sub ++ "/deps",
|
|
|
|
Root ++ "/" ++ Sub ++ "/lib"
|
|
|
|
] end, [], Y);
|
|
|
|
_ -> []
|
|
|
|
end,
|
|
|
|
|
|
|
|
LibDirs1 = LibDirs ++ Lib1 ++ Lib2,
|
|
|
|
%io:format("~p~n", [LibDirs1]),
|
|
|
|
compile(FileName, LibDirs1);
|
|
|
|
|
2014-03-05 11:36:36 -05:00
|
|
|
main([FileName, LibDirs]) ->
|
2013-04-18 11:07:15 -04:00
|
|
|
compile(FileName, LibDirs).
|
|
|
|
|
|
|
|
compile(FileName, LibDirs) ->
|
|
|
|
Root = get_root(filename:dirname(FileName)),
|
|
|
|
ok = code:add_pathsa(LibDirs),
|
2014-03-05 13:20:29 -05:00
|
|
|
compile:file(FileName,
|
|
|
|
[warn_obsolete_guard,
|
|
|
|
warn_unused_import,
|
|
|
|
warn_shadow_vars,
|
|
|
|
warn_export_vars,
|
|
|
|
strong_validation,
|
|
|
|
report] ++
|
2014-09-01 10:53:16 -04:00
|
|
|
[{i, filename:join(Root, I)} || I <- LibDirs] ++
|
|
|
|
case lists:member("deps/pmod_transform/include", LibDirs) of
|
|
|
|
true -> [{parse_transform, pmod_pt}];
|
|
|
|
_ -> []
|
|
|
|
end
|
|
|
|
).
|
2013-04-18 11:07:15 -04:00
|
|
|
|
|
|
|
get_root(Dir) ->
|
|
|
|
Path = filename:split(filename:absname(Dir)),
|
|
|
|
filename:join(get_root(lists:reverse(Path), Path)).
|
|
|
|
|
|
|
|
get_root([], Path) ->
|
|
|
|
Path;
|
|
|
|
get_root(["src" | Tail], _Path) ->
|
|
|
|
lists:reverse(Tail);
|
2013-09-12 02:29:13 -04:00
|
|
|
get_root(["test" | Tail], _Path) ->
|
|
|
|
lists:reverse(Tail);
|
2013-04-18 11:07:15 -04:00
|
|
|
get_root([_ | Tail], Path) ->
|
|
|
|
get_root(Tail, Path).
|