# IT4Innovations
# LK 2024

easyblock = 'ConfigureMake'

name = 'ncurses'
version = '6.5'

homepage = 'https://www.gnu.org/software/ncurses/'
description = """
 The Ncurses (new curses) library is a free software emulation of curses in
 System V Release 4.0, and more. It uses Terminfo format, supports pads and
 color and multiple highlights and forms characters and function-key mapping,
 and has all the other SYSV-curses enhancements over BSD Curses.
"""

toolchain = {'name': 'GCCcore', 'version': '14.2.0'}
toolchainopts = {'pic': True}

source_urls = [GNU_SOURCE]
sources = [SOURCE_TAR_GZ]
checksums = ['136d91bc269a9a5785e5f9e980bc76ab57428f604ce3e5a5a90cebc767971cc6']

builddependencies = [
    ('binutils', '2.42'),
    ('pkgconf', '2.2.0'),
]

local_common_configopts = "--with-shared --enable-overwrite --without-ada --enable-symlinks --with-versioned-syms "
local_common_configopts += "--enable-pc-files --with-pkg-config-libdir=%(installdir)s/lib/pkgconfig "
configopts = [
    # build ncurses: serial build in default paths with shared libraries
    local_common_configopts + "--disable-widec",
    # build ncursesw: serial with UTF-8
    local_common_configopts + "--enable-ext-colors --enable-widec --includedir=%(installdir)s/include/ncursesw/",
]

# Symlink libtinfo to libncurses
# libncurses with this configopts has all the symbols from libtinfo, but some packages look for libtinfo specifically
postinstallcmds = ['cd %(installdir)s/lib && for l in libncurses{.,_,w}*; do ln -s "${l}" "${l/ncurses/tinfo}"; done']

_target_suffix = ['', 'w']  # '': ncurses, 'w': ncursesw
_lib_suffix = ['%s%s' % (x, y) for x in _target_suffix for y in ['.a', '_g.a', '.' + SHLIB_EXT]]
_lib_names = ['form', 'menu', 'ncurses', 'panel', 'tinfo']
_pc_names = ['form', 'menu', 'ncurses++', 'ncurses', 'panel']

sanity_check_paths = {
    'files': ['bin/%s' % x for x in ["captoinfo", "clear", "infocmp", "infotocap", "ncurses%(version_major)s-config",
                                     "reset", "tabs", "tic", "toe", "tput", "tset"]] +
             ['lib/lib%s%s' % (x, y) for x in _lib_names for y in _lib_suffix] +
             ['lib/libncurses++%s.a' % x for x in _target_suffix] +
             ['lib/pkgconfig/%s%s.pc' % (x, y) for x in _pc_names for y in _target_suffix],
    'dirs': ['include', 'include/ncursesw'],
}

moduleclass = 'devel'
