SConstruct cleanup

- Use Substfile instead of hand written code
- Add more error checks, and dependencies