[process] Include process name in debug messages
[ipxe.git] / src / util / licence.pl
1 #!/usr/bin/perl -w
2 #
3 # Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
4 #
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.
9 #
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.
14 #
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
18 # 02110-1301, USA.
19
20 use strict;
21 use warnings;
22 use Getopt::Long;
23
24 # List of licences we can handle
25 my $known_licences = {
26 gpl_any => {
27 desc => "GPL (any version)",
28 can_subsume => {
29 public_domain => 1,
30 bsd3 => 1,
31 bsd2 => 1,
32 mit => 1,
33 isc => 1,
34 },
35 },
36 gpl2_or_later => {
37 desc => "GPL version 2 (or, at your option, any later version)",
38 can_subsume => {
39 gpl_any => 1,
40 gpl2_or_later_or_ubdl => 1,
41 public_domain => 1,
42 bsd3 => 1,
43 bsd2 => 1,
44 mit => 1,
45 isc => 1,
46 },
47 },
48 gpl2_only => {
49 desc => "GPL version 2 only",
50 can_subsume => {
51 gpl_any => 1,
52 gpl2_or_later => 1,
53 gpl2_or_later_or_ubdl => 1,
54 public_domain => 1,
55 bsd3 => 1,
56 bsd2 => 1,
57 mit => 1,
58 isc => 1,
59 },
60 },
61 gpl2_or_later_or_ubdl => {
62 desc => ( "GPL version 2 (or, at your option, any later version) or ".
63 "Unmodified Binary Distribution Licence" ),
64 can_subsume => {
65 public_domain => 1,
66 bsd3 => 1,
67 bsd2 => 1,
68 mit => 1,
69 isc => 1,
70 },
71 },
72 public_domain => {
73 desc => "Public Domain",
74 can_subsume => {},
75 },
76 bsd4 => {
77 desc => "BSD Licence (with advertising clause)",
78 can_subsume => {
79 public_domain => 1,
80 bsd3 => 1,
81 bsd2 => 1,
82 mit => 1,
83 isc => 1,
84 },
85 },
86 bsd3 => {
87 desc => "BSD Licence (without advertising clause)",
88 can_subsume => {
89 public_domain => 1,
90 bsd2 => 1,
91 mit => 1,
92 isc => 1,
93 },
94 },
95 bsd2 => {
96 desc => "BSD Licence (without advertising or endorsement clauses)",
97 can_subsume => {
98 public_domain => 1,
99 mit => 1,
100 isc => 1,
101 },
102 },
103 mit => {
104 desc => "MIT/X11/Xorg Licence",
105 can_subsume => {
106 public_domain => 1,
107 isc => 1,
108 },
109 },
110 isc => {
111 desc => "ISC Licence",
112 can_subsume => {
113 public_domain => 1,
114 },
115 },
116 };
117
118 # Parse command-line options
119 my $verbosity = 1;
120 Getopt::Long::Configure ( 'bundling', 'auto_abbrev' );
121 GetOptions (
122 'verbose|v+' => sub { $verbosity++; },
123 'quiet|q+' => sub { $verbosity--; },
124 ) or die "Could not parse command-line options\n";
125
126 # Parse licence list from command line
127 my $licences = {};
128 foreach my $licence ( @ARGV ) {
129 die "Unknown licence \"$licence\"\n"
130 unless exists $known_licences->{$licence};
131 $licences->{$licence} = $known_licences->{$licence};
132 }
133 die "No licences specified\n" unless %$licences;
134
135 # Dump licence list
136 if ( $verbosity >= 1 ) {
137 print "The following licences appear within this file:\n";
138 foreach my $licence ( keys %$licences ) {
139 print " ".$licences->{$licence}->{desc}."\n"
140 }
141 }
142
143 # Apply licence compatibilities to reduce to a single resulting licence
144 foreach my $licence ( keys %$licences ) {
145 # Skip already-deleted licences
146 next unless exists $licences->{$licence};
147 # Subsume any subsumable licences
148 foreach my $can_subsume ( keys %{$licences->{$licence}->{can_subsume}} ) {
149 if ( exists $licences->{$can_subsume} ) {
150 print $licences->{$licence}->{desc}." subsumes ".
151 $licences->{$can_subsume}->{desc}."\n"
152 if $verbosity >= 1;
153 delete $licences->{$can_subsume};
154 }
155 }
156 }
157
158 # Print resulting licence
159 die "Cannot reduce to a single resulting licence!\n"
160 if ( keys %$licences ) != 1;
161 ( my $licence ) = keys %$licences;
162 print "The overall licence for this file is:\n " if $verbosity >= 1;
163 print $licences->{$licence}->{desc}."\n";