Merge branch 'master' of mathias-kettner.de:omd
[omd.git] / packages / perl-modules / sort_modules
blobe9246fb76068d2e1ba1536bec66ce3a07b33b1cb
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 delete $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 next if $file =~ m/^ExtUtils\-MakeMaker\-\d+/mx;
27 next if $file =~ m/^parent\-\d+/mx;
28 next if $file =~ m/^version\-\d+/mx;
29 next if $file =~ m/^Module\-CoreList\-\d+/mx;
30 next if $file =~ m/^JSON\-/mx;
31 next if $file =~ m/^Types\-Serialiser\-\d+/mx;
32 next if $file =~ m/^common\-sense\-\d+/mx;
33 printf $out " %s \\\n", $file;
35 printf $out " %s\n", $last if defined $last;
36 print $out "\n";
37 $found = 1;
39 if($found) {
40 $found = 0 if $line =~ m/^\s*$/;
41 } else {
42 print $out $line;
45 close($out);
46 close($in);
47 `mv Makefile.new Makefile`;
48 print "Makefile written\n";
49 } else {
50 print "MODULES = \\\n";
51 for my $file (@{$sorted}) {
52 printf " %s \\\n", $file;
54 printf " %s\n", $last if defined $last;
55 print "\n\nuse -u to update Makefile automatically\n";
57 exit;