Skip to content

Instantly share code, notes, and snippets.

@uwiger
Created September 18, 2013 11:29
Show Gist options
  • Save uwiger/6607859 to your computer and use it in GitHub Desktop.
Save uwiger/6607859 to your computer and use it in GitHub Desktop.
%% -*- erlang -*-
Dep =
fun(A,Cs) ->
Key = "dep_" ++ A,
case [U || [K, U] <- Cs, K =:= Key] of
[] -> error({not_found, Key});
[URI] ->
{list_to_atom(A), ".*", {git,URI,"HEAD"}}
end
end.
Deps =
fun(Cfg, Cs) ->
case [Ds || ["DEPS"|Ds] <- Cs] of
[] -> Cfg;
[Deps1 | _] ->
lists:keystore(
deps, 1, Cfg, {deps, [Dep(A, Cs) || A <- Deps1]})
end
end.
FirstFiles =
fun(Cfg, Cs) ->
case [Fs || ["COMPILE_FIRST"|Fs] <- Cs] of
[] -> Cfg;
[Files | _] ->
lists:keystore(
erl_first_files, 1, Cfg,
{erl_first_files,
["src/" ++ F ++ ".erl" || F <- Files]})
end
end.
ErlOpts =
fun(Cfg, Cs) ->
case [Os || ["ERLC_OPTS"|Os] <- Cs] of
[] ->
Cfg;
[Opts|_] ->
Opts1 = lists:flatmap(
fun("+" ++ Opt) ->
[list_to_atom(Opt)];
("-Werror") -> [errors];
(_) -> []
end, lists:takewhile(
fun("#" ++ _) -> false;
(_) -> true
end, Opts)),
lists:keystore(erl_opts,1,Cfg, {erl_opts, Opts1})
end
end.
Commands =
fun(F) ->
case file:read_file(F) of
{ok, B} ->
Lines = re:split(B,"\\v",[{return,list}]),
[re:split(L, "[\\h\\?=]+", [{return,list}]) || L <- Lines];
_ -> []
end
end.
Cmds = Commands("Makefile"),
case [true || ["include", "erlang.mk"] <- Cmds] of
[] -> CONFIG;
[_ | _] ->
Cmds1 = Cmds ++ Commands("erlang.mk"),
CONFIG1 = ErlOpts(FirstFiles(Deps(CONFIG, Cmds1), Cmds1), Cmds1),
%% io:fwrite("CONFIG1 = ~p~n", [CONFIG1]),
CONFIG1
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment