This is a backport of core#19685 and core#20046
(with a contribution from https://github.com/bitcoin/bitcoin/pull/18677/commits/603fd6a2e708c04ef6c9880f89d0a4cbaa6fc7c5#diff-04ed828869a0888df31a01e355417d994dcf2f3a0b3a35b82c7510ebcd294943)
Note the use of `ninja` (introduced in some mk files in D865 and D13222)