diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..484a371 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +ERLC_WARNINGS = -W1 +MNESIA_DIR = db +RUN_INIT = -s ezic start + +all : clean compile + +nowarn : ERLC_WARNINGS = -W0 +nowarn : clean compile + +test : ERLC_WARNINGS = -W0 +test : OPTIONS := $(OPTIONS) -DTEST +test : all + erlc $(ERLC_WARNINGS) $(OPTIONS) -o ./ebin ./tests/*.erl + erl -noshell -pa ebin -s test_master start -s erlang halt + +compile : + erlc $(ERLC_WARNINGS) $(OPTIONS) -o ./ebin ./src/*.erl + -erl -noshell -pa ebin -s erldev make_app . -s erlang halt + +clean : + -@rm ebin/* + + +run : + erl -pa ebin -mnesia dir $(MNESIA_DIR) $(RUN_INIT) \ No newline at end of file diff --git a/src/erldev.erl b/src/erldev.erl new file mode 100644 index 0000000..9ffacc9 --- /dev/null +++ b/src/erldev.erl @@ -0,0 +1,48 @@ +-module(erldev). +%% Contains development-related functions. + +%-compile([export_all]). +-export([make_app/1]). + + + + +%% "Compiles" a *.app.src file into a .app file, and places it in +%% the appropriate ebin folder +make_app([AppDirAtom]) -> + %%@todo: module name conflicts? + AppDir = atom_to_list(AppDirAtom), + Modules = get_modules(AppDir), + AppSrc = try get_app_src(AppDir) + catch error:{badmatch, _} -> + io:format("Couldn't get AppSrcFile for ~p~n", [AppDir]), + erlang:halt() + end, + {application, Name, Opts} = AppSrc, + NewOpts = [ {modules, Modules} | Opts ], + AppFile = filename:join([AppDir, "ebin", atom_to_list(Name) ++ ".app"]), + ok = file:write_file(AppFile, io_lib:format("~p.~n", [{application, Name, NewOpts}])), + io:format("Wrote .app contents to: ~p~n", [AppFile]), + ok. + + + +%% Returns a list of module names of all *.erl files in a given Application +%% folder (assuming OTP directory structure) +get_modules(AppDir) -> + lists:map( + fun(X)-> filename:basename(X, ".erl") end, + filelib:wildcard( + filename:join([AppDir, "src", "*.erl"]) + ) + ). + + + +%% Converts the contsnts of the *.app.src file into erlang terms +get_app_src(AppDir) -> + [AppSrcFile] = filelib:wildcard(filename:join([AppDir, "src", "*.app.src"])), + {ok, [AppSrc]} = file:consult(AppSrcFile), + %io:format("AppSrc: ~p~n", [AppSrc]), + AppSrc. + diff --git a/src/ezic.erl b/src/ezic.erl new file mode 100644 index 0000000..1d3798e --- /dev/null +++ b/src/ezic.erl @@ -0,0 +1,6 @@ +-module(ezic). + +-export([start/0]). + +start() -> + void. diff --git a/tests/test_master.erl b/tests/test_master.erl new file mode 100644 index 0000000..1cab61d --- /dev/null +++ b/tests/test_master.erl @@ -0,0 +1,5 @@ +-module(test_master). +-export([start/0]). + +start() -> + void.