perl-modules: Added Monitoring-Plugin module
[omd.git] / packages / perl-modules / sort_modules
blob57ef13c4d4037d46bf9c3c4447b800c60780eaaf
1 #!/usr/bin/perl
3 use warnings;
4 use strict;
5 use lib 'lib';
6 use BuildHelper;
8 BEGIN {
9 for my $val (qw/PERL5LIB PERL_MB_OPT PERL_LOCAL_LIB_ROOT PERL_MM_OPT/) {
10 undef $ENV{$val} if defined $ENV{$val};
14 my($deps,$files) = BuildHelper::get_all_deps();
15 my $sorted = BuildHelper::sort_deps($deps, $files);
16 my $last = pop @{$sorted};
17 alarm(5);
18 if(defined $ARGV[0] and $ARGV[0] eq '-u') {
19 open(my $out, '>', 'Makefile.new') or die("cannot open Makefile.new: $!");
20 open(my $in, '<', 'Makefile') or die("cannot open Makefile: $!");
21 my $found = 0;
22 while(my $line = <$in>) {
23 if($line =~ m/^MODULES\s=/) {
24 print $out "MODULES = \\\n";
25 for my $file (@{$sorted}) {
26 printf $out " %s \\\n", $file;
28 printf $out " %s\n", $last if defined $last;
29 print $out "\n";
30 $found = 1;
32 if($found) {
33 $found = 0 if $line =~ m/^\s*$/;
34 } else {
35 print $out $line;
38 close($out);
39 close($in);
40 `mv Makefile.new Makefile`;
41 print "Makefile written\n";
42 } else {
43 print "MODULES = \\\n";
44 for my $file (@{$sorted}) {
45 printf " %s \\\n", $file;
47 printf " %s\n", $last if defined $last;
48 print "\n\nuse -u to update Makefile automatically\n";
50 exit;