#!/usr/bin/perl
#################################################################################
# Generate a list of library sonames included in the Moblin Compliance 
# Specification
#
# Copyright (c) The Linux Foundation
# Copyright (c) Institute for System Programming, RAS
#
# Author: Denis Silakov <silakov@ispras.ru>
#################################################################################

use strict;
use DBI;
use Getopt::Long;

use Env qw(LSBUSER LSBDBPASSWD LSBDB LSBDBHOST);

# Specification version
my $spec_version='2.0';
my $spec_name='Moblin';
		
my $dbh = DBI->connect('DBI:mysql:database='.$LSBDB.';host='.$LSBDBHOST, $LSBUSER, $LSBDBPASSWD)
        or die "Couldn't connect to database: " . DBI->errstr;

# Index of the Specification in the Standard table
my $standard_id=2;

GetOptions("v=s" => \$spec_version,
            "f=s" => \$spec_name);

my ($spec_id) = $dbh->selectrow_array("SELECT Sid FROM Standard WHERE Sname='$spec_name'");
if( !$spec_id ) {
    die "Failed to get id for '$spec_name' specification";
}

my $libs_Q = $dbh->prepare("SELECT ALrunname FROM Library
                            JOIN ArchLib ON ALlid=Lid
                            JOIN ArchLibStd ON ALSalid=ALid
                            WHERE ALSsid=$spec_id
                            AND ALSappearedin > '' AND ALSappearedin <= '$spec_version'
                            AND (ALSwithdrawnin IS NULL OR ALSwithdrawnin > '$spec_version')
                            AND Lname != 'proginterp'
                            ORDER BY ALrunname");

$libs_Q->execute() or die "Can't get list of libraries: ".DBI->errstr;

print <<"EOM"
#
# moblin-compliance spec file
#

Name:           moblin-compliance
Summary:        Moblin Compliance package
Version:        2.0
Release:        1
BuildArch: noarch
EOM
;

for(1..$libs_Q->rows) {
    my $libentry = $libs_Q->fetchrow_hashref;
    print "Requires: ".$libentry->{'ALrunname'}."\n";
}

$libs_Q->finish;

print <<"EOM"
Provides:       moblin-compliance = 2.0
License:        GPL
Group:          Development
URL:            http://moblin.org/projects/moblin-compliance-tools

%description
Virtual package installing library dependencies for Moblin Copmpliance

%prep
# nothing to do

%build
# nothing to do

%install
# nothing to do

%clean
# nothing to do

%files
# no files in a virtual package
EOM
;
