# IT4Innovations
# LK 2024

easyblock = 'CMakeMake'

name = 'TurboVNC'
version = '3.1.1'

homepage = 'https://www.turbovnc.org'
description = """TurboVNC is a derivative of VNC (Virtual Network Computing) that is tuned to provide
 peak performance for 3D and video workloads."""

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

source_urls = ['https://github.com/TurboVNC/turbovnc/archive']
sources = ['%(version)s.tar.gz']
checksums = [
    '834392e985cf29a6d7d3b21b6b95b8249c1390f2c4bbf716e03945ca9384bbc8',  # 3.0.1.tar.gz
]

builddependencies = [
    ('CMake', '3.27.6'),
    ('binutils', '2.40'),
]

dependencies = [
    ('Java', '11', '', SYSTEM),
    ('X11', '20231019'),
    ('pixman', '0.42.2'),
    ('libjpeg-turbo', '3.0.1'),
    ('Mesa', '23.1.9'),
    ('libGLU', '9.0.3'),
    ('libglvnd', '1.7.0'),
]

configopts = "-DTVNC_BUILDJAVA=0 -DTVNC_SYSTEMX11=1 "
configopts += "-DX11_X11_LIB=$EBROOTX11/lib/libX11.%s " % SHLIB_EXT
configopts += "-DX11_Xau_LIB=$EBROOTX11/lib/libXau.%s " % SHLIB_EXT
configopts += "-DX11_SM_LIB=$EBROOTX11/lib/libSM.%s " % SHLIB_EXT
configopts += "-DX11_ICE_LIB=$EBROOTX11/lib/libICE.%s " % SHLIB_EXT
configopts += "-DX11_Pixman_LIB=$EBROOTPIXMAN/lib/libpixman-1.%s.0 " % SHLIB_EXT
configopts += "-DOPENGL_glu_LIBRARY=$EBROOTLIBGLU/lib/libGLU.%s " % SHLIB_EXT
configopts += "-DOPENGL_egl_LIBRARY=$EBROOTLIBGLVND/lib/libEGL.%s " % SHLIB_EXT
configopts += "-DOPENGL_opengl_LIBRARY=$EBROOTLIBGLVND/lib/libOpenGL.%s " % SHLIB_EXT
configopts += "-DOPENGL_glx_LIBRARY=$EBROOTLIBGLVND/lib/libGLX.%s " % SHLIB_EXT

# if installdir starts with /opt, i.e. /opt/xxx, CMake will set SYSCONFDIR to /etc/opt/xxx instead of /opt/xxx/etc
# https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
# the solution is to define CMAKE_INSTALL_SYSCONFDIR explicitly
configopts += "-DCMAKE_INSTALL_SYSCONFDIR=%(installdir)s/etc "

# remove etc/turbovncserver-security.conf, to avoid errors like:
# (EE) Fatal server error:
# (EE) ERROR: .../TurboVNC/2.2.3-GCCcore-8.2.0/etc/turbovncserver-security.conf must be owned by you or by root
postinstallcmds = ["rm -rf %(installdir)s/etc/turbovncserver-security.conf"]

sanity_check_paths = {
    'files': ['bin/vncserver', 'bin/vncpasswd', 'bin/Xvnc'],
    'dirs': [],
}

moduleclass = 'vis'
