ported code to use rebar and R14B
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
|||||||
*.so
|
*.so
|
||||||
*.o
|
*.o
|
||||||
*.swp
|
*.swp
|
||||||
|
rebar
|
||||||
|
|||||||
37
Makefile
37
Makefile
@@ -1,30 +1,15 @@
|
|||||||
OTPROOT=/Users/schacon/projects/otp
|
REBAR=$(shell which rebar || echo ./rebar)
|
||||||
INCLUDES = -I$(OTPROOT)/erts/emulator/beam/
|
|
||||||
|
|
||||||
# OS X flags.
|
all: compile
|
||||||
GCCFLAGS = -O3 -fPIC -bundle -flat_namespace -undefined suppress -fno-common -Wall -m32
|
|
||||||
|
|
||||||
LIBS = -lz -lgit2
|
./rebar:
|
||||||
|
erl -noshell -s inets start \
|
||||||
|
-eval 'httpc:request(get, {"http://hg.basho.com/rebar/downloads/rebar", []}, [], [{stream, "./rebar"}])' \
|
||||||
|
-s init stop
|
||||||
|
chmod +x ./rebar
|
||||||
|
|
||||||
# Linux Flags
|
compile: $(REBAR)
|
||||||
#GCCFLAGS = -O3 -fPIC -shared -fno-common -Wall
|
@$(REBAR) compile
|
||||||
|
|
||||||
CFLAGS = $(GCCFLAGS) $(INCLUDES)
|
|
||||||
LDFLAGS = $(GCCFLAGS) $(LIBS)
|
|
||||||
|
|
||||||
OBJECTS = geef.o
|
|
||||||
|
|
||||||
DRIVER = geef.so
|
|
||||||
BEAM = geef.beam
|
|
||||||
|
|
||||||
all: $(DRIVER) $(BEAM)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f *.o *.beam $(DRIVER)
|
|
||||||
|
|
||||||
$(DRIVER): $(OBJECTS)
|
|
||||||
gcc -o $@ $^ $(LDFLAGS)
|
|
||||||
|
|
||||||
$(BEAM): geef.erl
|
|
||||||
erlc $^
|
|
||||||
|
|
||||||
|
clean: $(REBAR)
|
||||||
|
@$(REBAR) clean
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
#include "erl_nif.h"
|
#include "erl_nif.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <git/commit.h>
|
||||||
|
#include <git/tag.h>
|
||||||
#include <git/common.h>
|
#include <git/common.h>
|
||||||
#include <git/oid.h>
|
#include <git/errors.h>
|
||||||
|
#include <git/index.h>
|
||||||
#include <git/odb.h>
|
#include <git/odb.h>
|
||||||
|
#include <git/oid.h>
|
||||||
|
#include <git/revwalk.h>
|
||||||
|
#include <git/repository.h>
|
||||||
|
#include <git/zlib.h>
|
||||||
|
|
||||||
#define MAXBUFLEN 1024
|
#define MAXBUFLEN 1024
|
||||||
|
|
||||||
@@ -19,7 +26,7 @@ geef_hex_to_raw(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
|||||||
git_oid_mkstr(&oid, sha);
|
git_oid_mkstr(&oid, sha);
|
||||||
|
|
||||||
ErlNifBinary ibin;
|
ErlNifBinary ibin;
|
||||||
enif_alloc_binary(env, 20, &ibin);
|
enif_alloc_binary(20, &ibin);
|
||||||
memcpy(ibin.data, (&oid)->id, 20);
|
memcpy(ibin.data, (&oid)->id, 20);
|
||||||
|
|
||||||
return enif_make_binary(env, &ibin);
|
return enif_make_binary(env, &ibin);
|
||||||
14
ebin/geef.app
Normal file
14
ebin/geef.app
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{application, geef,
|
||||||
|
[
|
||||||
|
{description, ""},
|
||||||
|
{vsn, "0.0.1"},
|
||||||
|
{modules, [
|
||||||
|
geef
|
||||||
|
]},
|
||||||
|
{registered, []},
|
||||||
|
{applications, [
|
||||||
|
kernel,
|
||||||
|
stdlib
|
||||||
|
]},
|
||||||
|
{env, []}
|
||||||
|
]}.
|
||||||
4
geef
4
geef
@@ -1,6 +1,6 @@
|
|||||||
#!/Users/schacon/projects/otp/bin/escript
|
#!/usr/local/Cellar/erlang/R14B/bin/escript
|
||||||
%% -*- erlang -*-
|
%% -*- erlang -*-
|
||||||
%%! debug verbose -noshell
|
%%! debug verbose -noshell -pa ebin
|
||||||
|
|
||||||
main([Command|_Args]) ->
|
main([Command|_Args]) ->
|
||||||
geef:start(),
|
geef:start(),
|
||||||
|
|||||||
14
geef.erl
14
geef.erl
@@ -1,14 +0,0 @@
|
|||||||
-module(geef).
|
|
||||||
-export([start/0, hex_to_raw/1, object_exists/2]).
|
|
||||||
|
|
||||||
start() ->
|
|
||||||
erlang:load_nif("geef", 0).
|
|
||||||
|
|
||||||
hex_to_raw(_Val) ->
|
|
||||||
nif_error(?LINE).
|
|
||||||
|
|
||||||
object_exists(_Val, _Val2) ->
|
|
||||||
nif_error(?LINE).
|
|
||||||
|
|
||||||
nif_error(Line) ->
|
|
||||||
exit({nif_not_loaded,module,?MODULE,line,Line}).
|
|
||||||
13
rebar.config
Normal file
13
rebar.config
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{so_name, "geef.so"}.
|
||||||
|
|
||||||
|
{port_envs, [
|
||||||
|
{"DRV_LDFLAGS", "$DRV_LDFLAGS -lz -lgit2"},
|
||||||
|
|
||||||
|
%% OS X Leopard flags for 64-bit
|
||||||
|
{"darwin9.*-64$", "CXXFLAGS", "-m64"},
|
||||||
|
{"darwin9.*-64$", "LDFLAGS", "-arch x86_64"},
|
||||||
|
|
||||||
|
%% OS X Snow Leopard flags for 32-bit
|
||||||
|
{"darwin10.*-32$", "CXXFLAGS", "-m32"},
|
||||||
|
{"darwin10.*-32$", "LDFLAGS", "-arch i386"}
|
||||||
|
]}.
|
||||||
21
src/geef.erl
Normal file
21
src/geef.erl
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
-module(geef).
|
||||||
|
-export([start/0, hex_to_raw/1, object_exists/2]).
|
||||||
|
|
||||||
|
start() ->
|
||||||
|
case code:priv_dir(geef) of
|
||||||
|
{error, bad_name} ->
|
||||||
|
SoName = filename:join("priv", geef);
|
||||||
|
Dir ->
|
||||||
|
SoName = filename:join(Dir, geef)
|
||||||
|
end,
|
||||||
|
io:format("Hey There: ~s~n", [SoName]),
|
||||||
|
erlang:load_nif(SoName, 0).
|
||||||
|
|
||||||
|
hex_to_raw(_Val) ->
|
||||||
|
nif_error(?LINE).
|
||||||
|
|
||||||
|
object_exists(_Val, _Val2) ->
|
||||||
|
nif_error(?LINE).
|
||||||
|
|
||||||
|
nif_error(Line) ->
|
||||||
|
exit({nif_not_loaded,module,?MODULE,line,Line}).
|
||||||
Reference in New Issue
Block a user