aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/asciidoc.mk46
-rw-r--r--plugins/bootstrap.mk542
-rw-r--r--plugins/c_src.mk37
-rw-r--r--plugins/ci.mk65
-rw-r--r--plugins/cover.mk139
-rw-r--r--plugins/ct.mk68
-rw-r--r--plugins/dialyzer.mk4
-rw-r--r--plugins/edoc.mk11
-rw-r--r--plugins/elvis.mk10
-rw-r--r--plugins/erlydtl.mk18
-rw-r--r--plugins/escript.mk8
-rw-r--r--plugins/eunit.mk69
-rw-r--r--plugins/relx.mk33
-rw-r--r--plugins/shell.mk2
-rw-r--r--plugins/triq.mk43
-rw-r--r--plugins/xref.mk38
16 files changed, 789 insertions, 344 deletions
diff --git a/plugins/asciidoc.mk b/plugins/asciidoc.mk
new file mode 100644
index 0000000..baf4d3b
--- /dev/null
+++ b/plugins/asciidoc.mk
@@ -0,0 +1,46 @@
+# Copyright (c) 2015, Loïc Hoguin <[email protected]>
+# This file is part of erlang.mk and subject to the terms of the ISC License.
+
+.PHONY: asciidoc asciidoc-guide asciidoc-manual install-asciidoc distclean-asciidoc
+
+MAN_INSTALL_PATH ?= /usr/local/share/man
+MAN_SECTIONS ?= 3 7
+
+docs:: asciidoc
+
+asciidoc: distclean-asciidoc doc-deps asciidoc-guide asciidoc-manual
+
+ifeq ($(wildcard doc/src/guide/book.asciidoc),)
+asciidoc-guide:
+else
+asciidoc-guide:
+ a2x -v -f pdf doc/src/guide/book.asciidoc && mv doc/src/guide/book.pdf doc/guide.pdf
+ a2x -v -f chunked doc/src/guide/book.asciidoc && mv doc/src/guide/book.chunked/ doc/html/
+endif
+
+ifeq ($(wildcard doc/src/manual/*.asciidoc),)
+asciidoc-manual:
+else
+asciidoc-manual:
+ for f in doc/src/manual/*.asciidoc ; do \
+ a2x -v -f manpage $$f ; \
+ done
+ for s in $(MAN_SECTIONS); do \
+ mkdir -p doc/man$$s/ ; \
+ mv doc/src/manual/*.$$s doc/man$$s/ ; \
+ gzip doc/man$$s/*.$$s ; \
+ done
+
+install-docs:: install-asciidoc
+
+install-asciidoc: asciidoc-manual
+ for s in $(MAN_SECTIONS); do \
+ mkdir -p $(MAN_INSTALL_PATH)/man$$s/ ; \
+ install -g 0 -o 0 -m 0644 doc/man$$s/*.gz $(MAN_INSTALL_PATH)/man$$s/ ; \
+ done
+endif
+
+distclean:: distclean-asciidoc
+
+distclean-asciidoc:
+ $(gen_verbose) rm -rf doc/html/ doc/guide.pdf doc/man3/ doc/man7/
diff --git a/plugins/bootstrap.mk b/plugins/bootstrap.mk
index 9397253..6637520 100644
--- a/plugins/bootstrap.mk
+++ b/plugins/bootstrap.mk
@@ -1,4 +1,4 @@
-# Copyright (c) 2014, Loïc Hoguin <[email protected]>
+# Copyright (c) 2014-2015, Loïc Hoguin <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.
.PHONY: bootstrap bootstrap-lib bootstrap-rel new list-templates
@@ -16,235 +16,337 @@ help::
# Bootstrap templates.
-bs_appsrc = "{application, $(PROJECT), [" \
- " {description, \"\"}," \
- " {vsn, \"0.1.0\"}," \
- " {id, \"git\"}," \
- " {modules, []}," \
- " {registered, []}," \
- " {applications, [" \
- " kernel," \
- " stdlib" \
- " ]}," \
- " {mod, {$(PROJECT)_app, []}}," \
- " {env, []}" \
- "]}."
-bs_appsrc_lib = "{application, $(PROJECT), [" \
- " {description, \"\"}," \
- " {vsn, \"0.1.0\"}," \
- " {id, \"git\"}," \
- " {modules, []}," \
- " {registered, []}," \
- " {applications, [" \
- " kernel," \
- " stdlib" \
- " ]}" \
- "]}."
-bs_Makefile = "PROJECT = $(PROJECT)" \
- "include erlang.mk"
-bs_app = "-module($(PROJECT)_app)." \
- "-behaviour(application)." \
- "" \
- "-export([start/2])." \
- "-export([stop/1])." \
- "" \
- "start(_Type, _Args) ->" \
- " $(PROJECT)_sup:start_link()." \
- "" \
- "stop(_State) ->" \
- " ok."
-bs_relx_config = "{release, {$(PROJECT)_release, \"1\"}, [$(PROJECT)]}." \
- "{extended_start_script, true}." \
- "{sys_config, \"rel/sys.config\"}." \
- "{vm_args, \"rel/vm.args\"}."
-bs_sys_config = "[" \
- "]."
-bs_vm_args = "-name $(PROJECT)@127.0.0.1" \
- "-setcookie $(PROJECT)" \
- "-heart"
+define bs_appsrc
+{application, $(PROJECT), [
+ {description, ""},
+ {vsn, "0.1.0"},
+ {id, "git"},
+ {modules, []},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib
+ ]},
+ {mod, {$(PROJECT)_app, []}},
+ {env, []}
+]}.
+endef
+
+define bs_appsrc_lib
+{application, $(PROJECT), [
+ {description, ""},
+ {vsn, "0.1.0"},
+ {id, "git"},
+ {modules, []},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib
+ ]}
+]}.
+endef
+
+define bs_Makefile
+PROJECT = $(PROJECT)
+include erlang.mk
+endef
+
+define bs_app
+-module($(PROJECT)_app).
+-behaviour(application).
+
+-export([start/2]).
+-export([stop/1]).
+
+start(_Type, _Args) ->
+ $(PROJECT)_sup:start_link().
+
+stop(_State) ->
+ ok.
+endef
+
+define bs_relx_config
+{release, {$(PROJECT)_release, "1"}, [$(PROJECT)]}.
+{extended_start_script, true}.
+{sys_config, "rel/sys.config"}.
+{vm_args, "rel/vm.args"}.
+endef
+
+define bs_sys_config
+[
+].
+endef
+
+define bs_vm_args
+-name $(PROJECT)@127.0.0.1
+-setcookie $(PROJECT)
+-heart
+endef
+
# Normal templates.
-tpl_supervisor = "-module($(n))." \
- "-behaviour(supervisor)." \
- "" \
- "-export([start_link/0])." \
- "-export([init/1])." \
- "" \
- "start_link() ->" \
- " supervisor:start_link({local, ?MODULE}, ?MODULE, [])." \
- "" \
- "init([]) ->" \
- " Procs = []," \
- " {ok, {{one_for_one, 1, 5}, Procs}}."
-tpl_gen_server = "-module($(n))." \
- "-behaviour(gen_server)." \
- "" \
- "%% API." \
- "-export([start_link/0])." \
- "" \
- "%% gen_server." \
- "-export([init/1])." \
- "-export([handle_call/3])." \
- "-export([handle_cast/2])." \
- "-export([handle_info/2])." \
- "-export([terminate/2])." \
- "-export([code_change/3])." \
- "" \
- "-record(state, {" \
- "})." \
- "" \
- "%% API." \
- "" \
- "-spec start_link() -> {ok, pid()}." \
- "start_link() ->" \
- " gen_server:start_link(?MODULE, [], [])." \
- "" \
- "%% gen_server." \
- "" \
- "init([]) ->" \
- " {ok, \#state{}}." \
- "" \
- "handle_call(_Request, _From, State) ->" \
- " {reply, ignored, State}." \
- "" \
- "handle_cast(_Msg, State) ->" \
- " {noreply, State}." \
- "" \
- "handle_info(_Info, State) ->" \
- " {noreply, State}." \
- "" \
- "terminate(_Reason, _State) ->" \
- " ok." \
- "" \
- "code_change(_OldVsn, State, _Extra) ->" \
- " {ok, State}."
-tpl_cowboy_http = "-module($(n))." \
- "-behaviour(cowboy_http_handler)." \
- "" \
- "-export([init/3])." \
- "-export([handle/2])." \
- "-export([terminate/3])." \
- "" \
- "-record(state, {" \
- "})." \
- "" \
- "init(_, Req, _Opts) ->" \
- " {ok, Req, \#state{}}." \
- "" \
- "handle(Req, State=\#state{}) ->" \
- " {ok, Req2} = cowboy_req:reply(200, Req)," \
- " {ok, Req2, State}." \
- "" \
- "terminate(_Reason, _Req, _State) ->" \
- " ok."
-tpl_cowboy_loop = "-module($(n))." \
- "-behaviour(cowboy_loop_handler)." \
- "" \
- "-export([init/3])." \
- "-export([info/3])." \
- "-export([terminate/3])." \
- "" \
- "-record(state, {" \
- "})." \
- "" \
- "init(_, Req, _Opts) ->" \
- " {loop, Req, \#state{}, 5000, hibernate}." \
- "" \
- "info(_Info, Req, State) ->" \
- " {loop, Req, State, hibernate}." \
- "" \
- "terminate(_Reason, _Req, _State) ->" \
- " ok."
-tpl_cowboy_rest = "-module($(n))." \
- "" \
- "-export([init/3])." \
- "-export([content_types_provided/2])." \
- "-export([get_html/2])." \
- "" \
- "init(_, _Req, _Opts) ->" \
- " {upgrade, protocol, cowboy_rest}." \
- "" \
- "content_types_provided(Req, State) ->" \
- " {[{{<<\"text\">>, <<\"html\">>, '*'}, get_html}], Req, State}." \
- "" \
- "get_html(Req, State) ->" \
- " {<<\"<html><body>This is REST!</body></html>\">>, Req, State}."
-tpl_cowboy_ws = "-module($(n))." \
- "-behaviour(cowboy_websocket_handler)." \
- "" \
- "-export([init/3])." \
- "-export([websocket_init/3])." \
- "-export([websocket_handle/3])." \
- "-export([websocket_info/3])." \
- "-export([websocket_terminate/3])." \
- "" \
- "-record(state, {" \
- "})." \
- "" \
- "init(_, _, _) ->" \
- " {upgrade, protocol, cowboy_websocket}." \
- "" \
- "websocket_init(_, Req, _Opts) ->" \
- " Req2 = cowboy_req:compact(Req)," \
- " {ok, Req2, \#state{}}." \
- "" \
- "websocket_handle({text, Data}, Req, State) ->" \
- " {reply, {text, Data}, Req, State};" \
- "websocket_handle({binary, Data}, Req, State) ->" \
- " {reply, {binary, Data}, Req, State};" \
- "websocket_handle(_Frame, Req, State) ->" \
- " {ok, Req, State}." \
- "" \
- "websocket_info(_Info, Req, State) ->" \
- " {ok, Req, State}." \
- "" \
- "websocket_terminate(_Reason, _Req, _State) ->" \
- " ok."
-tpl_ranch_protocol = "-module($(n))." \
- "-behaviour(ranch_protocol)." \
- "" \
- "-export([start_link/4])." \
- "-export([init/4])." \
- "" \
- "-type opts() :: []." \
- "-export_type([opts/0])." \
- "" \
- "-record(state, {" \
- " socket :: inet:socket()," \
- " transport :: module()" \
- "})." \
- "" \
- "start_link(Ref, Socket, Transport, Opts) ->" \
- " Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts])," \
- " {ok, Pid}." \
- "" \
- "-spec init(ranch:ref(), inet:socket(), module(), opts()) -> ok." \
- "init(Ref, Socket, Transport, _Opts) ->" \
- " ok = ranch:accept_ack(Ref)," \
- " loop(\#state{socket=Socket, transport=Transport})." \
- "" \
- "loop(State) ->" \
- " loop(State)."
+
+define tpl_supervisor
+-module($(n)).
+-behaviour(supervisor).
+
+-export([start_link/0]).
+-export([init/1]).
+
+start_link() ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+init([]) ->
+ Procs = [],
+ {ok, {{one_for_one, 1, 5}, Procs}}.
+endef
+
+define tpl_gen_server
+-module($(n)).
+-behaviour(gen_server).
+
+%% API.
+-export([start_link/0]).
+
+%% gen_server.
+-export([init/1]).
+-export([handle_call/3]).
+-export([handle_cast/2]).
+-export([handle_info/2]).
+-export([terminate/2]).
+-export([code_change/3]).
+
+-record(state, {
+}).
+
+%% API.
+
+-spec start_link() -> {ok, pid()}.
+start_link() ->
+ gen_server:start_link(?MODULE, [], []).
+
+%% gen_server.
+
+init([]) ->
+ {ok, #state{}}.
+
+handle_call(_Request, _From, State) ->
+ {reply, ignored, State}.
+
+handle_cast(_Msg, State) ->
+ {noreply, State}.
+
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+terminate(_Reason, _State) ->
+ ok.
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+endef
+
+define tpl_cowboy_http
+-module($(n)).
+-behaviour(cowboy_http_handler).
+
+-export([init/3]).
+-export([handle/2]).
+-export([terminate/3]).
+
+-record(state, {
+}).
+
+init(_, Req, _Opts) ->
+ {ok, Req, #state{}}.
+
+handle(Req, State=#state{}) ->
+ {ok, Req2} = cowboy_req:reply(200, Req),
+ {ok, Req2, State}.
+
+terminate(_Reason, _Req, _State) ->
+ ok.
+endef
+
+define tpl_gen_fsm
+-module($(n)).
+-behaviour(gen_fsm).
+
+%% API.
+-export([start_link/0]).
+
+%% gen_fsm.
+-export([init/1]).
+-export([state_name/2]).
+-export([handle_event/3]).
+-export([state_name/3]).
+-export([handle_sync_event/4]).
+-export([handle_info/3]).
+-export([terminate/3]).
+-export([code_change/4]).
+
+-record(state, {
+}).
+
+%% API.
+
+-spec start_link() -> {ok, pid()}.
+start_link() ->
+ gen_fsm:start_link(?MODULE, [], []).
+
+%% gen_fsm.
+
+init([]) ->
+ {ok, state_name, #state{}}.
+
+state_name(_Event, StateData) ->
+ {next_state, state_name, StateData}.
+
+handle_event(_Event, StateName, StateData) ->
+ {next_state, StateName, StateData}.
+
+state_name(_Event, _From, StateData) ->
+ {reply, ignored, state_name, StateData}.
+
+handle_sync_event(_Event, _From, StateName, StateData) ->
+ {reply, ignored, StateName, StateData}.
+
+handle_info(_Info, StateName, StateData) ->
+ {next_state, StateName, StateData}.
+
+terminate(_Reason, _StateName, _StateData) ->
+ ok.
+
+code_change(_OldVsn, StateName, StateData, _Extra) ->
+ {ok, StateName, StateData}.
+endef
+
+define tpl_cowboy_loop
+-module($(n)).
+-behaviour(cowboy_loop_handler).
+
+-export([init/3]).
+-export([info/3]).
+-export([terminate/3]).
+
+-record(state, {
+}).
+
+init(_, Req, _Opts) ->
+ {loop, Req, #state{}, 5000, hibernate}.
+
+info(_Info, Req, State) ->
+ {loop, Req, State, hibernate}.
+
+terminate(_Reason, _Req, _State) ->
+ ok.
+endef
+
+define tpl_cowboy_rest
+-module($(n)).
+
+-export([init/3]).
+-export([content_types_provided/2]).
+-export([get_html/2]).
+
+init(_, _Req, _Opts) ->
+ {upgrade, protocol, cowboy_rest}.
+
+content_types_provided(Req, State) ->
+ {[{{<<"text">>, <<"html">>, '*'}, get_html}], Req, State}.
+
+get_html(Req, State) ->
+ {<<"<html><body>This is REST!</body></html>">>, Req, State}.
+endef
+
+define tpl_cowboy_ws
+-module($(n)).
+-behaviour(cowboy_websocket_handler).
+
+-export([init/3]).
+-export([websocket_init/3]).
+-export([websocket_handle/3]).
+-export([websocket_info/3]).
+-export([websocket_terminate/3]).
+
+-record(state, {
+}).
+
+init(_, _, _) ->
+ {upgrade, protocol, cowboy_websocket}.
+
+websocket_init(_, Req, _Opts) ->
+ Req2 = cowboy_req:compact(Req),
+ {ok, Req2, #state{}}.
+
+websocket_handle({text, Data}, Req, State) ->
+ {reply, {text, Data}, Req, State};
+websocket_handle({binary, Data}, Req, State) ->
+ {reply, {binary, Data}, Req, State};
+websocket_handle(_Frame, Req, State) ->
+ {ok, Req, State}.
+
+websocket_info(_Info, Req, State) ->
+ {ok, Req, State}.
+
+websocket_terminate(_Reason, _Req, _State) ->
+ ok.
+endef
+
+define tpl_ranch_protocol
+-module($(n)).
+-behaviour(ranch_protocol).
+
+-export([start_link/4]).
+-export([init/4]).
+
+-type opts() :: [].
+-export_type([opts/0]).
+
+-record(state, {
+ socket :: inet:socket(),
+ transport :: module()
+}).
+
+start_link(Ref, Socket, Transport, Opts) ->
+ Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts]),
+ {ok, Pid}.
+
+-spec init(ranch:ref(), inet:socket(), module(), opts()) -> ok.
+init(Ref, Socket, Transport, _Opts) ->
+ ok = ranch:accept_ack(Ref),
+ loop(#state{socket=Socket, transport=Transport}).
+
+loop(State) ->
+ loop(State).
+endef
# Plugin-specific targets.
+define render_template
+ @echo "$${$(1)}" > $(2)
+endef
+
+$(foreach template,$(filter bs_%,$(.VARIABLES)),$(eval export $(template)))
+$(foreach template,$(filter tpl_%,$(.VARIABLES)),$(eval export $(template)))
+
bootstrap:
ifneq ($(wildcard src/),)
$(error Error: src/ directory already exists)
endif
- @printf "%s\n" $(bs_Makefile) > Makefile
+ $(call render_template,bs_Makefile,Makefile)
@mkdir src/
- @printf "%s\n" $(bs_appsrc) > src/$(PROJECT).app.src
- @printf "%s\n" $(bs_app) > src/$(PROJECT)_app.erl
+ $(call render_template,bs_appsrc,src/$(PROJECT).app.src)
+ $(call render_template,bs_app,src/$(PROJECT)_app.erl)
$(eval n := $(PROJECT)_sup)
- @printf "%s\n" $(tpl_supervisor) > src/$(PROJECT)_sup.erl
+ $(call render_template,tpl_supervisor,src/$(PROJECT)_sup.erl)
bootstrap-lib:
ifneq ($(wildcard src/),)
$(error Error: src/ directory already exists)
endif
- @printf "%s\n" $(bs_Makefile) > Makefile
+ $(call render_template,bs_Makefile,Makefile)
@mkdir src/
- @printf "%s\n" $(bs_appsrc_lib) > src/$(PROJECT).app.src
+ $(call render_template,bs_appsrc_lib,src/$(PROJECT).app.src)
bootstrap-rel:
ifneq ($(wildcard relx.config),)
@@ -253,25 +355,25 @@ endif
ifneq ($(wildcard rel/),)
$(error Error: rel/ directory already exists)
endif
- @printf "%s\n" $(bs_relx_config) > relx.config
+ $(call render_template,bs_relx_config,relx.config)
@mkdir rel/
- @printf "%s\n" $(bs_sys_config) > rel/sys.config
- @printf "%s\n" $(bs_vm_args) > rel/vm.args
+ $(call render_template,bs_sys_config,rel/sys.config)
+ $(call render_template,bs_vm_args,rel/vm.args)
new:
ifeq ($(wildcard src/),)
$(error Error: src/ directory does not exist)
endif
ifndef t
- $(error Usage: make new t=TEMPLATE n=NAME)
+ $(error Usage: $(MAKE) new t=TEMPLATE n=NAME)
endif
ifndef tpl_$(t)
$(error Unknown template)
endif
ifndef n
- $(error Usage: make new t=TEMPLATE n=NAME)
+ $(error Usage: $(MAKE) new t=TEMPLATE n=NAME)
endif
- @printf "%s\n" $(tpl_$(t)) > src/$(n).erl
+ $(call render_template,tpl_$(t),src/$(n).erl)
list-templates:
@echo Available templates: $(sort $(patsubst tpl_%,%,$(filter tpl_%,$(.VARIABLES))))
diff --git a/plugins/c_src.mk b/plugins/c_src.mk
index 7c1fd2e..bdec23b 100644
--- a/plugins/c_src.mk
+++ b/plugins/c_src.mk
@@ -1,8 +1,7 @@
-# Copyright (c) 2014, Loïc Hoguin <[email protected]>
+# Copyright (c) 2014-2015, Loïc Hoguin <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.
.PHONY: clean-c_src distclean-c_src-env
-# todo
# Configuration.
@@ -49,14 +48,25 @@ link_verbose = $(link_verbose_$(V))
ifeq ($(wildcard $(C_SRC_DIR)),)
else ifneq ($(wildcard $(C_SRC_DIR)/Makefile),)
-app::
- $(MAKE) -C $(C_SRC_DIR)
+app:: app-c_src
+
+test-build:: app-c_src
+
+app-c_src:
+ $(MAKE) -C $(C_SRC_DIR) \
+ CFLAGS="$(CFLAGS)" \
+ CXXFLAGS="$(CXXFLAGS)" \
+ LDLIBS="$(LDLIBS)" \
+ LDFLAGS="$(LDFLAGS)"
clean::
$(MAKE) -C $(C_SRC_DIR) clean
else
+
+ifeq ($(SOURCES),)
SOURCES := $(shell find $(C_SRC_DIR) -type f \( -name "*.c" -o -name "*.C" -o -name "*.cc" -o -name "*.cpp" \))
+endif
OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))
COMPILE_C = $(c_verbose) $(CC) $(CFLAGS) $(CPPFLAGS) -c
@@ -64,6 +74,8 @@ COMPILE_CPP = $(cpp_verbose) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c
app:: $(C_SRC_ENV) $(C_SRC_OUTPUT)
+test-build:: $(C_SRC_ENV) $(C_SRC_OUTPUT)
+
$(C_SRC_OUTPUT): $(OBJECTS)
@mkdir -p priv/
$(link_verbose) $(CC) $(OBJECTS) $(LDFLAGS) $(LDLIBS) -o $(C_SRC_OUTPUT)
@@ -80,8 +92,16 @@ $(C_SRC_OUTPUT): $(OBJECTS)
%.o: %.cpp
$(COMPILE_CPP) $(OUTPUT_OPTION) $<
+clean:: clean-c_src
+
+clean-c_src:
+ $(gen_verbose) rm -f $(C_SRC_OUTPUT) $(OBJECTS)
+
+endif
+
+ifneq ($(wildcard $(C_SRC_DIR)),)
$(C_SRC_ENV):
- @erl -noshell -noinput -eval "file:write_file(\"$(C_SRC_ENV)\", \
+ @$(ERL) -eval "file:write_file(\"$(C_SRC_ENV)\", \
io_lib:format( \
\"ERTS_INCLUDE_DIR ?= ~s/erts-~s/include/~n\" \
\"ERL_INTERFACE_INCLUDE_DIR ?= ~s~n\" \
@@ -89,12 +109,7 @@ $(C_SRC_ENV):
[code:root_dir(), erlang:system_info(version), \
code:lib_dir(erl_interface, include), \
code:lib_dir(erl_interface, lib)])), \
- erlang:halt()."
-
-clean:: clean-c_src
-
-clean-c_src:
- $(gen_verbose) rm -f $(C_SRC_OUTPUT) $(OBJECTS)
+ halt()."
distclean:: distclean-c_src-env
diff --git a/plugins/ci.mk b/plugins/ci.mk
new file mode 100644
index 0000000..4f338b3
--- /dev/null
+++ b/plugins/ci.mk
@@ -0,0 +1,65 @@
+# Copyright (c) 2015, Loïc Hoguin <[email protected]>
+# This file is part of erlang.mk and subject to the terms of the ISC License.
+
+.PHONY: ci ci-setup distclean-kerl
+
+KERL ?= $(CURDIR)/kerl
+export KERL
+
+KERL_URL ?= https://raw.githubusercontent.com/yrashk/kerl/master/kerl
+
+OTP_GIT ?= https://github.com/erlang/otp
+
+CI_INSTALL_DIR ?= $(HOME)/erlang
+CI_OTP ?=
+
+ifeq ($(strip $(CI_OTP)),)
+ci::
+else
+ci:: $(KERL) $(addprefix ci-,$(CI_OTP))
+
+ci-setup::
+
+ci_verbose_0 = @echo " CI " $(1);
+ci_verbose = $(ci_verbose_$(V))
+
+define ci_target
+ci-$(1): $(CI_INSTALL_DIR)/$(1)
+ -$(ci_verbose) \
+ PATH="$(CI_INSTALL_DIR)/$(1)/bin:$(PATH)" \
+ CI_OTP_RELEASE="$(1)" \
+ CT_OPTS="-label $(1)" \
+ $(MAKE) clean ci-setup tests
+endef
+
+$(foreach otp,$(CI_OTP),$(eval $(call ci_target,$(otp))))
+
+define ci_otp_target
+$(CI_INSTALL_DIR)/$(1):
+ $(KERL) build git $(OTP_GIT) $(1) $(1)
+ $(KERL) install $(1) $(CI_INSTALL_DIR)/$(1)
+endef
+
+$(foreach otp,$(CI_OTP),$(eval $(call ci_otp_target,$(otp))))
+
+define kerl_fetch
+ $(call core_http_get,$(KERL),$(KERL_URL))
+ chmod +x $(KERL)
+endef
+
+$(KERL):
+ @$(call kerl_fetch)
+
+help::
+ @printf "%s\n" "" \
+ "Continuous Integration targets:" \
+ " ci Run '$(MAKE) tests' on all configured Erlang versions." \
+ "" \
+ "The CI_OTP variable must be defined with the Erlang versions" \
+ "that must be tested. For example: CI_OTP = OTP-17.3.4 OTP-17.5.3"
+
+distclean:: distclean-kerl
+
+distclean-kerl:
+ $(gen_verbose) rm -rf $(KERL)
+endif
diff --git a/plugins/cover.mk b/plugins/cover.mk
new file mode 100644
index 0000000..bd94051
--- /dev/null
+++ b/plugins/cover.mk
@@ -0,0 +1,139 @@
+# Copyright 2015, Viktor Söderqvist <[email protected]>
+# This file is part of erlang.mk and subject to the terms of the ISC License.
+
+COVER_REPORT_DIR = cover
+
+# utility variables for representing special symbols
+empty :=
+space := $(empty) $(empty)
+comma := ,
+
+# Hook in coverage to eunit
+
+ifdef COVER
+ifdef EUNIT_RUN
+EUNIT_RUN_BEFORE += -eval \
+ 'case cover:compile_beam_directory("ebin") of \
+ {error, _} -> halt(1); \
+ _ -> ok \
+ end.'
+EUNIT_RUN_AFTER += -eval 'cover:export("eunit.coverdata").'
+endif
+endif
+
+# Hook in coverage to ct
+
+ifdef COVER
+ifdef CT_RUN
+
+# All modules in 'ebin'
+COVER_MODS = $(notdir $(basename $(shell echo ebin/*.beam)))
+
+test-build:: $(TEST_DIR)/ct.cover.spec
+
+$(TEST_DIR)/ct.cover.spec:
+ @echo Cover mods: $(COVER_MODS)
+ $(gen_verbose) printf "%s\n" \
+ '{incl_mods,[$(subst $(space),$(comma),$(COVER_MODS))]}.' \
+ '{export,"$(CURDIR)/ct.coverdata"}.' > $@
+
+CT_RUN += -cover $(TEST_DIR)/ct.cover.spec
+endif
+endif
+
+# Core targets
+
+ifdef COVER
+ifneq ($(COVER_REPORT_DIR),)
+tests::
+ @$(MAKE) --no-print-directory cover-report
+endif
+endif
+
+clean:: coverdata-clean
+
+ifneq ($(COVER_REPORT_DIR),)
+distclean:: cover-report-clean
+endif
+
+help::
+ @printf "%s\n" "" \
+ "Cover targets:" \
+ " cover-report Generate a HTML coverage report from previously collected" \
+ " cover data." \
+ " all.coverdata Merge {eunit,ct}.coverdata into one coverdata file." \
+ "" \
+ "If COVER=1 is set, coverage data is generated by the targets eunit and ct. The" \
+ "target tests additionally generates a HTML coverage report from the combined" \
+ "coverdata files from each of these testing tools. HTML reports can be disabled" \
+ "by setting COVER_REPORT_DIR to empty."
+
+# Plugin specific targets
+
+COVERDATA = $(filter-out all.coverdata,$(wildcard *.coverdata))
+
+.PHONY: coverdata-clean
+coverdata-clean:
+ $(gen_verbose) rm -f *.coverdata ct.cover.spec
+
+# Merge all coverdata files into one.
+all.coverdata: $(COVERDATA)
+ $(gen_verbose) $(ERL) -eval ' \
+ $(foreach f,$(COVERDATA),cover:import("$(f)") == ok orelse halt(1),) \
+ cover:export("$@"), halt(0).'
+
+# These are only defined if COVER_REPORT_DIR is non-empty. Set COVER_REPORT_DIR to
+# empty if you want the coverdata files but not the HTML report.
+ifneq ($(COVER_REPORT_DIR),)
+
+.PHONY: cover-report-clean cover-report
+
+cover-report-clean:
+ $(gen_verbose) rm -rf $(COVER_REPORT_DIR)
+
+ifeq ($(COVERDATA),)
+cover-report:
+else
+
+# Modules which include eunit.hrl always contain one line without coverage
+# because eunit defines test/0 which is never called. We compensate for this.
+EUNIT_HRL_MODS = $(subst $(space),$(comma),$(shell \
+ grep -e '^\s*-include.*include/eunit\.hrl"' src/*.erl \
+ | sed "s/^src\/\(.*\)\.erl:.*/'\1'/" | uniq))
+
+define cover_report.erl
+ $(foreach f,$(COVERDATA),cover:import("$(f)") == ok orelse halt(1),)
+ Ms = cover:imported_modules(),
+ [cover:analyse_to_file(M, "$(COVER_REPORT_DIR)/" ++ atom_to_list(M)
+ ++ ".COVER.html", [html]) || M <- Ms],
+ Report = [begin {ok, R} = cover:analyse(M, module), R end || M <- Ms],
+ EunitHrlMods = [$(EUNIT_HRL_MODS)],
+ Report1 = [{M, {Y, case lists:member(M, EunitHrlMods) of
+ true -> N - 1; false -> N end}} || {M, {Y, N}} <- Report],
+ TotalY = lists:sum([Y || {_, {Y, _}} <- Report1]),
+ TotalN = lists:sum([N || {_, {_, N}} <- Report1]),
+ TotalPerc = round(100 * TotalY / (TotalY + TotalN)),
+ {ok, F} = file:open("$(COVER_REPORT_DIR)/index.html", [write]),
+ io:format(F, "<!DOCTYPE html><html>~n"
+ "<head><meta charset=\"UTF-8\">~n"
+ "<title>Coverage report</title></head>~n"
+ "<body>~n", []),
+ io:format(F, "<h1>Coverage</h1>~n<p>Total: ~p%</p>~n", [TotalPerc]),
+ io:format(F, "<table><tr><th>Module</th><th>Coverage</th></tr>~n", []),
+ [io:format(F, "<tr><td><a href=\"~p.COVER.html\">~p</a></td>"
+ "<td>~p%</td></tr>~n",
+ [M, M, round(100 * Y / (Y + N))]) || {M, {Y, N}} <- Report1],
+ How = "$(subst $(space),$(comma)$(space),$(basename $(COVERDATA)))",
+ Date = "$(shell date -u "+%Y-%m-%dT%H:%M:%SZ")",
+ io:format(F, "</table>~n"
+ "<p>Generated using ~s and erlang.mk on ~s.</p>~n"
+ "</body></html>", [How, Date]),
+ halt().
+endef
+
+cover-report:
+ $(gen_verbose) mkdir -p $(COVER_REPORT_DIR)
+ $(gen_verbose) $(call erlang,$(cover_report.erl))
+
+endif
+endif # ifneq ($(COVER_REPORT_DIR),)
diff --git a/plugins/ct.mk b/plugins/ct.mk
index 4453b70..eba0e52 100644
--- a/plugins/ct.mk
+++ b/plugins/ct.mk
@@ -1,77 +1,55 @@
-# Copyright (c) 2013-2014, Loïc Hoguin <[email protected]>
+# Copyright (c) 2013-2015, Loïc Hoguin <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.
-.PHONY: build-ct-deps build-ct-suites tests-ct clean-ct distclean-ct
+.PHONY: ct distclean-ct
# Configuration.
CT_OPTS ?=
-ifneq ($(wildcard test/),)
- CT_SUITES ?= $(sort $(subst _SUITE.erl,,$(shell find test -type f -name \*_SUITE.erl -exec basename {} \;)))
+ifneq ($(wildcard $(TEST_DIR)),)
+ CT_SUITES ?= $(sort $(subst _SUITE.erl,,$(shell find $(TEST_DIR) -type f -name \*_SUITE.erl -exec basename {} \;)))
else
CT_SUITES ?=
endif
-TEST_ERLC_OPTS ?= +debug_info +warn_export_vars +warn_shadow_vars +warn_obsolete_guard
-TEST_ERLC_OPTS += -DTEST=1 -DEXTRA=1 +'{parse_transform, eunit_autoexport}'
-
# Core targets.
-tests:: tests-ct
-
-clean:: clean-ct
+tests:: ct
distclean:: distclean-ct
help::
@printf "%s\n" "" \
+ "Common_test targets:" \
+ " ct Run all the common_test suites for this project" \
+ "" \
"All your common_test suites have their associated targets." \
"A suite named http_SUITE can be ran using the ct-http target."
# Plugin-specific targets.
-ALL_TEST_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(TEST_DEPS))
-
CT_RUN = ct_run \
-no_auto_compile \
- -noshell \
- -pa $(realpath ebin) $(DEPS_DIR)/*/ebin \
- -dir test \
- -logdir logs
-
-$(foreach dep,$(TEST_DEPS),$(eval $(call dep_target,$(dep))))
-
-build-ct-deps: $(ALL_TEST_DEPS_DIRS)
- @for dep in $(ALL_TEST_DEPS_DIRS) ; do $(MAKE) -C $$dep; done
+ -noinput \
+ -pa $(CURDIR)/ebin $(DEPS_DIR)/*/ebin $(TEST_DIR) \
+ -dir $(TEST_DIR) \
+ -logdir $(CURDIR)/logs
-build-ct-suites: build-ct-deps
- $(gen_verbose) erlc -v $(TEST_ERLC_OPTS) -I include/ -o test/ \
- $(wildcard test/*.erl test/*/*.erl) -pa ebin/
-
-tests-ct: ERLC_OPTS = $(TEST_ERLC_OPTS)
-tests-ct: clean deps app build-ct-suites
- @if [ -d "test" ] ; \
- then \
- mkdir -p logs/ ; \
- $(CT_RUN) -suite $(addsuffix _SUITE,$(CT_SUITES)) $(CT_OPTS) ; \
- fi
- $(gen_verbose) rm -f test/*.beam
+ifeq ($(CT_SUITES),)
+ct:
+else
+ct: test-build
+ @mkdir -p $(CURDIR)/logs/
+ $(gen_verbose) $(CT_RUN) -suite $(addsuffix _SUITE,$(CT_SUITES)) $(CT_OPTS)
+endif
define ct_suite_target
-ct-$(1): ERLC_OPTS = $(TEST_ERLC_OPTS)
-ct-$(1): clean deps app build-ct-suites
- @if [ -d "test" ] ; \
- then \
- mkdir -p logs/ ; \
- $(CT_RUN) -suite $(addsuffix _SUITE,$(1)) $(CT_OPTS) ; \
- fi
- $(gen_verbose) rm -f test/*.beam
+ct-$(1): test-build
+ @mkdir -p $(CURDIR)/logs/
+ $(gen_verbose) $(CT_RUN) -suite $(addsuffix _SUITE,$(1)) $(CT_OPTS)
endef
$(foreach test,$(CT_SUITES),$(eval $(call ct_suite_target,$(test))))
-clean-ct:
- $(gen_verbose) rm -rf test/*.beam
-
distclean-ct:
- $(gen_verbose) rm -rf logs/
+ $(gen_verbose) rm -rf $(CURDIR)/logs/
diff --git a/plugins/dialyzer.mk b/plugins/dialyzer.mk
index 3482c1b..23d16ee 100644
--- a/plugins/dialyzer.mk
+++ b/plugins/dialyzer.mk
@@ -1,4 +1,4 @@
-# Copyright (c) 2013-2014, Loïc Hoguin <[email protected]>
+# Copyright (c) 2013-2015, Loïc Hoguin <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.
.PHONY: plt distclean-plt dialyze
@@ -15,6 +15,8 @@ DIALYZER_OPTS ?= -Werror_handling -Wrace_conditions \
# Core targets.
+check:: dialyze
+
distclean:: distclean-plt
help::
diff --git a/plugins/edoc.mk b/plugins/edoc.mk
index 5249d08..6f0a82d 100644
--- a/plugins/edoc.mk
+++ b/plugins/edoc.mk
@@ -1,7 +1,7 @@
-# Copyright (c) 2013-2014, Loïc Hoguin <[email protected]>
+# Copyright (c) 2013-2015, Loïc Hoguin <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.
-.PHONY: distclean-edoc
+.PHONY: distclean-edoc edoc
# Configuration.
@@ -9,13 +9,14 @@ EDOC_OPTS ?=
# Core targets.
-docs:: distclean-edoc
- $(gen_verbose) erl -noshell \
- -eval 'edoc:application($(PROJECT), ".", [$(EDOC_OPTS)]), init:stop().'
+docs:: distclean-edoc edoc
distclean:: distclean-edoc
# Plugin-specific targets.
+edoc: doc-deps
+ $(gen_verbose) $(ERL) -eval 'edoc:application($(PROJECT), ".", [$(EDOC_OPTS)]), halt().'
+
distclean-edoc:
$(gen_verbose) rm -f doc/*.css doc/*.html doc/*.png doc/edoc-info
diff --git a/plugins/elvis.mk b/plugins/elvis.mk
index f3e75a8..580e2f5 100644
--- a/plugins/elvis.mk
+++ b/plugins/elvis.mk
@@ -21,20 +21,18 @@ help::
"Elvis targets:" \
" elvis Run Elvis using the local elvis.config or download the default otherwise"
-ifneq ($(wildcard $(ELVIS_CONFIG)),)
-rel:: distclean-elvis
-endif
-
distclean:: distclean-elvis
# Plugin-specific targets.
$(ELVIS):
- @$(call core_http_get,$(ELVIS_CONFIG),$(ELVIS_CONFIG_URL))
@$(call core_http_get,$(ELVIS),$(ELVIS_URL))
@chmod +x $(ELVIS)
-elvis: $(ELVIS)
+$(ELVIS_CONFIG):
+ @$(call core_http_get,$(ELVIS_CONFIG),$(ELVIS_CONFIG_URL))
+
+elvis: $(ELVIS) $(ELVIS_CONFIG)
@$(ELVIS) rock -c $(ELVIS_CONFIG) $(ELVIS_OPTS)
distclean-elvis:
diff --git a/plugins/erlydtl.mk b/plugins/erlydtl.mk
index e288072..d65231d 100644
--- a/plugins/erlydtl.mk
+++ b/plugins/erlydtl.mk
@@ -1,6 +1,10 @@
-# Copyright (c) 2013-2014, Loïc Hoguin <[email protected]>
+# Copyright (c) 2013-2015, Loïc Hoguin <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.
+# Configuration.
+
+DTL_FULL_PATH ?= 0
+
# Verbosity.
dtl_verbose_0 = @echo " DTL " $(filter %.dtl,$(?F));
@@ -9,14 +13,16 @@ dtl_verbose = $(dtl_verbose_$(V))
# Core targets.
define compile_erlydtl
- $(dtl_verbose) erl -noshell -pa ebin/ $(DEPS_DIR)/erlydtl/ebin/ -eval ' \
+ $(dtl_verbose) $(ERL) -pa ebin/ $(DEPS_DIR)/erlydtl/ebin/ -eval ' \
Compile = fun(F) -> \
- Module = list_to_atom( \
- string:to_lower(filename:basename(F, ".dtl")) ++ "_dtl"), \
- erlydtl:compile(F, Module, [{out_dir, "ebin/"}]) \
+ S = fun (1) -> re:replace(filename:rootname(string:sub_string(F, 11), ".dtl"), "/", "_", [{return, list}, global]); \
+ (0) -> filename:basename(F, ".dtl") \
+ end, \
+ Module = list_to_atom(string:to_lower(S($(DTL_FULL_PATH))) ++ "_dtl"), \
+ {ok, _} = erlydtl:compile(F, Module, [{out_dir, "ebin/"}, return_errors, {doc_root, "templates"}]) \
end, \
_ = [Compile(F) || F <- string:tokens("$(1)", " ")], \
- init:stop()'
+ halt().'
endef
ifneq ($(wildcard src/),)
diff --git a/plugins/escript.mk b/plugins/escript.mk
index 5a6a0dd..534db61 100644
--- a/plugins/escript.mk
+++ b/plugins/escript.mk
@@ -11,7 +11,6 @@ ESCRIPT_COMMENT ?= This is an -*- erlang -*- file
ESCRIPT_BEAMS ?= "ebin/*", "deps/*/ebin/*"
ESCRIPT_SYS_CONFIG ?= "rel/sys.config"
ESCRIPT_EMU_ARGS ?= -pa . \
- -noshell -noinput \
-sasl errlog_type error \
-escript main $(ESCRIPT_NAME)
ESCRIPT_SHEBANG ?= /usr/bin/env escript
@@ -33,6 +32,7 @@ help::
# Modified MIT License, https://github.com/synrc/mad/blob/master/LICENSE :
# Software may only be used for the great good and the true happiness of all
# sentient beings.
+
define ESCRIPT_RAW
'Read = fun(F) -> {ok, B} = file:read_file(filename:absname(F)), B end,'\
'Files = fun(L) -> A = lists:concat([filelib:wildcard(X)||X<- L ]),'\
@@ -51,12 +51,14 @@ define ESCRIPT_RAW
' ]),'\
' file:change_mode(Escript, 8#755)'\
'end,'\
-'Ez("$(ESCRIPT_NAME)").'
+'Ez("$(ESCRIPT_NAME)"),'\
+'halt().'
endef
+
ESCRIPT_COMMAND = $(subst ' ',,$(ESCRIPT_RAW))
escript:: distclean-escript deps app
- $(gen_verbose) erl -noshell -eval $(ESCRIPT_COMMAND) -s init stop
+ $(gen_verbose) $(ERL) -eval $(ESCRIPT_COMMAND)
distclean-escript:
$(gen_verbose) rm -f $(ESCRIPT_NAME)
diff --git a/plugins/eunit.mk b/plugins/eunit.mk
index 75aab0c..b9f2856 100644
--- a/plugins/eunit.mk
+++ b/plugins/eunit.mk
@@ -1,29 +1,26 @@
# Copyright (c) 2014, Enrique Fernandez <[email protected]>
+# Copyright (c) 2015, Loïc Hoguin <[email protected]>
# This file is contributed to erlang.mk and subject to the terms of the ISC License.
-.PHONY: help-eunit build-eunit eunit distclean-eunit
+.PHONY: eunit
# Configuration
-EUNIT_ERLC_OPTS ?= +debug_info +warn_export_vars +warn_shadow_vars +warn_obsolete_guard -DTEST=1 -DEXTRA=1
-
-EUNIT_DIR ?=
-EUNIT_DIRS = $(sort $(EUNIT_DIR) ebin)
-
-ifeq ($(strip $(EUNIT_DIR)),)
-TAGGED_EUNIT_TESTS = {dir,"ebin"}
+# All modules in TEST_DIR
+ifeq ($(strip $(TEST_DIR)),)
+TEST_DIR_MODS =
else
-# All modules in EUNIT_DIR
-EUNIT_DIR_MODS = $(notdir $(basename $(shell find $(EUNIT_DIR) -type f -name *.beam)))
+TEST_DIR_MODS = $(notdir $(basename $(shell find $(TEST_DIR) -type f -name *.beam)))
+endif
+
# All modules in 'ebin'
EUNIT_EBIN_MODS = $(notdir $(basename $(shell find ebin -type f -name *.beam)))
-# Only those modules in EUNIT_DIR with no matching module in 'ebin'.
+# Only those modules in TEST_DIR with no matching module in 'ebin'.
# This is done to avoid some tests being executed twice.
-EUNIT_MODS = $(filter-out $(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(EUNIT_DIR_MODS))
-TAGGED_EUNIT_TESTS = {dir,"ebin"} $(foreach mod,$(EUNIT_MODS),$(shell echo $(mod) | sed -e 's/\(.*\)/{module,\1}/g'))
-endif
+EUNIT_MODS = $(filter-out $(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(TEST_DIR_MODS))
+TAGGED_EUNIT_TESTS = $(foreach mod,$(EUNIT_EBIN_MODS) $(EUNIT_MODS),{module,$(mod)})
-EUNIT_OPTS ?= verbose
+EUNIT_OPTS ?=
# Utility functions
@@ -33,39 +30,25 @@ endef
# Core targets.
-help:: help-eunit
-
tests:: eunit
-clean:: clean-eunit
-
-# Plugin-specific targets.
-
-EUNIT_RUN = erl \
- -no_auto_compile \
- -noshell \
- -pa $(realpath $(EUNIT_DIR)) $(DEPS_DIR)/*/ebin \
- -pz $(realpath ebin) \
- -eval 'case eunit:test([$(call str-join,$(TAGGED_EUNIT_TESTS))], [$(EUNIT_OPTS)]) of ok -> erlang:halt(0); error -> erlang:halt(1) end.'
-
-help-eunit:
+help::
@printf "%s\n" "" \
"EUnit targets:" \
" eunit Run all the EUnit tests for this project"
-ifeq ($(strip $(EUNIT_DIR)),)
-build-eunit:
-else ifeq ($(strip $(EUNIT_DIR)),ebin)
-build-eunit:
-else
-build-eunit:
- $(gen_verbose) erlc -v $(EUNIT_ERLC_OPTS) -I include/ -o $(EUNIT_DIR) \
- $(wildcard $(EUNIT_DIR)/*.erl $(EUNIT_DIR)/*/*.erl) -pa ebin/
-endif
+# Plugin-specific targets.
-eunit: ERLC_OPTS = $(EUNIT_ERLC_OPTS)
-eunit: clean deps app build-eunit
+EUNIT_RUN_BEFORE ?=
+EUNIT_RUN_AFTER ?=
+EUNIT_RUN = $(ERL) \
+ -pa $(TEST_DIR) $(DEPS_DIR)/*/ebin \
+ -pz ebin \
+ $(EUNIT_RUN_BEFORE) \
+ -eval 'case eunit:test([$(call str-join,$(TAGGED_EUNIT_TESTS))],\
+ [$(EUNIT_OPTS)]) of ok -> ok; error -> halt(1) end.' \
+ $(EUNIT_RUN_AFTER) \
+ -eval 'halt(0).'
+
+eunit: test-build
$(gen_verbose) $(EUNIT_RUN)
-
-clean-eunit:
- $(gen_verbose) $(foreach dir,$(EUNIT_DIRS),rm -rf $(dir)/*.beam)
diff --git a/plugins/relx.mk b/plugins/relx.mk
index ee226d3..e38c9d0 100644
--- a/plugins/relx.mk
+++ b/plugins/relx.mk
@@ -1,7 +1,7 @@
-# Copyright (c) 2013-2014, Loïc Hoguin <[email protected]>
+# Copyright (c) 2013-2015, Loïc Hoguin <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.
-.PHONY: relx-rel distclean-relx-rel distclean-relx
+.PHONY: relx-rel distclean-relx-rel distclean-relx run
# Configuration.
@@ -10,7 +10,7 @@ RELX_CONFIG ?= $(CURDIR)/relx.config
RELX ?= $(CURDIR)/relx
export RELX
-RELX_URL ?= https://github.com/erlware/relx/releases/download/v1.0.2/relx
+RELX_URL ?= https://github.com/erlware/relx/releases/download/v2.0.0/relx
RELX_OPTS ?=
RELX_OUTPUT_DIR ?= _rel
@@ -22,9 +22,11 @@ endif
# Core targets.
+ifeq ($(IS_DEP),)
ifneq ($(wildcard $(RELX_CONFIG)),)
rel:: distclean-relx-rel relx-rel
endif
+endif
distclean:: distclean-relx-rel distclean-relx
@@ -46,3 +48,28 @@ distclean-relx-rel:
distclean-relx:
$(gen_verbose) rm -rf $(RELX)
+
+# Run target.
+
+ifeq ($(wildcard $(RELX_CONFIG)),)
+run:
+else
+
+define get_relx_release.erl
+ {ok, Config} = file:consult("$(RELX_CONFIG)"),
+ {release, {Name, _}, _} = lists:keyfind(release, 1, Config),
+ io:format("~s", [Name]),
+ halt(0).
+endef
+
+RELX_RELEASE = `$(call erlang,$(get_relx_release.erl))`
+
+run: all
+ @$(RELX_OUTPUT_DIR)/$(RELX_RELEASE)/bin/$(RELX_RELEASE) console
+
+help::
+ @printf "%s\n" "" \
+ "Relx targets:" \
+ " run Compile the project, build the release and run it"
+
+endif
diff --git a/plugins/shell.mk b/plugins/shell.mk
index 4e7e97e..6636b92 100644
--- a/plugins/shell.mk
+++ b/plugins/shell.mk
@@ -15,7 +15,7 @@ ALL_SHELL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(SHELL_DEPS))
help::
@printf "%s\n" "" \
"Shell targets:" \
- " shell Run an erlang shell with SHELL_OPTS or reasonable default"
+ " shell Run an erlang shell with SHELL_OPTS or reasonable default"
# Plugin-specific targets.
diff --git a/plugins/triq.mk b/plugins/triq.mk
new file mode 100644
index 0000000..f487f8c
--- /dev/null
+++ b/plugins/triq.mk
@@ -0,0 +1,43 @@
+# Copyright (c) 2015, Loïc Hoguin <[email protected]>
+# This file is part of erlang.mk and subject to the terms of the ISC License.
+
+ifneq ($(wildcard $(DEPS_DIR)/triq),)
+.PHONY: triq
+
+# Targets.
+
+tests:: triq
+
+define triq_check.erl
+ code:add_pathsa(["$(CURDIR)/ebin", "$(DEPS_DIR)/*/ebin"]),
+ try
+ case $(1) of
+ all -> [true] =:= lists:usort([triq:check(M) || M <- [$(MODULES)]]);
+ module -> triq:check($(2));
+ function -> triq:check($(2))
+ end
+ of
+ true -> halt(0);
+ _ -> halt(1)
+ catch error:undef ->
+ io:format("Undefined property or module~n"),
+ halt(0)
+ end.
+endef
+
+ifdef t
+ifeq (,$(findstring :,$(t)))
+triq: test-build
+ @$(call erlang,$(call triq_check.erl,module,$(t)))
+else
+triq: test-build
+ @echo Testing $(t)/0
+ @$(call erlang,$(call triq_check.erl,function,$(t)()))
+endif
+else
+triq: test-build
+ $(eval MODULES := $(shell find ebin -type f -name \*.beam \
+ | sed "s/ebin\//'/;s/\.beam/',/" | sed '$$s/.$$//'))
+ $(gen_verbose) $(call erlang,$(call triq_check.erl,all,undefined))
+endif
+endif
diff --git a/plugins/xref.mk b/plugins/xref.mk
new file mode 100644
index 0000000..b6e4d92
--- /dev/null
+++ b/plugins/xref.mk
@@ -0,0 +1,38 @@
+# Copyright (c) 2015, Euen Lopez <[email protected]>
+# This file is part of erlang.mk and subject to the terms of the ISC License.
+
+.PHONY: xref distclean-xref
+
+# Configuration.
+
+ifeq ($(XREF_CONFIG),)
+ XREF_ARGS :=
+else
+ XREF_ARGS := -c $(XREF_CONFIG)
+endif
+
+XREFR ?= $(CURDIR)/xrefr
+export XREFR
+
+XREFR_URL ?= https://github.com/inaka/xref_runner/releases/download/0.2.0/xrefr
+
+# Core targets.
+
+help::
+ @printf "%s\n" "" \
+ "Xref targets:" \
+ " xref Run Xrefr using $XREF_CONFIG as config file if defined"
+
+distclean:: distclean-xref
+
+# Plugin-specific targets.
+
+$(XREFR):
+ @$(call core_http_get,$(XREFR),$(XREFR_URL))
+ @chmod +x $(XREFR)
+
+xref: deps app $(XREFR)
+ $(gen_verbose) $(XREFR) $(XREFR_ARGS)
+
+distclean-xref:
+ $(gen_verbose) rm -rf $(XREFR)