4 # Automatic generation of BuildRequires dependencies for rpmbuild.
5 # Copyright (C) 2008 Red Hat Inc.
6 # Written by Richard W.M. Jones <rjones@redhat.com>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 use String::ShellQuote;
25 use File::Temp qw(tempfile);
28 die "auto-br-analyze: logfile parameter missing\n";
33 my $homedir = $ENV{HOME};
35 open LOG, "<$ARGV[0]" or die ($ARGV[0], ": $!\n");
38 if (/^(open|execve) (.+)/) {
41 # Ignore files which don't exist, and files located in some
42 # places we ignore (eg. under $HOME).
43 my ($dev, $ino, $mode) = stat $file;
44 next unless defined $dev;
45 next if $homedir && $file =~ /^$homedir/;
47 # ./configure opens every file in /etc/ld.so.conf, pulling
48 # in lots of false dependencies.
49 next if $file =~ m{^/etc/ld\.so\.conf\.d/.*\.conf$};
57 # Work out which RPM packages are used. Note we don't care about
58 # which specific file is owned by which specific package, which allows
59 # us to do a lot of nice shell magic for the hard work here.
62 my ($fh, $filename) = tempfile ();
67 "rpm -q --qf '%{name} %{epoch} %{version} %{release} %{arch}\n' -f ".
69 "grep -v '^file.*is not owned by any package\$' | ".
70 "grep -v '^error:' | ".
71 "sort -u > $filename";
72 open PIPE, "| $cmd" or die "$cmd: $!";
73 print PIPE "$_\0" foreach (sort keys %files);
77 if (/^(\S+) (\d+|\(none\)) (\S+) (\S+) (\S+)$/) {
78 my ($rpm, $epoch, $version, $release, $arch) =
80 $epoch = "0" if $epoch eq "(none)";
83 epoch => $epoch, version => $version, release => $release,
91 # Print the list of BuildRequires.
95 my $epoch = $_->{epoch};
96 my $version = $_->{version};
97 my $release = $_->{release};
98 my $arch = $_->{arch};
100 # Ignore 'rpm', 'rpm-build' and a few others which are introduced
101 # by the rpmbuild system itself.
102 next if $rpm eq "rpm" || $rpm eq "rpm-build" || $rpm eq "python"
103 || $rpm eq "redhat-rpm-config";
105 print "BuildRequires: $rpm = ";
109 print "$version.$release.$arch\n";