Build system fixes for Mac OS X.
Portability fixes for gcc < 4.7 and mac.