Skip to content

Commit

Permalink
don't link when no need
Browse files Browse the repository at this point in the history
  • Loading branch information
mihawk committed Nov 23, 2016
1 parent 92e3632 commit 45143eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/compile/mad_port.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,40 @@ compile_port(Dir,Specs0,Config) ->
Env1 = [{"PORT_IN_FILES", F},{"PORT_OUT_FILE", Obj}] ++ Env ++ default_env(),
CmdCC = string:strip(expand(System,TplCC,Env1)),
Cmd = expand(System,CmdCC,[{"CXXFLAGS",""},{"LDFLAGS",""},{"CFLAGS",""}]),
mad:info("cc ~s~n",[Cmd]),
{_,Status,Report} = sh:run("cc",string:tokens(Cmd," "),binary,Dir,Env),
case Status of
0 -> {ok,Obj} ;
_ -> {error, "Port Compilation Error:~n" ++ io_lib:format("~ts",[Report])},true
end;
true -> {ok,Obj}
true -> {even,Obj}
end
end,

Res = lists:foldl(fun({ok,X},Acc) -> [X|Acc];
Res = lists:foldl(fun({ok,X},Acc) -> [{ok,X}|Acc];
({even,X},Acc) -> [{even,X}|Acc];
({error,Err},_)-> {error,Err}
end,[],[Compile(F) || F <- Files]),
case Res of
{error, _}=Err -> Err;
Objs -> Env2 = [{"PORT_IN_FILES", string:join(Objs," ")},

%%if any ok recompile target
case Res of {error,_} = Err -> Err; Res ->
case lists:any(fun({ok,_}) -> true;(_)->false end, Res) of
false -> false; %% all even, no need to link target
true -> Objs = [O||{_,O} <-Res],
Env2 = [{"PORT_IN_FILES", string:join(Objs," ")},
{"PORT_OUT_FILE", Target}] ++ Env ++ default_env(),
TplLD = tpl_ld(TargetType,LinkLang),
CmdLD = string:strip(expand(System,TplLD,Env2)),
Cmd = expand(System,CmdLD,[{"CXXFLAGS",""},{"LDFLAGS",""},{"CFLAGS",""}]),
mad:info("cc ~s~n",[Cmd]),
{_,Status,Report} = sh:run("cc",string:tokens(Cmd," "),binary,Dir,Env),
case Status of
0 -> false;
_ -> mad:info("Port Compilation Error:~n" ++ io_lib:format("~ts",[Report]),[]),
{error, Report},true
end
end
end
end,
[Job(S)||S<-Specs].

Expand Down
4 changes: 2 additions & 2 deletions src/provision/mad_repl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
-compile(export_all).

disabled() -> [].
system() -> [compiler,syntax_tools,sasl,tools,mnesia,reltool,xmerl,crypto,kernel,stdlib,ssh,eldap,
wx,ssl,runtime_tools,public_key,observer,inets,asn1,et,eunit,hipe,os_mon,parsetools,odbc,n2o].
system() -> [compiler,syntax_tools,sasl,tools,mnesia,reltool,xmerl,crypto,kernel,stdlib,ssh,eldap,erl_interface,
wx,ssl,runtime_tools,public_key,observer,inets,asn1,et,eunit,hipe,os_mon,parsetools,odbc].

local_app() ->
case filename:basename(filelib:wildcard("ebin/*.app"),".app") of
Expand Down

0 comments on commit 45143eb

Please sign in to comment.