Some useful changes in build system

Fixes in build system + static library build.