diff options
author | John Ankarström <john@ankarstrom.se> | 2021-06-21 11:20:58 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-06-21 11:21:17 +0200 |
commit | d26f20ff4f4494c4dfe26793918edf9c42ecd47d (patch) | |
tree | e275b64928b85cd5ae13aeefa3b14764fb99cbbe /wpdf | |
parent | f4d044d4b6cbb2d2648a170cefa45befba3af3d5 (diff) | |
download | xutil-d26f20ff4f4494c4dfe26793918edf9c42ecd47d.tar.gz |
wpdf: Support implicit dependencies
Diffstat (limited to 'wpdf')
-rwxr-xr-x | wpdf | 38 |
1 files changed, 25 insertions, 13 deletions
@@ -5,34 +5,46 @@ use strict; use warnings; -my %deps; +my %deptarget; # dependency => target # collect dependencies for given pdf files -for (@ARGV) { - if (/\.pdf$/) { - (my $name = $_) =~ s/\.pdf$//; +for my $target (@ARGV) { + if ($target =~ /\.pdf$/) { + # try to directly parse out dependencies 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; - } + next if not /^\Q$target\E:\s*(.*)/; + $deptarget{$_} = $target for split /\s/, $1; + goto found; } - close $f; - exec('xpdf', '-remote', "wpdf-$name", "$name.pdf") if fork == 0; + + # try to get implicit dependencies + (my $esc = $target) =~ s/'/'"'"'/g; + open my $p, "make -ndv 2>&1 '$esc' |" + or die "could not run make: $!\n"; + while (<$p>) { + next if not /^\Q$target\E:< = (.*)/; + $deptarget{$_} = $target for split /\s/, $1; + last; + } + + close $p; +found: close $f; + exec('xpdf', '-remote', "wpdf-$target", $target) if fork == 0; + next; } else { warn "skipping $_: not a pdf\n"; } } # make pdf on demand -open my $p, '-|', 'watch', keys %deps +open my $p, '-|', 'watch', keys %deptarget or die "could not start watch: $!\n"; while (<$p>) { chomp; - system('make', "$deps{$_}.pdf") == 0 - && system('xpdf', '-remote', "wpdf-$deps{$_}", '-reload'); + system('make', "$deptarget{$_}") == 0 + && system('xpdf', '-remote', "wpdf-$deptarget{$_}", '-reload'); } close $p; exit($? != 0); |