Update makefile to override CXXFLAGS, LDFLAGS and fix problems in generating .d files