Fixes discover.ml to support PKGSRC-using platforms

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.
Shouldn't this replace the last occurrence instead of the last one? I guess this is unlikely that a patch contains twice `include` or `lib` but if it happens we'd probably want to replace the last one.