3
# Check licenses of a large subtree. It uses licensecheck from devscripts
4
# then postprocess the results
5
# (c) 2009, Fabien Tassin <fta@sofaraway.org>
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU General Public License as
9
# published by the Free Software Foundation; either version 2, or (at
10
# your option) any later version.
12
# This program is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# General Public License for more details.
17
# You should have received a copy of the GNU General Public License along
18
# with this program; if not, write to the Free Software Foundation, Inc.,
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
my $white_listed_licenses = [
25
'global BSD-style Chromium',
26
'global BSD-style libjingle',
29
'Apache (v2.0) GENERATED FILE',
30
'Apache (v2.0) BSD (2 clause)',
32
'BSD (2 clause) GENERATED FILE',
33
'BSD (2 clause)/LGPL 2 (or later)/LGPL 2.1 (or later)',
34
'BSD (2 or 3 clause)',
36
'BSD (3 clause) GENERATED FILE',
37
'BSD (2 clause) MIT/X11 (BSD like)',
39
'BSL (v1) BSD (3 clause) GENERATED FILE',
41
'GPL (with incorrect FSF address)',
42
'GPL (unversioned/unknown version)',
44
'GPL (v2 or later) compatible',
45
'GPL (v2 or later) (with incorrect FSF address)',
46
'GPL (v2 or later) GENERATED FILE',
47
'GPL 2.0/LGPL 2.1/MPL 1.1 tri-license',
55
'LGPL (v2 or later) GENERATED FILE',
56
'LGPL (v2.1 or later) GENERATED FILE',
57
'LGPL (v2 or later) (with incorrect FSF address)',
58
'LGPL (v2 or later) (with incorrect FSF address) GENERATED FILE',
60
'LGPL (v2.1 or later)',
61
'LGPL (v2.1 or later) (with incorrect FSF address)',
63
'MIT/X11 (BSD like) GENERATED FILE',
64
'MIT/X11-like (expat)',
65
'MPL (v1.1,) GPL (unversioned/unknown version) LGPL (v2.1 or later)',
66
'MPL (v1.1,) GPL (unversioned/unknown version) LGPL (v2 or later)',
67
'MPL (v1.1,) BSD (3 clause) GPL (unversioned/unknown version) LGPL (v2.1 or later)',
68
'MPL (v1.1) GPL (unversioned/unknown version)',
69
'MPL (v1.1) GPL (unversioned/unknown version) GENERATED FILE',
70
'MPL 1.1/GPL 2.0/LGPL 2.1',
71
'Paul Hsieh\'s Public Domain Option',
72
'SGI Free Software B License (v2.0)',
75
'*No copyright* Apache (v2.0)',
76
'*No copyright* BSD (2 clause)',
77
'*No copyright* GPL (v2 or later)',
78
'*No copyright* LGPL (v2 or later)',
79
'*No copyright* LGPL (v2.1 or later)',
80
'*No copyright* LGPL (v2 or later) (with incorrect FSF address) GENERATED FILE',
81
'*No copyright* GENERATED FILE',
82
'*No copyright* Public domain',
83
'ZERO-CODE-FILES or GENERATED',
86
my $manually_identified = {
87
'/base/third_party/dmg_fp/' => [
89
'Copyright (c) 1991, 2000, 2001 by Lucent Technologies.'
91
'/base/third_party/purify/pure_api.c' => [
93
'Explicitly no copyright'
95
'/base/third_party/purify/pure.h' => [
97
'(C) Copyright IBM Corporation. 2006, 2006. All Rights Reserved.'
99
'/third_party/sqlite/' => [
101
'The author disclaims all copyright. The library is in the public domain.'
107
'/depot_tools/tests/pymox/' => [
115
'/gpu/command_buffer/common/GLES2/' => [
116
'SGI Free Software B License (v2.0)',
119
'/media/tools/qt_faststart/qt_faststart.c' => [
123
'/native_client/src/third_party/libxt/' => [
124
'MIT/X11 (BSD like)',
127
'/native_client/' => [
131
'/v8/test/cctest/' => [
135
'/third_party/WebKit/WebKitLibraries/WebCoreSQLite3/' => [
137
'The author disclaims all copyright. The library is in the public domain.'
139
'/third_party/zlib/' => [
141
'This software is provided \'as-is\', without any express or implied'
143
'/third_party/lzma_sdk/' => [
145
'LZMA SDK is placed in the public domain.'
147
'/third_party/hunspell/src/hunspell/' => [
148
'MPL 1.1/GPL 2.0/LGPL 2.1',
149
'The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License")'
151
'/webkit/data/layout_tests' => [
152
'global BSD-style Webkit/LGPL 2.1',
153
'http://webkit.org/projects/goals.html'
155
'/third_party/WebKit/JavaScriptCore/icu' => [
157
'Copyright (c) 1995-2006 International Business Machines Corporation and others'
159
'/third_party/WebKit/WebCore/icu/' => [
161
'Copyright (c) 1995-2006 International Business Machines Corporation and others'
163
'/third_party/icu/' => [
165
'Copyright (c) 1995-2009 International Business Machines Corporation and others'
167
'/third_party/harfbuzz/' => [
169
'Copyright: 2000-2009 Red Hat, Inc'
171
'/third_party/WebKit/JavaScriptCore/ForwardingHeaders/' => [
172
'ZERO-CODE-FILES or GENERATED',
175
'/third_party/WebKit/WebCore/ForwardingHeaders/' => [
176
'ZERO-CODE-FILES or GENERATED',
179
'build-tree/src/third_party/WebKit/WebCore/' => [
180
'BSD (2 clause)/LGPL 2 (or later)/LGPL 2.1 (or later)',
183
'third_party/WebKit/JavaScriptCore/' => [
184
'BSD (2 clause)/LGPL 2 (or later)/LGPL 2.1 (or later)',
188
'ZERO-CODE-FILES or GENERATED',
191
'/third_party/libjingle/files/talk/' => [
192
'global BSD-style libjingle',
195
'/third_party/skia/' => [
199
'/third_party/hunspell/' => [
200
'GPL 2.0/LGPL 2.1/MPL 1.1 tri-license',
203
'/third_party/expat/' => [
204
'MIT/X11-like (expat)',
207
'/third_party/yasm/source/patched-yasm/modules/parsers/nasm/' => [
211
'/third_party/yasm/source/patched-yasm/modules/preprocs/' => [
215
'/third_party/yasm/source/patched-yasm/modules/' => [
216
'BSD (2 or 3 clause)',
219
'/third_party/yasm/source/patched-yasm/tools/python-yasm/' => [
223
'/third_party/yasm/' => [
224
'GPL (v2 or later) compatible',
225
'Copyright (c) 2001-2009 Peter Johnson and other Yasm developers.'
227
'/third_party/tlslite/' => [
231
'/third_party/ffmpeg/' => [
232
'GPL (v2 or later) compatible',
235
'/third_party/libevent/' => [
239
'/third_party/protobuf2/src/' => [
243
'/third_party/tcmalloc/tcmalloc/' => [
247
'/third_party/xdg-utils/' => [
248
'MIT/X11 (BSD like)',
251
'/net/disk_cache/hash.cc' => [
252
'Paul Hsieh\'s Public Domain Option',
258
getopts('ah', $opt) || &Usage();
259
&Usage() if $$opt{'h'};
262
die "Usage: $0 [options] directory\n" .
263
" -a display all licenses found (default will hide whitelisted licenses)\n" .
264
" -h this help screen\n";
267
my $dir = shift @ARGV;
272
my $copyright = shift;
274
return("empty file", "empty") if -z $file;
275
open(FILE, $file) || die "Can't open $file: $!\n";
278
while (!eof(FILE) && defined (my $line = <FILE>) && $linenum < $maxline) {
280
next unless $line =~ m/Copyright/i;
282
# Remove indents/comments
283
$line =~ s,^\s*(\#|/\*|//)\s*,,;
284
# remove everything before the copyright
285
$line =~ s/.*(Copyright)/$1/i;
287
while (!eof(FILE) && defined (my $line = <FILE>) && $linenum < $maxline) {
289
# Remove indents/comments
290
$line =~ s,^\s*(\#|/\*|//)\s*,,;
292
$text =~ m/Copyright.*?The Chromium Authors. All rights reserved.*?BSD-style license.*?found.*?in the.*?LICENSE file/ && do {
294
return("global BSD-style Chromium", $text);
296
$text =~ m/It is free software.*?under the.*?terms of either.*?GNU General Public License.*?either version (\d+).*?any later version.*?Artistic License/ && do {
298
return("dual GPLv$1+/Artistic License", $text);
300
$text =~ m/The use and distribution terms for this software are covered by the.*?Microsoft Permissive License \(Ms-PL\).*?/ && do {
302
return("Ms-PL", $text);
307
($license, $copyright);
313
open(LC, "/usr/bin/licensecheck -r --copyright $dir |") ||
314
die "Can't open /usr/bin/licensecheck: $!\n";
315
while (!eof(LC) && defined($line = <LC>)) {
317
my ($file, $license, $copyright) = (undef, undef, 'UNKNOWN');
318
if ($line =~ m/^(\S[^:]+): (.*)/) {
321
$license =~ s/\s*$//;
323
if ($line =~ m/^ \[(.*.)\]/) {
327
# check for manual identification
328
for my $manual (keys %$manually_identified) {
329
if ($file =~ m,$manual,) {
330
my $res = $$manually_identified{$manual};
331
my $tmp_license = "";
332
my $tmp_copyright = "";
333
($tmp_license, $tmp_copyright) = @$res;
334
if (!$copyright || $copyright =~ /.*no copyright.*/ ) {
335
$copyright = $tmp_copyright;
337
if (!$license || $license eq "UNKNOWN" || $license eq "*No copyright* UNKNOWN") {
338
$license = $tmp_license;
343
if ($license eq 'UNKNOWN') {
344
# Look further into that file. licensecheck may have missed something
345
($license, $copyright) = get_license($file, $license, $copyright);
347
#printf "%-80s %-30s %s\n", $file, $license, $copyright;
349
$path =~ s,/[^/]*$,,;
350
push @{$$data{$path}{$license}{$copyright}}, [ $file ];
351
next if $line =~ m/^$/;
353
die "line='$line'\n";
357
print "Whitelisted licenses: \n - '" . (join "'\n - '", @$white_listed_licenses) . "'\n\n" unless $$opt{'a'};
359
for my $dir (sort keys %$data) {
361
for my $license (sort keys %{$$data{$dir}}) {
363
for my $w (@$white_listed_licenses) {
364
$skip++ if $w eq $license;
366
next if !$$opt{'a'} && $skip;
368
for my $copyright (sort keys %{$$data{$dir}{$license}}) {
369
my @values = values %{$$data{$dir}{$license}};
371
printf "Files: %s/*\n", $dir;
373
printf "Files: %s/{", $dir;
375
for my $file (sort { $$a[0] cmp $$b[0] } @{$$data{$dir}{$license}{$copyright}}) {
381
my $filename = $$file[0];
382
$filename =~ s/$dir\///;
383
printf "%s", $filename;
387
print "Copyright: $copyright:\n";
388
print "License: $license\n";