aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md76
-rw-r--r--build.config4
-rw-r--r--core/erlc.mk34
-rw-r--r--erlang.mk327
-rw-r--r--packages.v1.tsv5
-rw-r--r--packages.v1.txt5
-rw-r--r--packages.v2.tsv7
-rw-r--r--plugins/bootstrap.mk50
-rw-r--r--plugins/c_src.mk88
-rw-r--r--plugins/escript.mk62
-rw-r--r--plugins/eunit.mk71
-rw-r--r--plugins/shell.mk2
12 files changed, 685 insertions, 46 deletions
diff --git a/README.md b/README.md
index f0b55f5..583462c 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,17 @@ Common Makefile rules for building and testing Erlang applications.
Also features support for dependencies and a package index.
+Why erlang.mk?
+--------------
+
+A number of reasons might push someone to use erlang.mk instead of
+an Erlang-based build tool, including but not limited to the following:
+
+ * You want a very fast compilation and test cycle
+ * You want the full power of Unix at your disposal when hooking into your build tool
+ * You want to use the deps mechanism with non-Erlang Makefile-based projects
+ * Your project will be part of a larger make or automake based environment
+
Requirements
------------
@@ -215,6 +226,11 @@ variable. It takes the arguments that will then be passed to
You can specify a list of modules to be compiled first using
the `COMPILE_FIRST` variable.
+You can also use the `ERLC_EXCLUDE` variable to prevent some
+modules from being compiled by the core compiler. Note that
+`ERLC_EXCLUDE` is a list of module names (i.e., no file extension
+is required).
+
If `{id, "git"},` is found in your project's `.app.src`, the
extended output of `git describe ...` will replace it. This
can be retrieved at runtime via `application:get_key/2`.
@@ -252,12 +268,12 @@ templates.
`list-templates` lists the available templates.
-C compiler plugin
------------------
+C/C++ compiler plugin
+---------------------
-This plugin is not included by default. It is meant to
-simplify the management of projects that include C source
-code, like NIFs.
+This plugin is available by default. It is meant to
+simplify the management of projects that include C
+and/or C++ source code, like NIFs for example.
If the file `$(C_SRC_DIR)/Makefile` exists, then the plugin
simply calls it when needed. Otherwise it tries to compile
@@ -273,9 +289,9 @@ You can override the temporary file containing information
about Erlang's environment by setting the `C_SRC_ENV` variable.
This file is automatically generated on first run.
-Finally you can add extra compiler options using the
-`C_SRC_OPTS` variable. You can also override the defaults
-`CC` and `CFLAGS` if required.
+The `CC`, `CXX`, `CFLAGS`, `CXXFLAGS`, `LDLIBS` and `LDFLAGS` variables
+may be modified or replaced with any value of your choosing.
+The defaults are system dependent.
Common_test plugin
------------------
@@ -360,6 +376,50 @@ subdirectories names in the compiled module name add
will be compiled into `a_b_templatename_dtl.beam`.
+Escript plugin
+--------------
+
+This plugin is available by default. It adds the following
+target:
+
+`escript` which creates a shell-executable archive named
+the same as your `$(PROJECT)`, containing the following files
+from your application and its dependencies:
+
+* `*.beam`
+* contents of `priv/`
+* `sys.config` for your application
+
+There are a number of optional configuration parameters:
+
+* `ESCRIPT_NAME` if a different output file is required
+* `ESCRIPT_COMMENT` to alter the comment line in the escript header
+* `ESCRIPT_BEAMS` for the paths searched for `*.beam` files to include
+* `ESCRIPT_SYS_CONFIG` defaults to `rel/sys.config`
+* `ESCRIPT_EMU_ARGS` for the parameters used to start the VM
+* `ESCRIPT_SHEBANG` for the line used by your shell to start `escript`
+* `ESCRIPT_STATIC` for non-beam directories to be included as well
+
+Refer to http://www.erlang.org/doc/man/escript.html for
+more information on `escript` functionality in general.
+
+EUnit plugin
+------------
+
+This plugin is available by default. It adds the following
+target:
+
+`eunit` which runs all the EUnit tests found in `ebin` and
+any of the additional EUnit directories specified in
+`EUNIT_DIR`.
+
+`EUNIT_OPTS` can be used to specify EUnit-specific options
+(e.g. `verbose`) that will be used when calling
+`eunit:test/2`. This configuration parameter defaults to
+`verbose`. Note
+that EUnit options are specified as a comma-separated
+list of options.
+
Relx plugin
-----------
diff --git a/build.config b/build.config
index 9df8520..8b6e721 100644
--- a/build.config
+++ b/build.config
@@ -10,11 +10,13 @@ core/erlc
#
# Comment to disable, uncomment to enable.
plugins/bootstrap
-#plugins/c_src
+plugins/c_src
plugins/ct
plugins/dialyzer
plugins/edoc
plugins/elvis
plugins/erlydtl
+plugins/escript
+plugins/eunit
plugins/relx
plugins/shell
diff --git a/core/erlc.mk b/core/erlc.mk
index a7f73f8..8d720aa 100644
--- a/core/erlc.mk
+++ b/core/erlc.mk
@@ -5,22 +5,32 @@
# Configuration.
-ERLC_OPTS ?= -Werror +debug_info +warn_export_all +warn_export_vars \
- +warn_shadow_vars +warn_obsolete_guard # +bin_opt_info +warn_missing_spec
+ERLC_OPTS ?= -Werror +debug_info +warn_export_vars +warn_shadow_vars \
+ +warn_obsolete_guard # +bin_opt_info +warn_export_all +warn_missing_spec
COMPILE_FIRST ?=
COMPILE_FIRST_PATHS = $(addprefix src/,$(addsuffix .erl,$(COMPILE_FIRST)))
+ERLC_EXCLUDE ?=
+ERLC_EXCLUDE_PATHS = $(addprefix src/,$(addsuffix .erl,$(ERLC_EXCLUDE)))
+
+ERLC_MIB_OPTS ?=
+COMPILE_MIB_FIRST ?=
+COMPILE_MIB_FIRST_PATHS = $(addprefix mibs/,$(addsuffix .mib,$(COMPILE_MIB_FIRST)))
# Verbosity.
appsrc_verbose_0 = @echo " APP " $(PROJECT).app.src;
appsrc_verbose = $(appsrc_verbose_$(V))
-erlc_verbose_0 = @echo " ERLC " $(filter %.erl %.core,$(?F));
+erlc_verbose_0 = @echo " ERLC " $(filter-out $(patsubst %,%.erl,$(ERLC_EXCLUDE)),\
+ $(filter %.erl %.core,$(?F)));
erlc_verbose = $(erlc_verbose_$(V))
xyrl_verbose_0 = @echo " XYRL " $(filter %.xrl %.yrl,$(?F));
xyrl_verbose = $(xyrl_verbose_$(V))
+mib_verbose_0 = @echo " MIB " $(filter %.bin %.mib,$(?F));
+mib_verbose = $(mib_verbose_$(V))
+
# Core targets.
app:: erlc-include ebin/$(PROJECT).app
@@ -38,7 +48,8 @@ app:: erlc-include ebin/$(PROJECT).app
define compile_erl
$(erlc_verbose) erlc -v $(ERLC_OPTS) -o ebin/ \
- -pa ebin/ -I include/ $(COMPILE_FIRST_PATHS) $(1)
+ -pa ebin/ -I include/ $(filter-out $(ERLC_EXCLUDE_PATHS),\
+ $(COMPILE_FIRST_PATHS) $(1))
endef
define compile_xyrl
@@ -47,10 +58,22 @@ define compile_xyrl
@rm ebin/*.erl
endef
+define compile_mib
+ $(mib_verbose) erlc -v $(ERLC_MIB_OPTS) -o priv/mibs/ \
+ -I priv/mibs/ $(COMPILE_MIB_FIRST_PATHS) $(1)
+ $(mib_verbose) erlc -o include/ -- priv/mibs/*.bin
+endef
+
ifneq ($(wildcard src/),)
ebin/$(PROJECT).app::
@mkdir -p ebin/
+ifneq ($(wildcard mibs/),)
+ebin/$(PROJECT).app:: $(shell find mibs -type f -name \*.mib)
+ @mkdir -p priv/mibs/ include
+ $(if $(strip $?),$(call compile_mib,$?))
+endif
+
ebin/$(PROJECT).app:: $(shell find src -type f -name \*.erl) \
$(shell find src -type f -name \*.core)
$(if $(strip $?),$(call compile_erl,$?))
@@ -70,4 +93,5 @@ erlc-include:
fi
clean-app:
- $(gen_verbose) rm -rf ebin/
+ $(gen_verbose) rm -rf ebin/ priv/mibs/ \
+ $(addprefix include/,$(addsuffix .hrl,$(notdir $(basename $(wildcard mibs/*.mib)))))
diff --git a/erlang.mk b/erlang.mk
index d3e120c..fa52243 100644
--- a/erlang.mk
+++ b/erlang.mk
@@ -206,22 +206,32 @@ help::
# Configuration.
-ERLC_OPTS ?= -Werror +debug_info +warn_export_all +warn_export_vars \
- +warn_shadow_vars +warn_obsolete_guard # +bin_opt_info +warn_missing_spec
+ERLC_OPTS ?= -Werror +debug_info +warn_export_vars +warn_shadow_vars \
+ +warn_obsolete_guard # +bin_opt_info +warn_export_all +warn_missing_spec
COMPILE_FIRST ?=
COMPILE_FIRST_PATHS = $(addprefix src/,$(addsuffix .erl,$(COMPILE_FIRST)))
+ERLC_EXCLUDE ?=
+ERLC_EXCLUDE_PATHS = $(addprefix src/,$(addsuffix .erl,$(ERLC_EXCLUDE)))
+
+ERLC_MIB_OPTS ?=
+COMPILE_MIB_FIRST ?=
+COMPILE_MIB_FIRST_PATHS = $(addprefix mibs/,$(addsuffix .mib,$(COMPILE_MIB_FIRST)))
# Verbosity.
appsrc_verbose_0 = @echo " APP " $(PROJECT).app.src;
appsrc_verbose = $(appsrc_verbose_$(V))
-erlc_verbose_0 = @echo " ERLC " $(filter %.erl %.core,$(?F));
+erlc_verbose_0 = @echo " ERLC " $(filter-out $(patsubst %,%.erl,$(ERLC_EXCLUDE)),\
+ $(filter %.erl %.core,$(?F)));
erlc_verbose = $(erlc_verbose_$(V))
xyrl_verbose_0 = @echo " XYRL " $(filter %.xrl %.yrl,$(?F));
xyrl_verbose = $(xyrl_verbose_$(V))
+mib_verbose_0 = @echo " MIB " $(filter %.bin %.mib,$(?F));
+mib_verbose = $(mib_verbose_$(V))
+
# Core targets.
app:: erlc-include ebin/$(PROJECT).app
@@ -239,7 +249,8 @@ app:: erlc-include ebin/$(PROJECT).app
define compile_erl
$(erlc_verbose) erlc -v $(ERLC_OPTS) -o ebin/ \
- -pa ebin/ -I include/ $(COMPILE_FIRST_PATHS) $(1)
+ -pa ebin/ -I include/ $(filter-out $(ERLC_EXCLUDE_PATHS),\
+ $(COMPILE_FIRST_PATHS) $(1))
endef
define compile_xyrl
@@ -248,10 +259,22 @@ define compile_xyrl
@rm ebin/*.erl
endef
+define compile_mib
+ $(mib_verbose) erlc -v $(ERLC_MIB_OPTS) -o priv/mibs/ \
+ -I priv/mibs/ $(COMPILE_MIB_FIRST_PATHS) $(1)
+ $(mib_verbose) erlc -o include/ -- priv/mibs/*.bin
+endef
+
ifneq ($(wildcard src/),)
ebin/$(PROJECT).app::
@mkdir -p ebin/
+ifneq ($(wildcard mibs/),)
+ebin/$(PROJECT).app:: $(shell find mibs -type f -name \*.mib)
+ @mkdir -p priv/mibs/ include
+ $(if $(strip $?),$(call compile_mib,$?))
+endif
+
ebin/$(PROJECT).app:: $(shell find src -type f -name \*.erl) \
$(shell find src -type f -name \*.core)
$(if $(strip $?),$(call compile_erl,$?))
@@ -271,7 +294,8 @@ erlc-include:
fi
clean-app:
- $(gen_verbose) rm -rf ebin/
+ $(gen_verbose) rm -rf ebin/ priv/mibs/ \
+ $(addprefix include/,$(addsuffix .hrl,$(notdir $(basename $(wildcard mibs/*.mib)))))
# Copyright (c) 2014, Loïc Hoguin <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.
@@ -392,6 +416,56 @@ tpl_gen_server = "-module($(n))." \
"" \
"code_change(_OldVsn, State, _Extra) ->" \
" {ok, State}."
+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}."
tpl_cowboy_http = "-module($(n))." \
"-behaviour(cowboy_http_handler)." \
"" \
@@ -551,6 +625,112 @@ endif
list-templates:
@echo Available templates: $(sort $(patsubst tpl_%,%,$(filter tpl_%,$(.VARIABLES))))
+# Copyright (c) 2014, 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.
+
+C_SRC_DIR = $(CURDIR)/c_src
+C_SRC_ENV ?= $(C_SRC_DIR)/env.mk
+C_SRC_OUTPUT ?= $(CURDIR)/priv/$(PROJECT).so
+
+# System type and C compiler/flags.
+
+UNAME_SYS := $(shell uname -s)
+ifeq ($(UNAME_SYS), Darwin)
+ CC ?= cc
+ CFLAGS ?= -O3 -std=c99 -arch x86_64 -finline-functions -Wall -Wmissing-prototypes
+ CXXFLAGS ?= -O3 -arch x86_64 -finline-functions -Wall
+ LDFLAGS ?= -arch x86_64 -flat_namespace -undefined suppress
+else ifeq ($(UNAME_SYS), FreeBSD)
+ CC ?= cc
+ CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
+ CXXFLAGS ?= -O3 -finline-functions -Wall
+else ifeq ($(UNAME_SYS), Linux)
+ CC ?= gcc
+ CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
+ CXXFLAGS ?= -O3 -finline-functions -Wall
+endif
+
+CFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
+CXXFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
+
+LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lerl_interface -lei
+LDFLAGS += -shared
+
+# Verbosity.
+
+c_verbose_0 = @echo " C " $(?F);
+c_verbose = $(c_verbose_$(V))
+
+cpp_verbose_0 = @echo " CPP " $(?F);
+cpp_verbose = $(cpp_verbose_$(V))
+
+link_verbose_0 = @echo " LD " $(@F);
+link_verbose = $(link_verbose_$(V))
+
+# Targets.
+
+ifeq ($(wildcard $(C_SRC_DIR)),)
+else ifneq ($(wildcard $(C_SRC_DIR)/Makefile),)
+app::
+ $(MAKE) -C $(C_SRC_DIR)
+
+clean::
+ $(MAKE) -C $(C_SRC_DIR) clean
+
+else
+SOURCES := $(shell find $(C_SRC_DIR) -type f \( -name "*.c" -o -name "*.C" -o -name "*.cc" -o -name "*.cpp" \))
+OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))
+
+COMPILE_C = $(c_verbose) $(CC) $(CFLAGS) $(CPPFLAGS) -c
+COMPILE_CPP = $(cpp_verbose) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c
+
+app:: $(C_SRC_ENV) $(C_SRC_OUTPUT)
+
+$(C_SRC_OUTPUT): $(OBJECTS)
+ @mkdir -p priv/
+ $(link_verbose) $(CC) $(OBJECTS) $(LDFLAGS) $(LDLIBS) -o $(C_SRC_OUTPUT)
+
+%.o: %.c
+ $(COMPILE_C) $(OUTPUT_OPTION) $<
+
+%.o: %.cc
+ $(COMPILE_CPP) $(OUTPUT_OPTION) $<
+
+%.o: %.C
+ $(COMPILE_CPP) $(OUTPUT_OPTION) $<
+
+%.o: %.cpp
+ $(COMPILE_CPP) $(OUTPUT_OPTION) $<
+
+$(C_SRC_ENV):
+ @erl -noshell -noinput -eval "file:write_file(\"$(C_SRC_ENV)\", \
+ io_lib:format( \
+ \"ERTS_INCLUDE_DIR ?= ~s/erts-~s/include/~n\" \
+ \"ERL_INTERFACE_INCLUDE_DIR ?= ~s~n\" \
+ \"ERL_INTERFACE_LIB_DIR ?= ~s~n\", \
+ [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)
+
+distclean:: distclean-c_src-env
+
+distclean-c_src-env:
+ $(gen_verbose) rm -f $(C_SRC_ENV)
+
+-include $(C_SRC_ENV)
+endif
+
# Copyright (c) 2013-2014, Loïc Hoguin <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.
@@ -767,6 +947,141 @@ ebin/$(PROJECT).app:: $(shell find templates -type f -name \*.dtl 2>/dev/null)
$(if $(strip $?),$(call compile_erlydtl,$?))
endif
+# Copyright (c) 2014 Dave Cottlehuber <[email protected]>
+# This file is part of erlang.mk and subject to the terms of the ISC License.
+
+.PHONY: distclean-escript escript
+
+# Configuration.
+
+ESCRIPT_NAME ?= $(PROJECT)
+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
+ESCRIPT_STATIC ?= "deps/*/priv/**", "priv/**"
+
+# Core targets.
+
+distclean:: distclean-escript
+
+help::
+ @printf "%s\n" "" \
+ "Escript targets:" \
+ " escript Build an executable escript archive" \
+
+# Plugin-specific targets.
+
+# Based on https://github.com/synrc/mad/blob/master/src/mad_bundle.erl
+# Copyright (c) 2013 Maxim Sokhatsky, Synrc Research Center
+# 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 ]),'\
+' [F || F <- A, not filelib:is_dir(F) ] end,'\
+'Squash = fun(L) -> [{filename:basename(F), Read(F) } || F <- L ] end,'\
+'Zip = fun(A, L) -> {ok,{_,Z}} = zip:create(A, L, [{compress,all},memory]), Z end,'\
+'Ez = fun(Escript) ->'\
+' Static = Files([$(ESCRIPT_STATIC)]),'\
+' Beams = Squash(Files([$(ESCRIPT_BEAMS), $(ESCRIPT_SYS_CONFIG)])),'\
+' Archive = Beams ++ [{ "static.gz", Zip("static.gz", Static)}],'\
+' escript:create(Escript, [ $(ESCRIPT_OPTIONS)'\
+' {archive, Archive, [memory]},'\
+' {shebang, "$(ESCRIPT_SHEBANG)"},'\
+' {comment, "$(ESCRIPT_COMMENT)"},'\
+' {emu_args, " $(ESCRIPT_EMU_ARGS)"}'\
+' ]),'\
+' file:change_mode(Escript, 8#755)'\
+'end,'\
+'Ez("$(ESCRIPT_NAME)").'
+endef
+ESCRIPT_COMMAND = $(subst ' ',,$(ESCRIPT_RAW))
+
+escript:: distclean-escript deps app
+ $(gen_verbose) erl -noshell -eval $(ESCRIPT_COMMAND) -s init stop
+
+distclean-escript:
+ $(gen_verbose) rm -f $(ESCRIPT_NAME)
+
+# Copyright (c) 2014, Enrique Fernandez <[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
+
+# 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"}
+else
+# All modules in EUNIT_DIR
+EUNIT_DIR_MODS = $(notdir $(basename $(shell find $(EUNIT_DIR) -type f -name *.beam)))
+# 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'.
+# 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_OPTS ?= verbose
+
+# Utility functions
+
+define str-join
+ $(shell echo '$(strip $(1))' | sed -e "s/ /,/g")
+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:
+ @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
+
+eunit: ERLC_OPTS = $(EUNIT_ERLC_OPTS)
+eunit: clean deps app build-eunit
+ $(gen_verbose) $(EUNIT_RUN)
+
+clean-eunit:
+ $(gen_verbose) $(foreach dir,$(EUNIT_DIRS),rm -rf $(dir)/*.beam)
+
# Copyright (c) 2013-2014, Loïc Hoguin <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.
@@ -823,7 +1138,7 @@ distclean-relx:
# Configuration.
-SHELL_PATH ?= -pa ../$(PROJECT)/ebin $(DEPS_DIR)/*/ebin
+SHELL_PATH ?= -pa $(CURDIR)/ebin $(DEPS_DIR)/*/ebin
SHELL_OPTS ?=
ALL_SHELL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(SHELL_DEPS))
diff --git a/packages.v1.tsv b/packages.v1.tsv
index 2e2e2e6..6916e1e 100644
--- a/packages.v1.tsv
+++ b/packages.v1.tsv
@@ -23,17 +23,21 @@ erwa https://github.com/bwegh/erwa https://github.com/bwegh/erwa A WAMP router a
exs1024 https://github.com/jj1bdx/exs1024 https://github.com/jj1bdx/exs1024 Xorshift1024star pseudo random number generator for Erlang.
exs64 https://github.com/jj1bdx/exs64 https://github.com/jj1bdx/exs64 Xorshift64star pseudo random number generator for Erlang.
exsplus https://github.com/jj1bdx/exsplus https://github.com/jj1bdx/exsplus Xorshift128plus pseudo random number generator for Erlang.
+feeder https://github.com/michaelnisi/feeder https://github.com/michaelnisi/feeder Stream parse RSS and Atom formatted XML feeds.
getopt https://github.com/jcomellas/getopt.git https://github.com/jcomellas/getopt Module to parse command line arguments using the GNU getopt syntax
gproc https://github.com/uwiger/gproc.git https://github.com/uwiger/gproc Extended process registry for Erlang
gun https://github.com/extend/gun http//ninenines.eu Asynchronous SPDY, HTTP and Websocket client written in Erlang.
+hanoidb https://github.com/krestenkrab/hanoidb https://github.com/krestenkrab/hanoidb Erlang LSM BTree Storage
ibrowse https://github.com/cmullaparthi/ibrowse https://github.com/cmullaparthi/ibrowse Erlang HTTP client
itweet https://github.com/inaka/itweet.git http://inaka.github.com/itweet/ Twitter Stream API on ibrowse
jiffy https://github.com/davisp/jiffy https://github.com/davisp/jiffy JSON NIFs for Erlang.
+jiffy_v https://github.com/shizzard/jiffy-v https://github.com/shizzard/jiffy-v JSON validation utility
jsx https://github.com/talentdeficit/jsx https://github.com/talentdeficit/jsx An Erlang application for consuming, producing and manipulating JSON.
katja https://github.com/nifoc/katja https://github.com/nifoc/katja A simple Riemann client written in Erlang.
lager https://github.com/basho/lager https://github.com/basho/lager A logging framework for Erlang/OTP.
lasse https://github.com/inaka/lasse.git https://github.com/inaka/lasse.git SSE handler for Cowboy
leptus https://github.com/s1n4/leptus https://github.com/s1n4/leptus Erlang REST framework
+live https://github.com/ninenines/live http://ninenines.eu Automated module and configuration reloader.
mekao https://github.com/ddosia/mekao.git https://github.com/ddosia/mekao SQL constructor
modlib https://github.com/gar1t/modlib.git https://github.com/gar1t/modlib Web framework based on Erlang's inets httpd
neo4j https://github.com/dmitriid/neo4j-erlang https://github.com/dmitriid/neo4j-erlang Erlang client library for Neo4J.
@@ -52,4 +56,5 @@ swab https://github.com/crownedgrouse/swab.git https://github.com/crownedgrouse/
sync https://github.com/rustyio/sync.git https://github.com/rustyio/sync On-the-fly recompiling and reloading in Erlang.
tddreloader https://github.com/version2beta/tddreloader https://github.com/version2beta/tddreloader Shell utility for recompiling, reloading, and testing code as it changes
tinymt-erlang https://github.com/jj1bdx/tinymt-erlang https://github.com/jj1bdx/tinymt-erlang TinyMT pseudo random number generator for Erlang.
+unicorn https://github.com/shizzard/unicorn https://github.com/shizzard/unicorn Generic configuration server
zeta https://github.com/s1n4/zeta https://github.com/s1n4/zeta HTTP access log parser in Erlang
diff --git a/packages.v1.txt b/packages.v1.txt
index 2e2e2e6..6916e1e 100644
--- a/packages.v1.txt
+++ b/packages.v1.txt
@@ -23,17 +23,21 @@ erwa https://github.com/bwegh/erwa https://github.com/bwegh/erwa A WAMP router a
exs1024 https://github.com/jj1bdx/exs1024 https://github.com/jj1bdx/exs1024 Xorshift1024star pseudo random number generator for Erlang.
exs64 https://github.com/jj1bdx/exs64 https://github.com/jj1bdx/exs64 Xorshift64star pseudo random number generator for Erlang.
exsplus https://github.com/jj1bdx/exsplus https://github.com/jj1bdx/exsplus Xorshift128plus pseudo random number generator for Erlang.
+feeder https://github.com/michaelnisi/feeder https://github.com/michaelnisi/feeder Stream parse RSS and Atom formatted XML feeds.
getopt https://github.com/jcomellas/getopt.git https://github.com/jcomellas/getopt Module to parse command line arguments using the GNU getopt syntax
gproc https://github.com/uwiger/gproc.git https://github.com/uwiger/gproc Extended process registry for Erlang
gun https://github.com/extend/gun http//ninenines.eu Asynchronous SPDY, HTTP and Websocket client written in Erlang.
+hanoidb https://github.com/krestenkrab/hanoidb https://github.com/krestenkrab/hanoidb Erlang LSM BTree Storage
ibrowse https://github.com/cmullaparthi/ibrowse https://github.com/cmullaparthi/ibrowse Erlang HTTP client
itweet https://github.com/inaka/itweet.git http://inaka.github.com/itweet/ Twitter Stream API on ibrowse
jiffy https://github.com/davisp/jiffy https://github.com/davisp/jiffy JSON NIFs for Erlang.
+jiffy_v https://github.com/shizzard/jiffy-v https://github.com/shizzard/jiffy-v JSON validation utility
jsx https://github.com/talentdeficit/jsx https://github.com/talentdeficit/jsx An Erlang application for consuming, producing and manipulating JSON.
katja https://github.com/nifoc/katja https://github.com/nifoc/katja A simple Riemann client written in Erlang.
lager https://github.com/basho/lager https://github.com/basho/lager A logging framework for Erlang/OTP.
lasse https://github.com/inaka/lasse.git https://github.com/inaka/lasse.git SSE handler for Cowboy
leptus https://github.com/s1n4/leptus https://github.com/s1n4/leptus Erlang REST framework
+live https://github.com/ninenines/live http://ninenines.eu Automated module and configuration reloader.
mekao https://github.com/ddosia/mekao.git https://github.com/ddosia/mekao SQL constructor
modlib https://github.com/gar1t/modlib.git https://github.com/gar1t/modlib Web framework based on Erlang's inets httpd
neo4j https://github.com/dmitriid/neo4j-erlang https://github.com/dmitriid/neo4j-erlang Erlang client library for Neo4J.
@@ -52,4 +56,5 @@ swab https://github.com/crownedgrouse/swab.git https://github.com/crownedgrouse/
sync https://github.com/rustyio/sync.git https://github.com/rustyio/sync On-the-fly recompiling and reloading in Erlang.
tddreloader https://github.com/version2beta/tddreloader https://github.com/version2beta/tddreloader Shell utility for recompiling, reloading, and testing code as it changes
tinymt-erlang https://github.com/jj1bdx/tinymt-erlang https://github.com/jj1bdx/tinymt-erlang TinyMT pseudo random number generator for Erlang.
+unicorn https://github.com/shizzard/unicorn https://github.com/shizzard/unicorn Generic configuration server
zeta https://github.com/s1n4/zeta https://github.com/s1n4/zeta HTTP access log parser in Erlang
diff --git a/packages.v2.tsv b/packages.v2.tsv
index 6fadc33..d405aac 100644
--- a/packages.v2.tsv
+++ b/packages.v2.tsv
@@ -23,17 +23,21 @@ erwa git https://github.com/bwegh/erwa master https://github.com/bwegh/erwa A WA
exs1024 git https://github.com/jj1bdx/exs1024 master https://github.com/jj1bdx/exs1024 Xorshift1024star pseudo random number generator for Erlang.
exs64 git https://github.com/jj1bdx/exs64 master https://github.com/jj1bdx/exs64 Xorshift64star pseudo random number generator for Erlang.
exsplus git https://github.com/jj1bdx/exsplus master https://github.com/jj1bdx/exsplus Xorshift128plus pseudo random number generator for Erlang.
+feeder git https://github.com/michaelnisi/feeder 1.4.2 https://github.com/michaelnisi/feeder Stream parse RSS and Atom formatted XML feeds.
getopt git https://github.com/jcomellas/getopt.git master https://github.com/jcomellas/getopt Module to parse command line arguments using the GNU getopt syntax
gproc git https://github.com/uwiger/gproc.git master https://github.com/uwiger/gproc Extended process registry for Erlang
gun git https://github.com/extend/gun master http//ninenines.eu Asynchronous SPDY, HTTP and Websocket client written in Erlang.
+hanoidb git https://github.com/krestenkrab/hanoidb master https://github.com/krestenkrab/hanoidb Erlang LSM BTree Storage
ibrowse git https://github.com/cmullaparthi/ibrowse v4.1.1 https://github.com/cmullaparthi/ibrowse Erlang HTTP client
itweet git https://github.com/inaka/itweet.git 3.0 http://inaka.github.com/itweet/ Twitter Stream API on ibrowse
jiffy git https://github.com/davisp/jiffy master https://github.com/davisp/jiffy JSON NIFs for Erlang.
+jiffy_v git https://github.com/shizzard/jiffy-v 0.3.3 https://github.com/shizzard/jiffy-v JSON validation utility
jsx git https://github.com/talentdeficit/jsx master https://github.com/talentdeficit/jsx An Erlang application for consuming, producing and manipulating JSON.
katja git https://github.com/nifoc/katja master https://github.com/nifoc/katja A simple Riemann client written in Erlang.
lager git https://github.com/basho/lager master https://github.com/basho/lager A logging framework for Erlang/OTP.
lasse git https://github.com/inaka/lasse.git 0.1.0 https://github.com/inaka/lasse.git SSE handler for Cowboy
leptus git https://github.com/s1n4/leptus https://github.com/s1n4/leptus Erlang REST framework
+live git https://github.com/ninenines/live master http://ninenines.eu Automated module and configuration reloader.
mekao git https://github.com/ddosia/mekao.git master https://github.com/ddosia/mekao SQL constructor
modlib git https://github.com/gar1t/modlib.git master https://github.com/gar1t/modlib Web framework based on Erlang's inets httpd
neo4j git https://github.com/dmitriid/neo4j-erlang master https://github.com/dmitriid/neo4j-erlang Erlang client library for Neo4J.
@@ -46,10 +50,11 @@ ranch git https://github.com/ninenines/ranch 1.1.0 http://ninenines.eu Socket ac
resource_discovery git https://github.com/erlware/resource_discovery master http://erlware.org/ An application used to dynamically discover resources present in an Erlang node cluster.
sfmt-erlang git https://github.com/jj1bdx/sfmt-erlang master https://github.com/jj1bdx/sfmt-erlang SFMT pseudo random number generator for Erlang.
sheriff git https://github.com/extend/sheriff master http://ninenines.eu Parse transform for type based validation.
-shotgun git https://github.com/inaka/shotgun.git 0.1 https://github.com/inaka/shotgun.git better than just a gun
+shotgun git https://github.com/inaka/shotgun.git 0.1.0 https://github.com/inaka/shotgun.git better than just a gun
sumo_db git https://github.com/inaka/sumo_db.git 1 https://github.com/inaka/sumo_db.git Erlang Persistency Framework
swab git https://github.com/crownedgrouse/swab.git master https://github.com/crownedgrouse/swab General purpose buffer handling module
sync git https://github.com/rustyio/sync.git master https://github.com/rustyio/sync On-the-fly recompiling and reloading in Erlang.
tddreloader git https://github.com/version2beta/tddreloader master https://github.com/version2beta/tddreloader Shell utility for recompiling, reloading, and testing code as it changes
tinymt-erlang git https://github.com/jj1bdx/tinymt-erlang master https://github.com/jj1bdx/tinymt-erlang TinyMT pseudo random number generator for Erlang.
+unicorn git https://github.com/shizzard/unicorn 0.3.0 https://github.com/shizzard/unicorn Generic configuration server
zeta git https://github.com/s1n4/zeta https://github.com/s1n4/zeta HTTP access log parser in Erlang
diff --git a/plugins/bootstrap.mk b/plugins/bootstrap.mk
index 9397253..0829de3 100644
--- a/plugins/bootstrap.mk
+++ b/plugins/bootstrap.mk
@@ -117,6 +117,56 @@ tpl_gen_server = "-module($(n))." \
"" \
"code_change(_OldVsn, State, _Extra) ->" \
" {ok, State}."
+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}."
tpl_cowboy_http = "-module($(n))." \
"-behaviour(cowboy_http_handler)." \
"" \
diff --git a/plugins/c_src.mk b/plugins/c_src.mk
index 2004b2d..7c1fd2e 100644
--- a/plugins/c_src.mk
+++ b/plugins/c_src.mk
@@ -1,14 +1,13 @@
# Copyright (c) 2014, 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
+.PHONY: clean-c_src distclean-c_src-env
# todo
# Configuration.
C_SRC_DIR = $(CURDIR)/c_src
C_SRC_ENV ?= $(C_SRC_DIR)/env.mk
-C_SRC_OPTS ?=
C_SRC_OUTPUT ?= $(CURDIR)/priv/$(PROJECT).so
# System type and C compiler/flags.
@@ -16,50 +15,91 @@ C_SRC_OUTPUT ?= $(CURDIR)/priv/$(PROJECT).so
UNAME_SYS := $(shell uname -s)
ifeq ($(UNAME_SYS), Darwin)
CC ?= cc
- CFLAGS ?= -O3 -std=c99 -arch x86_64 -flat_namespace -undefined suppress -finline-functions -Wall -Wmissing-prototypes
+ CFLAGS ?= -O3 -std=c99 -arch x86_64 -finline-functions -Wall -Wmissing-prototypes
+ CXXFLAGS ?= -O3 -arch x86_64 -finline-functions -Wall
+ LDFLAGS ?= -arch x86_64 -flat_namespace -undefined suppress
else ifeq ($(UNAME_SYS), FreeBSD)
CC ?= cc
CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
+ CXXFLAGS ?= -O3 -finline-functions -Wall
else ifeq ($(UNAME_SYS), Linux)
CC ?= gcc
CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
+ CXXFLAGS ?= -O3 -finline-functions -Wall
endif
-# Verbosity.
+CFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
+CXXFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
-c_src_verbose_0 = @echo " C_SRC " $(?F);
-c_src_verbose = $(appsrc_verbose_$(V))
+LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lerl_interface -lei
+LDFLAGS += -shared
-# Targets.
+# Verbosity.
-ifeq ($(wildcard $(C_SRC_DIR)/Makefile),)
+c_verbose_0 = @echo " C " $(?F);
+c_verbose = $(c_verbose_$(V))
-app:: $(C_SRC_ENV)
- @mkdir -p priv/
- $(c_src_verbose) $(CC) $(CFLAGS) $(C_SRC_DIR)/*.c -fPIC -shared -o $(C_SRC_OUTPUT) \
- -I $(ERTS_INCLUDE_DIR) $(C_SRC_OPTS)
+cpp_verbose_0 = @echo " CPP " $(?F);
+cpp_verbose = $(cpp_verbose_$(V))
-$(C_SRC_ENV):
- erl -noshell -noinput -eval "file:write_file(\"$(C_SRC_ENV)\", \
- io_lib:format(\"ERTS_INCLUDE_DIR ?= ~s/erts-~s/include/\", \
- [code:root_dir(), erlang:system_info(version)])), \
- init:stop()."
-
--include $(C_SRC_ENV)
+link_verbose_0 = @echo " LD " $(@F);
+link_verbose = $(link_verbose_$(V))
-else
-ifneq ($(wildcard $(C_SRC_DIR)),)
+# Targets.
+ifeq ($(wildcard $(C_SRC_DIR)),)
+else ifneq ($(wildcard $(C_SRC_DIR)/Makefile),)
app::
$(MAKE) -C $(C_SRC_DIR)
clean::
$(MAKE) -C $(C_SRC_DIR) clean
-endif
-endif
+else
+SOURCES := $(shell find $(C_SRC_DIR) -type f \( -name "*.c" -o -name "*.C" -o -name "*.cc" -o -name "*.cpp" \))
+OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))
+
+COMPILE_C = $(c_verbose) $(CC) $(CFLAGS) $(CPPFLAGS) -c
+COMPILE_CPP = $(cpp_verbose) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c
+
+app:: $(C_SRC_ENV) $(C_SRC_OUTPUT)
+
+$(C_SRC_OUTPUT): $(OBJECTS)
+ @mkdir -p priv/
+ $(link_verbose) $(CC) $(OBJECTS) $(LDFLAGS) $(LDLIBS) -o $(C_SRC_OUTPUT)
+
+%.o: %.c
+ $(COMPILE_C) $(OUTPUT_OPTION) $<
+
+%.o: %.cc
+ $(COMPILE_CPP) $(OUTPUT_OPTION) $<
+
+%.o: %.C
+ $(COMPILE_CPP) $(OUTPUT_OPTION) $<
+
+%.o: %.cpp
+ $(COMPILE_CPP) $(OUTPUT_OPTION) $<
+
+$(C_SRC_ENV):
+ @erl -noshell -noinput -eval "file:write_file(\"$(C_SRC_ENV)\", \
+ io_lib:format( \
+ \"ERTS_INCLUDE_DIR ?= ~s/erts-~s/include/~n\" \
+ \"ERL_INTERFACE_INCLUDE_DIR ?= ~s~n\" \
+ \"ERL_INTERFACE_LIB_DIR ?= ~s~n\", \
+ [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_ENV) $(C_SRC_OUTPUT)
+ $(gen_verbose) rm -f $(C_SRC_OUTPUT) $(OBJECTS)
+
+distclean:: distclean-c_src-env
+
+distclean-c_src-env:
+ $(gen_verbose) rm -f $(C_SRC_ENV)
+
+-include $(C_SRC_ENV)
+endif
diff --git a/plugins/escript.mk b/plugins/escript.mk
new file mode 100644
index 0000000..5a6a0dd
--- /dev/null
+++ b/plugins/escript.mk
@@ -0,0 +1,62 @@
+# Copyright (c) 2014 Dave Cottlehuber <[email protected]>
+# This file is part of erlang.mk and subject to the terms of the ISC License.
+
+.PHONY: distclean-escript escript
+
+# Configuration.
+
+ESCRIPT_NAME ?= $(PROJECT)
+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
+ESCRIPT_STATIC ?= "deps/*/priv/**", "priv/**"
+
+# Core targets.
+
+distclean:: distclean-escript
+
+help::
+ @printf "%s\n" "" \
+ "Escript targets:" \
+ " escript Build an executable escript archive" \
+
+# Plugin-specific targets.
+
+# Based on https://github.com/synrc/mad/blob/master/src/mad_bundle.erl
+# Copyright (c) 2013 Maxim Sokhatsky, Synrc Research Center
+# 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 ]),'\
+' [F || F <- A, not filelib:is_dir(F) ] end,'\
+'Squash = fun(L) -> [{filename:basename(F), Read(F) } || F <- L ] end,'\
+'Zip = fun(A, L) -> {ok,{_,Z}} = zip:create(A, L, [{compress,all},memory]), Z end,'\
+'Ez = fun(Escript) ->'\
+' Static = Files([$(ESCRIPT_STATIC)]),'\
+' Beams = Squash(Files([$(ESCRIPT_BEAMS), $(ESCRIPT_SYS_CONFIG)])),'\
+' Archive = Beams ++ [{ "static.gz", Zip("static.gz", Static)}],'\
+' escript:create(Escript, [ $(ESCRIPT_OPTIONS)'\
+' {archive, Archive, [memory]},'\
+' {shebang, "$(ESCRIPT_SHEBANG)"},'\
+' {comment, "$(ESCRIPT_COMMENT)"},'\
+' {emu_args, " $(ESCRIPT_EMU_ARGS)"}'\
+' ]),'\
+' file:change_mode(Escript, 8#755)'\
+'end,'\
+'Ez("$(ESCRIPT_NAME)").'
+endef
+ESCRIPT_COMMAND = $(subst ' ',,$(ESCRIPT_RAW))
+
+escript:: distclean-escript deps app
+ $(gen_verbose) erl -noshell -eval $(ESCRIPT_COMMAND) -s init stop
+
+distclean-escript:
+ $(gen_verbose) rm -f $(ESCRIPT_NAME)
diff --git a/plugins/eunit.mk b/plugins/eunit.mk
new file mode 100644
index 0000000..75aab0c
--- /dev/null
+++ b/plugins/eunit.mk
@@ -0,0 +1,71 @@
+# Copyright (c) 2014, Enrique Fernandez <[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
+
+# 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"}
+else
+# All modules in EUNIT_DIR
+EUNIT_DIR_MODS = $(notdir $(basename $(shell find $(EUNIT_DIR) -type f -name *.beam)))
+# 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'.
+# 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_OPTS ?= verbose
+
+# Utility functions
+
+define str-join
+ $(shell echo '$(strip $(1))' | sed -e "s/ /,/g")
+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:
+ @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
+
+eunit: ERLC_OPTS = $(EUNIT_ERLC_OPTS)
+eunit: clean deps app build-eunit
+ $(gen_verbose) $(EUNIT_RUN)
+
+clean-eunit:
+ $(gen_verbose) $(foreach dir,$(EUNIT_DIRS),rm -rf $(dir)/*.beam)
diff --git a/plugins/shell.mk b/plugins/shell.mk
index 9cbee2e..4e7e97e 100644
--- a/plugins/shell.mk
+++ b/plugins/shell.mk
@@ -5,7 +5,7 @@
# Configuration.
-SHELL_PATH ?= -pa ../$(PROJECT)/ebin $(DEPS_DIR)/*/ebin
+SHELL_PATH ?= -pa $(CURDIR)/ebin $(DEPS_DIR)/*/ebin
SHELL_OPTS ?=
ALL_SHELL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(SHELL_DEPS))