Smarter Erlang Programming with Emakefile Options and user_default

Say you’ve got an Erlang app with the standard file system layout, with your source code in src/ and your compiled code in ebin/. I’ve found this makes using the interactive shell interpreter a little harder.
Lets use the Emakefile that Erlang supports to let us recompile and reload our code on the fly.
Create a file called Emakefile, and put the below line in it. There’s other options, but this keeps things simple.
Say you’ve got an Erlang app with the standard file system layout, with your source code in src/ and your compiled code in ebin/. I’ve found this makes using the interactive shell interpreter a little harder.
Lets use the Emakefile that Erlang supports to let us recompile and reload our code on the fly.
Create a file called Emakefile, and put the below line in it. There’s other options, but this keeps things simple.
{"src/*", [report, verbose, {i, "include"}, {outdir, "ebin"}] }.
Now you can recompile & load everything like this:
1> make:all([load]).
But as far as I can tell, it won’t see your ebin directory. Keep reading.
Lets kick it up a notch. Typing make:all([load]) is obnoxious - lets use the power of user_default as written below.
http://medevyoujane.com/blog/2010/1/3/erlang-quick-tip-the-user_default-module.html
I wasn’t able to get the user_default module to work unless I specifically loaded it as follows:
code:load_abs("/Users/jhaddad/ebin/user_default").
(Found on http://amiest-devblog.blogspot.com/2008/01/reloading-all-code-from-erlang-shell_16.html)
Here’s all I have in there - I really just needed r() to work to reload everything.
-module(user_default).
-compile(export_all).
r( ) ->
make:all( [load] ).
I’ve been told there’s a reloader script in mochiweb that will auto load everything for you - that’ll be the subject of a later blog post. (edit: finally wrote the autoloader how to)
References
-
Make module documentation: http://www.erlang.org/doc/man/make.html
-
Compile options: http://www.erlang.org/doc/man/compile.html
Related Posts
Debugging with Erlang
'Running Erlang Code from the Command Line '
'Erlang: Understanding gen_server'
Need Expert Help with Apache Cassandra?
Get professional consulting for your distributed systems challenges. Performance optimization, architecture design, and troubleshooting.