Browse Source

compile ports

Maxim Sokhatsky 10 years ago
parent
commit
0ee75e4ddc
5 changed files with 27 additions and 3 deletions
  1. BIN
      mad
  2. 1 1
      otp.mk
  3. 1 1
      rebar.config
  4. 1 1
      src/mad.app.src
  5. 24 0
      src/mad_compile.erl

BIN
mad


+ 1 - 1
otp.mk

@@ -1,6 +1,6 @@
 compile: get-deps
 get-deps compile clean:
-	./mad $@
+	rebar $@
 escript: compile
 	./build
 ct: get-deps compile

+ 1 - 1
rebar.config

@@ -1,3 +1,3 @@
 {cache,"~/.mad/repos"}.
 {deps_dir,"deps"}.
-{deps, []}.
+{deps, [{sh, ".*", {git, "git://github.com/synrc/sh", "HEAD"}}]}.

+ 1 - 1
src/mad.app.src

@@ -2,5 +2,5 @@
  [{description, "MAD VXZ Manage Deps"},
   {vsn, ""},
   {registered, []},
-  {applications, [kernel,stdlib]},
+  {applications, [kernel,stdlib,re]},
   {env, []}]}.

+ 24 - 0
src/mad_compile.erl

@@ -44,6 +44,7 @@ dep(Cwd, _Conf, ConfigFile, Name) ->
             lists:foreach(compile_fun(IncDir, EbinDir, Opts), Files),
 
             dtl(DepPath,Conf1),
+            port(DepPath,Conf1),
 
             put(Name, compiled),
             ok
@@ -55,6 +56,29 @@ dtl(Dir,Config) ->
         [] -> skip;
          X -> compile_erlydtl_files(validate_erlydtl_opts(Dir,X)) end.
 
+port(Dir,Config) ->
+    case mad_utils:get_value(port_specs, Config, []) of
+        [] -> skip;
+         X -> compile_port(Dir,X,Config) end.
+
+compile_port(Dir,Specs,Config) ->
+    {_,System} = os:type(),
+    Env = [ {Var,Val} || {System,Var,Val} <- mad_utils:get_value(port_env, Config, []) ],
+    [ begin 
+           Template = string:join(filelib:wildcard(Dir ++"/" ++ Files)," ") 
+              ++ " CFLAGS LDFLAGS -o " ++ Dir ++ "/" ++ Out,
+%       Template = string:join(filelib:wildcard(Files)," ") 
+%              ++ " CFLAGS LDFLAGS -o " ++ Out,
+       io:format("Template: ~p",[Template]),
+       Args = string:strip(replace_env(Template,Env),both,32),
+       io:format("Compile Port~n Dir: ~p, Files: ~p, Env: ~p",[Dir,Args,Env]),
+       Res = sh:run("cc",string:tokens(Args," "),binary,Dir,Env),
+       io:format("Compile Result: ~p",[Res])
+      end || {System,Out,Files} <- Specs].
+
+replace_env(String, []) -> String;
+replace_env(String, [{K,V}|Env]) ->
+   replace_env(re:replace(String, K, V, [global, {return, list}]),Env).
 
 validate_property({modules, _}, Modules) -> {modules, Modules};
 validate_property(Else, _) -> Else.