#!/usr/bin/perl # Ok so to build the subdir, get the top level then the actual entries missing... # the nice 'checksubdirs' make target will help a lot! use strict; use warnings; use Data::Dumper; START: my $top = ''; my %missing = (); my %toremove = (); my @categories = (); open MAKE, "make checksubdirs |" or die "Unable to execute make checksubdir!\n"; warn "Reading makefiles....\n"; while() { chomp; if (/^===>\s+(.*)$/) { warn "$_\n"; $top = $1; push(@categories, $top); next; } if (/^Warning:\s+directory\s+(.*)\s+not\s+in\s+SUBDIR$/) { $missing{$top} = [] if not exists $missing{$top}; push($missing{$top}, $1); next; } if (/^Warning:\s+directory\s+(.*)\s+in\s+SUBDIR\s+does\s+not\s+exist$/) { $toremove{$top} = [] if not exists $toremove{$top}; push($toremove{$top}, $1); next; } die("Unknown line whilst parsing $top!! [$_]\n"); } close MAKE; #print Dumper(\%missing); #print Dumper(\%toremove); if ($ARGV[0] eq '-autocopy') { my $current = "/Storage/source/current"; # Ok at this point check for current (missing) directories and add to the svn then re-parse my @new = (); foreach my $toplevel (sort @categories) { next unless exists $toremove{$toplevel}; foreach my $s (@{$toremove{$toplevel}}) { if (! -d "$toplevel/$s" and -d "$current/$toplevel/$s") { system("cp -nprv $current/$toplevel/$s $toplevel/ && svn add $toplevel/$s"); push(@new, "$toplevel/$s"); } } } if (scalar @new) { warn "Added new directories, committing...\n"; system("svn ci -m \'Added " . join(" ", @new) . "\' " . join(" ", @new)); warn "Added new directories, restarting...\n"; goto START; } } my @commits = (); foreach my $toplevel (sort @categories) { next unless (exists $missing{$toplevel} or exists $toremove{$toplevel}); warn("Updating $toplevel/Makefile\n"); my $tof = ""; my $bof = ""; my @subs = (); my $top = 1; my $error = 0; open MAKEFILE, "<$toplevel/Makefile" or $error = 1; if ($error) { warn("Unable to read $toplevel/Makefile ($!), aborting...\n"); next; } while() { chomp; /^\s+SUBDIR/ && ($top = 0); if ($top) { $tof .= $_ . "\n"; next; } if (/^\s+SUBDIR\s*=\s*(.*)$/) { push(@subs, $1); next; } $bof .= $_ . "\n"; } close MAKEFILE; # at this point we need to process the @sub array to add and remove the appropriate directories... warn("Sorting directories (adding and removing)....\n"); my %subdirs = (); foreach my $s (@{$missing{$toplevel}}, @subs) { $subdirs{$s} = 1; } foreach my $s (@{$toremove{$toplevel}}) { delete($subdirs{$s}); } @subs = sort keys %subdirs; warn("Writing $toplevel/Makefile\n"); open MAKEFILE, ">$toplevel/Makefile" or $error = 1; if ($error) { warn("Unable to write $toplevel/Makefile ($!), aborting...\n"); next; } print MAKEFILE $tof; foreach my $s (@subs) { print MAKEFILE " SUBDIR += $s\n"; } print MAKEFILE $bof; close MAKEFILE; push(@commits, "$toplevel/Makefile"); warn("Finished $toplevel...\n"); } warn "Commiting all the updated Makefiles...\n"; my $commitmsg = "Updated makefiles after SUBDIR updates..."; system("svn ci -m $commitmsg " . join(" ", @commits)); warn "DONE!!!\n";