buildsystem: autodetect bsd/gnu stat and use appropriate

This fixes issues on Mac OS X

Signed-off-by: Andrew 'Necromant' Andrianov <andrew@ncrmnt.org>