aboutsummaryrefslogtreecommitdiff
path: root/wpdf
diff options
context:
space:
mode:
Diffstat (limited to 'wpdf')
-rwxr-xr-xwpdf38
1 files changed, 29 insertions, 9 deletions
diff --git a/wpdf b/wpdf
index a906c67..94e5029 100755
--- a/wpdf
+++ b/wpdf
@@ -12,8 +12,9 @@ my $parent = $$; # pid of parent
$SIG{USR1} = sub { kill 'HUP', 0 if not --$alive };
$SIG{HUP} = sub { exit 0 };
-# collect dependencies for given pdf files
+# collect dependencies for given files
for my $target (@ARGV) {
+ # if pdf, collect from Makefile
if ($target =~ /\.pdf$/) {
(my $basename = $target) =~ s/\.pdf$//;
open my $f, '<', 'Makefile'
@@ -32,18 +33,37 @@ for my $target (@ARGV) {
}
}
close $f;
- if (fork == 0) {
- system 'xpdf', '-remote', "wpdf-$target", $target;
- kill 'USR1', $parent;
- exit;
+ }
+
+ # if not pdf, assume target is actually source file and collect from it
+ # (with build(1) syntax)
+ else {
+ my $i = 0;
+ my $source = $target;
+ $target =~ s,\.[^./]*$,,; $target .= '.pdf';
+ $deptarget{$source} = $target;
+
+ open my $f, '<', $source;
+ while (<$f>) {
+ last if ++$i > 20;
+ if (/\s% (.*)/) {
+ $deptarget{$_} = $target for split /\s/, $1;
+ last;
+ }
}
- $alive++;
- next;
- } else {
- warn "skipping $_: not a pdf\n";
+ close $f;
}
+
+ if (fork == 0) {
+ system 'xpdf', '-remote', "wpdf-$target", $target;
+ kill 'USR1', $parent;
+ exit;
+ }
+ $alive++;
}
+die "no dependencies found\n" if not keys %deptarget;
+
# make pdf on demand
open my $p, '-|', 'watch', keys %deptarget
or die "could not start watch: $!\n";