3 # SPDX-License-Identifier: GPL-2.0-only
5 # DESCR: Check that files in have valid license headers
6 # $1 is an optional command line parameter containing directories to check
10 cd -- "$
(dirname "$0")" > /dev/null 2>&1 || return
14 # shellcheck source=helper_functions.sh
15 .
"${LINTDIR}/helper_functions.sh"
17 # regex list of files and directories to exclude from the search
19 ^src/commonlib/bsd/lz4.c.inc\$|\
20 ^src/cpu/x86/16bit/entry16.inc\$|\
21 ^src/device/oprom/x86emu/|\
22 ^src/device/oprom/include/x86emu/|\
23 ^src/device/oprom/yabel/|\
24 ^src/drivers/net/ne2k.c\$|\
25 ^src/drivers/xgi/common/initdef.h\$|\
26 ^src/drivers/xgi/common/vstruct.h\$|\
28 ^src/lib/lzmadecode.[ch]\$|\
33 ^util/amdtools/example_input/|\
34 ^util/cbfstool/lzma/|\
75 #space separated list of directories to test
76 if [ "$1" = "" ]; then
77 HEADER_DIRS
="src util"
83 #get initial list from git, removing HEADER_EXCLUDED files.
84 #make a copy to check for the old style header later.
85 headerlist
=$
(${FIND_FILES} $HEADER_DIRS |
grep -E -v "($HEADER_EXCLUDED)")
87 LICENSE_ID_STRING
="SPDX-License-Identifier"
89 #update headerlist by removing files that match the license string
91 if [ -n "$headerlist" ] && [ -z "$2" ]; then
92 headerlist
="$(grep -iL "${LICENSE_ID_STRING}: $1" $headerlist 2>/dev/null)"
93 elif [ -n "$headerlist" ]; then
94 p1list
="$(grep -il "${LICENSE_ID_STRING}: $1" $headerlist 2>/dev/null)"
95 p2list
="$(grep -il "${LICENSE_ID_STRING}: $2" $headerlist 2>/dev/null)"
97 # Make list of files that were in both previous lists
98 pbothlist
="$(echo $p1list $p2list | tr ' ' "\n" | \
101 # Remove all files that were in both of the previous lists
102 # Note that this is unstable if we ever get any filenames
104 headerlist
="$(echo $headerlist $pbothlist | tr ' ' "\n" | \
109 #search the files for license headers
110 check_for_license
'Apache-2.0'
111 check_for_license
'BSD-2-Clause'
112 check_for_license
'BSD-3-Clause'
113 check_for_license
'GPL-2.0-only'
114 check_for_license
'GPL-2.0-or-later'
115 check_for_license
'GPL-2.0-only WITH Linux-syscall-note'
116 check_for_license
'GPL-3.0-only'
117 check_for_license
'GPL-3.0-only WITH GCC-exception-3.1'
118 check_for_license
'GPL-3.0-or-later'
119 check_for_license
'HPND'
120 check_for_license
'HPND-sell-variant'
121 check_for_license
'ISC'
122 check_for_license
'MIT'
123 check_for_license
'X11'
125 # This is 4 clause ("with advertising") but the University of Berkeley
126 # declared that 4th clause void, see
127 # ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
128 # With this, BSD-4-Clause-UC becomes GPLv2 compatible, and so SPDX doesn't
129 # differentiate between this license with or without advertising.
130 check_for_license
'BSD-4-Clause-UC'
132 # This is the Creative Commons Public Domain Dedication and Certification
133 # for files that are already in the public domain. This includes files
134 # that cannot be licensed such as blank files or files with no "creative"
136 check_for_license
'CC-PDDC'
138 for file in $headerlist; do
139 # Verify the file actually exists
140 if [ -f "$file" ]; then
141 echo "$file has no recognized SPDX identifier."