From b065043451b9fcf69b1a812e6853c55d598d4092 Mon Sep 17 00:00:00 2001
From: barracuda156 <vital.had@gmail.com>
Date: Fri, 3 Nov 2023 13:36:26 +0800
Subject: [PATCH 4/5] build_config.h, sys_info.cc, args.cc: fix PowerPC
 definitions

---
 src/gn/args.cc          |  3 +++
 src/util/build_config.h | 13 +++++++++----
 src/util/sys_info.cc    |  4 +++-
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git src/gn/args.cc src/gn/args.cc
index 6b5d25f3..d5feaf24 100644
--- src/gn/args.cc
+++ src/gn/args.cc
@@ -344,6 +344,7 @@ void Args::SetSystemVarsLocked(Scope* dest) const {
   static const char kMips[] = "mipsel";
   static const char kMips64[] = "mips64el";
   static const char kS390X[] = "s390x";
+  static const char kPPC[] = "ppc";
   static const char kPPC64[] = "ppc64";
   static const char kRISCV32[] = "riscv32";
   static const char kRISCV64[] = "riscv64";
@@ -368,6 +369,8 @@ void Args::SetSystemVarsLocked(Scope* dest) const {
     arch = kMips64;
   else if (os_arch == "s390x")
     arch = kS390X;
+  else if (os_arch == "ppc")
+    arch = kPPC;
   else if (os_arch == "ppc64" || os_arch == "ppc64le")
     // We handle the endianness inside //build/config/host_byteorder.gni.
     // This allows us to use the same toolchain as ppc64 BE
diff --git src/util/build_config.h src/util/build_config.h
index 668518ba..baa667b7 100644
--- src/util/build_config.h
+++ src/util/build_config.h
@@ -120,16 +120,21 @@
 #define ARCH_CPU_S390 1
 #define ARCH_CPU_31_BITS 1
 #define ARCH_CPU_BIG_ENDIAN 1
-#elif (defined(__PPC64__) || defined(__PPC__)) && defined(__BIG_ENDIAN__)
+#elif defined(__ppc__) || defined(__PPC__)
+#define ARCH_CPU_PPC_FAMILY 1
+#define ARCH_CPU_PPC 1
+#define ARCH_CPU_32_BITS 1
+#define ARCH_CPU_BIG_ENDIAN 1
+#elif defined(__PPC64__) && defined(__LITTLE_ENDIAN__)
 #define ARCH_CPU_PPC64_FAMILY 1
 #define ARCH_CPU_PPC64 1
 #define ARCH_CPU_64_BITS 1
-#define ARCH_CPU_BIG_ENDIAN 1
-#elif defined(__PPC64__)
+#define ARCH_CPU_LITTLE_ENDIAN 1
+#elif (defined(__PPC64__) || defined(__ppc64__))
 #define ARCH_CPU_PPC64_FAMILY 1
 #define ARCH_CPU_PPC64 1
 #define ARCH_CPU_64_BITS 1
-#define ARCH_CPU_LITTLE_ENDIAN 1
+#define ARCH_CPU_BIG_ENDIAN 1
 #elif defined(__ARMEL__)
 #define ARCH_CPU_ARM_FAMILY 1
 #define ARCH_CPU_ARMEL 1
diff --git src/util/sys_info.cc src/util/sys_info.cc
index c8dc590a..a1970d67 100644
--- src/util/sys_info.cc
+++ src/util/sys_info.cc
@@ -34,7 +34,9 @@ std::string OperatingSystemArchitecture() {
     arch = "x86_64";
   } else if (arch == "amd64") {
     arch = "x86_64";
-  } else if (os == "AIX" || os == "OS400") {
+  } else if (arch == "ppc" || arch == "powerpc" || arch == "Power Macintosh") {
+    arch = "ppc";
+  } else if (os == "AIX" || os == "OS400" || arch == "ppc64" || arch == "powerpc64") {
     arch = "ppc64";
   } else if (std::string(info.sysname) == "OS/390") {
     arch = "s390x";
