New build system

The change allows for re-use of the constructs and more flexibility, also easier maintainense.
Fix compiler warnings.