diff --git a/intel/test_decode.c b/intel/test_decode.c
index b710f34..bef9d99 100644
--- a/intel/test_decode.c
+++ b/intel/test_decode.c
@@ -21,7 +21,9 @@
  * IN THE SOFTWARE.
  */
 
-#define _GNU_SOURCE
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include <string.h>
 #include <stdlib.h>
@@ -33,7 +35,6 @@
 #include <sys/mman.h>
 #include <err.h>
 
-#include "config.h"
 #include "intel_bufmgr.h"
 #include "intel_chipset.h"
 
diff --git a/libkms/api.c b/libkms/api.c
index 5befaa0..b512c42 100644
--- a/libkms/api.c
+++ b/libkms/api.c
@@ -26,7 +26,9 @@
  **************************************************************************/
 
 
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#endif
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/libkms/dumb.c b/libkms/dumb.c
index 440efb3..794282f 100644
--- a/libkms/dumb.c
+++ b/libkms/dumb.c
@@ -26,7 +26,9 @@
  **************************************************************************/
 
 
-#define HAVE_STDINT_H
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #define _FILE_OFFSET_BITS 64
 
 #include <errno.h>
diff --git a/libkms/exynos.c b/libkms/exynos.c
index 93e36a1..243915b 100644
--- a/libkms/exynos.c
+++ b/libkms/exynos.c
@@ -11,7 +11,9 @@
  * option) any later version.
  */
 
-#define HAVE_STDINT_H
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #define _FILE_OFFSET_BITS 64
 
 #include <errno.h>
diff --git a/libkms/intel.c b/libkms/intel.c
index abae452..92f1cf2 100644
--- a/libkms/intel.c
+++ b/libkms/intel.c
@@ -26,7 +26,9 @@
  **************************************************************************/
 
 
-#define HAVE_STDINT_H
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #define _FILE_OFFSET_BITS 64
 
 #include <errno.h>
diff --git a/libkms/linux.c b/libkms/linux.c
index 9b4f29e..17e1d58 100644
--- a/libkms/linux.c
+++ b/libkms/linux.c
@@ -30,7 +30,9 @@
  */
 
 
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#endif
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/libkms/nouveau.c b/libkms/nouveau.c
index 608092f..2de827d 100644
--- a/libkms/nouveau.c
+++ b/libkms/nouveau.c
@@ -26,7 +26,9 @@
  **************************************************************************/
 
 
-#define HAVE_STDINT_H
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #define _FILE_OFFSET_BITS 64
 
 #include <errno.h>
diff --git a/libkms/radeon.c b/libkms/radeon.c
index f5e382a..29375c4 100644
--- a/libkms/radeon.c
+++ b/libkms/radeon.c
@@ -26,7 +26,9 @@
  **************************************************************************/
 
 
-#define HAVE_STDINT_H
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #define _FILE_OFFSET_BITS 64
 
 #include <errno.h>
diff --git a/libkms/vmwgfx.c b/libkms/vmwgfx.c
index d594b3b..598f383 100644
--- a/libkms/vmwgfx.c
+++ b/libkms/vmwgfx.c
@@ -26,7 +26,9 @@
  **************************************************************************/
 
 
-#define HAVE_STDINT_H
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #define _FILE_OFFSET_BITS 64
 
 #include <errno.h>
diff --git a/tests/drmstat.c b/tests/drmstat.c
index c51cbc6..5935d07 100644
--- a/tests/drmstat.c
+++ b/tests/drmstat.c
@@ -28,7 +28,9 @@
  * 
  */
 
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#endif
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/tests/modetest/buffers.c b/tests/modetest/buffers.c
index 8206ce3..29b520d 100644
--- a/tests/modetest/buffers.c
+++ b/tests/modetest/buffers.c
@@ -24,7 +24,9 @@
  * IN THE SOFTWARE.
  */
 
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#endif
 
 #include <assert.h>
 #include <errno.h>
diff --git a/tests/modetest/cursor.c b/tests/modetest/cursor.c
index 7077f20..60f240a 100644
--- a/tests/modetest/cursor.c
+++ b/tests/modetest/cursor.c
@@ -22,7 +22,9 @@
  * IN THE SOFTWARE.
  */
 
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#endif
 
 #include <assert.h>
 #include <errno.h>
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
index 7d436b5..92efb82 100644
--- a/tests/modetest/modetest.c
+++ b/tests/modetest/modetest.c
@@ -37,7 +37,9 @@
  * TODO: use cairo to write the mode info on the selected output once
  *       the mode has been programmed, along with possible test patterns.
  */
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#endif
 
 #include <assert.h>
 #include <ctype.h>
diff --git a/tests/vbltest/vbltest.c b/tests/vbltest/vbltest.c
index 2a09d28..50e29dc 100644
--- a/tests/vbltest/vbltest.c
+++ b/tests/vbltest/vbltest.c
@@ -37,7 +37,9 @@
  * TODO: use cairo to write the mode info on the selected output once
  *       the mode has been programmed, along with possible test patterns.
  */
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#endif
 
 #include <assert.h>
 #include <stdio.h>
