ported code to use rebar and R14B

This commit is contained in:
Scott Chacon
2010-11-03 15:53:14 -07:00
parent fc4b19eff1
commit c1ea72abae
8 changed files with 71 additions and 44 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
*.so
*.o
*.swp
rebar

View File

@@ -1,30 +1,15 @@
OTPROOT=/Users/schacon/projects/otp
INCLUDES = -I$(OTPROOT)/erts/emulator/beam/
REBAR=$(shell which rebar || echo ./rebar)
# OS X flags.
GCCFLAGS = -O3 -fPIC -bundle -flat_namespace -undefined suppress -fno-common -Wall -m32
all: compile
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
#GCCFLAGS = -O3 -fPIC -shared -fno-common -Wall
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 $^
compile: $(REBAR)
@$(REBAR) compile
clean: $(REBAR)
@$(REBAR) clean

View File

@@ -1,8 +1,15 @@
#include "erl_nif.h"
#include <stdio.h>
#include <git/commit.h>
#include <git/tag.h>
#include <git/common.h>
#include <git/oid.h>
#include <git/errors.h>
#include <git/index.h>
#include <git/odb.h>
#include <git/oid.h>
#include <git/revwalk.h>
#include <git/repository.h>
#include <git/zlib.h>
#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);
ErlNifBinary ibin;
enif_alloc_binary(env, 20, &ibin);
enif_alloc_binary(20, &ibin);
memcpy(ibin.data, (&oid)->id, 20);
return enif_make_binary(env, &ibin);

14
ebin/geef.app Normal file
View File

@@ -0,0 +1,14 @@
{application, geef,
[
{description, ""},
{vsn, "0.0.1"},
{modules, [
geef
]},
{registered, []},
{applications, [
kernel,
stdlib
]},
{env, []}
]}.

4
geef
View File

@@ -1,6 +1,6 @@
#!/Users/schacon/projects/otp/bin/escript
#!/usr/local/Cellar/erlang/R14B/bin/escript
%% -*- erlang -*-
%%! debug verbose -noshell
%%! debug verbose -noshell -pa ebin
main([Command|_Args]) ->
geef:start(),

View File

@@ -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
View 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
View 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}).