You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

licence.pl 4.1KB

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