mad_erl.erl 1.0 KB

123456789101112131415161718192021222324252627
  1. -module(mad_erl).
  2. -copyright('Sina Samavati').
  3. -compile(export_all).
  4. -define(COMPILE_OPTS(Inc, Ebin, Opts, Deps), [return_errors, return_warnings, {i, [Inc]}, {outdir, Ebin}] ++ Opts++Deps).
  5. erl_to_beam(Bin, F) -> filename:join(Bin, filename:basename(F, ".erl") ++ ".beam").
  6. compile(File,Inc,Bin,Opt,Deps) ->
  7. BeamFile = erl_to_beam(Bin, File),
  8. Compiled = mad_compile:is_compiled(BeamFile, File),
  9. if Compiled =:= false ->
  10. Opts1 = ?COMPILE_OPTS(Inc, Bin, Opt, Deps),
  11. mad:info("Compiling ~s~n", [File -- mad_utils:cwd()]),
  12. ret(compile:file(File, Opts1));
  13. true -> false end.
  14. ret(error) -> true;
  15. ret({error,X}) -> lines(error,X);
  16. ret({error,X,_}) -> lines(error,X);
  17. ret({ok,_}) -> false;
  18. ret({ok,_,[]}) -> false;
  19. ret({ok,_,X}) -> lines(warning,X), false;
  20. ret({ok,_,X,_}) -> lines(warning,X), false.
  21. lines(Tag,X) ->
  22. S=case file:get_cwd() of {ok,Cwd} -> length(Cwd); _ -> 0 end,
  23. [[ mad:info("Line ~p: ~p ~p in ~p~n",[ L,Tag,R,lists:nthtail(S,F) ]) || {L,_,R} <- E ] || {F,E} <- X ], true.