Update tools.mk and fix some xref/dialyzer issues

@slfritchie, can you please double-check 6014262f028934537eb4f9773c0a3eba9b72268e?