PageRenderTime 324ms CodeModel.GetById 120ms app.highlight 19ms RepoModel.GetById 112ms app.codeStats 70ms

/support/compile.erl

http://github.com/skarab/ewgi
Erlang | 44 lines | 25 code | 4 blank | 15 comment | 2 complexity | 0ed9dd92d9c597c9d5d26880147e1160 MD5 | raw file
 1#!/usr/bin/env escript
 2%% -*- erlang -*-
 3%%! -noinput +B
 4
 5%% @author Davide MarquĂŞs <nesrait@gmail.com>
 6%% @copyright 2009 Davide MarquĂŞs <nesrait@gmail.com>
 7%%
 8%% @doc Wrapper script for building a project using an Emakefile.
 9%% If new modules are detected we do a touch("src/$(APP).app") to trigger (in the
10%% Makefile) the recreation of the ebin/$(APP).app file with the new modules.
11%% @end
12%%
13%% Licensed under the MIT license:
14%% http://www.opensource.org/licenses/mit-license.php
15
16main([EBinFolder, AppFileSrc | Others]) ->
17	[code:add_patha(Other) || Other <- Others],
18	code:add_patha(EBinFolder),
19	M1 = filelib:wildcard(EBinFolder ++ "/*.beam"),
20	case make:all() of
21		up_to_date ->
22			%% If there are new/missing files regenerate the .app file
23			M2 = filelib:wildcard(EBinFolder ++ "/*.beam"),
24			if (M1 =/= M2) ->
25				touch(AppFileSrc);
26			true -> ok
27			end,
28			halt(0);
29		error ->
30			halt(1)
31	end;
32main(_) ->
33	io:format("Invalid arguments to compile.erl!").
34
35-include_lib("kernel/include/file.hrl").
36
37%% Opening/closing file because just calling file:write_file_info/2
38%% wasn't getting the job done.
39touch(FileName) ->
40	{ok, IoDevice} = file:open(FileName, [read, write]),
41	{ok, FileInfo} = file:read_file_info(FileName),
42	Now = calendar:now_to_local_time(erlang:now()),
43	ok = file:write_file_info(FileName, FileInfo#file_info{mtime=Now}),
44	file:close(IoDevice).