[erlang-questions] idea: using erlc for more file types
Vlad Dumitrescu
vladdu55@REDACTED
Mon Oct 29 13:53:44 CET 2007
Hi all,
("idea" was the closest matching tag, sometimes it's difficult to
know what's appropriate)
I would need to process files in Erlang that are not in the set that
is handled by erlc, but it would be very handy if they were. I think
then that it's not an earth-shattering suggestion that erlc should be
able to handle other file types.
A way to solve that would be by adding a command-line parameter
-compiler mymodule:myfunction
and use the specified function as entry point for the compiler proper.
A patch is attached (but of course, better and cleaner solutions may exist).
best regards,
Vlad
----------------------
Index: erts/etc/common/erlc.c
===================================================================
--- erts/etc/common/erlc.c (revision 18)
+++ erts/etc/common/erlc.c (working copy)
@@ -187,6 +187,9 @@
PUSH2("@output_type", output_type);
break;
case 'c': /* Allowed for compatibility with 'erl'. */
+ if (strcmp(argv[1], "-compiler") == 0) {
+ PUSH2("@compiler", process_opt(&argc, &argv, 0));
+ } else
if (strcmp(argv[1], "-compile") != 0)
goto error;
break;
Index: lib/stdlib/include/erl_compile.hrl
===================================================================
--- lib/stdlib/include/erl_compile.hrl (revision 18)
+++ lib/stdlib/include/erl_compile.hrl (working copy)
@@ -36,7 +36,8 @@
specific=[], % Compiler specific options.
outfile="", % Name of output file (internal
% use in erl_compile.erl).
- cwd % Current working directory
+ cwd, % Current working directory
% for erlc.
+ compiler
}).
Index: lib/stdlib/src/erl_compile.erl
===================================================================
--- lib/stdlib/src/erl_compile.erl (revision 18)
+++ lib/stdlib/src/erl_compile.erl (working copy)
@@ -26,22 +26,24 @@
%% Mapping from extension to {M,F} to run the correct compiler.
-compiler(".erl") -> {compile, compile};
-compiler(".S") -> {compile, compile_asm};
-compiler(".beam") -> {compile, compile_beam};
-compiler(".core") -> {compile, compile_core};
-compiler(".mib") -> {snmpc, compile};
-compiler(".bin") -> {snmpc, mib_to_hrl};
-compiler(".yrl") -> {yecc, compile};
-compiler(".script") -> {systools, script2boot};
-compiler(".rel") -> {systools, compile_rel};
-compiler(".idl") -> {ic, compile};
-compiler(".asn1") -> {asn1ct, compile_asn1};
-compiler(".asn") -> {asn1ct, compile_asn};
-compiler(".py") -> {asn1ct, compile_py};
-compiler(".xml") -> {xmerl_scan, process};
-compiler(_) -> no.
+compiler(".erl", _) -> {compile, compile};
+compiler(".S", _) -> {compile, compile_asm};
+compiler(".beam", _) -> {compile, compile_beam};
+compiler(".core", _) -> {compile, compile_core};
+compiler(".mib", _) -> {snmpc, compile};
+compiler(".bin", _) -> {snmpc, mib_to_hrl};
+compiler(".yrl", _) -> {yecc, compile};
+compiler(".script", _) -> {systools, script2boot};
+compiler(".rel", _) -> {systools, compile_rel};
+compiler(".idl", _) -> {ic, compile};
+compiler(".asn1", _) -> {asn1ct, compile_asn1};
+compiler(".asn", _) -> {asn1ct, compile_asn};
+compiler(".py", _) -> {asn1ct, compile_py};
+compiler(".xml", _) -> {xmerl_scan, process};
+compiler(_, #options{compiler=C}) -> C;
+compiler(_, _) -> no.
+
%% Entry from command line.
compile_cmdline(List) ->
@@ -130,8 +132,16 @@
compile1(Rest, Cwd, Opts#options{output_type=OutputType});
compile1(['@files'|Rest], Cwd, Opts) ->
Includes = lists:reverse(Opts#options.includes),
- compile2(Rest, Cwd, Opts#options{includes=Includes}).
+ compile2(Rest, Cwd, Opts#options{includes=Includes});
+compile1(['@compiler', MF|Rest], Cwd, Opts) ->
+ case string:tokens(MF, ":") of
+ [M, F] ->
+ compile2(Rest, Cwd, Opts#options{compiler={make_term(M), make_term(F)}});
+ _ ->
+ compile2(Rest, Cwd, Opts)
+ end.
+
compile2(Files, Cwd, Opts) ->
case {Opts#options.outfile, length(Files)} of
{"", _} ->
More information about the erlang-questions
mailing list