#
# $Id: qmake.pl,v 1.6 2010/09/01 00:45:46 billo Exp $
#

my $qt4 = 'C:\\RiverWare\\tools\\Qt-482';

$ENV{QTDIR} = $qt4;
$ENV{Path} = $qt4 . '\\bin;' . $ENV{Path};

my @pkg = ('Accounting', 'AccountingGUI', 'DbDmi', 'EngrObjs', 'GUI',
           'Halibut', 'Opt', 'Optimize', 'OracleConnect', 'Q3GUI',
           'QtAccounting', 'QtDmi', 'QtRpl', 'QtRun', 'QtSCT', 'QtUtils',
           'Rcl', 'Remote', 'Rpl', 'RplExpression', 'RplGUI', 'RwOracle',
           'RwQt', 'Servers', 'Sim', 'Units', 'Utils', 'VCXX');

# get riverware and library .pro modification times.
my $rwmod = (stat('riverwarebase.pro'))[9];
my $libmod = (stat('library.pro'))[9];

chdir '..';

foreach (@pkg) {

    chdir $_;

    make($_);
    make($_ . 'Generated');

    chdir '..';
}

chdir 'EngrObjs';
make ('riverware');
chdir '..';

sub make {
    my $file = $_[0];
    my ($pro, $vcproj) = ("$file.pro", "$file.vcproj");

    if (-f $pro) {

        # get the package .vcproj modification time (if extant).
        my $vcmod = (stat($vcproj))[9] if -f $vcproj;

        # run qmake if either:
        #   - package .vcproj doesn't exist
        #   - .vcproj is older than package .pro
        #   - .vcproj is older than library .pro
        #   - .vcproj is older than riverware .pro
        if (! -f $vcproj ||
            $vcmod < (stat($pro))[9] ||
            $vcmod < $libmod ||
            $vcmod < $rwmod)
        {
            my $cmd = "qmake $pro";
            print "\n$cmd\n";
            system($cmd);

        }
    }
}

exit 0;
