Build system cleanup and improvements.

The old version of the CFLAGS variable was explicitly calling `pkg-config --libs --cflags glib-2.0` for every file that used this variable. Better to just calculate this once and use it everwhere.