You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 line
3.3 KiB

  1. %% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
  2. %% ex: ts=4 sw=4 et
  3. %% -------------------------------------------------------------------
  4. %%
  5. %% rebar: Erlang Build Tools
  6. %%
  7. %% Copyright (c) 2009 Dave Smith (dizzyd@dizzyd.com),
  8. %% Tim Dysinger (tim@dysinger.net)
  9. %%
  10. %% Permission is hereby granted, free of charge, to any person obtaining a copy
  11. %% of this software and associated documentation files (the "Software"), to deal
  12. %% in the Software without restriction, including without limitation the rights
  13. %% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. %% copies of the Software, and to permit persons to whom the Software is
  15. %% furnished to do so, subject to the following conditions:
  16. %%
  17. %% The above copyright notice and this permission notice shall be included in
  18. %% all copies or substantial portions of the Software.
  19. %%
  20. %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. %% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. %% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. %% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. %% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. %% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. %% THE SOFTWARE.
  27. %% -------------------------------------------------------------------
  28. -module(rebar_lfe_compiler).
  29. -export([compile/2]).
  30. %% for internal use only
  31. -export([info/2]).
  32. -include("rebar.hrl").
  33. %% ===================================================================
  34. %% Public API
  35. %% ===================================================================
  36. compile(Config, _AppFile) ->
  37. FirstFiles = rebar_config:get_list(Config, lfe_first_files, []),
  38. rebar_base_compiler:run(Config, FirstFiles, "src", ".lfe", "ebin", ".beam",
  39. fun compile_lfe/3).
  40. %% ===================================================================
  41. %% Internal functions
  42. %% ===================================================================
  43. info(help, compile) ->
  44. ?CONSOLE(
  45. "Build Lisp Flavoured Erlang (*.lfe) sources.~n"
  46. "~n"
  47. "Valid rebar.config options:~n"
  48. " erl_opts is reused.'~n",
  49. []).
  50. compile_lfe(Source, _Target, Config) ->
  51. case code:which(lfe_comp) of
  52. non_existing ->
  53. ?ERROR("~n"
  54. "*** MISSING LFE COMPILER ***~n"
  55. " You must do one of the following:~n"
  56. " a) Install LFE globally in your erl libs~n"
  57. " b) Add LFE as a dep for your project, eg:~n"
  58. " {lfe, \"0.6.1\",~n"
  59. " {git, \"git://github.com/rvirding/lfe\",~n"
  60. " {tag, \"v0.6.1\"}}}~n"
  61. "~n", []),
  62. ?FAIL;
  63. _ ->
  64. ErlOpts = rebar_utils:erl_opts(Config),
  65. Opts = [{i, "include"}, {outdir, "ebin"}, return] ++ ErlOpts,
  66. case lfe_comp:file(Source, Opts) of
  67. {ok, _Mod, Ws} ->
  68. rebar_base_compiler:ok_tuple(Config, Source, Ws);
  69. {error, Es, Ws} ->
  70. rebar_base_compiler:error_tuple(Config, Source,
  71. Es, Ws, Opts);
  72. _ ->
  73. ?FAIL
  74. end
  75. end.