#!/usr/bin/perl

use CGI;
use Mysql;

use Env qw(LSBUSER LSBDBPASSWD LSBDB LSBDBHOST);

$Dbh = Mysql->connect($LSBDBHOST,$LSBDB,$LSBUSER, $LSBDBPASSWD) || die $Mysql::db_errstr;

$select = "SELECT DISTINCT * FROM Library ";
$select.= "LEFT JOIN ArchLib ON Lid=ALlid ";
$select.= "LEFT JOIN Architecture ON Aid=ALaid ";
$select.= "WHERE Library.Lstd='Yes' ";
$select.= "AND Architecture.Aname!='None' ";
$select.= "ORDER BY ALrunname,Aid ";

#print $select;

$sth = $Dbh->query($select) || die $Dbh->errmsg();

print "/* Generated file - Do Not Edit */\n";
print "char *DtNeeded[] = {\n";
for(1..$sth->numrows) {
	%entry=$sth->fetchhash;
	if( $entry{'ALrunname'} eq "" ) {
		next;
		}
	if( $entry{'Aname'} ne "All" ) {
                print "#if ".$entry{'Asymbol'}."\n";
        }
	printf "\t\"%s\",\n",$entry{'ALrunname'};
	if( $entry{'Aname'} ne "All" ) {
                print "#endif /* ".$entry{'Asymbol'}." */\n";
        }
}
print "\t};\n";
print "int numDtNeeded = sizeof(DtNeeded)/sizeof(char *);\n";

