This is just about the simplest possible way to do it. I haven't investigated different compilation options either.