All pastes #68400 Raw Edit

Jas-Nix

public text v1 · immutable
#68400 ·published 2006-06-21 15:38 UTC
rendered paste body
#!/usr/bin/perl -w

# build_e_cvs - builds your E CVS code based on
# a dependency file. can be used to build any  
# other set of dep oriented apps too.
#
# Author: Hisham 'CodeWarrior' Mardam Bey
# <hisham@hisham.cc>
#
# TODO:
# (*)  --start arg, start at a certain point.
# (*)  resume / crash detection.

#################################
my $verbose = '>/dev/null 2>&1';
my $install;
my $help;
my $cvsco;
my $all;
my $oldcvs;
use strict;
use Cwd;
use Getopt::Long qw(:config bundling);
GetOptions('all|a' => \$all, 'cvsco|c' => \$cvsco, 'install|i' => \$install, 'oldcvs|o' => \$oldcvs, 'help|h' => \$help, 'verbose|v' => sub {$verbose =''; } ); 
#################################
########Global Variables#########
my $root_dir ="$ENV{HOME}/e17_cvs";
#Uncomment the cvs server you would like to use.
my $cvs_srv = qw(:pserver:anonymous@anoncvs.enlightenment.org:/var/cvs/e);
#my $cvs_srv = ":pserver:anonymous\@thinktux.net/root";
#my $cvs_srv = ":pserver:anonymous\@cvs.sourceforge.net:/cvsroot/enlightenment";
#my $cvs_srv = ":ext:devilhorns\@cvs.sourceforge.net:/cvsroot/enlightenment";     
# will fetch our cvs code
 sub cvscopart {

   #backup $root_dir

#	system("mv -f $root_dir ${root_dir}_bak"); 
   
	print "check out e17\n";

# Create $root_dir if it doesn't exist
   system("mkdir -p $root_dir");

   chdir("$root_dir") || die("Could not change to specified root: $root_dir/..");

   system("cvs -d $cvs_srv co e17");


	print "checkout complete\n";

	print "checkout misc\n";

	chdir("$root_dir/e17") || die("Could not change to specified root dir: $root_dir/e17");

	system("cvs -d $cvs_srv co misc");

	#(!$?) || die("Could not checkout misc\n");
	print "checkout complete\n";

	system("cvs -d $cvs_srv co e_modules");
#	(!$?) || die("Could not checkout e_modules\n");
	print "checkout complete\n";
}#end cvscopart

# main application logic here.
## Package used to hold apps and all of
## their associated commands.
###
package App;

#sub oldcvspart {
#	system("mv -f ${root_dir}_backup $root_dir");
#}#end oldcvspart

sub new {
    my $this = {};
    $this->{app}         = "";
    $this->{configure}   = "";
    $this->{make}        = "";
    $this->{makeinstall} = "";
    $this->{confparams}  = "";
    $this->{name}        = "";
    $this->{descr}       = "";
    $this->{dir}         = "";
    shift;
    if(@_ ==  8) {
	$this->{app}         = shift;
	$this->{dir}         = shift;
	$this->{configure}   = shift;
	$this->{make}        = shift;
	$this->{makeinstall} = shift;
	$this->{confparams}  = shift;
	$this->{name}        = shift;
	$this->{descr}       = shift;
    }
    bless $this;
    return $this;    
}
###
## Package to parse the config file containing
## the list of dependencies / apps.
###
package Parser; 

sub new {
    my $this = {};
    shift;
    my $conf_file = shift;
    my $delim = shift;
    my $i = 0;
    
    $this->{apps} = ();
    
    open(CFG,$conf_file) || die("Could not open configuration file: $conf_file\n");
    while(<CFG>) {
	chomp;
	next if $_ =~ /(^#)|(^\s*$)/;
	my $line = $_;
	my @fields = split /\|/,$line;
	$this->{apps}[$i++] = new App(@fields);
    }
	
    bless $this;
    return $this;
}

 package main;

# global configuration
our $debug = 1; # set to 0 for no messages.
my $parser = new Parser("deps","|");

# will write stuff to standard output
 sub debug {
    if($main::debug) {
	print shift;
    }
}

# will install from our root dir
    chdir("$root_dir/e17") || die("Could not change to specified root dir: $root_dir");
sub installpart {

    for (my $i = 0; $i < @{$parser->{apps}}; $i++) {
	my $app = $parser->{apps}[$i];
#    while( my($k,$v) = each (%{$app}) ) {
#	print "$k=$v","\n";
#    }
# >/dev/null 2>&1
	debug("Entering $root_dir/$app->{dir}\n");
	chdir("$root_dir/e17" . "/" . $app->{dir}) || die("Failed at $app->{name}: Could not enter $root_dir/$app->{dir}\n");
	### Temp hack to make clean
	# debug("Running make clean\n");
	# system("make clean $verbose");
	debug("Running ./$app->{configure} $app->{confparams}\n");
	(-e $app->{configure}) || die("Failed at $app->{name}: $app->{configure} not found.\n");
	system("./$app->{configure} $app->{confparams} $verbose");
	(!$?) || die("Failed at $app->{name}: Could not execute $app->{configure}\n");
	debug("Running $app->{make}\n");
	# (-e $app->{make}) || die("Failed at $app->{name}: $app->{make} not found.\n");
	system("$app->{make} $verbose");
	(!$?) || die("Failed at $app->{name}: Could not execute $app->{make}\n");
	# (-e $app->{makeinstall}) || die("Failed at $app->{name}: $app->{make} not found.\n");
	debug("Running $app->{makeinstall}\n");
	system("$app->{makeinstall} $verbose");
	(!$?) || die("Failed at $app->{name}: Could not execute $app->{makeinstall}\n");    
	unlink("/tmp/build_e_cvs.tmp");
	debug("Leaving $root_dir/$app->{dir}\n");
    }
}

if ($all)  
{
    &cvscopart;
    &installpart;
} 
elsif ($cvsco) 
{
    &cvscopart;
} 
elsif ($install)
{
	&installpart;
}
elsif ($oldcvs)
{
	&oldcvspart;
}
else 
{
    print <<EOF;
    
    Usage: `basename $0` [OPTIONS...]
    ==============OPTIONS================
      
    -h  --help      : This help message.
    -a  --all       : Update CVS & Install
    -i  --install   : Install without updating CVS.
    -c  --cvsco     : Update CVS.
    -o  --oldcvs    : Restores from backed up CVS dir.
    -v  --verbose   : If you don't know what this means you're a moron
EOF
}
exit;