Try to clean up configure script

Move all the legacy detection to a macro. Migrate cURL to libtool, and
avoid all the variable saving.