Completely revamp configure so that it preserves the standard make variables CPPFLAGS, CFLAGS, CXXFLAGS, LDFLAGS and LIBS by moving the configure additions to EXTRA_* variables. Also, allow the user to specify NOTEST_* values for all of the above, which eliminates the need for THREAD_CPPFLAGS, THREAD_CFLAGS, and OPTIM. Fix the setting of INCLUDES and EXTRA_INCLUDES. Check flags as they are added to avoid pointless duplications. Fix the order in which flags are given on the compile and link lines.
Search for OpenSSL in the "standard locations" .../include and .../lib which are ubiquitous after openSSL's "make install". The old logic relied on a common directory for both include files and libraries (very non-standard).