Detect tools before cleaning in ./configure

Previously this script would first try to run `ruby -S rake clean`. The `rake`
command here was pulled from the `@rake` instance variable. Due to this
variable not being set by default at this point the resulting command would be
`ruby -S clean` instead, resulting in a load error.

This commit fixes this by first checking the tools used and *then* running a
clean.

This fixes #2915.