use tempfiles instead of locking

This should solve a long-standing issue with corrupted files being (and locks) being left on disk when compilation fails for some reason.