From 0b3dfa14a17831333aad9cc02f8e37398bff739c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= <john@ankarstrom.se>
Date: Mon, 21 Jun 2021 14:15:01 +0200
Subject: wpdf: Support multiple implicit dependencies

Turns out that make's -dv option is rather inflexible.
---
 wpdf | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/wpdf b/wpdf
index 304f687..99fa525 100755
--- a/wpdf
+++ b/wpdf
@@ -10,27 +10,23 @@ my %deptarget; # dependency => target
 # collect dependencies for given pdf files
 for my $target (@ARGV) {
 	if ($target =~ /\.pdf$/) {
-		# try to directly parse out dependencies
+		(my $basename = $target) =~ s/\.pdf$//;
 		open my $f, '<', 'Makefile'
 			or die "could not open Makefile: $!\n";
 		while (<$f>) {
-			next if not /^\Q$target\E:\s*(.*)/;
-			$deptarget{$_} = $target for split /\s/, $1;
-			goto found;
+			# explicit
+			if (/^\Q$target\E:\s*(.*)/) {
+				$deptarget{$_} = $target for split /\s/, $1;
+				last;
+			}
+			# implicit
+			if (/^\.([^ .]+)\.pdf\s*:\s*(.*)/) {
+				$deptarget{"$basename.$1"} = $target;
+				$deptarget{$_} = $target for split /\s/, $2;
+				last;
+			}
 		}
-
-		# 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;
+		close $f;
 		exec('xpdf', '-remote', "wpdf-$target", $target) if fork == 0;
 		next;
 	} else {
-- 
cgit v1.2.3