easyblock = 'ConfigureMake'

name = 'nodejs'
version = '16.15.1'  # LTS on 2022-06-12
local_libversion = '93'

homepage = 'https://nodejs.org'
description = """Node.js is a platform built on Chrome's JavaScript runtime
 for easily building fast, scalable network applications. Node.js uses an
 event-driven, non-blocking I/O model that makes it lightweight and efficient,
 perfect for data-intensive real-time applications that run across distributed devices."""

toolchain = {'name': 'GCCcore', 'version': '11.2.0'}

source_urls = ['https://nodejs.org/dist/v%(version)s/']
sources = ['node-v%(version)s.tar.gz']
checksums = ['308aee7149c4092a53c87c28ef49e23a8d1606119e79ae68333062e2a1f94208']

builddependencies = [
    ('binutils', '2.37'),
    ('Python', '3.9.6', '-bare'),
]

configopts = [
    '--with-intl=none',           # Fully disable ICU to avoid issues with the embedded icu-small library
    '--shared --with-intl=none',  # Build libnode.so in a second run
]

# Link libv8 libs to libnode
postinstallcmds = [
    "cd %%(installdir)s/lib; ln -s libnode.%s.%s libnode.%s" % (SHLIB_EXT, local_libversion, SHLIB_EXT),
    "cd %%(installdir)s/lib; ln -s libnode.%s.%s libv8.%s" % (SHLIB_EXT, local_libversion, SHLIB_EXT),
    "cd %%(installdir)s/lib; ln -s libnode.%s.%s libv8_libbase.%s" % (SHLIB_EXT, local_libversion, SHLIB_EXT),
    "cd %%(installdir)s/lib; ln -s libnode.%s.%s libv8_libplatform.%s" % (SHLIB_EXT, local_libversion, SHLIB_EXT),
]

sanity_check_paths = {
    'files': ['bin/node', 'bin/npm', 'lib/libnode.%s.%s' % (SHLIB_EXT, local_libversion)],
    'dirs': ['lib/node_modules', 'include/node']
}

moduleclass = 'lang'
