I did it modifying the .pro files in qt source directory.
I added SUBDIRS -= gui to $QTDIR/src/src.pro, SUBDIRS -= iconengines imageformats inputmethod styles to $QTDIR/src/plugins/plugins.pro, and some more in $QTDIR/tools directory (for example SUBDIRS -= assistant designer linguist to tools.pro).

Then configure as usual, and make.
If you get errors, you should only find out what subdir needs to be excluded by compilation.

This way I got Qt working with network, sql, xml modules.