Improve environment handling in configure script.