Add dynbinary build script and refactor the handling of static-related build flags

This is as discussed with @shykes on IRC