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 $extra_deps = {
26 sensors => [ 'lm-sensors' ],
27 };
29 my $infile = "debian/README.Debian.plugins.in";
30 my $outfile = "debian/README.Debian.plugins";
32 my ($ifile, $ofile);
34 if (! open($ifile, "<", $infile)) {
35 print STDERR "Could not open file '$infile': $!\n";
36 exit 1;
37 }
39 if (! open($ofile, ">", $outfile)) {
40 print STDERR "Could not open file '$outfile': $!\n";
41 exit 1;
42 }
44 while (my $line = <$ifile>) {
45 if ($line !~ m/^\@PLUGIN_DEPS\@\n$/) {
46 print $ofile $line;
47 }
48 else {
49 print_plugin_deps($ofile);
50 }
51 }
53 close($ofile);
54 close($ifile);
56 sub print_plugin_deps
57 {
58 my $fh = shift;
59 my $pdir = undef;
60 my $i = 0;
62 my $plugindir = "debian/collectd/usr/lib/collectd/";
64 if (! opendir($pdir, $plugindir)) {
65 print STDERR "Could not open directory '$plugindir': $!\n";
66 exit 1;
67 }
69 foreach my $dirent (sort readdir($pdir)) {
70 if ($dirent !~ m/^(\w+).so$/) {
71 next;
72 }
74 my $name = $1;
75 my $deps = `dpkg-shlibdeps -O $plugindir/$dirent`;
77 chomp $deps;
79 $deps =~ s/^shlibs:Depends=//;
81 my @deps = grep !m/^libc6\b/, split m/, /, $deps;
83 if (scalar @deps) {
84 if (0 < $i) {
85 print $fh "\n";
86 }
88 ++$i;
90 print $fh "$name:\n";
92 if (defined $extra_deps->{$name}) {
93 unshift @deps, @{$extra_deps->{$name}};
94 }
96 foreach my $dep (@deps) {
97 print $fh " * $dep\n";
98 }
99 }
100 }
101 }
103 # vim: set tw=78 sw=4 ts=4 noexpandtab :