blob: 56addac710bd44b8ff23affad4d9966c9151fd0e [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|\
Nicholas Chin4ff23a22024-03-21 11:27:50 -060070cmos\.default|\
71\.apcb$\
Martin Rothc4511e22016-01-12 10:25:49 -070072"
73
74#space separated list of directories to test
75if [ "$1" = "" ]; then
76 HEADER_DIRS="src util"
77else
78 HEADER_DIRS="$1"
79fi
Patrick Georgie8826302010-11-19 10:16:43 +000080
Martin Rothc4511e22016-01-12 10:25:49 -070081
82#get initial list from git, removing HEADER_EXCLUDED files.
83#make a copy to check for the old style header later.
Felix Singer74b4bd02023-04-01 14:42:54 +020084headerlist=$(${FIND_FILES} $HEADER_DIRS | grep -E -v "($HEADER_EXCLUDED)")
Martin Rothc4511e22016-01-12 10:25:49 -070085
86#update headerlist by removing files that match the license string
87check_for_license() {
Martin Roth84129b82016-04-11 13:35:59 -060088 if [ -n "$headerlist" ] && [ -z "$2" ]; then
Martin Rothf8db0282016-01-21 13:20:39 -070089 headerlist="$(grep -iL "$1" $headerlist 2>/dev/null)"
Martin Roth84129b82016-04-11 13:35:59 -060090 elif [ -n "$headerlist" ]; then
91 p1list="$(grep -il "$1" $headerlist 2>/dev/null)"
92 p2list="$(grep -il "$2" $headerlist 2>/dev/null)"
Martin Rothf8db0282016-01-21 13:20:39 -070093
94 # Make list of files that were in both previous lists
Martin Roth84129b82016-04-11 13:35:59 -060095 pbothlist="$(echo $p1list $p2list | tr ' ' "\n" | \
Martin Rothf8db0282016-01-21 13:20:39 -070096 sort | uniq -d)"
97
98 # Remove all files that were in both of the previous lists
99 # Note that this is unstable if we ever get any filenames
100 # with spaces.
101 headerlist="$(echo $headerlist $pbothlist | tr ' ' "\n" | \
102 sort | uniq -u)"
103 fi
Martin Rothc4511e22016-01-12 10:25:49 -0700104}
105
106#search the files for license headers
Martin Rothe348eba2019-09-23 18:14:34 -0600107check_for_license 'SPDX-License-Identifier: Apache-2.0'
Patrick Georgie03132a2020-05-10 19:56:54 +0200108check_for_license 'SPDX-License-Identifier: BSD-2-Clause'
Martin Rothe348eba2019-09-23 18:14:34 -0600109check_for_license 'SPDX-License-Identifier: BSD-3-Clause'
110check_for_license 'SPDX-License-Identifier: GPL-2.0-only'
111check_for_license 'SPDX-License-Identifier: GPL-2.0-or-later'
Rajat Jain99900112020-03-27 13:12:47 -0700112check_for_license 'SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note'
Martin Rothe348eba2019-09-23 18:14:34 -0600113check_for_license 'SPDX-License-Identifier: GPL-3.0-only'
Martin Rothafa3e5a2022-08-07 17:10:36 -0600114check_for_license 'SPDX-License-Identifier: GPL-3.0-only WITH GCC-exception-3.1'
Martin Rothe348eba2019-09-23 18:14:34 -0600115check_for_license 'SPDX-License-Identifier: GPL-3.0-or-later'
Patrick Georgi878a7a72020-05-10 21:19:04 +0200116check_for_license 'SPDX-License-Identifier: HPND'
117check_for_license 'SPDX-License-Identifier: HPND-sell-variant'
Martin Rothe348eba2019-09-23 18:14:34 -0600118check_for_license 'SPDX-License-Identifier: ISC'
119check_for_license 'SPDX-License-Identifier: MIT'
120check_for_license 'SPDX-License-Identifier: X11'
121
Patrick Georgie342cd32020-03-04 14:58:49 +0100122# This is 4 clause ("with advertising") but the University of Berkeley
123# declared that 4th clause void, see
124# ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
125# With this, BSD-4-Clause-UC becomes GPLv2 compatible, and so SPDX doesn't
126# differentiate between this license with or without advertising.
127check_for_license 'SPDX-License-Identifier: BSD-4-Clause-UC'
128
Martin Rothf67a1aa2022-08-04 12:20:29 -0600129# This is the Creative Commons Public Domain Dedication and Certification
130# for files that are already in the public domain. This includes files
131# that cannot be licensed such as blank files or files with no "creative"
132# content.
133check_for_license 'SPDX-License-Identifier: CC-PDDC'
134
Martin Rothc4511e22016-01-12 10:25:49 -0700135for file in $headerlist; do
Martin Roth957fde62022-08-07 17:21:17 -0600136 # Verify the file actually exists
137 if [ -f "$file" ]; then
Jacob Garberd2fea1a2020-05-18 13:25:18 -0600138 echo "$file has no recognized SPDX identifier."
Martin Rothc4511e22016-01-12 10:25:49 -0700139 fi
140done