#!/usr/bin/perl ############################################################################## # Copyright (C) 2008 Paulo Cesar Pereira de Andrade. All Rights Reserved. # # This is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This software is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # Authors: # Paulo Cesar Pereira de Andrade ############################################################################## use Cwd; use strict; ############################################################################## # From xorg-build.pl ############################################################################## sub git_config { my ($option) = @_; $option = `git-config --global --get $option`; $option =~ s/^\s+//; $option =~ s/\s+$//; return $option; }; my $x_depsdir = git_config("xorg-git.deps-dir"); $x_depsdir = "/usr/local/xorg/deps" unless ($x_depsdir); $x_depsdir = Cwd::realpath($x_depsdir); ############################################################################## # End From xorg-build.pl ############################################################################## ############################################################################## my %database; sub load_database { my ($name); foreach $name (split('\n', `find $x_depsdir -type f -a -name \\*.files`)) { $name = Cwd::realpath($name); open(DATA, "<$name") or die("Cannot read $name ($!)"); $name =~ s/^$x_depsdir\///; $name =~ s/\.files$//; while () { chomp; if ($database{$_}) { # Just in case two packages installed a file with the same name print(STDERR " ** File $database{$_}:$_ also owned by $name\n"); } $database{$_} = $name; } close(DATA); } }; # Do it load_database(); ############################################################################## my %dependencies; sub build_dependencies { my ($name, $depend); foreach $name (split('\n', `find $x_depsdir -type f -a -name \\*.deps`)) { $name = Cwd::realpath($name); open(DATA, "<$name") or die("Cannot read $name ($!)"); $name =~ s/^$x_depsdir\///; $name =~ s/\.deps$//; # Just in case it has no dependencies, so output will be made to tsort push(@{$dependencies{$name}}, $name); while ($depend = ) { chomp($depend); if ($database{$depend}) { $depend = $database{$depend}; unless (grep($_ eq $depend, @{$dependencies{$name}})) { push(@{$dependencies{$name}}, $depend); } } else { # XXX This may have been caused by some rename, link/unlink, # or the like during install. If it happens, xorg-trace.pl # needs some extra handling. print(STDERR " ** $name requires $depend not owned by any module\n"); } } close(DATA); } }; # Do it build_dependencies(); ############################################################################## sub print_build_order { my ($module, $depend); # This works for the needs of this script, but some special # handling on descriptors is required if not using a temp file # and filtering of output is required. open(TSORT, "| tsort | tac 2>&1") or die("tsort|tac: ($!)."); foreach $module (keys %dependencies) { foreach $depend (@{$dependencies{$module}}) { print(TSORT "$module $depend\n"); } } close(TSORT); }; # Do it again print_build_order();