Remove trailing whitespace
Prefer dynamic libs for security
Respect system CXXFLAGS

Especially source distros will have to patch this downstream,
since -Os, -ggdb etc are intrusive flags which are expected to
be set by the user. 'CXXFLAGS?=' only sets these if there is no
CXXFLAGS in the env.
Respect system LDFLAGS

Without '+=' any system/env LDFLAGS such as -Wl,-O1
would get ignored.
Respect CXXFLAGS in linking command

Even if all objects have been compiled directly, there are a lot
of flags that can affect both object compilation and linking.
The current standard in most build systems therefor is to just
include CFLAGS/CXXFLAGS in all linking commands as well.