From 8feb19058ef24a4d639a4c594313a91f747dc8a9 Mon Sep 17 00:00:00 2001
From: barracuda156 <vital.had@gmail.com>
Date: Mon, 6 Nov 2023 01:40:13 +0800
Subject: [PATCH] Fix build system

---
 common.gypi                            | 22 ++++++++++++----------
 configure.py                           |  4 +++-
 deps/cares/config/darwin/ares_config.h |  2 +-
 node.gyp                               |  1 -
 node.gypi                              |  3 ---
 tools/v8_gypfiles/toolchain.gypi       | 22 +++++++++++++++-------
 6 files changed, 31 insertions(+), 23 deletions(-)

diff --git common.gypi common.gypi
index 2bfae462d0..e3599a61af 100644
--- a/common.gypi
+++ b/common.gypi
@@ -38,6 +38,9 @@
 
     ##### V8 defaults for Node.js #####
 
+    # Try reduce ridiculous size of static libs.
+    'v8_enable_debugging_features': 0,
+
     # Old time default, now explicitly stated.
     'v8_use_snapshot': 1,
 
@@ -129,9 +132,12 @@
       }, {
         'openssl_product': '<(STATIC_LIB_PREFIX)openssl<(STATIC_LIB_SUFFIX)',
       }],
-      ['OS=="mac"', {
+      ['OS=="mac" and target_arch!="ppc" and target_arch!="ppc64"', {
         'clang%': 1,
       }],
+      ['target_arch in "arm mips ppc"', {
+        'ldflags': [ '-latomic' ]
+      }],
       ['target_arch in "ppc64 s390x"', {
         'v8_enable_backtrace': 1,
       }],
@@ -194,7 +200,7 @@
             }],
           ],
         },
-        'cflags': [ '-O3' ],
+        'cflags': [ '-O2' ],
         'conditions': [
           ['OS=="solaris"', {
             # pull in V8's postmortem metadata
@@ -237,7 +243,7 @@
           }
         },
         'xcode_settings': {
-          'GCC_OPTIMIZATION_LEVEL': '3', # stop gyp from defaulting to -Os
+          'GCC_OPTIMIZATION_LEVEL': '2', # stop gyp from defaulting to -Os
         },
       }
     },
