diff options
author | John Ankarström <john@ankarstrom.se> | 2021-07-09 15:56:28 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-07-09 15:56:28 +0200 |
commit | 08276e58732272cb244ea54b2abc1c198132f284 (patch) | |
tree | 1f0749c38ca20b0cf2c6ba475752e28f22e011a2 /wpdf | |
parent | 7fdc9fb18a5815399bd44e943f8845807570e61b (diff) | |
download | xutil-08276e58732272cb244ea54b2abc1c198132f284.tar.gz |
wpdf: Support build(1) syntax in source file
Diffstat (limited to 'wpdf')
-rwxr-xr-x | wpdf | 38 |
1 files changed, 29 insertions, 9 deletions
@@ -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"; |