Code

Moved check_plugins.pl and gen_plugin_deps.pl to debian/bin/.
[pkg-collectd.git] / debian / bin / gen_plugin_deps.pl
1 #!/usr/bin/perl
2 #
3 # collectd - gen_plugin_deps.pl
4 # Copyright (C) 2007 Sebastian Harl
5 #
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation; only version 2 of the License is applicable.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18 #
19 # Author:
20 #   Sebastian Harl <sh at tokkee.org>
22 use strict;
23 use warnings;
25 my $infile  = "debian/README.Debian.plugins.in";
26 my $outfile = "debian/README.Debian.plugins";
28 my ($ifile, $ofile);
30 if (! open($ifile, "<", $infile)) {
31         print STDERR "Could not open file '$infile': $!\n";
32         exit 1;
33 }
35 if (! open($ofile, ">", $outfile)) {
36         print STDERR "Could not open file '$outfile': $!\n";
37         exit 1;
38 }
40 while (my $line = <$ifile>) {
41         if ($line !~ m/^\@PLUGIN_DEPS\@\n$/) {
42                 print $ofile $line;
43         }
44         else {
45                 print_plugin_deps($ofile);
46         }
47 }
49 close($ofile);
50 close($ifile);
52 sub print_plugin_deps
53 {
54         my $fh   = shift;
55         my $pdir = undef;
56         my $i    = 0;
58         my $plugindir = "debian/collectd/usr/lib/collectd/";
60         if (! opendir($pdir, $plugindir)) {
61                 print STDERR "Could not open directory '$plugindir': $!\n";
62                 exit 1;
63         }
65         foreach my $dirent (sort readdir($pdir)) {
66                 if ($dirent !~ m/^(\w+).so$/) {
67                         next;
68                 }
70                 my $name = $1;
71                 my $deps = `dpkg-shlibdeps -O $plugindir/$dirent`;
73                 chomp $deps;
75                 $deps =~ s/^shlibs:Depends=//;
77                 my @deps = grep !m/^libc6\b/, split m/, /, $deps;
79                 if (scalar @deps) {
80                         if (0 < $i) {
81                                 print $fh "\n";
82                         }
84                         ++$i;
86                         print $fh "$name:\n";
87                         foreach my $dep (@deps) {
88                                 print $fh " * $dep\n";
89                         }
90                 }
91         }
92 }
94 # vim: set tw=78 sw=4 ts=4 noexpandtab :