package Cpanel::Easy::OptLib::libxslt;

# cpanel - Cpanel/Easy/OptLib/libxslt.pm          Copyright(c) 2014 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cpanel license. Unauthorized copying is prohibited

sub path_installed {
    my ($easy_obj) = @_;

    my $xsltversion = '1.1.32';

    return {
        'name'         => 'xslt',
        'install_path' => '/opt/xslt/',
        'itis_up2date' => sub {
            my $formatted_xsltversion = sprintf( '%d%02d%02d', split( /\./, $xsltversion ) );
            my $formatted_xmlversion = '20632';

            # check for an updated libxml2
            if ( -e '/opt/xml2/include/libxml2/libxml/xmlversion.h' && open my $xmlversion_fh, '<', '/opt/xml2/include/libxml2/libxml/xmlversion.h' ) {
                while ( my $line = <$xmlversion_fh> ) {
                    if ( $line =~ /^\s*#\s*define\s+LIBXML_VERSION\s+(\d+)/ ) {
                        $formatted_xmlversion = $1;
                        last;
                    }
                }
                close $xmlversion_fh;
            }
            if ( `/opt/xslt/bin/xsltproc --version` !~ m/^libxslt ${formatted_xsltversion} was compiled against libxml ${formatted_xmlversion}$/m ) {
                return 0;
            }

            return 1;
        },
        'working_path' => 'libxslt-1',
        'command_list' => [
            [ './configure', '--prefix=/opt/xslt', '--with-libxml-prefix=/opt/xml2/', '--with-python=no', '--with-crypto=no' ],
            ['make'],
            [qw(make install)],
        ],
    };
}

1;
