build-scripts: monster re-write of build scripts. Based on ktoonsez's

Change-Id: I1bb897bc690d0be6d236ec22e0a82bebbf09238b