<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w
#
# Copyright (C) 2008 Michael Brown &lt;mbrown@fensystems.co.uk&gt;.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

use strict;
use warnings;
use Getopt::Long;

# List of licences we can handle
my $known_licences = {
  gpl_any =&gt; {
    desc =&gt; "GPL (any version)",
    can_subsume =&gt; {
      public_domain =&gt; 1,
      bsd3 =&gt; 1,
      bsd2 =&gt; 1,
      mit  =&gt; 1,
      isc  =&gt; 1,
    },
  },
  gpl2_or_later =&gt; {
    desc =&gt; "GPL version 2 (or, at your option, any later version)",
    can_subsume =&gt; {
      gpl_any =&gt; 1,
      public_domain =&gt; 1,
      bsd3 =&gt; 1,
      bsd2 =&gt; 1,
      mit  =&gt; 1,
      isc  =&gt; 1,
    },
  },
  gpl2_only =&gt; {
    desc =&gt; "GPL version 2 only",
    can_subsume =&gt; {
      gpl_any =&gt; 1,
      gpl2_or_later =&gt; 1,
      public_domain =&gt; 1,
      bsd3 =&gt; 1,
      bsd2 =&gt; 1,
      mit  =&gt; 1,
      isc  =&gt; 1,
    },
  },
  public_domain =&gt; {
    desc =&gt; "Public Domain",
    can_subsume =&gt; {},
  },
  bsd4 =&gt; {
    desc =&gt; "BSD Licence (with advertising clause)",
    can_subsume =&gt; {
      public_domain =&gt; 1,
      bsd3 =&gt; 1,
      bsd2 =&gt; 1,
      mit  =&gt; 1,
      isc  =&gt; 1,
    },
  },
  bsd3 =&gt; {
    desc =&gt; "BSD Licence (without advertising clause)",
    can_subsume =&gt; {
      public_domain =&gt; 1,
      bsd2 =&gt; 1,
      mit  =&gt; 1,
      isc  =&gt; 1,
    },
  },
  bsd2 =&gt; {
    desc =&gt; "BSD Licence (without advertising or endorsement clauses)",
    can_subsume =&gt; {
      public_domain =&gt; 1,
      mit  =&gt; 1,
      isc  =&gt; 1,
    },
  },
  mit =&gt; {
    desc =&gt; "MIT/X11/Xorg Licence",
    can_subsume =&gt; {
      public_domain =&gt; 1,
      isc =&gt; 1,
    },
  },
  isc =&gt; {
    desc =&gt; "ISC Licence",
    can_subsume =&gt; {
      public_domain =&gt; 1,
    },
  },
};

# Parse command-line options
my $verbosity = 1;
Getopt::Long::Configure ( 'bundling', 'auto_abbrev' );
GetOptions (
  'verbose|v+' =&gt; sub { $verbosity++; },
  'quiet|q+' =&gt; sub { $verbosity--; },
) or die "Could not parse command-line options\n";

# Parse licence list from command line
my $licences = {};
foreach my $licence ( @ARGV ) {
  die "Unknown licence \"$licence\"\n"
      unless exists $known_licences-&gt;{$licence};
  $licences-&gt;{$licence} = $known_licences-&gt;{$licence};
}
die "No licences specified\n" unless %$licences;

# Dump licence list
if ( $verbosity &gt;= 1 ) {
  print "The following licences appear within this file:\n";
  foreach my $licence ( keys %$licences ) {
    print "  ".$licences-&gt;{$licence}-&gt;{desc}."\n"
  }
}

# Apply licence compatibilities to reduce to a single resulting licence
foreach my $licence ( keys %$licences ) {
  # Skip already-deleted licences
  next unless exists $licences-&gt;{$licence};
  # Subsume any subsumable licences
  foreach my $can_subsume ( keys %{$licences-&gt;{$licence}-&gt;{can_subsume}} ) {
    if ( exists $licences-&gt;{$can_subsume} ) {
      print $licences-&gt;{$licence}-&gt;{desc}." subsumes ".
	  $licences-&gt;{$can_subsume}-&gt;{desc}."\n"
	  if $verbosity &gt;= 1;
      delete $licences-&gt;{$can_subsume};
    }
  }
}

# Print resulting licence
die "Cannot reduce to a single resulting licence!\n"
    if ( keys %$licences ) != 1;
( my $licence ) = keys %$licences;
print "The overall licence for this file is:\n  " if $verbosity &gt;= 1;
print $licences-&gt;{$licence}-&gt;{desc}."\n";
</pre></body></html>