Cleanup build to localize flags for external packages.

Cleaning up configure so that compile/link flags for external packages are only used by the minimal set of modules that need them.  Ideally, this will minimize build and namespace conflicts, reduce executable sizes, and make command lines easier to read.

Don't merge yet, still tweaking.