blob: 07cdb23d95628b1594ca7598e66e98b2982f70a7 [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/|\
Martin Rothbdad9a82018-05-26 19:47:07 -060032^util/amdtools/example_input/|\
33^util/cbfstool/lzma/|\
Patrick Georgideea25b2020-05-10 16:34:10 +020034^util/cbfstool/lz4/|\
Martin Rothc4511e22016-01-12 10:25:49 -070035^util/kconfig/|\
Martin Rothc4511e22016-01-12 10:25:49 -070036Kconfig|\
37\<COPYING\>|\
38\<LICENSE\>|\
39\<README\>|\
40Changelog|\
Jacob Garber07201d72020-09-08 12:25:44 -060041AUTHORS|\
Martin Rothc4511e22016-01-12 10:25:49 -070042TODO|\
43EXAMPLE|\
Martin Rothbdad9a82018-05-26 19:47:07 -060044NEWS|\
45ChangeLog|\
46Dockerfile|\
Martin Roth251e2662022-08-07 17:17:41 -060047\.gitignore$|\
Martin Rothbdad9a82018-05-26 19:47:07 -060048\.in$|\
49\.[18]$|\
50\.md$|\
51\.wiki$|\
52\.xxdump$|\
53\.spec$|\
Martin Rothc4511e22016-01-12 10:25:49 -070054\.txt$|\
55\.jpg$|\
56\.cksum$|\
57\.bin$|\
Martin Rothdea13332018-05-04 09:19:07 -060058\.vbt$|\
Martin Rothc4511e22016-01-12 10:25:49 -070059\.hex$|\
60\.patch$|\
61_shipped$|\
62/microcode-[^/]*.h$|\
63/sdram-.*\.inc$|\
Martin Roth84129b82016-04-11 13:35:59 -060064\.fmd|\
Naresh G Solanki358b2b32016-10-27 23:13:37 +053065\.cb|\
Martin Roth84129b82016-04-11 13:35:59 -060066\.cfg$|\
67\.spd|\
68config|\
69cmos\.layout|\
70cmos\.default\
Martin Rothc4511e22016-01-12 10:25:49 -070071"
72
73#space separated list of directories to test
74if [ "$1" = "" ]; then
75 HEADER_DIRS="src util"
76else
77 HEADER_DIRS="$1"
78fi
Patrick Georgie8826302010-11-19 10:16:43 +000079
Martin Rothc4511e22016-01-12 10:25:49 -070080
81#get initial list from git, removing HEADER_EXCLUDED files.
82#make a copy to check for the old style header later.
Felix Singer74b4bd02023-04-01 14:42:54 +020083headerlist=$(${FIND_FILES} $HEADER_DIRS | grep -E -v "($HEADER_EXCLUDED)")
Martin Rothc4511e22016-01-12 10:25:49 -070084
85#update headerlist by removing files that match the license string
86check_for_license() {
Martin Roth84129b82016-04-11 13:35:59 -060087 if [ -n "$headerlist" ] && [ -z "$2" ]; then
Martin Rothf8db0282016-01-21 13:20:39 -070088 headerlist="$(grep -iL "$1" $headerlist 2>/dev/null)"
Martin Roth84129b82016-04-11 13:35:59 -060089 elif [ -n "$headerlist" ]; then
90 p1list="$(grep -il "$1" $headerlist 2>/dev/null)"
91 p2list="$(grep -il "$2" $headerlist 2>/dev/null)"
Martin Rothf8db0282016-01-21 13:20:39 -070092
93 # Make list of files that were in both previous lists
Martin Roth84129b82016-04-11 13:35:59 -060094 pbothlist="$(echo $p1list $p2list | tr ' ' "\n" | \
Martin Rothf8db0282016-01-21 13:20:39 -070095 sort | uniq -d)"
96
97 # Remove all files that were in both of the previous lists
98 # Note that this is unstable if we ever get any filenames
99 # with spaces.
100 headerlist="$(echo $headerlist $pbothlist | tr ' ' "\n" | \
101 sort | uniq -u)"
102 fi
Martin Rothc4511e22016-01-12 10:25:49 -0700103}
104
105#search the files for license headers
Martin Rothe348eba2019-09-23 18:14:34 -0600106check_for_license 'SPDX-License-Identifier: Apache-2.0'
Patrick Georgie03132a2020-05-10 19:56:54 +0200107check_for_license 'SPDX-License-Identifier: BSD-2-Clause'
Martin Rothe348eba2019-09-23 18:14:34 -0600108check_for_license 'SPDX-License-Identifier: BSD-3-Clause'
109check_for_license 'SPDX-License-Identifier: GPL-2.0-only'
110check_for_license 'SPDX-License-Identifier: GPL-2.0-or-later'
Rajat Jain99900112020-03-27 13:12:47 -0700111check_for_license 'SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note'
Martin Rothe348eba2019-09-23 18:14:34 -0600112check_for_license 'SPDX-License-Identifier: GPL-3.0-only'
Martin Rothafa3e5a2022-08-07 17:10:36 -0600113check_for_license 'SPDX-License-Identifier: GPL-3.0-only WITH GCC-exception-3.1'
Martin Rothe348eba2019-09-23 18:14:34 -0600114check_for_license 'SPDX-License-Identifier: GPL-3.0-or-later'
Patrick Georgi878a7a72020-05-10 21:19:04 +0200115check_for_license 'SPDX-License-Identifier: HPND'
116check_for_license 'SPDX-License-Identifier: HPND-sell-variant'
Martin Rothe348eba2019-09-23 18:14:34 -0600117check_for_license 'SPDX-License-Identifier: ISC'
118check_for_license 'SPDX-License-Identifier: MIT'
119check_for_license 'SPDX-License-Identifier: X11'
120
Patrick Georgie342cd32020-03-04 14:58:49 +0100121# This is 4 clause ("with advertising") but the University of Berkeley
122# declared that 4th clause void, see
123# ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
124# With this, BSD-4-Clause-UC becomes GPLv2 compatible, and so SPDX doesn't
125# differentiate between this license with or without advertising.
126check_for_license 'SPDX-License-Identifier: BSD-4-Clause-UC'
127
Martin Rothf67a1aa2022-08-04 12:20:29 -0600128# This is the Creative Commons Public Domain Dedication and Certification
129# for files that are already in the public domain. This includes files
130# that cannot be licensed such as blank files or files with no "creative"
131# content.
132check_for_license 'SPDX-License-Identifier: CC-PDDC'
133
Martin Rothc4511e22016-01-12 10:25:49 -0700134for file in $headerlist; do
Martin Roth957fde62022-08-07 17:21:17 -0600135 # Verify the file actually exists
136 if [ -f "$file" ]; then
Jacob Garberd2fea1a2020-05-18 13:25:18 -0600137 echo "$file has no recognized SPDX identifier."
Martin Rothc4511e22016-01-12 10:25:49 -0700138 fi
139done