11cb0ef41Sopenharmony_cifrom __future__ import print_function
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciimport json
41cb0ef41Sopenharmony_ciimport sys
51cb0ef41Sopenharmony_ciimport errno
61cb0ef41Sopenharmony_ciimport argparse
71cb0ef41Sopenharmony_ciimport os
81cb0ef41Sopenharmony_ciimport pprint
91cb0ef41Sopenharmony_ciimport re
101cb0ef41Sopenharmony_ciimport shlex
111cb0ef41Sopenharmony_ciimport subprocess
121cb0ef41Sopenharmony_ciimport shutil
131cb0ef41Sopenharmony_ciimport bz2
141cb0ef41Sopenharmony_ciimport io
151cb0ef41Sopenharmony_cifrom pathlib import Path
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_cifrom distutils.version import StrictVersion
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci# If not run from node/, cd to node/.
201cb0ef41Sopenharmony_cios.chdir(Path(__file__).parent)
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_cioriginal_argv = sys.argv[1:]
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci# gcc and g++ as defaults matches what GYP's Makefile generator does,
251cb0ef41Sopenharmony_ci# except on OS X.
261cb0ef41Sopenharmony_ciCC = os.environ.get('CC', 'cc' if sys.platform == 'darwin' else 'gcc')
271cb0ef41Sopenharmony_ciCXX = os.environ.get('CXX', 'c++' if sys.platform == 'darwin' else 'g++')
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_citools_path = Path('tools')
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_cisys.path.insert(0, str(tools_path / 'gyp' / 'pylib'))
321cb0ef41Sopenharmony_cifrom gyp.common import GetFlavor
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci# imports in tools/configure.d
351cb0ef41Sopenharmony_cisys.path.insert(0, str(tools_path / 'configure.d'))
361cb0ef41Sopenharmony_ciimport nodedownload
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci# imports in tools/
391cb0ef41Sopenharmony_cisys.path.insert(0, 'tools')
401cb0ef41Sopenharmony_ciimport getmoduleversion
411cb0ef41Sopenharmony_ciimport getnapibuildversion
421cb0ef41Sopenharmony_ciimport getsharedopensslhasquic
431cb0ef41Sopenharmony_cifrom gyp_node import run_gyp
441cb0ef41Sopenharmony_cifrom utils import SearchFiles
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci# parse our options
471cb0ef41Sopenharmony_ciparser = argparse.ArgumentParser()
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_civalid_os = ('win', 'mac', 'solaris', 'freebsd', 'openbsd', 'linux',
501cb0ef41Sopenharmony_ci            'android', 'aix', 'cloudabi', 'os400', 'ios')
511cb0ef41Sopenharmony_civalid_arch = ('arm', 'arm64', 'ia32', 'mips', 'mipsel', 'mips64el', 'ppc',
521cb0ef41Sopenharmony_ci              'ppc64', 'x64', 'x86', 'x86_64', 's390x', 'riscv64', 'loong64')
531cb0ef41Sopenharmony_civalid_arm_float_abi = ('soft', 'softfp', 'hard')
541cb0ef41Sopenharmony_civalid_arm_fpu = ('vfp', 'vfpv3', 'vfpv3-d16', 'neon')
551cb0ef41Sopenharmony_civalid_mips_arch = ('loongson', 'r1', 'r2', 'r6', 'rx')
561cb0ef41Sopenharmony_civalid_mips_fpu = ('fp32', 'fp64', 'fpxx')
571cb0ef41Sopenharmony_civalid_mips_float_abi = ('soft', 'hard')
581cb0ef41Sopenharmony_civalid_intl_modes = ('none', 'small-icu', 'full-icu', 'system-icu')
591cb0ef41Sopenharmony_ciicu_versions = json.loads((tools_path / 'icu' / 'icu_versions.json').read_text(encoding='utf-8'))
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_cishareable_builtins = {'cjs_module_lexer/lexer': 'deps/cjs-module-lexer/lexer.js',
621cb0ef41Sopenharmony_ci                     'cjs_module_lexer/dist/lexer': 'deps/cjs-module-lexer/dist/lexer.js',
631cb0ef41Sopenharmony_ci                     'undici/undici': 'deps/undici/undici.js'
641cb0ef41Sopenharmony_ci}
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ci# create option groups
671cb0ef41Sopenharmony_cishared_optgroup = parser.add_argument_group("Shared libraries",
681cb0ef41Sopenharmony_ci    "Flags that allows you to control whether you want to build against "
691cb0ef41Sopenharmony_ci    "built-in dependencies or its shared representations. If necessary, "
701cb0ef41Sopenharmony_ci    "provide multiple libraries with comma.")
711cb0ef41Sopenharmony_cistatic_optgroup = parser.add_argument_group("Static libraries",
721cb0ef41Sopenharmony_ci    "Flags that allows you to control whether you want to build against "
731cb0ef41Sopenharmony_ci    "additional static libraries.")
741cb0ef41Sopenharmony_ciintl_optgroup = parser.add_argument_group("Internationalization",
751cb0ef41Sopenharmony_ci    "Flags that lets you enable i18n features in Node.js as well as which "
761cb0ef41Sopenharmony_ci    "library you want to build against.")
771cb0ef41Sopenharmony_cihttp2_optgroup = parser.add_argument_group("HTTP2",
781cb0ef41Sopenharmony_ci    "Flags that allows you to control HTTP2 features in Node.js")
791cb0ef41Sopenharmony_cishared_builtin_optgroup = parser.add_argument_group("Shared builtins",
801cb0ef41Sopenharmony_ci    "Flags that allows you to control whether you want to build against "
811cb0ef41Sopenharmony_ci    "internal builtins or shared files.")
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci# Options should be in alphabetical order but keep --prefix at the top,
841cb0ef41Sopenharmony_ci# that's arguably the one people will be looking for most.
851cb0ef41Sopenharmony_ciparser.add_argument('--prefix',
861cb0ef41Sopenharmony_ci    action='store',
871cb0ef41Sopenharmony_ci    dest='prefix',
881cb0ef41Sopenharmony_ci    default='/usr/local',
891cb0ef41Sopenharmony_ci    help='select the install prefix [default: %(default)s]')
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ciparser.add_argument('--coverage',
921cb0ef41Sopenharmony_ci    action='store_true',
931cb0ef41Sopenharmony_ci    dest='coverage',
941cb0ef41Sopenharmony_ci    default=None,
951cb0ef41Sopenharmony_ci    help='Build node with code coverage enabled')
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ciparser.add_argument('--debug',
981cb0ef41Sopenharmony_ci    action='store_true',
991cb0ef41Sopenharmony_ci    dest='debug',
1001cb0ef41Sopenharmony_ci    default=None,
1011cb0ef41Sopenharmony_ci    help='also build debug build')
1021cb0ef41Sopenharmony_ci
1031cb0ef41Sopenharmony_ciparser.add_argument('--debug-node',
1041cb0ef41Sopenharmony_ci    action='store_true',
1051cb0ef41Sopenharmony_ci    dest='debug_node',
1061cb0ef41Sopenharmony_ci    default=None,
1071cb0ef41Sopenharmony_ci    help='build the Node.js part of the binary with debugging symbols')
1081cb0ef41Sopenharmony_ci
1091cb0ef41Sopenharmony_ciparser.add_argument('--dest-cpu',
1101cb0ef41Sopenharmony_ci    action='store',
1111cb0ef41Sopenharmony_ci    dest='dest_cpu',
1121cb0ef41Sopenharmony_ci    choices=valid_arch,
1131cb0ef41Sopenharmony_ci    help=f"CPU architecture to build for ({', '.join(valid_arch)})")
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_ciparser.add_argument('--cross-compiling',
1161cb0ef41Sopenharmony_ci    action='store_true',
1171cb0ef41Sopenharmony_ci    dest='cross_compiling',
1181cb0ef41Sopenharmony_ci    default=None,
1191cb0ef41Sopenharmony_ci    help='force build to be considered as cross compiled')
1201cb0ef41Sopenharmony_ciparser.add_argument('--no-cross-compiling',
1211cb0ef41Sopenharmony_ci    action='store_false',
1221cb0ef41Sopenharmony_ci    dest='cross_compiling',
1231cb0ef41Sopenharmony_ci    default=None,
1241cb0ef41Sopenharmony_ci    help='force build to be considered as NOT cross compiled')
1251cb0ef41Sopenharmony_ci
1261cb0ef41Sopenharmony_ciparser.add_argument('--dest-os',
1271cb0ef41Sopenharmony_ci    action='store',
1281cb0ef41Sopenharmony_ci    dest='dest_os',
1291cb0ef41Sopenharmony_ci    choices=valid_os,
1301cb0ef41Sopenharmony_ci    help=f"operating system to build for ({', '.join(valid_os)})")
1311cb0ef41Sopenharmony_ci
1321cb0ef41Sopenharmony_ciparser.add_argument('--error-on-warn',
1331cb0ef41Sopenharmony_ci    action='store_true',
1341cb0ef41Sopenharmony_ci    dest='error_on_warn',
1351cb0ef41Sopenharmony_ci    default=None,
1361cb0ef41Sopenharmony_ci    help='Turn compiler warnings into errors for node core sources.')
1371cb0ef41Sopenharmony_ci
1381cb0ef41Sopenharmony_ciparser.add_argument('--gdb',
1391cb0ef41Sopenharmony_ci    action='store_true',
1401cb0ef41Sopenharmony_ci    dest='gdb',
1411cb0ef41Sopenharmony_ci    default=None,
1421cb0ef41Sopenharmony_ci    help='add gdb support')
1431cb0ef41Sopenharmony_ci
1441cb0ef41Sopenharmony_ciparser.add_argument('--no-ifaddrs',
1451cb0ef41Sopenharmony_ci    action='store_true',
1461cb0ef41Sopenharmony_ci    dest='no_ifaddrs',
1471cb0ef41Sopenharmony_ci    default=None,
1481cb0ef41Sopenharmony_ci    help='use on deprecated SunOS systems that do not support ifaddrs.h')
1491cb0ef41Sopenharmony_ci
1501cb0ef41Sopenharmony_ciparser.add_argument('--disable-single-executable-application',
1511cb0ef41Sopenharmony_ci    action='store_true',
1521cb0ef41Sopenharmony_ci    dest='disable_single_executable_application',
1531cb0ef41Sopenharmony_ci    default=None,
1541cb0ef41Sopenharmony_ci    help='Disable Single Executable Application support.')
1551cb0ef41Sopenharmony_ci
1561cb0ef41Sopenharmony_ciparser.add_argument("--fully-static",
1571cb0ef41Sopenharmony_ci    action="store_true",
1581cb0ef41Sopenharmony_ci    dest="fully_static",
1591cb0ef41Sopenharmony_ci    default=None,
1601cb0ef41Sopenharmony_ci    help="Generate an executable without external dynamic libraries. This "
1611cb0ef41Sopenharmony_ci         "will not work on OSX when using the default compilation environment")
1621cb0ef41Sopenharmony_ci
1631cb0ef41Sopenharmony_ciparser.add_argument("--partly-static",
1641cb0ef41Sopenharmony_ci    action="store_true",
1651cb0ef41Sopenharmony_ci    dest="partly_static",
1661cb0ef41Sopenharmony_ci    default=None,
1671cb0ef41Sopenharmony_ci    help="Generate an executable with libgcc and libstdc++ libraries. This "
1681cb0ef41Sopenharmony_ci         "will not work on OSX when using the default compilation environment")
1691cb0ef41Sopenharmony_ci
1701cb0ef41Sopenharmony_ciparser.add_argument("--enable-vtune-profiling",
1711cb0ef41Sopenharmony_ci    action="store_true",
1721cb0ef41Sopenharmony_ci    dest="enable_vtune_profiling",
1731cb0ef41Sopenharmony_ci    help="Enable profiling support for Intel VTune profiler to profile "
1741cb0ef41Sopenharmony_ci         "JavaScript code executed in Node.js. This feature is only available "
1751cb0ef41Sopenharmony_ci         "for x32, x86, and x64 architectures.")
1761cb0ef41Sopenharmony_ci
1771cb0ef41Sopenharmony_ciparser.add_argument("--enable-pgo-generate",
1781cb0ef41Sopenharmony_ci    action="store_true",
1791cb0ef41Sopenharmony_ci    dest="enable_pgo_generate",
1801cb0ef41Sopenharmony_ci    default=None,
1811cb0ef41Sopenharmony_ci    help="Enable profiling with pgo of a binary. This feature is only available "
1821cb0ef41Sopenharmony_ci         "on linux with gcc and g++ 5.4.1 or newer.")
1831cb0ef41Sopenharmony_ci
1841cb0ef41Sopenharmony_ciparser.add_argument("--enable-pgo-use",
1851cb0ef41Sopenharmony_ci    action="store_true",
1861cb0ef41Sopenharmony_ci    dest="enable_pgo_use",
1871cb0ef41Sopenharmony_ci    default=None,
1881cb0ef41Sopenharmony_ci    help="Enable use of the profile generated with --enable-pgo-generate. This "
1891cb0ef41Sopenharmony_ci         "feature is only available on linux with gcc and g++ 5.4.1 or newer.")
1901cb0ef41Sopenharmony_ci
1911cb0ef41Sopenharmony_ciparser.add_argument("--enable-lto",
1921cb0ef41Sopenharmony_ci    action="store_true",
1931cb0ef41Sopenharmony_ci    dest="enable_lto",
1941cb0ef41Sopenharmony_ci    default=None,
1951cb0ef41Sopenharmony_ci    help="Enable compiling with lto of a binary. This feature is only available "
1961cb0ef41Sopenharmony_ci         "with gcc 5.4.1+ or clang 3.9.1+.")
1971cb0ef41Sopenharmony_ci
1981cb0ef41Sopenharmony_ciparser.add_argument("--link-module",
1991cb0ef41Sopenharmony_ci    action="append",
2001cb0ef41Sopenharmony_ci    dest="linked_module",
2011cb0ef41Sopenharmony_ci    help="Path to a JS file to be bundled in the binary as a builtin. "
2021cb0ef41Sopenharmony_ci         "This module will be referenced by path without extension; "
2031cb0ef41Sopenharmony_ci         "e.g. /root/x/y.js will be referenced via require('root/x/y'). "
2041cb0ef41Sopenharmony_ci         "Can be used multiple times")
2051cb0ef41Sopenharmony_ci
2061cb0ef41Sopenharmony_ciparser.add_argument("--openssl-conf-name",
2071cb0ef41Sopenharmony_ci    action="store",
2081cb0ef41Sopenharmony_ci    dest="openssl_conf_name",
2091cb0ef41Sopenharmony_ci    default='nodejs_conf',
2101cb0ef41Sopenharmony_ci    help="The OpenSSL config appname (config section name) used by Node.js")
2111cb0ef41Sopenharmony_ci
2121cb0ef41Sopenharmony_ciparser.add_argument('--openssl-default-cipher-list',
2131cb0ef41Sopenharmony_ci    action='store',
2141cb0ef41Sopenharmony_ci    dest='openssl_default_cipher_list',
2151cb0ef41Sopenharmony_ci    help='Use the specified cipher list as the default cipher list')
2161cb0ef41Sopenharmony_ci
2171cb0ef41Sopenharmony_ciparser.add_argument("--openssl-no-asm",
2181cb0ef41Sopenharmony_ci    action="store_true",
2191cb0ef41Sopenharmony_ci    dest="openssl_no_asm",
2201cb0ef41Sopenharmony_ci    default=None,
2211cb0ef41Sopenharmony_ci    help="Do not build optimized assembly for OpenSSL")
2221cb0ef41Sopenharmony_ci
2231cb0ef41Sopenharmony_ciparser.add_argument('--openssl-is-fips',
2241cb0ef41Sopenharmony_ci    action='store_true',
2251cb0ef41Sopenharmony_ci    dest='openssl_is_fips',
2261cb0ef41Sopenharmony_ci    default=None,
2271cb0ef41Sopenharmony_ci    help='specifies that the OpenSSL library is FIPS compatible')
2281cb0ef41Sopenharmony_ci
2291cb0ef41Sopenharmony_ciparser.add_argument('--openssl-use-def-ca-store',
2301cb0ef41Sopenharmony_ci    action='store_true',
2311cb0ef41Sopenharmony_ci    dest='use_openssl_ca_store',
2321cb0ef41Sopenharmony_ci    default=None,
2331cb0ef41Sopenharmony_ci    help='Use OpenSSL supplied CA store instead of compiled-in Mozilla CA copy.')
2341cb0ef41Sopenharmony_ci
2351cb0ef41Sopenharmony_ciparser.add_argument('--openssl-system-ca-path',
2361cb0ef41Sopenharmony_ci    action='store',
2371cb0ef41Sopenharmony_ci    dest='openssl_system_ca_path',
2381cb0ef41Sopenharmony_ci    help='Use the specified path to system CA (PEM format) in addition to '
2391cb0ef41Sopenharmony_ci         'the OpenSSL supplied CA store or compiled-in Mozilla CA copy.')
2401cb0ef41Sopenharmony_ci
2411cb0ef41Sopenharmony_ciparser.add_argument('--experimental-http-parser',
2421cb0ef41Sopenharmony_ci    action='store_true',
2431cb0ef41Sopenharmony_ci    dest='experimental_http_parser',
2441cb0ef41Sopenharmony_ci    default=None,
2451cb0ef41Sopenharmony_ci    help='(no-op)')
2461cb0ef41Sopenharmony_ci
2471cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-http-parser',
2481cb0ef41Sopenharmony_ci    action='store_true',
2491cb0ef41Sopenharmony_ci    dest='shared_http_parser',
2501cb0ef41Sopenharmony_ci    default=None,
2511cb0ef41Sopenharmony_ci    help='link to a shared http_parser DLL instead of static linking')
2521cb0ef41Sopenharmony_ci
2531cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-http-parser-includes',
2541cb0ef41Sopenharmony_ci    action='store',
2551cb0ef41Sopenharmony_ci    dest='shared_http_parser_includes',
2561cb0ef41Sopenharmony_ci    help='directory containing http_parser header files')
2571cb0ef41Sopenharmony_ci
2581cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-http-parser-libname',
2591cb0ef41Sopenharmony_ci    action='store',
2601cb0ef41Sopenharmony_ci    dest='shared_http_parser_libname',
2611cb0ef41Sopenharmony_ci    default='http_parser',
2621cb0ef41Sopenharmony_ci    help='alternative lib name to link to [default: %(default)s]')
2631cb0ef41Sopenharmony_ci
2641cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-http-parser-libpath',
2651cb0ef41Sopenharmony_ci    action='store',
2661cb0ef41Sopenharmony_ci    dest='shared_http_parser_libpath',
2671cb0ef41Sopenharmony_ci    help='a directory to search for the shared http_parser DLL')
2681cb0ef41Sopenharmony_ci
2691cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-libuv',
2701cb0ef41Sopenharmony_ci    action='store_true',
2711cb0ef41Sopenharmony_ci    dest='shared_libuv',
2721cb0ef41Sopenharmony_ci    default=None,
2731cb0ef41Sopenharmony_ci    help='link to a shared libuv DLL instead of static linking')
2741cb0ef41Sopenharmony_ci
2751cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-libuv-includes',
2761cb0ef41Sopenharmony_ci    action='store',
2771cb0ef41Sopenharmony_ci    dest='shared_libuv_includes',
2781cb0ef41Sopenharmony_ci    help='directory containing libuv header files')
2791cb0ef41Sopenharmony_ci
2801cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-libuv-libname',
2811cb0ef41Sopenharmony_ci    action='store',
2821cb0ef41Sopenharmony_ci    dest='shared_libuv_libname',
2831cb0ef41Sopenharmony_ci    default='uv',
2841cb0ef41Sopenharmony_ci    help='alternative lib name to link to [default: %(default)s]')
2851cb0ef41Sopenharmony_ci
2861cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-libuv-libpath',
2871cb0ef41Sopenharmony_ci    action='store',
2881cb0ef41Sopenharmony_ci    dest='shared_libuv_libpath',
2891cb0ef41Sopenharmony_ci    help='a directory to search for the shared libuv DLL')
2901cb0ef41Sopenharmony_ci
2911cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-nghttp2',
2921cb0ef41Sopenharmony_ci    action='store_true',
2931cb0ef41Sopenharmony_ci    dest='shared_nghttp2',
2941cb0ef41Sopenharmony_ci    default=None,
2951cb0ef41Sopenharmony_ci    help='link to a shared nghttp2 DLL instead of static linking')
2961cb0ef41Sopenharmony_ci
2971cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-nghttp2-includes',
2981cb0ef41Sopenharmony_ci    action='store',
2991cb0ef41Sopenharmony_ci    dest='shared_nghttp2_includes',
3001cb0ef41Sopenharmony_ci    help='directory containing nghttp2 header files')
3011cb0ef41Sopenharmony_ci
3021cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-nghttp2-libname',
3031cb0ef41Sopenharmony_ci    action='store',
3041cb0ef41Sopenharmony_ci    dest='shared_nghttp2_libname',
3051cb0ef41Sopenharmony_ci    default='nghttp2',
3061cb0ef41Sopenharmony_ci    help='alternative lib name to link to [default: %(default)s]')
3071cb0ef41Sopenharmony_ci
3081cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-nghttp2-libpath',
3091cb0ef41Sopenharmony_ci    action='store',
3101cb0ef41Sopenharmony_ci    dest='shared_nghttp2_libpath',
3111cb0ef41Sopenharmony_ci    help='a directory to search for the shared nghttp2 DLLs')
3121cb0ef41Sopenharmony_ci
3131cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-nghttp3',
3141cb0ef41Sopenharmony_ci    action='store_true',
3151cb0ef41Sopenharmony_ci    dest='shared_nghttp3',
3161cb0ef41Sopenharmony_ci    default=None,
3171cb0ef41Sopenharmony_ci    help='link to a shared nghttp3 DLL instead of static linking')
3181cb0ef41Sopenharmony_ci
3191cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-nghttp3-includes',
3201cb0ef41Sopenharmony_ci    action='store',
3211cb0ef41Sopenharmony_ci    dest='shared_nghttp3_includes',
3221cb0ef41Sopenharmony_ci    help='directory containing nghttp3 header files')
3231cb0ef41Sopenharmony_ci
3241cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-nghttp3-libname',
3251cb0ef41Sopenharmony_ci    action='store',
3261cb0ef41Sopenharmony_ci    dest='shared_nghttp3_libname',
3271cb0ef41Sopenharmony_ci    default='nghttp3',
3281cb0ef41Sopenharmony_ci    help='alternative lib name to link to [default: %(default)s]')
3291cb0ef41Sopenharmony_ci
3301cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-nghttp3-libpath',
3311cb0ef41Sopenharmony_ci    action='store',
3321cb0ef41Sopenharmony_ci    dest='shared_nghttp3_libpath',
3331cb0ef41Sopenharmony_ci    help='a directory to search for the shared nghttp3 DLLs')
3341cb0ef41Sopenharmony_ci
3351cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-ngtcp2',
3361cb0ef41Sopenharmony_ci    action='store_true',
3371cb0ef41Sopenharmony_ci    dest='shared_ngtcp2',
3381cb0ef41Sopenharmony_ci    default=None,
3391cb0ef41Sopenharmony_ci    help='link to a shared ngtcp2 DLL instead of static linking')
3401cb0ef41Sopenharmony_ci
3411cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-ngtcp2-includes',
3421cb0ef41Sopenharmony_ci    action='store',
3431cb0ef41Sopenharmony_ci    dest='shared_ngtcp2_includes',
3441cb0ef41Sopenharmony_ci    help='directory containing ngtcp2 header files')
3451cb0ef41Sopenharmony_ci
3461cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-ngtcp2-libname',
3471cb0ef41Sopenharmony_ci    action='store',
3481cb0ef41Sopenharmony_ci    dest='shared_ngtcp2_libname',
3491cb0ef41Sopenharmony_ci    default='ngtcp2',
3501cb0ef41Sopenharmony_ci    help='alternative lib name to link to [default: %(default)s]')
3511cb0ef41Sopenharmony_ci
3521cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-ngtcp2-libpath',
3531cb0ef41Sopenharmony_ci    action='store',
3541cb0ef41Sopenharmony_ci    dest='shared_ngtcp2_libpath',
3551cb0ef41Sopenharmony_ci    help='a directory to search for the shared tcp2 DLLs')
3561cb0ef41Sopenharmony_ci
3571cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-openssl',
3581cb0ef41Sopenharmony_ci    action='store_true',
3591cb0ef41Sopenharmony_ci    dest='shared_openssl',
3601cb0ef41Sopenharmony_ci    default=None,
3611cb0ef41Sopenharmony_ci    help='link to a shared OpenSSl DLL instead of static linking')
3621cb0ef41Sopenharmony_ci
3631cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-openssl-includes',
3641cb0ef41Sopenharmony_ci    action='store',
3651cb0ef41Sopenharmony_ci    dest='shared_openssl_includes',
3661cb0ef41Sopenharmony_ci    help='directory containing OpenSSL header files')
3671cb0ef41Sopenharmony_ci
3681cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-openssl-libname',
3691cb0ef41Sopenharmony_ci    action='store',
3701cb0ef41Sopenharmony_ci    dest='shared_openssl_libname',
3711cb0ef41Sopenharmony_ci    default='crypto,ssl',
3721cb0ef41Sopenharmony_ci    help='alternative lib name to link to [default: %(default)s]')
3731cb0ef41Sopenharmony_ci
3741cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-openssl-libpath',
3751cb0ef41Sopenharmony_ci    action='store',
3761cb0ef41Sopenharmony_ci    dest='shared_openssl_libpath',
3771cb0ef41Sopenharmony_ci    help='a directory to search for the shared OpenSSL DLLs')
3781cb0ef41Sopenharmony_ci
3791cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-zlib',
3801cb0ef41Sopenharmony_ci    action='store_true',
3811cb0ef41Sopenharmony_ci    dest='shared_zlib',
3821cb0ef41Sopenharmony_ci    default=None,
3831cb0ef41Sopenharmony_ci    help='link to a shared zlib DLL instead of static linking')
3841cb0ef41Sopenharmony_ci
3851cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-zlib-includes',
3861cb0ef41Sopenharmony_ci    action='store',
3871cb0ef41Sopenharmony_ci    dest='shared_zlib_includes',
3881cb0ef41Sopenharmony_ci    help='directory containing zlib header files')
3891cb0ef41Sopenharmony_ci
3901cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-zlib-libname',
3911cb0ef41Sopenharmony_ci    action='store',
3921cb0ef41Sopenharmony_ci    dest='shared_zlib_libname',
3931cb0ef41Sopenharmony_ci    default='z',
3941cb0ef41Sopenharmony_ci    help='alternative lib name to link to [default: %(default)s]')
3951cb0ef41Sopenharmony_ci
3961cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-zlib-libpath',
3971cb0ef41Sopenharmony_ci    action='store',
3981cb0ef41Sopenharmony_ci    dest='shared_zlib_libpath',
3991cb0ef41Sopenharmony_ci    help='a directory to search for the shared zlib DLL')
4001cb0ef41Sopenharmony_ci
4011cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-brotli',
4021cb0ef41Sopenharmony_ci    action='store_true',
4031cb0ef41Sopenharmony_ci    dest='shared_brotli',
4041cb0ef41Sopenharmony_ci    default=None,
4051cb0ef41Sopenharmony_ci    help='link to a shared brotli DLL instead of static linking')
4061cb0ef41Sopenharmony_ci
4071cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-brotli-includes',
4081cb0ef41Sopenharmony_ci    action='store',
4091cb0ef41Sopenharmony_ci    dest='shared_brotli_includes',
4101cb0ef41Sopenharmony_ci    help='directory containing brotli header files')
4111cb0ef41Sopenharmony_ci
4121cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-brotli-libname',
4131cb0ef41Sopenharmony_ci    action='store',
4141cb0ef41Sopenharmony_ci    dest='shared_brotli_libname',
4151cb0ef41Sopenharmony_ci    default='brotlidec,brotlienc',
4161cb0ef41Sopenharmony_ci    help='alternative lib name to link to [default: %(default)s]')
4171cb0ef41Sopenharmony_ci
4181cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-brotli-libpath',
4191cb0ef41Sopenharmony_ci    action='store',
4201cb0ef41Sopenharmony_ci    dest='shared_brotli_libpath',
4211cb0ef41Sopenharmony_ci    help='a directory to search for the shared brotli DLL')
4221cb0ef41Sopenharmony_ci
4231cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-cares',
4241cb0ef41Sopenharmony_ci    action='store_true',
4251cb0ef41Sopenharmony_ci    dest='shared_cares',
4261cb0ef41Sopenharmony_ci    default=None,
4271cb0ef41Sopenharmony_ci    help='link to a shared cares DLL instead of static linking')
4281cb0ef41Sopenharmony_ci
4291cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-cares-includes',
4301cb0ef41Sopenharmony_ci    action='store',
4311cb0ef41Sopenharmony_ci    dest='shared_cares_includes',
4321cb0ef41Sopenharmony_ci    help='directory containing cares header files')
4331cb0ef41Sopenharmony_ci
4341cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-cares-libname',
4351cb0ef41Sopenharmony_ci    action='store',
4361cb0ef41Sopenharmony_ci    dest='shared_cares_libname',
4371cb0ef41Sopenharmony_ci    default='cares',
4381cb0ef41Sopenharmony_ci    help='alternative lib name to link to [default: %(default)s]')
4391cb0ef41Sopenharmony_ci
4401cb0ef41Sopenharmony_cishared_optgroup.add_argument('--shared-cares-libpath',
4411cb0ef41Sopenharmony_ci    action='store',
4421cb0ef41Sopenharmony_ci    dest='shared_cares_libpath',
4431cb0ef41Sopenharmony_ci    help='a directory to search for the shared cares DLL')
4441cb0ef41Sopenharmony_ci
4451cb0ef41Sopenharmony_ciparser.add_argument_group(shared_optgroup)
4461cb0ef41Sopenharmony_ci
4471cb0ef41Sopenharmony_cifor builtin in shareable_builtins:
4481cb0ef41Sopenharmony_ci  builtin_id = 'shared_builtin_' + builtin + '_path'
4491cb0ef41Sopenharmony_ci  shared_builtin_optgroup.add_argument('--shared-builtin-' + builtin + '-path',
4501cb0ef41Sopenharmony_ci    action='store',
4511cb0ef41Sopenharmony_ci    dest='node_shared_builtin_' + builtin.replace('/', '_') + '_path',
4521cb0ef41Sopenharmony_ci    help='Path to shared file for ' + builtin + ' builtin. '
4531cb0ef41Sopenharmony_ci         'Will be used instead of bundled version at runtime')
4541cb0ef41Sopenharmony_ci
4551cb0ef41Sopenharmony_ciparser.add_argument_group(shared_builtin_optgroup)
4561cb0ef41Sopenharmony_ci
4571cb0ef41Sopenharmony_cistatic_optgroup.add_argument('--static-zoslib-gyp',
4581cb0ef41Sopenharmony_ci    action='store',
4591cb0ef41Sopenharmony_ci    dest='static_zoslib_gyp',
4601cb0ef41Sopenharmony_ci    help='path to zoslib.gyp file for includes and to link to static zoslib library')
4611cb0ef41Sopenharmony_ci
4621cb0ef41Sopenharmony_ciparser.add_argument_group(static_optgroup)
4631cb0ef41Sopenharmony_ci
4641cb0ef41Sopenharmony_ciparser.add_argument('--systemtap-includes',
4651cb0ef41Sopenharmony_ci    action='store',
4661cb0ef41Sopenharmony_ci    dest='systemtap_includes',
4671cb0ef41Sopenharmony_ci    help='directory containing systemtap header files')
4681cb0ef41Sopenharmony_ci
4691cb0ef41Sopenharmony_ciparser.add_argument('--tag',
4701cb0ef41Sopenharmony_ci    action='store',
4711cb0ef41Sopenharmony_ci    dest='tag',
4721cb0ef41Sopenharmony_ci    help='custom build tag')
4731cb0ef41Sopenharmony_ci
4741cb0ef41Sopenharmony_ciparser.add_argument('--release-urlbase',
4751cb0ef41Sopenharmony_ci    action='store',
4761cb0ef41Sopenharmony_ci    dest='release_urlbase',
4771cb0ef41Sopenharmony_ci    help='Provide a custom URL prefix for the `process.release` properties '
4781cb0ef41Sopenharmony_ci         '`sourceUrl` and `headersUrl`. When compiling a release build, this '
4791cb0ef41Sopenharmony_ci         'will default to https://nodejs.org/download/release/')
4801cb0ef41Sopenharmony_ci
4811cb0ef41Sopenharmony_ciparser.add_argument('--enable-d8',
4821cb0ef41Sopenharmony_ci    action='store_true',
4831cb0ef41Sopenharmony_ci    dest='enable_d8',
4841cb0ef41Sopenharmony_ci    default=None,
4851cb0ef41Sopenharmony_ci    help=argparse.SUPPRESS)  # Unsupported, undocumented.
4861cb0ef41Sopenharmony_ci
4871cb0ef41Sopenharmony_ciparser.add_argument('--enable-trace-maps',
4881cb0ef41Sopenharmony_ci    action='store_true',
4891cb0ef41Sopenharmony_ci    dest='trace_maps',
4901cb0ef41Sopenharmony_ci    default=None,
4911cb0ef41Sopenharmony_ci    help='Enable the --trace-maps flag in V8 (use at your own risk)')
4921cb0ef41Sopenharmony_ci
4931cb0ef41Sopenharmony_ciparser.add_argument('--experimental-enable-pointer-compression',
4941cb0ef41Sopenharmony_ci    action='store_true',
4951cb0ef41Sopenharmony_ci    dest='enable_pointer_compression',
4961cb0ef41Sopenharmony_ci    default=None,
4971cb0ef41Sopenharmony_ci    help='[Experimental] Enable V8 pointer compression (limits max heap to 4GB and breaks ABI compatibility)')
4981cb0ef41Sopenharmony_ci
4991cb0ef41Sopenharmony_ciparser.add_argument('--disable-shared-readonly-heap',
5001cb0ef41Sopenharmony_ci    action='store_true',
5011cb0ef41Sopenharmony_ci    dest='disable_shared_ro_heap',
5021cb0ef41Sopenharmony_ci    default=None,
5031cb0ef41Sopenharmony_ci    help='Disable the shared read-only heap feature in V8')
5041cb0ef41Sopenharmony_ci
5051cb0ef41Sopenharmony_ciparser.add_argument('--v8-options',
5061cb0ef41Sopenharmony_ci    action='store',
5071cb0ef41Sopenharmony_ci    dest='v8_options',
5081cb0ef41Sopenharmony_ci    help='v8 options to pass, see `node --v8-options` for examples.')
5091cb0ef41Sopenharmony_ci
5101cb0ef41Sopenharmony_ciparser.add_argument('--with-ossfuzz',
5111cb0ef41Sopenharmony_ci    action='store_true',
5121cb0ef41Sopenharmony_ci    dest='ossfuzz',
5131cb0ef41Sopenharmony_ci    default=None,
5141cb0ef41Sopenharmony_ci    help='Enables building of fuzzers. This command should be run in an OSS-Fuzz Docker image.')
5151cb0ef41Sopenharmony_ci
5161cb0ef41Sopenharmony_ciparser.add_argument('--with-arm-float-abi',
5171cb0ef41Sopenharmony_ci    action='store',
5181cb0ef41Sopenharmony_ci    dest='arm_float_abi',
5191cb0ef41Sopenharmony_ci    choices=valid_arm_float_abi,
5201cb0ef41Sopenharmony_ci    help=f"specifies which floating-point ABI to use ({', '.join(valid_arm_float_abi)}).")
5211cb0ef41Sopenharmony_ci
5221cb0ef41Sopenharmony_ciparser.add_argument('--with-arm-fpu',
5231cb0ef41Sopenharmony_ci    action='store',
5241cb0ef41Sopenharmony_ci    dest='arm_fpu',
5251cb0ef41Sopenharmony_ci    choices=valid_arm_fpu,
5261cb0ef41Sopenharmony_ci    help=f"ARM FPU mode ({', '.join(valid_arm_fpu)}) [default: %(default)s]")
5271cb0ef41Sopenharmony_ci
5281cb0ef41Sopenharmony_ciparser.add_argument('--with-mips-arch-variant',
5291cb0ef41Sopenharmony_ci    action='store',
5301cb0ef41Sopenharmony_ci    dest='mips_arch_variant',
5311cb0ef41Sopenharmony_ci    default='r2',
5321cb0ef41Sopenharmony_ci    choices=valid_mips_arch,
5331cb0ef41Sopenharmony_ci    help=f"MIPS arch variant ({', '.join(valid_mips_arch)}) [default: %(default)s]")
5341cb0ef41Sopenharmony_ci
5351cb0ef41Sopenharmony_ciparser.add_argument('--with-mips-fpu-mode',
5361cb0ef41Sopenharmony_ci    action='store',
5371cb0ef41Sopenharmony_ci    dest='mips_fpu_mode',
5381cb0ef41Sopenharmony_ci    default='fp32',
5391cb0ef41Sopenharmony_ci    choices=valid_mips_fpu,
5401cb0ef41Sopenharmony_ci    help=f"MIPS FPU mode ({', '.join(valid_mips_fpu)}) [default: %(default)s]")
5411cb0ef41Sopenharmony_ci
5421cb0ef41Sopenharmony_ciparser.add_argument('--with-mips-float-abi',
5431cb0ef41Sopenharmony_ci    action='store',
5441cb0ef41Sopenharmony_ci    dest='mips_float_abi',
5451cb0ef41Sopenharmony_ci    default='hard',
5461cb0ef41Sopenharmony_ci    choices=valid_mips_float_abi,
5471cb0ef41Sopenharmony_ci    help=f"MIPS floating-point ABI ({', '.join(valid_mips_float_abi)}) [default: %(default)s]")
5481cb0ef41Sopenharmony_ci
5491cb0ef41Sopenharmony_ciparser.add_argument('--with-dtrace',
5501cb0ef41Sopenharmony_ci    action='store_true',
5511cb0ef41Sopenharmony_ci    dest='with_dtrace',
5521cb0ef41Sopenharmony_ci    default=None,
5531cb0ef41Sopenharmony_ci    help='build with DTrace (default is true on sunos and darwin)')
5541cb0ef41Sopenharmony_ci
5551cb0ef41Sopenharmony_ciparser.add_argument('--with-etw',
5561cb0ef41Sopenharmony_ci    action='store_true',
5571cb0ef41Sopenharmony_ci    dest='with_etw',
5581cb0ef41Sopenharmony_ci    default=None,
5591cb0ef41Sopenharmony_ci    help='build with ETW (default is true on Windows)')
5601cb0ef41Sopenharmony_ci
5611cb0ef41Sopenharmony_ciparser.add_argument('--use-largepages',
5621cb0ef41Sopenharmony_ci    action='store_true',
5631cb0ef41Sopenharmony_ci    dest='node_use_large_pages',
5641cb0ef41Sopenharmony_ci    default=None,
5651cb0ef41Sopenharmony_ci    help='This option has no effect. --use-largepages is now a runtime option.')
5661cb0ef41Sopenharmony_ci
5671cb0ef41Sopenharmony_ciparser.add_argument('--use-largepages-script-lld',
5681cb0ef41Sopenharmony_ci    action='store_true',
5691cb0ef41Sopenharmony_ci    dest='node_use_large_pages_script_lld',
5701cb0ef41Sopenharmony_ci    default=None,
5711cb0ef41Sopenharmony_ci    help='This option has no effect. --use-largepages is now a runtime option.')
5721cb0ef41Sopenharmony_ci
5731cb0ef41Sopenharmony_ciparser.add_argument('--use-section-ordering-file',
5741cb0ef41Sopenharmony_ci    action='store',
5751cb0ef41Sopenharmony_ci    dest='node_section_ordering_info',
5761cb0ef41Sopenharmony_ci    default='',
5771cb0ef41Sopenharmony_ci    help='Pass a section ordering file to the linker. This requires that ' +
5781cb0ef41Sopenharmony_ci         'Node.js be linked using the gold linker. The gold linker must have ' +
5791cb0ef41Sopenharmony_ci         'version 1.2 or greater.')
5801cb0ef41Sopenharmony_ci
5811cb0ef41Sopenharmony_ciintl_optgroup.add_argument('--with-intl',
5821cb0ef41Sopenharmony_ci    action='store',
5831cb0ef41Sopenharmony_ci    dest='with_intl',
5841cb0ef41Sopenharmony_ci    default='full-icu',
5851cb0ef41Sopenharmony_ci    choices=valid_intl_modes,
5861cb0ef41Sopenharmony_ci    help=f"Intl mode (valid choices: {', '.join(valid_intl_modes)}) [default: %(default)s]")
5871cb0ef41Sopenharmony_ci
5881cb0ef41Sopenharmony_ciintl_optgroup.add_argument('--without-intl',
5891cb0ef41Sopenharmony_ci    action='store_const',
5901cb0ef41Sopenharmony_ci    dest='with_intl',
5911cb0ef41Sopenharmony_ci    const='none',
5921cb0ef41Sopenharmony_ci    help='Disable Intl, same as --with-intl=none')
5931cb0ef41Sopenharmony_ci
5941cb0ef41Sopenharmony_ciintl_optgroup.add_argument('--with-icu-path',
5951cb0ef41Sopenharmony_ci    action='store',
5961cb0ef41Sopenharmony_ci    dest='with_icu_path',
5971cb0ef41Sopenharmony_ci    help='Path to icu.gyp (ICU i18n, Chromium version only.)')
5981cb0ef41Sopenharmony_ci
5991cb0ef41Sopenharmony_ciicu_default_locales='root,en'
6001cb0ef41Sopenharmony_ci
6011cb0ef41Sopenharmony_ciintl_optgroup.add_argument('--with-icu-locales',
6021cb0ef41Sopenharmony_ci    action='store',
6031cb0ef41Sopenharmony_ci    dest='with_icu_locales',
6041cb0ef41Sopenharmony_ci    default=icu_default_locales,
6051cb0ef41Sopenharmony_ci    help='Comma-separated list of locales for "small-icu". "root" is assumed. '
6061cb0ef41Sopenharmony_ci        '[default: %(default)s]')
6071cb0ef41Sopenharmony_ci
6081cb0ef41Sopenharmony_ciintl_optgroup.add_argument('--with-icu-source',
6091cb0ef41Sopenharmony_ci    action='store',
6101cb0ef41Sopenharmony_ci    dest='with_icu_source',
6111cb0ef41Sopenharmony_ci    help='Intl mode: optional local path to icu/ dir, or path/URL of '
6121cb0ef41Sopenharmony_ci        'the icu4c source archive. '
6131cb0ef41Sopenharmony_ci        f"v{icu_versions['minimum_icu']}.x or later recommended.")
6141cb0ef41Sopenharmony_ci
6151cb0ef41Sopenharmony_ciintl_optgroup.add_argument('--with-icu-default-data-dir',
6161cb0ef41Sopenharmony_ci    action='store',
6171cb0ef41Sopenharmony_ci    dest='with_icu_default_data_dir',
6181cb0ef41Sopenharmony_ci    help='Path to the icuXXdt{lb}.dat file. If unspecified, ICU data will '
6191cb0ef41Sopenharmony_ci         'only be read if the NODE_ICU_DATA environment variable or the '
6201cb0ef41Sopenharmony_ci         '--icu-data-dir runtime argument is used. This option has effect '
6211cb0ef41Sopenharmony_ci         'only when Node.js is built with --with-intl=small-icu.')
6221cb0ef41Sopenharmony_ci
6231cb0ef41Sopenharmony_ciparser.add_argument('--with-ltcg',
6241cb0ef41Sopenharmony_ci    action='store_true',
6251cb0ef41Sopenharmony_ci    dest='with_ltcg',
6261cb0ef41Sopenharmony_ci    default=None,
6271cb0ef41Sopenharmony_ci    help='Use Link Time Code Generation. This feature is only available on Windows.')
6281cb0ef41Sopenharmony_ci
6291cb0ef41Sopenharmony_ciparser.add_argument('--without-node-snapshot',
6301cb0ef41Sopenharmony_ci    action='store_true',
6311cb0ef41Sopenharmony_ci    dest='without_node_snapshot',
6321cb0ef41Sopenharmony_ci    default=None,
6331cb0ef41Sopenharmony_ci    help='Turn off V8 snapshot integration. Currently experimental.')
6341cb0ef41Sopenharmony_ci
6351cb0ef41Sopenharmony_ciparser.add_argument('--without-node-code-cache',
6361cb0ef41Sopenharmony_ci    action='store_true',
6371cb0ef41Sopenharmony_ci    dest='without_node_code_cache',
6381cb0ef41Sopenharmony_ci    default=None,
6391cb0ef41Sopenharmony_ci    help='Turn off V8 Code cache integration.')
6401cb0ef41Sopenharmony_ci
6411cb0ef41Sopenharmony_ciintl_optgroup.add_argument('--download',
6421cb0ef41Sopenharmony_ci    action='store',
6431cb0ef41Sopenharmony_ci    dest='download_list',
6441cb0ef41Sopenharmony_ci    help=nodedownload.help())
6451cb0ef41Sopenharmony_ci
6461cb0ef41Sopenharmony_ciintl_optgroup.add_argument('--download-path',
6471cb0ef41Sopenharmony_ci    action='store',
6481cb0ef41Sopenharmony_ci    dest='download_path',
6491cb0ef41Sopenharmony_ci    default='deps',
6501cb0ef41Sopenharmony_ci    help='Download directory [default: %(default)s]')
6511cb0ef41Sopenharmony_ci
6521cb0ef41Sopenharmony_ciparser.add_argument_group(intl_optgroup)
6531cb0ef41Sopenharmony_ci
6541cb0ef41Sopenharmony_ciparser.add_argument('--debug-lib',
6551cb0ef41Sopenharmony_ci    action='store_true',
6561cb0ef41Sopenharmony_ci    dest='node_debug_lib',
6571cb0ef41Sopenharmony_ci    default=None,
6581cb0ef41Sopenharmony_ci    help='build lib with DCHECK macros')
6591cb0ef41Sopenharmony_ci
6601cb0ef41Sopenharmony_cihttp2_optgroup.add_argument('--debug-nghttp2',
6611cb0ef41Sopenharmony_ci    action='store_true',
6621cb0ef41Sopenharmony_ci    dest='debug_nghttp2',
6631cb0ef41Sopenharmony_ci    default=None,
6641cb0ef41Sopenharmony_ci    help='build nghttp2 with DEBUGBUILD (default is false)')
6651cb0ef41Sopenharmony_ci
6661cb0ef41Sopenharmony_ciparser.add_argument_group(http2_optgroup)
6671cb0ef41Sopenharmony_ci
6681cb0ef41Sopenharmony_ciparser.add_argument('--without-dtrace',
6691cb0ef41Sopenharmony_ci    action='store_true',
6701cb0ef41Sopenharmony_ci    dest='without_dtrace',
6711cb0ef41Sopenharmony_ci    default=None,
6721cb0ef41Sopenharmony_ci    help='build without DTrace')
6731cb0ef41Sopenharmony_ci
6741cb0ef41Sopenharmony_ciparser.add_argument('--without-etw',
6751cb0ef41Sopenharmony_ci    action='store_true',
6761cb0ef41Sopenharmony_ci    dest='without_etw',
6771cb0ef41Sopenharmony_ci    default=None,
6781cb0ef41Sopenharmony_ci    help='build without ETW')
6791cb0ef41Sopenharmony_ci
6801cb0ef41Sopenharmony_ciparser.add_argument('--without-npm',
6811cb0ef41Sopenharmony_ci    action='store_true',
6821cb0ef41Sopenharmony_ci    dest='without_npm',
6831cb0ef41Sopenharmony_ci    default=None,
6841cb0ef41Sopenharmony_ci    help='do not install the bundled npm (package manager)')
6851cb0ef41Sopenharmony_ci
6861cb0ef41Sopenharmony_ciparser.add_argument('--without-corepack',
6871cb0ef41Sopenharmony_ci    action='store_true',
6881cb0ef41Sopenharmony_ci    dest='without_corepack',
6891cb0ef41Sopenharmony_ci    default=None,
6901cb0ef41Sopenharmony_ci    help='do not install the bundled Corepack')
6911cb0ef41Sopenharmony_ci
6921cb0ef41Sopenharmony_ci# Dummy option for backwards compatibility
6931cb0ef41Sopenharmony_ciparser.add_argument('--without-report',
6941cb0ef41Sopenharmony_ci    action='store_true',
6951cb0ef41Sopenharmony_ci    dest='unused_without_report',
6961cb0ef41Sopenharmony_ci    default=None,
6971cb0ef41Sopenharmony_ci    help=argparse.SUPPRESS)
6981cb0ef41Sopenharmony_ci
6991cb0ef41Sopenharmony_ciparser.add_argument('--with-snapshot',
7001cb0ef41Sopenharmony_ci    action='store_true',
7011cb0ef41Sopenharmony_ci    dest='unused_with_snapshot',
7021cb0ef41Sopenharmony_ci    default=None,
7031cb0ef41Sopenharmony_ci    help=argparse.SUPPRESS)
7041cb0ef41Sopenharmony_ci
7051cb0ef41Sopenharmony_ciparser.add_argument('--without-snapshot',
7061cb0ef41Sopenharmony_ci    action='store_true',
7071cb0ef41Sopenharmony_ci    dest='unused_without_snapshot',
7081cb0ef41Sopenharmony_ci    default=None,
7091cb0ef41Sopenharmony_ci    help=argparse.SUPPRESS)
7101cb0ef41Sopenharmony_ci
7111cb0ef41Sopenharmony_ciparser.add_argument('--without-siphash',
7121cb0ef41Sopenharmony_ci    action='store_true',
7131cb0ef41Sopenharmony_ci    dest='without_siphash',
7141cb0ef41Sopenharmony_ci    default=None,
7151cb0ef41Sopenharmony_ci    help=argparse.SUPPRESS)
7161cb0ef41Sopenharmony_ci
7171cb0ef41Sopenharmony_ci# End dummy list.
7181cb0ef41Sopenharmony_ci
7191cb0ef41Sopenharmony_ciparser.add_argument('--without-ssl',
7201cb0ef41Sopenharmony_ci    action='store_true',
7211cb0ef41Sopenharmony_ci    dest='without_ssl',
7221cb0ef41Sopenharmony_ci    default=None,
7231cb0ef41Sopenharmony_ci    help='build without SSL (disables crypto, https, inspector, etc.)')
7241cb0ef41Sopenharmony_ci
7251cb0ef41Sopenharmony_ciparser.add_argument('--without-node-options',
7261cb0ef41Sopenharmony_ci    action='store_true',
7271cb0ef41Sopenharmony_ci    dest='without_node_options',
7281cb0ef41Sopenharmony_ci    default=None,
7291cb0ef41Sopenharmony_ci    help='build without NODE_OPTIONS support')
7301cb0ef41Sopenharmony_ci
7311cb0ef41Sopenharmony_ciparser.add_argument('--ninja',
7321cb0ef41Sopenharmony_ci    action='store_true',
7331cb0ef41Sopenharmony_ci    dest='use_ninja',
7341cb0ef41Sopenharmony_ci    default=None,
7351cb0ef41Sopenharmony_ci    help='generate build files for use with Ninja')
7361cb0ef41Sopenharmony_ci
7371cb0ef41Sopenharmony_ciparser.add_argument('--enable-asan',
7381cb0ef41Sopenharmony_ci    action='store_true',
7391cb0ef41Sopenharmony_ci    dest='enable_asan',
7401cb0ef41Sopenharmony_ci    default=None,
7411cb0ef41Sopenharmony_ci    help='compile for Address Sanitizer to find memory bugs')
7421cb0ef41Sopenharmony_ci
7431cb0ef41Sopenharmony_ciparser.add_argument('--enable-static',
7441cb0ef41Sopenharmony_ci    action='store_true',
7451cb0ef41Sopenharmony_ci    dest='enable_static',
7461cb0ef41Sopenharmony_ci    default=None,
7471cb0ef41Sopenharmony_ci    help='build as static library')
7481cb0ef41Sopenharmony_ci
7491cb0ef41Sopenharmony_ciparser.add_argument('--no-browser-globals',
7501cb0ef41Sopenharmony_ci    action='store_true',
7511cb0ef41Sopenharmony_ci    dest='no_browser_globals',
7521cb0ef41Sopenharmony_ci    default=None,
7531cb0ef41Sopenharmony_ci    help='do not export browser globals like setTimeout, console, etc. ' +
7541cb0ef41Sopenharmony_ci         '(This mode is deprecated and not officially supported for regular ' +
7551cb0ef41Sopenharmony_ci         'applications)')
7561cb0ef41Sopenharmony_ci
7571cb0ef41Sopenharmony_ciparser.add_argument('--without-inspector',
7581cb0ef41Sopenharmony_ci    action='store_true',
7591cb0ef41Sopenharmony_ci    dest='without_inspector',
7601cb0ef41Sopenharmony_ci    default=None,
7611cb0ef41Sopenharmony_ci    help='disable the V8 inspector protocol')
7621cb0ef41Sopenharmony_ci
7631cb0ef41Sopenharmony_ciparser.add_argument('--shared',
7641cb0ef41Sopenharmony_ci    action='store_true',
7651cb0ef41Sopenharmony_ci    dest='shared',
7661cb0ef41Sopenharmony_ci    default=None,
7671cb0ef41Sopenharmony_ci    help='compile shared library for embedding node in another project. ' +
7681cb0ef41Sopenharmony_ci         '(This mode is not officially supported for regular applications)')
7691cb0ef41Sopenharmony_ci
7701cb0ef41Sopenharmony_ciparser.add_argument('--libdir',
7711cb0ef41Sopenharmony_ci    action='store',
7721cb0ef41Sopenharmony_ci    dest='libdir',
7731cb0ef41Sopenharmony_ci    default='lib',
7741cb0ef41Sopenharmony_ci    help='a directory to install the shared library into relative to the '
7751cb0ef41Sopenharmony_ci         'prefix. This is a no-op if --shared is not specified. ' +
7761cb0ef41Sopenharmony_ci         '(This mode is not officially supported for regular applications)')
7771cb0ef41Sopenharmony_ci
7781cb0ef41Sopenharmony_ciparser.add_argument('--without-v8-platform',
7791cb0ef41Sopenharmony_ci    action='store_true',
7801cb0ef41Sopenharmony_ci    dest='without_v8_platform',
7811cb0ef41Sopenharmony_ci    default=False,
7821cb0ef41Sopenharmony_ci    help='do not initialize v8 platform during node.js startup. ' +
7831cb0ef41Sopenharmony_ci         '(This mode is not officially supported for regular applications)')
7841cb0ef41Sopenharmony_ci
7851cb0ef41Sopenharmony_ciparser.add_argument('--without-bundled-v8',
7861cb0ef41Sopenharmony_ci    action='store_true',
7871cb0ef41Sopenharmony_ci    dest='without_bundled_v8',
7881cb0ef41Sopenharmony_ci    default=False,
7891cb0ef41Sopenharmony_ci    help='do not use V8 includes from the bundled deps folder. ' +
7901cb0ef41Sopenharmony_ci         '(This mode is not officially supported for regular applications)')
7911cb0ef41Sopenharmony_ci
7921cb0ef41Sopenharmony_ciparser.add_argument('--verbose',
7931cb0ef41Sopenharmony_ci    action='store_true',
7941cb0ef41Sopenharmony_ci    dest='verbose',
7951cb0ef41Sopenharmony_ci    default=False,
7961cb0ef41Sopenharmony_ci    help='get more output from this script')
7971cb0ef41Sopenharmony_ci
7981cb0ef41Sopenharmony_ciparser.add_argument('--v8-non-optimized-debug',
7991cb0ef41Sopenharmony_ci    action='store_true',
8001cb0ef41Sopenharmony_ci    dest='v8_non_optimized_debug',
8011cb0ef41Sopenharmony_ci    default=False,
8021cb0ef41Sopenharmony_ci    help='compile V8 with minimal optimizations and with runtime checks')
8031cb0ef41Sopenharmony_ci
8041cb0ef41Sopenharmony_ciparser.add_argument('--v8-with-dchecks',
8051cb0ef41Sopenharmony_ci    action='store_true',
8061cb0ef41Sopenharmony_ci    dest='v8_with_dchecks',
8071cb0ef41Sopenharmony_ci    default=False,
8081cb0ef41Sopenharmony_ci    help='compile V8 with debug checks and runtime debugging features enabled')
8091cb0ef41Sopenharmony_ci
8101cb0ef41Sopenharmony_ciparser.add_argument('--v8-lite-mode',
8111cb0ef41Sopenharmony_ci    action='store_true',
8121cb0ef41Sopenharmony_ci    dest='v8_lite_mode',
8131cb0ef41Sopenharmony_ci    default=False,
8141cb0ef41Sopenharmony_ci    help='compile V8 in lite mode for constrained environments (lowers V8 '+
8151cb0ef41Sopenharmony_ci         'memory footprint, but also implies no just-in-time compilation ' +
8161cb0ef41Sopenharmony_ci         'support, thus much slower execution)')
8171cb0ef41Sopenharmony_ci
8181cb0ef41Sopenharmony_ciparser.add_argument('--v8-enable-object-print',
8191cb0ef41Sopenharmony_ci    action='store_true',
8201cb0ef41Sopenharmony_ci    dest='v8_enable_object_print',
8211cb0ef41Sopenharmony_ci    default=True,
8221cb0ef41Sopenharmony_ci    help='compile V8 with auxiliary functions for native debuggers')
8231cb0ef41Sopenharmony_ci
8241cb0ef41Sopenharmony_ciparser.add_argument('--v8-disable-object-print',
8251cb0ef41Sopenharmony_ci    action='store_true',
8261cb0ef41Sopenharmony_ci    dest='v8_disable_object_print',
8271cb0ef41Sopenharmony_ci    default=False,
8281cb0ef41Sopenharmony_ci    help='disable the V8 auxiliary functions for native debuggers')
8291cb0ef41Sopenharmony_ci
8301cb0ef41Sopenharmony_ciparser.add_argument('--v8-enable-hugepage',
8311cb0ef41Sopenharmony_ci    action='store_true',
8321cb0ef41Sopenharmony_ci    dest='v8_enable_hugepage',
8331cb0ef41Sopenharmony_ci    default=None,
8341cb0ef41Sopenharmony_ci    help='Enable V8 transparent hugepage support. This feature is only '+
8351cb0ef41Sopenharmony_ci         'available on Linux platform.')
8361cb0ef41Sopenharmony_ci
8371cb0ef41Sopenharmony_ciparser.add_argument('--v8-enable-short-builtin-calls',
8381cb0ef41Sopenharmony_ci    action='store_true',
8391cb0ef41Sopenharmony_ci    dest='v8_enable_short_builtin_calls',
8401cb0ef41Sopenharmony_ci    default=None,
8411cb0ef41Sopenharmony_ci    help='Enable V8 short builtin calls support. This feature is enabled '+
8421cb0ef41Sopenharmony_ci         'on x86_64 platform by default.')
8431cb0ef41Sopenharmony_ci
8441cb0ef41Sopenharmony_ciparser.add_argument('--v8-enable-snapshot-compression',
8451cb0ef41Sopenharmony_ci    action='store_true',
8461cb0ef41Sopenharmony_ci    dest='v8_enable_snapshot_compression',
8471cb0ef41Sopenharmony_ci    default=None,
8481cb0ef41Sopenharmony_ci    help='Enable the built-in snapshot compression in V8.')
8491cb0ef41Sopenharmony_ci
8501cb0ef41Sopenharmony_ciparser.add_argument('--node-builtin-modules-path',
8511cb0ef41Sopenharmony_ci    action='store',
8521cb0ef41Sopenharmony_ci    dest='node_builtin_modules_path',
8531cb0ef41Sopenharmony_ci    default=False,
8541cb0ef41Sopenharmony_ci    help='node will load builtin modules from disk instead of from binary')
8551cb0ef41Sopenharmony_ci
8561cb0ef41Sopenharmony_ciparser.add_argument('--node-snapshot-main',
8571cb0ef41Sopenharmony_ci    action='store',
8581cb0ef41Sopenharmony_ci    dest='node_snapshot_main',
8591cb0ef41Sopenharmony_ci    default=None,
8601cb0ef41Sopenharmony_ci    help='Run a file when building the embedded snapshot. Currently ' +
8611cb0ef41Sopenharmony_ci         'experimental.')
8621cb0ef41Sopenharmony_ci
8631cb0ef41Sopenharmony_ci# Create compile_commands.json in out/Debug and out/Release.
8641cb0ef41Sopenharmony_ciparser.add_argument('-C',
8651cb0ef41Sopenharmony_ci    action='store_true',
8661cb0ef41Sopenharmony_ci    dest='compile_commands_json',
8671cb0ef41Sopenharmony_ci    default=None,
8681cb0ef41Sopenharmony_ci    help=argparse.SUPPRESS)
8691cb0ef41Sopenharmony_ci
8701cb0ef41Sopenharmony_ci(options, args) = parser.parse_known_args()
8711cb0ef41Sopenharmony_ci
8721cb0ef41Sopenharmony_ci# Expand ~ in the install prefix now, it gets written to multiple files.
8731cb0ef41Sopenharmony_cioptions.prefix = str(Path(options.prefix or '').expanduser())
8741cb0ef41Sopenharmony_ci
8751cb0ef41Sopenharmony_ci# set up auto-download list
8761cb0ef41Sopenharmony_ciauto_downloads = nodedownload.parse(options.download_list)
8771cb0ef41Sopenharmony_ci
8781cb0ef41Sopenharmony_ci
8791cb0ef41Sopenharmony_cidef error(msg):
8801cb0ef41Sopenharmony_ci  prefix = '\033[1m\033[31mERROR\033[0m' if os.isatty(1) else 'ERROR'
8811cb0ef41Sopenharmony_ci  print(f'{prefix}: {msg}')
8821cb0ef41Sopenharmony_ci  sys.exit(1)
8831cb0ef41Sopenharmony_ci
8841cb0ef41Sopenharmony_cidef warn(msg):
8851cb0ef41Sopenharmony_ci  warn.warned = True
8861cb0ef41Sopenharmony_ci  prefix = '\033[1m\033[93mWARNING\033[0m' if os.isatty(1) else 'WARNING'
8871cb0ef41Sopenharmony_ci  print(f'{prefix}: {msg}')
8881cb0ef41Sopenharmony_ci
8891cb0ef41Sopenharmony_ci# track if warnings occurred
8901cb0ef41Sopenharmony_ciwarn.warned = False
8911cb0ef41Sopenharmony_ci
8921cb0ef41Sopenharmony_cidef info(msg):
8931cb0ef41Sopenharmony_ci  prefix = '\033[1m\033[32mINFO\033[0m' if os.isatty(1) else 'INFO'
8941cb0ef41Sopenharmony_ci  print(f'{prefix}: {msg}')
8951cb0ef41Sopenharmony_ci
8961cb0ef41Sopenharmony_cidef print_verbose(x):
8971cb0ef41Sopenharmony_ci  if not options.verbose:
8981cb0ef41Sopenharmony_ci    return
8991cb0ef41Sopenharmony_ci  if isinstance(x, str):
9001cb0ef41Sopenharmony_ci    print(x)
9011cb0ef41Sopenharmony_ci  else:
9021cb0ef41Sopenharmony_ci    pprint.pprint(x, indent=2)
9031cb0ef41Sopenharmony_ci
9041cb0ef41Sopenharmony_cidef b(value):
9051cb0ef41Sopenharmony_ci  """Returns the string 'true' if value is truthy, 'false' otherwise."""
9061cb0ef41Sopenharmony_ci  return 'true' if value else 'false'
9071cb0ef41Sopenharmony_ci
9081cb0ef41Sopenharmony_cidef B(value):
9091cb0ef41Sopenharmony_ci  """Returns 1 if value is truthy, 0 otherwise."""
9101cb0ef41Sopenharmony_ci  return 1 if value else 0
9111cb0ef41Sopenharmony_ci
9121cb0ef41Sopenharmony_cidef to_utf8(s):
9131cb0ef41Sopenharmony_ci  return s if isinstance(s, str) else s.decode("utf-8")
9141cb0ef41Sopenharmony_ci
9151cb0ef41Sopenharmony_cidef pkg_config(pkg):
9161cb0ef41Sopenharmony_ci  """Run pkg-config on the specified package
9171cb0ef41Sopenharmony_ci  Returns ("-l flags", "-I flags", "-L flags", "version")
9181cb0ef41Sopenharmony_ci  otherwise (None, None, None, None)"""
9191cb0ef41Sopenharmony_ci  pkg_config = os.environ.get('PKG_CONFIG', 'pkg-config')
9201cb0ef41Sopenharmony_ci  args = []  # Print pkg-config warnings on first round.
9211cb0ef41Sopenharmony_ci  retval = []
9221cb0ef41Sopenharmony_ci  for flag in ['--libs-only-l', '--cflags-only-I',
9231cb0ef41Sopenharmony_ci               '--libs-only-L', '--modversion']:
9241cb0ef41Sopenharmony_ci    args += [flag]
9251cb0ef41Sopenharmony_ci    if isinstance(pkg, list):
9261cb0ef41Sopenharmony_ci      args += pkg
9271cb0ef41Sopenharmony_ci    else:
9281cb0ef41Sopenharmony_ci      args += [pkg]
9291cb0ef41Sopenharmony_ci    try:
9301cb0ef41Sopenharmony_ci      proc = subprocess.Popen(shlex.split(pkg_config) + args,
9311cb0ef41Sopenharmony_ci                              stdout=subprocess.PIPE)
9321cb0ef41Sopenharmony_ci      with proc:
9331cb0ef41Sopenharmony_ci        val = to_utf8(proc.communicate()[0]).strip()
9341cb0ef41Sopenharmony_ci    except OSError as e:
9351cb0ef41Sopenharmony_ci      if e.errno != errno.ENOENT:
9361cb0ef41Sopenharmony_ci        raise e  # Unexpected error.
9371cb0ef41Sopenharmony_ci      return (None, None, None, None)  # No pkg-config/pkgconf installed.
9381cb0ef41Sopenharmony_ci    retval.append(val)
9391cb0ef41Sopenharmony_ci    args = ['--silence-errors']
9401cb0ef41Sopenharmony_ci  return tuple(retval)
9411cb0ef41Sopenharmony_ci
9421cb0ef41Sopenharmony_ci
9431cb0ef41Sopenharmony_cidef try_check_compiler(cc, lang):
9441cb0ef41Sopenharmony_ci  try:
9451cb0ef41Sopenharmony_ci    proc = subprocess.Popen(shlex.split(cc) + ['-E', '-P', '-x', lang, '-'],
9461cb0ef41Sopenharmony_ci                            stdin=subprocess.PIPE, stdout=subprocess.PIPE)
9471cb0ef41Sopenharmony_ci  except OSError:
9481cb0ef41Sopenharmony_ci    return (False, False, '', '')
9491cb0ef41Sopenharmony_ci
9501cb0ef41Sopenharmony_ci  with proc:
9511cb0ef41Sopenharmony_ci    proc.stdin.write(b'__clang__ __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ '
9521cb0ef41Sopenharmony_ci                     b'__clang_major__ __clang_minor__ __clang_patchlevel__')
9531cb0ef41Sopenharmony_ci
9541cb0ef41Sopenharmony_ci    if sys.platform == 'zos':
9551cb0ef41Sopenharmony_ci      values = (to_utf8(proc.communicate()[0]).split('\n')[-2].split() + ['0'] * 7)[0:7]
9561cb0ef41Sopenharmony_ci    else:
9571cb0ef41Sopenharmony_ci      values = (to_utf8(proc.communicate()[0]).split() + ['0'] * 7)[0:7]
9581cb0ef41Sopenharmony_ci
9591cb0ef41Sopenharmony_ci  is_clang = values[0] == '1'
9601cb0ef41Sopenharmony_ci  gcc_version = tuple(map(int, values[1:1+3]))
9611cb0ef41Sopenharmony_ci  clang_version = tuple(map(int, values[4:4+3])) if is_clang else None
9621cb0ef41Sopenharmony_ci
9631cb0ef41Sopenharmony_ci  return (True, is_clang, clang_version, gcc_version)
9641cb0ef41Sopenharmony_ci
9651cb0ef41Sopenharmony_ci
9661cb0ef41Sopenharmony_ci#
9671cb0ef41Sopenharmony_ci# The version of asm compiler is needed for building openssl asm files.
9681cb0ef41Sopenharmony_ci# See deps/openssl/openssl.gypi for detail.
9691cb0ef41Sopenharmony_ci# Commands and regular expressions to obtain its version number are taken from
9701cb0ef41Sopenharmony_ci# https://github.com/openssl/openssl/blob/OpenSSL_1_0_2-stable/crypto/sha/asm/sha512-x86_64.pl#L112-L129
9711cb0ef41Sopenharmony_ci#
9721cb0ef41Sopenharmony_cidef get_version_helper(cc, regexp):
9731cb0ef41Sopenharmony_ci  try:
9741cb0ef41Sopenharmony_ci    proc = subprocess.Popen(shlex.split(cc) + ['-v'], stdin=subprocess.PIPE,
9751cb0ef41Sopenharmony_ci                            stderr=subprocess.PIPE, stdout=subprocess.PIPE)
9761cb0ef41Sopenharmony_ci  except OSError:
9771cb0ef41Sopenharmony_ci    error('''No acceptable C compiler found!
9781cb0ef41Sopenharmony_ci
9791cb0ef41Sopenharmony_ci       Please make sure you have a C compiler installed on your system and/or
9801cb0ef41Sopenharmony_ci       consider adjusting the CC environment variable if you installed
9811cb0ef41Sopenharmony_ci       it in a non-standard prefix.''')
9821cb0ef41Sopenharmony_ci
9831cb0ef41Sopenharmony_ci  with proc:
9841cb0ef41Sopenharmony_ci    match = re.search(regexp, to_utf8(proc.communicate()[1]))
9851cb0ef41Sopenharmony_ci
9861cb0ef41Sopenharmony_ci  return match.group(2) if match else '0.0'
9871cb0ef41Sopenharmony_ci
9881cb0ef41Sopenharmony_cidef get_nasm_version(asm):
9891cb0ef41Sopenharmony_ci  try:
9901cb0ef41Sopenharmony_ci    proc = subprocess.Popen(shlex.split(asm) + ['-v'],
9911cb0ef41Sopenharmony_ci                            stdin=subprocess.PIPE, stderr=subprocess.PIPE,
9921cb0ef41Sopenharmony_ci                            stdout=subprocess.PIPE)
9931cb0ef41Sopenharmony_ci  except OSError:
9941cb0ef41Sopenharmony_ci    warn('''No acceptable ASM compiler found!
9951cb0ef41Sopenharmony_ci         Please make sure you have installed NASM from https://www.nasm.us
9961cb0ef41Sopenharmony_ci         and refer BUILDING.md.''')
9971cb0ef41Sopenharmony_ci    return '0.0'
9981cb0ef41Sopenharmony_ci
9991cb0ef41Sopenharmony_ci  with proc:
10001cb0ef41Sopenharmony_ci    match = re.match(r"NASM version ([2-9]\.[0-9][0-9]+)",
10011cb0ef41Sopenharmony_ci                     to_utf8(proc.communicate()[0]))
10021cb0ef41Sopenharmony_ci
10031cb0ef41Sopenharmony_ci  return match.group(1) if match else '0.0'
10041cb0ef41Sopenharmony_ci
10051cb0ef41Sopenharmony_cidef get_llvm_version(cc):
10061cb0ef41Sopenharmony_ci  return get_version_helper(
10071cb0ef41Sopenharmony_ci    cc, r"(^(?:.+ )?clang version|based on LLVM) ([0-9]+\.[0-9]+)")
10081cb0ef41Sopenharmony_ci
10091cb0ef41Sopenharmony_cidef get_xcode_version(cc):
10101cb0ef41Sopenharmony_ci  return get_version_helper(
10111cb0ef41Sopenharmony_ci    cc, r"(^Apple (?:clang|LLVM) version) ([0-9]+\.[0-9]+)")
10121cb0ef41Sopenharmony_ci
10131cb0ef41Sopenharmony_cidef get_gas_version(cc):
10141cb0ef41Sopenharmony_ci  try:
10151cb0ef41Sopenharmony_ci    custom_env = os.environ.copy()
10161cb0ef41Sopenharmony_ci    custom_env["LC_ALL"] = "C"
10171cb0ef41Sopenharmony_ci    proc = subprocess.Popen(shlex.split(cc) + ['-Wa,-v', '-c', '-o',
10181cb0ef41Sopenharmony_ci                                               '/dev/null', '-x',
10191cb0ef41Sopenharmony_ci                                               'assembler',  '/dev/null'],
10201cb0ef41Sopenharmony_ci                            stdin=subprocess.PIPE, stderr=subprocess.PIPE,
10211cb0ef41Sopenharmony_ci                            stdout=subprocess.PIPE, env=custom_env)
10221cb0ef41Sopenharmony_ci  except OSError:
10231cb0ef41Sopenharmony_ci    error('''No acceptable C compiler found!
10241cb0ef41Sopenharmony_ci
10251cb0ef41Sopenharmony_ci       Please make sure you have a C compiler installed on your system and/or
10261cb0ef41Sopenharmony_ci       consider adjusting the CC environment variable if you installed
10271cb0ef41Sopenharmony_ci       it in a non-standard prefix.''')
10281cb0ef41Sopenharmony_ci
10291cb0ef41Sopenharmony_ci  with proc:
10301cb0ef41Sopenharmony_ci    gas_ret = to_utf8(proc.communicate()[1])
10311cb0ef41Sopenharmony_ci
10321cb0ef41Sopenharmony_ci  match = re.match(r"GNU assembler version ([2-9]\.[0-9]+)", gas_ret)
10331cb0ef41Sopenharmony_ci
10341cb0ef41Sopenharmony_ci  if match:
10351cb0ef41Sopenharmony_ci    return match.group(1)
10361cb0ef41Sopenharmony_ci
10371cb0ef41Sopenharmony_ci  warn(f'Could not recognize `gas`: {gas_ret}')
10381cb0ef41Sopenharmony_ci  return '0.0'
10391cb0ef41Sopenharmony_ci
10401cb0ef41Sopenharmony_ci# Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1.  It passes
10411cb0ef41Sopenharmony_ci# the version check more by accident than anything else but a more rigorous
10421cb0ef41Sopenharmony_ci# check involves checking the build number against an allowlist.  I'm not
10431cb0ef41Sopenharmony_ci# quite prepared to go that far yet.
10441cb0ef41Sopenharmony_cidef check_compiler(o):
10451cb0ef41Sopenharmony_ci  if sys.platform == 'win32':
10461cb0ef41Sopenharmony_ci    o['variables']['llvm_version'] = '0.0'
10471cb0ef41Sopenharmony_ci    if not options.openssl_no_asm and options.dest_cpu in ('x86', 'x64'):
10481cb0ef41Sopenharmony_ci      nasm_version = get_nasm_version('nasm')
10491cb0ef41Sopenharmony_ci      o['variables']['nasm_version'] = nasm_version
10501cb0ef41Sopenharmony_ci      if nasm_version == '0.0':
10511cb0ef41Sopenharmony_ci        o['variables']['openssl_no_asm'] = 1
10521cb0ef41Sopenharmony_ci    return
10531cb0ef41Sopenharmony_ci
10541cb0ef41Sopenharmony_ci  ok, is_clang, clang_version, gcc_version = try_check_compiler(CXX, 'c++')
10551cb0ef41Sopenharmony_ci  version_str = ".".join(map(str, clang_version if is_clang else gcc_version))
10561cb0ef41Sopenharmony_ci  print_verbose(f"Detected {'clang ' if is_clang else ''}C++ compiler (CXX={CXX}) version: {version_str}")
10571cb0ef41Sopenharmony_ci  if not ok:
10581cb0ef41Sopenharmony_ci    warn(f'failed to autodetect C++ compiler version (CXX={CXX})')
10591cb0ef41Sopenharmony_ci  elif clang_version < (8, 0, 0) if is_clang else gcc_version < (8, 3, 0):
10601cb0ef41Sopenharmony_ci    warn(f'C++ compiler (CXX={CXX}, {version_str}) too old, need g++ 8.3.0 or clang++ 8.0.0')
10611cb0ef41Sopenharmony_ci
10621cb0ef41Sopenharmony_ci  ok, is_clang, clang_version, gcc_version = try_check_compiler(CC, 'c')
10631cb0ef41Sopenharmony_ci  version_str = ".".join(map(str, clang_version if is_clang else gcc_version))
10641cb0ef41Sopenharmony_ci  print_verbose(f"Detected {'clang ' if is_clang else ''}C compiler (CC={CC}) version: {version_str}")
10651cb0ef41Sopenharmony_ci  if not ok:
10661cb0ef41Sopenharmony_ci    warn(f'failed to autodetect C compiler version (CC={CC})')
10671cb0ef41Sopenharmony_ci  elif not is_clang and gcc_version < (4, 2, 0):
10681cb0ef41Sopenharmony_ci    # clang 3.2 is a little white lie because any clang version will probably
10691cb0ef41Sopenharmony_ci    # do for the C bits.  However, we might as well encourage people to upgrade
10701cb0ef41Sopenharmony_ci    # to a version that is not completely ancient.
10711cb0ef41Sopenharmony_ci    warn(f'C compiler (CC={CC}, {version_str}) too old, need gcc 4.2 or clang 3.2')
10721cb0ef41Sopenharmony_ci
10731cb0ef41Sopenharmony_ci  o['variables']['llvm_version'] = get_llvm_version(CC) if is_clang else '0.0'
10741cb0ef41Sopenharmony_ci
10751cb0ef41Sopenharmony_ci  # Need xcode_version or gas_version when openssl asm files are compiled.
10761cb0ef41Sopenharmony_ci  if options.without_ssl or options.openssl_no_asm or options.shared_openssl:
10771cb0ef41Sopenharmony_ci    return
10781cb0ef41Sopenharmony_ci
10791cb0ef41Sopenharmony_ci  if is_clang:
10801cb0ef41Sopenharmony_ci    if sys.platform == 'darwin':
10811cb0ef41Sopenharmony_ci      o['variables']['xcode_version'] = get_xcode_version(CC)
10821cb0ef41Sopenharmony_ci  else:
10831cb0ef41Sopenharmony_ci    o['variables']['gas_version'] = get_gas_version(CC)
10841cb0ef41Sopenharmony_ci
10851cb0ef41Sopenharmony_ci
10861cb0ef41Sopenharmony_cidef cc_macros(cc=None):
10871cb0ef41Sopenharmony_ci  """Checks predefined macros using the C compiler command."""
10881cb0ef41Sopenharmony_ci
10891cb0ef41Sopenharmony_ci  try:
10901cb0ef41Sopenharmony_ci    p = subprocess.Popen(shlex.split(cc or CC) + ['-dM', '-E', '-'],
10911cb0ef41Sopenharmony_ci                         stdin=subprocess.PIPE,
10921cb0ef41Sopenharmony_ci                         stdout=subprocess.PIPE,
10931cb0ef41Sopenharmony_ci                         stderr=subprocess.PIPE)
10941cb0ef41Sopenharmony_ci  except OSError:
10951cb0ef41Sopenharmony_ci    error('''No acceptable C compiler found!
10961cb0ef41Sopenharmony_ci
10971cb0ef41Sopenharmony_ci       Please make sure you have a C compiler installed on your system and/or
10981cb0ef41Sopenharmony_ci       consider adjusting the CC environment variable if you installed
10991cb0ef41Sopenharmony_ci       it in a non-standard prefix.''')
11001cb0ef41Sopenharmony_ci
11011cb0ef41Sopenharmony_ci  with p:
11021cb0ef41Sopenharmony_ci    p.stdin.write(b'\n')
11031cb0ef41Sopenharmony_ci    out = to_utf8(p.communicate()[0]).split('\n')
11041cb0ef41Sopenharmony_ci
11051cb0ef41Sopenharmony_ci  k = {}
11061cb0ef41Sopenharmony_ci  for line in out:
11071cb0ef41Sopenharmony_ci    lst = shlex.split(line)
11081cb0ef41Sopenharmony_ci    if len(lst) > 2:
11091cb0ef41Sopenharmony_ci      key = lst[1]
11101cb0ef41Sopenharmony_ci      val = lst[2]
11111cb0ef41Sopenharmony_ci      k[key] = val
11121cb0ef41Sopenharmony_ci  return k
11131cb0ef41Sopenharmony_ci
11141cb0ef41Sopenharmony_ci
11151cb0ef41Sopenharmony_cidef is_arch_armv7():
11161cb0ef41Sopenharmony_ci  """Check for ARMv7 instructions"""
11171cb0ef41Sopenharmony_ci  cc_macros_cache = cc_macros()
11181cb0ef41Sopenharmony_ci  return cc_macros_cache.get('__ARM_ARCH') == '7'
11191cb0ef41Sopenharmony_ci
11201cb0ef41Sopenharmony_ci
11211cb0ef41Sopenharmony_cidef is_arch_armv6():
11221cb0ef41Sopenharmony_ci  """Check for ARMv6 instructions"""
11231cb0ef41Sopenharmony_ci  cc_macros_cache = cc_macros()
11241cb0ef41Sopenharmony_ci  return cc_macros_cache.get('__ARM_ARCH') == '6'
11251cb0ef41Sopenharmony_ci
11261cb0ef41Sopenharmony_ci
11271cb0ef41Sopenharmony_cidef is_arm_hard_float_abi():
11281cb0ef41Sopenharmony_ci  """Check for hardfloat or softfloat eabi on ARM"""
11291cb0ef41Sopenharmony_ci  # GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
11301cb0ef41Sopenharmony_ci  # the Floating Point ABI used (PCS stands for Procedure Call Standard).
11311cb0ef41Sopenharmony_ci  # We use these as well as a couple of other defines to statically determine
11321cb0ef41Sopenharmony_ci  # what FP ABI used.
11331cb0ef41Sopenharmony_ci
11341cb0ef41Sopenharmony_ci  return '__ARM_PCS_VFP' in cc_macros()
11351cb0ef41Sopenharmony_ci
11361cb0ef41Sopenharmony_ci
11371cb0ef41Sopenharmony_cidef host_arch_cc():
11381cb0ef41Sopenharmony_ci  """Host architecture check using the CC command."""
11391cb0ef41Sopenharmony_ci
11401cb0ef41Sopenharmony_ci  if sys.platform.startswith('zos'):
11411cb0ef41Sopenharmony_ci    return 's390x'
11421cb0ef41Sopenharmony_ci  k = cc_macros(os.environ.get('CC_host'))
11431cb0ef41Sopenharmony_ci
11441cb0ef41Sopenharmony_ci  matchup = {
11451cb0ef41Sopenharmony_ci    '__aarch64__' : 'arm64',
11461cb0ef41Sopenharmony_ci    '__arm__'     : 'arm',
11471cb0ef41Sopenharmony_ci    '__i386__'    : 'ia32',
11481cb0ef41Sopenharmony_ci    '__MIPSEL__'  : 'mipsel',
11491cb0ef41Sopenharmony_ci    '__mips__'    : 'mips',
11501cb0ef41Sopenharmony_ci    '__PPC64__'   : 'ppc64',
11511cb0ef41Sopenharmony_ci    '__PPC__'     : 'ppc64',
11521cb0ef41Sopenharmony_ci    '__x86_64__'  : 'x64',
11531cb0ef41Sopenharmony_ci    '__s390x__'   : 's390x',
11541cb0ef41Sopenharmony_ci    '__riscv'     : 'riscv',
11551cb0ef41Sopenharmony_ci    '__loongarch64': 'loong64',
11561cb0ef41Sopenharmony_ci  }
11571cb0ef41Sopenharmony_ci
11581cb0ef41Sopenharmony_ci  rtn = 'ia32' # default
11591cb0ef41Sopenharmony_ci
11601cb0ef41Sopenharmony_ci  for key, value in matchup.items():
11611cb0ef41Sopenharmony_ci    if k.get(key, 0) and k[key] != '0':
11621cb0ef41Sopenharmony_ci      rtn = value
11631cb0ef41Sopenharmony_ci      break
11641cb0ef41Sopenharmony_ci
11651cb0ef41Sopenharmony_ci  if rtn == 'mipsel' and '_LP64' in k:
11661cb0ef41Sopenharmony_ci    rtn = 'mips64el'
11671cb0ef41Sopenharmony_ci
11681cb0ef41Sopenharmony_ci  if rtn == 'riscv':
11691cb0ef41Sopenharmony_ci    if k['__riscv_xlen'] == '64':
11701cb0ef41Sopenharmony_ci      rtn = 'riscv64'
11711cb0ef41Sopenharmony_ci    else:
11721cb0ef41Sopenharmony_ci      rtn = 'riscv32'
11731cb0ef41Sopenharmony_ci
11741cb0ef41Sopenharmony_ci  return rtn
11751cb0ef41Sopenharmony_ci
11761cb0ef41Sopenharmony_ci
11771cb0ef41Sopenharmony_cidef host_arch_win():
11781cb0ef41Sopenharmony_ci  """Host architecture check using environ vars (better way to do this?)"""
11791cb0ef41Sopenharmony_ci
11801cb0ef41Sopenharmony_ci  observed_arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
11811cb0ef41Sopenharmony_ci  arch = os.environ.get('PROCESSOR_ARCHITEW6432', observed_arch)
11821cb0ef41Sopenharmony_ci
11831cb0ef41Sopenharmony_ci  matchup = {
11841cb0ef41Sopenharmony_ci    'AMD64'  : 'x64',
11851cb0ef41Sopenharmony_ci    'x86'    : 'ia32',
11861cb0ef41Sopenharmony_ci    'arm'    : 'arm',
11871cb0ef41Sopenharmony_ci    'mips'   : 'mips',
11881cb0ef41Sopenharmony_ci    'ARM64'  : 'arm64'
11891cb0ef41Sopenharmony_ci  }
11901cb0ef41Sopenharmony_ci
11911cb0ef41Sopenharmony_ci  return matchup.get(arch, 'ia32')
11921cb0ef41Sopenharmony_ci
11931cb0ef41Sopenharmony_ci
11941cb0ef41Sopenharmony_cidef configure_arm(o):
11951cb0ef41Sopenharmony_ci  if options.arm_float_abi:
11961cb0ef41Sopenharmony_ci    arm_float_abi = options.arm_float_abi
11971cb0ef41Sopenharmony_ci  elif is_arm_hard_float_abi():
11981cb0ef41Sopenharmony_ci    arm_float_abi = 'hard'
11991cb0ef41Sopenharmony_ci  else:
12001cb0ef41Sopenharmony_ci    arm_float_abi = 'default'
12011cb0ef41Sopenharmony_ci
12021cb0ef41Sopenharmony_ci  arm_fpu = 'vfp'
12031cb0ef41Sopenharmony_ci
12041cb0ef41Sopenharmony_ci  if is_arch_armv7():
12051cb0ef41Sopenharmony_ci    arm_fpu = 'vfpv3'
12061cb0ef41Sopenharmony_ci    o['variables']['arm_version'] = '7'
12071cb0ef41Sopenharmony_ci  else:
12081cb0ef41Sopenharmony_ci    o['variables']['arm_version'] = '6' if is_arch_armv6() else 'default'
12091cb0ef41Sopenharmony_ci
12101cb0ef41Sopenharmony_ci  o['variables']['arm_thumb'] = 0      # -marm
12111cb0ef41Sopenharmony_ci  o['variables']['arm_float_abi'] = arm_float_abi
12121cb0ef41Sopenharmony_ci
12131cb0ef41Sopenharmony_ci  if options.dest_os == 'android':
12141cb0ef41Sopenharmony_ci    arm_fpu = 'vfpv3'
12151cb0ef41Sopenharmony_ci    o['variables']['arm_version'] = '7'
12161cb0ef41Sopenharmony_ci
12171cb0ef41Sopenharmony_ci  o['variables']['arm_fpu'] = options.arm_fpu or arm_fpu
12181cb0ef41Sopenharmony_ci
12191cb0ef41Sopenharmony_ci
12201cb0ef41Sopenharmony_cidef configure_mips(o, target_arch):
12211cb0ef41Sopenharmony_ci  can_use_fpu_instructions = options.mips_float_abi != 'soft'
12221cb0ef41Sopenharmony_ci  o['variables']['v8_can_use_fpu_instructions'] = b(can_use_fpu_instructions)
12231cb0ef41Sopenharmony_ci  o['variables']['v8_use_mips_abi_hardfloat'] = b(can_use_fpu_instructions)
12241cb0ef41Sopenharmony_ci  o['variables']['mips_arch_variant'] = options.mips_arch_variant
12251cb0ef41Sopenharmony_ci  o['variables']['mips_fpu_mode'] = options.mips_fpu_mode
12261cb0ef41Sopenharmony_ci  host_byteorder = 'little' if target_arch in ('mipsel', 'mips64el') else 'big'
12271cb0ef41Sopenharmony_ci  o['variables']['v8_host_byteorder'] = host_byteorder
12281cb0ef41Sopenharmony_ci
12291cb0ef41Sopenharmony_cidef configure_zos(o):
12301cb0ef41Sopenharmony_ci  o['variables']['node_static_zoslib'] = b(True)
12311cb0ef41Sopenharmony_ci  if options.static_zoslib_gyp:
12321cb0ef41Sopenharmony_ci    # Apply to all Node.js components for now
12331cb0ef41Sopenharmony_ci    o['variables']['zoslib_include_dir'] = Path(options.static_zoslib_gyp).parent + '/include'
12341cb0ef41Sopenharmony_ci    o['include_dirs'] += [o['variables']['zoslib_include_dir']]
12351cb0ef41Sopenharmony_ci  else:
12361cb0ef41Sopenharmony_ci    raise Exception('--static-zoslib-gyp=<path to zoslib.gyp file> is required.')
12371cb0ef41Sopenharmony_ci
12381cb0ef41Sopenharmony_cidef clang_version_ge(version_checked):
12391cb0ef41Sopenharmony_ci  for compiler in [(CC, 'c'), (CXX, 'c++')]:
12401cb0ef41Sopenharmony_ci    _, is_clang, clang_version, _1 = (
12411cb0ef41Sopenharmony_ci      try_check_compiler(compiler[0], compiler[1])
12421cb0ef41Sopenharmony_ci    )
12431cb0ef41Sopenharmony_ci    if is_clang and clang_version >= version_checked:
12441cb0ef41Sopenharmony_ci      return True
12451cb0ef41Sopenharmony_ci  return False
12461cb0ef41Sopenharmony_ci
12471cb0ef41Sopenharmony_cidef gcc_version_ge(version_checked):
12481cb0ef41Sopenharmony_ci  for compiler in [(CC, 'c'), (CXX, 'c++')]:
12491cb0ef41Sopenharmony_ci    _, is_clang, _1, gcc_version = (
12501cb0ef41Sopenharmony_ci      try_check_compiler(compiler[0], compiler[1])
12511cb0ef41Sopenharmony_ci    )
12521cb0ef41Sopenharmony_ci    if is_clang or gcc_version < version_checked:
12531cb0ef41Sopenharmony_ci      return False
12541cb0ef41Sopenharmony_ci  return True
12551cb0ef41Sopenharmony_ci
12561cb0ef41Sopenharmony_cidef configure_node_lib_files(o):
12571cb0ef41Sopenharmony_ci  o['variables']['node_library_files'] = SearchFiles('lib', 'js')
12581cb0ef41Sopenharmony_ci
12591cb0ef41Sopenharmony_cidef configure_node(o):
12601cb0ef41Sopenharmony_ci  if options.dest_os == 'android':
12611cb0ef41Sopenharmony_ci    o['variables']['OS'] = 'android'
12621cb0ef41Sopenharmony_ci  o['variables']['node_prefix'] = options.prefix
12631cb0ef41Sopenharmony_ci  o['variables']['node_install_npm'] = b(not options.without_npm)
12641cb0ef41Sopenharmony_ci  o['variables']['node_install_corepack'] = b(not options.without_corepack)
12651cb0ef41Sopenharmony_ci  o['variables']['debug_node'] = b(options.debug_node)
12661cb0ef41Sopenharmony_ci  o['default_configuration'] = 'Debug' if options.debug else 'Release'
12671cb0ef41Sopenharmony_ci  o['variables']['error_on_warn'] = b(options.error_on_warn)
12681cb0ef41Sopenharmony_ci
12691cb0ef41Sopenharmony_ci  host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
12701cb0ef41Sopenharmony_ci  target_arch = options.dest_cpu or host_arch
12711cb0ef41Sopenharmony_ci  # ia32 is preferred by the build tools (GYP) over x86 even if we prefer the latter
12721cb0ef41Sopenharmony_ci  # the Makefile resets this to x86 afterward
12731cb0ef41Sopenharmony_ci  if target_arch == 'x86':
12741cb0ef41Sopenharmony_ci    target_arch = 'ia32'
12751cb0ef41Sopenharmony_ci  # x86_64 is common across linuxes, allow it as an alias for x64
12761cb0ef41Sopenharmony_ci  if target_arch == 'x86_64':
12771cb0ef41Sopenharmony_ci    target_arch = 'x64'
12781cb0ef41Sopenharmony_ci  o['variables']['host_arch'] = host_arch
12791cb0ef41Sopenharmony_ci  o['variables']['target_arch'] = target_arch
12801cb0ef41Sopenharmony_ci  o['variables']['node_byteorder'] = sys.byteorder
12811cb0ef41Sopenharmony_ci
12821cb0ef41Sopenharmony_ci  cross_compiling = (options.cross_compiling
12831cb0ef41Sopenharmony_ci                     if options.cross_compiling is not None
12841cb0ef41Sopenharmony_ci                     else target_arch != host_arch)
12851cb0ef41Sopenharmony_ci  if cross_compiling:
12861cb0ef41Sopenharmony_ci    os.environ['GYP_CROSSCOMPILE'] = "1"
12871cb0ef41Sopenharmony_ci  if options.unused_without_snapshot:
12881cb0ef41Sopenharmony_ci    warn('building --without-snapshot is no longer possible')
12891cb0ef41Sopenharmony_ci
12901cb0ef41Sopenharmony_ci  o['variables']['want_separate_host_toolset'] = int(cross_compiling)
12911cb0ef41Sopenharmony_ci
12921cb0ef41Sopenharmony_ci  # Enable branch protection for arm64
12931cb0ef41Sopenharmony_ci  if target_arch == 'arm64':
12941cb0ef41Sopenharmony_ci    o['cflags']+=['-msign-return-address=all']
12951cb0ef41Sopenharmony_ci    o['variables']['arm_fpu'] = options.arm_fpu or 'neon'
12961cb0ef41Sopenharmony_ci
12971cb0ef41Sopenharmony_ci  if options.node_snapshot_main is not None:
12981cb0ef41Sopenharmony_ci    if options.shared:
12991cb0ef41Sopenharmony_ci      # This should be possible to fix, but we will need to refactor the
13001cb0ef41Sopenharmony_ci      # libnode target to avoid building it twice.
13011cb0ef41Sopenharmony_ci      error('--node-snapshot-main is incompatible with --shared')
13021cb0ef41Sopenharmony_ci    if options.without_node_snapshot:
13031cb0ef41Sopenharmony_ci      error('--node-snapshot-main is incompatible with ' +
13041cb0ef41Sopenharmony_ci            '--without-node-snapshot')
13051cb0ef41Sopenharmony_ci    if cross_compiling:
13061cb0ef41Sopenharmony_ci      error('--node-snapshot-main is incompatible with cross compilation')
13071cb0ef41Sopenharmony_ci    o['variables']['node_snapshot_main'] = options.node_snapshot_main
13081cb0ef41Sopenharmony_ci
13091cb0ef41Sopenharmony_ci  if options.without_node_snapshot or options.node_builtin_modules_path:
13101cb0ef41Sopenharmony_ci    o['variables']['node_use_node_snapshot'] = 'false'
13111cb0ef41Sopenharmony_ci  else:
13121cb0ef41Sopenharmony_ci    o['variables']['node_use_node_snapshot'] = b(
13131cb0ef41Sopenharmony_ci      not cross_compiling and not options.shared)
13141cb0ef41Sopenharmony_ci
13151cb0ef41Sopenharmony_ci  if options.without_node_code_cache or options.without_node_snapshot or options.node_builtin_modules_path:
13161cb0ef41Sopenharmony_ci    o['variables']['node_use_node_code_cache'] = 'false'
13171cb0ef41Sopenharmony_ci  else:
13181cb0ef41Sopenharmony_ci    # TODO(refack): fix this when implementing embedded code-cache when cross-compiling.
13191cb0ef41Sopenharmony_ci    o['variables']['node_use_node_code_cache'] = b(
13201cb0ef41Sopenharmony_ci      not cross_compiling and not options.shared)
13211cb0ef41Sopenharmony_ci
13221cb0ef41Sopenharmony_ci  if target_arch == 'arm':
13231cb0ef41Sopenharmony_ci    configure_arm(o)
13241cb0ef41Sopenharmony_ci  elif target_arch in ('mips', 'mipsel', 'mips64el'):
13251cb0ef41Sopenharmony_ci    configure_mips(o, target_arch)
13261cb0ef41Sopenharmony_ci  elif sys.platform == 'zos':
13271cb0ef41Sopenharmony_ci    configure_zos(o)
13281cb0ef41Sopenharmony_ci
13291cb0ef41Sopenharmony_ci  if flavor in ('aix', 'os400'):
13301cb0ef41Sopenharmony_ci    o['variables']['node_target_type'] = 'static_library'
13311cb0ef41Sopenharmony_ci
13321cb0ef41Sopenharmony_ci  if target_arch in ('x86', 'x64', 'ia32', 'x32'):
13331cb0ef41Sopenharmony_ci    o['variables']['node_enable_v8_vtunejit'] = b(options.enable_vtune_profiling)
13341cb0ef41Sopenharmony_ci  elif options.enable_vtune_profiling:
13351cb0ef41Sopenharmony_ci    raise Exception(
13361cb0ef41Sopenharmony_ci       'The VTune profiler for JavaScript is only supported on x32, x86, and x64 '
13371cb0ef41Sopenharmony_ci       'architectures.')
13381cb0ef41Sopenharmony_ci  else:
13391cb0ef41Sopenharmony_ci    o['variables']['node_enable_v8_vtunejit'] = 'false'
13401cb0ef41Sopenharmony_ci
13411cb0ef41Sopenharmony_ci  if flavor != 'linux' and (options.enable_pgo_generate or options.enable_pgo_use):
13421cb0ef41Sopenharmony_ci    raise Exception(
13431cb0ef41Sopenharmony_ci      'The pgo option is supported only on linux.')
13441cb0ef41Sopenharmony_ci
13451cb0ef41Sopenharmony_ci  if flavor == 'linux':
13461cb0ef41Sopenharmony_ci    if options.enable_pgo_generate or options.enable_pgo_use:
13471cb0ef41Sopenharmony_ci      version_checked = (5, 4, 1)
13481cb0ef41Sopenharmony_ci      if not gcc_version_ge(version_checked):
13491cb0ef41Sopenharmony_ci        version_checked_str = ".".join(map(str, version_checked))
13501cb0ef41Sopenharmony_ci        raise Exception(
13511cb0ef41Sopenharmony_ci          'The options --enable-pgo-generate and --enable-pgo-use '
13521cb0ef41Sopenharmony_ci          f'are supported for gcc and gxx {version_checked_str} or newer only.')
13531cb0ef41Sopenharmony_ci
13541cb0ef41Sopenharmony_ci    if options.enable_pgo_generate and options.enable_pgo_use:
13551cb0ef41Sopenharmony_ci      raise Exception(
13561cb0ef41Sopenharmony_ci        'Only one of the --enable-pgo-generate or --enable-pgo-use options '
13571cb0ef41Sopenharmony_ci        'can be specified at a time. You would like to use '
13581cb0ef41Sopenharmony_ci        '--enable-pgo-generate first, profile node, and then recompile '
13591cb0ef41Sopenharmony_ci        'with --enable-pgo-use')
13601cb0ef41Sopenharmony_ci
13611cb0ef41Sopenharmony_ci  o['variables']['enable_pgo_generate'] = b(options.enable_pgo_generate)
13621cb0ef41Sopenharmony_ci  o['variables']['enable_pgo_use']      = b(options.enable_pgo_use)
13631cb0ef41Sopenharmony_ci
13641cb0ef41Sopenharmony_ci  if flavor == 'win' and (options.enable_lto):
13651cb0ef41Sopenharmony_ci    raise Exception(
13661cb0ef41Sopenharmony_ci      'Use Link Time Code Generation instead.')
13671cb0ef41Sopenharmony_ci
13681cb0ef41Sopenharmony_ci  if options.enable_lto:
13691cb0ef41Sopenharmony_ci    gcc_version_checked = (5, 4, 1)
13701cb0ef41Sopenharmony_ci    clang_version_checked = (3, 9, 1)
13711cb0ef41Sopenharmony_ci    if not gcc_version_ge(gcc_version_checked) and not clang_version_ge(clang_version_checked):
13721cb0ef41Sopenharmony_ci      gcc_version_checked_str = ".".join(map(str, gcc_version_checked))
13731cb0ef41Sopenharmony_ci      clang_version_checked_str = ".".join(map(str, clang_version_checked))
13741cb0ef41Sopenharmony_ci      raise Exception(
13751cb0ef41Sopenharmony_ci        f'The option --enable-lto is supported for gcc {gcc_version_checked_str}+'
13761cb0ef41Sopenharmony_ci        f'or clang {clang_version_checked_str}+ only.')
13771cb0ef41Sopenharmony_ci
13781cb0ef41Sopenharmony_ci  o['variables']['enable_lto'] = b(options.enable_lto)
13791cb0ef41Sopenharmony_ci
13801cb0ef41Sopenharmony_ci  if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
13811cb0ef41Sopenharmony_ci    use_dtrace = not options.without_dtrace
13821cb0ef41Sopenharmony_ci    # Don't enable by default on linux and freebsd
13831cb0ef41Sopenharmony_ci    if flavor in ('linux', 'freebsd'):
13841cb0ef41Sopenharmony_ci      use_dtrace = options.with_dtrace
13851cb0ef41Sopenharmony_ci
13861cb0ef41Sopenharmony_ci    if flavor == 'linux':
13871cb0ef41Sopenharmony_ci      if options.systemtap_includes:
13881cb0ef41Sopenharmony_ci        o['include_dirs'] += [options.systemtap_includes]
13891cb0ef41Sopenharmony_ci    o['variables']['node_use_dtrace'] = b(use_dtrace)
13901cb0ef41Sopenharmony_ci  elif options.with_dtrace:
13911cb0ef41Sopenharmony_ci    raise Exception(
13921cb0ef41Sopenharmony_ci       'DTrace is currently only supported on SunOS, MacOS or Linux systems.')
13931cb0ef41Sopenharmony_ci  else:
13941cb0ef41Sopenharmony_ci    o['variables']['node_use_dtrace'] = 'false'
13951cb0ef41Sopenharmony_ci
13961cb0ef41Sopenharmony_ci  if options.node_use_large_pages or options.node_use_large_pages_script_lld:
13971cb0ef41Sopenharmony_ci    warn('''The `--use-largepages` and `--use-largepages-script-lld` options
13981cb0ef41Sopenharmony_ci         have no effect during build time. Support for mapping to large pages is
13991cb0ef41Sopenharmony_ci         now a runtime option of Node.js. Run `node --use-largepages` or add
14001cb0ef41Sopenharmony_ci         `--use-largepages` to the `NODE_OPTIONS` environment variable once
14011cb0ef41Sopenharmony_ci         Node.js is built to enable mapping to large pages.''')
14021cb0ef41Sopenharmony_ci
14031cb0ef41Sopenharmony_ci  if options.no_ifaddrs:
14041cb0ef41Sopenharmony_ci    o['defines'] += ['SUNOS_NO_IFADDRS']
14051cb0ef41Sopenharmony_ci
14061cb0ef41Sopenharmony_ci  o['variables']['single_executable_application'] = b(not options.disable_single_executable_application)
14071cb0ef41Sopenharmony_ci  if options.disable_single_executable_application:
14081cb0ef41Sopenharmony_ci    o['defines'] += ['DISABLE_SINGLE_EXECUTABLE_APPLICATION']
14091cb0ef41Sopenharmony_ci
14101cb0ef41Sopenharmony_ci  # By default, enable ETW on Windows.
14111cb0ef41Sopenharmony_ci  if flavor == 'win':
14121cb0ef41Sopenharmony_ci    o['variables']['node_use_etw'] = b(not options.without_etw)
14131cb0ef41Sopenharmony_ci  elif options.with_etw:
14141cb0ef41Sopenharmony_ci    raise Exception('ETW is only supported on Windows.')
14151cb0ef41Sopenharmony_ci  else:
14161cb0ef41Sopenharmony_ci    o['variables']['node_use_etw'] = 'false'
14171cb0ef41Sopenharmony_ci
14181cb0ef41Sopenharmony_ci  o['variables']['node_with_ltcg'] = b(options.with_ltcg)
14191cb0ef41Sopenharmony_ci  if flavor != 'win' and options.with_ltcg:
14201cb0ef41Sopenharmony_ci    raise Exception('Link Time Code Generation is only supported on Windows.')
14211cb0ef41Sopenharmony_ci
14221cb0ef41Sopenharmony_ci  if options.tag:
14231cb0ef41Sopenharmony_ci    o['variables']['node_tag'] = '-' + options.tag
14241cb0ef41Sopenharmony_ci  else:
14251cb0ef41Sopenharmony_ci    o['variables']['node_tag'] = ''
14261cb0ef41Sopenharmony_ci
14271cb0ef41Sopenharmony_ci  o['variables']['node_release_urlbase'] = options.release_urlbase or ''
14281cb0ef41Sopenharmony_ci
14291cb0ef41Sopenharmony_ci  if options.v8_options:
14301cb0ef41Sopenharmony_ci    o['variables']['node_v8_options'] = options.v8_options.replace('"', '\\"')
14311cb0ef41Sopenharmony_ci
14321cb0ef41Sopenharmony_ci  if options.enable_static:
14331cb0ef41Sopenharmony_ci    o['variables']['node_target_type'] = 'static_library'
14341cb0ef41Sopenharmony_ci
14351cb0ef41Sopenharmony_ci  o['variables']['node_debug_lib'] = b(options.node_debug_lib)
14361cb0ef41Sopenharmony_ci
14371cb0ef41Sopenharmony_ci  if options.debug_nghttp2:
14381cb0ef41Sopenharmony_ci    o['variables']['debug_nghttp2'] = 1
14391cb0ef41Sopenharmony_ci  else:
14401cb0ef41Sopenharmony_ci    o['variables']['debug_nghttp2'] = 'false'
14411cb0ef41Sopenharmony_ci
14421cb0ef41Sopenharmony_ci  o['variables']['node_no_browser_globals'] = b(options.no_browser_globals)
14431cb0ef41Sopenharmony_ci
14441cb0ef41Sopenharmony_ci  o['variables']['node_shared'] = b(options.shared)
14451cb0ef41Sopenharmony_ci  o['variables']['libdir'] = options.libdir
14461cb0ef41Sopenharmony_ci  node_module_version = getmoduleversion.get_version()
14471cb0ef41Sopenharmony_ci
14481cb0ef41Sopenharmony_ci  if options.dest_os == 'android':
14491cb0ef41Sopenharmony_ci    shlib_suffix = 'so'
14501cb0ef41Sopenharmony_ci  elif sys.platform == 'darwin':
14511cb0ef41Sopenharmony_ci    shlib_suffix = '%s.dylib'
14521cb0ef41Sopenharmony_ci  elif sys.platform.startswith('aix'):
14531cb0ef41Sopenharmony_ci    shlib_suffix = '%s.a'
14541cb0ef41Sopenharmony_ci  elif sys.platform == 'os400':
14551cb0ef41Sopenharmony_ci    shlib_suffix = '%s.a'
14561cb0ef41Sopenharmony_ci  elif sys.platform.startswith('zos'):
14571cb0ef41Sopenharmony_ci    shlib_suffix = '%s.x'
14581cb0ef41Sopenharmony_ci  else:
14591cb0ef41Sopenharmony_ci    shlib_suffix = 'so'
14601cb0ef41Sopenharmony_ci  if '%s' in shlib_suffix:
14611cb0ef41Sopenharmony_ci    shlib_suffix %= node_module_version
14621cb0ef41Sopenharmony_ci
14631cb0ef41Sopenharmony_ci  o['variables']['node_module_version'] = int(node_module_version)
14641cb0ef41Sopenharmony_ci  o['variables']['shlib_suffix'] = shlib_suffix
14651cb0ef41Sopenharmony_ci
14661cb0ef41Sopenharmony_ci  if options.linked_module:
14671cb0ef41Sopenharmony_ci    o['variables']['linked_module_files'] = options.linked_module
14681cb0ef41Sopenharmony_ci
14691cb0ef41Sopenharmony_ci  o['variables']['asan'] = int(options.enable_asan or 0)
14701cb0ef41Sopenharmony_ci
14711cb0ef41Sopenharmony_ci  if options.coverage:
14721cb0ef41Sopenharmony_ci    o['variables']['coverage'] = 'true'
14731cb0ef41Sopenharmony_ci  else:
14741cb0ef41Sopenharmony_ci    o['variables']['coverage'] = 'false'
14751cb0ef41Sopenharmony_ci
14761cb0ef41Sopenharmony_ci  if options.shared:
14771cb0ef41Sopenharmony_ci    o['variables']['node_target_type'] = 'shared_library'
14781cb0ef41Sopenharmony_ci  elif options.enable_static:
14791cb0ef41Sopenharmony_ci    o['variables']['node_target_type'] = 'static_library'
14801cb0ef41Sopenharmony_ci  else:
14811cb0ef41Sopenharmony_ci    o['variables']['node_target_type'] = 'executable'
14821cb0ef41Sopenharmony_ci
14831cb0ef41Sopenharmony_ci  if options.node_builtin_modules_path:
14841cb0ef41Sopenharmony_ci    print('Warning! Loading builtin modules from disk is for development')
14851cb0ef41Sopenharmony_ci    o['variables']['node_builtin_modules_path'] = options.node_builtin_modules_path
14861cb0ef41Sopenharmony_ci
14871cb0ef41Sopenharmony_cidef configure_napi(output):
14881cb0ef41Sopenharmony_ci  version = getnapibuildversion.get_napi_version()
14891cb0ef41Sopenharmony_ci  output['variables']['napi_build_version'] = version
14901cb0ef41Sopenharmony_ci
14911cb0ef41Sopenharmony_cidef configure_library(lib, output, pkgname=None):
14921cb0ef41Sopenharmony_ci  shared_lib = 'shared_' + lib
14931cb0ef41Sopenharmony_ci  output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
14941cb0ef41Sopenharmony_ci
14951cb0ef41Sopenharmony_ci  if getattr(options, shared_lib):
14961cb0ef41Sopenharmony_ci    (pkg_libs, pkg_cflags, pkg_libpath, _) = pkg_config(pkgname or lib)
14971cb0ef41Sopenharmony_ci
14981cb0ef41Sopenharmony_ci    if options.__dict__[shared_lib + '_includes']:
14991cb0ef41Sopenharmony_ci      output['include_dirs'] += [options.__dict__[shared_lib + '_includes']]
15001cb0ef41Sopenharmony_ci    elif pkg_cflags:
15011cb0ef41Sopenharmony_ci      stripped_flags = [flag.strip() for flag in pkg_cflags.split('-I')]
15021cb0ef41Sopenharmony_ci      output['include_dirs'] += [flag for flag in stripped_flags if flag]
15031cb0ef41Sopenharmony_ci
15041cb0ef41Sopenharmony_ci    # libpath needs to be provided ahead libraries
15051cb0ef41Sopenharmony_ci    if options.__dict__[shared_lib + '_libpath']:
15061cb0ef41Sopenharmony_ci      if flavor == 'win':
15071cb0ef41Sopenharmony_ci        if 'msvs_settings' not in output:
15081cb0ef41Sopenharmony_ci          output['msvs_settings'] = { 'VCLinkerTool': { 'AdditionalOptions': [] } }
15091cb0ef41Sopenharmony_ci        output['msvs_settings']['VCLinkerTool']['AdditionalOptions'] += [
15101cb0ef41Sopenharmony_ci          f"/LIBPATH:{options.__dict__[shared_lib + '_libpath']}"]
15111cb0ef41Sopenharmony_ci      else:
15121cb0ef41Sopenharmony_ci        output['libraries'] += [
15131cb0ef41Sopenharmony_ci            f"-L{options.__dict__[shared_lib + '_libpath']}"]
15141cb0ef41Sopenharmony_ci    elif pkg_libpath:
15151cb0ef41Sopenharmony_ci      output['libraries'] += [pkg_libpath]
15161cb0ef41Sopenharmony_ci
15171cb0ef41Sopenharmony_ci    default_libs = getattr(options, shared_lib + '_libname')
15181cb0ef41Sopenharmony_ci    default_libs = [f'-l{l}' for l in default_libs.split(',')]
15191cb0ef41Sopenharmony_ci
15201cb0ef41Sopenharmony_ci    if default_libs:
15211cb0ef41Sopenharmony_ci      output['libraries'] += default_libs
15221cb0ef41Sopenharmony_ci    elif pkg_libs:
15231cb0ef41Sopenharmony_ci      output['libraries'] += pkg_libs.split()
15241cb0ef41Sopenharmony_ci
15251cb0ef41Sopenharmony_ci
15261cb0ef41Sopenharmony_cidef configure_v8(o):
15271cb0ef41Sopenharmony_ci  o['variables']['v8_enable_webassembly'] = 0 if options.v8_lite_mode else 1
15281cb0ef41Sopenharmony_ci  o['variables']['v8_enable_javascript_promise_hooks'] = 1
15291cb0ef41Sopenharmony_ci  o['variables']['v8_enable_lite_mode'] = 1 if options.v8_lite_mode else 0
15301cb0ef41Sopenharmony_ci  o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0
15311cb0ef41Sopenharmony_ci  o['variables']['v8_no_strict_aliasing'] = 1  # Work around compiler bugs.
15321cb0ef41Sopenharmony_ci  o['variables']['v8_optimized_debug'] = 0 if options.v8_non_optimized_debug else 1
15331cb0ef41Sopenharmony_ci  o['variables']['dcheck_always_on'] = 1 if options.v8_with_dchecks else 0
15341cb0ef41Sopenharmony_ci  o['variables']['v8_enable_object_print'] = 0 if options.v8_disable_object_print else 1
15351cb0ef41Sopenharmony_ci  o['variables']['v8_random_seed'] = 0  # Use a random seed for hash tables.
15361cb0ef41Sopenharmony_ci  o['variables']['v8_promise_internal_field_count'] = 1 # Add internal field to promises for async hooks.
15371cb0ef41Sopenharmony_ci  o['variables']['v8_use_siphash'] = 0 if options.without_siphash else 1
15381cb0ef41Sopenharmony_ci  o['variables']['v8_enable_pointer_compression'] = 1 if options.enable_pointer_compression else 0
15391cb0ef41Sopenharmony_ci  o['variables']['v8_enable_31bit_smis_on_64bit_arch'] = 1 if options.enable_pointer_compression else 0
15401cb0ef41Sopenharmony_ci  o['variables']['v8_enable_shared_ro_heap'] = 0 if options.enable_pointer_compression or options.disable_shared_ro_heap else 1
15411cb0ef41Sopenharmony_ci  o['variables']['v8_trace_maps'] = 1 if options.trace_maps else 0
15421cb0ef41Sopenharmony_ci  o['variables']['node_use_v8_platform'] = b(not options.without_v8_platform)
15431cb0ef41Sopenharmony_ci  o['variables']['node_use_bundled_v8'] = b(not options.without_bundled_v8)
15441cb0ef41Sopenharmony_ci  o['variables']['force_dynamic_crt'] = 1 if options.shared else 0
15451cb0ef41Sopenharmony_ci  o['variables']['node_enable_d8'] = b(options.enable_d8)
15461cb0ef41Sopenharmony_ci  if options.enable_d8:
15471cb0ef41Sopenharmony_ci    o['variables']['test_isolation_mode'] = 'noop'  # Needed by d8.gyp.
15481cb0ef41Sopenharmony_ci  if options.without_bundled_v8 and options.enable_d8:
15491cb0ef41Sopenharmony_ci    raise Exception('--enable-d8 is incompatible with --without-bundled-v8.')
15501cb0ef41Sopenharmony_ci  if options.static_zoslib_gyp:
15511cb0ef41Sopenharmony_ci    o['variables']['static_zoslib_gyp'] = options.static_zoslib_gyp
15521cb0ef41Sopenharmony_ci  if flavor != 'linux' and options.v8_enable_hugepage:
15531cb0ef41Sopenharmony_ci    raise Exception('--v8-enable-hugepage is supported only on linux.')
15541cb0ef41Sopenharmony_ci  o['variables']['v8_enable_hugepage'] = 1 if options.v8_enable_hugepage else 0
15551cb0ef41Sopenharmony_ci  if options.v8_enable_short_builtin_calls or o['variables']['target_arch'] == 'x64':
15561cb0ef41Sopenharmony_ci    o['variables']['v8_enable_short_builtin_calls'] = 1
15571cb0ef41Sopenharmony_ci  if options.v8_enable_snapshot_compression:
15581cb0ef41Sopenharmony_ci    o['variables']['v8_enable_snapshot_compression'] = 1
15591cb0ef41Sopenharmony_ci  if options.v8_enable_object_print and options.v8_disable_object_print:
15601cb0ef41Sopenharmony_ci    raise Exception(
15611cb0ef41Sopenharmony_ci        'Only one of the --v8-enable-object-print or --v8-disable-object-print options '
15621cb0ef41Sopenharmony_ci        'can be specified at a time.')
15631cb0ef41Sopenharmony_ci
15641cb0ef41Sopenharmony_cidef configure_openssl(o):
15651cb0ef41Sopenharmony_ci  variables = o['variables']
15661cb0ef41Sopenharmony_ci  variables['node_use_openssl'] = b(not options.without_ssl)
15671cb0ef41Sopenharmony_ci  variables['node_shared_openssl'] = b(options.shared_openssl)
15681cb0ef41Sopenharmony_ci  variables['node_shared_ngtcp2'] = b(options.shared_ngtcp2)
15691cb0ef41Sopenharmony_ci  variables['node_shared_nghttp3'] = b(options.shared_nghttp3)
15701cb0ef41Sopenharmony_ci  variables['openssl_is_fips'] = b(options.openssl_is_fips)
15711cb0ef41Sopenharmony_ci  variables['node_fipsinstall'] = b(False)
15721cb0ef41Sopenharmony_ci
15731cb0ef41Sopenharmony_ci  if options.openssl_no_asm:
15741cb0ef41Sopenharmony_ci    variables['openssl_no_asm'] = 1
15751cb0ef41Sopenharmony_ci
15761cb0ef41Sopenharmony_ci  o['defines'] += ['NODE_OPENSSL_CONF_NAME=' + options.openssl_conf_name]
15771cb0ef41Sopenharmony_ci
15781cb0ef41Sopenharmony_ci  if options.without_ssl:
15791cb0ef41Sopenharmony_ci    def without_ssl_error(option):
15801cb0ef41Sopenharmony_ci      error(f'--without-ssl is incompatible with {option}')
15811cb0ef41Sopenharmony_ci    if options.shared_openssl:
15821cb0ef41Sopenharmony_ci      without_ssl_error('--shared-openssl')
15831cb0ef41Sopenharmony_ci    if options.openssl_no_asm:
15841cb0ef41Sopenharmony_ci      without_ssl_error('--openssl-no-asm')
15851cb0ef41Sopenharmony_ci    if options.openssl_is_fips:
15861cb0ef41Sopenharmony_ci      without_ssl_error('--openssl-is-fips')
15871cb0ef41Sopenharmony_ci    if options.openssl_default_cipher_list:
15881cb0ef41Sopenharmony_ci      without_ssl_error('--openssl-default-cipher-list')
15891cb0ef41Sopenharmony_ci    return
15901cb0ef41Sopenharmony_ci
15911cb0ef41Sopenharmony_ci  if options.use_openssl_ca_store:
15921cb0ef41Sopenharmony_ci    o['defines'] += ['NODE_OPENSSL_CERT_STORE']
15931cb0ef41Sopenharmony_ci  if options.openssl_system_ca_path:
15941cb0ef41Sopenharmony_ci    variables['openssl_system_ca_path'] = options.openssl_system_ca_path
15951cb0ef41Sopenharmony_ci  variables['node_without_node_options'] = b(options.without_node_options)
15961cb0ef41Sopenharmony_ci  if options.without_node_options:
15971cb0ef41Sopenharmony_ci      o['defines'] += ['NODE_WITHOUT_NODE_OPTIONS']
15981cb0ef41Sopenharmony_ci  if options.openssl_default_cipher_list:
15991cb0ef41Sopenharmony_ci    variables['openssl_default_cipher_list'] = \
16001cb0ef41Sopenharmony_ci            options.openssl_default_cipher_list
16011cb0ef41Sopenharmony_ci
16021cb0ef41Sopenharmony_ci  if not options.shared_openssl and not options.openssl_no_asm:
16031cb0ef41Sopenharmony_ci    is_x86 = 'x64' in variables['target_arch'] or 'ia32' in variables['target_arch']
16041cb0ef41Sopenharmony_ci
16051cb0ef41Sopenharmony_ci    # supported asm compiler for AVX2. See https://github.com/openssl/openssl/
16061cb0ef41Sopenharmony_ci    # blob/OpenSSL_1_1_0-stable/crypto/modes/asm/aesni-gcm-x86_64.pl#L52-L69
16071cb0ef41Sopenharmony_ci    openssl110_asm_supported = \
16081cb0ef41Sopenharmony_ci      ('gas_version' in variables and StrictVersion(variables['gas_version']) >= StrictVersion('2.23')) or \
16091cb0ef41Sopenharmony_ci      ('xcode_version' in variables and StrictVersion(variables['xcode_version']) >= StrictVersion('5.0')) or \
16101cb0ef41Sopenharmony_ci      ('llvm_version' in variables and StrictVersion(variables['llvm_version']) >= StrictVersion('3.3')) or \
16111cb0ef41Sopenharmony_ci      ('nasm_version' in variables and StrictVersion(variables['nasm_version']) >= StrictVersion('2.10'))
16121cb0ef41Sopenharmony_ci
16131cb0ef41Sopenharmony_ci    if is_x86 and not openssl110_asm_supported:
16141cb0ef41Sopenharmony_ci      error('''Did not find a new enough assembler, install one or build with
16151cb0ef41Sopenharmony_ci       --openssl-no-asm.
16161cb0ef41Sopenharmony_ci       Please refer to BUILDING.md''')
16171cb0ef41Sopenharmony_ci
16181cb0ef41Sopenharmony_ci  elif options.openssl_no_asm:
16191cb0ef41Sopenharmony_ci    warn('''--openssl-no-asm will result in binaries that do not take advantage
16201cb0ef41Sopenharmony_ci         of modern CPU cryptographic instructions and will therefore be slower.
16211cb0ef41Sopenharmony_ci         Please refer to BUILDING.md''')
16221cb0ef41Sopenharmony_ci
16231cb0ef41Sopenharmony_ci  if options.openssl_no_asm and options.shared_openssl:
16241cb0ef41Sopenharmony_ci    error('--openssl-no-asm is incompatible with --shared-openssl')
16251cb0ef41Sopenharmony_ci
16261cb0ef41Sopenharmony_ci  if options.openssl_is_fips:
16271cb0ef41Sopenharmony_ci    o['defines'] += ['OPENSSL_FIPS']
16281cb0ef41Sopenharmony_ci
16291cb0ef41Sopenharmony_ci  if options.openssl_is_fips and not options.shared_openssl:
16301cb0ef41Sopenharmony_ci    variables['node_fipsinstall'] = b(True)
16311cb0ef41Sopenharmony_ci
16321cb0ef41Sopenharmony_ci  if options.shared_openssl:
16331cb0ef41Sopenharmony_ci    has_quic = getsharedopensslhasquic.get_has_quic(options.__dict__['shared_openssl_includes'])
16341cb0ef41Sopenharmony_ci  else:
16351cb0ef41Sopenharmony_ci    has_quic = getsharedopensslhasquic.get_has_quic('deps/openssl/openssl/include')
16361cb0ef41Sopenharmony_ci
16371cb0ef41Sopenharmony_ci  variables['openssl_quic'] = b(has_quic)
16381cb0ef41Sopenharmony_ci  if has_quic:
16391cb0ef41Sopenharmony_ci    o['defines'] += ['NODE_OPENSSL_HAS_QUIC']
16401cb0ef41Sopenharmony_ci
16411cb0ef41Sopenharmony_ci  configure_library('openssl', o)
16421cb0ef41Sopenharmony_ci
16431cb0ef41Sopenharmony_ci
16441cb0ef41Sopenharmony_cidef configure_static(o):
16451cb0ef41Sopenharmony_ci  if options.fully_static or options.partly_static:
16461cb0ef41Sopenharmony_ci    if flavor == 'mac':
16471cb0ef41Sopenharmony_ci      warn("Generation of static executable will not work on OSX "
16481cb0ef41Sopenharmony_ci            "when using the default compilation environment")
16491cb0ef41Sopenharmony_ci      return
16501cb0ef41Sopenharmony_ci
16511cb0ef41Sopenharmony_ci    if options.fully_static:
16521cb0ef41Sopenharmony_ci      o['libraries'] += ['-static']
16531cb0ef41Sopenharmony_ci    elif options.partly_static:
16541cb0ef41Sopenharmony_ci      o['libraries'] += ['-static-libgcc', '-static-libstdc++']
16551cb0ef41Sopenharmony_ci      if options.enable_asan:
16561cb0ef41Sopenharmony_ci        o['libraries'] += ['-static-libasan']
16571cb0ef41Sopenharmony_ci
16581cb0ef41Sopenharmony_ci
16591cb0ef41Sopenharmony_cidef write(filename, data):
16601cb0ef41Sopenharmony_ci  print_verbose(f'creating {filename}')
16611cb0ef41Sopenharmony_ci  with Path(filename).open(mode='w+', encoding='utf-8') as f:
16621cb0ef41Sopenharmony_ci    f.write(data)
16631cb0ef41Sopenharmony_ci
16641cb0ef41Sopenharmony_cido_not_edit = '# Do not edit. Generated by the configure script.\n'
16651cb0ef41Sopenharmony_ci
16661cb0ef41Sopenharmony_cidef glob_to_var(dir_base, dir_sub, patch_dir):
16671cb0ef41Sopenharmony_ci  file_list = []
16681cb0ef41Sopenharmony_ci  dir_all = f'{dir_base}/{dir_sub}'
16691cb0ef41Sopenharmony_ci  files = os.walk(dir_all)
16701cb0ef41Sopenharmony_ci  for ent in files:
16711cb0ef41Sopenharmony_ci    (_, _1, files) = ent
16721cb0ef41Sopenharmony_ci    for file in files:
16731cb0ef41Sopenharmony_ci      if file.endswith(('.cpp', '.c', '.h')):
16741cb0ef41Sopenharmony_ci        # srcfile uses "slash" as dir separator as its output is consumed by gyp
16751cb0ef41Sopenharmony_ci        srcfile = f'{dir_sub}/{file}'
16761cb0ef41Sopenharmony_ci        if patch_dir:
16771cb0ef41Sopenharmony_ci          patchfile = Path(dir_base, patch_dir, file)
16781cb0ef41Sopenharmony_ci          if patchfile.is_file():
16791cb0ef41Sopenharmony_ci            srcfile = f'{patch_dir}/{file}'
16801cb0ef41Sopenharmony_ci            info(f'Using floating patch "{patchfile}" from "{dir_base}"')
16811cb0ef41Sopenharmony_ci        file_list.append(srcfile)
16821cb0ef41Sopenharmony_ci    break
16831cb0ef41Sopenharmony_ci  return file_list
16841cb0ef41Sopenharmony_ci
16851cb0ef41Sopenharmony_cidef configure_intl(o):
16861cb0ef41Sopenharmony_ci  def icu_download(path):
16871cb0ef41Sopenharmony_ci    depFile = tools_path / 'icu' / 'current_ver.dep'
16881cb0ef41Sopenharmony_ci    icus = json.loads(depFile.read_text(encoding='utf-8'))
16891cb0ef41Sopenharmony_ci    # download ICU, if needed
16901cb0ef41Sopenharmony_ci    if not os.access(options.download_path, os.W_OK):
16911cb0ef41Sopenharmony_ci      error('''Cannot write to desired download path.
16921cb0ef41Sopenharmony_ci        Either create it or verify permissions.''')
16931cb0ef41Sopenharmony_ci    attemptdownload = nodedownload.candownload(auto_downloads, "icu")
16941cb0ef41Sopenharmony_ci    for icu in icus:
16951cb0ef41Sopenharmony_ci      url = icu['url']
16961cb0ef41Sopenharmony_ci      (expectHash, hashAlgo, allAlgos) = nodedownload.findHash(icu)
16971cb0ef41Sopenharmony_ci      if not expectHash:
16981cb0ef41Sopenharmony_ci        error(f'''Could not find a hash to verify ICU download.
16991cb0ef41Sopenharmony_ci          {depFile} may be incorrect.
17001cb0ef41Sopenharmony_ci          For the entry {url},
17011cb0ef41Sopenharmony_ci          Expected one of these keys: {' '.join(allAlgos)}''')
17021cb0ef41Sopenharmony_ci      local = url.split('/')[-1]
17031cb0ef41Sopenharmony_ci      targetfile = Path(options.download_path, local)
17041cb0ef41Sopenharmony_ci      if not targetfile.is_file():
17051cb0ef41Sopenharmony_ci        if attemptdownload:
17061cb0ef41Sopenharmony_ci          nodedownload.retrievefile(url, targetfile)
17071cb0ef41Sopenharmony_ci      else:
17081cb0ef41Sopenharmony_ci        print(f'Re-using existing {targetfile}')
17091cb0ef41Sopenharmony_ci      if targetfile.is_file():
17101cb0ef41Sopenharmony_ci        print(f'Checking file integrity with {hashAlgo}:\r')
17111cb0ef41Sopenharmony_ci        gotHash = nodedownload.checkHash(targetfile, hashAlgo)
17121cb0ef41Sopenharmony_ci        print(f'{hashAlgo}:      {gotHash}  {targetfile}')
17131cb0ef41Sopenharmony_ci        if expectHash == gotHash:
17141cb0ef41Sopenharmony_ci          return targetfile
17151cb0ef41Sopenharmony_ci
17161cb0ef41Sopenharmony_ci        warn(f'Expected: {expectHash}      *MISMATCH*')
17171cb0ef41Sopenharmony_ci        warn(f'\n ** Corrupted ZIP? Delete {targetfile} to retry download.\n')
17181cb0ef41Sopenharmony_ci    return None
17191cb0ef41Sopenharmony_ci  icu_config = {
17201cb0ef41Sopenharmony_ci    'variables': {}
17211cb0ef41Sopenharmony_ci  }
17221cb0ef41Sopenharmony_ci  icu_config_name = 'icu_config.gypi'
17231cb0ef41Sopenharmony_ci
17241cb0ef41Sopenharmony_ci  # write an empty file to start with
17251cb0ef41Sopenharmony_ci  write(icu_config_name, do_not_edit +
17261cb0ef41Sopenharmony_ci        pprint.pformat(icu_config, indent=2, width=1024) + '\n')
17271cb0ef41Sopenharmony_ci
17281cb0ef41Sopenharmony_ci  # always set icu_small, node.gyp depends on it being defined.
17291cb0ef41Sopenharmony_ci  o['variables']['icu_small'] = b(False)
17301cb0ef41Sopenharmony_ci
17311cb0ef41Sopenharmony_ci  # prevent data override
17321cb0ef41Sopenharmony_ci  o['defines'] += ['ICU_NO_USER_DATA_OVERRIDE']
17331cb0ef41Sopenharmony_ci
17341cb0ef41Sopenharmony_ci  with_intl = options.with_intl
17351cb0ef41Sopenharmony_ci  with_icu_source = options.with_icu_source
17361cb0ef41Sopenharmony_ci  have_icu_path = bool(options.with_icu_path)
17371cb0ef41Sopenharmony_ci  if have_icu_path and with_intl != 'none':
17381cb0ef41Sopenharmony_ci    error('Cannot specify both --with-icu-path and --with-intl')
17391cb0ef41Sopenharmony_ci  elif have_icu_path:
17401cb0ef41Sopenharmony_ci    # Chromium .gyp mode: --with-icu-path
17411cb0ef41Sopenharmony_ci    o['variables']['v8_enable_i18n_support'] = 1
17421cb0ef41Sopenharmony_ci    # use the .gyp given
17431cb0ef41Sopenharmony_ci    o['variables']['icu_gyp_path'] = options.with_icu_path
17441cb0ef41Sopenharmony_ci    return
17451cb0ef41Sopenharmony_ci
17461cb0ef41Sopenharmony_ci  # --with-intl=<with_intl>
17471cb0ef41Sopenharmony_ci  # set the default
17481cb0ef41Sopenharmony_ci  if with_intl in (None, 'none'):
17491cb0ef41Sopenharmony_ci    o['variables']['v8_enable_i18n_support'] = 0
17501cb0ef41Sopenharmony_ci    return  # no Intl
17511cb0ef41Sopenharmony_ci
17521cb0ef41Sopenharmony_ci  if with_intl == 'small-icu':
17531cb0ef41Sopenharmony_ci    # small ICU (English only)
17541cb0ef41Sopenharmony_ci    o['variables']['v8_enable_i18n_support'] = 1
17551cb0ef41Sopenharmony_ci    o['variables']['icu_small'] = b(True)
17561cb0ef41Sopenharmony_ci    locs = set(options.with_icu_locales.split(','))
17571cb0ef41Sopenharmony_ci    locs.add('root')  # must have root
17581cb0ef41Sopenharmony_ci    o['variables']['icu_locales'] = ','.join(str(loc) for loc in sorted(locs))
17591cb0ef41Sopenharmony_ci    # We will check a bit later if we can use the canned deps/icu-small
17601cb0ef41Sopenharmony_ci    o['variables']['icu_default_data'] = options.with_icu_default_data_dir or ''
17611cb0ef41Sopenharmony_ci  elif with_intl == 'full-icu':
17621cb0ef41Sopenharmony_ci    # full ICU
17631cb0ef41Sopenharmony_ci    o['variables']['v8_enable_i18n_support'] = 1
17641cb0ef41Sopenharmony_ci  elif with_intl == 'system-icu':
17651cb0ef41Sopenharmony_ci    # ICU from pkg-config.
17661cb0ef41Sopenharmony_ci    o['variables']['v8_enable_i18n_support'] = 1
17671cb0ef41Sopenharmony_ci    pkgicu = pkg_config('icu-i18n')
17681cb0ef41Sopenharmony_ci    if not pkgicu[0]:
17691cb0ef41Sopenharmony_ci      error('''Could not load pkg-config data for "icu-i18n".
17701cb0ef41Sopenharmony_ci       See above errors or the README.md.''')
17711cb0ef41Sopenharmony_ci    (libs, cflags, libpath, icuversion) = pkgicu
17721cb0ef41Sopenharmony_ci    icu_ver_major = icuversion.split('.')[0]
17731cb0ef41Sopenharmony_ci    o['variables']['icu_ver_major'] = icu_ver_major
17741cb0ef41Sopenharmony_ci    if int(icu_ver_major) < icu_versions['minimum_icu']:
17751cb0ef41Sopenharmony_ci      error(f"icu4c v{icuversion} is too old, v{icu_versions['minimum_icu']}.x or later is required.")
17761cb0ef41Sopenharmony_ci    # libpath provides linker path which may contain spaces
17771cb0ef41Sopenharmony_ci    if libpath:
17781cb0ef41Sopenharmony_ci      o['libraries'] += [libpath]
17791cb0ef41Sopenharmony_ci    # safe to split, cannot contain spaces
17801cb0ef41Sopenharmony_ci    o['libraries'] += libs.split()
17811cb0ef41Sopenharmony_ci    if cflags:
17821cb0ef41Sopenharmony_ci      stripped_flags = [flag.strip() for flag in cflags.split('-I')]
17831cb0ef41Sopenharmony_ci      o['include_dirs'] += [flag for flag in stripped_flags if flag]
17841cb0ef41Sopenharmony_ci    # use the "system" .gyp
17851cb0ef41Sopenharmony_ci    o['variables']['icu_gyp_path'] = 'tools/icu/icu-system.gyp'
17861cb0ef41Sopenharmony_ci    return
17871cb0ef41Sopenharmony_ci
17881cb0ef41Sopenharmony_ci  # this is just the 'deps' dir. Used for unpacking.
17891cb0ef41Sopenharmony_ci  icu_parent_path = 'deps'
17901cb0ef41Sopenharmony_ci
17911cb0ef41Sopenharmony_ci  # The full path to the ICU source directory. Should not include './'.
17921cb0ef41Sopenharmony_ci  icu_deps_path = 'deps/icu'
17931cb0ef41Sopenharmony_ci  icu_full_path = icu_deps_path
17941cb0ef41Sopenharmony_ci
17951cb0ef41Sopenharmony_ci  # icu-tmp is used to download and unpack the ICU tarball.
17961cb0ef41Sopenharmony_ci  icu_tmp_path = Path(icu_parent_path, 'icu-tmp')
17971cb0ef41Sopenharmony_ci
17981cb0ef41Sopenharmony_ci  # canned ICU. see tools/icu/README.md to update.
17991cb0ef41Sopenharmony_ci  canned_icu_dir = 'deps/icu-small'
18001cb0ef41Sopenharmony_ci
18011cb0ef41Sopenharmony_ci  # use the README to verify what the canned ICU is
18021cb0ef41Sopenharmony_ci  canned_icu_path = Path(canned_icu_dir)
18031cb0ef41Sopenharmony_ci  canned_is_full = (canned_icu_path / 'README-FULL-ICU.txt').is_file()
18041cb0ef41Sopenharmony_ci  canned_is_small = (canned_icu_path / 'README-SMALL-ICU.txt').is_file()
18051cb0ef41Sopenharmony_ci  if canned_is_small:
18061cb0ef41Sopenharmony_ci    warn(f'Ignoring {canned_icu_dir} - in-repo small icu is no longer supported.')
18071cb0ef41Sopenharmony_ci
18081cb0ef41Sopenharmony_ci  # We can use 'deps/icu-small' - pre-canned ICU *iff*
18091cb0ef41Sopenharmony_ci  # - canned_is_full AND
18101cb0ef41Sopenharmony_ci  # - with_icu_source is unset (i.e. no other ICU was specified)
18111cb0ef41Sopenharmony_ci  #
18121cb0ef41Sopenharmony_ci  # This is *roughly* equivalent to
18131cb0ef41Sopenharmony_ci  # $ configure --with-intl=full-icu --with-icu-source=deps/icu-small
18141cb0ef41Sopenharmony_ci  # .. Except that we avoid copying icu-small over to deps/icu.
18151cb0ef41Sopenharmony_ci  # In this default case, deps/icu is ignored, although make clean will
18161cb0ef41Sopenharmony_ci  # still harmlessly remove deps/icu.
18171cb0ef41Sopenharmony_ci
18181cb0ef41Sopenharmony_ci  if (not with_icu_source) and canned_is_full:
18191cb0ef41Sopenharmony_ci    # OK- we can use the canned ICU.
18201cb0ef41Sopenharmony_ci    icu_full_path = canned_icu_dir
18211cb0ef41Sopenharmony_ci    icu_config['variables']['icu_full_canned'] = 1
18221cb0ef41Sopenharmony_ci  # --with-icu-source processing
18231cb0ef41Sopenharmony_ci  # now, check that they didn't pass --with-icu-source=deps/icu
18241cb0ef41Sopenharmony_ci  elif with_icu_source and Path(icu_full_path).resolve() == Path(with_icu_source).resolve():
18251cb0ef41Sopenharmony_ci    warn(f'Ignoring redundant --with-icu-source={with_icu_source}')
18261cb0ef41Sopenharmony_ci    with_icu_source = None
18271cb0ef41Sopenharmony_ci  # if with_icu_source is still set, try to use it.
18281cb0ef41Sopenharmony_ci  if with_icu_source:
18291cb0ef41Sopenharmony_ci    if Path(icu_full_path).is_dir():
18301cb0ef41Sopenharmony_ci      print(f'Deleting old ICU source: {icu_full_path}')
18311cb0ef41Sopenharmony_ci      shutil.rmtree(icu_full_path)
18321cb0ef41Sopenharmony_ci    # now, what path was given?
18331cb0ef41Sopenharmony_ci    if Path(with_icu_source).is_dir():
18341cb0ef41Sopenharmony_ci      # it's a path. Copy it.
18351cb0ef41Sopenharmony_ci      print(f'{with_icu_source} -> {icu_full_path}')
18361cb0ef41Sopenharmony_ci      shutil.copytree(with_icu_source, icu_full_path)
18371cb0ef41Sopenharmony_ci    else:
18381cb0ef41Sopenharmony_ci      # could be file or URL.
18391cb0ef41Sopenharmony_ci      # Set up temporary area
18401cb0ef41Sopenharmony_ci      if Path(icu_tmp_path).is_dir():
18411cb0ef41Sopenharmony_ci        shutil.rmtree(icu_tmp_path)
18421cb0ef41Sopenharmony_ci      icu_tmp_path.mkdir()
18431cb0ef41Sopenharmony_ci      icu_tarball = None
18441cb0ef41Sopenharmony_ci      if Path(with_icu_source).is_file():
18451cb0ef41Sopenharmony_ci        # it's a file. Try to unpack it.
18461cb0ef41Sopenharmony_ci        icu_tarball = with_icu_source
18471cb0ef41Sopenharmony_ci      else:
18481cb0ef41Sopenharmony_ci        # Can we download it?
18491cb0ef41Sopenharmony_ci        local = icu_tmp_path / with_icu_source.split('/')[-1]  # local part
18501cb0ef41Sopenharmony_ci        icu_tarball = nodedownload.retrievefile(with_icu_source, local)
18511cb0ef41Sopenharmony_ci      # continue with "icu_tarball"
18521cb0ef41Sopenharmony_ci      nodedownload.unpack(icu_tarball, icu_tmp_path)
18531cb0ef41Sopenharmony_ci      # Did it unpack correctly? Should contain 'icu'
18541cb0ef41Sopenharmony_ci      tmp_icu = icu_tmp_path / 'icu'
18551cb0ef41Sopenharmony_ci      if tmp_icu.is_dir():
18561cb0ef41Sopenharmony_ci        tmp_icu.rename(icu_full_path)
18571cb0ef41Sopenharmony_ci        shutil.rmtree(icu_tmp_path)
18581cb0ef41Sopenharmony_ci      else:
18591cb0ef41Sopenharmony_ci        shutil.rmtree(icu_tmp_path)
18601cb0ef41Sopenharmony_ci        error(f'--with-icu-source={with_icu_source} did not result in an "icu" dir.')
18611cb0ef41Sopenharmony_ci
18621cb0ef41Sopenharmony_ci  # ICU mode. (icu-generic.gyp)
18631cb0ef41Sopenharmony_ci  o['variables']['icu_gyp_path'] = 'tools/icu/icu-generic.gyp'
18641cb0ef41Sopenharmony_ci  # ICU source dir relative to tools/icu (for .gyp file)
18651cb0ef41Sopenharmony_ci  o['variables']['icu_path'] = icu_full_path
18661cb0ef41Sopenharmony_ci  if not Path(icu_full_path).is_dir():
18671cb0ef41Sopenharmony_ci    # can we download (or find) a zipfile?
18681cb0ef41Sopenharmony_ci    localzip = icu_download(icu_full_path)
18691cb0ef41Sopenharmony_ci    if localzip:
18701cb0ef41Sopenharmony_ci      nodedownload.unpack(localzip, icu_parent_path)
18711cb0ef41Sopenharmony_ci    else:
18721cb0ef41Sopenharmony_ci      warn(f"* ECMA-402 (Intl) support didn't find ICU in {icu_full_path}..")
18731cb0ef41Sopenharmony_ci  if not Path(icu_full_path).is_dir():
18741cb0ef41Sopenharmony_ci    error(f'''Cannot build Intl without ICU in {icu_full_path}.
18751cb0ef41Sopenharmony_ci       Fix, or disable with "--with-intl=none"''')
18761cb0ef41Sopenharmony_ci  else:
18771cb0ef41Sopenharmony_ci    print_verbose(f'* Using ICU in {icu_full_path}')
18781cb0ef41Sopenharmony_ci  # Now, what version of ICU is it? We just need the "major", such as 54.
18791cb0ef41Sopenharmony_ci  # uvernum.h contains it as a #define.
18801cb0ef41Sopenharmony_ci  uvernum_h = Path(icu_full_path, 'source', 'common', 'unicode', 'uvernum.h')
18811cb0ef41Sopenharmony_ci  if not uvernum_h.is_file():
18821cb0ef41Sopenharmony_ci    error(f'Could not load {uvernum_h} - is ICU installed?')
18831cb0ef41Sopenharmony_ci  icu_ver_major = None
18841cb0ef41Sopenharmony_ci  matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
18851cb0ef41Sopenharmony_ci  match_version = re.compile(matchVerExp)
18861cb0ef41Sopenharmony_ci  with io.open(uvernum_h, encoding='utf8') as in_file:
18871cb0ef41Sopenharmony_ci    for line in in_file:
18881cb0ef41Sopenharmony_ci      m = match_version.match(line)
18891cb0ef41Sopenharmony_ci      if m:
18901cb0ef41Sopenharmony_ci        icu_ver_major = str(m.group(1))
18911cb0ef41Sopenharmony_ci  if not icu_ver_major:
18921cb0ef41Sopenharmony_ci    error(f'Could not read U_ICU_VERSION_SHORT version from {uvernum_h}')
18931cb0ef41Sopenharmony_ci  elif int(icu_ver_major) < icu_versions['minimum_icu']:
18941cb0ef41Sopenharmony_ci    error(f"icu4c v{icu_ver_major}.x is too old, v{icu_versions['minimum_icu']}.x or later is required.")
18951cb0ef41Sopenharmony_ci  icu_endianness = sys.byteorder[0]
18961cb0ef41Sopenharmony_ci  o['variables']['icu_ver_major'] = icu_ver_major
18971cb0ef41Sopenharmony_ci  o['variables']['icu_endianness'] = icu_endianness
18981cb0ef41Sopenharmony_ci  icu_data_file_l = f'icudt{icu_ver_major}l.dat' # LE filename
18991cb0ef41Sopenharmony_ci  icu_data_file = f'icudt{icu_ver_major}{icu_endianness}.dat'
19001cb0ef41Sopenharmony_ci  # relative to configure
19011cb0ef41Sopenharmony_ci  icu_data_path = Path(icu_full_path, 'source', 'data', 'in', icu_data_file_l) # LE
19021cb0ef41Sopenharmony_ci  compressed_data = f'{icu_data_path}.bz2'
19031cb0ef41Sopenharmony_ci  if not icu_data_path.is_file() and Path(compressed_data).is_file():
19041cb0ef41Sopenharmony_ci    # unpack. deps/icu is a temporary path
19051cb0ef41Sopenharmony_ci    if icu_tmp_path.is_dir():
19061cb0ef41Sopenharmony_ci      shutil.rmtree(icu_tmp_path)
19071cb0ef41Sopenharmony_ci    icu_tmp_path.mkdir()
19081cb0ef41Sopenharmony_ci    icu_data_path = icu_tmp_path / icu_data_file_l
19091cb0ef41Sopenharmony_ci    with icu_data_path.open(mode='wb') as outf:
19101cb0ef41Sopenharmony_ci        inf = bz2.BZ2File(compressed_data, 'rb')
19111cb0ef41Sopenharmony_ci        try:
19121cb0ef41Sopenharmony_ci          shutil.copyfileobj(inf, outf)
19131cb0ef41Sopenharmony_ci        finally:
19141cb0ef41Sopenharmony_ci          inf.close()
19151cb0ef41Sopenharmony_ci    # Now, proceed..
19161cb0ef41Sopenharmony_ci
19171cb0ef41Sopenharmony_ci  # relative to dep..
19181cb0ef41Sopenharmony_ci  icu_data_in = Path('..', '..', icu_data_path)
19191cb0ef41Sopenharmony_ci  if not icu_data_path.is_file() and icu_endianness != 'l':
19201cb0ef41Sopenharmony_ci    # use host endianness
19211cb0ef41Sopenharmony_ci    icu_data_path = Path(icu_full_path, 'source', 'data', 'in', icu_data_file) # will be generated
19221cb0ef41Sopenharmony_ci  if not icu_data_path.is_file():
19231cb0ef41Sopenharmony_ci    # .. and we're not about to build it from .gyp!
19241cb0ef41Sopenharmony_ci    error(f'''ICU prebuilt data file {icu_data_path} does not exist.
19251cb0ef41Sopenharmony_ci       See the README.md.''')
19261cb0ef41Sopenharmony_ci
19271cb0ef41Sopenharmony_ci  # this is the input '.dat' file to use .. icudt*.dat
19281cb0ef41Sopenharmony_ci  # may be little-endian if from a icu-project.org tarball
19291cb0ef41Sopenharmony_ci  o['variables']['icu_data_in'] = str(icu_data_in)
19301cb0ef41Sopenharmony_ci
19311cb0ef41Sopenharmony_ci  # map from variable name to subdirs
19321cb0ef41Sopenharmony_ci  icu_src = {
19331cb0ef41Sopenharmony_ci    'stubdata': 'stubdata',
19341cb0ef41Sopenharmony_ci    'common': 'common',
19351cb0ef41Sopenharmony_ci    'i18n': 'i18n',
19361cb0ef41Sopenharmony_ci    'tools': 'tools/toolutil',
19371cb0ef41Sopenharmony_ci    'genccode': 'tools/genccode',
19381cb0ef41Sopenharmony_ci    'genrb': 'tools/genrb',
19391cb0ef41Sopenharmony_ci    'icupkg': 'tools/icupkg',
19401cb0ef41Sopenharmony_ci  }
19411cb0ef41Sopenharmony_ci  # this creates a variable icu_src_XXX for each of the subdirs
19421cb0ef41Sopenharmony_ci  # with a list of the src files to use
19431cb0ef41Sopenharmony_ci  for key, value in icu_src.items():
19441cb0ef41Sopenharmony_ci    var  = f'icu_src_{key}'
19451cb0ef41Sopenharmony_ci    path = f'../../{icu_full_path}/source/{value}'
19461cb0ef41Sopenharmony_ci    icu_config['variables'][var] = glob_to_var('tools/icu', path, f'patches/{icu_ver_major}/source/{value}')
19471cb0ef41Sopenharmony_ci  # calculate platform-specific genccode args
19481cb0ef41Sopenharmony_ci  # print("platform %s, flavor %s" % (sys.platform, flavor))
19491cb0ef41Sopenharmony_ci  # if sys.platform == 'darwin':
19501cb0ef41Sopenharmony_ci  #   shlib_suffix = '%s.dylib'
19511cb0ef41Sopenharmony_ci  # elif sys.platform.startswith('aix'):
19521cb0ef41Sopenharmony_ci  #   shlib_suffix = '%s.a'
19531cb0ef41Sopenharmony_ci  # else:
19541cb0ef41Sopenharmony_ci  #   shlib_suffix = 'so.%s'
19551cb0ef41Sopenharmony_ci  if flavor == 'win':
19561cb0ef41Sopenharmony_ci    icu_config['variables']['icu_asm_ext'] = 'obj'
19571cb0ef41Sopenharmony_ci    icu_config['variables']['icu_asm_opts'] = [ '-o ' ]
19581cb0ef41Sopenharmony_ci  elif with_intl == 'small-icu' or options.cross_compiling:
19591cb0ef41Sopenharmony_ci    icu_config['variables']['icu_asm_ext'] = 'c'
19601cb0ef41Sopenharmony_ci    icu_config['variables']['icu_asm_opts'] = []
19611cb0ef41Sopenharmony_ci  elif flavor == 'mac':
19621cb0ef41Sopenharmony_ci    icu_config['variables']['icu_asm_ext'] = 'S'
19631cb0ef41Sopenharmony_ci    icu_config['variables']['icu_asm_opts'] = [ '-a', 'gcc-darwin' ]
19641cb0ef41Sopenharmony_ci  elif sys.platform == 'os400':
19651cb0ef41Sopenharmony_ci    icu_config['variables']['icu_asm_ext'] = 'S'
19661cb0ef41Sopenharmony_ci    icu_config['variables']['icu_asm_opts'] = [ '-a', 'xlc' ]
19671cb0ef41Sopenharmony_ci  elif sys.platform.startswith('aix'):
19681cb0ef41Sopenharmony_ci    icu_config['variables']['icu_asm_ext'] = 'S'
19691cb0ef41Sopenharmony_ci    icu_config['variables']['icu_asm_opts'] = [ '-a', 'xlc' ]
19701cb0ef41Sopenharmony_ci  elif sys.platform == 'zos':
19711cb0ef41Sopenharmony_ci    icu_config['variables']['icu_asm_ext'] = 'S'
19721cb0ef41Sopenharmony_ci    icu_config['variables']['icu_asm_opts'] = [ '-a', 'zos' ]
19731cb0ef41Sopenharmony_ci  else:
19741cb0ef41Sopenharmony_ci    # assume GCC-compatible asm is OK
19751cb0ef41Sopenharmony_ci    icu_config['variables']['icu_asm_ext'] = 'S'
19761cb0ef41Sopenharmony_ci    icu_config['variables']['icu_asm_opts'] = [ '-a', 'gcc' ]
19771cb0ef41Sopenharmony_ci
19781cb0ef41Sopenharmony_ci  # write updated icu_config.gypi with a bunch of paths
19791cb0ef41Sopenharmony_ci  write(icu_config_name, do_not_edit +
19801cb0ef41Sopenharmony_ci        pprint.pformat(icu_config, indent=2, width=1024) + '\n')
19811cb0ef41Sopenharmony_ci  return  # end of configure_intl
19821cb0ef41Sopenharmony_ci
19831cb0ef41Sopenharmony_cidef configure_inspector(o):
19841cb0ef41Sopenharmony_ci  disable_inspector = (options.without_inspector or
19851cb0ef41Sopenharmony_ci                       options.without_ssl)
19861cb0ef41Sopenharmony_ci  o['variables']['v8_enable_inspector'] = 0 if disable_inspector else 1
19871cb0ef41Sopenharmony_ci
19881cb0ef41Sopenharmony_cidef configure_section_file(o):
19891cb0ef41Sopenharmony_ci  try:
19901cb0ef41Sopenharmony_ci    proc = subprocess.Popen(['ld.gold'] + ['-v'], stdin = subprocess.PIPE,
19911cb0ef41Sopenharmony_ci                            stdout = subprocess.PIPE, stderr = subprocess.PIPE)
19921cb0ef41Sopenharmony_ci  except OSError:
19931cb0ef41Sopenharmony_ci    if options.node_section_ordering_info != "":
19941cb0ef41Sopenharmony_ci      warn('''No acceptable ld.gold linker found!''')
19951cb0ef41Sopenharmony_ci    return 0
19961cb0ef41Sopenharmony_ci
19971cb0ef41Sopenharmony_ci  with proc:
19981cb0ef41Sopenharmony_ci    match = re.match(r"^GNU gold.*([0-9]+)\.([0-9]+)$",
19991cb0ef41Sopenharmony_ci                     proc.communicate()[0].decode("utf-8"))
20001cb0ef41Sopenharmony_ci
20011cb0ef41Sopenharmony_ci  if match:
20021cb0ef41Sopenharmony_ci    gold_major_version = match.group(1)
20031cb0ef41Sopenharmony_ci    gold_minor_version = match.group(2)
20041cb0ef41Sopenharmony_ci    if int(gold_major_version) == 1 and int(gold_minor_version) <= 1:
20051cb0ef41Sopenharmony_ci      error('''GNU gold version must be greater than 1.2 in order to use section
20061cb0ef41Sopenharmony_ci            reordering''')
20071cb0ef41Sopenharmony_ci
20081cb0ef41Sopenharmony_ci  if options.node_section_ordering_info != "":
20091cb0ef41Sopenharmony_ci    o['variables']['node_section_ordering_info'] = os.path.realpath(
20101cb0ef41Sopenharmony_ci      str(options.node_section_ordering_info))
20111cb0ef41Sopenharmony_ci  else:
20121cb0ef41Sopenharmony_ci    o['variables']['node_section_ordering_info'] = ""
20131cb0ef41Sopenharmony_ci
20141cb0ef41Sopenharmony_cidef make_bin_override():
20151cb0ef41Sopenharmony_ci  if sys.platform == 'win32':
20161cb0ef41Sopenharmony_ci    raise Exception('make_bin_override should not be called on win32.')
20171cb0ef41Sopenharmony_ci  # If the system python is not the python we are running (which should be
20181cb0ef41Sopenharmony_ci  # python 3), then create a directory with a symlink called `python` to our
20191cb0ef41Sopenharmony_ci  # sys.executable. This directory will be prefixed to the PATH, so that
20201cb0ef41Sopenharmony_ci  # other tools that shell out to `python` will use the appropriate python
20211cb0ef41Sopenharmony_ci
20221cb0ef41Sopenharmony_ci  which_python = shutil.which('python')
20231cb0ef41Sopenharmony_ci  if (which_python and
20241cb0ef41Sopenharmony_ci      os.path.realpath(which_python) == os.path.realpath(sys.executable)):
20251cb0ef41Sopenharmony_ci    return
20261cb0ef41Sopenharmony_ci
20271cb0ef41Sopenharmony_ci  bin_override = Path('out', 'tools', 'bin').resolve()
20281cb0ef41Sopenharmony_ci  try:
20291cb0ef41Sopenharmony_ci    bin_override.mkdir(parents=True)
20301cb0ef41Sopenharmony_ci  except OSError as e:
20311cb0ef41Sopenharmony_ci    if e.errno != errno.EEXIST:
20321cb0ef41Sopenharmony_ci      raise e
20331cb0ef41Sopenharmony_ci
20341cb0ef41Sopenharmony_ci  python_link = bin_override / 'python'
20351cb0ef41Sopenharmony_ci  try:
20361cb0ef41Sopenharmony_ci    python_link.unlink()
20371cb0ef41Sopenharmony_ci  except OSError as e:
20381cb0ef41Sopenharmony_ci    if e.errno != errno.ENOENT:
20391cb0ef41Sopenharmony_ci      raise e
20401cb0ef41Sopenharmony_ci  os.symlink(sys.executable, python_link)
20411cb0ef41Sopenharmony_ci
20421cb0ef41Sopenharmony_ci  # We need to set the environment right now so that when gyp (in run_gyp)
20431cb0ef41Sopenharmony_ci  # shells out, it finds the right python (specifically at
20441cb0ef41Sopenharmony_ci  # https://github.com/nodejs/node/blob/d82e107/deps/v8/gypfiles/toolchain.gypi#L43)
20451cb0ef41Sopenharmony_ci  os.environ['PATH'] = str(bin_override) + ':' + os.environ['PATH']
20461cb0ef41Sopenharmony_ci
20471cb0ef41Sopenharmony_ci  return bin_override
20481cb0ef41Sopenharmony_ci
20491cb0ef41Sopenharmony_cioutput = {
20501cb0ef41Sopenharmony_ci  'variables': {},
20511cb0ef41Sopenharmony_ci  'include_dirs': [],
20521cb0ef41Sopenharmony_ci  'libraries': [],
20531cb0ef41Sopenharmony_ci  'defines': [],
20541cb0ef41Sopenharmony_ci  'cflags': [],
20551cb0ef41Sopenharmony_ci}
20561cb0ef41Sopenharmony_ci
20571cb0ef41Sopenharmony_ci# Print a warning when the compiler is too old.
20581cb0ef41Sopenharmony_cicheck_compiler(output)
20591cb0ef41Sopenharmony_ci
20601cb0ef41Sopenharmony_ci# determine the "flavor" (operating system) we're building for,
20611cb0ef41Sopenharmony_ci# leveraging gyp's GetFlavor function
20621cb0ef41Sopenharmony_ciflavor_params = {}
20631cb0ef41Sopenharmony_ciif options.dest_os:
20641cb0ef41Sopenharmony_ci  flavor_params['flavor'] = options.dest_os
20651cb0ef41Sopenharmony_ciflavor = GetFlavor(flavor_params)
20661cb0ef41Sopenharmony_ci
20671cb0ef41Sopenharmony_ciconfigure_node(output)
20681cb0ef41Sopenharmony_ciconfigure_node_lib_files(output)
20691cb0ef41Sopenharmony_ciconfigure_napi(output)
20701cb0ef41Sopenharmony_ciconfigure_library('zlib', output)
20711cb0ef41Sopenharmony_ciconfigure_library('http_parser', output)
20721cb0ef41Sopenharmony_ciconfigure_library('libuv', output)
20731cb0ef41Sopenharmony_ciconfigure_library('brotli', output, pkgname=['libbrotlidec', 'libbrotlienc'])
20741cb0ef41Sopenharmony_ciconfigure_library('cares', output, pkgname='libcares')
20751cb0ef41Sopenharmony_ciconfigure_library('nghttp2', output, pkgname='libnghttp2')
20761cb0ef41Sopenharmony_ciconfigure_library('nghttp3', output, pkgname='libnghttp3')
20771cb0ef41Sopenharmony_ciconfigure_library('ngtcp2', output, pkgname='libngtcp2')
20781cb0ef41Sopenharmony_ciconfigure_v8(output)
20791cb0ef41Sopenharmony_ciconfigure_openssl(output)
20801cb0ef41Sopenharmony_ciconfigure_intl(output)
20811cb0ef41Sopenharmony_ciconfigure_static(output)
20821cb0ef41Sopenharmony_ciconfigure_inspector(output)
20831cb0ef41Sopenharmony_ciconfigure_section_file(output)
20841cb0ef41Sopenharmony_ci
20851cb0ef41Sopenharmony_ci# configure shareable builtins
20861cb0ef41Sopenharmony_cioutput['variables']['node_builtin_shareable_builtins'] = []
20871cb0ef41Sopenharmony_cifor builtin, value in shareable_builtins.items():
20881cb0ef41Sopenharmony_ci  builtin_id = 'node_shared_builtin_' + builtin.replace('/', '_') + '_path'
20891cb0ef41Sopenharmony_ci  if getattr(options, builtin_id):
20901cb0ef41Sopenharmony_ci    output['defines'] += [builtin_id.upper() + '=' + getattr(options, builtin_id)]
20911cb0ef41Sopenharmony_ci  else:
20921cb0ef41Sopenharmony_ci    output['variables']['node_builtin_shareable_builtins'] += [value]
20931cb0ef41Sopenharmony_ci
20941cb0ef41Sopenharmony_ci# Forward OSS-Fuzz settings
20951cb0ef41Sopenharmony_cioutput['variables']['ossfuzz'] = b(options.ossfuzz)
20961cb0ef41Sopenharmony_ci
20971cb0ef41Sopenharmony_ci# variables should be a root level element,
20981cb0ef41Sopenharmony_ci# move everything else to target_defaults
20991cb0ef41Sopenharmony_civariables = output['variables']
21001cb0ef41Sopenharmony_cidel output['variables']
21011cb0ef41Sopenharmony_civariables['is_debug'] = B(options.debug)
21021cb0ef41Sopenharmony_ci
21031cb0ef41Sopenharmony_ci# make_global_settings should be a root level element too
21041cb0ef41Sopenharmony_ciif 'make_global_settings' in output:
21051cb0ef41Sopenharmony_ci  make_global_settings = output['make_global_settings']
21061cb0ef41Sopenharmony_ci  del output['make_global_settings']
21071cb0ef41Sopenharmony_cielse:
21081cb0ef41Sopenharmony_ci  make_global_settings = False
21091cb0ef41Sopenharmony_ci
21101cb0ef41Sopenharmony_cioutput = {
21111cb0ef41Sopenharmony_ci  'variables': variables,
21121cb0ef41Sopenharmony_ci  'target_defaults': output,
21131cb0ef41Sopenharmony_ci}
21141cb0ef41Sopenharmony_ciif make_global_settings:
21151cb0ef41Sopenharmony_ci  output['make_global_settings'] = make_global_settings
21161cb0ef41Sopenharmony_ci
21171cb0ef41Sopenharmony_ciprint_verbose(output)
21181cb0ef41Sopenharmony_ci
21191cb0ef41Sopenharmony_ciwrite('config.gypi', do_not_edit +
21201cb0ef41Sopenharmony_ci      pprint.pformat(output, indent=2, width=1024) + '\n')
21211cb0ef41Sopenharmony_ci
21221cb0ef41Sopenharmony_ciwrite('config.status', '#!/bin/sh\nset -x\nexec ./configure ' +
21231cb0ef41Sopenharmony_ci      ' '.join([shlex.quote(arg) for arg in original_argv]) + '\n')
21241cb0ef41Sopenharmony_ciPath('config.status').chmod(0o775)
21251cb0ef41Sopenharmony_ci
21261cb0ef41Sopenharmony_ci
21271cb0ef41Sopenharmony_ciconfig = {
21281cb0ef41Sopenharmony_ci  'BUILDTYPE': 'Debug' if options.debug else 'Release',
21291cb0ef41Sopenharmony_ci  'NODE_TARGET_TYPE': variables['node_target_type'],
21301cb0ef41Sopenharmony_ci}
21311cb0ef41Sopenharmony_ci
21321cb0ef41Sopenharmony_ci# Not needed for trivial case. Useless when it's a win32 path.
21331cb0ef41Sopenharmony_ciif sys.executable != 'python' and ':\\' not in sys.executable:
21341cb0ef41Sopenharmony_ci  config['PYTHON'] = sys.executable
21351cb0ef41Sopenharmony_ci
21361cb0ef41Sopenharmony_ciif options.prefix:
21371cb0ef41Sopenharmony_ci  config['PREFIX'] = options.prefix
21381cb0ef41Sopenharmony_ci
21391cb0ef41Sopenharmony_ciif options.use_ninja:
21401cb0ef41Sopenharmony_ci  config['BUILD_WITH'] = 'ninja'
21411cb0ef41Sopenharmony_ci
21421cb0ef41Sopenharmony_ci# On Windows there is another find.exe in C:\Windows\System32
21431cb0ef41Sopenharmony_ciif sys.platform == 'win32':
21441cb0ef41Sopenharmony_ci  config['FIND'] = '/usr/bin/find'
21451cb0ef41Sopenharmony_ci
21461cb0ef41Sopenharmony_ciconfig_lines = ['='.join((k,v)) for k,v in config.items()]
21471cb0ef41Sopenharmony_ci# Add a blank string to get a blank line at the end.
21481cb0ef41Sopenharmony_ciconfig_lines += ['']
21491cb0ef41Sopenharmony_ciconfig_str = '\n'.join(config_lines)
21501cb0ef41Sopenharmony_ci
21511cb0ef41Sopenharmony_ci# On Windows there's no reason to search for a different python binary.
21521cb0ef41Sopenharmony_cibin_override = None if sys.platform == 'win32' else make_bin_override()
21531cb0ef41Sopenharmony_ciif bin_override:
21541cb0ef41Sopenharmony_ci  config_str = 'export PATH:=' + str(bin_override) + ':$(PATH)\n' + config_str
21551cb0ef41Sopenharmony_ci
21561cb0ef41Sopenharmony_ciwrite('config.mk', do_not_edit + config_str)
21571cb0ef41Sopenharmony_ci
21581cb0ef41Sopenharmony_ci
21591cb0ef41Sopenharmony_ci
21601cb0ef41Sopenharmony_cigyp_args = ['--no-parallel', '-Dconfiguring_node=1']
21611cb0ef41Sopenharmony_cigyp_args += ['-Dbuild_type=' + config['BUILDTYPE']]
21621cb0ef41Sopenharmony_ci
21631cb0ef41Sopenharmony_ciif options.use_ninja:
21641cb0ef41Sopenharmony_ci  gyp_args += ['-f', 'ninja-' + flavor]
21651cb0ef41Sopenharmony_cielif flavor == 'win' and sys.platform != 'msys':
21661cb0ef41Sopenharmony_ci  gyp_args += ['-f', 'msvs', '-G', 'msvs_version=auto']
21671cb0ef41Sopenharmony_cielse:
21681cb0ef41Sopenharmony_ci  gyp_args += ['-f', 'make-' + flavor]
21691cb0ef41Sopenharmony_ci
21701cb0ef41Sopenharmony_ciif options.compile_commands_json:
21711cb0ef41Sopenharmony_ci  gyp_args += ['-f', 'compile_commands_json']
21721cb0ef41Sopenharmony_ci  os.path.islink('./compile_commands.json') and os.unlink('./compile_commands.json')
21731cb0ef41Sopenharmony_ci  os.symlink('./out/' + config['BUILDTYPE'] + '/compile_commands.json', './compile_commands.json')
21741cb0ef41Sopenharmony_ci
21751cb0ef41Sopenharmony_ci# override the variable `python` defined in common.gypi
21761cb0ef41Sopenharmony_ciif bin_override is not None:
21771cb0ef41Sopenharmony_ci  gyp_args += ['-Dpython=' + sys.executable]
21781cb0ef41Sopenharmony_ci
21791cb0ef41Sopenharmony_ci# pass the leftover non-whitespace positional arguments to GYP
21801cb0ef41Sopenharmony_cigyp_args += [arg for arg in args if not str.isspace(arg)]
21811cb0ef41Sopenharmony_ci
21821cb0ef41Sopenharmony_ciif warn.warned and not options.verbose:
21831cb0ef41Sopenharmony_ci  warn('warnings were emitted in the configure phase')
21841cb0ef41Sopenharmony_ci
21851cb0ef41Sopenharmony_ciprint_verbose("running: \n    " + " ".join(['python', 'tools/gyp_node.py'] + gyp_args))
21861cb0ef41Sopenharmony_cirun_gyp(gyp_args)
21871cb0ef41Sopenharmony_ciinfo('configure completed successfully')
2188