@@ -458,7 +464,7 @@
         ],
       }],
       ['OS=="mac"', {
-        'defines': ['_DARWIN_USE_64_BIT_INODE=1'],
+        'defines': ['_DARWIN_USE_64_BIT_INODE=1', '__STDC_FORMAT_MACROS', '_DARWIN_C_SOURCE'],
         'xcode_settings': {
           'ALWAYS_SEARCH_USER_PATHS': 'NO',
           'GCC_CW_ASM_SYNTAX': 'NO',                # No -fasm-blocks
@@ -468,10 +474,11 @@
           'GCC_ENABLE_CPP_RTTI': 'NO',              # -fno-rtti
           'GCC_ENABLE_PASCAL_STRINGS': 'NO',        # No -mpascal-strings
           'PREBINDING': 'NO',                       # No -Wl,-prebind
-          'MACOSX_DEPLOYMENT_TARGET': '10.10',      # -mmacosx-version-min=10.10
+          'MACOSX_DEPLOYMENT_TARGET': '@OSX_V@',      # -mmacosx-version-min=@OSX_V@
           'USE_HEADERMAP': 'NO',
           'OTHER_CFLAGS': [
             '-fno-strict-aliasing',
+            '-fpermissive',
           ],
           'WARNING_CFLAGS': [
             '-Wall',
@@ -484,7 +491,6 @@
           ['_type!="static_library"', {
             'xcode_settings': {
               'OTHER_LDFLAGS': [
-                '-Wl,-no_pie',
                 '-Wl,-search_paths_first',
               ],
             },
@@ -497,12 +503,11 @@
           ['target_arch=="x64"', {
             'xcode_settings': {'ARCHS': ['x86_64']},
           }],
-          ['clang==1', {
-            'xcode_settings': {
-              'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
-              'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++1y',  # -std=gnu++1y
-              'CLANG_CXX_LIBRARY': 'libc++',
-            },
+          ['target_arch=="ppc"', {
+            'xcode_settings': {'ARCHS': ['ppc']},
+          }],
+          ['target_arch=="ppc64"', {
+            'xcode_settings': {'ARCHS': ['ppc64']},
           }],
         ],
       }],
diff --git configure.py configure.py
index e6485a7b38..1be6361779 100755
--- a/configure.py
+++ b/configure.py
@@ -952,7 +952,9 @@ def host_arch_cc():
     '__MIPSEL__'  : 'mipsel',
     '__mips__'    : 'mips',
     '__PPC64__'   : 'ppc64',
-    '__PPC__'     : 'ppc64',
+    '__ppc64__'   : 'ppc64',
+    '__PPC__'     : 'ppc',
+    '__ppc__'     : 'ppc',
     '__x86_64__'  : 'x64',
     '__s390x__'   : 's390x',
   }
diff --git deps/cares/config/darwin/ares_config.h deps/cares/config/darwin/ares_config.h
index 6625eccd6a..c2e206954a 100644
--- a/deps/cares/config/darwin/ares_config.h
+++ b/deps/cares/config/darwin/ares_config.h
@@ -354,7 +354,7 @@
 /* #undef NEED_THREAD_SAFE */
 
 /* cpu-machine-OS */
-#define OS "x86_64-apple-darwin16.7.0"
+/* #define OS "x86_64-apple-darwin16.7.0" */
 
 /* Name of package */
 #define PACKAGE "c-ares"
diff --git node.gyp node.gyp
index 3bb6ce32fa..d5dd0b16da 100644
--- a/node.gyp
+++ b/node.gyp
@@ -297,7 +297,6 @@
         '-Wendif-labels',
         '-W',
         '-Wno-unused-parameter',
-        '-Werror=undefined-inline',
       ],
     },
 
diff --git node.gypi node.gypi
index 116c1c7149..8b79045b24 100644
--- a/node.gypi
+++ b/node.gypi
@@ -26,9 +26,6 @@
   },
 
   'conditions': [
-    [ 'clang==1', {
-      'cflags': [ '-Werror=undefined-inline', ]
-    }],
     [ 'node_shared=="false" and "<(_type)"=="executable"', {
       'msvs_settings': {
         'VCManifestTool': {
diff --git tools/v8_gypfiles/toolchain.gypi tools/v8_gypfiles/toolchain.gypi
index 0876b16b46..680cfc7ce5 100644
--- a/tools/v8_gypfiles/toolchain.gypi
+++ b/tools/v8_gypfiles/toolchain.gypi
@@ -291,10 +291,12 @@
           ],
       }],  # s390x
       ['v8_target_arch=="ppc" or v8_target_arch=="ppc64"', {
-        'defines': [
-          'V8_TARGET_ARCH_PPC',
-        ],
         'conditions': [
+          ['v8_target_arch=="ppc"', {
+            'defines': [
+              'V8_TARGET_ARCH_PPC',
+            ],
+          }],
           ['v8_target_arch=="ppc64"', {
             'defines': [
               'V8_TARGET_ARCH_PPC64',
@@ -1011,7 +1013,7 @@
               }],
             ],
             'xcode_settings': {
-              'ARCHS': [ 'i386' ],
+              'ARCHS': [ 'ppc' ],
             },
           }],
           ['_toolset=="target"', {
@@ -1029,12 +1031,12 @@
               }],
             ],
             'xcode_settings': {
-              'ARCHS': [ 'i386' ],
+              'ARCHS': [ 'ppc' ],
             },
           }],
         ],
       }],
-      ['(OS=="linux" or OS=="android") and \
+      ['(OS=="linux" or OS=="mac" or OS=="android") and \
         (v8_target_arch=="x64" or v8_target_arch=="arm64" or \
          v8_target_arch=="ppc64" or v8_target_arch=="s390x")', {
         'target_conditions': [
@@ -1045,6 +1047,9 @@
                 'ldflags': [ '-m64' ]
               }],
              ],
+             'xcode_settings': {
+               'ARCHS': [ 'ppc64' ],
+             },
            }],
           ['_toolset=="target"', {
              'conditions': [
@@ -1052,7 +1057,10 @@
                  'cflags': [ '-m64' ],
                  'ldflags': [ '-m64' ],
                }],
-             ]
+             ],
+             'xcode_settings': {
+               'ARCHS': [ 'ppc64' ],
+             },
            }],
          ],
       }],
