Port from svn to git. Also fix some compile issues of this old version on OSX.