blob: 44657d27c900f0f104f7c807d9dede1ad4ee68c2 [file] [log] [blame]
Martin Roth0ad5fbd2020-12-24 12:06:38 -07001#!/usr/bin/env sh
Patrick Georgie8826302010-11-19 10:16:43 +00002#
Patrick Georgi7333a112020-05-08 20:48:04 +02003# SPDX-License-Identifier: GPL-2.0-only
4
Martin Rothc4511e22016-01-12 10:25:49 -07005# DESCR: Check that files in have valid license headers
6# $1 is an optional command line parameter containing directories to check
7
Martin Rothd81debd2022-06-03 00:06:57 -06008
9LINTDIR="$(
10 cd -- "$(dirname "$0")" > /dev/null 2>&1 || return
11 pwd -P
12)"
13
14# shellcheck source=helper_functions.sh
15. "${LINTDIR}/helper_functions.sh"
16
Martin Rothc4511e22016-01-12 10:25:49 -070017# regex list of files and directories to exclude from the search
18HEADER_EXCLUDED="\
Patrick Georgideea25b2020-05-10 16:34:10 +020019^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/|\
Jacob Garber10999ea62020-05-18 13:36:58 -060024^src/drivers/net/ne2k.c\$|\
Patrick Georgideea25b2020-05-10 16:34:10 +020025^src/drivers/xgi/common/initdef.h\$|\
26^src/drivers/xgi/common/vstruct.h\$|\
Martin Rothbdad9a82018-05-26 19:47:07 -060027^src/lib/gnat/|\
Patrick Georgideea25b2020-05-10 16:34:10 +020028^src/lib/lzmadecode.[ch]\$|\
29^src/lib/stack.c\$|\
Felix Singerbbe0a992022-08-22 20:08:40 +020030^src/sbom/TAGS|\
Martin Rothc4511e22016-01-12 10:25:49 -070031^src/vendorcode/|\
Maximilian Brune33079b82024-03-04 15:34:41 +010032^tests/data/|\
Martin Rothbdad9a82018-05-26 19:47:07 -060033^util/amdtools/example_input/|\
34^util/cbfstool/lzma/|\
Patrick Georgideea25b2020-05-10 16:34:10 +020035^util/cbfstool/lz4/|\
Martin Rothc4511e22016-01-12 10:25:49 -070036^util/kconfig/|\
Martin Rothc4511e22016-01-12 10:25:49 -070037Kconfig|\
38\<COPYING\>|\
39\<LICENSE\>|\
40\<README\>|\
41Changelog|\
Jacob Garber07201d72020-09-08 12:25:44 -060042AUTHORS|\
Martin Rothc4511e22016-01-12 10:25:49 -070043TODO|\
44EXAMPLE|\
Martin Rothbdad9a82018-05-26 19:47:07 -060045NEWS|\
46ChangeLog|\
47Dockerfile|\
Martin Roth251e2662022-08-07 17:17:41 -060048\.gitignore$|\
Martin Rothbdad9a82018-05-26 19:47:07 -060049\.in$|\
50\.[18]$|\
51\.md$|\
52\.wiki$|\
53\.xxdump$|\
54\.spec$|\
Martin Rothc4511e22016-01-12 10:25:49 -070055\.txt$|\
56\.jpg$|\
57\.cksum$|\
58\.bin$|\
Martin Rothdea13332018-05-04 09:19:07 -060059\.vbt$|\
Martin Rothc4511e22016-01-12 10:25:49 -070060\.hex$|\
61\.patch$|\
62_shipped$|\
63/microcode-[^/]*.h$|\
64/sdram-.*\.inc$|\
Martin Roth84129b82016-04-11 13:35:59 -060065\.fmd|\
Naresh G Solanki358b2b32016-10-27 23:13:37 +053066\.cb|\
Martin Roth84129b82016-04-11 13:35:59 -060067\.cfg$|\
68\.spd|\
69config|\
70cmos\.layout|\
Nicholas Chin4ff23a22024-03-21 11:27:50 -060071cmos\.default|\
72\.apcb$\
Martin Rothc4511e22016-01-12 10:25:49 -070073"
74
75#space separated list of directories to test
76if [ "$1" = "" ]; then
77 HEADER_DIRS="src util"
78else
79 HEADER_DIRS="$1"
80fi
Patrick Georgie8826302010-11-19 10:16:43 +000081
Martin Rothc4511e22016-01-12 10:25:49 -070082
83#get initial list from git, removing HEADER_EXCLUDED files.
84#make a copy to check for the old style header later.
Felix Singer74b4bd02023-04-01 14:42:54 +020085headerlist=$(${FIND_FILES} $HEADER_DIRS | grep -E -v "($HEADER_EXCLUDED)")
Martin Rothc4511e22016-01-12 10:25:49 -070086
Martin Roth1eccf772024-02-16 10:19:07 -070087LICENSE_ID_STRING="SPDX-License-Identifier"
88
Martin Rothc4511e22016-01-12 10:25:49 -070089#update headerlist by removing files that match the license string
90check_for_license() {
Martin Roth84129b82016-04-11 13:35:59 -060091 if [ -n "$headerlist" ] && [ -z "$2" ]; then
Martin Roth1eccf772024-02-16 10:19:07 -070092 headerlist="$(grep -iL "${LICENSE_ID_STRING}: $1" $headerlist 2>/dev/null)"
Martin Roth84129b82016-04-11 13:35:59 -060093 elif [ -n "$headerlist" ]; then
Martin Roth1eccf772024-02-16 10:19:07 -070094 p1list="$(grep -il "${LICENSE_ID_STRING}: $1" $headerlist 2>/dev/null)"
95 p2list="$(grep -il "${LICENSE_ID_STRING}: $2" $headerlist 2>/dev/null)"
Martin Rothf8db0282016-01-21 13:20:39 -070096
97 # Make list of files that were in both previous lists
Martin Roth84129b82016-04-11 13:35:59 -060098 pbothlist="$(echo $p1list $p2list | tr ' ' "\n" | \
Martin Rothf8db0282016-01-21 13:20:39 -070099 sort | uniq -d)"
100
101 # Remove all files that were in both of the previous lists
102 # Note that this is unstable if we ever get any filenames
103 # with spaces.
104 headerlist="$(echo $headerlist $pbothlist | tr ' ' "\n" | \
105 sort | uniq -u)"
106 fi
Martin Rothc4511e22016-01-12 10:25:49 -0700107}
108
109#search the files for license headers
Martin Roth1eccf772024-02-16 10:19:07 -0700110check_for_license 'Apache-2.0'
111check_for_license 'BSD-2-Clause'
112check_for_license 'BSD-3-Clause'
113check_for_license 'GPL-2.0-only'
114check_for_license 'GPL-2.0-or-later'
115check_for_license 'GPL-2.0-only WITH Linux-syscall-note'
116check_for_license 'GPL-3.0-only'
117check_for_license 'GPL-3.0-only WITH GCC-exception-3.1'
118check_for_license 'GPL-3.0-or-later'
119check_for_license 'HPND'
120check_for_license 'HPND-sell-variant'
121check_for_license 'ISC'
122check_for_license 'MIT'
123check_for_license 'X11'
Martin Rothe348eba2019-09-23 18:14:34 -0600124
Patrick Georgie342cd32020-03-04 14:58:49 +0100125# 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.
Martin Roth1eccf772024-02-16 10:19:07 -0700130check_for_license 'BSD-4-Clause-UC'
Patrick Georgie342cd32020-03-04 14:58:49 +0100131
Martin Rothf67a1aa2022-08-04 12:20:29 -0600132# 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"
135# content.
Martin Roth1eccf772024-02-16 10:19:07 -0700136check_for_license 'CC-PDDC'
Martin Rothf67a1aa2022-08-04 12:20:29 -0600137
Martin Rothc4511e22016-01-12 10:25:49 -0700138for file in $headerlist; do
Martin Roth957fde62022-08-07 17:21:17 -0600139 # Verify the file actually exists
140 if [ -f "$file" ]; then
Jacob Garberd2fea1a2020-05-18 13:25:18 -0600141 echo "$file has no recognized SPDX identifier."
Martin Rothc4511e22016-01-12 10:25:49 -0700142 fi
143done