Jacob Perkins avatar Jacob Perkins committed d7d3182

app & build refactor

Comments (0)

Files changed (10)

+syntax: glob
+
+*.beam
+*~
+.plt
+{"src/*", [
+	debug_info,
+	{i, "include/"},
+	{outdir, "ebin/"}
+]}.
-VERSION=0.0.1
 PKGNAME=emongo
-LIBDIR=`erl -eval 'io:format("~s~n", [code:lib_dir()])' -s init stop -noshell`
 ROOTDIR=`erl -eval 'io:format("~s~n", [code:root_dir()])' -s init stop -noshell`
+LIBDIR=$(shell erl -eval 'io:format("~s~n", [code:lib_dir()])' -s init stop -noshell)
+# get application vsn from app file
+VERSION=$(shell erl -pa ebin/ -eval 'application:load(erldis), {ok, Vsn} = application:get_key(erldis, vsn), io:format("~s~n", [Vsn])' -s init stop -noshell)
 
-all: rel
-	
-compile: app
-	mkdir -p ebin/
-	(cd src;$(MAKE))
+all: src
 
-app:
-	sh ebin/$(PKGNAME).app.in $(VERSION)
+src: FORCE
+	@erl -make
 
-test: compile
+test: src
 	prove t/*.t
 
 clean:
-	(cd src;$(MAKE) clean)
-	rm -rf erl_crash.dump *.boot *.rel *.script ebin/*.beam ebin/*.app
+	rm -rf erl_crash.dump *.boot *.rel *.script ebin/*.beam
 
-rel: compile
-	erl -pa ebin -noshell -run emongo_app build_rel -s init stop
-	
 package: clean
 	@mkdir $(PKGNAME)-$(VERSION)/ && cp -rf ebin include Makefile priv README.markdown src support t $(PKGNAME)-$(VERSION)
 	@COPYFILE_DISABLE=true tar zcf $(PKGNAME)-$(VERSION).tgz $(PKGNAME)-$(VERSION)
 	@mkdir -p $(prefix)/$(LIBDIR)/$(PKGNAME)-$(VERSION)/{ebin,include}
 	@mkdir -p $(prefix)/$(ROOTDIR)/bin
 	for i in ebin/*.beam include/*.hrl ebin/*.app; do install $$i $(prefix)/$(LIBDIR)/$(PKGNAME)-$(VERSION)/$$i ; done
-	cp *.boot $(prefix)/$(ROOTDIR)/bin/
+	cp *.boot $(prefix)/$(ROOTDIR)/bin/
+
+plt:
+	@dialyzer --build_plt --output_plt .plt -q -r . -I include/
+
+check: all
+	@dialyzer --check_plt --plt .plt -q -r . -I include/
+
+FORCE:
+{application, emongo, [
+	{description, "Erlang MongoDB Driver"},
+	{vsn, "0.0.2"},
+	{modules, [
+		emongo, emongo_app, emongo_sup, emongo_bson, emongo_conn, emongo_packet
+	]},
+	{registered, [emongo_sup, emongo]},
+	{mod, {emongo_app, []}},
+	{applications, [kernel, stdlib]},
+	{env, [
+		{pools, [
+			{emongo, [
+				{size, 1},
+				{host, "localhost"},
+				{port, 27017},
+				{database, "test"}
+			]}
+		]}
+	]}
+]}.

ebin/emongo.app.in

-#!/bin/bash
-
-VERSION=${1}
-MODULES=`ls -1 src/*.erl | awk -F[/.] '{ print "\t\t" $2 }' | sed '$q;s/$/,/g'`
-
-cat > ebin/emongo.app << EOF
-{application, emongo, [
-    {description, "Erlang MongoDB Driver"},
-    {vsn, "${VERSION}"},
-    {modules, [
-${MODULES}
-    ]},
-    {registered, []},
-    {mod, {emongo_app, []}},
-    {applications, [kernel, stdlib]}
-]}.
-EOF

src/Makefile

-include ../support/include.mk
-
-all: $(EBIN_FILES)
-
-debug:
-	$(MAKE) DEBUG=-DDEBUG
-
-clean:
-	rm -rf $(EBIN_FILES) erl_crash.dump
 		undefined ->
 			[];
 		{ok, Pools} ->
-			[begin
-				Pool = #pool{
-					id = PoolId, 
-					size = proplists:get_value(size, Props, 1),
-					host = proplists:get_value(host, Props, "localhost"), 
-					port = proplists:get_value(port, Props, 27017), 
-					database = proplists:get_value(database, Props, "test")
-				},
-				{PoolId, do_open_connections(Pool)}
-			 end || {PoolId, Props} <- Pools]
+			F = fun({PoolId, Props}) ->
+					Pool = #pool{
+						id = PoolId, 
+						size = proplists:get_value(size, Props, 1),
+						host = proplists:get_value(host, Props, "localhost"), 
+						port = proplists:get_value(port, Props, 27017), 
+						database = proplists:get_value(database, Props, "test")
+					},
+					{PoolId, do_open_connections(Pool)}
+				end,
+			
+			lists:map(F, Pools)
 	end.
 		
 do_open_connections(#pool{conn_pids=Pids, size=Size}=Pool) -> 

src/emongo_app.erl

 %% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 %% OTHER DEALINGS IN THE SOFTWARE.
 -module(emongo_app).
+
 -behaviour(application).
 
--export([start/2,stop/1, init/1, build_rel/0]).
+-export([start/2, stop/1]).
 
-start(_, _) ->
-    supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+start(_, _) -> emongo_sup:start_link().
 
-stop(_) -> ok.
-
-init(_) ->
-   {ok, {{one_for_one, 10, 10}, [
-       {emongo, {emongo, start_link, []}, permanent, 5000, worker, [emongo]}
-   ]}}.
-
-build_rel() ->
-	Apps = [kernel,stdlib,sasl],
-    {ok, FD} = file:open("emongo.rel", [write]),
-    RelInfo = {release,
-        {"emongo", "0.3"},
-        get_app_version(erts), 
-            [get_app_version(AppName) || AppName <- Apps] ++ [
-            {emongo, "0.0.1"}
-        ]
-    },
-    io:format(FD, "~p.", [RelInfo]),
-    file:close(FD),
-    systools:make_script("emongo", [local]),
-    ok.
-
-get_app_version(AppName) ->
-	case code:lib_dir(AppName) of
-		{error, bad_name} ->
-			exit({bad_name, AppName});
-		Dir ->
-			case lists:reverse(string:tokens(Dir, "-")) of
-				[Vsn|_] -> {AppName, Vsn};
-				_ ->
-					exit({failed_to_tokenize, Dir})
-			end
-	end.
+stop(_) -> ok.

src/emongo_sup.erl

+-module(emongo_sup).
+
+-behaviour(supervisor).
+
+-export([start_link/0, init/1]).
+
+start_link() -> supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+init(_) ->
+	{ok, {{one_for_one, 10, 10}, [
+		{emongo, {emongo, start_link, []}, permanent, 5000, worker, [emongo]}
+	]}}.

support/include.mk

-## -*- makefile -*-
-
-ERL := erl
-ERLC := $(ERL)c
-
-INCLUDE_DIRS := ../include
-EBIN_DIRS := $(wildcard ../ebin)
-ERLC_FLAGS := -W $(INCLUDE_DIRS:../%=-I ../%) $(EBIN_DIRS:%=-pa %)
-
-ifndef no_debug_info
-  ERLC_FLAGS += +debug_info
-endif
-
-ifdef debug
-  ERLC_FLAGS += -Ddebug
-endif
-
-EBIN_DIR := ../ebin
-DOC_DIR  := ../doc
-EMULATOR := beam
-
-ERL_SOURCES  := $(wildcard *.erl)
-ERL_HEADERS  := $(wildcard *.hrl) $(wildcard ../include/*.hrl)
-ERL_OBJECTS  := $(ERL_SOURCES:%.erl=$(EBIN_DIR)/%.beam)
-ERL_TEMPLATES := $(ERL_TEMPLATE:%.et=$(EBIN_DIR)/%.beam)
-ERL_OBJECTS_LOCAL := $(ERL_SOURCES:%.erl=./%.$(EMULATOR))
-APP_FILES := $(wildcard *.app)
-EBIN_FILES = $(ERL_OBJECTS) $(APP_FILES:%.app=../ebin/%.app) $(ERL_TEMPLATES)
-MODULES = $(ERL_SOURCES:%.erl=%)
-
-../ebin/%.app: %.app
-	cp $< $@
-
-$(EBIN_DIR)/%.$(EMULATOR): %.erl
-	$(ERLC) $(ERLC_FLAGS) -o $(EBIN_DIR) $<
-
-./%.$(EMULATOR): %.erl
-	$(ERLC) $(ERLC_FLAGS) -o . $<
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.