diff options
-rwxr-xr-x | etc/wpdf | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -7,6 +7,7 @@ use warnings; my $alive; # number of children alive my %deptarget; # dependency => target +my %depsource; # dependency => source my $parent = $$; # pid of parent $SIG{USR1} = sub { kill 'HUP', 0 if not --$alive }; @@ -42,12 +43,14 @@ for my $target (@ARGV) { my $source = $target; $target =~ s,\.[^./]*$,,; $target .= '.pdf'; $deptarget{$source} = $target; + $depsource{$source} = $source; open my $f, '<', $source; while (<$f>) { last if ++$i > 20; if (/\s% (.*)/) { $deptarget{$_} = $target for split /\s/, $1; + $depsource{$_} = $source for split /\s/, $1; last; } } @@ -69,7 +72,9 @@ open my $p, '-|', 'watch', keys %deptarget or die "could not start watch: $!\n"; while (<$p>) { chomp; - system('make', "$deptarget{$_}") == 0 + my $cmd = ($_ =~ /\.pdf$/) ? 'make' : 'build'; + my $arg = ($_ =~ /\.pdf$/) ? $deptarget{$_} : $depsource{$_}; + system($cmd, $arg) == 0 && system('xpdf', '-remote', "wpdf-$deptarget{$_}", '-reload'); } close $p; |