improve library detection in configure script