Some support for headless and IDE builds

hi marco

I started from scratch again.

Should be usable to build console and UI with the IDE. 

Please check