Fixes discover.ml to support platforms that use PKGSRC

This patch tries to add support for **PKGSRC** in `discover.ml`'s search path algorithm. **PKGSRC** installs `libev` files in `/usr/pkg/include/ev` and `/usr/pkg/lib/ev`. The version of `discover.ml` prior to this would compute the library path to be `/usr/pkg/include/ev/../lib`, which is wrong.
I'm not convinced by `global_replace` either. I think in general what makes the most sense is to replace the last occurrence.