aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/bootstrap.mk
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/bootstrap.mk')
-rw-r--r--plugins/bootstrap.mk88
1 files changed, 71 insertions, 17 deletions
diff --git a/plugins/bootstrap.mk b/plugins/bootstrap.mk
index 41b5fa7..6494180 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
@@ -20,6 +20,7 @@ define bs_appsrc
{application, $(PROJECT), [
{description, ""},
{vsn, "0.1.0"},
+ {id, "git"},
{modules, []},
{registered, []},
{applications, [
@@ -35,6 +36,7 @@ define bs_appsrc_lib
{application, $(PROJECT), [
{description, ""},
{vsn, "0.1.0"},
+ {id, "git"},
{modules, []},
{registered, []},
{applications, [
@@ -82,6 +84,7 @@ define bs_vm_args
endef
# Normal templates.
+
define tpl_supervisor
-module($(n)).
-behaviour(supervisor).
@@ -164,6 +167,59 @@ 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).
@@ -196,7 +252,7 @@ init(_, _Req, _Opts) ->
{upgrade, protocol, cowboy_rest}.
content_types_provided(Req, State) ->
- {[{{<<"text">>, <<"html">>, '_'}, get_html}], Req, State}.
+ {[{{<<"text">>, <<"html">>, '*'}, get_html}], Req, State}.
get_html(Req, State) ->
{<<"<html><body>This is REST!</body></html>">>, Req, State}.
@@ -267,32 +323,30 @@ endef
# Plugin-specific targets.
define render_template
- @echo '$(subst $(newline),\n,${1})' > $(2)
+ @echo "$${$(1)}" > $(2)
endef
-define newline
-
-
-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
- $(call render_template,$(bs_Makefile),Makefile)
+ $(call render_template,bs_Makefile,Makefile)
@mkdir src/
- $(call render_template,$(bs_appsrc),src/$(PROJECT).app.src)
- $(call render_template,$(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)
- $(call render_template,$(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
- $(call render_template,$(bs_Makefile),Makefile)
+ $(call render_template,bs_Makefile,Makefile)
@mkdir src/
- $(call render_template,$(bs_appsrc_lib),src/$(PROJECT).app.src)
+ $(call render_template,bs_appsrc_lib,src/$(PROJECT).app.src)
bootstrap-rel:
ifneq ($(wildcard relx.config),)
@@ -301,10 +355,10 @@ endif
ifneq ($(wildcard rel/),)
$(error Error: rel/ directory already exists)
endif
- $(call render_template,$(bs_relx_config),relx.config)
+ $(call render_template,bs_relx_config,relx.config)
@mkdir rel/
- $(call render_template,$(bs_sys_config),rel/sys.config)
- $(call render_template,$(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/),)
@@ -319,7 +373,7 @@ endif
ifndef n
$(error Usage: make new t=TEMPLATE n=NAME)
endif
- $(call render_template,$(tpl_$(t)),src/$(n).erl)
+ $(call render_template,tpl_$(t),src/$(n).erl)
list-templates:
@echo Available templates: $(sort $(patsubst tpl_%,%,$(filter tpl_%,$(.VARIABLES))))