diff --git a/contrib/endian-shim.h b/contrib/endian-shim.h
index 80c1becd532e81bd86c9a02e5af5972a249adf47..372bf19093b8dfb1cdd3cd9ef1f3949d888c56b6 100755
--- a/contrib/endian-shim.h
+++ b/contrib/endian-shim.h
@@ -45,7 +45,7 @@
 #define be64toh(x) OSSwapBigToHostInt64(x)
 #define le64toh(x) OSSwapLittleToHostInt64(x)
 
-#elif defined(__linux__)
+#elif defined(__linux__) || defined(__GNU__)
 # include <endian.h>
 # if !defined(htobe64)
 #  if __BYTE_ORDER == __LITTLE_ENDIAN
diff --git a/meson.build b/meson.build
index 0ed820152476e0caed3ba6d203ba236083fb8438..1fc7e55577c1f30b5f00164fb3e389beecb85213 100755
--- a/meson.build
+++ b/meson.build
@@ -96,6 +96,9 @@ else
 	elif host_machine.system() == 'darwin'
 		test_args += '-D_DARWIN_C_SOURCE'
 		add_project_arguments('-D_DARWIN_C_SOURCE', language: 'c')
+	elif host_machine.system() == 'gnu'
+		test_args += '-D_GNU_SOURCE'
+		add_project_arguments('-D_GNU_SOURCE', language: 'c')
 	endif
 	librist_soversion = librist_soversion
 	have_clock_gettime = cc.has_function('clock_gettime', prefix : '#include <time.h>', args : test_args)