From 9ffa1d1f29fc1ac92f28e809aa5bf97897338d1d Mon Sep 17 00:00:00 2001
From: barracuda156 <vital.had@gmail.com>
Date: Sat, 20 Jan 2024 16:48:45 +0800
Subject: [PATCH 6/6] Fix endianness includes and macros

2025 Sept 17: Updated 2 of 4 patches for algol68g version 3.9.5.

---
 a68g-config.h               | 8 +++++++-
 configure.ac                | 2 +-
 src/a68g/rts-sounds.c       | 9 ++++-----
 src/include/a68g-includes.h | 4 ++++
 4 files changed, 16 insertions(+), 7 deletions(-)

diff --git a68g-config.h a68g-config.h
index d3a0e0e..3c87975 100644
--- a68g-config.h
+++ a68g-config.h
@@ -66,7 +66,13 @@
 /* #undef HAVE_DLFCN_H */
 
 /* Define to 1 if you have the <endian.h> header file. */
-#define HAVE_ENDIAN_H 1
+/* #define HAVE_ENDIAN_H 1 */
+
+/* Define to 1 if you have the <machine/endian.h> header file. */
+#define HAVE_MACHINE_ENDIAN_H 1
+
+/* Define to 1 if you have the <sys/endian.h> header file. */
+/* #define HAVE_SYS_ENDIAN_H 1 */
 
 /* Define to 1 if you have the <errno.h> header file. */
 #define HAVE_ERRNO_H 1

--- configure.ac.orig	2025-09-15 08:48:43
+++ configure.ac	2025-09-17 18:10:37
@@ -567,7 +567,7 @@
 AC_HEADER_SYS_WAIT
 AC_HEADER_TIOCGWINSZ
 
-AC_CHECK_HEADERS([assert.h complex.h ctype.h endian.h errno.h execinfo.h fcntl.h fenv.h float.h libgen.h limits.h malloc.h regex.h setjmp.h signal.h stdarg.h stddef.h stdio.h stdlib.h sys/ioctl.h sys/resource.h sys/time.h termios.h time.h unistd.h])
+AC_CHECK_HEADERS([assert.h complex.h ctype.h endian.h machine/endian.h sys/endian.h errno.h execinfo.h fcntl.h fenv.h float.h libgen.h limits.h malloc.h regex.h setjmp.h signal.h stdarg.h stddef.h stdio.h stdlib.h sys/ioctl.h sys/resource.h sys/time.h termios.h time.h unistd.h])
 
 #
 # Functions we expect.

diff -u src/a68g/rts-sounds.c.orig src/a68g/rts-sounds.c
--- src/a68g/rts-sounds.c.orig	2025-08-08 14:52:48
+++ src/a68g/rts-sounds.c	2025-08-09 23:33:53
@@ -31,14 +31,13 @@
 
 #define MAX_BYTES 4
 
-#if (__BYTE_ORDER == __LITTLE_ENDIAN)
-  #define A68G_LITTLE_ENDIAN A68G_TRUE
-  #define A68G_BIG_ENDIAN A68G_FALSE
-#elif (__BYTE_ORDER == __BIG_ENDIAN)
+#if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) || \
+  (defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN))
   #define A68G_LITTLE_ENDIAN A68G_FALSE
   #define A68G_BIG_ENDIAN A68G_TRUE
 #else
-  #error "undefined endianness"
+  #define A68G_LITTLE_ENDIAN A68G_TRUE
+  #define A68G_BIG_ENDIAN A68G_FALSE
 #endif
 
 // From public Microsoft RIFF documentation.

--- src/include/a68g-includes.h.orig	2025-09-15 08:46:38
+++ src/include/a68g-includes.h	2025-09-17 18:24:09
@@ -75,6 +75,10 @@
 
 #if defined (HAVE_ENDIAN_H)
   #include <endian.h>
+#elif defined (HAVE_MACHINE_ENDIAN_H)
+  #include <machine/endian.h>
+#elif defined (HAVE_SYS_ENDIAN_H)
+  #include <sys/endian.h>
 #endif
 
 #if defined (HAVE_ERRNO_H)
