Configure script refactoring of module handling

-Fixes a few errors in the code that might only trigger in corner cases
-Reorders some code to avoid having to duplicate code, and then forgetting to consider it when adding new code
-Reduces spawning of external processes
-Improves modules listing at the end of configure

The resulting makefiles are almost identical, except that BUILD_SHARED_MODULE_OBJS is reordered to match SHARED_MODULE_OBJS, this should not have any effect on the compile.

PS: This requires that autoconf is run to regenerate the configure script itself.
For most users, there is not a useful distinction between core and static modules.  That is why the existing output just mentions static and shared/DSO modules.