App-CPANtoRPM
view release on metacpan or search on metacpan
lib/App/CPANtoRPM.pm view on Meta::CPAN
"http://search.cpan.org/authors/id/$package{cpandir}/$package{archive}" :
$package{'fromsrc'} );
foreach my $key (keys %{ $Macros{$$self{'macros'}} }) {
my $val = $Macros{$$self{'macros'}}{$key};
$package{$key} = $val;
}
#
# Find out if there are is a post-build script.
#
$self->_post_build();
#
# Make sure we can run rpm.
#
my $cmd = 'rpm --version > /dev/null';
$self->_log_message('INFO',"Attempting system command: $cmd");
if (system($cmd) != 0) {
$self->_log_message('ERR','Unable to run rpm.');
}
#
# Make sure that the RPM build hierarchy exists.
#
$self->_check_rpm_build();
$self->_log_message('INFO',
"SPEC file: $package{topdir}/SPECS/$package{specname}");
#
# Every package needs a packager.
#
if ($$self{'packager'}) {
$package{'packager'} = $$self{'packager'};
} else {
my $tmp = `rpm --eval '\%packager'`;
chomp($tmp);
if (! $tmp || $tmp eq "\%packager") {
$self->_log_message('ERR','%packager not defined in ~/.rpmmacros.',
'Add it or use the --packager option.');
}
$package{'packager'} = $tmp;
}
#
# Some values may contain email addresses which might be of the form:
# Name <Email>
# and the brackets <> conflict with the SPEC file templated.
#
# The values where this can occur are:
# args : this is already taken care of (< was turned to \<)
# packager : a single value
# author : multiple values
#
# We need to escape the brackets in the unhandled cases.
#
foreach my $val ($package{'packager'},@{ $package{'author'} }) {
$val =~ s/</\\</g;
$val =~ s/>/\\>/g;
}
#
# Start spec file creation...
#
$self->_log_message('INFO',
"Spec file: $package{topdir}/SPECS/$package{specname}");
my $out = new IO::File;
$out->open("> $package{topdir}/SPECS/$package{specname}") ||
$self->_log_message('ERR',
"Unable to create spec file: $package{specname}: $!");
#
# The SPEC file is a stored in the __DATA__ section of this script.
#
my @tmp = <DATA>;
chomp(@tmp);
my @lines;
# @stack contains listrefs:
# [ KEEP, END_STRING, TOGGLE_STRING ]
# KEEP is 1 if we're using these lines.
# When a line is found with END_STRING, the structure ends.
# When a line is foud with TOGGLE_STRING, KEEP is toggled.
my(@stack) = ();
LINE:
while (@tmp) {
my $line = shift(@tmp);
last if ($line eq '<eof>');
# If we're currently in an <if> <else> <endif> conditional, look
# for <else> and <endif>.
if (@stack) {
my($keep,$end,$toggle) = @{ $stack[$#stack] };
if ($line =~ /$end/) {
pop(@stack);
next LINE;
} elsif ($line =~ /$toggle/) {
$stack[$#stack][0] = 1 - $keep;
next LINE;
}
next LINE if (! $keep);
}
# Set up a new:
# <if:VAR>
# structure.
( run in 2.186 seconds using v1.01-cache-2.11-cpan-98e64b0badf )