Some fixes for OS X

These are the changes I made to get it building with scons, plus the fix to T5_file. This shouldn't affect other platforms.