#!/usr/bin/perl -w
## pocc-alternate.pl for pocc in /Users/pouchet
##
## Made by Louis-Noel Pouchet
## Contact: <louis-noel.pouchet@inria.fr>
##
## Started on  Wed Apr 15 18:50:36 2009 Louis-Noel Pouchet
## Last update Fri Nov 13 01:17:49 2009 Louis-Noel Pouchet
##
#
# pocc-alternate: this file is part of the PoCC project.
#
# PoCC, the Polyhedral Compiler Collection package
#
# Copyright (C) 2009 Louis-Noel Pouchet
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1
# of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# The complete GNU General Public Licence Notice can be found as the
# `COPYING.LESSER' file in the root directory.
#
# Author:
# Louis-Noel Pouchet <Louis-Noel.Pouchet@inria.fr>
#

use Switch;
use Term::ANSIColor;

## Some global variables.
$BDIR_ALT = ".";
$CONFIGURE = "";
$DRIVER = "";

sub get_available_confs
{
    $val = `find $BDIR_ALT/config -maxdepth 1 -type d | grep -v "/\.svn" | grep -v "pocc/config\$"`;
    $val =~ s/$BDIR_ALT\/config\///g;
    @ret = split(/\n/, $val);

    return @ret;
}


sub switch_conf
{
    my ($conf) = @_;
    system ("cp -f $BDIR_ALT/config/$conf/* $BDIR_ALT/config");
}


sub alternate
{
    my ($basedir, $altconfig) = @_;
    $BDIR_ALT = $basedir;
    @avail_confs = get_available_confs();
    my $i;
    for ($i = 0; $i <= $#avail_confs; $i++) {
	if ($avail_confs[$i] eq $altconfig) {
	    switch_conf($altconfig);
	    print "[PoCC-alternate] Alternate config loaded: $altconfig\n";
	    return 0;
	}
    }
    die "[PoCC-alternate] Unknown configuration: $altconfig\n";
}
