--- src/bson/bson-config.h.orig	2023-01-07 06:38:44.000000000 +0800
+++ src/bson/bson-config.h	2023-07-15 07:44:47.000000000 +0800
@@ -8,31 +8,35 @@
 #define BSON_HAVE_ATOMIC_64_ADD_AND_FETCH 0
 /* sparc is big endian */
 #include <sys/byteorder.h>
-#ifdef _BIG_ENDIAN
+#define BSON_BYTE_ORDER 4321
+#elif defined(__APPLE__) && defined(__POWERPC__)
+#define BSON_BYTE_ORDER 4321
+#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
 #define BSON_BYTE_ORDER 4321
 #else
 #define BSON_BYTE_ORDER 1234
 #endif
-#else
-/* for everyone else */
-#define BSON_BYTE_ORDER 1234
+
 #define BSON_HAVE_STRNLEN 1
 #define BSON_HAVE_ATOMIC_32_ADD_AND_FETCH 1
 #define BSON_HAVE_ATOMIC_64_ADD_AND_FETCH 1
 #if !defined (__FreeBSD__) && !defined (__OpenBSD__)
 #define BSON_HAVE_SYSCALL_TID 1
 #endif
-#endif
 
 /* Fix for snow leopard */
 #ifdef __APPLE__
 #define BSON_HAVE_REALLOCF 1
 #define BSON_HAVE_STRLCPY 1
-#include <Availability.h>
+#include <AvailabilityMacros.h>
 #ifndef MAC_OS_X_VERSION_10_8
 #undef BSON_HAVE_STRNLEN
 #define BSON_HAVE_STRNLEN 0
 #endif
+#ifdef __ppc__
+#undef BSON_HAVE_ATOMIC_64_ADD_AND_FETCH
+#define BSON_HAVE_ATOMIC_64_ADD_AND_FETCH 0
+#endif
 #endif
 
 /*

--- src/Makevars.in.orig	2023-01-07 06:38:40.000000000 +0800
+++ src/Makevars.in	2023-07-15 09:44:13.000000000 +0800
@@ -6,7 +6,7 @@
 	bson/bson-error.o bson/bson-iso8601.o bson/bson-iter.o bson/bson-json.o \
 	bson/bson-keys.o bson/bson-md5.o bson/bson-memory.o bson/bson-oid.o \
 	bson/bson-reader.o bson/bson-string.o bson/bson-timegm.o bson/bson-utf8.o \
-	bson/bson-value.o bson/bson.o bson/bson-decimal128.o jsonsl/jsonsl.o
+	bson/bson-value.o bson/bson.o bson/bson-decimal128.o bson/bson-atomic.o jsonsl/jsonsl.o
 
 LIBMONGOC=mongoc/mongoc-array.o common/common-b64.o mongoc/mongoc-buffer.o \
 	mongoc/mongoc-bulk-operation.o mongoc/mongoc-client-pool.o mongoc/mongoc-client.o \
