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., 675 Mass Ave, Cambridge, MA 02139, USA.
23 # List of licences we can handle
24 my $known_licences = {
26 desc => "GPL (any version)",
34 desc => "GPL version 2 (or, at your option, any later version)",
43 desc => "GPL version 2 only",
53 desc => "Public Domain",
57 desc => "BSD Licence (with advertising clause)",
65 desc => "BSD Licence (without advertising clause)",
72 desc => "BSD Licence (without advertising or endorsement clauses)",
79 # Parse command-line options
81 Getopt::Long::Configure ( 'bundling', 'auto_abbrev' );
83 'verbose|v+' => sub { $verbosity++; },
84 'quiet|q+' => sub { $verbosity--; },
85 ) or die "Could not parse command-line options\n";
87 # Parse licence list from command line
89 foreach my $licence ( @ARGV ) {
90 die "Unknown licence \"$licence\"\n"
91 unless exists $known_licences->{$licence};
92 $licences->{$licence} = $known_licences->{$licence};
94 die "No licences specified\n" unless %$licences;
97 if ( $verbosity >= 1 ) {
98 print "The following licences appear within this file:\n";
99 foreach my $licence ( keys %$licences ) {
100 print " ".$licences->{$licence}->{desc}."\n"
104 # Apply licence compatibilities to reduce to a single resulting licence
105 foreach my $licence ( keys %$licences ) {
106 # Skip already-deleted licences
107 next unless exists $licences->{$licence};
108 # Subsume any subsumable licences
109 foreach my $can_subsume ( keys %{$licences->{$licence}->{can_subsume}} ) {
110 if ( exists $licences->{$can_subsume} ) {
111 print $licences->{$licence}->{desc}." subsumes ".
112 $licences->{$can_subsume}->{desc}."\n"
114 delete $licences->{$can_subsume};
119 # Print resulting licence
120 die "Cannot reduce to a single resulting licence!\n"
121 if ( keys %$licences ) != 1;
122 ( my $licence ) = keys %$licences;
123 print "The overall licence for this file is:\n " if $verbosity >= 1;
124 print $licences->{$licence}->{desc}."\n";