[buildout]
extends =
  ../coreutils/buildout.cfg
  ../patch/buildout.cfg
  ../git/buildout.cfg
  ../pkgconfig/buildout.cfg
  ../openssl/buildout.cfg
  ../zlib/buildout.cfg
  ../python-2.7/buildout.cfg
  ../python3/buildout.cfg

parts =
  nodejs

# nodejs >= 16 needs gcc >= 8.3
# nodejs >= 22 needs gcc >= 12.3
[gcc]
min_version = 8.3


[nodejs]
<= nodejs-18.18.0

[nodejs-headers]
<= nodejs-headers-18.18.0


[node-gyp-environment]
# environment section to build with node-gyp.
# node-gyp downloads a tarball containing nodejs headers by default
# this uses a locally downloaded tarball, for reproductibility.
npm_config_tarball = ${nodejs-headers:target}


[nodejs-16.19.0]
<= nodejs-base
version = v16.19.0
md5sum = e72b698681aff62bf17146ad70dc9425
patches =
  https://raw.githubusercontent.com/nxhack/openwrt-node-packages/9e3ab4cc9fd5f19c25ccd6f19be5a9b47e2c6933/node/patches/v16.x/010-execvp-arg-list-too-long.patch#17bb14ea3a1b5b4832e3680e4edfeded
patch-options = -p1
PATH = ${pkgconfig:location}/bin:${python3:location}/bin:${patch:location}/bin/:%(PATH)s
post-install =
  # configure header tarball for node-gyp
  # https://stackoverflow.com/a/64052237
  @@LOCATION@@/bin/node @@LOCATION@@/bin/npm config set --global tarball ${nodejs-headers-base-16.19.0:target}

[nodejs-headers-base-16.19.0]
<= nodejs-headers-base
version = v16.19.0
md5sum = e7bfbf135ae54d1dcca63bf17be84818

[nodejs-18.18.0]
<= nodejs-base
version = v18.18.0
md5sum = a1ce8df7e6b9df9f4ba3ff1d4e2173d2

[nodejs-headers-18.18.0]
<= nodejs-headers-base
version = v18.18.0
md5sum = c5ab3e98977dfd639d830625d79eff52


[nodejs-22.11.0]
<= nodejs-base
version = v22.11.0
md5sum = 573831fd2b7abf70a882946e511b64f4

[nodejs-headers-22.11.0]
<= nodejs-headers-base
version = v22.11.0
md5sum = 45ffb2b6ff09e4391caa6beb13343721


[nodejs-14.16.0]
<= nodejs-base
version = v14.16.0
md5sum = 7dc3666f407bf4e12a01ce1be2883d31
openssl-location = ${openssl-1.1:location}

[nodejs-12.18.3]
<= nodejs-base
version = v12.18.3
md5sum = 28bf6a4d98b238403fa58a0805f4a979
openssl-location = ${openssl-1.1:location}
PATH = ${pkgconfig:location}/bin:${python2.7:location}/bin:%(PATH)s
configure-command = ./configure

[nodejs-base]
# Server-side Javascript.
version =
md5sum =
openssl-location = ${openssl:location}

recipe = slapos.recipe.cmmi
shared = true
url = https://nodejs.org/dist/${:version}/node-${:version}.tar.gz
configure-command = python3 configure
configure-options =
  --prefix=%(location)s
  --shared-openssl
  --shared-openssl-includes=${:openssl-location}/include
  --shared-openssl-libpath=${:openssl-location}/lib
PATH = ${python3:location}/bin:${pkgconfig:location}/bin:%(PATH)s
environment =
  HOME=@@LOCATION@@
  PATH=${:PATH}
  PKG_CONFIG_PATH=${:openssl-location}/lib/pkgconfig/
  CPPFLAGS=-I${zlib:location}/include
  LDFLAGS=-Wl,-rpath=${:openssl-location}/lib -L${zlib:location}/lib -Wl,-rpath=${zlib:location}/lib
  LD_LIBRARY_PATH=${:openssl-location}/lib

[nodejs-headers-base]
recipe = slapos.recipe.build:download
shared = true
version =
md5sum =
url = https://nodejs.org/download/release/${:version}/node-${:version}-headers.tar.gz
