easyblock = 'Bundle'

name = 'Xvfb'
version = '1.20.9'

homepage = 'https://www.x.org/releases/X11R7.6/doc/man/man1/Xvfb.1.xhtml'
description = """Xvfb is an X server that can run on machines with no display hardware and no physical input devices.
 It emulates a dumb framebuffer using virtual memory."""

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

builddependencies = [
    ('binutils', '2.35'),
    ('pkg-config', '0.29.2'),
    ('Python', '3.8.6'),
]

dependencies = [
    ('X11', '20201008'),
    ('pixman', '0.40.0'),
    ('libdrm', '2.4.102'),
    ('Mesa', '20.2.1'),
    ('nettle', '3.6'),
    ('libunwind', '1.4.0'),
    ('XZ', '5.2.5'),
]

default_easyblock = 'ConfigureMake'

local_xvfb_configopts = "--enable-xvfb --disable-xorg --disable-xnest --disable-xwin "
local_xvfb_configopts += "--disable-dri --disable-dri2 --disable-dri3 --disable-libunwind "
local_xvfb_configopts += "--with-fontrootdir=%(installdir)s/share/fonts/X11"

# use 'make V=1' to see compiler commands
local_xvfb_buildopts = "V=1 "

# use static libraries for nettle & libunwind, so avoid errors like "No rule to make target '-lnettle'"
local_xvfb_buildopts += 'SHA1_LIBS="$EBROOTNETTLE/lib*/libnettle.a" '
local_xvfb_buildopts += 'LIBUNWIND_LIBS="$EBROOTLIBUNWIND/lib*/libunwind.a $EBROOTXZ/lib*/liblzma.a"'

default_component_specs = {
    'source_urls': ['https://www.x.org/archive//individual/font/'],
    'sources': [SOURCE_TAR_GZ],
    'start_dir': '%(name)s-%(version)s',
}

local_font_misc_preconfigopts = "export PKG_CONFIG_PATH=%(installdir)s/lib/pkgconfig:$PKG_CONFIG_PATH && "
local_font_misc_preconfigopts += "export PATH=%(installdir)s/bin:$PATH && "

components = [
    ('mkfontscale', '1.2.1', {
        'source_urls': ['https://www.x.org/archive//individual/app/'],
        'checksums': ['e5b687029e44d0bd3ccd254a4da6a5cbfc40350aa8b43fcca16ef6e9b9bb9f22'],
    }),
    ('mkfontdir', '1.0.7', {
        'source_urls': ['https://www.x.org/archive//individual/app/'],
        'checksums': ['bccc5fb7af1b614eabe4a22766758c87bfc36d66191d08c19d2fa97674b7b5b7'],
    }),
    ('bdftopcf', '1.1', {
        'source_urls': ['https://www.x.org/archive//individual/app/'],
        'checksums': ['699d1a62012035b1461c7f8e3f05a51c8bd6f28f348983249fb89bbff7309b47'],
    }),
    ('font-util', '1.3.2', {
        'checksums': ['f115a3735604de1e852a4bf669be0269d8ce8f21f8e0e74ec5934b31dadc1e76'],
    }),
    ('font-misc-misc', '1.1.2', {
        'checksums': ['46142c876e176036c61c0c24c0a689079704d5ca5b510d48c025861ee2dbf829'],
        'preconfigopts': local_font_misc_preconfigopts,
    }),
    ('xkbcomp', '1.4.4', {
        'source_urls': ['https://www.x.org/archive//individual/app/'],
        'checksums': ['159fba6b62ef4a3fb16ef7fc4eb4fc26f3888652471ceb604c495783dda020bc'],
    }),
    ('xkeyboard-config', '2.31', {
        'source_urls': ['https://www.x.org/archive//individual/data/xkeyboard-config/'],
        'checksums': ['5ac6b5b661aeb9d0ea84ad961cbbdd8fdf2503d6e8ca65ca1b1c5d9aea2ddc52'],
        'configopts': '--with-xkb-rules-symlink=xorg',
    }),
    ('xauth', '1.1', {
        'source_urls': ['https://www.x.org/releases/individual/app/'],
        'checksums': ['e9fce796c8c5c9368594b9e8bbba237fb54b6615f5fd60e8d0a5b3c52a92c5ef'],
    }),
    (name, version, {
        'source_urls': ['https://www.x.org/releases/individual//xserver/'],
        'sources': ['xorg-server-%(version)s.tar.gz'],
        'patches': [('xvfb-run', '.')],
        'checksums': [
            '067c348fe1a86a1924010354c1c7cf1eaa9e43866e48540aa56a465f2a341ddc',  # xorg-server-1.20.9.tar.gz
            'fd6d13182b77871d4f65fccdaebb8a72387a726426066d3f8e6aa26b010ea0e8',  # xvfb-run
        ],
        'start_dir': 'xorg-server-%(version)s',
        'configopts': local_xvfb_configopts,
        'buildopts': local_xvfb_buildopts,
        'installopts': local_xvfb_buildopts,
    }),
]

postinstallcmds = ["cp -a xvfb-run %(installdir)s/bin/ && chmod u+x  %(installdir)s/bin/xvfb-run"]

sanity_check_paths = {
    'files': ['bin/Xvfb', 'bin/xvfb-run'],
    'dirs': ['lib/xorg', 'share/fonts/X11/misc', 'share/fonts/X11/util'],
}

sanity_check_commands = [
    "xvfb-run --help",
    "xvfb-run --error-file %(builddir)s/xvfb-run-test.err echo hello",
]

moduleclass = 'vis'
