Various build system fixes (2nd try)

As written in the last pull request: rewrote the system PolarSSL detection and tested with/without PolarSSL installed.