patch for #2173 and fix Rmath cross-compile