diff --git a/lib/common/byteorder.h b/lib/common/byteorder.h
index 4b58a45658958e168b8b0dab51ee21eeba6a5d6a..634e184324ffbac06efd89a41d7f563bbd51b6c5 100644
--- a/lib/common/byteorder.h
+++ b/lib/common/byteorder.h
@@ -53,16 +53,30 @@
 #undef __LITTLE_ENDIAN
 #endif
 
-#if defined(__sparc__)
 #ifndef __BIG_ENDIAN
-#define __BIG_ENDIAN 4321
-#endif
+#  if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#    define __BIG_ENDIAN 4321
+#  elif defined(__clang__) && __BIG_ENDIAN__
+#    define __BIG_ENDIAN 4321
+#  elif defined(__sparc__)
+#    define __BIG_ENDIAN 4321
+#  endif
 #endif
 
-#if defined(__i386__) || defined(__x86_64__)
 #ifndef __LITTLE_ENDIAN
-#define __LITTLE_ENDIAN 1234
+#  if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#    define __LITTLE_ENDIAN 1234
+#  elif defined(__clang__) && __LITTLE_ENDIAN__
+#    define __LITTLE_ENDIAN 1234
+#  elif defined(_MSC_VER) && (_M_AMD64 || _M_IX86)
+#    define __LITTLE_ENDIAN 1234
+#  elif defined(__i386__) || defined(__x86_64__)
+#    define __LITTLE_ENDIAN 1234
+#  endif
 #endif
+
+#if defined(__BIG_ENDIAN) == defined(__LITTLE_ENDIAN)
+#error "Unknown byte order!"
 #endif
 
 
diff --git a/lib/common/cmp_data_types.c b/lib/common/cmp_data_types.c
index bba86c89ddf92ea9191cc6f37b004ec8f8a4d19d..f548702fb487d89d68b8f3dae91c63c724afaa02 100644
--- a/lib/common/cmp_data_types.c
+++ b/lib/common/cmp_data_types.c
@@ -885,7 +885,7 @@ int be_to_cpu_data_type(void *data, uint32_t data_size_byte, enum cmp_data_type
 	}
 	samples = data_size_byte / sample_size;
 
-#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#ifdef __LITTLE_ENDIAN
 	switch (data_type) {
 	case DATA_TYPE_IMAGETTE:
 	case DATA_TYPE_IMAGETTE_ADAPTIVE:
@@ -949,7 +949,7 @@ int be_to_cpu_data_type(void *data, uint32_t data_size_byte, enum cmp_data_type
 		return -1;
 	/* LCOV_EXCL_STOP */
 	}
-#endif /*__BYTE_ORDER__ */
+#endif /* __LITTLE_ENDIAN */
 
 	return 0;
 }
diff --git a/lib/rdcu_compress/rdcu_ctrl.c b/lib/rdcu_compress/rdcu_ctrl.c
index 0c23b5bf7396386f886ff763ada7552f6b454bd7..c5d748e34ceefc27c7c0368df3299f45ec7fd5aa 100644
--- a/lib/rdcu_compress/rdcu_ctrl.c
+++ b/lib/rdcu_compress/rdcu_ctrl.c
@@ -1653,9 +1653,9 @@ int rdcu_write_sram_16(const uint16_t *buf, uint32_t addr, uint32_t size)
 	if (addr + size > RDCU_SRAM_START + RDCU_SRAM_SIZE)
 		return -1;
 
-#if !(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#ifdef __BIG_ENDIAN
 	return rdcu_write_sram(buf, addr, size);
-#else
+#elif defined(__LITTLE_ENDIAN)
 	{
 		uint32_t i;
 
@@ -1666,7 +1666,9 @@ int rdcu_write_sram_16(const uint16_t *buf, uint32_t addr, uint32_t size)
 		}
 	}
 	return (int)size; /* lol */
-#endif /* __BYTE_ORDER__ */
+#else
+#error "Unknown byte order!"
+#endif
 }
 
 
@@ -1699,9 +1701,9 @@ int rdcu_write_sram_32(const uint32_t *buf, uint32_t addr, uint32_t size)
 	if (addr + size > RDCU_SRAM_START + RDCU_SRAM_SIZE)
 		return -1;
 
-#if !(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#ifdef __BIG_ENDIAN
 	return rdcu_write_sram(buf, addr, size);
-#else
+#elif defined(__LITTLE_ENDIAN)
 	{
 		uint32_t i;
 
@@ -1712,7 +1714,9 @@ int rdcu_write_sram_32(const uint32_t *buf, uint32_t addr, uint32_t size)
 		}
 	}
 	return (int)size; /* lol */
-#endif /* __BYTE_ORDER__ */
+#else
+#error "Unknown byte order!"
+#endif
 }
 
 
diff --git a/lib/rdcu_compress/rdcu_rmap.c b/lib/rdcu_compress/rdcu_rmap.c
index 7a740e8c205585a62be58ed05bd0960e89e6b217..dc7c71a5dfd259ce0b43a9d03a79a1bf87bdab90 100644
--- a/lib/rdcu_compress/rdcu_rmap.c
+++ b/lib/rdcu_compress/rdcu_rmap.c
@@ -292,7 +292,7 @@ static int rdcu_process_rx(void)
 			uint8_t crc8;
 
 			/* convert endianness in-place if needed */
-#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#ifdef __LITTLE_ENDIAN
 			{
 				uint32_t i, tmp;
 
@@ -302,7 +302,7 @@ static int rdcu_process_rx(void)
 					memcpy(&rp->data[i], &tmp, sizeof(tmp));
 				}
 			}
-#endif /* __BYTE_ORDER__ */
+#endif /* __LITTLE_ENDIAN */
 
 			crc8 = rmap_crc8(rp->data, rp->data_len);
 			if (crc8 != rp->data_crc) {
@@ -471,7 +471,7 @@ int rdcu_sync(int (*fn)(uint16_t trans_id, uint8_t *cmd),
 	}
 
 	/* convert endianness if needed */
-#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#ifdef __LITTLE_ENDIAN
 	if (data_len) {
 		uint32_t i;
 		uint32_t *tmp_buf = alloca(data_len);
@@ -482,7 +482,7 @@ int rdcu_sync(int (*fn)(uint16_t trans_id, uint8_t *cmd),
 
 		addr = tmp_buf;
 	}
-#endif /* __BYTE_ORDER__ */
+#endif /* __LITTLE_ENDIAN */
 
 	n = rdcu_submit_tx(rmap_cmd, (uint32_t)n, addr, data_len);
 	free(rmap_cmd);
diff --git a/lib/rdcu_compress/rmap.h b/lib/rdcu_compress/rmap.h
index 3dde00952ef8241ea944406b67f622463d83b562..9c217804b37300e8fa9414af3b6368870436236a 100644
--- a/lib/rdcu_compress/rmap.h
+++ b/lib/rdcu_compress/rmap.h
@@ -23,6 +23,7 @@
 #include <stddef.h>
 
 #include "../common/compiler.h"
+#include "../common/byteorder.h"
 
 /**
  * valid RMAP command codes, see Table 5-1 of ECSS‐E‐ST‐50‐52C
@@ -142,12 +143,12 @@
 
 __extension__
 struct rmap_instruction {
-#if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#ifdef __BIG_ENDIAN
 	uint8_t	reserved:1;
 	uint8_t	cmd_resp:1;
 	uint8_t cmd:4;
 	uint8_t	reply_addr_len:2;
-#elif (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#elif defined (__LITTLE_ENDIAN)
 	uint8_t	reply_addr_len:2;
 	uint8_t cmd:4;
 	uint8_t	cmd_resp:1;