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.

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