#!/usr/bin/perl -w #******************************************************************************* #* Name : buildp4rpm.pl #* Description : Build an RPM based on the latest versions of p4 and #* p4d on Perforce's FTP site. #* #* Syntax : buildp4rpm.pl --rpmroot #* [--tarball ] #* [--specfile ] #* [--ftp] #* #* Default behaviour is to build the RPM and SRPM based on the current #* versions of p4 and p4d which it will find in the PATH. With the --ftp #* flag, this script will download the latest binary from the Perforce #* FTP site (currently this is Release 2000.1). #* #******************************************************************************* use Net::FTP; use Getopt::Long; use File::Copy; use Carp; use strict; use vars qw( $SPECFILE $TMPFILE $FTPHOST $P4_FTP_PATH $P4D_FTP_PATH $EMAIL_ADDRESS $TARBALL ); #******************************************************************************* #* Configuration section #******************************************************************************* $SPECFILE="p4.spec"; $TMPFILE="p4.spec.tmp"; $TARBALL="p4.tar.gz"; $FTPHOST="ftp.perforce.com"; $P4_FTP_PATH="/pub/perforce/r00.1/bin.linux52x86/p4"; $P4D_FTP_PATH="/pub/perforce/r00.1/bin.linux52x86/p4d"; $EMAIL_ADDRESS="someone\@somewhere.com"; sub croaksyntax() { print < [--tarball ] [--specfile ] [--ftp] where: --tarball - Path to p4.tar.gz tarball containing the RPM support files. --rpmroot - Path to RPM build root directory. This script will place all the files required to build the RPM in the build tree. --ftp - Causes the latest builds to be downloaded from the Perforce FTP site prior to editing the spec file. If not specified, then the binaries in the PATH are used. --specfile - Specifies the name of the specfile to edit. If not specified, then defaults to $SPECFILE. EOF exit( 0 ); } sub GetFile( $ ) { my $file = shift; print( "Fetching file $file from $FTPHOST ...\n" ); my $ftp = new Net::FTP( "$FTPHOST" ); $ftp->login( "anonymous", $EMAIL_ADDRESS ) or croak( "Failed to login to $FTPHOST. Download aborted." ); $ftp->get( "$file" ) or croak( "Failed to download file: $file." ); } sub GetVersInfo( $ ) { my $file = shift; my $version; my $build; open( FH, "$file -V |" ) or croak( "Can't execute $file to work out it's version" ); while ( ) { if ( /^Rev. P4D?\/\w+\/([\d\.]+)\/(\d+)/ ) { $version = $1; $build = $2; } } close( FH ); return ( $version, $build ); } sub EditSpec( $$$ ) { my $version = shift; my $server_build = shift; my $client_build = shift; open( IN, "$SPECFILE" ) or croak( "Cannot open $SPECFILE for reading" ); open( OUT, ">$TMPFILE" ) or croak( "Cannot open $TMPFILE for writing" ); my $seen_client = 0; while ( ) { if ( /^Version:/ ) { print( OUT "Version: $version\n" ); } elsif ( /^Release:\s*(\d+)/ ) { if ( $seen_client ) { print( OUT "Release: $client_build\n" ); } else { print( OUT "Release: $server_build\n" ); } } else { print( OUT $_ ); } if ( /^\%package.*p4-client/ ) { $seen_client = 1; } } close( IN ); close( OUT ); rename( $SPECFILE, "$SPECFILE.bck" ); rename( $TMPFILE, $SPECFILE ); } #******************************************************************************* #* Start of main script #******************************************************************************* # Check command line my $use_ftp = ''; my $p4_path = "p4"; my $p4d_path = "p4d"; my $rpmroot = ""; GetOptions( 'rpmroot=s' => \$rpmroot, 'tarball=s' => \$TARBALL, 'specfile=s' => \$SPECFILE, 'ftp' => \$use_ftp ); # RPM root is mandatory if ( $rpmroot eq "" ) { croaksyntax(); } # Ensure that we can see the p4 tarball if ( ! -f $TARBALL ) { print <