home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 July / Chip_2003-07_cd2.bin / misc / gendistrib < prev    next >
Text File  |  2003-03-13  |  5KB  |  137 lines

  1. #!/usr/bin/perl
  2.  
  3. #- Copyright (C) 1999 MandrakeSoft (fpons@mandrakesoft.com)
  4. #-
  5. #- This program is free software; you can redistribute it and/or modify
  6. #- it under the terms of the GNU General Public License as published by
  7. #- the Free Software Foundation; either version 2, or (at your option)
  8. #- any later version.
  9. #-
  10. #- This program is distributed in the hope that it will be useful,
  11. #- but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #- GNU General Public License for more details.
  14. #-
  15. #- You should have received a copy of the GNU General Public License
  16. #- along with this program; if not, write to the Free Software
  17. #- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18.  
  19. use strict;
  20. use URPM;
  21. use URPM::Build;
  22.  
  23. my $urpm = new URPM;
  24. my ($noclean, $nohdlists, $nobasefiles, @root, @hdlists) = (0, 0, 0);
  25.  
  26. ($noclean,     @ARGV) = @ARGV if $ARGV[0] eq "--noclean";
  27. (undef, @root, @ARGV) = @ARGV if $ARGV[0] eq "--distrib";
  28.  
  29. @root > 0 && @ARGV == 0 or die "usage: gendistrib [--noclean] --distrib <root distrib> <root_distrib2> ...\n";
  30.  
  31. my $root = $root[0];
  32. my ($depslist, $provides, $compss, $hdlists) = ("$root/Mandrake/base/depslist.ordered",
  33.                         "$root/Mandrake/base/provides",
  34.                         "$root/Mandrake/base/compss",
  35.                         "$root/Mandrake/base/hdlists");
  36.  
  37. open F, $hdlists or die "unable to open $hdlists";
  38. foreach (<F>) {
  39.     chomp;
  40.     s/\s*#.*$//;
  41.     /^\s*$/ and next;
  42.     m/^\s*(?:noauto:)?(hdlist\S*\.cz2?)\s+(\S+)\s*(.*)$/ or die "invalid hdlist description \"$_\" in hdlists file";
  43.  
  44.     push @hdlists, { synthesis => "$root/Mandrake/base/synthesis.$1", hdlist => "$root/Mandrake/base/$1", dir => $2, descr => $3 };
  45. }
  46. close F;
  47.  
  48. my $headers_dir = ($ENV{TMPDIR} || "/tmp") . "/.build_hdlist";
  49. sub clean_cache {
  50.     system($ENV{LD_LOADER} ? $ENV{LD_LOADER} : @{[]}, "rm", "-rf", $headers_dir) unless $noclean;
  51. }
  52.  
  53. clean_cache();
  54.  
  55. foreach (0..$#hdlists) {
  56.     my $e = $hdlists[$_];
  57.     my $r;
  58.  
  59.     #- try to find the right repository where can be found the directory
  60.     #- listed in the hdlist file.
  61.     #- if the number of root is equal the number of medium, assume a medium
  62.     #- foreach root, else try to find a valid root containing the medium.
  63.     if (scalar(@hdlists) == scalar(@root)) {
  64.     $r = $root[$_];
  65.     } else {
  66.     foreach (@root) {
  67.         -d "$_/$e->{dir}" and $r = $_, last;
  68.     }
  69.     }
  70.     -d "$r/$e->{dir}" or die "unable to find a valid root directory which contains $e->{dir}\n";
  71.  
  72.     print STDERR "parsing rpm files in directory $r/$e->{dir}\n";
  73.     my @headers = $urpm->parse_rpms_build_headers(dir  => $headers_dir,
  74.                           rpms => [ glob("$r/$e->{dir}/*.rpm") ]);
  75.     $e->{headers} = \@headers;
  76. }
  77.  
  78. #- clean everything to start second pass.
  79. print STDERR "clean data for second pass\n";
  80. $urpm->unresolved_provides_clean;
  81.  
  82. foreach (0..$#hdlists) {
  83.     my $e = $hdlists[$_];
  84.  
  85.     print STDERR "parsing headers for $e->{descr}\n";
  86.     my ($start, $end) = $urpm->parse_headers(dir     => $headers_dir,
  87.                          headers => $e->{headers});
  88.  
  89.     print STDERR "computing deps\n";
  90.     $urpm->compute_deps;
  91.  
  92.     print STDERR "building hdlist for medium \"$e->{descr}\"\n";
  93.     $urpm->build_hdlist(start  => $start,
  94.             end    => $end,
  95.             dir    => $headers_dir,
  96.             hdlist => $e->{hdlist},
  97.             ratio  => 9);
  98.  
  99.     print STDERR "building synthesis for medium \"$e->{descr}\n";
  100.     $urpm->build_synthesis(start     => $start,
  101.                end       => $end,
  102.                synthesis => $e->{synthesis});
  103. }
  104.  
  105. clean_cache();
  106.  
  107. print STDERR "building base files\n";
  108. $urpm->build_base_files(depslist => "$root/Mandrake/base/depslist.ordered",
  109.             provides => "$root/Mandrake/base/provides",
  110.             compss   => "$root/Mandrake/base/compss");
  111.  
  112. #- check if there are NOTFOUND in dependancy, check if they are in other medium, warn the user.
  113. foreach (0 .. $#{$urpm->{depslist}}) {
  114.     my $pkg = $urpm->{depslist}[$_];
  115.  
  116.     foreach (split " ", $urpm->{deps}[$_]) {
  117.     /NOTFOUND_(.*)/ or next;
  118.     print STDERR $pkg->fullname . " requires [$1] which\n";
  119.     if ($urpm->{provides}{$1}) {
  120.         print STDERR "  is available on packages not listed in this medium or previous medium:\n";
  121.         foreach (keys %{$urpm->{provides}{$1}}) {
  122.         my $dep_pkg = $urpm->{depslist}[$_];
  123.         print STDERR "    " . $dep_pkg->fullname . "\n";
  124.         }
  125.     } else {
  126.         print STDERR "  is not available in any medium listed\n";
  127.         if (/NOTFOUND_(\D*)(\d+[\.\-\d]*)?(.*)?\.so\./) {
  128.         my $re = (quotemeta $1) . '(\d+[\.\-\d]*)' . (!$2 && "?") . '\.so\.';
  129.         foreach (keys %{$urpm->{provides}}) {
  130.             /$re/ or next;
  131.             print STDERR "  but a similar provides is available as [$_], need rebuild ?\n";
  132.         }
  133.         }
  134.     }
  135.     }
  136. }
  137.