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

my $to_untag = '';
while (<>) {
    s,(\${_IMPORT_PREFIX}/lib),$1/$ENV{DEB_HOST_MULTIARCH},g;
    s,\.so\.1\.3\.\d*,\.so,g;
    s,([^a-z]fltk\w*(?<!_SHARED))(\W),${1}_STATIC$2,g;

    if (/^#/) {
	$to_untag =~ s/_SHARED//g;
	print $to_untag;
	if (/"(fltk.*)_SHARED"/) {
	    $to_untag = ("# Create imported target $1\n" .
			 "add_library($1 SHARED IMPORTED)\n\n$_");
	} else {
	    $to_untag = '';
	}
    } elsif ($to_untag) {
	next if /IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG/;
	$to_untag .= $_;
    }
    print;
}
