Build cleanup 2.10

See #2290. It contains the same commits. The difference between master and 2.10.x is in the merge commit where this PR is merged into #2290