diff --git a/src/backend.c b/src/backend.c
index 77842daf55722cb2a83f05e746d01f7477bd423e..f3a47a4d036a83a35dc66af00932052a742e9260 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -3,12 +3,14 @@
 ||| uLPC is distributed as GPL (General Public License)
 ||| See the files COPYING and DISCLAIMER for more information.
 \*/
+#include "global.h"
 #include <errno.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
+#endif
 #include <sys/param.h>
 #include <string.h>
-#include "global.h"
 #include "interpret.h"
 #include "object.h"
 #include "types.h"
diff --git a/src/backend.h b/src/backend.h
index 9dad1c41cc612f76f855886b562261025b6fc14d..b69daeb74c97fd73537675309b3be5025a47a36e 100644
--- a/src/backend.h
+++ b/src/backend.h
@@ -6,6 +6,13 @@
 #ifndef BACKEND_H
 #define BACKEND_H
 
+#include "global.h"
+
+#ifdef HAVE_TIME_H
+#include <time.h>
+#undef HAVE_TIME_H
+#endif
+
 extern time_t current_time;
 typedef void (*callback)(int,void *);
 
diff --git a/src/builtin_efuns.c b/src/builtin_efuns.c
index e61d0a4456962686e51c4f2338970b7937530376..bf2b6ab2d03943ba329e05940637839ecfe16b6e 100644
--- a/src/builtin_efuns.c
+++ b/src/builtin_efuns.c
@@ -22,7 +22,9 @@
 #include "fsort.h"
 #include "call_out.h"
 #include "callback.h"
+#ifdef HAVE_SYS_TIME
 #include <sys/time.h>
+#endif
 #ifdef HAVE_CRYPT_H
 #include <crypt.h>
 #endif
diff --git a/src/call_out.h b/src/call_out.h
index 2793be77a886bb6c5a5348844d95b7e7348a2268..7f51b71373327ab8df90a2ab7508881857606773 100644
--- a/src/call_out.h
+++ b/src/call_out.h
@@ -8,6 +8,12 @@
 
 #include "types.h"
 
+#ifdef HAVE_TIME_H
+/* Needed for time_t */
+#include <time.h>
+#undef HAVE_TIME_H
+#endif
+
 struct call_out_s
 {
   time_t time;