3 # Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 2 of the
8 # License, or any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 # List of licences we can handle
25 my $known_licences = {
27 desc => "GPL (any version)",
37 desc => "GPL version 2 (or, at your option, any later version)",
48 desc => "GPL version 2 only",
60 desc => "Public Domain",
64 desc => "BSD Licence (with advertising clause)",
74 desc => "BSD Licence (without advertising clause)",
83 desc => "BSD Licence (without advertising or endorsement clauses)",
91 desc => "MIT/X11/Xorg Licence",
98 desc => "ISC Licence",
105 # Parse command-line options
107 Getopt::Long::Configure ( 'bundling', 'auto_abbrev' );
109 'verbose|v+' => sub { $verbosity++; },
110 'quiet|q+' => sub { $verbosity--; },
111 ) or die "Could not parse command-line options\n";
113 # Parse licence list from command line
115 foreach my $licence ( @ARGV ) {
116 die "Unknown licence \"$licence\"\n"
117 unless exists $known_licences->{$licence};
118 $licences->{$licence} = $known_licences->{$licence};
120 die "No licences specified\n" unless %$licences;
123 if ( $verbosity >= 1 ) {
124 print "The following licences appear within this file:\n";
125 foreach my $licence ( keys %$licences ) {
126 print " ".$licences->{$licence}->{desc}."\n"
130 # Apply licence compatibilities to reduce to a single resulting licence
131 foreach my $licence ( keys %$licences ) {
132 # Skip already-deleted licences
133 next unless exists $licences->{$licence};
134 # Subsume any subsumable licences
135 foreach my $can_subsume ( keys %{$licences->{$licence}->{can_subsume}} ) {
136 if ( exists $licences->{$can_subsume} ) {
137 print $licences->{$licence}->{desc}." subsumes ".
138 $licences->{$can_subsume}->{desc}."\n"
140 delete $licences->{$can_subsume};
145 # Print resulting licence
146 die "Cannot reduce to a single resulting licence!\n"
147 if ( keys %$licences ) != 1;
148 ( my $licence ) = keys %$licences;
149 print "The overall licence for this file is:\n " if $verbosity >= 1;
150 print $licences->{$licence}->{desc}."\n";