fix static build

When built statically the nif couldn't be loaded. This patch fix the
following:

- make sure that the patches are applied.
- fix LDFLAGS order

While I am here add a unitest to fix the lib.