#!/usr/bin/perl -w
use strict;

print STDERR "   $0 ", join(' ', @ARGV), "\n";

my $suppressed = 0;
my $to_untag = '';
while (<>) {
    s,(\$\{_IMPORT_PREFIX}/lib)(?!/$ENV{DEB_HOST_MULTIARCH}),$1/$ENV{DEB_HOST_MULTIARCH},g;
    s,/$ENV{DEB_HOST_MULTIARCH}/,/\${DEB_HOST_MULTIARCH}/,g;
    next if /INTERFACE_LINK_DIRECTORIES/;
    s/-L[^;]*;//g;
    s,\.so\.1\.4\.\d*,\.so,g;
    s,([^a-z]fltk::(?!fluid|options)\w*)(?!-shared)(\W),${1}-static$2,g;
    s,(libfltk[a-z0-9_:]*)-shared,$1,g;

    if (/^#/) {
	print $to_untag;
	$to_untag =~ s/-shared//g;
	print $to_untag;
	$suppressed = 0;
	if (/(fltk.*)-shared/) {
	    $to_untag = $_;
	} else {
	    $to_untag = '';
	}
    } elsif ($to_untag) {
	next if /IMPORTED_LINK_INTERFACE_LIBRARIES_NONE/;
	if (/add_executable|\/bin\//) {
	    $suppressed = 1;
	    $to_untag = '';
	    next;
	}
	$to_untag .= $_;
    }
    print unless $suppressed || $to_untag;
}
