diff -Nurd fink-package-precedence-0.36.orig/fink-package-precedence fink-package-precedence-0.36/fink-package-precedence
--- fink-package-precedence-0.36.orig/fink-package-precedence	1969-12-31 19:00:00.000000000 -0500
+++ fink-package-precedence-0.36/fink-package-precedence	2021-08-02 22:07:35.000000000 -0400
@@ -0,0 +1,428 @@
+#!/usr/bin/perl
+# -*- mode: Perl; tab-width: 4; -*-
+
+# A dirty hack by Daniel Macks
+
+use warnings;
+use strict;
+
+use File::Find;
+use Getopt::Long;
+use Cwd qw/ abs_path /;
+use File::Basename;
+use File::Spec;
+use File::Temp qw(tempdir);
+
+my %opts = (
+	'headers' => 1,				# scan .h in -M dependency files?
+	'depfile-ext' => [],		# extensions for header-dep scan
+	'prohibit-bdep' => [],		# whine if .h supplied by these packages
+	'libs' => 1,				# scan otool -L of compiled binaries?
+	'help' => 0,				# print usage msg?
+	);
+
+GetOptions(
+	\%opts,
+	'headers!',
+	'depfile-ext=s@',
+	'prohibit-bdep=s@',
+	'libs!',
+	'help|?',
+	) or $opts{'help'} = 1;
+if (!$opts{'headers'} && !$opts{'libs'}) {
+	# must specify at least one mode
+	$opts{'help'} = 1;
+};
+if (@{$opts{'prohibit-bdep'}}) {
+	# handle comma-separated list like multiply-passed flag
+	$opts{'prohibit-bdep'} = [ split /,/, join ',', @{$opts{'prohibit-bdep'}} ];
+
+	if (!$opts{'headers'}) {
+		# can't disallow bdep based on header scan if not scanning headers
+		$opts{'help'} = 1;
+	}
+}
+if (@{$opts{'depfile-ext'}}) {
+	# handle comma-separated list like multiply-passed flag
+	$opts{'depfile-ext'} = [ split /,/, join ',', @{$opts{'depfile-ext'}} ];
+
+	if (!$opts{'headers'}) {
+		# can't specify header depfile extensions if not scanning headers
+		$opts{'help'} = 1;
+	}
+} else {
+	$opts{'depfile-ext'} = ['\.Plo', '\.Po'];
+}
+if (!@ARGV) {
+	# must specify at least one location
+	$opts{'help'} = 1;
+}
+if ($opts{'help'}) {
+	my $version = '@VERSION@';
+	my $msg = <<"EOMSG";
+fink-package-precedence $version
+
+Usage: $0 [options] <list of locations>
+
+Options:
+
+  --headers/--no-headers  Scan dependency files (*1) for:
+                          * Use of system headers that should be
+                            masked by fink ones (*2)
+                            (bad -I ordering or missing BuildDepends)
+                          * Fink packages that supply headers used
+                            (packages to list in BuildDepends)
+
+  --depfile-ext=<regexp>  Which files to scan for --headers scan
+                          * Defaults to {\.Plo,\.Po} if not specified (*3)
+                          * Left-truncated regex for full pathname
+                            (beware of regex-quoting and shell-quoting)
+
+  --prohibit-bdep=<pkg>   Test if --headers finds a .h that is supplied
+                          by installed fink package <pkg> (*2)
+                          (comma-separated list or multiple use of this
+                          flag is allowed)
+
+  --libs/--no-libs        Scan compiled binaries for:
+                          * System libraries that should be masked by
+                            fink ones (*2)
+                            (bad -L ordering or missing BuildDepends)
+
+  --help                  Display this help message and exit
+
+  *1 For example, generated by gcc -M flags as activated by
+     ./configure --enable-dependency-tracking
+
+  *2 error-code on exit if this condition occurs
+
+  *3 These are usually correct for most autotools/libtool-based
+     projects that support --enable-dependency-tracking (*1). Passing
+     -MD directly (perhaps via CPPFLAGS) usually gives .d instead.
+
+  <list of locations> can be dependency filenames, compiled-binary
+  filenames, .deb compiled-package archives, or directories to scan
+  for these files.
+
+EOMSG
+
+	die $msg;
+}
+# /  <-- this slash keeps emacs syntax-highlighting less confused
+
+if ($opts{'headers'}) {
+
+print "Scanning /", join( ",", @{$opts{'depfile-ext'}} ), "\$/ dependency files...\n";
+
+my $dep_re = '(' . join( '|', @{$opts{'depfile-ext'}} ) . ')$';
+$dep_re = qr/$dep_re/;
+
+my %deps;						# key=included file
+								# value=first dependencies file where it's listed
+
+my $plo_count; # undef has sentinel meaning that we have not even found a dir to scan
+
+foreach my $argv (@ARGV) {
+	next if $argv =~ /\.deb$/;  # binary archives have no compile-time header data
+	$plo_count += 0; # unset sentinel; defined because we have something to scan
+
+	my $argv_abs_dir_regex = abs_path($argv);
+	$argv_abs_dir_regex = qr/^\Q$argv_abs_dir_regex\E/;
+
+find sub {
+	return unless $File::Find::name =~ /$dep_re/;	# skip files that aren't our dependency lists
+
+	print "\t$File::Find::name\n";
+	$plo_count++;
+	open my $plo, '<', $_ or die "Could not read $_: $!\n";
+	while ( defined ( $_ = <$plo> ) ) {
+		next if /^\s*$/;		# usually lots of blank lines
+		s/^[^:]*://;				# only care deps; filename is key dependant
+		# FIXME: breaks if .h's pathname contains whitespace
+		# (gcc -MD uses backslash-protection)
+		foreach my $file (split) {
+			next unless $file =~ /^\//;	# skip continuation markers
+										# and build-dir local files
+			next if $file =~ /$argv_abs_dir_regex/; # alt format of
+													# build-dir local
+			$file =~ s/\/\.(?=\/)//g;  # foo/./././bar/./quux -> foo/bar/quux
+			$deps{$file} = $File::Find::name if ! exists $deps{$file};
+		}
+	}
+	close $plo;
+}, $argv;
+}
+
+{
+	# dpkg's files database only tracks canonical paths, but headers
+	# could be accessed via other paths:
+	#  * simple symlinks (foo.h->bar.h; need to look up both foo.h and
+	#    bar.h)
+	#  * directory symlinks (foo1->foo2; need to look up foo1 and
+	#    foo2/bar.h for foo1/bar.h)
+	#  * superfluous "/." components foo/./bar.h; need to look up
+	#    foo/bar.h)
+	#  * backtracking (foo1/foo2/../bar.h; need to look up foo1/foo2
+	#    (?)  and foo1/bar.h
+
+	# need to stash original keys() so iterator doesn't get confused
+	# if we add/delete entries while iterating
+	my @inc_files = keys %deps;
+	foreach my $file (@inc_files) {
+		my $src = $deps{$file};     # value (in case we delete key)
+		my $abs = abs_path($file);  # clean up all sorts of spaghetti
+		if (!defined $abs) {
+			warn "abs_path($file) failed (seen in $src)\n";
+		} elsif ($file ne $abs) {
+			# link in here somewhere, need linknames and targets
+			# always want the actual file
+			$deps{$abs} = $src if ! exists $deps{$abs};
+			# dpkg knows file-links, but not files via dir-links
+			delete $deps{$file} unless dirname($file) eq dirname($abs);
+			if ($file !~ /\/\.\.\//) {  # FIXME: not sure how to
+										# handle levels of ../ yet!
+				my $path; # grows dir by dir for $file's full path
+				foreach (split /\//, $file) {
+					next if ! length $_;
+					$path .= "/$_";
+					if (-l $path) {
+						$deps{$path} = $src if ! exists $deps{$path};
+						# too confusing to disentangle multiple symlinks
+						last;
+					}
+				}
+			}
+		}
+	}
+}
+
+if (! defined $plo_count) {
+	print "Only .deb binary archives requested.\n";
+	$plo_count = 0;  # sentinel has done its job
+} elsif (! $plo_count) {
+	die "No dependency files found.\n";
+}
+
+print "Looking for incorrect headers in ", $plo_count, " dependency files...\n";
+
+# regexes for headers to disallow.
+# * /usr/local is bad news!
+# * OSX or X11 files for which fink has replacements
+# * /opt/local is cross-contamination from MacPorts
+my $repl_regex = join '|', (
+	'/usr/local/include',
+	'/usr/include/(curses|ncurses|form|menu|panel|term|termcap)\.h',
+	'/usr/include/iconv\.h',
+	'/usr/include/libxml2',
+	'/usr/include/libxslt',
+	'/usr/include/pcap',
+	'/usr/include/readline',
+	'/usr/.*/ft2build\.h',
+	'/usr/.*/freetype2',
+	'/usr/.*/fontconfig',
+	'/usr/.*/expat\.h',
+	'/usr/.*/Xft',
+	'/usr/.*/cairo',
+	'/usr/.*/glitz',
+	'/usr/.*/pixman',
+	'/usr/.*/png\.h',
+	'/usr/.*/pngconf\.h',
+	'/opt/X11.*/ft2build\.h',
+	'/opt/X11.*/freetype2',
+	'/opt/X11.*/fontconfig',
+	'/opt/X11.*/expat\.h',
+	'/opt/X11.*/Xft',
+	'/opt/X11.*/cairo',
+	'/opt/X11.*/glitz',
+	'/opt/X11.*/pixman',
+	'/opt/X11.*/png\.h',
+	'/opt/X11.*/pngconf\.h',
+	'/opt/local',
+);
+$repl_regex = qr/^($repl_regex)/; # pre-compile (will use many times)
+my $fink_prefix = '@PREFIX@';
+my $fink_prefix_regex = qr/^\Q$fink_prefix\E/;
+
+my @fink_headers;
+
+my $bad_system = 0;
+foreach (sort keys %deps) {
+	if (/$repl_regex/) {
+		print "\t $deps{$_} uses $_\n";
+		$bad_system |= 1;
+		if (/^\/usr\/local\/include\//) {
+			$bad_system |= 2;
+		}
+	} elsif (/$fink_prefix_regex/) {
+		push @fink_headers, $_;
+	}
+}
+if ($bad_system & 2) {
+	die << 'EOMSG';
+There are files installed in /usr/local on your computer that are
+known to interfere with building some Fink packages. Try temporarily
+renaming or moving /usr/local while Fink is compiling a package. See
+http://fink.sourceforge.net/faq/comp-general.php#usr-local-libs for
+more information.
+EOMSG
+} elsif ($bad_system) {
+	die "Please fix build process to get consistent use of fink's headers.\n";
+}
+
+my %fink_pkgs;
+my @not_found;
+my $dpkg_S = "$fink_prefix/bin/dpkg -S";
+my $progress = 1;
+print "Determining fink providers of ", scalar(@fink_headers), " headers...\n";
+while (@fink_headers) {
+	# do in blocks of files using heuristic to avoid shell cmd-line limit
+	# ('dpkg -S' is expensive!)
+	my @chunk = splice @fink_headers, 0, 100;
+	print "\t$progress - ", ($progress+=@chunk)-1, "\n";
+
+	# @chunk could contain null strings, would need to filter them out if
+	# using 3+ argument form of open()
+	open my $dpkg_S_fh, "$dpkg_S -- @chunk 2>&1 |" or die "Could not fork $dpkg_S: $!\n";
+	while (<$dpkg_S_fh>) {
+		if (/^dpkg: (.*\.)$/) {
+			# 'dpkg: $filename not found.' but "not found" may be localized
+			push @not_found, $1;
+		} elsif (/^([^:]+):/) {
+			$fink_pkgs{$1} = 1;
+		}
+	}
+	close $dpkg_S_fh;		 # or die "Error reading $dpkg_S: $! $?\n";
+	# must not trap close() error, since that is expected if a file is
+	# not found in dpkh -S database
+}
+
+print "Found use of headers from ", scalar(keys %fink_pkgs), " fink packages:\n";
+map { print "\t$_\n" } sort keys %fink_pkgs;
+if (@not_found) {
+	print "Could not determine fink package for ", scalar(@not_found), " headers:\n";
+	map { print "\t$_\n" } sort @not_found;
+}
+
+my @bad_bdep = grep { exists $fink_pkgs{$_} } @{$opts{'prohibit-bdep'}};
+if (@bad_bdep) {
+	print "Use of headers from prohibited installed packages:\n";
+	map { print "\t$_\n" } sort @bad_bdep;
+	die "Please fix build process to avoid seeing them.\n";
+}
+
+}
+
+if ($opts{'libs'}) {
+	chomp(my $xcodepath=`xcode-select -print-path 2>/dev/null`);
+	my $otool = '/Library/Developer/CommandLineTools/usr/bin/otool-classic';
+	if (!-x $otool) {
+		$otool = $xcodepath . '/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool-classic';
+	}
+	if (!-x $otool) {
+		$otool = '/usr/bin/otool';
+	}
+	if (!-x $otool) {
+		die "Cannot scan binary linking without a suitable 'otool' command available\n";
+	}
+
+print "Scanning binaries for incorrect dyld linking...\n";
+
+my %deps;						# key=linked lib
+								# value=first binary that links against it
+my %deb_tempdirs;				# unpacked .deb archive -> .deb file itself
+
+	{
+		my @binary_dirs = @ARGV;
+		map {
+			if (/\.deb$/) {
+				# Unpack .deb (keep its filename visible in unpacked
+				# dir so that reports about it include archivename).
+				# Use explicit tmpdir (rather than "TMPDIR=>1") to
+				# make sure we keep in sync with later uses of paths.
+				my $destdir = tempdir("$_.XXXXXXXXXX", DIR=>File::Spec->tmpdir, CLEANUP=>1 );
+				if (system('dpkg', '-x', $_, $destdir)) {
+					die "Error: could not unpack .deb\n";
+				}
+				# save archive's filename for user output
+				$deb_tempdirs{$destdir} = $_;
+				# scan unpacked dir instead of the archive's filename
+				$_ = $destdir;
+			}
+		} @binary_dirs;
+
+find sub {
+	return unless -f;
+	return if /\.class$/;
+	open my $otool_L_fh, '-|', $otool, '-L', '-', $_ or die "Could not fork $otool -L $_: $!\n";  # otool uses "-" not "--" to end flag-list!
+	while ( defined ( $_ = <$otool_L_fh> ) ) {
+		next unless /^\t(.+) \(/;	# only read dyld links
+		$deps{$1} = $File::Find::name if ! exists $deps{$1};
+	}
+	close $otool_L_fh or die "Error reading $otool -L: $! $?\n";
+}, @binary_dirs;
+	}
+	
+# regexes for libraries to disallow.
+# * /usr/local is bad news!
+# * OSX or X11 files for which fink has replacements
+# * /opt/local is cross-contamination from MacPorts
+my $repl_regex = join '|', (
+	'/usr/local/lib',
+	'/usr/lib/lib(curses|ncurses|form|menu|panel)',
+	'/usr/lib/libiconv',
+	'/usr/lib/libpcap',
+	'/usr/lib/libreadline',
+	'/usr/lib/libxml',
+	'/usr/lib/libxslt',
+	'/usr/X11.*/libfreetype',
+	'/usr/X11.*/libfontconfig',
+	'/opt/X11.*/libfreetype',
+	'/opt/X11.*/libfontconfig',
+	'/usr/.*/libexpat',
+	'/usr/X11.*/libXft',
+	'/usr/X11.*/libcairo',
+	'/usr/X11.*/libglitz',
+	'/usr/X11.*/libpixman',
+	'/usr/X11.*/libpng',
+	'/opt/X11.*/libXft',
+	'/opt/X11.*/libcairo',
+	'/opt/X11.*/libglitz',
+	'/opt/X11.*/libpixman',
+	'/opt/X11.*/libpng',
+	'/opt/local',
+);
+$repl_regex = qr/^($repl_regex)/; # pre-compile (will use many times)
+
+my $bad_system = 0;
+my $tmpdir_regex = File::Spec->tmpdir();
+$tmpdir_regex = qr/\Q$tmpdir_regex/;
+foreach (sort keys %deps) {
+	if (/$repl_regex/) {
+		my $bad_binary = $deps{$_};
+		if ($bad_binary =~ /$tmpdir_regex/) {
+			# Unpacked .deb archives are stored in tmpdir, but we want
+			# users to see .deb archivename, not unpacked tmpdir path
+			foreach (keys %deb_tempdirs) {
+				last if $bad_binary =~ s/^\Q$_/$deb_tempdirs{$_}:/;
+			}
+		}
+		print "\t $bad_binary uses $_\n";
+		$bad_system |= 1;
+		if (/^\/usr\/local\/lib\//) {
+			$bad_system |= 2;
+		}
+	}
+}
+if ($bad_system & 2) {
+	die << 'EOMSG';
+There are files installed in /usr/local on your computer that are
+known to interfere with building some Fink packages. Try temporarily
+renaming or moving /usr/local while Fink is compiling a package. See
+http://fink.sourceforge.net/faq/comp-general.php#usr-local-libs for
+more information.
+EOMSG
+} elsif ($bad_system) {
+	die "Please fix build process to get consistent use of fink's libraries.\n";
+}
+
+
+}
