3 # Copyright (C) 2011-2024 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
23 # - file_license The license mentioned in the file,
24 # or a token with '??' if unknown.
27 if head -n 50 $file |
grep 'the GNU LGPLv3[+] or the GNU GPLv2[+]' > /dev
/null \
28 ||
{ { head -n 50 $file |
grep 'under the terms of either:' > /dev
/null
; } \
29 && { head -n 50 $file |
grep 'GNU Lesser General Public' > /dev
/null
; } \
30 && { head -n 50 $file |
grep 'GNU General Public' > /dev
/null
; } \
31 && { head -n 50 $file |
grep 'either version 3' > /dev
/null
; } \
32 && { head -n 50 $file |
grep 'either version 2' > /dev
/null
; }; }; then
33 file_license
='LGPLv3+ or GPLv2+'
35 if head -n 50 $file |
grep 'GNU General Public' > /dev
/null
; then
36 if { head -n 50 $file |
grep 'version 3 or later' > /dev
/null
; } \
37 ||
{ head -n 50 $file |
grep 'either version 3' > /dev
/null
; }; then
38 file_license
='GPL' # an alias for GPLv3+
40 if { head -n 50 $file |
grep 'version 2 or later' > /dev
/null
; } \
41 ||
{ head -n 50 $file |
grep 'either version 2' > /dev
/null
; }; then
48 if head -n 50 $file |
grep 'Lesser General' > /dev
/null
; then
49 if { head -n 50 $file |
grep 'version 3 or later' > /dev
/null
; } \
50 ||
{ head -n 50 $file |
grep 'either version 3' > /dev
/null
; }; then
51 file_license
='LGPL' # an alias for LGPLv3+
53 if { head -n 50 $file |
grep 'version 2 or later' > /dev
/null
; } \
54 ||
{ head -n 50 $file |
tr -d '\n' |
grep 'version 2 of the *. *License, or' > /dev
/null
; } \
55 ||
{ head -n 50 $file |
tr -d '\n' |
grep 'version 2\.1 of the *. *License, or' > /dev
/null
; }; then
56 file_license
='LGPLv2+'
62 if head -n 50 $file |
grep 'unlimited permission to copy and/or distribute' > /dev
/null
; then
63 file_license
='unlimited'
65 if head -n 50 $file |
grep 'This file is in the public domain' > /dev
/null
; then
66 file_license
='public domain'
78 # - module A module name.
80 # - module_license The license mentioned in the module.
81 func_module_license
()
83 module_license
=`./gnulib-tool --extract-license $module`
84 if test "$module_license" = 'GPLv3+' ||
test "$module_license" = 'GPLed build tool'; then
87 if test "$module_license" = 'GPLv2+ build tool'; then
88 module_license
='GPLv2+'
93 # func_weaker_license license1 license2
94 # Determines the weaker among the licenses license1, license2.
96 # - license1 A license.
97 # - license2 A license.
99 # - weaker_license The weaker among the licenses license1, license2.
100 func_weaker_license
()
102 if test "$1" = 'public domain' ||
test "$2" = 'public domain'; then
103 weaker_license
='public domain'
105 if test "$1" = 'unlimited' ||
test "$2" = 'unlimited'; then
106 weaker_license
='unlimited'
108 if test "$1" = 'LGPLv2+' ||
test "$2" = 'LGPLv2+'; then
109 weaker_license
='LGPLv2+'
111 if test "$1" = 'LGPLv3+ or GPLv2+' ||
test "$2" = 'LGPLv3+ or GPLv2+'; then
112 weaker_license
='LGPLv3+ or GPLv2+'
114 if { test "$1" = 'LGPL' && test "$2" != 'GPLv2+'; } \
115 ||
{ test "$2" = 'LGPL' && test "$1" != 'GPLv2+'; }; then
116 weaker_license
='LGPL'
118 if { test "$1" = 'GPLv2+' && test "$2" != 'LGPL'; } \
119 ||
{ test "$2" = 'GPLv2+' && test "$1" != 'LGPL'; }; then
120 weaker_license
='GPLv2+'
122 if test "$1" = "$2"; then
125 weaker_license
='<complex>'
135 # Iterate over the modules and collect the mismatch candidates.
137 for module
in `./gnulib-tool --list`; do
139 for file in `./gnulib-tool --extract-filelist "$module" | grep '^\(lib\|build-aux\)/'`; do
141 *.class
) # These are binary files, that don't contain a license notice.
145 if test "$file_license" != "$module_license"; then
146 # This pair (module, file) is a mismatch candidate.
147 case " $candidates " in
150 candidates
="$candidates $file" ;;
158 # Look at the candidates in more detail.
160 for file in $candidates; do
163 for module
in `./gnulib-tool --find "$file"`; do
165 if test -z "$weakest_license"; then
166 weakest_license
="$module_license"
168 func_weaker_license
"$weakest_license" "$module_license"
169 weakest_license
="$weaker_license"
172 if test "$file_license" != "$weakest_license"; then
173 # The 'glob' module is a special case. It contains LGPLv2+ code (shared with
174 # glibc) but at the same time also has a dependency to a module under GPL
175 # (namely, 'fstatat'). This is not a mistake.
176 if test "$weakest_license" = GPL \
177 && case "$file" in lib
/glob
*) true
;; *) false
;; esac; then
180 if test $error = 0; then
181 echo "Module License File License File name"
182 echo "================= ================= ====================================="
184 printf '%-17s %-17s %s\n' "$weakest_license" "$file_license" "$file"