blob: 2f65321a6fe0c79d3d457192f394b2db2b48733f [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
8# regex list of files and directories to exclude from the search
9HEADER_EXCLUDED="\
Patrick Georgideea25b2020-05-10 16:34:10 +020010^src/commonlib/bsd/lz4.c.inc\$|\
11^src/cpu/x86/16bit/entry16.inc\$|\
12^src/device/oprom/x86emu/|\
13^src/device/oprom/include/x86emu/|\
14^src/device/oprom/yabel/|\
Jacob Garber10999ea62020-05-18 13:36:58 -060015^src/drivers/net/ne2k.c\$|\
Patrick Georgideea25b2020-05-10 16:34:10 +020016^src/drivers/xgi/common/initdef.h\$|\
17^src/drivers/xgi/common/vstruct.h\$|\
Martin Rothbdad9a82018-05-26 19:47:07 -060018^src/lib/gnat/|\
Patrick Georgideea25b2020-05-10 16:34:10 +020019^src/lib/lzmadecode.[ch]\$|\
20^src/lib/stack.c\$|\
Martin Rothc4511e22016-01-12 10:25:49 -070021^src/vendorcode/|\
Martin Rothbdad9a82018-05-26 19:47:07 -060022^util/amdtools/example_input/|\
23^util/cbfstool/lzma/|\
Patrick Georgideea25b2020-05-10 16:34:10 +020024^util/cbfstool/lz4/|\
Martin Rothc4511e22016-01-12 10:25:49 -070025^util/kconfig/|\
Martin Rothc4511e22016-01-12 10:25:49 -070026Kconfig|\
27\<COPYING\>|\
28\<LICENSE\>|\
29\<README\>|\
30Changelog|\
Jacob Garber07201d72020-09-08 12:25:44 -060031AUTHORS|\
Martin Rothc4511e22016-01-12 10:25:49 -070032TODO|\
33EXAMPLE|\
Martin Rothbdad9a82018-05-26 19:47:07 -060034NEWS|\
35ChangeLog|\
36Dockerfile|\
37\.in$|\
38\.[18]$|\
39\.md$|\
40\.wiki$|\
41\.xxdump$|\
42\.spec$|\
Martin Rothc4511e22016-01-12 10:25:49 -070043\.txt$|\
44\.jpg$|\
45\.cksum$|\
46\.bin$|\
Martin Rothdea13332018-05-04 09:19:07 -060047\.vbt$|\
Martin Rothc4511e22016-01-12 10:25:49 -070048\.hex$|\
49\.patch$|\
50_shipped$|\
51/microcode-[^/]*.h$|\
52/sdram-.*\.inc$|\
Martin Roth84129b82016-04-11 13:35:59 -060053Makefile\.inc|\
54\.fmd|\
Naresh G Solanki358b2b32016-10-27 23:13:37 +053055\.cb|\
Martin Roth84129b82016-04-11 13:35:59 -060056\.cfg$|\
57\.spd|\
58config|\
59cmos\.layout|\
60cmos\.default\
Martin Rothc4511e22016-01-12 10:25:49 -070061"
62
63#space separated list of directories to test
64if [ "$1" = "" ]; then
65 HEADER_DIRS="src util"
66else
67 HEADER_DIRS="$1"
68fi
Patrick Georgie8826302010-11-19 10:16:43 +000069
70LC_ALL=C export LC_ALL
Martin Rothc4511e22016-01-12 10:25:49 -070071
72#get initial list from git, removing HEADER_EXCLUDED files.
73#make a copy to check for the old style header later.
74headerlist=$(git ls-files $HEADER_DIRS | egrep -v "($HEADER_EXCLUDED)")
75
76#update headerlist by removing files that match the license string
77check_for_license() {
Martin Roth84129b82016-04-11 13:35:59 -060078 if [ -n "$headerlist" ] && [ -z "$2" ]; then
Martin Rothf8db0282016-01-21 13:20:39 -070079 headerlist="$(grep -iL "$1" $headerlist 2>/dev/null)"
Martin Roth84129b82016-04-11 13:35:59 -060080 elif [ -n "$headerlist" ]; then
81 p1list="$(grep -il "$1" $headerlist 2>/dev/null)"
82 p2list="$(grep -il "$2" $headerlist 2>/dev/null)"
Martin Rothf8db0282016-01-21 13:20:39 -070083
84 # Make list of files that were in both previous lists
Martin Roth84129b82016-04-11 13:35:59 -060085 pbothlist="$(echo $p1list $p2list | tr ' ' "\n" | \
Martin Rothf8db0282016-01-21 13:20:39 -070086 sort | uniq -d)"
87
88 # Remove all files that were in both of the previous lists
89 # Note that this is unstable if we ever get any filenames
90 # with spaces.
91 headerlist="$(echo $headerlist $pbothlist | tr ' ' "\n" | \
92 sort | uniq -u)"
93 fi
Martin Rothc4511e22016-01-12 10:25:49 -070094}
95
96#search the files for license headers
Martin Rothe348eba2019-09-23 18:14:34 -060097check_for_license 'SPDX-License-Identifier: Apache-2.0'
Patrick Georgie03132a2020-05-10 19:56:54 +020098check_for_license 'SPDX-License-Identifier: BSD-2-Clause'
Martin Rothe348eba2019-09-23 18:14:34 -060099check_for_license 'SPDX-License-Identifier: BSD-3-Clause'
100check_for_license 'SPDX-License-Identifier: GPL-2.0-only'
101check_for_license 'SPDX-License-Identifier: GPL-2.0-or-later'
Rajat Jain99900112020-03-27 13:12:47 -0700102check_for_license 'SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note'
Martin Rothe348eba2019-09-23 18:14:34 -0600103check_for_license 'SPDX-License-Identifier: GPL-3.0-only'
104check_for_license 'SPDX-License-Identifier: GPL-3.0-or-later'
Patrick Georgi878a7a72020-05-10 21:19:04 +0200105check_for_license 'SPDX-License-Identifier: HPND'
106check_for_license 'SPDX-License-Identifier: HPND-sell-variant'
Martin Rothe348eba2019-09-23 18:14:34 -0600107check_for_license 'SPDX-License-Identifier: ISC'
108check_for_license 'SPDX-License-Identifier: MIT'
109check_for_license 'SPDX-License-Identifier: X11'
110
Patrick Georgie342cd32020-03-04 14:58:49 +0100111# This is 4 clause ("with advertising") but the University of Berkeley
112# declared that 4th clause void, see
113# ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
114# With this, BSD-4-Clause-UC becomes GPLv2 compatible, and so SPDX doesn't
115# differentiate between this license with or without advertising.
116check_for_license 'SPDX-License-Identifier: BSD-4-Clause-UC'
117
Martin Rothc4511e22016-01-12 10:25:49 -0700118for file in $headerlist; do
Martin Roth03e9d6a2017-02-09 16:44:24 -0800119 # Verify the file exists, and has content that requires a header
120 # This assumes that a file that has 4 lines or fewer is not notable
121 # enough to require a license.
122 if [ -f "$file" ] && [ "$(wc -l < "$file")" -gt 4 ]; then
Jacob Garberd2fea1a2020-05-18 13:25:18 -0600123 echo "$file has no recognized SPDX identifier."
Martin Rothc4511e22016-01-12 10:25:49 -0700124 fi
125done