home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 March / PCWELT_3_2006.ISO / base / 05_common.mo / usr / lib / rpm / cpanflute2 < prev    next >
Encoding:
Text File  |  2003-10-29  |  4.2 KB  |  161 lines

  1. #!/usr/bin/perl -w
  2. use strict;
  3.  
  4. use Getopt::Long;
  5. use File::Basename;
  6. use File::Copy;
  7. use Archive::Tar;
  8.  
  9. use lib '/usr/lib/rpm';
  10. use Specfile;
  11.  
  12. my %options;
  13.  
  14. GetOptions(\%options, "outdir=s", "tmpdir=s", "email=s", "name=s", "create", "test", "epoch=n", "version=s", "release=s", "perlver=s", "patch=s", "noarch=s") or die_usage();
  15.  
  16. my $fullname = shift;
  17.  
  18. die_usage() unless $fullname;
  19.  
  20. my $tarball = basename($fullname);
  21. my $create = $options{create} || '';
  22. my $email = $options{email} || (getpwuid($<))[0] . '@redhat.com';
  23. my $outdir = $options{outdir} || './';
  24. my $tmpdir = $options{tmpdir} || '/tmp';
  25. my $noarch = $options{noarch};
  26.  
  27. $tarball =~ /^(.+)\-([^-]+)\.tar\.gz$/;
  28. my $name = $options{name} || $1;
  29. my $ver = $options{version} || $2;
  30.  
  31. die "Module name/version not parsable from $tarball" unless $name and $ver;
  32.  
  33. $name =~ s/::/-/g;
  34.  
  35. copy($fullname, $tmpdir)
  36.   or die "copy: $!";
  37.  
  38. $noarch = $options{noarch};
  39.  
  40. my $patchfile = '';
  41. if ($options{patch}) {
  42.   copy($options{patch}, $tmpdir);
  43.   $patchfile = $options{patch};
  44. }
  45.  
  46. my $spec = new RPM::Specfile;
  47.  
  48. my $perlver = "0:5.00503";
  49. if ($options{perlver} and $options{perlver} eq '5.6.1') {
  50.   $perlver = "1:5.6.1";
  51. }
  52.  
  53. # some basic spec fields
  54. $spec->name("perl-$name");
  55. $spec->version($ver);
  56. $spec->release($options{release} || "8");
  57. $spec->epoch($options{epoch});
  58. $spec->summary("$name Perl module");
  59. $spec->description($spec->summary);
  60. $spec->group("Development/Libraries");
  61. $spec->license("distributable");
  62. $spec->buildrequires("perl >= $perlver");
  63. $spec->packager($email);
  64. $spec->add_changelog_entry($email, 'Specfile autogenerated');
  65.  
  66. $spec->buildarch('noarch') if $noarch;
  67.  
  68. # $spec->push_require(q|%(perl -MConfig -le 'if (defined $Config{useithreads}) { print "perl(:WITH_ITHREADS)" } else { print "perl(:WITHOUT_ITHREADS)" }')|);
  69. # $spec->push_require(q|%(perl -MConfig -le 'if (defined $Config{usethreads}) { print "perl(:WITH_THREADS)" } else { print "perl(:WITHOUT_THREADS)" }')|);
  70. # $spec->push_require(q|%(perl -MConfig -le 'if (defined $Config{uselargefiles}) { print "perl(:WITH_LARGEFILES)" } else { print "perl(:WITHOUT_LARGEFILES)" }')|);
  71.  
  72. $spec->push_source($tarball);
  73. $spec->push_patch(basename($patchfile))
  74.   if $patchfile;
  75.  
  76. # make a URL that can actually possibly take you to the right place
  77. my $url_name = $name;
  78. $url_name =~ s/-/::/g;
  79. $url_name =~ s/([^a-zA-Z0-9])/sprintf "%%%x", ord $1/ge;
  80. $spec->url("http://search.cpan.org/search?mode=module&query=$url_name");
  81.  
  82. # now we get into the multiline tags.  stolen mostly verbatim from
  83. # cpanflute1
  84.  
  85. my $patch = '';
  86. if ($patchfile) {
  87.   $patch = "%patch0 -p1\n";
  88. }
  89.  
  90. $spec->prep("%setup -q -n $name-%{version} $create\n$patch");
  91. $spec->file_param("-f $name-$ver-filelist");
  92. $spec->push_file("%defattr(-,root,root)");
  93.  
  94. my $test_clause = '';
  95. $test_clause = "make test" if $options{test};
  96.  
  97. $spec->build(<<EOB);
  98. CFLAGS="\$RPM_OPT_FLAGS" perl Makefile.PL
  99. make
  100. $test_clause
  101. EOB
  102.  
  103. $spec->clean('rm -rf $RPM_BUILD_ROOT');
  104. my $inst = q{
  105. rm -rf $RPM_BUILD_ROOT
  106. eval `perl '-V:installarchlib'`
  107. mkdir -p $RPM_BUILD_ROOT/$installarchlib
  108. make PREFIX=$RPM_BUILD_ROOT/usr install
  109.  
  110. [ -x /usr/lib/rpm/brp-compress ] && /usr/lib/rpm/brp-compress
  111.  
  112. find $RPM_BUILD_ROOT/usr -type f -print | \
  113.     sed "s@^$RPM_BUILD_ROOT@@g" | \
  114.     grep -v perllocal.pod | \
  115.     grep -v "\.packlist" > $name-$ver-filelist
  116. if [ "$(cat $name-$ver-filelist)X" = "X" ] ; then
  117.     echo "ERROR: EMPTY FILE LIST"
  118.     exit -1
  119. fi
  120. };
  121.  
  122. $inst =~ s/\$name/$name/g;
  123. $inst =~ s/\$ver/$ver/g;
  124.  
  125. $spec->install($inst);
  126.  
  127. # write the spec file.  create some macros.
  128. $spec->write_specfile("$tmpdir/perl-$name.spec");
  129.  
  130. open FH, ">$tmpdir/macros"
  131.   or die "Can't create $tmpdir/macros: $!";
  132.  
  133. print FH qq{
  134. %_topdir        $tmpdir
  135. %_builddir      %{_topdir}
  136. %_rpmdir        %{_topdir}
  137. %_sourcedir     %{_topdir}
  138. %_specdir       %{_topdir}
  139. %_srcrpmdir     $outdir
  140. };
  141.  
  142. close FH;
  143.  
  144. open FH, ">$tmpdir/rpmrc"
  145.   or die "Can't create $tmpdir/rpmrc: $!";
  146.  
  147. print FH qq{
  148. include: /usr/lib/rpm/rpmrc
  149. macrofiles: /usr/lib/rpm/macros:$tmpdir/macros
  150. };
  151. close FH;
  152.  
  153. # perform the build, die on error
  154. my $retval = system "rpm --rcfile $tmpdir/rpmrc -bs --rmsource --rmspec --clean $tmpdir/perl-$name.spec";
  155. $retval = $? >> 8;
  156. if ($retval != 0) {
  157.   die "RPM building failed!\n";
  158. }
  159.  
  160. unlink "$tmpdir/rpmrc", "$tmpdir/macros";
  161.