Make CXX/CXXFLAGS overridable

This makes it easier to support systemwide compiler settings.
While here, link with pthreads in a more correct way (-pthread instead
of -lpthread).