makefiles: adjust definition and handling of CFLAGS and CPPFLAGS

Try to make the makefiles work better if CFLAGS and/or CPPFLAGS
is defined externally.