Permalink
Browse files

updating build process and adding epm file

  • Loading branch information...
Jacob Vorreuter
Jacob Vorreuter committed Feb 26, 2010
1 parent 2a0823b commit b373badd6084112f95433d25b3d42f01a632b5e5
Showing with 75 additions and 98 deletions.
  1. +7 −0 Emakefile
  2. +12 −22 Makefile
  3. +48 −0 build_rel.escript
  4. +6 −0 emongo.epm
  5. +0 −9 src/Makefile
  6. +2 −29 src/emongo_app.erl
  7. +0 −38 support/include.mk
View
@@ -0,0 +1,7 @@
+% -*- mode: erlang -*-
+
+{[ 'src/*' ],
+ [ {i, "include"},
+ {outdir, "ebin"},
+ debug_info ]
+}.
View
@@ -3,32 +3,22 @@ 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`
-all: rel
-
-compile: app
- mkdir -p ebin/
- (cd src;$(MAKE))
+all: emake
+
+emake: app
+ erl -make
app:
sh ebin/$(PKGNAME).app.in $(VERSION)
+
+release: emake release/$(PKGNAME).tar.gz
+
+release/$(PKGNAME).rel release/$(PKGNAME).script release/$(PKGNAME).tar.gz: app
+ mkdir -p release
+ escript build_rel.escript $(PKGNAME)
-test: compile
+test: emake
prove t/*.t
clean:
- (cd src;$(MAKE) clean)
- rm -rf erl_crash.dump *.boot *.rel *.script ebin/*.beam ebin/*.app
-
-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)
- @rm -rf $(PKGNAME)-$(VERSION)/
-
-install:
- @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/
+ rm -rf $(wildcard ebin/*.beam) erl_crash.dump *.boot *.rel *.script ebin/*.app release
View
@@ -0,0 +1,48 @@
+#!/usr/bin/env escript
+%% -*- erlang -*-
+
+main([AppName]) ->
+ {ok, [{application,_,AppProps}]} = file:consult("ebin/" ++ AppName ++ ".app"),
+ AppDeps = proplists:get_value(applications, AppProps, []),
+ AppVsn = proplists:get_value(vsn, AppProps),
+ {ok, FD} = file:open("release/" ++ AppName ++ ".rel", [write]),
+ RelInfo = {release,
+ {AppName, AppVsn},
+ {erts, erts_vsn()},
+ [{Pkg, lib_vsn(Pkg)} || Pkg <- AppDeps]
+ },
+ io:format(FD, "~p.", [RelInfo]),
+ file:close(FD),
+ systools:make_script("release/" ++ AppName, [{exref, AppDeps}, {outdir, "release"}]),
+ systools:make_tar("release/" ++ AppName, [{dirs, tar_dirs()}, {outdir, "release"}]),
+ ok.
+
+erts_vsn() ->
+ erlang:system_info(version).
+
+lib_vsn(App) ->
+ load(App),
+ {ok, Vsn} = application:get_key(App, vsn),
+ Vsn.
+
+load(App) ->
+ case application:load(App) of
+ ok ->
+ ok;
+ {error, {already_loaded, _}} ->
+ ok;
+ E ->
+ io:format(standard_error, "Warning - can't load ~p (~p)~n", [App, E]),
+ erlang:exit(E)
+ end.
+
+tar_dirs() ->
+ {ok, Files} = file:list_dir("."),
+ [list_to_atom(Dir) || Dir <- lists:filter(
+ fun ("." ++ _) -> false;
+ (File) ->
+ filelib:is_dir(File) andalso not lists:member(File, ["ebin", "include", "t"])
+ end, Files)].
+
+
+
View
@@ -0,0 +1,6 @@
+[
+ {deps, [
+ {"etap", []}
+ ]},
+ {test_command, "make test"}
+].
View
@@ -1,9 +0,0 @@
-include ../support/include.mk
-
-all: $(EBIN_FILES)
-
-debug:
- $(MAKE) DEBUG=-DDEBUG
-
-clean:
- rm -rf $(EBIN_FILES) erl_crash.dump
View
@@ -23,7 +23,7 @@
-module(emongo_app).
-behaviour(application).
--export([start/2,stop/1, init/1, build_rel/0]).
+-export([start/2,stop/1, init/1]).
start(_, _) ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
@@ -33,31 +33,4 @@ 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.
+ ]}}.
View
@@ -1,38 +0,0 @@
-## -*- 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 . $<

0 comments on commit b373bad

Please sign in to comment.