|
@@ -21,25 +21,40 @@ compile_port(Dir,Specs0,Config) ->
|
|
[ {Var,Val} || {Var,Val} <- mad_utils:get_value(port_env, Config, []) ] ++
|
|
[ {Var,Val} || {Var,Val} <- mad_utils:get_value(port_env, Config, []) ] ++
|
|
[ {"LDFLAGS",[]},{"CFLAGS",[]}],
|
|
[ {"LDFLAGS",[]},{"CFLAGS",[]}],
|
|
[ begin
|
|
[ begin
|
|
- Template = string:join(files(Dir,Files)," ")
|
|
|
|
- ++ " CFLAGS LDFLAGS " ++ ei() ++ " -o " ++ Dir ++ "/" ++ Out,
|
|
|
|
- Args = string:strip(replace_env(Template,Env),both,32),
|
|
|
|
- % mad:info("Args: ~p~n",[Args]),
|
|
|
|
- % mad:info("Env: ~p~n",[Env]),
|
|
|
|
- {_,Status,Report} = sh:run("cc",string:tokens(Args," "),binary,Dir,Env),
|
|
|
|
- case Status of
|
|
|
|
- 0 -> false;
|
|
|
|
- _ -> mad:info("Port Compilation Error:~n" ++ io_lib:format("~ts",[Report]),[]), true end
|
|
|
|
- end || {Out,Files} <- Specs ].
|
|
|
|
|
|
+ Files = files(Dir,Patern),
|
|
|
|
+ Ouput = Dir ++ "/" ++ Out,
|
|
|
|
+ case is_compiled(Ouput,Files) of
|
|
|
|
+ false -> Template = string:join(Files," ")
|
|
|
|
+ ++ " CFLAGS LDFLAGS " ++ ei(Flavour,Out) ++ " -o " ++ Ouput,
|
|
|
|
+ Args = string:strip(replace_env(Template,Env),both,32),
|
|
|
|
+ %mad:info("Args: ~p~n",[Args]),
|
|
|
|
+ %mad:info("Env: ~p~n",[Env]),
|
|
|
|
+ {_,Status,Report} = sh:run("cc",string:tokens(Args," "),binary,Dir,Env),
|
|
|
|
+ case Status of
|
|
|
|
+ 0 -> false;
|
|
|
|
+ _ -> mad:info("Port Compilation Error:~n" ++ io_lib:format("~ts",[Report]),[]), true
|
|
|
|
+ end;
|
|
|
|
+ _ -> %mad:info("No Need recompile ~p~n",[{Ouput,Files}]),
|
|
|
|
+ false
|
|
|
|
+ end
|
|
|
|
+ end || {Out,Patern} <- Specs ].
|
|
|
|
|
|
|
|
+is_compiled(O,Files) -> lists:foldl(fun(X,false) -> false;
|
|
|
|
+ (X,true) -> mad_utils:last_modified(O) >= mad_utils:last_modified(X)
|
|
|
|
+ end, true, Files).
|
|
system(Sys,System) -> Sys == System orelse match(Sys,System).
|
|
system(Sys,System) -> Sys == System orelse match(Sys,System).
|
|
match(Re,System) -> case re:run(System, Re, [{capture,none}]) of match -> true; nomatch -> false end.
|
|
match(Re,System) -> case re:run(System, Re, [{capture,none}]) of match -> true; nomatch -> false end.
|
|
erts_dir() -> lists:concat([code:root_dir(), "/erts-", erlang:system_info(version)]).
|
|
erts_dir() -> lists:concat([code:root_dir(), "/erts-", erlang:system_info(version)]).
|
|
-ei_dir() -> code:lib_dir(erl_interface).
|
|
|
|
|
|
+ei_dir(inc) -> case code:lib_dir(erl_interface) of {error,bad_name} -> ""; D -> "-I"++D++"/include " end;
|
|
|
|
+ei_dir(lib) -> case code:lib_dir(erl_interface) of {error,bad_name} -> ""; D -> "-L"++D++"/lib " end.
|
|
files(Dir,Files) -> [string:join(filelib:wildcard(Dir ++ "/" ++ F)," ")||F<-Files].
|
|
files(Dir,Files) -> [string:join(filelib:wildcard(Dir ++ "/" ++ F)," ")||F<-Files].
|
|
-ei() -> "-bundle -flat_namespace -undefined suppress " %% for linking phase
|
|
|
|
- "-I"++ei_dir()++"/include "
|
|
|
|
|
|
+ei(Flavour,Out) -> type(Flavour,Out)
|
|
|
|
+ ++ ei_dir(inc) ++
|
|
"-I"++erts_dir()++"/include "
|
|
"-I"++erts_dir()++"/include "
|
|
- "-L"++ei_dir()++"/lib "
|
|
|
|
|
|
+ ++ ei_dir(lib) ++
|
|
"-L"++erts_dir()++"/lib ".
|
|
"-L"++erts_dir()++"/lib ".
|
|
-
|
|
|
|
|
|
+type(Flavour,Out) -> case {Flavour, filename:extension(Out)} of %% exe or shared
|
|
|
|
+ {_, []} -> "";
|
|
|
|
+ {darwin, ".so"} -> "-bundle -flat_namespace -undefined suppress "
|
|
|
|
+ end.
|
|
|
|
+
|