2
0
mirror of https://github.com/xcat2/xcat-dep.git synced 2024-11-23 10:01:46 +00:00
xcat-dep/cpio/bldcpio.pl
xq2005 2efadc56cf build cpio-lang 2.11-20 on sles 10
Former-commit-id: e6ddc4ade4f51a0ce08e074ca1a7b7c7e7fcbb16
2013-05-29 14:55:20 +00:00

118 lines
2.5 KiB
Perl
Executable File

#! /usr/bin/perl
# install pkg for build: gcc, openssl-dev, glibc-devel
use File::Find;
#check the distro
$cmd = "cat /etc/*release";
@output = `$cmd`;
my $os;
if (grep /Red Hat Enterprise Linux Server release 5\.\d/, @output) {
$os = "rh5";
} elsif (grep /Red Hat Enterprise Linux Server release 6\.\d/, @output) {
$os = "rh6";
} elsif (grep /SUSE Linux Enterprise Server 10/, @output) {
$os = "sles10";
} elsif (grep /SUSE Linux Enterprise Server 11/, @output) {
$os = "sles11";
} elsif (grep /Fedora release/, @output) {
$os = "fedora";
} else {
print "unknow os\n";
exit 1;
}
$cmd = "uname -p";
my $arch = `$cmd`;
chomp($arch);
$arch =~ s/i686/i386/;
print "The build env is: $os-$arch\n";
# check the source files
my $pwd = `pwd`;
chomp($pwd);
if (! -f "$pwd/cpio-2.11.tar.bz2"){
print "missed some necessary files for building.\n";
exit 1;
}
my $blddir;
my $specprefix;
if ($os eq "rh5") {
$blddir = "/usr/src/redhat";
} elsif ($os eq "rh6" || $os eq "fedora") {
$blddir = "/root/rpmbuild";
} elsif ($os =~ /sles1\d/) {
$blddir = "/usr/src/packages";
$specprefix = "sles";
}
#&runcmd("mkdir -p $blddir/SOURCES");
#&runcmd("mkdir -p $blddir/SPECS");
#&runcmd("mkdir -p $blddir/BUILD");
#&runcmd("mkdir -p $blddir/RPMS");
# clean the env
$cmd = "rm -rf $blddir/SOURCES/cpio*";
&runcmd($cmd);
$cmd = "rm -rf $blddir/SPECS/cpio*";
&runcmd($cmd);
$cmd = "rm -rf $blddir/BUILD/cpio*";
&runcmd($cmd);
$cmd = "rm -rf $blddir/RPMS/$arch/cpio*";
&runcmd($cmd);
# copy the build files
$cmd = "cp -rf ./cpio-2.11.tar.bz2 $blddir/SOURCES/";
&runcmd($cmd);
$cmd = "cp -rf ./*.patch $blddir/SOURCES/";
&runcmd($cmd);
$cmd = "cp -rf ./*.1 $blddir/SOURCES/";
&runcmd($cmd);
$cmd = "cp -rf ./${specprefix}cpio.spec $blddir/SPECS/cpio.spec";
&runcmd($cmd);
$cmd = "rpmbuild -bb $blddir/SPECS/cpio.spec";
&runcmd($cmd);
my $objrpm = "";
my @rpm = `find $blddir/RPMS/$arch/ -name "cpio-2.11-20*rpm"`;
my $dstdir = "/tmp/build/$os/$arch";
# check the build result
if ( @rpm == 0 ) {
print "The rpm file was not generated successfully\n";
exit 1;
} else {
$cmd = "mkdir -p $dstdir";
&runcmd ($cmd);
$cmd = "cp -rf $blddir/RPMS/$arch/cpio*rpm $dstdir";
&runcmd ($cmd);
print "The obj file has been built successfully, you can get it here: $dstdir\n";
exit 0;
}
sub runcmd () {
my $cmd = shift;
print "++++Trying to run command: [$cmd]\n";
my @output = `$cmd`;
if ($?) {
print "A error happened when running the comamnd [$cmd]\n";
print "error message: @output\n";
exit 1;
}
if ($verbose) {
print "run cmd message: @output\n";
}
}