#!/usr/bin/perl use strict; use POSIX; # config #my $BASE="/usr/src/redhat"; my $BASE="/home/ftp/rpm"; ########################################################################### my ($NAME,$VERSION,$PREFIX,$SOURCE,$DESC1,$DESC2,$COPY,$GROUP,$URL,$DOC); my (@PATCHES,$PATCH1,$PATCH2,$PREFIX); my (@files,@f,@tar,$src,$patch,$line,$i,$spec,$warn,$date,$setup); $|=1; $warn=0; $date=strftime("%a %b %d %Y",localtime(time)); # intro print <); print "What is version of the package? "; chomp($VERSION=<>); # look for files opendir DIR,"$BASE/SOURCES"; @files = grep(/$NAME/,readdir(DIR)); closedir DIR; print "\nThese files I've found in $BASE/SOURCES:\n"; foreach my $file (@files) { print "\t$file\n"; } print "\n"; # ask for src @f = grep (/(tgz|tar\.gz)$/,@files); $src = ""; $src = $f[0] if $#f == 0; print "What is the filename of the source [$src] ? "; $SOURCE = <>; chomp($SOURCE); $SOURCE = $src if $SOURCE eq ""; # check source open FILE, "tar tzf $BASE/SOURCES/$SOURCE |" or die "can't list $SOURCE"; @tar = ; close FILE; @f = grep /\.spec$/,@tar; if ($#f > -1) { print "Hey, this package comes with a spec file ($f[0])!\n"; print "\"rpm -ta $BASE/SOURCES/$SOURCE\" should work fine.\n"; exit; } @f = grep /configure.in/,@tar; if ($#f > -1) { print "Looks like this package uses autoconf. Good.\n"; } else { print "WARNING: The source package does'nt use autoconf.\n"; $warn++; } @f = sort { length($a) <=> length($b) } grep /Makefile.in/,@tar; if ($#f > -1) { chomp($f[0]); open FILE, "tar xzOf $BASE/SOURCES/$SOURCE $f[0] |"; while ($line = ) { if ($line =~ /(\w+)\s*=\s*\@prefix\@/) { print "$f[0]: $line"; print "using \"$1\" for installing into %{buildroot}\n"; $PREFIX="$1"; last; } } close FILE; if ($PREFIX !~ /\S/) { print "WARNING: couldn't figure out the prefix variable used in\n"; print " Makefile.in, trying \"prefix\"."; $PREFIX="prefix"; $warn++; } } else { print "WARNING: No Makefile.in found in the package.\n"; $PREFIX="prefix"; $warn++; } $SOURCE =~ s/$VERSION/%\{version\}/; @f = sort { length($a) <=> length($b) } @tar; if ($f[0] ne "$NAME-$VERSION/") { $setup = " -n $f[0]"; $setup =~ s/\/$//; $setup =~ s/$VERSION/%\{version\}/; } # look for doc files chomp($line = $tar[0]); @f = grep (/${line}[^\/]*$/,@tar); # top-level dir only @f = grep (!/Makefile/,@f); # no Makefiles @f = grep (/\/[A-Z]/,@f); # start with uppercase foreach my $f (@f) { $f =~ s/$line//; chomp($f); $DOC .= "$f " }; # ask for patches print "\n"; for (;;) { print "Any patches (enter filename or enter when done) ? "; chomp($patch = <>); last if $patch eq ""; $patch =~ s/$VERSION/%\{version\}/; push @PATCHES,$patch; } # ask for description print "\none-liner description? "; chomp($DESC1 = <>); # misc print "\nCopyright? "; chomp($COPY = <>); print "\nGroup? "; chomp($GROUP = <>); ########################################################################### # compose some strings $i = 0; foreach my $item (@PATCHES) { $PATCH1 .= "Patch$i: $item\n"; $PATCH2 .= "%patch$i -p1\n"; $i++; } ########################################################################### # write spec file $spec = "$BASE/SPECS/$NAME.spec"; open SPEC,">$spec" or die "open $spec: $!"; print SPEC < rpmlist %files -f rpmlist %defattr(-,root,root) #%doc $DOC %clean rm -rf \$RPM_BUILD_ROOT END_OF_SPEC close SPEC; print <, run make -n $PREFIX=/var/tmp/$NAME-$VERSION.root/usr install and look what the install stage would to. If it does'nt install to /var/tmp/$NAME-$VERSION.root, you'll have to fix Makefile.in and create a patch. If the install works fine, you might want tune the %install and %files section of the spec file a bit to create a nice RPM with doc files in /usr/doc and the like. If you plan to distribute the RPM's (upload to contrib for example), I _strongly_ suggest to do this. EOF exit;