Fix nativeapi.pm so it knows about AC_HEADER_STAT().
Make the error message about unexpected '#ifdef HAVE_XXX' clearer.
Protect sys/stat.h #includes with the corresponding '#ifdef HAVE_XXX'
check.

diff --git a/loader/preloader.c b/loader/preloader.c
index a10558b..cb974ff 100644
--- a/loader/preloader.c
+++ b/loader/preloader.c
@@ -68,7 +68,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
-#include <sys/stat.h>
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
 #include <fcntl.h>
 #ifdef HAVE_SYS_MMAN_H
 # include <sys/mman.h>