Check if mktemp is available before using it.

Fixes #1514.
Merge remote-tracking branch 'upstream/master'