| Author |
Message |
< Erlang ~ user_default:c |
| happi |
Posted: Fri Jul 21, 2006 1:17 pm |
|
|
|
Joined: 07 Nov 2005
Posts: 6
Location: Sweden
|
If you have a system that is normaly built with makefiles, and which uses the otp structure of src and ebin directories you might have had problem compiling from the erlang shell.
I use the following useful hack in my user_default:
Code:
c(M) ->
case shell_default:c(M) of
error ->
try src(M) of
S -> shell_default:c(S,[{outdir,filename:dirname(beam(M))}])
catch error: _ -> error
end;
O -> O
end.
c(M, Opts) ->
case shell_default:c(M, Opts) of
error ->
try src(M) of
S -> shell_default:c(S,Opts++[{outdir,filename:dirname(beam(M))}])
catch error: E -> E
end;
O -> O
end.
src(Module) ->
proplists:get_value(source,
proplists:get_value(compile,
Module:module_info())).
beam(Module) ->
code:which(Module).
|
|
|
| Back to top |
|
| Ludvig |
Posted: Fri Jul 21, 2006 1:31 pm |
|
|
|
User
Joined: 20 Jul 2006
Posts: 38
Location: London
|
|
| Back to top |
|
| Ludvig |
Posted: Fri Jul 21, 2006 3:57 pm |
|
|
|
User
Joined: 20 Jul 2006
Posts: 38
Location: London
|
I have now added your code to my .erlang file:
But when I'm starting erl I get this message
=ERROR REPORT==== 21-Jul-2006::16:56:24 ===
file:path_eval([".","/home/ludvig"],".erlang"): error on line 3: 3: syntax error before: '->'
Do you know what could be the problem. Is .erlang the right file? |
|
|
| Back to top |
|
| happi |
Posted: Mon Jul 24, 2006 6:28 am |
|
|
|
Joined: 07 Nov 2005
Posts: 6
Location: Sweden
|
Ludvig wrote:
Do you know what could be the problem. Is .erlang the right file?
No, it should go into user_default.erl |
|
|
| Back to top |
|
| Ludvig |
Posted: Mon Jul 24, 2006 8:39 am |
|
|
|
User
Joined: 20 Jul 2006
Posts: 38
Location: London
|
Where should I put this file?
Should I compile it and put it somewhere and then do add_path in my .erlang file?
--- EDIT ---
I have now tried this:
.erlang
Code: code:load_abs("/home/ludvig/user_default").
user_default.erl
Code: -module(user_default).
-compile(export_all).
c(M) ->
case shell_default:c(M) of
error ->
try src(M) of
S -> shell_default:c(S,[{outdir,filename:dirname(beam(M))}])
catch error: _ -> error
end;
O -> O
end.
c(M, Opts) ->
case shell_default:c(M, Opts) of
error ->
try src(M) of
S -> shell_default:c(S,Opts++[{outdir,filename:dirname(beam(M))}])
catch error: E -> E
end;
O -> O
end.
src(Module) ->
proplists:get_value(source,
proplists:get_value(compile,
Module:module_info())).
beam(Module) ->
code:which(Module).
And I have a structure with:
test
test/src
test/ebin
But when I compile a file it will just be put in the folder that I'm currently at. So it dosen't seem to work for me. Any idea? |
|
|
| Back to top |
|
| happi |
Posted: Tue Jul 25, 2006 7:34 pm |
|
|
|
Joined: 07 Nov 2005
Posts: 6
Location: Sweden
|
Ludvig wrote:
[...] when I compile a file it will just be put in the folder that I'm currently at. So it dosen't seem to work for me. Any idea?
It only works for re-compiling the file, i.e. you need to have it compiled with make once first (it looks at the path of the old beam file to find out where to put the new one. |
|
|
| Back to top |
|
| Ludvig |
Posted: Wed Jul 26, 2006 7:33 am |
|
|
|
User
Joined: 20 Jul 2006
Posts: 38
Location: London
|
| Hmm, okay. I will try it out again. But will this user_default override the existing c function or do I have to do something special to use it? like user_default:c(blaa)? |
|
|
| Back to top |
|
|
|