Completely revamp configure so that it preserves the standard makevariables CPPFLAGS, CFLAGS, CXXFLAGS, LDFLAGS and LIBS by movingthe configure additions to EXTRA_* variables. Also, allow the userto specify NOTEST_* values for all of the above, which eliminates theneed for THREAD_CPPFLAGS, THREAD_CFLAGS, and OPTIM. Fix the settingof INCLUDES and EXTRA_INCLUDES. Check flags as they are added toavoid pointless duplications. Fix the order in which flags are givenon the compile and link lines.