In the book Joe describes building an Erlang project using make and most of the downloadable bits of Erlang code use make too; this makes sense, make is virtually ubiquitous. However the other components of this project are Ruby on Rails applications and make heavy use of Rake, so I figure why subject myself to Make when I can use the beautiful Rake.
Here is my Rakefile for building an Erlang project.
INCLUDE = "include"
ERLC_FLAGS = "-I +warn_unused_vars +warn_unused_import"
SRC = FileList['src/*.erl']
OBJ = SRC.pathmap("%{src,ebin}X.beam")
CLEAN.include("ebin/*.beam")
directory 'ebin'
rule ".beam" => ["%{ebin,src}X.erl"] do |t|
sh "erlc -pa ebin -W -o ebin "
end
task :compile => ['ebin'] + OBJ
task :default => :compile
This gives you
rake compile
which builds all the .erl
files in the src
subdirectory into the .beam
files in the ebin
directory. Files will only be built if they have changes since the last build. You also get rake clean
which deletes all the .beam
files from the ebin
directory.I much prefer this over the equivalent Makefile and it is much easier to extend since you have the full power of Ruby at your disposal.
Enjoy.
Update: Fixed bug when compile many files from after clean.
5 comments:
Sorry, but:
** Invoke compile (first_time)
** Invoke ebin (first_time, not_needed)
rake aborted!
Don't know how to build task 'ebin/shop1.beam ebin/shop.beam ebin/geom.beam'
Thanks for that. There was a bug in the compile dependencies that caused problems when builing many files after a clean. It should work now.
I fixed this a while ago but forgot to update my blog post so thanks for reminding me.
I have also used Rake with erlang.
Here is what I came up with when I need to rebuild eunit.
========================
require 'rake/clean'
CLOBBER.include 'ebin'
SRC_TO_BIN = [/src(\/.*\.)erl/,'ebin\1beam']
BIN_TO_SRC = [/ebin(\/.*\.)beam/,'src\1erl']
beams = ['ebin'] + FileList.new('src/*.erl').gsub(*SRC_TO_BIN)
task :default => beams
directory 'ebin'
rule(%r{^ebin/.*\.beam$} => lambda { |fn| fn.gsub(*BIN_TO_SRC) }) do |t|
`erlc -pa ebin -Iinclude +warn_unused_vars +nowarn_shadow_vars +warn_unused_import -oebin #{t.source}`
end
========================
-- Mike Berrow
Thanks for the Makefile!
Just a note (and for future readers), it works fine with rake 0.7.3, but didn't work for me with rake 0.7.1...
Post a Comment