1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#!/usr/bin/perl
# wpdf -- view, watch and remake pdf based on Makefile
use strict;
use warnings;
my %deps;
# collect dependencies for given pdf files
for (@ARGV) {
if (/\.pdf$/) {
(my $name = $_) =~ s/\.pdf$//;
open my $f, '<', 'Makefile'
or die "could not open Makefile: $!\n";
while (<$f>) {
if (/^\Q$name.pdf\E:\s*(.*)/) {
$deps{$_} = $name for split /\s/, $1;
last;
}
}
close $f;
exec('xpdf', '-remote', "wpdf-$name", "$name.pdf") if fork == 0;
} else {
warn "skipping $_: not a pdf\n";
}
}
# make pdf on demand
open my $p, '-|', 'watch', keys %deps
or die "could not start watch: $!\n";
while (<$p>) {
chomp;
system('make', "$deps{$_}.pdf") == 0
&& system('xpdf', '-remote', "wpdf-$deps{$_}", '-reload');
}
close $p;
|