Separate out compiler flags into different concerns.

Separate FLAGS into CPPFLAGS, LDFLAGS and CFLAGS and make sure CFLAGS is passed to all compilation steps (apart from the overall link).

Before, adding -g to FLAGS would not add debugging symbols to all objects.