Do merkle root and txid duplicates check simultaneously

Move the txid duplicates check into BuildMerkleTree, where it can be done
much more efficiently (without needing to build a full txid set to detect
duplicates).

The previous version (using the std::set<uint256> to detect duplicates) was
also slightly too weak. A block mined with actual duplicate transactions
(which is invalid, due to the inputs of the duplicated transactions being
seen as double spends) would trigger the duplicates logic, resulting in the
block not being stored on disk, and rerequested. This change fixes that by
only triggering in the case of duplicated transactions that can actually
result in an identical merkle root.
minor variable init changes in init.cpp

- explicit init of pcoinsdbview and pwalletMain (even if not needed, as
  globals are init to NULL, it seems cleaner)
- remove check if (pwalletMain) in Shutdown() as delete is valid even if
  pwalletMain is NULL
doc: Add instructions for consistent Mac OS X build names
Switch testing framework from MAIN to new UNITTEST network

UNITTEST inherites from MAIN but allows synamically changing its parameters using the ModifiableParams() interface
Suggested corrections on comments, variable names.
Also new test case testing the PoW skip in UNITTEST.
Avoid introducing a virtual into CChainParams

Treat fSkipProofOfWorkCheck the same as other parameters.
When transaction outputs exceed inputs, show the offending amounts so as to aid debugging.
Print input index when signature validation fails, to aid debugging.
travis: If the comparison-tool fails, dump the tail of the debug log

The entire debug log would be huge, and could cause issues for automated tools
like travis. Printing 200 lines is an initial guess at a reasonable number,
more may be required.
build: Fix OSX build when using Homebrew and qt5

Qt5 is bottled, so configure won't find it without some help. Use
brew to find out its prefix.

Also, qt5 added the host_bins variable to pkg-config, use it.
build: macdeploy: filter out irrelevant qt5 frameworks and dylibs
Upgrade comparison tool further
Merge pull request #4980

20a11ff minor variable init changes in init.cpp (Philip Kaufmann)
Merge pull request #4926

584a358 Do merkle root and txid duplicates check simultaneously (Pieter Wuille)
Merge pull request #5027

0f78a0a Upgrade comparison tool further (Pieter Wuille)
Merge pull request #5017

f74fc9b Print input index when signature validation fails, to aid debugging. (Mark Friedenbach)
217a5c9 When transaction outputs exceed inputs, show the offending amounts so as to aid debugging. (Mark Friedenbach)
Merge pull request #5025

5ad450a travis: If the comparison-tool fails, dump the tail of the debug log (Cory Fields)
Merge pull request #4845

4705902 Avoid introducing a virtual into CChainParams (Wladimir J. van der Laan)
5e2e7fc Suggested corrections on comments, variable names. Also new test case testing the PoW skip in UNITTEST. (SergioDemianLerner)
a25fd6b Switch testing framework from MAIN to new UNITTEST network (SergioDemianLerner)
Revert merge of pull #4845

It breaks the new mingw tests!

See

- https://travis-ci.org/bitcoin/bitcoin/jobs/36845581
- https://travis-ci.org/bitcoin/bitcoin/jobs/36845582

This reverts commit 470590277782cce2fe73275c74523aef59a51eab, 5e2e7fcb99738d9254d4030d53e4f711b2fc5ee0, a25fd6be138ff2bff7e2ad6a1a789db523c0193f.
CBufferedFile: convert into a non-refcounted RAII wrapper

- it now takes over the passed file descriptor and closes it in the
  destructor
- this fixes a leak in LoadExternalBlockFile(), where an exception could
  cause the file to not getting closed

- disallow copies (like recently added for CAutoFile)
- make nType and nVersion private