#### Control part variable.
_NODE_PREFIX=/usr/lib/node-${PKGVER%%.*}

abinfo "Configuring Node.js ..."
export WITHOUT_LIEF=""
if ab_match_arch loongson3; then
# FIXME:
# ../deps/LIEF/include/LIEF/asm/mips/opcodes.hpp:22:11: error: expected identifier or '{'
# 22 | namespace mips {
# | ^
# <built-in>:420:14: note: expanded from macro 'mips'
    abinfo "Disabling LIEF for loongson3 ..."
    export WITHOUT_LIEF="--without-lief"
fi
# FIXME: According to https://github.com/nodejs/node/issues/62676
# Use bundled icu for now until v8 has fixed the problem
"$SRCDIR"/configure \
    --prefix=${_NODE_PREFIX} \
    --ninja \
    --shared-ada \
    --shared-brotli \
    --shared-cares \
    --shared-ffi \
    --shared-hdr-histogram \
    --shared-http-parser \
    --shared-libuv \
    --shared-nghttp2 \
    --shared-nghttp3 \
    --shared-ngtcp2 \
    --shared-openssl \
    --shared-simdutf \
    --shared-sqlite \
    --shared-zstd \
    --shared-zlib \
    --with-intl=full-icu \
    --with-corepack \
    --v8-enable-temporal-support \
    $WITHOUT_LIEF \
    $NODE_FLAGS_ARCH

abinfo "Building Node.js ..."
make "$MAKEFLAGS"

abinfo "Installing Node.js ..."
make install \
    DESTDIR="$PKGDIR"

abinfo "Installing node-gyp ..."
install -Dvm755 \
   "$PKGDIR"/${_NODE_PREFIX}/lib/node_modules/npm/bin/node-gyp-bin/node-gyp \
   "$PKGDIR"/${_NODE_PREFIX}/bin/node-gyp
sed -e 's|"`dirname "$0"`/../../|"`dirname "$0"`/../lib/node-${PKGVER%%.*}/lib/node_modules/npm/|' \
    -i "$PKGDIR"/${_NODE_PREFIX}/bin/node-gyp

abinfo "Creating Corepack shims..."
PATH="$PATH:"$PKGDIR"/${_NODE_PREFIX}/bin" \
"$PKGDIR"/${_NODE_PREFIX}/bin/corepack \
    enable
