Millwall have signed Australia striker Scott McDonald on a two-year contract after his deal with Middlesbrough was terminated by mutual consent.