2 %%! -noshell -noinput -pa .\ebin
3 %% -*- mode:erlang;tab-width:4;erlang-indent-level:4;indent-tabs-mode:nil -*-
4 %% ex: ft=erlang ts=4 sw=4 et
6 -define(SCRIPT, "mkrl").
8 compile_dir(DebugFlag, Dir) ->
9 Files = filelib:wildcard(filename:join(Dir, "*.erl")),
10 io:format("~p~n", [Files]),
11 case make:files(Files,
18 io:format("Compilation failed!~n"),
23 %% Add check for debug flag
24 case lists:member("debug", Args) of
26 DebugFlag = debug_info;
31 %% Compile all src/*.erl to ebin
32 %%XXX: This is not enough for bootstraping... at least hooks/core
33 lists:foreach(fun(F) ->
34 compile_dir(DebugFlag, F)
40 true = code:add_path("ebin"),
42 Files = load_files("*", "ebin") ++ load_files("*.config", "etc"),
44 case zip:create("mem", Files, [memory]) of
45 {ok, {"mem", ZipBin}} ->
46 %% Archive was successfully created. Prefix that binary with our
47 %% header and write to ?SCRIPT file
48 Script = <<"#!/usr/bin/env escript\n%%! -noshell -noinput\n", ZipBin/binary>>,
49 case file:write_file(?SCRIPT, Script) of
52 {error, WriteError} ->
53 io:format("Failed to write ~p script: ~p\n", [?SCRIPT, WriteError]),
57 io:format("Failed to construct ~p script archive: ~p\n", [?SCRIPT, ZipError]),
61 %% Finally, update executable perms for our script
64 [] = os:cmd("chmod u+x " ++ ?SCRIPT),
71 %% Add a helpful message
72 io:format("CONGRATULATIONS! You now have a self-contained script called \"~s\" in~n"
73 "your current working directory. Place this script anywhere in your path.~n", [?SCRIPT]).
75 load_files(Wildcard, Dir) ->
76 [read_file(Filename, Dir) || Filename <- filelib:wildcard(Wildcard, Dir)].
78 read_file(Filename, Dir) ->
79 {ok, Bin} = file:read_file(filename:join(Dir, Filename)),