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.