Skip to content

Commit

Permalink
Rebar-ize libgeoip-erlang
Browse files Browse the repository at this point in the history
To build:
  rebar complie

To clean:
  rebar clean

To bundle:
  mkdir -p libgeoip-1.0.3; cp -rp ebin priv libgeoip-1.0.3

--HG--
rename : src/libgeoip_app.app => src/libgeoip.app.src
  • Loading branch information
mattsta committed Oct 19, 2010
1 parent baa5ff6 commit 70b58ef
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 59 deletions.
3 changes: 3 additions & 0 deletions .hgignore
Expand Up @@ -2,3 +2,6 @@ syntax: glob
dist/
src/geoipport
libgeoip-*
priv/
ebin/
c_src/*.o
15 changes: 10 additions & 5 deletions README
Expand Up @@ -2,6 +2,7 @@
who: matt@genges.com
what: erlang port for libgeoip. supports GeoIPCity and GeoLiteCity DBs.
when: made December 2008. published December 2008.
when2: Last updated October 2010. Rebar-ized and added license.
where: everywhere
why: I don't like having to do external service calls for geo lookups.

Expand All @@ -24,12 +25,16 @@ benchmark versus egeoip:
egeoip: 5498 lookups per second
resulting in libgeoip-erlang being about 28% faster than egeoip.

installation: build it.
edit src/Makefile if erlang isn't in /usr/local/lib/erlang
put everything in dist/ where you need it to be
Building Instructions:
> rebar compile
You may need to edit rebar.config if your maxmind headers and
objects aren't in /opt/local.

Note: You must have the libgeoip directory name *in* your path for libgeoip to
find the correct port to run.

usage [APPLICATION]:
% erl -pz ./libgeoip-erlang/libgeoip-VER/ebin/
> erl -pz ../ligeoip-erlang/ebin -pz ../libgeoip-erlang/priv

Eshell V5.6.5 (abort with ^G)
1> application:start(libgeoip_app).
Expand All @@ -44,7 +49,7 @@ db_set


usage [DIRECT]:
% erl -pz ./libgeoip-erlang/libgeoip-1.0/ebin/
> erl -pz ../libgeoip-erlang/ebin -pz ../libgeoip-erlang/priv

Eshell V5.6.5 (abort with ^G)
1> libgeoip:start_link("/usr/local/maxmind/data/GeoLiteCity.dat").
Expand Down
23 changes: 23 additions & 0 deletions c_src/Makefile
@@ -0,0 +1,23 @@
.PHONY: dist clean

## - if you have multiple versions, pick the highest one
OTP_LIB_DIR:= $(shell erl -noshell -eval 'io:format("~s", [code:lib_dir()])' -s erlang halt)
EI=$(shell ls -d $(OTP_LIB_DIR)/erl_interface* | sort -n |tail -1)
LIBGEOIP=../priv/libgeoip

## - default macports install location for libgeoip
GEOIP_LIBS=/opt/local

dist: $(LIBGEOIP)

$(LIBGEOIP): geoipport.c erl_comm.c geohash.c Makefile
@mkdir -p ../priv
gcc -Wall -Os -L$(GEOIP_LIBS)/lib -I$(GEOIP_LIBS)/include \
-L$(EI)/lib/ -I$(EI)/include/ \
-o $(LIBGEOIP) erl_comm.c geoipport.c geohash.c -lerl_interface -lei -lGeoIP \
-lpthread

## - Comments are fun

clean:
rm -f $(LIBGEOIP)
File renamed without changes.
1 change: 1 addition & 0 deletions src/geohash.c → c_src/geohash.c
Expand Up @@ -2,6 +2,7 @@
| direct JS -> C port of encodeGeoHash (ugly formatting and all) from:
| http://github.com/davetroy/geohash-js/tree/master/geohash.js
| no decoding or adjacency finding implemented (or required) yet
| geohash.js is MIT licensed as is this translation of it.
*/

int BITS[] = {16, 8, 4, 2, 1};
Expand Down
Binary file added c_src/geoipport
Binary file not shown.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions rebar.config
@@ -0,0 +1,6 @@
{port_envs, [{"CFLAGS", "-Wall -I/opt/local/include "},
{"LDFLAGS", "-L/opt/local/lib "}]}.

% This is a hack because I can't make rebar compile non-linked-in drivers.
{port_pre_script, {"gmake -C c_src", "priv/libgeoip"}}.
{port_cleanup_script, "gmake -C c_src clean"}.
50 changes: 0 additions & 50 deletions src/Makefile

This file was deleted.

6 changes: 3 additions & 3 deletions src/libgeoip_app.app → src/libgeoip.app.src
@@ -1,7 +1,7 @@
{application, libgeoip_app,
{application, libgeoip,
[{description, "libgeoip port"},
{vsn, "1.0.1"},
{modules, [libgeoip_app, libgeoip_sup, libgeoip]},
{vsn, "1.0.2"},
{modules, []},
{registered, [libgeoip]},
{applications, [kernel, stdlib]},
{mod, {libgeoip_app,[]}}
Expand Down
3 changes: 2 additions & 1 deletion src/libgeoip.erl
Expand Up @@ -23,7 +23,8 @@ init(DBName) ->
{error, bad_name} -> "";
Found -> Found ++ "/"
end,
GeoIP = open_port({spawn, Path ++ "geoipport"}, [{packet, 2}, binary]),
io:format("Path is: ~p~n", [Path]),
GeoIP = open_port({spawn, Path ++ "libgeoip"}, [{packet, 2}, binary]),
process_flag(trap_exit, true),
case DBName of
[] -> ok;
Expand Down

0 comments on commit 70b58ef

Please sign in to comment.