Merge remote-tracking branch 'origin/kas/unfubar'
diff --git a/Makefile b/Makefile
index 5d1630b..7bca978 100644
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,11 @@
 all: compile
 
 compile:
-	@ ./rebar compile
+	@rebar compile
 
 tests:
-	@ ./rebar eunit
+	@rebar eunit
 
 clean:
-	@ ./rebar clean
+	@rebar clean
 
diff --git a/c_src/Makefile b/c_src/Makefile
new file mode 100644
index 0000000..86fcca6
--- /dev/null
+++ b/c_src/Makefile
@@ -0,0 +1,6 @@
+compile:
+	env
+	$(CC) $(CFLAGS) $(ERL_CFLAGS) $(EXE_LDFLAGS) bcrypt_port.c bcrypt.o blowfish.o -o ../priv/bcrypt
+
+clean:
+	@rm -f ../priv/bcrypt
diff --git a/rebar b/rebar
deleted file mode 100755
index 19adebf..0000000
--- a/rebar
+++ /dev/null
Binary files differ
diff --git a/rebar.config b/rebar.config
index 2d7e862..e3fc279 100644
--- a/rebar.config
+++ b/rebar.config
@@ -1,14 +1,16 @@
 %% -*- mode: erlang;erlang-indent-level: 2;indent-tabs-mode: nil -*-
-{erl_opts, [debug_info]}.
+%% {erl_opts, [debug_info]}.
 
-{so_specs,
- [{"priv/bcrypt_nif.so",
-   ["c_src/blowfish.o", "c_src/bcrypt.o", "c_src/bcrypt_nif.o", "c_src/async_queue.o"]}]}.
+%% {so_specs,
+%%  [{"priv/bcrypt_nif.so",
+%%    ["c_src/*.c"]}]}.
+{port_env,
+ [{"DRV_LDFLAGS","-shared $ERL_LDFLAGS -lpthread"},
+  {"darwin", "DRV_LDFLAGS", "-bundle -flat_namespace -undefined suppress $ERL_LDFLAGS -lpthread"},
+  {"DRV_CFLAGS","-Ic_src -Wall -fPIC $ERL_CFLAGS"}]}.
+
+{port_specs, [{"priv/bcrypt_nif.so", ["c_src/*.c"]}]}.
 
 {post_hooks,
- [{clean, "rm -f priv/bcrypt"},
-  {compile,
-   "$CC $CFLAGS $ERL $ERL_CFLAGS "
-   "c_src/bcrypt_port.c c_src/bcrypt.o c_src/blowfish.o "
-   "$LDFLAGS $ERL_LDFLAGS -lpthread "
-   "-o priv/bcrypt"}]}.
+ [{clean, "make -C c_src clean"},
+  {compile, "make -C c_src"}]}.