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.

{"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

If you found this post helpful, please consider sharing to your network. I'm also available to help you be successful with your distributed systems! Please reach out if you're interested in working with me, and I'll be happy to schedule a free one-hour consultation.