Some exceptionally hard-won fixes. The build works now.