#!perl -w @D = grep { -d } <*>; @F = ("./Makefile"); while ($d = shift @D) { $f = "$d/Makefile"; push @F, $f if (-f $f); push @D, grep { -d } <$d/*>; } foreach $f (@F) { print "Patching $f...$/"; open F, "<$f"; @LINE = ; close F; foreach (@LINE) { next unless (m#&&# && m#cd#); my ($prefix) = (m#^\t(.?)cd#); my ($subdir) = (m#^\t${prefix}cd ([^&]*)#); my $curdir = $subdir; $curdir =~ s#[^/\\]+#..#g; s#(.*)#$1 && cd $curdir#; s# && #$/\t$prefix#g; } open F, ">$f"; print F @LINE; close F; } print "Done$/";