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 3.8KB

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